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;
|
|
|
|
|
}
|
2016-08-05 22:13:16 +12:00
|
|
|
|
else if (shape.NodeType == NodeType.Freehand)
|
|
|
|
|
{
|
|
|
|
|
nodes[(int)NodePosition.TopLeft].Shape = NodeShape.Circle;
|
|
|
|
|
nodes[(int)NodePosition.TopLeft].Visible = true;
|
|
|
|
|
}
|
2016-05-06 10:15:41 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsResizing { get; private set; }
|
|
|
|
|
public bool IsBottomRightResizing { get; set; }
|
|
|
|
|
|
2016-05-11 10:38:35 +12:00
|
|
|
|
private ShapeManager shapeManager;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
private NodeObject[] nodes;
|
2016-06-25 19:55:32 +12:00
|
|
|
|
private bool isUpPressed, isDownPressed, isLeftPressed, isRightPressed;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
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
|
|
|
|
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-08-05 22:13:16 +12:00
|
|
|
|
shape.StartPosition = InputManager.MousePosition0Based;
|
2016-05-06 10:52:16 +12:00
|
|
|
|
}
|
|
|
|
|
else if (nodes[(int)NodePosition.BottomRight].IsDragging)
|
|
|
|
|
{
|
|
|
|
|
IsResizing = true;
|
2016-05-06 11:23:18 +12:00
|
|
|
|
|
2016-08-05 22:13:16 +12:00
|
|
|
|
shape.EndPosition = InputManager.MousePosition0Based;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (shape.NodeType == NodeType.Freehand)
|
|
|
|
|
{
|
|
|
|
|
if (nodes[(int)NodePosition.TopLeft].IsDragging)
|
|
|
|
|
{
|
|
|
|
|
shapeManager.IsCreating = true;
|
|
|
|
|
|
|
|
|
|
Hide();
|
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)
|
|
|
|
|
{
|
2015-08-20 05:22:07 +12:00
|
|
|
|
case Keys.Left:
|
2016-07-17 18:25:53 +12:00
|
|
|
|
case Keys.A:
|
2016-06-25 19:55:32 +12:00
|
|
|
|
isLeftPressed = true;
|
2015-08-20 05:22:07 +12:00
|
|
|
|
break;
|
|
|
|
|
case Keys.Right:
|
2016-07-17 18:25:53 +12:00
|
|
|
|
case Keys.D:
|
2016-06-25 19:55:32 +12:00
|
|
|
|
isRightPressed = true;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
break;
|
2016-08-05 22:44:47 +12:00
|
|
|
|
case Keys.Up:
|
|
|
|
|
case Keys.W:
|
|
|
|
|
isUpPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Down:
|
|
|
|
|
case Keys.S:
|
|
|
|
|
isDownPressed = true;
|
|
|
|
|
break;
|
2016-06-13 05:04:06 +12:00
|
|
|
|
case Keys.Menu:
|
2016-06-12 22:48:56 +12:00
|
|
|
|
IsBottomRightResizing = true;
|
2016-06-13 05:04:06 +12:00
|
|
|
|
break;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2015-08-20 05:22:07 +12:00
|
|
|
|
|
2016-08-05 22:44:47 +12:00
|
|
|
|
int speed;
|
2016-08-03 21:01:39 +12:00
|
|
|
|
|
2016-08-05 22:44:47 +12:00
|
|
|
|
if (e.Shift)
|
2015-08-20 05:22:07 +12:00
|
|
|
|
{
|
2016-08-05 22:44:47 +12:00
|
|
|
|
speed = RegionCaptureOptions.MoveSpeedMaximum;
|
2015-08-20 05:50:21 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-08-05 22:44:47 +12:00
|
|
|
|
speed = RegionCaptureOptions.MoveSpeedMinimum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
|
|
if (isLeftPressed)
|
|
|
|
|
{
|
|
|
|
|
x -= speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isRightPressed)
|
|
|
|
|
{
|
|
|
|
|
x += speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
|
|
if (isUpPressed)
|
|
|
|
|
{
|
|
|
|
|
y -= speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isDownPressed)
|
|
|
|
|
{
|
|
|
|
|
y += speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x != 0 || y != 0)
|
|
|
|
|
{
|
|
|
|
|
BaseShape shape = shapeManager.CurrentShape;
|
|
|
|
|
|
|
|
|
|
if (shape == null || shapeManager.IsCreating)
|
2015-08-20 05:50:21 +12:00
|
|
|
|
{
|
2016-08-05 22:44:47 +12:00
|
|
|
|
Cursor.Position = Cursor.Position.Add(x, y);
|
2015-08-20 05:50:21 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-08-05 22:44:47 +12:00
|
|
|
|
if (e.Control)
|
|
|
|
|
{
|
|
|
|
|
shape.Move(x, y);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
shape.Resize(x, y, e.Alt);
|
|
|
|
|
}
|
2015-08-20 05:50:21 +12:00
|
|
|
|
}
|
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.Left:
|
2016-07-17 18:25:53 +12:00
|
|
|
|
case Keys.A:
|
2016-06-25 19:55:32 +12:00
|
|
|
|
isLeftPressed = false;
|
2015-08-20 05:22:07 +12:00
|
|
|
|
break;
|
|
|
|
|
case Keys.Right:
|
2016-07-17 18:25:53 +12:00
|
|
|
|
case Keys.D:
|
2016-06-25 19:55:32 +12:00
|
|
|
|
isRightPressed = false;
|
2015-08-20 05:22:07 +12:00
|
|
|
|
break;
|
2016-08-05 22:44:47 +12:00
|
|
|
|
case Keys.Up:
|
|
|
|
|
case Keys.W:
|
|
|
|
|
isUpPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Down:
|
|
|
|
|
case Keys.S:
|
|
|
|
|
isDownPressed = false;
|
|
|
|
|
break;
|
2016-06-13 05:04:06 +12:00
|
|
|
|
case Keys.Menu:
|
|
|
|
|
IsBottomRightResizing = 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;
|
|
|
|
|
}
|
2016-08-05 22:13:16 +12:00
|
|
|
|
else if (shape.NodeType == NodeType.Freehand)
|
|
|
|
|
{
|
|
|
|
|
FreehandRegionShape freehandRegionShape = (FreehandRegionShape)shape;
|
|
|
|
|
nodes[(int)NodePosition.TopLeft].Position = freehandRegionShape.LastPosition;
|
|
|
|
|
}
|
2016-05-06 10:15:41 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|