mirror of
https://github.com/ShareX/ShareX.git
synced 2024-08-07 22:38:05 +12:00
Adding curve drawing support to line and arrow tools
This commit is contained in:
parent
981cf14c91
commit
c43ccd9ac5
2 changed files with 43 additions and 4 deletions
|
@ -38,8 +38,15 @@ protected override void DrawLine(Graphics g, Pen pen)
|
||||||
{
|
{
|
||||||
pen.CustomEndCap = arrowCap;
|
pen.CustomEndCap = arrowCap;
|
||||||
|
|
||||||
|
if (MiddlePosition.IsEmpty)
|
||||||
|
{
|
||||||
g.DrawLine(pen, StartPosition, EndPosition);
|
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 override ShapeType ShapeType { get; } = ShapeType.DrawingLine;
|
||||||
|
|
||||||
|
public Point MiddlePosition { get; private set; } = Point.Empty;
|
||||||
|
|
||||||
public override bool IsValidShape
|
public override bool IsValidShape
|
||||||
{
|
{
|
||||||
get
|
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)
|
public override void OnDraw(Graphics g)
|
||||||
{
|
{
|
||||||
if (BorderSize > 0 && BorderColor.A > 0)
|
if (BorderSize > 0 && BorderColor.A > 0)
|
||||||
|
@ -67,13 +79,21 @@ protected virtual void DrawLine(Graphics g, Pen pen)
|
||||||
pen.StartCap = LineCap.Round;
|
pen.StartCap = LineCap.Round;
|
||||||
pen.EndCap = LineCap.Round;
|
pen.EndCap = LineCap.Round;
|
||||||
|
|
||||||
|
if (MiddlePosition.IsEmpty)
|
||||||
|
{
|
||||||
g.DrawLine(pen, StartPosition, EndPosition);
|
g.DrawLine(pen, StartPosition, EndPosition);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g.DrawCurve(pen, new Point[] { StartPosition, MiddlePosition, EndPosition });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Move(int x, int y)
|
public override void Move(int x, int y)
|
||||||
{
|
{
|
||||||
StartPosition = StartPosition.Add(x, y);
|
StartPosition = StartPosition.Add(x, y);
|
||||||
EndPosition = EndPosition.Add(x, y);
|
EndPosition = EndPosition.Add(x, y);
|
||||||
|
MiddlePosition = MiddlePosition.Add(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Resize(int x, int y, bool fromBottomRight)
|
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()
|
public override void OnNodeVisible()
|
||||||
{
|
{
|
||||||
Manager.ResizeNodes[(int)NodePosition.TopLeft].Shape = Manager.ResizeNodes[(int)NodePosition.BottomRight].Shape = NodeShape.Circle;
|
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 = true;
|
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()
|
public override void OnNodeUpdate()
|
||||||
|
@ -108,12 +133,19 @@ public override void OnNodeUpdate()
|
||||||
|
|
||||||
EndPosition = InputManager.MousePosition0Based;
|
EndPosition = InputManager.MousePosition0Based;
|
||||||
}
|
}
|
||||||
|
else if (Manager.ResizeNodes[(int)NodePosition.Extra].IsDragging)
|
||||||
|
{
|
||||||
|
Manager.IsResizing = true;
|
||||||
|
|
||||||
|
MiddlePosition = InputManager.MousePosition0Based;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnNodePositionUpdate()
|
public override void OnNodePositionUpdate()
|
||||||
{
|
{
|
||||||
Manager.ResizeNodes[(int)NodePosition.TopLeft].Position = StartPosition;
|
Manager.ResizeNodes[(int)NodePosition.TopLeft].Position = StartPosition;
|
||||||
Manager.ResizeNodes[(int)NodePosition.BottomRight].Position = EndPosition;
|
Manager.ResizeNodes[(int)NodePosition.BottomRight].Position = EndPosition;
|
||||||
|
Manager.ResizeNodes[(int)NodePosition.Extra].Position = MiddlePosition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue