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;
|
2015-07-17 03:21:02 +12:00
|
|
|
|
using System.Drawing;
|
2016-05-03 21:35:10 +12:00
|
|
|
|
using System.Drawing.Drawing2D;
|
2015-07-17 03:21:02 +12:00
|
|
|
|
|
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
|
|
|
|
{
|
2016-05-03 22:48:37 +12:00
|
|
|
|
public abstract class BaseShape
|
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-06 10:15:41 +12:00
|
|
|
|
public virtual NodeType NodeType { get; } = NodeType.Rectangle;
|
2016-05-03 23:06:15 +12:00
|
|
|
|
|
2016-05-03 19:46:45 +12:00
|
|
|
|
public Rectangle Rectangle { get; set; }
|
2016-05-06 11:23:18 +12:00
|
|
|
|
|
2016-05-20 11:53:45 +12:00
|
|
|
|
public ShapeManager Manager { get; set; }
|
|
|
|
|
|
2016-05-21 05:34:45 +12:00
|
|
|
|
protected AnnotationOptions AnnotationOptions
|
2016-05-21 05:01:00 +12:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-05-21 05:34:45 +12:00
|
|
|
|
return 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-05-24 04:18:09 +12:00
|
|
|
|
public virtual bool IsValidShape
|
2016-05-23 11:18:29 +12:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return !Rectangle.IsEmpty && Rectangle.Width >= MinimumSize && Rectangle.Height >= MinimumSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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 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-03 20:45:12 +12:00
|
|
|
|
if (Manager.IsCreating && !Rectangle.IsEmpty)
|
2016-08-03 17:35:34 +12:00
|
|
|
|
{
|
|
|
|
|
Point currentPosition = InputManager.MousePosition0Based;
|
|
|
|
|
|
|
|
|
|
if (Manager.IsCornerMoving)
|
|
|
|
|
{
|
|
|
|
|
StartPosition = StartPosition.Add(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
|
|
|
|
|
}
|
|
|
|
|
else if (Manager.IsProportionalResizing)
|
|
|
|
|
{
|
|
|
|
|
if (NodeType == NodeType.Rectangle)
|
|
|
|
|
{
|
|
|
|
|
currentPosition = CaptureHelpers.SnapPositionToDegree(StartPosition, currentPosition, 90, 45);
|
|
|
|
|
}
|
|
|
|
|
else if (NodeType == NodeType.Line)
|
|
|
|
|
{
|
|
|
|
|
currentPosition = CaptureHelpers.SnapPositionToDegree(StartPosition, currentPosition, 45, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (Manager.IsSnapResizing)
|
|
|
|
|
{
|
|
|
|
|
currentPosition = Manager.SnapPosition(StartPosition, currentPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndPosition = currentPosition;
|
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
|
}
|
2015-07-17 03:21:02 +12:00
|
|
|
|
}
|
|
|
|
|
}
|