Propagate DPI Changes down to Drawable Containers and Adorners and Resize Grippers Accordingly (#200)

* Propagate DPI Changes down to Drawable Containers and Adorners and Resize Grippers Accordingly
* Make Grippers Slightly Larger
* Add White Border to Grippers for Better Contrast on Dark Backgrounds
This commit is contained in:
jklingen 2020-08-06 21:29:55 +02:00 committed by GitHub
parent 926855cd70
commit f159a871ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 185 additions and 128 deletions

View file

@ -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(6, 6);
protected Size _size = defaultSize;
public AbstractAdorner(IDrawableContainer owner)
{
@ -139,6 +141,15 @@ namespace Greenshot.Drawing.Adorners
}
}
/// <summary>
/// Adjust UI elements to the supplied DPI settings
/// </summary>
/// <param name="dpi"></param>
public void AdjustToDpi(uint dpi)
{
_size = DpiHelper.ScaleWithDpi(defaultSize, dpi);
}
/// <summary>
/// Draw the adorner
/// </summary>

View file

@ -145,14 +145,12 @@ namespace Greenshot.Drawing.Adorners
var bounds = BoundsOnSurface;
GraphicsState state = targetGraphics.Save();
targetGraphics.SmoothingMode = SmoothingMode.None;
targetGraphics.CompositingMode = CompositingMode.SourceCopy;
targetGraphics.PixelOffsetMode = PixelOffsetMode.Half;
targetGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
try
{
targetGraphics.FillRectangle(Brushes.Black, bounds.X, bounds.Y, bounds.Width, bounds.Height);
targetGraphics.FillRectangle(Brushes.Black, bounds);
targetGraphics.DrawRectangle(new Pen(Brushes.White), bounds);
}
catch
{

View file

@ -172,12 +172,10 @@ namespace Greenshot.Drawing.Adorners
var bounds = BoundsOnSurface;
GraphicsState state = targetGraphics.Save();
targetGraphics.SmoothingMode = SmoothingMode.None;
targetGraphics.CompositingMode = CompositingMode.SourceCopy;
targetGraphics.PixelOffsetMode = PixelOffsetMode.Half;
targetGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
targetGraphics.FillRectangle(Brushes.Black, bounds.X, bounds.Y, bounds.Width , bounds.Height);
targetGraphics.FillRectangle(Brushes.Black, bounds);
targetGraphics.DrawRectangle(new Pen(Brushes.White), bounds);
targetGraphics.Restore(state);
}
}

View file

@ -97,7 +97,8 @@ namespace Greenshot.Drawing.Adorners
Graphics targetGraphics = paintEventArgs.Graphics;
var bounds = BoundsOnSurface;
targetGraphics.FillRectangle(Brushes.Green, bounds.X, bounds.Y, bounds.Width, bounds.Height);
targetGraphics.FillRectangle(Brushes.Green, bounds);
targetGraphics.DrawRectangle(new Pen(Brushes.White), bounds);
}
/// <summary>

View file

@ -369,6 +369,18 @@ namespace Greenshot.Drawing
Draw(graphics, renderMode);
}
/// <summary>
/// Adjust UI elements to the supplied DPI settings
/// </summary>
/// <param name="dpi"></param>
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);
}

View file

@ -604,5 +604,16 @@ namespace Greenshot.Drawing {
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(true);
}
}
/// <summary>
/// Adjust UI elements to the supplied DPI settings
/// </summary>
/// <param name="dpi"></param>
public void AdjustToDpi(uint dpi)
{
foreach (var drawableContainer in this) {
drawableContainer.AdjustToDpi(dpi);
}
}
}
}

View file

@ -432,6 +432,17 @@ namespace Greenshot.Drawing
/// </summary>
public ICaptureDetails CaptureDetails { get; set; }
/// <summary>
/// Adjust UI elements to the supplied DPI settings
/// </summary>
/// <param name="dpi"></param>
public void AdjustToDpi(uint dpi)
{
foreach (var element in this._elements) {
element.AdjustToDpi(dpi);
}
}
/// <summary>
/// Base Surface constructor
/// </summary>

View file

@ -101,6 +101,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)

View file

@ -87,5 +87,11 @@ namespace GreenshotPlugin.Interfaces.Drawing.Adorners
/// </summary>
/// <param name="matrix">Matrix</param>
void Transform(Matrix matrix);
/// <summary>
/// Adjust UI elements to the supplied DPI settings
/// </summary>
/// <param name="dpi"></param>
void AdjustToDpi(uint dpi);
}
}

View file

@ -120,6 +120,12 @@ namespace GreenshotPlugin.Interfaces.Drawing
/// Available adorners for the DrawableContainer
/// </summary>
IList<IAdorner> Adorners { get; }
/// <summary>
/// Adjust UI elements to the supplied DPI settings
/// </summary>
/// <param name="dpi"></param>
void AdjustToDpi(uint dpi);
}
public interface IDrawableContainerList : IList<IDrawableContainer>, IDisposable
@ -167,6 +173,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