From d1ec0b8ae638ba8840471d1a2721634180078267 Mon Sep 17 00:00:00 2001 From: Jaex Date: Tue, 10 May 2016 01:54:11 +0300 Subject: [PATCH] Improvements to support resizing and moving two point (line, arrow) shapes --- .../RegionHelpers/ResizeManager.cs | 32 ++++++++++++++++--- .../RegionHelpers/ShapeManager.cs | 14 ++++---- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/ResizeManager.cs b/ShareX.ScreenCaptureLib/RegionHelpers/ResizeManager.cs index 226060956..3c95ce74b 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/ResizeManager.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/ResizeManager.cs @@ -318,7 +318,15 @@ public void MoveCurrentArea(int x, int y) if (shape != null) { - shape.Rectangle = shape.Rectangle.LocationOffset(x, y); + if (shape.NodeType == NodeType.Rectangle) + { + shape.Rectangle = shape.Rectangle.LocationOffset(x, y); + } + else if (shape.NodeType == NodeType.Line) + { + shape.StartPosition = shape.StartPosition.Add(x, y); + shape.EndPosition = shape.EndPosition.Add(x, y); + } } } @@ -328,13 +336,27 @@ public void ResizeCurrentArea(int x, int y, bool isBottomRightMoving) if (shape != null) { - if (isBottomRightMoving) + if (shape.NodeType == NodeType.Rectangle) { - shape.Rectangle = shape.Rectangle.SizeOffset(x, y); + if (isBottomRightMoving) + { + shape.Rectangle = shape.Rectangle.SizeOffset(x, y); + } + else + { + shape.Rectangle = shape.Rectangle.LocationOffset(x, y).SizeOffset(-x, -y); + } } - else + else if (shape.NodeType == NodeType.Line) { - shape.Rectangle = shape.Rectangle.LocationOffset(x, y).SizeOffset(-x, -y); + if (isBottomRightMoving) + { + shape.StartPosition = shape.StartPosition.Add(x, y); + } + else + { + shape.EndPosition = shape.EndPosition.Add(x, y); + } } } } diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs b/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs index 1b8127ace..3d41648f9 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs @@ -589,17 +589,15 @@ private void surface_KeyUp(object sender, KeyEventArgs e) public void Update() { - if (CurrentShape != null) + BaseShape shape = CurrentShape; + + if (shape != null) { if (IsMoving) { - Rectangle rect = CurrentRectangle; - rect.X += InputManager.MouseVelocity.X; - rect.Y += InputManager.MouseVelocity.Y; - CurrentShape.Rectangle = rect; + ResizeManager.MoveCurrentArea(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y); } - - if (IsCreating && !CurrentRectangle.IsEmpty) + else if (IsCreating && !CurrentRectangle.IsEmpty) { CurrentPosition = InputManager.MousePosition0Based; @@ -615,7 +613,7 @@ public void Update() newPosition = SnapPosition(PositionOnClick, newPosition); } - CurrentShape.EndPosition = newPosition; + shape.EndPosition = newPosition; } }