2013-11-03 23:53:49 +13: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
|
2013-11-03 23:53:49 +13: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)
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.HelpersLib;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
public class ResizeManager
|
|
|
|
|
{
|
|
|
|
|
private bool visible;
|
|
|
|
|
|
|
|
|
|
public bool Visible
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return visible;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
visible = value;
|
|
|
|
|
|
2016-05-06 10:15:41 +12:00
|
|
|
|
if (!visible)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-06 10:15:41 +12:00
|
|
|
|
foreach (NodeObject node in nodes)
|
|
|
|
|
{
|
|
|
|
|
node.Visible = visible;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-05-11 10:38:35 +12:00
|
|
|
|
BaseShape shape = shapeManager.CurrentShape;
|
2016-05-06 10:15:41 +12:00
|
|
|
|
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
|
|
|
|
if (shape.NodeType == NodeType.Rectangle)
|
|
|
|
|
{
|
|
|
|
|
foreach (NodeObject node in nodes)
|
|
|
|
|
{
|
|
|
|
|
node.Shape = NodeShape.Square;
|
|
|
|
|
node.Visible = visible;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (shape.NodeType == NodeType.Line)
|
|
|
|
|
{
|
|
|
|
|
nodes[(int)NodePosition.TopLeft].Shape = nodes[(int)NodePosition.BottomRight].Shape = NodeShape.Circle;
|
|
|
|
|
nodes[(int)NodePosition.TopLeft].Visible = nodes[(int)NodePosition.BottomRight].Visible = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsResizing { get; private set; }
|
|
|
|
|
public int MaxMoveSpeed { get; set; }
|
|
|
|
|
public int MinMoveSpeed { get; set; }
|
|
|
|
|
public bool IsBottomRightResizing { get; set; }
|
|
|
|
|
|
2015-08-20 05:22:07 +12:00
|
|
|
|
private bool IsUpPressed { get; set; }
|
|
|
|
|
private bool IsDownPressed { get; set; }
|
|
|
|
|
private bool IsLeftPressed { get; set; }
|
|
|
|
|
private bool IsRightPressed { get; set; }
|
|
|
|
|
|
2016-05-11 10:38:35 +12:00
|
|
|
|
private ShapeManager shapeManager;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
private NodeObject[] nodes;
|
|
|
|
|
private Rectangle tempRect;
|
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
public ResizeManager(BaseRegionForm form, ShapeManager shapeManager)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-11 10:38:35 +12:00
|
|
|
|
this.shapeManager = shapeManager;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
MinMoveSpeed = form.Config.MinMoveSpeed;
|
|
|
|
|
MaxMoveSpeed = form.Config.MaxMoveSpeed;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
form.KeyDown += form_KeyDown;
|
|
|
|
|
form.KeyUp += form_KeyUp;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
nodes = new NodeObject[8];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
|
{
|
2016-05-15 19:12:53 +12:00
|
|
|
|
nodes[i] = form.MakeNode();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nodes[(int)NodePosition.BottomRight].Order = 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2016-05-11 10:38:35 +12:00
|
|
|
|
BaseShape shape = shapeManager.CurrentShape;
|
2016-05-06 10:52:16 +12:00
|
|
|
|
|
|
|
|
|
if (shape != null && Visible && nodes != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
if (InputManager.IsMouseDown(MouseButtons.Left))
|
|
|
|
|
{
|
2016-05-06 10:52:16 +12:00
|
|
|
|
if (shape.NodeType == NodeType.Rectangle)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-06 10:52:16 +12:00
|
|
|
|
for (int i = 0; i < 8; i++)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-06 10:52:16 +12:00
|
|
|
|
if (nodes[i].IsDragging)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-06 10:52:16 +12:00
|
|
|
|
IsResizing = true;
|
|
|
|
|
|
|
|
|
|
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
|
|
|
|
|
{
|
|
|
|
|
tempRect = shape.Rectangle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NodePosition nodePosition = (NodePosition)i;
|
|
|
|
|
|
|
|
|
|
int x = InputManager.MouseVelocity.X;
|
|
|
|
|
|
|
|
|
|
switch (nodePosition)
|
|
|
|
|
{
|
|
|
|
|
case NodePosition.TopLeft:
|
|
|
|
|
case NodePosition.Left:
|
|
|
|
|
case NodePosition.BottomLeft:
|
|
|
|
|
tempRect.X += x;
|
|
|
|
|
tempRect.Width -= x;
|
|
|
|
|
break;
|
|
|
|
|
case NodePosition.TopRight:
|
|
|
|
|
case NodePosition.Right:
|
|
|
|
|
case NodePosition.BottomRight:
|
|
|
|
|
tempRect.Width += x;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int y = InputManager.MouseVelocity.Y;
|
|
|
|
|
|
|
|
|
|
switch (nodePosition)
|
|
|
|
|
{
|
|
|
|
|
case NodePosition.TopLeft:
|
|
|
|
|
case NodePosition.Top:
|
|
|
|
|
case NodePosition.TopRight:
|
|
|
|
|
tempRect.Y += y;
|
|
|
|
|
tempRect.Height -= y;
|
|
|
|
|
break;
|
|
|
|
|
case NodePosition.BottomLeft:
|
|
|
|
|
case NodePosition.Bottom:
|
|
|
|
|
case NodePosition.BottomRight:
|
|
|
|
|
tempRect.Height += y;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shape.Rectangle = CaptureHelpers.FixRectangle(tempRect);
|
|
|
|
|
|
|
|
|
|
break;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2016-05-06 10:52:16 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (shape.NodeType == NodeType.Line)
|
|
|
|
|
{
|
|
|
|
|
if (nodes[(int)NodePosition.TopLeft].IsDragging)
|
|
|
|
|
{
|
|
|
|
|
IsResizing = true;
|
2016-05-06 11:23:18 +12:00
|
|
|
|
|
2016-05-06 10:52:16 +12:00
|
|
|
|
shape.StartPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y);
|
|
|
|
|
}
|
|
|
|
|
else if (nodes[(int)NodePosition.BottomRight].IsDragging)
|
|
|
|
|
{
|
|
|
|
|
IsResizing = true;
|
2016-05-06 11:23:18 +12:00
|
|
|
|
|
2016-05-06 10:52:16 +12:00
|
|
|
|
shape.EndPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IsResizing = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateNodePositions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
private void form_KeyDown(object sender, KeyEventArgs e)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
switch (e.KeyCode)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Up:
|
2015-08-20 05:22:07 +12:00
|
|
|
|
IsUpPressed = true;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
break;
|
|
|
|
|
case Keys.Down:
|
2015-08-20 05:22:07 +12:00
|
|
|
|
IsDownPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Left:
|
|
|
|
|
IsLeftPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Right:
|
|
|
|
|
IsRightPressed = true;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
break;
|
|
|
|
|
case Keys.Tab:
|
|
|
|
|
IsBottomRightResizing = !IsBottomRightResizing;
|
2015-08-20 05:22:07 +12:00
|
|
|
|
return;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2015-08-20 05:22:07 +12:00
|
|
|
|
|
2015-08-20 05:50:21 +12:00
|
|
|
|
// Calculate cursor movement
|
2016-06-11 22:38:47 +12:00
|
|
|
|
int speed = e.Shift ? MaxMoveSpeed : MinMoveSpeed;
|
2015-08-20 05:50:21 +12:00
|
|
|
|
int y = IsUpPressed && IsDownPressed ? 0 : IsDownPressed ? speed : IsUpPressed ? -speed : 0;
|
|
|
|
|
int x = IsLeftPressed && IsRightPressed ? 0 : IsRightPressed ? speed : IsLeftPressed ? -speed : 0;
|
|
|
|
|
|
|
|
|
|
// Move the cursor
|
2016-05-11 10:38:35 +12:00
|
|
|
|
if (shapeManager.CurrentShape == null || shapeManager.IsCreating)
|
2015-08-20 05:22:07 +12:00
|
|
|
|
{
|
2016-05-10 06:45:37 +12:00
|
|
|
|
Cursor.Position = Cursor.Position.Add(x, y);
|
2015-08-20 05:50:21 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-06-11 22:38:47 +12:00
|
|
|
|
if (e.Control)
|
2015-08-20 05:50:21 +12:00
|
|
|
|
{
|
|
|
|
|
MoveCurrentArea(x, y);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ResizeCurrentArea(x, y, IsBottomRightResizing);
|
|
|
|
|
}
|
2015-08-20 05:22:07 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
private void form_KeyUp(object sender, KeyEventArgs e)
|
2015-08-20 04:39:05 +12:00
|
|
|
|
{
|
2015-08-20 05:22:07 +12:00
|
|
|
|
switch (e.KeyCode)
|
2015-08-20 04:39:05 +12:00
|
|
|
|
{
|
2015-08-20 05:22:07 +12:00
|
|
|
|
case Keys.Up:
|
|
|
|
|
IsUpPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Down:
|
|
|
|
|
IsDownPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Left:
|
|
|
|
|
IsLeftPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Right:
|
|
|
|
|
IsRightPressed = false;
|
|
|
|
|
break;
|
2015-08-20 04:39:05 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public bool IsCursorOnNode()
|
|
|
|
|
{
|
2016-05-25 05:31:40 +12:00
|
|
|
|
return Visible && nodes.Any(node => node.IsCursorHover);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Show()
|
|
|
|
|
{
|
|
|
|
|
UpdateNodePositions();
|
|
|
|
|
|
|
|
|
|
Visible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Hide()
|
|
|
|
|
{
|
|
|
|
|
Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-06 10:52:16 +12:00
|
|
|
|
private void UpdateNodePositions()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-11 10:38:35 +12:00
|
|
|
|
BaseShape shape = shapeManager.CurrentShape;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-06 10:15:41 +12:00
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
|
|
|
|
if (shape.NodeType == NodeType.Rectangle)
|
|
|
|
|
{
|
|
|
|
|
Rectangle rect = shape.Rectangle;
|
|
|
|
|
|
2016-05-25 05:31:40 +12:00
|
|
|
|
int xStart = rect.X;
|
|
|
|
|
int xMid = rect.X + rect.Width / 2;
|
|
|
|
|
int xEnd = rect.X + rect.Width - 1;
|
|
|
|
|
|
|
|
|
|
int yStart = rect.Y;
|
|
|
|
|
int yMid = rect.Y + rect.Height / 2;
|
|
|
|
|
int yEnd = rect.Y + rect.Height - 1;
|
|
|
|
|
|
|
|
|
|
nodes[(int)NodePosition.TopLeft].Position = new Point(xStart, yStart);
|
|
|
|
|
nodes[(int)NodePosition.Top].Position = new Point(xMid, yStart);
|
|
|
|
|
nodes[(int)NodePosition.TopRight].Position = new Point(xEnd, yStart);
|
|
|
|
|
nodes[(int)NodePosition.Right].Position = new Point(xEnd, yMid);
|
|
|
|
|
nodes[(int)NodePosition.BottomRight].Position = new Point(xEnd, yEnd);
|
|
|
|
|
nodes[(int)NodePosition.Bottom].Position = new Point(xMid, yEnd);
|
|
|
|
|
nodes[(int)NodePosition.BottomLeft].Position = new Point(xStart, yEnd);
|
|
|
|
|
nodes[(int)NodePosition.Left].Position = new Point(xStart, yMid);
|
2016-05-06 10:15:41 +12:00
|
|
|
|
}
|
|
|
|
|
else if (shape.NodeType == NodeType.Line)
|
|
|
|
|
{
|
|
|
|
|
nodes[(int)NodePosition.TopLeft].Position = shape.StartPosition;
|
|
|
|
|
nodes[(int)NodePosition.BottomRight].Position = shape.EndPosition;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveCurrentArea(int x, int y)
|
|
|
|
|
{
|
2016-05-11 10:38:35 +12:00
|
|
|
|
BaseShape shape = shapeManager.CurrentShape;
|
2016-05-06 11:23:18 +12:00
|
|
|
|
|
|
|
|
|
if (shape != null)
|
|
|
|
|
{
|
2016-05-23 08:19:13 +12:00
|
|
|
|
if (shape.NodeType == NodeType.Rectangle || shape.NodeType == NodeType.Point)
|
2016-05-10 10:54:11 +12:00
|
|
|
|
{
|
|
|
|
|
shape.Rectangle = shape.Rectangle.LocationOffset(x, y);
|
|
|
|
|
}
|
|
|
|
|
else if (shape.NodeType == NodeType.Line)
|
|
|
|
|
{
|
|
|
|
|
shape.StartPosition = shape.StartPosition.Add(x, y);
|
|
|
|
|
shape.EndPosition = shape.EndPosition.Add(x, y);
|
|
|
|
|
}
|
2016-05-06 11:23:18 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResizeCurrentArea(int x, int y, bool isBottomRightMoving)
|
|
|
|
|
{
|
2016-05-11 10:38:35 +12:00
|
|
|
|
BaseShape shape = shapeManager.CurrentShape;
|
2016-05-06 11:23:18 +12:00
|
|
|
|
|
|
|
|
|
if (shape != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-10 10:54:11 +12:00
|
|
|
|
if (shape.NodeType == NodeType.Rectangle)
|
2016-05-06 11:23:18 +12:00
|
|
|
|
{
|
2016-05-10 10:54:11 +12:00
|
|
|
|
if (isBottomRightMoving)
|
|
|
|
|
{
|
|
|
|
|
shape.Rectangle = shape.Rectangle.SizeOffset(x, y);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
shape.Rectangle = shape.Rectangle.LocationOffset(x, y).SizeOffset(-x, -y);
|
|
|
|
|
}
|
2016-05-06 11:23:18 +12:00
|
|
|
|
}
|
2016-05-10 10:54:11 +12:00
|
|
|
|
else if (shape.NodeType == NodeType.Line)
|
2016-05-06 11:23:18 +12:00
|
|
|
|
{
|
2016-05-10 10:54:11 +12:00
|
|
|
|
if (isBottomRightMoving)
|
|
|
|
|
{
|
|
|
|
|
shape.StartPosition = shape.StartPosition.Add(x, y);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
shape.EndPosition = shape.EndPosition.Add(x, y);
|
|
|
|
|
}
|
2016-05-06 11:23:18 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|