mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-07 07:26:05 +12:00
Adding curve drawing support to line and arrow tools
This commit is contained in:
parent
981cf14c91
commit
c43ccd9ac5
|
@ -38,7 +38,14 @@ protected override void DrawLine(Graphics g, Pen pen)
|
|||
{
|
||||
pen.CustomEndCap = arrowCap;
|
||||
|
||||
g.DrawLine(pen, StartPosition, EndPosition);
|
||||
if (MiddlePosition.IsEmpty)
|
||||
{
|
||||
g.DrawLine(pen, StartPosition, EndPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawCurve(pen, new Point[] { StartPosition, MiddlePosition, EndPosition });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ public class LineDrawingShape : BaseDrawingShape
|
|||
{
|
||||
public override ShapeType ShapeType { get; } = ShapeType.DrawingLine;
|
||||
|
||||
public Point MiddlePosition { get; private set; } = Point.Empty;
|
||||
|
||||
public override bool IsValidShape
|
||||
{
|
||||
get
|
||||
|
@ -41,6 +43,16 @@ public override bool IsValidShape
|
|||
}
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
base.OnUpdate();
|
||||
|
||||
if (!MiddlePosition.IsEmpty)
|
||||
{
|
||||
Rectangle = new Point[] { StartPosition, MiddlePosition, EndPosition }.CreateRectangle();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics g)
|
||||
{
|
||||
if (BorderSize > 0 && BorderColor.A > 0)
|
||||
|
@ -67,13 +79,21 @@ protected virtual void DrawLine(Graphics g, Pen pen)
|
|||
pen.StartCap = LineCap.Round;
|
||||
pen.EndCap = LineCap.Round;
|
||||
|
||||
g.DrawLine(pen, StartPosition, EndPosition);
|
||||
if (MiddlePosition.IsEmpty)
|
||||
{
|
||||
g.DrawLine(pen, StartPosition, EndPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawCurve(pen, new Point[] { StartPosition, MiddlePosition, EndPosition });
|
||||
}
|
||||
}
|
||||
|
||||
public override void Move(int x, int y)
|
||||
{
|
||||
StartPosition = StartPosition.Add(x, y);
|
||||
EndPosition = EndPosition.Add(x, y);
|
||||
MiddlePosition = MiddlePosition.Add(x, y);
|
||||
}
|
||||
|
||||
public override void Resize(int x, int y, bool fromBottomRight)
|
||||
|
@ -90,8 +110,13 @@ public override void Resize(int x, int y, bool fromBottomRight)
|
|||
|
||||
public override void OnNodeVisible()
|
||||
{
|
||||
Manager.ResizeNodes[(int)NodePosition.TopLeft].Shape = Manager.ResizeNodes[(int)NodePosition.BottomRight].Shape = NodeShape.Circle;
|
||||
Manager.ResizeNodes[(int)NodePosition.TopLeft].Visible = Manager.ResizeNodes[(int)NodePosition.BottomRight].Visible = true;
|
||||
Manager.ResizeNodes[(int)NodePosition.TopLeft].Shape = Manager.ResizeNodes[(int)NodePosition.BottomRight].Shape = Manager.ResizeNodes[(int)NodePosition.Extra].Shape = NodeShape.Circle;
|
||||
Manager.ResizeNodes[(int)NodePosition.TopLeft].Visible = Manager.ResizeNodes[(int)NodePosition.BottomRight].Visible = Manager.ResizeNodes[(int)NodePosition.Extra].Visible = true;
|
||||
}
|
||||
|
||||
public override void OnCreated()
|
||||
{
|
||||
MiddlePosition = new Point((int)MathHelpers.Lerp(StartPosition.X, EndPosition.X, 0.5f), (int)MathHelpers.Lerp(StartPosition.Y, EndPosition.Y, 0.5f));
|
||||
}
|
||||
|
||||
public override void OnNodeUpdate()
|
||||
|
@ -108,12 +133,19 @@ public override void OnNodeUpdate()
|
|||
|
||||
EndPosition = InputManager.MousePosition0Based;
|
||||
}
|
||||
else if (Manager.ResizeNodes[(int)NodePosition.Extra].IsDragging)
|
||||
{
|
||||
Manager.IsResizing = true;
|
||||
|
||||
MiddlePosition = InputManager.MousePosition0Based;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnNodePositionUpdate()
|
||||
{
|
||||
Manager.ResizeNodes[(int)NodePosition.TopLeft].Position = StartPosition;
|
||||
Manager.ResizeNodes[(int)NodePosition.BottomRight].Position = EndPosition;
|
||||
Manager.ResizeNodes[(int)NodePosition.Extra].Position = MiddlePosition;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue