2016-08-03 12:48:11 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2021-07-29 15:22:51 +12:00
|
|
|
|
Copyright (c) 2007-2021 ShareX Team
|
2016-08-03 12:48:11 +12:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2016-08-03 17:59:52 +12:00
|
|
|
|
using ShareX.HelpersLib;
|
2016-08-03 12:48:11 +12:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
|
|
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
|
|
|
|
{
|
|
|
|
|
public class FreehandRegionShape : BaseRegionShape
|
|
|
|
|
{
|
|
|
|
|
public override ShapeType ShapeType { get; } = ShapeType.RegionFreehand;
|
2016-08-05 22:13:16 +12:00
|
|
|
|
|
|
|
|
|
public Point LastPosition
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (points.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return points[points.Count - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Point.Empty;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (points.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
points[points.Count - 1] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-03 12:48:11 +12:00
|
|
|
|
|
2016-08-04 12:07:00 +12:00
|
|
|
|
private List<Point> points = new List<Point>();
|
2016-08-04 22:19:42 +12:00
|
|
|
|
private bool isPolygonMode;
|
2016-08-03 12:48:11 +12:00
|
|
|
|
|
2018-08-30 02:49:50 +12:00
|
|
|
|
protected override void UseLightResizeNodes()
|
2018-08-23 22:20:55 +12:00
|
|
|
|
{
|
|
|
|
|
ChangeNodeShape(NodeShape.Circle);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 12:48:11 +12:00
|
|
|
|
public override void OnUpdate()
|
|
|
|
|
{
|
|
|
|
|
if (Manager.IsCreating)
|
|
|
|
|
{
|
2016-08-05 20:43:52 +12:00
|
|
|
|
if (Manager.IsCornerMoving)
|
2016-08-04 13:13:57 +12:00
|
|
|
|
{
|
2016-08-05 20:43:52 +12:00
|
|
|
|
Move(InputManager.MouseVelocity);
|
2016-08-04 13:13:57 +12:00
|
|
|
|
}
|
2016-08-05 20:43:52 +12:00
|
|
|
|
else
|
2016-08-03 12:48:11 +12:00
|
|
|
|
{
|
2017-11-07 05:01:02 +13:00
|
|
|
|
Point pos = InputManager.ClientMousePosition;
|
2016-08-05 20:43:52 +12:00
|
|
|
|
|
2016-08-05 22:13:16 +12:00
|
|
|
|
if (points.Count == 0 || (!Manager.IsProportionalResizing && LastPosition != pos))
|
2016-08-04 22:19:42 +12:00
|
|
|
|
{
|
|
|
|
|
points.Add(pos);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 20:43:52 +12:00
|
|
|
|
if (Manager.IsProportionalResizing)
|
|
|
|
|
{
|
|
|
|
|
if (!isPolygonMode)
|
|
|
|
|
{
|
|
|
|
|
points.Add(pos);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 22:13:16 +12:00
|
|
|
|
LastPosition = pos;
|
2016-08-05 20:43:52 +12:00
|
|
|
|
}
|
2016-08-04 13:13:57 +12:00
|
|
|
|
|
2016-08-05 20:43:52 +12:00
|
|
|
|
isPolygonMode = Manager.IsProportionalResizing;
|
2016-08-04 22:19:42 +12:00
|
|
|
|
|
2016-08-05 22:13:16 +12:00
|
|
|
|
Rectangle = points.CreateRectangle();
|
|
|
|
|
}
|
2016-08-03 12:48:11 +12:00
|
|
|
|
}
|
2016-08-03 19:09:21 +12:00
|
|
|
|
else if (Manager.IsMoving)
|
|
|
|
|
{
|
2016-08-03 21:08:06 +12:00
|
|
|
|
Move(InputManager.MouseVelocity);
|
2016-08-03 19:09:21 +12:00
|
|
|
|
}
|
2016-08-03 12:48:11 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public override void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
|
2016-08-03 12:48:11 +12:00
|
|
|
|
{
|
2016-09-03 05:02:06 +12:00
|
|
|
|
if (points.Count > 2)
|
2016-08-03 12:48:11 +12:00
|
|
|
|
{
|
2016-09-03 05:02:06 +12:00
|
|
|
|
gp.AddPolygon(points.ToArray());
|
2016-08-03 12:48:11 +12:00
|
|
|
|
}
|
2016-10-03 10:50:51 +13:00
|
|
|
|
else if (points.Count == 2)
|
|
|
|
|
{
|
|
|
|
|
gp.AddLine(points[0], points[1]);
|
|
|
|
|
}
|
2016-08-03 12:48:11 +12:00
|
|
|
|
}
|
2016-08-03 21:08:06 +12:00
|
|
|
|
|
|
|
|
|
public override void Move(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < points.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
points[i] = points[i].Add(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rectangle = Rectangle.LocationOffset(x, y);
|
|
|
|
|
}
|
2016-08-03 21:19:01 +12:00
|
|
|
|
|
|
|
|
|
public override void Resize(int x, int y, bool fromBottomRight)
|
|
|
|
|
{
|
2016-08-08 20:46:45 +12:00
|
|
|
|
Move(x, y);
|
2016-08-03 21:19:01 +12:00
|
|
|
|
}
|
2016-08-06 01:35:44 +12:00
|
|
|
|
|
|
|
|
|
public override void OnNodeVisible()
|
|
|
|
|
{
|
2016-08-17 20:35:06 +12:00
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.TopLeft].Visible = true;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnNodeUpdate()
|
|
|
|
|
{
|
2016-08-17 20:35:06 +12:00
|
|
|
|
if (Manager.ResizeNodes[(int)NodePosition.TopLeft].IsDragging)
|
2016-08-06 01:35:44 +12:00
|
|
|
|
{
|
|
|
|
|
Manager.IsCreating = true;
|
|
|
|
|
Manager.NodesVisible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnNodePositionUpdate()
|
|
|
|
|
{
|
2016-08-17 20:35:06 +12:00
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.TopLeft].Position = LastPosition;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
}
|
2016-08-03 12:48:11 +12:00
|
|
|
|
}
|
|
|
|
|
}
|