BUG-1682: Keep the target gripper inside the surface

This commit is contained in:
RKrom 2014-12-01 21:52:46 +01:00
commit 469cfff275
2 changed files with 34 additions and 19 deletions

View file

@ -330,13 +330,32 @@ namespace Greenshot.Drawing {
} }
/// <summary> /// <summary>
/// Should be overridden to handle gripper moves on the "TargetGripper" /// Move the TargetGripper around, confined to the surface to solve BUG-1682
/// </summary> /// </summary>
/// <param name="newX"></param> /// <param name="newX"></param>
/// <param name="newY"></param> /// <param name="newY"></param>
protected virtual void TargetGripperMove(int newX, int newY) { protected virtual void TargetGripperMove(int newX, int newY) {
_targetGripper.Left = newX; Point newGripperLocation = new Point(newX, newY);
_targetGripper.Top = 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;
} }
/// <summary> /// <summary>

View file

@ -85,11 +85,6 @@ namespace Greenshot.Drawing {
AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER); AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER);
} }
protected override void TargetGripperMove(int absX, int absY) {
base.TargetGripperMove(absX, absY);
Invalidate();
}
/// <summary> /// <summary>
/// Called from Surface (the _parent) when the drawing begins (mouse-down) /// Called from Surface (the _parent) when the drawing begins (mouse-down)
/// </summary> /// </summary>
@ -108,22 +103,23 @@ namespace Greenshot.Drawing {
/// </summary> /// </summary>
/// <param name="x"></param> /// <param name="x"></param>
/// <param name="y"></param> /// <param name="y"></param>
/// <returns></returns> /// <returns>base.HandleMouseMove</returns>
public override bool HandleMouseMove(int x, int y) { public override bool HandleMouseMove(int x, int y) {
bool returnValue = base.HandleMouseMove(x, 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; Point newGripperLocation = _initialGripperPoint;
if (_boundsAfterResize.Right - _boundsAfterResize.Left >= 0) { newGripperLocation.Offset(xOffset, yOffset);
newGripperLocation.Offset(-20, 0);
} else {
newGripperLocation.Offset(20, 0);
}
if (_boundsAfterResize.Bottom - _boundsAfterResize.Top >= 0) {
newGripperLocation.Offset(0, -20);
} else {
newGripperLocation.Offset(0, 20);
}
if (TargetGripper.Location != newGripperLocation) { if (TargetGripper.Location != newGripperLocation) {
Invalidate();
TargetGripperMove(newGripperLocation.X, newGripperLocation.Y); TargetGripperMove(newGripperLocation.X, newGripperLocation.Y);
Invalidate();
} }
return returnValue; return returnValue;
} }