Calculate freehand rectangle on update, close figure on shape path requested

This commit is contained in:
Jaex 2016-08-03 08:59:52 +03:00
parent c0ab0507f3
commit 3a7510d2a2
2 changed files with 12 additions and 2 deletions

View file

@ -521,5 +521,10 @@ public static Rectangle Combine(this IEnumerable<Rectangle> rects)
return result;
}
public static Rectangle AddPoint(this Rectangle rect, Point point)
{
return Rectangle.Union(rect, new Rectangle(point, new Size(1, 1)));
}
}
}

View file

@ -23,6 +23,7 @@
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
@ -42,7 +43,9 @@ public override void OnUpdate()
{
if (points.Count == 0 || points.Last() != InputManager.MousePosition0Based)
{
points.Add(InputManager.MousePosition0Based);
Point point = InputManager.MousePosition0Based;
points.Add(point);
Rectangle = Rectangle.AddPoint(point);
}
}
}
@ -53,6 +56,8 @@ public override void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
if (len > 1)
{
gp.StartFigure();
if (len > 2)
{
for (int i = 0; i < len - 1; i++)
@ -63,7 +68,7 @@ public override void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
gp.AddLine(points[len - 1], points[0]);
Rectangle = Rectangle.Round(gp.GetBounds());
gp.CloseFigure();
}
}
}