diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs index 17e19d2f9..a68ccb55f 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs @@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License #endregion License Information (GPL v3) +using ShareX.HelpersLib; using System.Drawing; namespace ShareX.ScreenCaptureLib @@ -35,18 +36,35 @@ public class ImageDrawingShape : BaseDrawingShape public void SetImage(Image img) { - Dispose(); - - Image = img; + SetImage(img, Rectangle.Location); } public void SetImage(Image img, Point pos) { - SetImage(img); + Dispose(); + + Image = img; if (Image != null) { - Rectangle = new Rectangle(new Point(pos.X - Image.Width / 2, pos.Y - Image.Height / 2), Image.Size); + Rectangle = new Rectangle(pos, Image.Size); + } + } + + public void OpenImageDialog() + { + Manager.IsMoving = false; + + string filepath = ImageHelpers.OpenImageFileDialog(); + + if (!string.IsNullOrEmpty(filepath)) + { + Image img = ImageHelpers.LoadImage(filepath); + + if (img != null) + { + SetImage(img); + } } } @@ -58,6 +76,16 @@ public override void OnDraw(Graphics g) } } + public override void OnCreated() + { + OpenImageDialog(); + } + + public override void OnDoubleClicked() + { + OpenImageDialog(); + } + public override void Dispose() { if (Image != null) diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs index 501a2a1eb..8c72335b8 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs @@ -136,7 +136,7 @@ public bool IsCurrentShapeTypeRegion } public bool IsCreating { get; set; } - public bool IsMoving { get; private set; } + public bool IsMoving { get; set; } public bool IsResizing { get; set; } public bool IsCornerMoving { get; private set; } @@ -1717,7 +1717,9 @@ private void AddImageFromClipboard() { CurrentShapeType = ShapeType.DrawingImage; ImageDrawingShape shape = (ImageDrawingShape)CreateShape(ShapeType.DrawingImage); - shape.SetImage(img, InputManager.MousePosition0Based); + Point pos = InputManager.MousePosition0Based; + Point shapePos = new Point(pos.X - img.Width / 2, pos.Y - img.Height / 2); + shape.SetImage(img, shapePos); AddShape(shape); SelectCurrentShape(); }