Improvements to support resizing and moving two point (line, arrow) shapes

This commit is contained in:
Jaex 2016-05-10 01:54:11 +03:00
parent 0e7ba6cbe9
commit d1ec0b8ae6
2 changed files with 33 additions and 13 deletions

View file

@ -318,7 +318,15 @@ public void MoveCurrentArea(int x, int y)
if (shape != null)
{
shape.Rectangle = shape.Rectangle.LocationOffset(x, y);
if (shape.NodeType == NodeType.Rectangle)
{
shape.Rectangle = shape.Rectangle.LocationOffset(x, y);
}
else if (shape.NodeType == NodeType.Line)
{
shape.StartPosition = shape.StartPosition.Add(x, y);
shape.EndPosition = shape.EndPosition.Add(x, y);
}
}
}
@ -328,13 +336,27 @@ public void ResizeCurrentArea(int x, int y, bool isBottomRightMoving)
if (shape != null)
{
if (isBottomRightMoving)
if (shape.NodeType == NodeType.Rectangle)
{
shape.Rectangle = shape.Rectangle.SizeOffset(x, y);
if (isBottomRightMoving)
{
shape.Rectangle = shape.Rectangle.SizeOffset(x, y);
}
else
{
shape.Rectangle = shape.Rectangle.LocationOffset(x, y).SizeOffset(-x, -y);
}
}
else
else if (shape.NodeType == NodeType.Line)
{
shape.Rectangle = shape.Rectangle.LocationOffset(x, y).SizeOffset(-x, -y);
if (isBottomRightMoving)
{
shape.StartPosition = shape.StartPosition.Add(x, y);
}
else
{
shape.EndPosition = shape.EndPosition.Add(x, y);
}
}
}
}

View file

@ -589,17 +589,15 @@ private void surface_KeyUp(object sender, KeyEventArgs e)
public void Update()
{
if (CurrentShape != null)
BaseShape shape = CurrentShape;
if (shape != null)
{
if (IsMoving)
{
Rectangle rect = CurrentRectangle;
rect.X += InputManager.MouseVelocity.X;
rect.Y += InputManager.MouseVelocity.Y;
CurrentShape.Rectangle = rect;
ResizeManager.MoveCurrentArea(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
}
if (IsCreating && !CurrentRectangle.IsEmpty)
else if (IsCreating && !CurrentRectangle.IsEmpty)
{
CurrentPosition = InputManager.MousePosition0Based;
@ -615,7 +613,7 @@ public void Update()
newPosition = SnapPosition(PositionOnClick, newPosition);
}
CurrentShape.EndPosition = newPosition;
shape.EndPosition = newPosition;
}
}