Thumbnail overlays are broken

This commit is contained in:
Anton Kasyanov
2016-06-06 22:23:30 +03:00
parent 4dfd195537
commit 8d57acb900
2 changed files with 39 additions and 27 deletions

View File

@@ -136,6 +136,10 @@ namespace EveOPreview.UI
{ {
view.Show(); view.Show();
} }
else
{
view.Refresh();
}
} }
this.EnableViewEvents(); this.EnableViewEvents();

View File

@@ -18,12 +18,11 @@ namespace EveOPreview.UI
// Just somewhat more complex than usual // Just somewhat more complex than usual
private bool _isThumbnailSetUp; private bool _isThumbnailSetUp;
private bool _isTopMost; private bool _isTopMost;
private bool _isOverlayVisible;
private bool _isPositionChanged;
private bool _isSizeChanged;
private DWM_THUMBNAIL_PROPERTIES _Thumbnail; private DWM_THUMBNAIL_PROPERTIES _Thumbnail;
private IntPtr _ThumbnailHandle; private IntPtr _ThumbnailHandle;
private int _currentWidth;
private int _currentHeight;
private int _currentTop;
private int _currentLeft;
#endregion #endregion
public ThumbnailView() public ThumbnailView()
@@ -34,11 +33,10 @@ namespace EveOPreview.UI
this.IsOverlayEnabled = false; this.IsOverlayEnabled = false;
this._isThumbnailSetUp = false; this._isThumbnailSetUp = false;
this._isTopMost = false; this._isTopMost = false;
this._isOverlayVisible = false;
this._currentWidth = -1; this._isPositionChanged = true;
this._currentHeight = -1; this._isSizeChanged = true;
this._currentTop = -1;
this._currentLeft = -1;
InitializeComponent(); InitializeComponent();
@@ -96,15 +94,6 @@ namespace EveOPreview.UI
{ {
base.Show(); base.Show();
if (this.IsOverlayEnabled)
{
this._overlay.Show();
}
else
{
this._overlay.Hide();
}
this.Refresh(); this.Refresh();
this.IsActive = true; this.IsActive = true;
@@ -146,6 +135,9 @@ namespace EveOPreview.UI
public void SetWindowFrames(bool enable) public void SetWindowFrames(bool enable)
{ {
this.FormBorderStyle = enable ? FormBorderStyle.SizableToolWindow : FormBorderStyle.None; this.FormBorderStyle = enable ? FormBorderStyle.SizableToolWindow : FormBorderStyle.None;
// Notify about windo contents position change
this._isSizeChanged = true;
} }
public void SetTopMost(bool enableTopmost) public void SetTopMost(bool enableTopmost)
@@ -156,6 +148,7 @@ namespace EveOPreview.UI
} }
this.TopMost = enableTopmost; this.TopMost = enableTopmost;
this._overlay.TopMost = enableTopmost;
this._isTopMost = enableTopmost; this._isTopMost = enableTopmost;
} }
@@ -166,15 +159,12 @@ namespace EveOPreview.UI
this.InitializeThumbnail(); this.InitializeThumbnail();
} }
bool sizeChanged = (this._currentWidth != this.ClientRectangle.Right) || (this._currentHeight != this.ClientRectangle.Bottom); bool sizeChanged = this._isSizeChanged;
bool locationChanged = (this._currentLeft != this.Location.X) || (this._currentTop != this.Location.Y); bool locationChanged = this._isPositionChanged;
if (sizeChanged) if (sizeChanged)
{ {
this._currentWidth = this.ClientRectangle.Right; this._Thumbnail.rcDestination = new RECT(0, 0, this.ClientRectangle.Right, this.ClientRectangle.Bottom);
this._currentHeight = this.ClientRectangle.Bottom;
this._Thumbnail.rcDestination = new RECT(0, 0, this._currentWidth, this._currentHeight);
try try
{ {
DwmApiNativeMethods.DwmUpdateThumbnailProperties(this._ThumbnailHandle, this._Thumbnail); DwmApiNativeMethods.DwmUpdateThumbnailProperties(this._ThumbnailHandle, this._Thumbnail);
@@ -183,10 +173,28 @@ namespace EveOPreview.UI
{ {
//This exception will be thrown if the EVE client disappears while this method is running //This exception will be thrown if the EVE client disappears while this method is running
} }
this._isSizeChanged = false;
} }
if (!(this.IsOverlayEnabled && (sizeChanged || locationChanged))) if (!this.IsOverlayEnabled)
{ {
if (this._isOverlayVisible)
{
this._overlay.Hide();
this._isOverlayVisible = false;
}
return;
}
if (!this._isOverlayVisible)
{
this._overlay.Show();
this._isOverlayVisible = true;
}
else if (!(sizeChanged || locationChanged))
{
// No need to adjust in the overlay location if it is already visible and properly set
return; return;
} }
@@ -196,12 +204,10 @@ namespace EveOPreview.UI
Point overlayLocation = this.Location; Point overlayLocation = this.Location;
this._currentLeft = overlayLocation.X;
this._currentTop = overlayLocation.Y;
overlayLocation.X += 5 + (this.Size.Width - this.RenderAreaPictureBox.Size.Width) / 2; overlayLocation.X += 5 + (this.Size.Width - this.RenderAreaPictureBox.Size.Width) / 2;
overlayLocation.Y += 5 + (this.Size.Height - this.RenderAreaPictureBox.Size.Height) - (this.Size.Width - this.RenderAreaPictureBox.Size.Width) / 2; overlayLocation.Y += 5 + (this.Size.Height - this.RenderAreaPictureBox.Size.Height) - (this.Size.Width - this.RenderAreaPictureBox.Size.Width) / 2;
this._isPositionChanged = false;
this._overlay.Size = overlaySize; this._overlay.Size = overlaySize;
this._overlay.Location = overlayLocation; this._overlay.Location = overlayLocation;
} }
@@ -219,11 +225,13 @@ namespace EveOPreview.UI
private void Move_Handler(object sender, EventArgs e) private void Move_Handler(object sender, EventArgs e)
{ {
this._isPositionChanged = true;
this.ThumbnailMoved?.Invoke(this.Id); this.ThumbnailMoved?.Invoke(this.Id);
} }
private void Resize_Handler(object sender, EventArgs e) private void Resize_Handler(object sender, EventArgs e)
{ {
this._isSizeChanged = true;
this.ThumbnailResized?.Invoke(this.Id); this.ThumbnailResized?.Invoke(this.Id);
} }