From 3a7510d2a28001d0ca0dda69bf46b4f950535c5c Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 3 Aug 2016 08:59:52 +0300 Subject: [PATCH] Calculate freehand rectangle on update, close figure on shape path requested --- ShareX.HelpersLib/Extensions/Extensions.cs | 5 +++++ .../Shapes/Region/FreehandRegionShape.cs | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ShareX.HelpersLib/Extensions/Extensions.cs b/ShareX.HelpersLib/Extensions/Extensions.cs index ec111c265..b0c9c22ef 100644 --- a/ShareX.HelpersLib/Extensions/Extensions.cs +++ b/ShareX.HelpersLib/Extensions/Extensions.cs @@ -521,5 +521,10 @@ public static Rectangle Combine(this IEnumerable rects) return result; } + + public static Rectangle AddPoint(this Rectangle rect, Point point) + { + return Rectangle.Union(rect, new Rectangle(point, new Size(1, 1))); + } } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Shapes/Region/FreehandRegionShape.cs b/ShareX.ScreenCaptureLib/Shapes/Region/FreehandRegionShape.cs index c0e506786..de8770226 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Region/FreehandRegionShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Region/FreehandRegionShape.cs @@ -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(); } } }