More fixes for Surface.Image size

- crop works properly;
- Freehand drawings are selectable everywhere at all zoom levels.

Known issue: freehand selection outline is not drawn
This commit is contained in:
Killy 2020-04-27 16:00:58 +03:00
commit 3d39241f82
2 changed files with 14 additions and 7 deletions

View file

@ -47,8 +47,8 @@ namespace Greenshot.Drawing {
/// Constructor /// Constructor
/// </summary> /// </summary>
public FreehandContainer(Surface parent) : base(parent) { public FreehandContainer(Surface parent) : base(parent) {
Width = parent.Width; Width = parent.Image.Width;
Height = parent.Height; Height = parent.Image.Height;
Top = 0; Top = 0;
Left = 0; Left = 0;
} }
@ -236,7 +236,14 @@ namespace Greenshot.Drawing {
int safetymargin = 10; int safetymargin = 10;
return new Rectangle(myBounds.Left + Left - (safetymargin+lineThickness), myBounds.Top + Top - (safetymargin+lineThickness), myBounds.Width + 2*(lineThickness+safetymargin), myBounds.Height + 2*(lineThickness+safetymargin)); return new Rectangle(myBounds.Left + Left - (safetymargin+lineThickness), myBounds.Top + Top - (safetymargin+lineThickness), myBounds.Width + 2*(lineThickness+safetymargin), myBounds.Height + 2*(lineThickness+safetymargin));
} }
return new Rectangle(0, 0, _parent?.Width??0, _parent?.Height?? 0); if (_parent?.Image is Image image)
{
return new Rectangle(0, 0, image.Width, image.Height);
}
else
{
return Rectangle.Empty;
}
} }
} }

View file

@ -991,13 +991,13 @@ namespace Greenshot.Drawing
{ {
cropRectangle = new Rectangle(cropRectangle.Left, 0, cropRectangle.Width, cropRectangle.Height + cropRectangle.Top); cropRectangle = new Rectangle(cropRectangle.Left, 0, cropRectangle.Width, cropRectangle.Height + cropRectangle.Top);
} }
if (cropRectangle.Left + cropRectangle.Width > Width) if (cropRectangle.Left + cropRectangle.Width > Image.Width)
{ {
cropRectangle = new Rectangle(cropRectangle.Left, cropRectangle.Top, Width - cropRectangle.Left, cropRectangle.Height); cropRectangle = new Rectangle(cropRectangle.Left, cropRectangle.Top, Image.Width - cropRectangle.Left, cropRectangle.Height);
} }
if (cropRectangle.Top + cropRectangle.Height > Height) if (cropRectangle.Top + cropRectangle.Height > Image.Height)
{ {
cropRectangle = new Rectangle(cropRectangle.Left, cropRectangle.Top, cropRectangle.Width, Height - cropRectangle.Top); cropRectangle = new Rectangle(cropRectangle.Left, cropRectangle.Top, cropRectangle.Width, Image.Height - cropRectangle.Top);
} }
if (cropRectangle.Height > 0 && cropRectangle.Width > 0) if (cropRectangle.Height > 0 && cropRectangle.Width > 0)
{ {