Improve performance of the code used to display active thumbnail's borders
This commit is contained in:
@@ -67,21 +67,7 @@ namespace EveOPreview.Configuration
|
||||
|
||||
public bool EnableActiveClientHighlight { get; set; }
|
||||
|
||||
public Color ActiveClientHighlightColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._activeClientHighlightColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
// Some WinForms magic
|
||||
// True Black color cannot be used as highlight frame color
|
||||
// So a somewhat less-Black one is used
|
||||
this._activeClientHighlightColor = (value != Color.Black) ? value : Color.FromArgb(1, 1, 1);
|
||||
}
|
||||
}
|
||||
private Color _activeClientHighlightColor;
|
||||
public Color ActiveClientHighlightColor { get; set; }
|
||||
|
||||
public int ActiveClientHighlightThickness { get; set; }
|
||||
|
||||
@@ -184,7 +170,7 @@ namespace EveOPreview.Configuration
|
||||
ThumbnailConfig.ApplyRestrictions(this.ThumbnailSize.Height, this.ThumbnailMinimumSize.Height, this.ThumbnailMaximumSize.Height));
|
||||
this.ThumbnailOpacity = ThumbnailConfig.ApplyRestrictions((int)(this.ThumbnailOpacity * 100.00), 20, 100) / 100.00;
|
||||
this.ThumbnailZoomFactor = ThumbnailConfig.ApplyRestrictions(this.ThumbnailZoomFactor, 2, 10);
|
||||
this.ActiveClientHighlightThickness = ThumbnailConfig.ApplyRestrictions(this.ActiveClientHighlightThickness, 1, 3);
|
||||
this.ActiveClientHighlightThickness = ThumbnailConfig.ApplyRestrictions(this.ActiveClientHighlightThickness, 1, 6);
|
||||
}
|
||||
|
||||
private static int ApplyRestrictions(int value, int minimum, int maximum)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace EveOPreview.UI
|
||||
@@ -8,12 +7,6 @@ namespace EveOPreview.UI
|
||||
{
|
||||
#region Private fields
|
||||
private readonly Action<object, MouseEventArgs> _areaClickAction;
|
||||
private bool _isHighlightEnabled;
|
||||
private Color _highlightColor;
|
||||
private int _highlightWidthLeft;
|
||||
private int _highlightWidthTop;
|
||||
private int _highlightWidthRight;
|
||||
private int _highlightWidthBottom;
|
||||
#endregion
|
||||
|
||||
public ThumbnailOverlay(Form owner, Action<object, MouseEventArgs> areaClickAction)
|
||||
@@ -21,9 +14,6 @@ namespace EveOPreview.UI
|
||||
this.Owner = owner;
|
||||
this._areaClickAction = areaClickAction;
|
||||
|
||||
this._isHighlightEnabled = false;
|
||||
this._highlightColor = Color.Red;
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -42,27 +32,6 @@ namespace EveOPreview.UI
|
||||
this.OverlayLabel.Visible = enable;
|
||||
}
|
||||
|
||||
public void SetHighlightWidth(int left, int top, int right, int bottom)
|
||||
{
|
||||
this._highlightWidthLeft = left;
|
||||
this._highlightWidthTop = top;
|
||||
this._highlightWidthRight = right;
|
||||
this._highlightWidthBottom = bottom;
|
||||
}
|
||||
|
||||
public void EnableHighlight(bool enabled, Color color)
|
||||
{
|
||||
if (enabled == this._isHighlightEnabled)
|
||||
{
|
||||
// Nothing to do here
|
||||
return;
|
||||
}
|
||||
|
||||
this._isHighlightEnabled = enabled;
|
||||
this._highlightColor = color;
|
||||
this.Refresh();
|
||||
}
|
||||
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
@@ -72,19 +41,5 @@ namespace EveOPreview.UI
|
||||
return Params;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
if (this._isHighlightEnabled)
|
||||
{
|
||||
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle,
|
||||
this._highlightColor, this._highlightWidthLeft, ButtonBorderStyle.Solid,
|
||||
this._highlightColor, this._highlightWidthTop, ButtonBorderStyle.Solid,
|
||||
this._highlightColor, this._highlightWidthRight, ButtonBorderStyle.Solid,
|
||||
this._highlightColor, this._highlightWidthBottom, ButtonBorderStyle.Solid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,10 +203,24 @@ namespace EveOPreview.UI
|
||||
|
||||
public void SetHighlight(bool enabled, Color color, int width)
|
||||
{
|
||||
this._isSizeChanged = this._isSizeChanged || (this._isHighlightEnabled != enabled);
|
||||
this._isHighlightEnabled = enabled;
|
||||
this._highlightWidth = width;
|
||||
this._overlay.EnableHighlight(enabled, color);
|
||||
if (this._isHighlightEnabled == enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
this._isHighlightEnabled = true;
|
||||
this._highlightWidth = width;
|
||||
this.BackColor = color;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._isHighlightEnabled = false;
|
||||
this.BackColor = SystemColors.Control;
|
||||
}
|
||||
|
||||
this._isSizeChanged = true;
|
||||
}
|
||||
|
||||
public void ZoomIn(ViewZoomAnchor anchor, int zoomFactor)
|
||||
@@ -330,11 +344,10 @@ namespace EveOPreview.UI
|
||||
int actualHeight = baseHeight - 2 * this._highlightWidth;
|
||||
double desiredWidth = actualHeight * baseAspectRatio;
|
||||
int actualWidth = (int)Math.Round(desiredWidth, MidpointRounding.AwayFromZero);
|
||||
int highlightWidthLeft = Math.Min(4, (baseWidth - actualWidth) / 2);
|
||||
int highlightWidthRight = Math.Min(4, baseWidth - actualWidth - highlightWidthLeft);
|
||||
int highlightWidthLeft = (baseWidth - actualWidth) / 2;
|
||||
int highlightWidthRight = baseWidth - actualWidth - highlightWidthLeft;
|
||||
|
||||
this._overlay.SetHighlightWidth(highlightWidthLeft, this._highlightWidth, highlightWidthRight, this._highlightWidth);
|
||||
this._thumbnail.rcDestination = new RECT(0 + highlightWidthLeft, 0 + this._highlightWidth, actualWidth + highlightWidthLeft, actualHeight + this._highlightWidth);
|
||||
this._thumbnail.rcDestination = new RECT(0 + highlightWidthLeft, 0 + this._highlightWidth, baseWidth - highlightWidthRight, baseHeight - this._highlightWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -378,8 +391,9 @@ namespace EveOPreview.UI
|
||||
Size overlaySize = this.ClientSize;
|
||||
Point overlayLocation = this.Location;
|
||||
|
||||
overlayLocation.X += (this.Size.Width - this.ClientSize.Width) / 2;
|
||||
overlayLocation.Y += (this.Size.Height - this.ClientSize.Height) - (this.Size.Width - this.ClientSize.Width) / 2;
|
||||
int borderWidth = (this.Size.Width - this.ClientSize.Width) / 2;
|
||||
overlayLocation.X += borderWidth;
|
||||
overlayLocation.Y += (this.Size.Height - this.ClientSize.Height) - borderWidth;
|
||||
|
||||
this._isPositionChanged = false;
|
||||
this._overlay.Size = overlaySize;
|
||||
|
||||
Reference in New Issue
Block a user