2015-07-17 03:21:02 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2016-01-04 04:16:01 +13:00
|
|
|
|
Copyright (c) 2007-2016 ShareX Team
|
2015-07-17 03:21:02 +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-05-03 21:35:10 +12:00
|
|
|
|
using ShareX.HelpersLib;
|
2016-08-19 22:22:12 +12:00
|
|
|
|
using System;
|
2015-07-17 03:21:02 +12:00
|
|
|
|
using System.Drawing;
|
2016-05-03 21:35:10 +12:00
|
|
|
|
using System.Drawing.Drawing2D;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
using System.Windows.Forms;
|
2015-07-17 03:21:02 +12:00
|
|
|
|
|
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
|
|
|
|
{
|
2016-08-19 22:22:12 +12:00
|
|
|
|
public abstract class BaseShape : IDisposable
|
2015-07-17 03:21:02 +12:00
|
|
|
|
{
|
2016-05-24 04:18:09 +12:00
|
|
|
|
protected const int MinimumSize = 3;
|
2016-05-23 11:18:29 +12:00
|
|
|
|
|
2016-05-03 23:06:15 +12:00
|
|
|
|
public abstract ShapeType ShapeType { get; }
|
2016-05-07 01:02:46 +12:00
|
|
|
|
|
2016-05-03 19:46:45 +12:00
|
|
|
|
public Rectangle Rectangle { get; set; }
|
2016-05-06 11:23:18 +12:00
|
|
|
|
|
2016-08-09 10:24:17 +12:00
|
|
|
|
protected AnnotationOptions AnnotationOptions => Manager.Config.AnnotationOptions;
|
2016-05-21 05:01:00 +12:00
|
|
|
|
|
2016-05-06 11:23:18 +12:00
|
|
|
|
private Point startPosition;
|
|
|
|
|
|
|
|
|
|
public Point StartPosition
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return startPosition;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
startPosition = value;
|
|
|
|
|
|
|
|
|
|
Rectangle = CaptureHelpers.CreateRectangle(StartPosition, EndPosition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Point endPosition;
|
|
|
|
|
|
|
|
|
|
public Point EndPosition
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return endPosition;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
endPosition = value;
|
|
|
|
|
|
|
|
|
|
Rectangle = CaptureHelpers.CreateRectangle(StartPosition, EndPosition);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-17 03:21:02 +12:00
|
|
|
|
|
2016-08-09 10:24:17 +12:00
|
|
|
|
public virtual bool IsValidShape => !Rectangle.IsEmpty && Rectangle.Width >= MinimumSize && Rectangle.Height >= MinimumSize;
|
2016-05-23 11:18:29 +12:00
|
|
|
|
|
2016-08-09 09:15:52 +12:00
|
|
|
|
public virtual bool IsRegionShape { get; } = false;
|
|
|
|
|
|
2016-08-15 11:02:27 +12:00
|
|
|
|
public virtual bool ShowResizeNodes { get; } = true;
|
|
|
|
|
|
2016-08-06 02:20:08 +12:00
|
|
|
|
public virtual bool FixedSize { get; } = false;
|
2016-08-06 01:48:46 +12:00
|
|
|
|
|
2016-08-06 00:10:05 +12:00
|
|
|
|
internal ShapeManager Manager { get; set; }
|
|
|
|
|
|
2016-08-10 04:16:48 +12:00
|
|
|
|
private Point tempNodePos, tempStartPos, tempEndPos;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
|
2016-05-29 22:10:48 +12:00
|
|
|
|
public virtual bool Intersects(Point position)
|
|
|
|
|
{
|
|
|
|
|
return Rectangle.Contains(position);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public void AddShapePath(GraphicsPath gp, int sizeOffset = 0)
|
2016-05-11 10:17:51 +12:00
|
|
|
|
{
|
2016-08-03 17:35:34 +12:00
|
|
|
|
Rectangle rect = Rectangle;
|
2016-05-03 21:35:10 +12:00
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
if (sizeOffset != 0)
|
|
|
|
|
{
|
|
|
|
|
rect = rect.SizeOffset(sizeOffset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnShapePathRequested(gp, rect);
|
2016-05-03 21:35:10 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 21:01:39 +12:00
|
|
|
|
public virtual void Move(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
Rectangle = Rectangle.LocationOffset(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Move(Point point)
|
|
|
|
|
{
|
|
|
|
|
Move(point.X, point.Y);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 21:15:26 +12:00
|
|
|
|
public virtual void Resize(int x, int y, bool fromBottomRight)
|
|
|
|
|
{
|
|
|
|
|
if (fromBottomRight)
|
|
|
|
|
{
|
|
|
|
|
Rectangle = Rectangle.SizeOffset(x, y);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Rectangle = Rectangle.LocationOffset(x, y).SizeOffset(-x, -y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public virtual void OnCreated()
|
2016-05-03 21:35:10 +12:00
|
|
|
|
{
|
|
|
|
|
}
|
2016-05-20 10:13:19 +12:00
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public virtual void OnUpdate()
|
2016-05-21 05:01:00 +12:00
|
|
|
|
{
|
2016-08-06 00:10:05 +12:00
|
|
|
|
if (Manager.IsCreating)
|
2016-08-03 17:35:34 +12:00
|
|
|
|
{
|
2016-08-05 20:43:52 +12:00
|
|
|
|
Point pos = InputManager.MousePosition0Based;
|
2016-08-03 17:35:34 +12:00
|
|
|
|
|
|
|
|
|
if (Manager.IsCornerMoving)
|
|
|
|
|
{
|
2016-08-05 22:13:16 +12:00
|
|
|
|
StartPosition = StartPosition.Add(InputManager.MouseVelocity);
|
2016-08-03 17:35:34 +12:00
|
|
|
|
}
|
|
|
|
|
else if (Manager.IsProportionalResizing)
|
|
|
|
|
{
|
2016-08-06 02:20:08 +12:00
|
|
|
|
float degree, startDegree;
|
|
|
|
|
|
|
|
|
|
if (ShapeType == ShapeType.DrawingLine || ShapeType == ShapeType.DrawingArrow)
|
2016-08-03 17:35:34 +12:00
|
|
|
|
{
|
2016-08-06 02:20:08 +12:00
|
|
|
|
degree = 45;
|
|
|
|
|
startDegree = 0;
|
2016-08-03 17:35:34 +12:00
|
|
|
|
}
|
2016-08-06 02:20:08 +12:00
|
|
|
|
else
|
2016-08-03 17:35:34 +12:00
|
|
|
|
{
|
2016-08-06 02:20:08 +12:00
|
|
|
|
degree = 90;
|
|
|
|
|
startDegree = 45;
|
2016-08-03 17:35:34 +12:00
|
|
|
|
}
|
2016-08-06 02:20:08 +12:00
|
|
|
|
|
|
|
|
|
pos = CaptureHelpers.SnapPositionToDegree(StartPosition, pos, degree, startDegree);
|
2016-08-03 17:35:34 +12:00
|
|
|
|
}
|
|
|
|
|
else if (Manager.IsSnapResizing)
|
|
|
|
|
{
|
2016-08-05 20:43:52 +12:00
|
|
|
|
pos = Manager.SnapPosition(StartPosition, pos);
|
2016-08-03 17:35:34 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 20:43:52 +12:00
|
|
|
|
EndPosition = pos;
|
2016-08-03 17:35:34 +12:00
|
|
|
|
}
|
2016-08-03 20:45:12 +12:00
|
|
|
|
else if (Manager.IsMoving)
|
|
|
|
|
{
|
2016-08-03 21:01:39 +12:00
|
|
|
|
Move(InputManager.MouseVelocity);
|
2016-08-03 20:45:12 +12:00
|
|
|
|
}
|
2016-05-21 05:01:00 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public virtual void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
|
2016-05-21 09:09:09 +12:00
|
|
|
|
{
|
2016-08-03 17:35:34 +12:00
|
|
|
|
gp.AddRectangle(rect);
|
2016-05-21 09:09:09 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public virtual void OnConfigLoad()
|
2016-08-03 12:48:11 +12:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public virtual void OnConfigSave()
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public virtual void OnDoubleClicked()
|
2016-05-20 10:13:19 +12:00
|
|
|
|
{
|
|
|
|
|
}
|
2016-08-06 01:35:44 +12:00
|
|
|
|
|
|
|
|
|
public virtual void OnNodeVisible()
|
|
|
|
|
{
|
2016-08-17 20:35:06 +12:00
|
|
|
|
foreach (ResizeNode node in Manager.ResizeNodes)
|
2016-08-06 01:35:44 +12:00
|
|
|
|
{
|
|
|
|
|
node.Shape = NodeShape.Square;
|
|
|
|
|
node.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void OnNodeUpdate()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
|
{
|
2016-08-17 20:35:06 +12:00
|
|
|
|
ResizeNode node = Manager.ResizeNodes[i];
|
2016-08-10 04:16:48 +12:00
|
|
|
|
|
|
|
|
|
if (node.IsDragging)
|
2016-08-06 01:35:44 +12:00
|
|
|
|
{
|
|
|
|
|
Manager.IsResizing = true;
|
|
|
|
|
|
|
|
|
|
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
|
|
|
|
|
{
|
2016-08-10 04:16:48 +12:00
|
|
|
|
tempNodePos = node.Position;
|
|
|
|
|
tempStartPos = Rectangle.Location;
|
|
|
|
|
tempEndPos = new Point(Rectangle.X + Rectangle.Width - 1, Rectangle.Y + Rectangle.Height - 1);
|
2016-08-06 01:35:44 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-10 04:16:48 +12:00
|
|
|
|
Point pos = InputManager.MousePosition0Based;
|
|
|
|
|
Point startPos = tempStartPos;
|
|
|
|
|
Point endPos = tempEndPos;
|
|
|
|
|
|
2016-08-06 01:35:44 +12:00
|
|
|
|
NodePosition nodePosition = (NodePosition)i;
|
|
|
|
|
|
2016-08-10 04:16:48 +12:00
|
|
|
|
int x = pos.X - tempNodePos.X;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
|
|
|
|
|
switch (nodePosition)
|
|
|
|
|
{
|
|
|
|
|
case NodePosition.TopLeft:
|
|
|
|
|
case NodePosition.Left:
|
|
|
|
|
case NodePosition.BottomLeft:
|
2016-08-10 04:16:48 +12:00
|
|
|
|
startPos.X += x;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
break;
|
|
|
|
|
case NodePosition.TopRight:
|
|
|
|
|
case NodePosition.Right:
|
|
|
|
|
case NodePosition.BottomRight:
|
2016-08-10 04:16:48 +12:00
|
|
|
|
endPos.X += x;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-10 04:16:48 +12:00
|
|
|
|
int y = pos.Y - tempNodePos.Y;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
|
|
|
|
|
switch (nodePosition)
|
|
|
|
|
{
|
|
|
|
|
case NodePosition.TopLeft:
|
|
|
|
|
case NodePosition.Top:
|
|
|
|
|
case NodePosition.TopRight:
|
2016-08-10 04:16:48 +12:00
|
|
|
|
startPos.Y += y;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
break;
|
|
|
|
|
case NodePosition.BottomLeft:
|
|
|
|
|
case NodePosition.Bottom:
|
|
|
|
|
case NodePosition.BottomRight:
|
2016-08-10 04:16:48 +12:00
|
|
|
|
endPos.Y += y;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-10 04:16:48 +12:00
|
|
|
|
Rectangle = CaptureHelpers.CreateRectangle(startPos, endPos);
|
2016-08-06 01:35:44 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void OnNodePositionUpdate()
|
|
|
|
|
{
|
|
|
|
|
int xStart = Rectangle.X;
|
|
|
|
|
int xMid = Rectangle.X + Rectangle.Width / 2;
|
|
|
|
|
int xEnd = Rectangle.X + Rectangle.Width - 1;
|
|
|
|
|
|
|
|
|
|
int yStart = Rectangle.Y;
|
|
|
|
|
int yMid = Rectangle.Y + Rectangle.Height / 2;
|
|
|
|
|
int yEnd = Rectangle.Y + Rectangle.Height - 1;
|
|
|
|
|
|
2016-08-17 20:35:06 +12:00
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.TopLeft].Position = new Point(xStart, yStart);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Top].Position = new Point(xMid, yStart);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.TopRight].Position = new Point(xEnd, yStart);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Right].Position = new Point(xEnd, yMid);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.BottomRight].Position = new Point(xEnd, yEnd);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Bottom].Position = new Point(xMid, yEnd);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.BottomLeft].Position = new Point(xStart, yEnd);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Left].Position = new Point(xStart, yMid);
|
2016-08-06 01:35:44 +12:00
|
|
|
|
}
|
2016-08-19 22:22:12 +12:00
|
|
|
|
|
|
|
|
|
public virtual void Dispose()
|
|
|
|
|
{
|
|
|
|
|
}
|
2015-07-17 03:21:02 +12:00
|
|
|
|
}
|
|
|
|
|
}
|