From 3d39241f82799b741afb039e65783f6d0e52f9c0 Mon Sep 17 00:00:00 2001 From: Killy Date: Mon, 27 Apr 2020 16:00:58 +0300 Subject: [PATCH] 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 --- Greenshot/Drawing/FreehandContainer.cs | 13 ++++++++++--- Greenshot/Drawing/Surface.cs | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Greenshot/Drawing/FreehandContainer.cs b/Greenshot/Drawing/FreehandContainer.cs index 129ba4822..c7d5cf1e8 100644 --- a/Greenshot/Drawing/FreehandContainer.cs +++ b/Greenshot/Drawing/FreehandContainer.cs @@ -47,8 +47,8 @@ namespace Greenshot.Drawing { /// Constructor /// public FreehandContainer(Surface parent) : base(parent) { - Width = parent.Width; - Height = parent.Height; + Width = parent.Image.Width; + Height = parent.Image.Height; Top = 0; Left = 0; } @@ -236,7 +236,14 @@ namespace Greenshot.Drawing { 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(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; + } } } diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index 3d1f309a3..e9d26ef05 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -991,13 +991,13 @@ namespace Greenshot.Drawing { 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) {