From 469cfff275d1920dee50188e0894931758de9fff Mon Sep 17 00:00:00 2001 From: RKrom Date: Mon, 1 Dec 2014 21:52:46 +0100 Subject: [PATCH] BUG-1682: Keep the target gripper inside the surface --- Greenshot/Drawing/DrawableContainer.cs | 25 ++++++++++++++++--- Greenshot/Drawing/SpeechbubbleContainer.cs | 28 ++++++++++------------ 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Greenshot/Drawing/DrawableContainer.cs b/Greenshot/Drawing/DrawableContainer.cs index 34ac7352b..a2dcdda48 100644 --- a/Greenshot/Drawing/DrawableContainer.cs +++ b/Greenshot/Drawing/DrawableContainer.cs @@ -330,13 +330,32 @@ namespace Greenshot.Drawing { } /// - /// Should be overridden to handle gripper moves on the "TargetGripper" + /// Move the TargetGripper around, confined to the surface to solve BUG-1682 /// /// /// protected virtual void TargetGripperMove(int newX, int newY) { - _targetGripper.Left = newX; - _targetGripper.Top = newY; + Point newGripperLocation = new Point(newX, newY); + Rectangle surfaceBounds = new Rectangle(0, 0, _parent.Width, _parent.Height); + // Check if gripper inside the parent (surface), if not we need to move it inside + // This was made for BUG-1682 + if (!surfaceBounds.Contains(newGripperLocation)) { + if (newGripperLocation.X > surfaceBounds.Right) { + newGripperLocation.X = surfaceBounds.Right - 5; + } + if (newGripperLocation.X < surfaceBounds.Left) { + newGripperLocation.X = surfaceBounds.Left; + } + if (newGripperLocation.Y > surfaceBounds.Bottom) { + newGripperLocation.Y = surfaceBounds.Bottom - 5; + } + if (newGripperLocation.Y < surfaceBounds.Top) { + newGripperLocation.Y = surfaceBounds.Top; + } + } + + _targetGripper.Left = newGripperLocation.X; + _targetGripper.Top = newGripperLocation.Y; } /// diff --git a/Greenshot/Drawing/SpeechbubbleContainer.cs b/Greenshot/Drawing/SpeechbubbleContainer.cs index 552f56322..9741a06bd 100644 --- a/Greenshot/Drawing/SpeechbubbleContainer.cs +++ b/Greenshot/Drawing/SpeechbubbleContainer.cs @@ -85,11 +85,6 @@ namespace Greenshot.Drawing { AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER); } - protected override void TargetGripperMove(int absX, int absY) { - base.TargetGripperMove(absX, absY); - Invalidate(); - } - /// /// Called from Surface (the _parent) when the drawing begins (mouse-down) /// @@ -108,22 +103,23 @@ namespace Greenshot.Drawing { /// /// /// - /// + /// base.HandleMouseMove public override bool HandleMouseMove(int x, int y) { bool returnValue = base.HandleMouseMove(x, y); + + bool leftAligned = _boundsAfterResize.Right - _boundsAfterResize.Left >= 0; + bool topAligned = _boundsAfterResize.Bottom - _boundsAfterResize.Top >= 0; + + int xOffset = leftAligned ? -20 : 20; + int yOffset = topAligned ? -20 : 20; + Point newGripperLocation = _initialGripperPoint; - if (_boundsAfterResize.Right - _boundsAfterResize.Left >= 0) { - newGripperLocation.Offset(-20, 0); - } else { - newGripperLocation.Offset(20, 0); - } - if (_boundsAfterResize.Bottom - _boundsAfterResize.Top >= 0) { - newGripperLocation.Offset(0, -20); - } else { - newGripperLocation.Offset(0, 20); - } + newGripperLocation.Offset(xOffset, yOffset); + if (TargetGripper.Location != newGripperLocation) { + Invalidate(); TargetGripperMove(newGripperLocation.X, newGripperLocation.Y); + Invalidate(); } return returnValue; }