From 67643f5b0fbaad6acfef788d89efdb2ee69f161f Mon Sep 17 00:00:00 2001 From: Jaex Date: Fri, 6 May 2016 01:52:16 +0300 Subject: [PATCH] Two point node dragging support --- ShareX.ScreenCaptureLib/Forms/SurfaceForm.cs | 33 +++-- .../RegionHelpers/NodeObject.cs | 5 + .../RegionHelpers/ResizeManager.cs | 121 ++++++++++-------- 3 files changed, 89 insertions(+), 70 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Forms/SurfaceForm.cs b/ShareX.ScreenCaptureLib/Forms/SurfaceForm.cs index cdc20732a..13c97a24d 100644 --- a/ShareX.ScreenCaptureLib/Forms/SurfaceForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/SurfaceForm.cs @@ -284,31 +284,30 @@ protected new virtual void Update() DrawableObject[] objects = DrawableObjects.OrderByDescending(x => x.Order).ToArray(); - if (objects.All(x => x.Visible && !x.IsDragging)) + if (objects.All(x => !x.IsDragging)) { for (int i = 0; i < objects.Count(); i++) { DrawableObject obj = objects[i]; - obj.IsMouseHover = obj.Rectangle.Contains(InputManager.MousePosition0Based); - - if (obj.IsMouseHover) + if (obj.Visible) { - for (int y = i + 1; y < objects.Count(); y++) + obj.IsMouseHover = obj.Rectangle.Contains(InputManager.MousePosition0Based); + + if (obj.IsMouseHover) { - objects[y].IsMouseHover = false; + if (InputManager.IsMousePressed(MouseButtons.Left)) + { + obj.IsDragging = true; + } + + for (int y = i + 1; y < objects.Count(); y++) + { + objects[y].IsMouseHover = false; + } + + break; } - - break; - } - } - - foreach (DrawableObject obj in objects) - { - if (obj.IsMouseHover && InputManager.IsMousePressed(MouseButtons.Left)) - { - obj.IsDragging = true; - break; } } } diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/NodeObject.cs b/ShareX.ScreenCaptureLib/RegionHelpers/NodeObject.cs index 7d8e1f068..ccd3825a3 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/NodeObject.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/NodeObject.cs @@ -60,6 +60,11 @@ public override void Draw(Graphics g) { Rectangle rect = new Rectangle((int)Rectangle.X, (int)Rectangle.Y, (int)Rectangle.Width - 1, (int)Rectangle.Height - 1); + if (IsMouseHover) + { + rect.Inflate(1, 1); + } + switch (Shape) { case NodeShape.Square: diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/ResizeManager.cs b/ShareX.ScreenCaptureLib/RegionHelpers/ResizeManager.cs index 0ff95f453..4f48f564d 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/ResizeManager.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/ResizeManager.cs @@ -111,60 +111,78 @@ public ResizeManager(SurfaceForm surface, AreaManager areaManager) public void Update() { - if (Visible && nodes != null) + BaseShape shape = areaManager.CurrentShape; + + if (shape != null && Visible && nodes != null) { if (InputManager.IsMouseDown(MouseButtons.Left)) { - for (int i = 0; i < 8; i++) + if (shape.NodeType == NodeType.Rectangle) { - if (nodes[i].IsDragging) + for (int i = 0; i < 8; i++) + { + if (nodes[i].IsDragging) + { + IsResizing = true; + + if (!InputManager.IsBeforeMouseDown(MouseButtons.Left)) + { + tempRect = shape.Rectangle; + } + + NodePosition nodePosition = (NodePosition)i; + + int x = InputManager.MouseVelocity.X; + + switch (nodePosition) + { + case NodePosition.TopLeft: + case NodePosition.Left: + case NodePosition.BottomLeft: + tempRect.X += x; + tempRect.Width -= x; + break; + case NodePosition.TopRight: + case NodePosition.Right: + case NodePosition.BottomRight: + tempRect.Width += x; + break; + } + + int y = InputManager.MouseVelocity.Y; + + switch (nodePosition) + { + case NodePosition.TopLeft: + case NodePosition.Top: + case NodePosition.TopRight: + tempRect.Y += y; + tempRect.Height -= y; + break; + case NodePosition.BottomLeft: + case NodePosition.Bottom: + case NodePosition.BottomRight: + tempRect.Height += y; + break; + } + + shape.Rectangle = CaptureHelpers.FixRectangle(tempRect); + + break; + } + } + } + else if (shape.NodeType == NodeType.Line) + { + if (nodes[(int)NodePosition.TopLeft].IsDragging) { IsResizing = true; - - if (!InputManager.IsBeforeMouseDown(MouseButtons.Left)) - { - tempRect = areaManager.CurrentRectangle; - } - - NodePosition nodePosition = (NodePosition)i; - - int x = InputManager.MouseVelocity.X; - - switch (nodePosition) - { - case NodePosition.TopLeft: - case NodePosition.Left: - case NodePosition.BottomLeft: - tempRect.X += x; - tempRect.Width -= x; - break; - case NodePosition.TopRight: - case NodePosition.Right: - case NodePosition.BottomRight: - tempRect.Width += x; - break; - } - - int y = InputManager.MouseVelocity.Y; - - switch (nodePosition) - { - case NodePosition.TopLeft: - case NodePosition.Top: - case NodePosition.TopRight: - tempRect.Y += y; - tempRect.Height -= y; - break; - case NodePosition.BottomLeft: - case NodePosition.Bottom: - case NodePosition.BottomRight: - tempRect.Height += y; - break; - } - - areaManager.CurrentRectangle = CaptureHelpers.FixRectangle(tempRect); - - break; + shape.StartPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y); + } + else if (nodes[(int)NodePosition.BottomRight].IsDragging) + { + IsResizing = true; + shape.EndPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y); } } } @@ -257,13 +275,10 @@ public void Hide() Visible = false; } - public void UpdateNodePositions() + private void UpdateNodePositions() { - UpdateNodePositions(areaManager.CurrentShape); - } + BaseShape shape = areaManager.CurrentShape; - private void UpdateNodePositions(BaseShape shape) - { if (shape != null) { if (shape.NodeType == NodeType.Rectangle)