Limit crop rectangle to inside canvas

This commit is contained in:
Jaex 2017-12-13 02:02:00 +03:00
parent 8eaa3b198e
commit 91f203cd35
2 changed files with 19 additions and 3 deletions

View file

@ -59,6 +59,8 @@ public Rectangle Rectangle
public bool IsInsideCanvas => !RectangleInsideCanvas.IsEmpty;
public virtual bool LimitRectangleToInsideCanvas { get; }
private Point startPosition;
public Point StartPosition
@ -219,6 +221,16 @@ public virtual void OnUpdate()
{
Move(InputManager.MouseVelocity);
}
CheckLimitRectangle();
}
private void CheckLimitRectangle()
{
if (LimitRectangleToInsideCanvas)
{
Rectangle = RectangleInsideCanvas;
}
}
public virtual void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
@ -379,6 +391,8 @@ public virtual void OnNodeUpdate()
Rectangle = newRect;
}
CheckLimitRectangle();
}
}
}

View file

@ -32,8 +32,10 @@ public class CropTool : BaseTool
{
public override ShapeType ShapeType { get; } = ShapeType.ToolCrop;
public override bool LimitRectangleToInsideCanvas { get; } = true;
private ButtonObject confirmButton, cancelButton;
private int buttonOffset = 12;
private int buttonOffset = 15;
public override void OnUpdate()
{
@ -53,7 +55,7 @@ public override void OnDraw(Graphics g)
{
if (IsValidShape)
{
Manager.DrawRegionArea(g, RectangleInsideCanvas, true);
Manager.DrawRegionArea(g, Rectangle, true);
}
}
@ -82,7 +84,7 @@ public override void OnCreated()
private void ConfirmButton_MousePressed(object sender, MouseEventArgs e)
{
Manager.CropArea(RectangleInsideCanvas);
Manager.CropArea(Rectangle);
Remove();
}