Fixed two issues with the adorner resize, sometime the initial value wasn't set and also there were some drawing artifacts. Still needs testing though.

This commit is contained in:
Robin Krom 2020-08-06 22:00:59 +02:00
parent f159a871ca
commit 63a9df5844
5 changed files with 42 additions and 35 deletions

View file

@ -1,20 +1,20 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* *
* For more information see: http://getgreenshot.org/ * For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or * the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -32,11 +32,12 @@ namespace Greenshot.Drawing.Adorners
{ {
public virtual EditStatus EditStatus { get; protected set; } = EditStatus.IDLE; public virtual EditStatus EditStatus { get; protected set; } = EditStatus.IDLE;
private static readonly Size defaultSize = new Size(6, 6); private static readonly Size DefaultSize = new Size(6, 6);
protected Size _size = defaultSize; protected Size _size;
public AbstractAdorner(IDrawableContainer owner) public AbstractAdorner(IDrawableContainer owner)
{ {
_size = DpiHelper.ScaleWithDpi(DefaultSize, 0);
Owner = owner; Owner = owner;
} }
@ -144,10 +145,10 @@ namespace Greenshot.Drawing.Adorners
/// <summary> /// <summary>
/// Adjust UI elements to the supplied DPI settings /// Adjust UI elements to the supplied DPI settings
/// </summary> /// </summary>
/// <param name="dpi"></param> /// <param name="dpi">uint</param>
public void AdjustToDpi(uint dpi) public void AdjustToDpi(uint dpi)
{ {
_size = DpiHelper.ScaleWithDpi(defaultSize, dpi); _size = DpiHelper.ScaleWithDpi(DefaultSize, dpi);
} }
/// <summary> /// <summary>

View file

@ -32,6 +32,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using GreenshotPlugin.IniFile; using GreenshotPlugin.IniFile;
using GreenshotPlugin.Interfaces; using GreenshotPlugin.Interfaces;
@ -205,10 +206,8 @@ namespace Greenshot.Drawing
} }
public Size Size { public Size Size {
get { get => new Size(width, height);
return new Size(width, height); set {
}
set {
width = value.Width; width = value.Width;
height = value.Height; height = value.Height;
} }
@ -219,15 +218,9 @@ namespace Greenshot.Drawing
/// </summary> /// </summary>
[NonSerialized] [NonSerialized]
private IList<IAdorner> _adorners = new List<IAdorner>(); private IList<IAdorner> _adorners = new List<IAdorner>();
public IList<IAdorner> Adorners public IList<IAdorner> Adorners => _adorners;
{
get
{
return _adorners;
}
}
[NonSerialized] [NonSerialized]
// will store current bounds of this DrawableContainer before starting a resize // will store current bounds of this DrawableContainer before starting a resize
protected Rectangle _boundsBeforeResize = Rectangle.Empty; protected Rectangle _boundsBeforeResize = Rectangle.Empty;
@ -236,8 +229,8 @@ namespace Greenshot.Drawing
protected RectangleF _boundsAfterResize = RectangleF.Empty; protected RectangleF _boundsAfterResize = RectangleF.Empty;
public Rectangle Bounds { public Rectangle Bounds {
get { return GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); } get => GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
set { set {
Left = Round(value.Left); Left = Round(value.Left);
Top = Round(value.Top); Top = Round(value.Top);
Width = Round(value.Width); Width = Round(value.Width);
@ -279,8 +272,12 @@ namespace Greenshot.Drawing
return new Rectangle(Point.Empty, _parent.Image.Size); return new Rectangle(Point.Empty, _parent.Image.Size);
} }
} }
// Take a base safetymargin // Take a base safety margin
int lineThickness = 5; int lineThickness = 5;
// add adorner size
lineThickness += Adorners.Max(adorner => Math.Max(adorner.Bounds.Width, adorner.Bounds.Height));
if (HasField(FieldType.LINE_THICKNESS)) { if (HasField(FieldType.LINE_THICKNESS)) {
lineThickness += GetFieldValueAsInt(FieldType.LINE_THICKNESS); lineThickness += GetFieldValueAsInt(FieldType.LINE_THICKNESS);
} }
@ -372,10 +369,10 @@ namespace Greenshot.Drawing
/// <summary> /// <summary>
/// Adjust UI elements to the supplied DPI settings /// Adjust UI elements to the supplied DPI settings
/// </summary> /// </summary>
/// <param name="dpi"></param> /// <param name="dpi">uint with dpi value</param>
public void AdjustToDpi(uint dpi) public void AdjustToDpi(uint dpi)
{ {
foreach(var adorner in Adorners) foreach(var adorner in Adorners)
{ {
adorner.AdjustToDpi(dpi); adorner.AdjustToDpi(dpi);
} }

View file

@ -35,6 +35,10 @@ namespace GreenshotPlugin.Core
/// <returns>double</returns> /// <returns>double</returns>
public static float DpiScaleFactor(uint dpi) public static float DpiScaleFactor(uint dpi)
{ {
if (dpi == 0)
{
dpi = Dpi;
}
return (float)dpi / DefaultScreenDpi; return (float)dpi / DefaultScreenDpi;
} }

View file

@ -1,20 +1,20 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* *
* For more information see: http://getgreenshot.org/ * For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or * the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -32,6 +32,11 @@ namespace GreenshotPlugin.Interfaces.Drawing.Adorners
/// </summary> /// </summary>
bool IsActive { get; } bool IsActive { get; }
/// <summary>
/// These are the bounds of the adorner
/// </summary>
Rectangle Bounds { get; }
/// <summary> /// <summary>
/// The current edit status, this is needed to locate the adorner to send events to /// The current edit status, this is needed to locate the adorner to send events to
/// </summary> /// </summary>
@ -44,7 +49,7 @@ namespace GreenshotPlugin.Interfaces.Drawing.Adorners
/// <summary> /// <summary>
/// Is the current point "over" the Adorner? /// Is the current point "over" the Adorner?
/// If this is the case, the /// If this is the case, the
/// </summary> /// </summary>
/// <param name="point">Point to test</param> /// <param name="point">Point to test</param>
/// <returns>true if so</returns> /// <returns>true if so</returns>

View file

@ -1,20 +1,20 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* *
* For more information see: http://getgreenshot.org/ * For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or * the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -124,7 +124,7 @@ namespace GreenshotPlugin.Interfaces.Drawing
/// <summary> /// <summary>
/// Adjust UI elements to the supplied DPI settings /// Adjust UI elements to the supplied DPI settings
/// </summary> /// </summary>
/// <param name="dpi"></param> /// <param name="dpi">uint</param>
void AdjustToDpi(uint dpi); void AdjustToDpi(uint dpi);
} }