diff --git a/Eve-O-Preview/Presentation/ThumbnailManager.cs b/Eve-O-Preview/Presentation/ThumbnailManager.cs index 667d931..414bb03 100644 --- a/Eve-O-Preview/Presentation/ThumbnailManager.cs +++ b/Eve-O-Preview/Presentation/ThumbnailManager.cs @@ -84,7 +84,7 @@ namespace EveOPreview.UI foreach (KeyValuePair entry in this._thumbnailViews) { - entry.Value.Size = size; + entry.Value.ThumbnailSize = size; entry.Value.Refresh(false); } @@ -126,7 +126,7 @@ namespace EveOPreview.UI if (!this._isHoverEffectActive) { // No need to move Thumbnails while one of them is highlighted - view.Location = this._configuration.GetThumbnailLocation(view.Title, this._activeClientTitle, view.Location); + view.ThumbnailLocation = this._configuration.GetThumbnailLocation(view.Title, this._activeClientTitle, view.ThumbnailLocation); view.SetOpacity(this._configuration.ThumbnailsOpacity); view.SetTopMost(this._configuration.ShowThumbnailsAlwaysOnTop); } @@ -152,7 +152,7 @@ namespace EveOPreview.UI foreach (KeyValuePair entry in this._thumbnailViews) { - entry.Value.SetWindowFrames(this._configuration.ShowThumbnailFrames); + entry.Value.SetFrames(this._configuration.ShowThumbnailFrames); } this.EnableViewEvents(); @@ -206,8 +206,8 @@ namespace EveOPreview.UI view.IsOverlayEnabled = this._configuration.ShowThumbnailOverlays; view.SetSizeLimitations(this._configuration.ThumbnailMinimumSize, this._configuration.ThumbnailMaximumSize); view.SetTopMost(this._configuration.ShowThumbnailsAlwaysOnTop); - view.SetWindowFrames(this._configuration.ShowThumbnailFrames); - view.Location = this._configuration.GetThumbnailLocation(processTitle, this._activeClientTitle, view.Location); + view.SetFrames(this._configuration.ShowThumbnailFrames); + view.ThumbnailLocation = this._configuration.GetThumbnailLocation(processTitle, this._activeClientTitle, view.ThumbnailLocation); view.ThumbnailResized = this.ThumbnailViewResized; view.ThumbnailMoved = this.ThumbnailViewMoved; @@ -349,7 +349,7 @@ namespace EveOPreview.UI IThumbnailView view = this._thumbnailViews[id]; - this.SetThumbnailsSize(view.Size); + this.SetThumbnailsSize(view.ThumbnailSize); view.Refresh(false); } @@ -363,7 +363,7 @@ namespace EveOPreview.UI IThumbnailView view = this._thumbnailViews[id]; - this._configuration.SetThumbnailLocation(view.Title, this._activeClientTitle, view.Location); + this._configuration.SetThumbnailLocation(view.Title, this._activeClientTitle, view.ThumbnailLocation); view.Refresh(false); } diff --git a/Eve-O-Preview/UI/Factory/ThumbnailViewFactory.cs b/Eve-O-Preview/UI/Factory/ThumbnailViewFactory.cs index 0163555..986e3d2 100644 --- a/Eve-O-Preview/UI/Factory/ThumbnailViewFactory.cs +++ b/Eve-O-Preview/UI/Factory/ThumbnailViewFactory.cs @@ -18,7 +18,7 @@ namespace EveOPreview.UI view.Id = id; view.Title = title; - view.Size = size; + view.ThumbnailSize = size; return view; } diff --git a/Eve-O-Preview/UI/Implementation/ThumbnailView.Designer.cs b/Eve-O-Preview/UI/Implementation/ThumbnailView.Designer.cs index d0de14f..c8680f3 100644 --- a/Eve-O-Preview/UI/Implementation/ThumbnailView.Designer.cs +++ b/Eve-O-Preview/UI/Implementation/ThumbnailView.Designer.cs @@ -14,27 +14,8 @@ namespace EveOPreview.UI /// private void InitializeComponent() { - this.RenderAreaPictureBox = new System.Windows.Forms.PictureBox(); - ((System.ComponentModel.ISupportInitialize)(this.RenderAreaPictureBox)).BeginInit(); this.SuspendLayout(); // - // RenderAreaPictureBox - // - this.RenderAreaPictureBox.BackColor = System.Drawing.Color.Transparent; - this.RenderAreaPictureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; - this.RenderAreaPictureBox.Cursor = System.Windows.Forms.Cursors.Hand; - this.RenderAreaPictureBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.RenderAreaPictureBox.Location = new System.Drawing.Point(0, 0); - this.RenderAreaPictureBox.Margin = new System.Windows.Forms.Padding(0); - this.RenderAreaPictureBox.Name = "RenderAreaPictureBox"; - this.RenderAreaPictureBox.Size = new System.Drawing.Size(153, 89); - this.RenderAreaPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.RenderAreaPictureBox.TabIndex = 0; - this.RenderAreaPictureBox.TabStop = false; - this.RenderAreaPictureBox.MouseLeave += new System.EventHandler(this.LostFocus_Handler); - this.RenderAreaPictureBox.MouseHover += new System.EventHandler(this.Focused_Handler); - this.RenderAreaPictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ThumbnailActivated_Handler); - // // ThumbnailView // this.AccessibleRole = System.Windows.Forms.AccessibleRole.None; @@ -42,7 +23,6 @@ namespace EveOPreview.UI this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(153, 89); this.ControlBox = false; - this.Controls.Add(this.RenderAreaPictureBox); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; this.MaximizeBox = false; this.MinimizeBox = false; @@ -53,18 +33,17 @@ namespace EveOPreview.UI this.ShowInTaskbar = false; this.Text = "Preview"; this.TopMost = true; + this.MouseLeave += new System.EventHandler(this.LostFocus_Handler); + this.MouseHover += new System.EventHandler(this.Focused_Handler); + this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ThumbnailActivated_Handler); this.Move += new System.EventHandler(this.Move_Handler); this.Resize += new System.EventHandler(this.Resize_Handler); - ((System.ComponentModel.ISupportInitialize)(this.RenderAreaPictureBox)).EndInit(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - private System.Windows.Forms.PictureBox RenderAreaPictureBox; - } } \ No newline at end of file diff --git a/Eve-O-Preview/UI/Implementation/ThumbnailView.cs b/Eve-O-Preview/UI/Implementation/ThumbnailView.cs index a8d0c0d..5a99a01 100644 --- a/Eve-O-Preview/UI/Implementation/ThumbnailView.cs +++ b/Eve-O-Preview/UI/Implementation/ThumbnailView.cs @@ -12,15 +12,13 @@ namespace EveOPreview.UI //private readonly IThumbnailManager _manager; private readonly ThumbnailOverlay _overlay; - //private Size _baseSize; - //private Point _basePosition; - // This is pure brainless View // Just somewhat more complex than usual private bool _isThumbnailSetUp; private bool _isOverlayVisible; private bool _isPositionChanged; private bool _isSizeChanged; + private DateTime _suppressResizeEventsTimestamp; private DWM_THUMBNAIL_PROPERTIES _thumbnail; private IntPtr _thumbnailHandle; private Size _baseSize; @@ -40,6 +38,8 @@ namespace EveOPreview.UI this._isPositionChanged = true; this._isSizeChanged = true; + this._suppressResizeEventsTimestamp = DateTime.UtcNow; + InitializeComponent(); this._overlay = new ThumbnailOverlay(this, this.ThumbnailActivated_Handler); @@ -66,11 +66,11 @@ namespace EveOPreview.UI public bool IsOverlayEnabled { get; set; } - public new Point Location + public Point ThumbnailLocation { get { - return base.Location; + return this.Location; } set { @@ -78,7 +78,19 @@ namespace EveOPreview.UI { this.StartPosition = FormStartPosition.Manual; } - base.Location = value; + this.Location = value; + } + } + + public Size ThumbnailSize + { + get + { + return this.ClientSize; + } + set + { + this.ClientSize = value; } } @@ -137,11 +149,14 @@ namespace EveOPreview.UI this.Opacity = opacity; } - public void SetWindowFrames(bool enable) + public void SetFrames(bool enable) { + // Fix for WinForms issue with the Resize event being fired with inconsistent ClientSize value + // Any Resize events fired before this timestamp will be ignored + this._suppressResizeEventsTimestamp = DateTime.UtcNow.AddMilliseconds(450); this.FormBorderStyle = enable ? FormBorderStyle.SizableToolWindow : FormBorderStyle.None; - // Notify about windo contents position change + // Notify about possible contents position change this._isSizeChanged = true; } @@ -226,11 +241,9 @@ namespace EveOPreview.UI try { this._hotkeyHandler.Register(); - System.Diagnostics.Debug.WriteLine("Registered shortcut for " + this.Title); } catch (Exception) { - System.Diagnostics.Debug.WriteLine("Failed to register shortcut for " + this.Title); // There can be a lot of possible exception reasons here // In case of any of them the hotkey setting is silently ignored } @@ -265,7 +278,7 @@ namespace EveOPreview.UI if (sizeChanged) { - this._thumbnail.rcDestination = new RECT(0, 0, this.ClientRectangle.Right, this.ClientRectangle.Bottom); + this._thumbnail.rcDestination = new RECT(0, 0, this.ClientSize.Width, this.ClientSize.Height); try { DwmApiNativeMethods.DwmUpdateThumbnailProperties(this._thumbnailHandle, this._thumbnail); @@ -304,14 +317,14 @@ namespace EveOPreview.UI return; } - Size overlaySize = this.RenderAreaPictureBox.Size; + Size overlaySize = this.ClientSize; overlaySize.Width -= 2 * 5; overlaySize.Height -= 2 * 5; Point overlayLocation = this.Location; - 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.X += 5 + (this.Size.Width - this.ClientSize.Width) / 2; + overlayLocation.Y += 5 + (this.Size.Height - this.ClientSize.Height) - (this.Size.Width - this.ClientSize.Width) / 2; this._isPositionChanged = false; this._overlay.Size = overlaySize; @@ -337,7 +350,13 @@ namespace EveOPreview.UI private void Resize_Handler(object sender, EventArgs e) { + if (DateTime.UtcNow < this._suppressResizeEventsTimestamp) + { + return; + } + this._isSizeChanged = true; + this.ThumbnailResized?.Invoke(this.Id); } @@ -365,9 +384,9 @@ namespace EveOPreview.UI //if (e.Button == MouseButtons.Middle) //{ - //// Trigger full thumbnail refresh - //this.UnregisterThumbnail(); - //this.Refresh(); + //// Trigger full thumbnail refresh + //this.UnregisterThumbnail(); + //this.Refresh(); //} } diff --git a/Eve-O-Preview/UI/Interface/IThumbnailView.cs b/Eve-O-Preview/UI/Interface/IThumbnailView.cs index b371fc7..1034160 100644 --- a/Eve-O-Preview/UI/Interface/IThumbnailView.cs +++ b/Eve-O-Preview/UI/Interface/IThumbnailView.cs @@ -11,15 +11,15 @@ namespace EveOPreview.UI bool IsEnabled { get; set; } bool IsActive { get; set; } - Point Location { get; set; } - Size Size { get; set; } + Point ThumbnailLocation { get; set; } + Size ThumbnailSize { get; set; } bool IsOverlayEnabled { get; set; } bool IsKnownHandle(IntPtr handle); void SetSizeLimitations(Size minimumSize, Size maximumSize); void SetOpacity(double opacity); - void SetWindowFrames(bool enable); + void SetFrames(bool enable); void SetTopMost(bool enableTopmost); void ZoomIn(ViewZoomAnchor anchor, int zoomFactor);