mirror of
https://github.com/greenshot/greenshot
synced 2025-07-31 04:00:13 -07:00
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:
parent
926855cd70
commit
f159a871ca
10 changed files with 185 additions and 128 deletions
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,118 +1,119 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using GreenshotPlugin.Interfaces.Drawing;
|
||||
|
||||
namespace Greenshot.Drawing.Adorners
|
||||
{
|
||||
/// <summary>
|
||||
/// This implements the special "gripper" for the Speech-Bubble tail
|
||||
/// </summary>
|
||||
public class TargetAdorner : AbstractAdorner
|
||||
{
|
||||
|
||||
public TargetAdorner(IDrawableContainer owner, Point location) : base(owner)
|
||||
{
|
||||
Location = location;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the mouse down
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="mouseEventArgs"></param>
|
||||
public override void MouseDown(object sender, MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
EditStatus = EditStatus.MOVING;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the mouse move
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="mouseEventArgs"></param>
|
||||
public override void MouseMove(object sender, MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
if (EditStatus != EditStatus.MOVING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.Invalidate();
|
||||
Point newGripperLocation = new Point(mouseEventArgs.X, mouseEventArgs.Y);
|
||||
Rectangle imageBounds = new Rectangle(0, 0, Owner.Parent.Image.Width, Owner.Parent.Image.Height);
|
||||
// Check if gripper inside the parent (surface), if not we need to move it inside
|
||||
// This was made for BUG-1682
|
||||
if (!imageBounds.Contains(newGripperLocation))
|
||||
{
|
||||
if (newGripperLocation.X > imageBounds.Right)
|
||||
{
|
||||
newGripperLocation.X = imageBounds.Right - 5;
|
||||
}
|
||||
if (newGripperLocation.X < imageBounds.Left)
|
||||
{
|
||||
newGripperLocation.X = imageBounds.Left;
|
||||
}
|
||||
if (newGripperLocation.Y > imageBounds.Bottom)
|
||||
{
|
||||
newGripperLocation.Y = imageBounds.Bottom - 5;
|
||||
}
|
||||
if (newGripperLocation.Y < imageBounds.Top)
|
||||
{
|
||||
newGripperLocation.Y = imageBounds.Top;
|
||||
}
|
||||
}
|
||||
|
||||
Location = newGripperLocation;
|
||||
Owner.Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the adorner
|
||||
/// </summary>
|
||||
/// <param name="paintEventArgs">PaintEventArgs</param>
|
||||
public override void Paint(PaintEventArgs paintEventArgs)
|
||||
{
|
||||
Graphics targetGraphics = paintEventArgs.Graphics;
|
||||
|
||||
var bounds = BoundsOnSurface;
|
||||
targetGraphics.FillRectangle(Brushes.Green, bounds.X, bounds.Y, bounds.Width, bounds.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Made sure this adorner is transformed
|
||||
/// </summary>
|
||||
/// <param name="matrix">Matrix</param>
|
||||
public override void Transform(Matrix matrix)
|
||||
{
|
||||
if (matrix == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Point[] points = new[] { Location };
|
||||
matrix.TransformPoints(points);
|
||||
Location = points[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using GreenshotPlugin.Interfaces.Drawing;
|
||||
|
||||
namespace Greenshot.Drawing.Adorners
|
||||
{
|
||||
/// <summary>
|
||||
/// This implements the special "gripper" for the Speech-Bubble tail
|
||||
/// </summary>
|
||||
public class TargetAdorner : AbstractAdorner
|
||||
{
|
||||
|
||||
public TargetAdorner(IDrawableContainer owner, Point location) : base(owner)
|
||||
{
|
||||
Location = location;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the mouse down
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="mouseEventArgs"></param>
|
||||
public override void MouseDown(object sender, MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
EditStatus = EditStatus.MOVING;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the mouse move
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="mouseEventArgs"></param>
|
||||
public override void MouseMove(object sender, MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
if (EditStatus != EditStatus.MOVING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.Invalidate();
|
||||
Point newGripperLocation = new Point(mouseEventArgs.X, mouseEventArgs.Y);
|
||||
Rectangle imageBounds = new Rectangle(0, 0, Owner.Parent.Image.Width, Owner.Parent.Image.Height);
|
||||
// Check if gripper inside the parent (surface), if not we need to move it inside
|
||||
// This was made for BUG-1682
|
||||
if (!imageBounds.Contains(newGripperLocation))
|
||||
{
|
||||
if (newGripperLocation.X > imageBounds.Right)
|
||||
{
|
||||
newGripperLocation.X = imageBounds.Right - 5;
|
||||
}
|
||||
if (newGripperLocation.X < imageBounds.Left)
|
||||
{
|
||||
newGripperLocation.X = imageBounds.Left;
|
||||
}
|
||||
if (newGripperLocation.Y > imageBounds.Bottom)
|
||||
{
|
||||
newGripperLocation.Y = imageBounds.Bottom - 5;
|
||||
}
|
||||
if (newGripperLocation.Y < imageBounds.Top)
|
||||
{
|
||||
newGripperLocation.Y = imageBounds.Top;
|
||||
}
|
||||
}
|
||||
|
||||
Location = newGripperLocation;
|
||||
Owner.Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the adorner
|
||||
/// </summary>
|
||||
/// <param name="paintEventArgs">PaintEventArgs</param>
|
||||
public override void Paint(PaintEventArgs paintEventArgs)
|
||||
{
|
||||
Graphics targetGraphics = paintEventArgs.Graphics;
|
||||
|
||||
var bounds = BoundsOnSurface;
|
||||
targetGraphics.FillRectangle(Brushes.Green, bounds);
|
||||
targetGraphics.DrawRectangle(new Pen(Brushes.White), bounds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Made sure this adorner is transformed
|
||||
/// </summary>
|
||||
/// <param name="matrix">Matrix</param>
|
||||
public override void Transform(Matrix matrix)
|
||||
{
|
||||
if (matrix == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Point[] points = new[] { Location };
|
||||
matrix.TransformPoints(points);
|
||||
Location = points[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue