From 59f0b43c181cff2cf7d584f48880651cd59f7740 Mon Sep 17 00:00:00 2001 From: Jaex Date: Tue, 23 Aug 2016 16:30:59 +0300 Subject: [PATCH] Change SetImage method to allow centering image to cursor --- .../Shapes/Drawing/ImageDrawingShape.cs | 33 ++++++++++++------- .../Shapes/Drawing/StepDrawingShape.cs | 1 + .../Shapes/ShapeManager.cs | 5 ++- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs index a68ccb55f..d2a754177 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/ImageDrawingShape.cs @@ -34,12 +34,7 @@ public class ImageDrawingShape : BaseDrawingShape public Image Image { get; private set; } - public void SetImage(Image img) - { - SetImage(img, Rectangle.Location); - } - - public void SetImage(Image img, Point pos) + public void SetImage(Image img, bool centerImage) { Dispose(); @@ -47,11 +42,23 @@ public void SetImage(Image img, Point pos) if (Image != null) { - Rectangle = new Rectangle(pos, Image.Size); + Point location; + Size size = Image.Size; + + if (centerImage) + { + location = new Point(Rectangle.X - size.Width / 2, Rectangle.Y - size.Height / 2); + } + else + { + location = Rectangle.Location; + } + + Rectangle = new Rectangle(location, size); } } - public void OpenImageDialog() + public void OpenImageDialog(bool centerImage) { Manager.IsMoving = false; @@ -63,7 +70,7 @@ public void OpenImageDialog() if (img != null) { - SetImage(img); + SetImage(img, centerImage); } } } @@ -76,14 +83,16 @@ public override void OnDraw(Graphics g) } } - public override void OnCreated() + public override void OnCreating() { - OpenImageDialog(); + StartPosition = EndPosition = InputManager.MousePosition0Based; + + OpenImageDialog(true); } public override void OnDoubleClicked() { - OpenImageDialog(); + OpenImageDialog(false); } public override void Dispose() diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/StepDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/StepDrawingShape.cs index 44e70deca..2080248af 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/StepDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/StepDrawingShape.cs @@ -35,6 +35,7 @@ public class StepDrawingShape : BaseDrawingShape private const int DefaultSize = 30; public override ShapeType ShapeType { get; } = ShapeType.DrawingStep; + public override bool ShowResizeNodes { get; } = false; public int Number { get; set; } diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs index 574ad8b7f..f07273e6f 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs @@ -1700,9 +1700,8 @@ private void AddImageFromClipboard() { CurrentShapeType = ShapeType.DrawingImage; ImageDrawingShape shape = (ImageDrawingShape)CreateShape(ShapeType.DrawingImage); - Point pos = InputManager.MousePosition0Based; - Point shapePos = new Point(pos.X - img.Width / 2, pos.Y - img.Height / 2); - shape.SetImage(img, shapePos); + shape.StartPosition = shape.EndPosition = InputManager.MousePosition0Based; + shape.SetImage(img, true); AddShape(shape); SelectCurrentShape(); }