From c56e173738204ce0974a45026dd533f0d01eebf1 Mon Sep 17 00:00:00 2001 From: Anton Kasyanov Date: Wed, 19 Oct 2016 23:42:43 +0300 Subject: [PATCH] Ensure that thumbnail borders do NOT overlap with the EVE client window image --- .../Presentation/ThumbnailManager.cs | 2 +- .../UI/Implementation/ThumbnailOverlay.cs | 30 +++++++++++----- .../UI/Implementation/ThumbnailView.cs | 34 +++++++++++++++++-- Eve-O-Preview/UI/Interface/IThumbnailView.cs | 2 +- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/Eve-O-Preview/Presentation/ThumbnailManager.cs b/Eve-O-Preview/Presentation/ThumbnailManager.cs index 1e813d4..5ba49e2 100644 --- a/Eve-O-Preview/Presentation/ThumbnailManager.cs +++ b/Eve-O-Preview/Presentation/ThumbnailManager.cs @@ -137,7 +137,7 @@ namespace EveOPreview.UI view.IsOverlayEnabled = this._configuration.ShowThumbnailOverlays; - view.SetHighlight(this._configuration.EnableActiveClientHighlight && (view.Id == this._activeClientHandle), this._configuration.ActiveClientHighlightColor); + view.SetHighlight(this._configuration.EnableActiveClientHighlight && (view.Id == this._activeClientHandle), this._configuration.ActiveClientHighlightColor, 3); if (!view.IsActive) { diff --git a/Eve-O-Preview/UI/Implementation/ThumbnailOverlay.cs b/Eve-O-Preview/UI/Implementation/ThumbnailOverlay.cs index 16b3f3d..8b507ae 100644 --- a/Eve-O-Preview/UI/Implementation/ThumbnailOverlay.cs +++ b/Eve-O-Preview/UI/Implementation/ThumbnailOverlay.cs @@ -8,8 +8,12 @@ namespace EveOPreview.UI { #region Private fields private readonly Action _areaClickAction; - private bool _highlightEnabled; + private bool _isHighlightEnabled; private Color _highlightColor; + private int _highlightWidthLeft; + private int _highlightWidthTop; + private int _highlightWidthRight; + private int _highlightWidthBottom; #endregion public ThumbnailOverlay(Form owner, Action areaClickAction) @@ -17,7 +21,7 @@ namespace EveOPreview.UI this.Owner = owner; this._areaClickAction = areaClickAction; - this._highlightEnabled = false; + this._isHighlightEnabled = false; this._highlightColor = Color.Red; InitializeComponent(); @@ -38,15 +42,23 @@ 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._highlightEnabled) + if (enabled == this._isHighlightEnabled) { // Nothing to do here return; } - this._highlightEnabled = enabled; + this._isHighlightEnabled = enabled; this._highlightColor = color; this.Refresh(); } @@ -65,13 +77,13 @@ namespace EveOPreview.UI { base.OnPaint(e); - if (this._highlightEnabled) + if (this._isHighlightEnabled) { ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, - this._highlightColor, 4, ButtonBorderStyle.Solid, - this._highlightColor, 4, ButtonBorderStyle.Solid, - this._highlightColor, 4, ButtonBorderStyle.Solid, - this._highlightColor, 4, ButtonBorderStyle.Solid); + this._highlightColor, this._highlightWidthLeft, ButtonBorderStyle.Solid, + this._highlightColor, this._highlightWidthTop, ButtonBorderStyle.Solid, + this._highlightColor, this._highlightWidthRight, ButtonBorderStyle.Solid, + this._highlightColor, this._highlightWidthBottom, ButtonBorderStyle.Solid); } } } diff --git a/Eve-O-Preview/UI/Implementation/ThumbnailView.cs b/Eve-O-Preview/UI/Implementation/ThumbnailView.cs index 1dc3da9..cde6534 100644 --- a/Eve-O-Preview/UI/Implementation/ThumbnailView.cs +++ b/Eve-O-Preview/UI/Implementation/ThumbnailView.cs @@ -18,6 +18,8 @@ namespace EveOPreview.UI private bool _isPositionChanged; private bool _isSizeChanged; private bool _isCustomMouseModeActive; + private bool _isHighlightEnabled; + private int _highlightWidth; private DateTime _suppressResizeEventsTimestamp; private DWM_THUMBNAIL_PROPERTIES _thumbnail; private IntPtr _thumbnailHandle; @@ -43,6 +45,8 @@ namespace EveOPreview.UI this._isSizeChanged = true; this._isCustomMouseModeActive = false; + this._isHighlightEnabled = false; + this._suppressResizeEventsTimestamp = DateTime.UtcNow; InitializeComponent(); @@ -197,8 +201,11 @@ namespace EveOPreview.UI this._isTopMost = enableTopmost; } - public void SetHighlight(bool enabled, Color color) + 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); } @@ -310,7 +317,30 @@ namespace EveOPreview.UI if (sizeChanged) { - this._thumbnail.rcDestination = new RECT(0, 0, this.ClientSize.Width, this.ClientSize.Height); + // This approach would work only for square-shaped thumbnail window + // To get PROPER results we have to do some crazy math + //int delta = this._isHighlightEnabled ? this._highlightWidth : 0; + //this._thumbnail.rcDestination = new RECT(0 + delta, 0 + delta, this.ClientSize.Width - delta, this.ClientSize.Height - delta); + if (this._isHighlightEnabled) + { + int baseWidth = this.ClientSize.Width; + int baseHeight = this.ClientSize.Height; + double baseAspectRatio = ((double)baseWidth) / baseHeight; + + int actualHeight = baseHeight - 2 * this._highlightWidth; + double desiredWidth = actualHeight * baseAspectRatio; + int actualWidth = (int)Math.Round(desiredWidth); + int highlightWidthLeft = Math.Min(5, (baseWidth - actualWidth) / 2); + int highlightWidthRight = Math.Min(5, 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); + } + else + { + //No highlighting enables, so no odd math required + this._thumbnail.rcDestination = new RECT(0, 0, this.ClientSize.Width, this.ClientSize.Height); + } try { WindowManagerNativeMethods.DwmUpdateThumbnailProperties(this._thumbnailHandle, this._thumbnail); diff --git a/Eve-O-Preview/UI/Interface/IThumbnailView.cs b/Eve-O-Preview/UI/Interface/IThumbnailView.cs index 21b5cfd..20f5b41 100644 --- a/Eve-O-Preview/UI/Interface/IThumbnailView.cs +++ b/Eve-O-Preview/UI/Interface/IThumbnailView.cs @@ -21,7 +21,7 @@ namespace EveOPreview.UI void SetOpacity(double opacity); void SetFrames(bool enable); void SetTopMost(bool enableTopmost); - void SetHighlight(bool enabled, Color color); + void SetHighlight(bool enabled, Color color, int width); void ZoomIn(ViewZoomAnchor anchor, int zoomFactor); void ZoomOut();