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
|
2022-01-12 05:32:17 +13:00
|
|
|
|
Copyright (c) 2007-2022 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-09-02 19:09:24 +12:00
|
|
|
|
public abstract ShapeCategory ShapeCategory { get; }
|
|
|
|
|
|
2016-05-03 23:06:15 +12:00
|
|
|
|
public abstract ShapeType ShapeType { get; }
|
2016-05-07 01:02:46 +12:00
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
private RectangleF rectangle;
|
2016-05-06 11:23:18 +12:00
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public RectangleF Rectangle
|
2017-11-15 19:54:19 +13:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return rectangle;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
rectangle = value;
|
|
|
|
|
startPosition = rectangle.Location;
|
2022-02-20 19:30:39 +13:00
|
|
|
|
endPosition = new PointF(rectangle.X + rectangle.Width - 1, rectangle.Y + rectangle.Height - 1);
|
2017-11-15 19:54:19 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public RectangleF RectangleInsideCanvas => RectangleF.Intersect(Rectangle, Manager.Form.CanvasRectangle);
|
2017-11-15 01:05:12 +13:00
|
|
|
|
|
|
|
|
|
public bool IsInsideCanvas => !RectangleInsideCanvas.IsEmpty;
|
|
|
|
|
|
2017-12-13 12:02:00 +13:00
|
|
|
|
public virtual bool LimitRectangleToInsideCanvas { get; }
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
private PointF startPosition;
|
2016-05-06 11:23:18 +12:00
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public PointF StartPosition
|
2016-05-06 11:23:18 +12:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return startPosition;
|
|
|
|
|
}
|
2017-11-16 22:40:56 +13:00
|
|
|
|
private set
|
2016-05-06 11:23:18 +12:00
|
|
|
|
{
|
|
|
|
|
startPosition = value;
|
2017-11-15 19:54:19 +13:00
|
|
|
|
rectangle = CaptureHelpers.CreateRectangle(startPosition, endPosition);
|
2016-05-06 11:23:18 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
private PointF endPosition;
|
2016-05-06 11:23:18 +12:00
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public PointF EndPosition
|
2016-05-06 11:23:18 +12:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return endPosition;
|
|
|
|
|
}
|
2017-11-16 22:40:56 +13:00
|
|
|
|
private set
|
2016-05-06 11:23:18 +12:00
|
|
|
|
{
|
|
|
|
|
endPosition = value;
|
2017-11-15 19:54:19 +13:00
|
|
|
|
rectangle = CaptureHelpers.CreateRectangle(startPosition, endPosition);
|
2016-05-06 11:23:18 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-17 03:21:02 +12:00
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public SizeF InitialSize { get; set; }
|
2017-11-21 06:57:47 +13:00
|
|
|
|
|
2019-07-22 12:17:18 +12:00
|
|
|
|
public virtual bool IsValidShape => !Rectangle.IsEmpty && Rectangle.Width >= Options.MinimumSize && Rectangle.Height >= Options.MinimumSize;
|
2016-05-23 11:18:29 +12:00
|
|
|
|
|
2019-04-16 01:45:37 +12:00
|
|
|
|
public virtual bool IsSelectable => Manager.CurrentTool == ShapeType || Manager.CurrentTool == ShapeType.ToolSelect;
|
|
|
|
|
|
2019-05-03 20:01:09 +12:00
|
|
|
|
public bool ForceProportionalResizing { get; protected set; }
|
|
|
|
|
|
2016-08-06 00:10:05 +12:00
|
|
|
|
internal ShapeManager Manager { get; set; }
|
|
|
|
|
|
2017-10-24 10:40:37 +13:00
|
|
|
|
protected InputManager InputManager => Manager.InputManager;
|
2017-11-07 05:01:02 +13:00
|
|
|
|
protected RegionCaptureOptions Options => Manager.Options;
|
|
|
|
|
protected AnnotationOptions AnnotationOptions => Manager.Options.AnnotationOptions;
|
2016-08-24 01:03:48 +12:00
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
private PointF tempNodePos, tempStartPos, tempEndPos;
|
|
|
|
|
private RectangleF tempRectangle;
|
2016-08-06 01:35:44 +12:00
|
|
|
|
|
2019-04-16 06:29:22 +12:00
|
|
|
|
public bool IsHandledBySelectTool
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (ShapeCategory)
|
|
|
|
|
{
|
|
|
|
|
case ShapeCategory.Drawing:
|
|
|
|
|
case ShapeCategory.Effect:
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public virtual bool Intersects(PointF position)
|
2016-05-29 22:10:48 +12:00
|
|
|
|
{
|
|
|
|
|
return Rectangle.Contains(position);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-23 22:20:55 +12:00
|
|
|
|
internal void ChangeNodeShape(NodeShape nodeShape)
|
|
|
|
|
{
|
|
|
|
|
foreach (ResizeNode node in Manager.ResizeNodes)
|
|
|
|
|
{
|
|
|
|
|
node.Shape = nodeShape;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-30 02:49:50 +12:00
|
|
|
|
protected virtual void UseLightResizeNodes()
|
2018-08-23 22:20:55 +12:00
|
|
|
|
{
|
|
|
|
|
ChangeNodeShape(NodeShape.Square);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void UpdateNodeShape()
|
|
|
|
|
{
|
2018-08-30 02:49:50 +12:00
|
|
|
|
if (Options.UseLightResizeNodes)
|
2018-08-23 22:20:55 +12:00
|
|
|
|
{
|
2018-08-30 02:49:50 +12:00
|
|
|
|
UseLightResizeNodes();
|
2018-08-23 22:20:55 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ChangeNodeShape(NodeShape.CustomNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:59:53 +12:00
|
|
|
|
public virtual void ShowNodes()
|
|
|
|
|
{
|
2018-08-23 22:20:55 +12:00
|
|
|
|
UpdateNodeShape();
|
2016-08-25 01:59:53 +12:00
|
|
|
|
Manager.NodesVisible = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-14 00:21:48 +12:00
|
|
|
|
public virtual void Remove()
|
2016-08-24 01:39:15 +12:00
|
|
|
|
{
|
|
|
|
|
Manager.DeleteShape(this);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 17:35:34 +12:00
|
|
|
|
public void AddShapePath(GraphicsPath gp, int sizeOffset = 0)
|
2016-05-11 10:17:51 +12:00
|
|
|
|
{
|
2022-02-20 19:30:39 +13:00
|
|
|
|
RectangleF 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
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public virtual void Move(float x, float y)
|
2016-08-03 21:01:39 +12:00
|
|
|
|
{
|
2017-11-16 23:42:13 +13:00
|
|
|
|
StartPosition = StartPosition.Add(x, y);
|
|
|
|
|
EndPosition = EndPosition.Add(x, y);
|
2016-08-03 21:01:39 +12:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public void Move(PointF offset)
|
2016-08-03 21:01:39 +12:00
|
|
|
|
{
|
2017-10-18 03:44:46 +13:00
|
|
|
|
Move(offset.X, offset.Y);
|
2016-08-03 21:01:39 +12:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public void MoveAbsolute(float x, float y, bool center = false)
|
2020-09-16 07:12:57 +12:00
|
|
|
|
{
|
|
|
|
|
if (center)
|
|
|
|
|
{
|
|
|
|
|
x -= Rectangle.Size.Width / 2;
|
|
|
|
|
y -= Rectangle.Size.Height / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Move(x - Rectangle.X, y - Rectangle.Y);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public void MoveAbsolute(PointF point, bool center = false)
|
2020-09-16 07:12:57 +12:00
|
|
|
|
{
|
|
|
|
|
MoveAbsolute(point.X, point.Y, center);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 21:15:26 +12:00
|
|
|
|
public virtual void Resize(int x, int y, bool fromBottomRight)
|
|
|
|
|
{
|
|
|
|
|
if (fromBottomRight)
|
|
|
|
|
{
|
2017-11-16 19:36:21 +13:00
|
|
|
|
Rectangle = Rectangle.SizeOffset(x, y);
|
2016-08-03 21:15:26 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-11-16 19:36:21 +13:00
|
|
|
|
Rectangle = Rectangle.LocationOffset(x, y).SizeOffset(-x, -y);
|
2016-08-03 21:15:26 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 14:00:05 +12:00
|
|
|
|
public virtual BaseShape Duplicate()
|
|
|
|
|
{
|
|
|
|
|
ShapeManager manager = Manager;
|
|
|
|
|
Manager = null;
|
|
|
|
|
BaseShape shape = this.Copy();
|
|
|
|
|
Manager = manager;
|
|
|
|
|
shape.Manager = manager;
|
|
|
|
|
return shape;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-24 01:03:48 +12:00
|
|
|
|
public virtual void OnCreating()
|
|
|
|
|
{
|
2022-02-20 19:30:39 +13:00
|
|
|
|
PointF pos = Manager.Form.ScaledClientMousePosition;
|
2016-08-24 01:03:48 +12:00
|
|
|
|
|
2016-09-02 19:09:24 +12:00
|
|
|
|
if (Options.IsFixedSize && ShapeCategory == ShapeCategory.Region)
|
2016-08-24 01:03:48 +12:00
|
|
|
|
{
|
|
|
|
|
Manager.IsMoving = true;
|
2022-02-20 19:30:39 +13:00
|
|
|
|
Rectangle = new RectangleF(new PointF(pos.X - (Options.FixedSize.Width / 2), pos.Y - (Options.FixedSize.Height / 2)), Options.FixedSize);
|
2018-06-17 18:24:00 +12:00
|
|
|
|
OnCreated();
|
2016-08-24 01:03:48 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Manager.IsCreating = true;
|
2022-02-20 19:30:39 +13:00
|
|
|
|
Rectangle = new RectangleF(pos.X, pos.Y, 1, 1);
|
2016-08-24 01:03:48 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 07:25:18 +13:00
|
|
|
|
public virtual void OnCreated()
|
|
|
|
|
{
|
|
|
|
|
InitialSize = Rectangle.Size;
|
2021-10-23 13:07:07 +13:00
|
|
|
|
|
|
|
|
|
if (ShapeCategory == ShapeCategory.Drawing || ShapeCategory == ShapeCategory.Effect)
|
|
|
|
|
{
|
|
|
|
|
Manager.OnImageModified();
|
|
|
|
|
}
|
2017-11-21 07:25:18 +13:00
|
|
|
|
}
|
2017-11-14 22:12:49 +13:00
|
|
|
|
|
2018-03-01 11:52:11 +13:00
|
|
|
|
public virtual void OnMoving()
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-11-14 22:12:49 +13:00
|
|
|
|
|
2018-03-01 11:52:11 +13:00
|
|
|
|
public virtual void OnMoved()
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-05-20 10:13:19 +12:00
|
|
|
|
|
2018-03-01 11:52:11 +13:00
|
|
|
|
public virtual void OnResizing()
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-11-14 23:55:05 +13:00
|
|
|
|
|
2018-03-01 11:52:11 +13:00
|
|
|
|
public virtual void OnResized()
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-11-14 23:55:05 +13: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
|
|
|
|
{
|
2022-02-20 19:30:39 +13:00
|
|
|
|
PointF pos = Manager.Form.ScaledClientMousePosition;
|
2016-08-03 17:35:34 +12:00
|
|
|
|
|
2017-11-07 19:24:04 +13:00
|
|
|
|
if (Manager.IsCornerMoving && !Manager.IsPanning)
|
2016-08-03 17:35:34 +12:00
|
|
|
|
{
|
2022-02-01 14:01:18 +13:00
|
|
|
|
StartPosition = StartPosition.Add(Manager.Form.ScaledClientMouseVelocity);
|
2016-08-03 17:35:34 +12:00
|
|
|
|
}
|
2018-12-19 22:30:15 +13:00
|
|
|
|
|
2019-05-03 20:01:09 +12:00
|
|
|
|
if (Manager.IsProportionalResizing || ForceProportionalResizing)
|
2016-08-03 17:35:34 +12:00
|
|
|
|
{
|
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
|
|
|
|
}
|
2017-11-07 19:24:04 +13:00
|
|
|
|
else if (Manager.IsMoving && !Manager.IsPanning)
|
2016-08-03 20:45:12 +12:00
|
|
|
|
{
|
2022-02-01 14:01:18 +13:00
|
|
|
|
Move(Manager.Form.ScaledClientMouseVelocity);
|
2016-08-03 20:45:12 +12:00
|
|
|
|
}
|
2017-12-13 12:02:00 +13:00
|
|
|
|
|
|
|
|
|
if (LimitRectangleToInsideCanvas)
|
|
|
|
|
{
|
2017-12-13 12:22:24 +13:00
|
|
|
|
StartPosition = StartPosition.Restrict(Manager.Form.CanvasRectangle);
|
|
|
|
|
EndPosition = EndPosition.Restrict(Manager.Form.CanvasRectangle);
|
2017-12-13 12:02:00 +13:00
|
|
|
|
}
|
2016-05-21 05:01:00 +12:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
public virtual void OnShapePathRequested(GraphicsPath gp, RectangleF 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-25 01:29:50 +12:00
|
|
|
|
for (int i = 0; i < 8; i++)
|
2016-08-06 01:35:44 +12:00
|
|
|
|
{
|
2016-08-25 01:29:50 +12:00
|
|
|
|
ResizeNode node = Manager.ResizeNodes[i];
|
2016-08-06 01:35:44 +12:00
|
|
|
|
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;
|
2017-11-21 08:31:16 +13:00
|
|
|
|
tempStartPos = Rectangle.Location;
|
2022-02-20 19:30:39 +13:00
|
|
|
|
tempEndPos = new PointF(Rectangle.X + Rectangle.Width - 1, Rectangle.Y + Rectangle.Height - 1);
|
2017-11-21 07:25:18 +13:00
|
|
|
|
tempRectangle = Rectangle;
|
2017-11-15 00:21:36 +13:00
|
|
|
|
|
|
|
|
|
OnResizing();
|
2016-08-06 01:35:44 +12:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 19:24:04 +13:00
|
|
|
|
if (Manager.IsCornerMoving || Manager.IsPanning)
|
|
|
|
|
{
|
2022-02-01 14:01:18 +13:00
|
|
|
|
tempStartPos.Offset(Manager.Form.ScaledClientMouseVelocity);
|
|
|
|
|
tempEndPos.Offset(Manager.Form.ScaledClientMouseVelocity);
|
|
|
|
|
tempNodePos.Offset(Manager.Form.ScaledClientMouseVelocity);
|
|
|
|
|
tempRectangle.LocationOffset(Manager.Form.ScaledClientMouseVelocity);
|
2017-11-07 19:24:04 +13:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
PointF pos = Manager.Form.ScaledClientMousePosition;
|
|
|
|
|
PointF startPos = tempStartPos;
|
|
|
|
|
PointF endPos = tempEndPos;
|
2016-08-10 04:16:48 +12:00
|
|
|
|
|
2016-08-06 01:35:44 +12:00
|
|
|
|
NodePosition nodePosition = (NodePosition)i;
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
float 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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
float 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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 19:24:04 +13:00
|
|
|
|
StartPosition = startPos;
|
|
|
|
|
EndPosition = endPos;
|
2017-11-21 06:57:47 +13:00
|
|
|
|
|
2017-12-01 19:33:08 +13:00
|
|
|
|
if (Manager.IsProportionalResizing && !InitialSize.IsEmpty)
|
2017-11-21 06:57:47 +13:00
|
|
|
|
{
|
2017-11-21 08:31:53 +13:00
|
|
|
|
switch (nodePosition)
|
|
|
|
|
{
|
|
|
|
|
case NodePosition.Top:
|
|
|
|
|
case NodePosition.Right:
|
|
|
|
|
case NodePosition.Bottom:
|
|
|
|
|
case NodePosition.Left:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 06:57:47 +13:00
|
|
|
|
double ratio = Math.Min(Rectangle.Width / (double)InitialSize.Width, Rectangle.Height / (double)InitialSize.Height);
|
2017-11-21 07:25:18 +13:00
|
|
|
|
int newWidth = (int)Math.Round(InitialSize.Width * ratio);
|
|
|
|
|
int newHeight = (int)Math.Round(InitialSize.Height * ratio);
|
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
PointF anchor = new PointF();
|
2017-11-21 07:25:18 +13:00
|
|
|
|
|
|
|
|
|
switch (nodePosition)
|
|
|
|
|
{
|
|
|
|
|
case NodePosition.TopLeft:
|
|
|
|
|
case NodePosition.Left:
|
|
|
|
|
case NodePosition.BottomLeft:
|
|
|
|
|
anchor.X = tempRectangle.Right - 1;
|
|
|
|
|
break;
|
|
|
|
|
case NodePosition.TopRight:
|
|
|
|
|
case NodePosition.Right:
|
|
|
|
|
case NodePosition.BottomRight:
|
|
|
|
|
anchor.X = tempRectangle.X;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (nodePosition)
|
|
|
|
|
{
|
|
|
|
|
case NodePosition.TopLeft:
|
|
|
|
|
case NodePosition.Top:
|
|
|
|
|
case NodePosition.TopRight:
|
|
|
|
|
anchor.Y = tempRectangle.Bottom - 1;
|
|
|
|
|
break;
|
|
|
|
|
case NodePosition.BottomLeft:
|
|
|
|
|
case NodePosition.Bottom:
|
|
|
|
|
case NodePosition.BottomRight:
|
|
|
|
|
anchor.Y = tempRectangle.Y;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-11-21 06:57:47 +13:00
|
|
|
|
|
2022-02-20 19:30:39 +13:00
|
|
|
|
RectangleF newRect = Rectangle;
|
2017-11-21 06:57:47 +13:00
|
|
|
|
|
2017-11-21 07:25:18 +13:00
|
|
|
|
if (pos.X < anchor.X)
|
2017-11-21 06:57:47 +13:00
|
|
|
|
{
|
2017-11-21 07:25:18 +13:00
|
|
|
|
newRect.X = newRect.Right - newWidth;
|
2017-11-21 06:57:47 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 07:25:18 +13:00
|
|
|
|
newRect.Width = newWidth;
|
2017-11-21 06:57:47 +13:00
|
|
|
|
|
2017-11-21 07:25:18 +13:00
|
|
|
|
if (pos.Y < anchor.Y)
|
2017-11-21 06:57:47 +13:00
|
|
|
|
{
|
2017-11-21 07:25:18 +13:00
|
|
|
|
newRect.Y = newRect.Bottom - newHeight;
|
2017-11-21 06:57:47 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 07:25:18 +13:00
|
|
|
|
newRect.Height = newHeight;
|
2017-11-21 06:57:47 +13:00
|
|
|
|
|
|
|
|
|
Rectangle = newRect;
|
|
|
|
|
}
|
2017-12-13 12:02:00 +13:00
|
|
|
|
|
2017-12-13 12:22:24 +13:00
|
|
|
|
if (LimitRectangleToInsideCanvas)
|
|
|
|
|
{
|
|
|
|
|
Rectangle = RectangleInsideCanvas;
|
|
|
|
|
}
|
2016-08-06 01:35:44 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void OnNodePositionUpdate()
|
|
|
|
|
{
|
2022-02-20 19:30:39 +13:00
|
|
|
|
float xStart = Rectangle.X;
|
|
|
|
|
float xMid = Rectangle.X + (Rectangle.Width / 2);
|
|
|
|
|
float xEnd = Rectangle.X + Rectangle.Width - 1;
|
|
|
|
|
|
|
|
|
|
float yStart = Rectangle.Y;
|
|
|
|
|
float yMid = Rectangle.Y + (Rectangle.Height / 2);
|
|
|
|
|
float yEnd = Rectangle.Y + Rectangle.Height - 1;
|
|
|
|
|
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.TopLeft].Position = new PointF(xStart, yStart);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Top].Position = new PointF(xMid, yStart);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.TopRight].Position = new PointF(xEnd, yStart);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Right].Position = new PointF(xEnd, yMid);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.BottomRight].Position = new PointF(xEnd, yEnd);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Bottom].Position = new PointF(xMid, yEnd);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.BottomLeft].Position = new PointF(xStart, yEnd);
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Left].Position = new PointF(xStart, yMid);
|
2017-05-12 19:13:50 +12:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
Manager.ResizeNodes[i].Visible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Manager.ResizeNodes[(int)NodePosition.Right].Rectangle.IntersectsWith(Manager.ResizeNodes[(int)NodePosition.BottomRight].Rectangle))
|
|
|
|
|
{
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Left].Visible =
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Right].Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Manager.ResizeNodes[(int)NodePosition.Bottom].Rectangle.IntersectsWith(Manager.ResizeNodes[(int)NodePosition.BottomRight].Rectangle))
|
|
|
|
|
{
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Top].Visible =
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Bottom].Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Manager.ResizeNodes[(int)NodePosition.TopRight].Rectangle.IntersectsWith(Manager.ResizeNodes[(int)NodePosition.BottomRight].Rectangle))
|
|
|
|
|
{
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.TopLeft].Visible =
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Top].Visible =
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.TopRight].Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Manager.ResizeNodes[(int)NodePosition.BottomLeft].Rectangle.IntersectsWith(Manager.ResizeNodes[(int)NodePosition.BottomRight].Rectangle))
|
|
|
|
|
{
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.TopLeft].Visible =
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.Left].Visible =
|
|
|
|
|
Manager.ResizeNodes[(int)NodePosition.BottomLeft].Visible = false;
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|