mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 21:43:24 -07:00
BUG-1682: Keep the target gripper inside the surface
This commit is contained in:
parent
bba978c209
commit
469cfff275
2 changed files with 34 additions and 19 deletions
|
@ -330,13 +330,32 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Should be overridden to handle gripper moves on the "TargetGripper"
|
||||
/// Move the TargetGripper around, confined to the surface to solve BUG-1682
|
||||
/// </summary>
|
||||
/// <param name="newX"></param>
|
||||
/// <param name="newY"></param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from Surface (the _parent) when the drawing begins (mouse-down)
|
||||
/// </summary>
|
||||
|
@ -108,22 +103,23 @@ namespace Greenshot.Drawing {
|
|||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
/// <returns>base.HandleMouseMove</returns>
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue