From 68d8082c17f57fc06f4ef02b4aff1498fe7d6dee Mon Sep 17 00:00:00 2001 From: Greenshot-AppVeyor Date: Sun, 26 Apr 2020 13:58:05 +0200 Subject: [PATCH] Propagate DPI Changes down to Drawable Containers and Adorners and Resize Grippers Accordingly --- Greenshot/Drawing/Adorners/AbstractAdorner.cs | 13 ++++++++++++- Greenshot/Drawing/DrawableContainer.cs | 12 ++++++++++++ Greenshot/Drawing/DrawableContainerList.cs | 13 ++++++++++++- Greenshot/Drawing/Surface.cs | 11 +++++++++++ Greenshot/Forms/ImageEditorForm.cs | 2 ++ .../Interfaces/Drawing/Adorners/IAdorner.cs | 6 ++++++ GreenshotPlugin/Interfaces/Drawing/Container.cs | 7 +++++++ 7 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Greenshot/Drawing/Adorners/AbstractAdorner.cs b/Greenshot/Drawing/Adorners/AbstractAdorner.cs index 0612753aa..ff5556368 100644 --- a/Greenshot/Drawing/Adorners/AbstractAdorner.cs +++ b/Greenshot/Drawing/Adorners/AbstractAdorner.cs @@ -22,6 +22,7 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +using GreenshotPlugin.Core; using GreenshotPlugin.Interfaces.Drawing; using GreenshotPlugin.Interfaces.Drawing.Adorners; @@ -31,7 +32,8 @@ namespace Greenshot.Drawing.Adorners { public virtual EditStatus EditStatus { get; protected set; } = EditStatus.IDLE; - protected Size _size = new Size(4, 4); + private static readonly Size defaultSize = new Size(4, 4); + protected Size _size = defaultSize; public AbstractAdorner(IDrawableContainer owner) { @@ -127,6 +129,15 @@ namespace Greenshot.Drawing.Adorners } } + /// + /// Adjust UI elements to the supplied DPI settings + /// + /// + public void AdjustToDpi(uint dpi) + { + _size = DpiHelper.ScaleWithDpi(defaultSize, dpi); + } + /// /// Draw the adorner /// diff --git a/Greenshot/Drawing/DrawableContainer.cs b/Greenshot/Drawing/DrawableContainer.cs index 8d805b1f0..0749805d4 100644 --- a/Greenshot/Drawing/DrawableContainer.cs +++ b/Greenshot/Drawing/DrawableContainer.cs @@ -397,6 +397,18 @@ namespace Greenshot.Drawing Draw(graphics, renderMode); } + /// + /// Adjust UI elements to the supplied DPI settings + /// + /// + public void AdjustToDpi(uint dpi) + { + foreach(var adorner in Adorners) + { + adorner.AdjustToDpi(dpi); + } + } + public virtual bool Contains(int x, int y) { return Bounds.Contains(x , y); } diff --git a/Greenshot/Drawing/DrawableContainerList.cs b/Greenshot/Drawing/DrawableContainerList.cs index d3c325f5b..8d04238f2 100644 --- a/Greenshot/Drawing/DrawableContainerList.cs +++ b/Greenshot/Drawing/DrawableContainerList.cs @@ -581,5 +581,16 @@ namespace Greenshot.Drawing { // Do not change this code. Put cleanup code in Dispose(bool disposing) above. Dispose(true); } - } + + /// + /// Adjust UI elements to the supplied DPI settings + /// + /// + public void AdjustToDpi(uint dpi) + { + foreach (var drawableContainer in this) { + drawableContainer.AdjustToDpi(dpi); + } + } + } } diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index bd56db3a2..efc018c1e 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -403,6 +403,17 @@ namespace Greenshot.Drawing /// public ICaptureDetails CaptureDetails { get; set; } + /// + /// Adjust UI elements to the supplied DPI settings + /// + /// + public void AdjustToDpi(uint dpi) + { + foreach (var element in this._elements) { + element.AdjustToDpi(dpi); + } + } + /// /// Base Surface constructor /// diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index bcb8c275c..b6ca89679 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -96,6 +96,8 @@ namespace Greenshot { destinationsToolStrip.ImageScalingSize = newSize; propertiesToolStrip.ImageScalingSize = newSize; propertiesToolStrip.MinimumSize = new Size(150, newSize.Height + 10); + + _surface.AdjustToDpi(dpi); } public ImageEditorForm(ISurface iSurface, bool outputMade) diff --git a/GreenshotPlugin/Interfaces/Drawing/Adorners/IAdorner.cs b/GreenshotPlugin/Interfaces/Drawing/Adorners/IAdorner.cs index e35af2141..b8e087101 100644 --- a/GreenshotPlugin/Interfaces/Drawing/Adorners/IAdorner.cs +++ b/GreenshotPlugin/Interfaces/Drawing/Adorners/IAdorner.cs @@ -87,5 +87,11 @@ namespace GreenshotPlugin.Interfaces.Drawing.Adorners /// /// Matrix void Transform(Matrix matrix); + + /// + /// Adjust UI elements to the supplied DPI settings + /// + /// + void AdjustToDpi(uint dpi); } } diff --git a/GreenshotPlugin/Interfaces/Drawing/Container.cs b/GreenshotPlugin/Interfaces/Drawing/Container.cs index b2b6e3d19..6fd0df7fa 100644 --- a/GreenshotPlugin/Interfaces/Drawing/Container.cs +++ b/GreenshotPlugin/Interfaces/Drawing/Container.cs @@ -121,6 +121,12 @@ namespace GreenshotPlugin.Interfaces.Drawing /// Available adorners for the DrawableContainer /// IList Adorners { get; } + + /// + /// Adjust UI elements to the supplied DPI settings + /// + /// + void AdjustToDpi(uint dpi); } public interface IDrawableContainerList : IList, IDisposable @@ -164,6 +170,7 @@ namespace GreenshotPlugin.Interfaces.Drawing void PushElementsToBottom(IDrawableContainerList elements); void ShowContextMenu(MouseEventArgs e, ISurface surface); void HandleFieldChangedEvent(object sender, FieldChangedEventArgs e); + void AdjustToDpi(uint dpi); } public interface ITextContainer : IDrawableContainer