mirror of
https://github.com/ShareX/ShareX.git
synced 2024-08-07 14:28:42 +12:00
Moved node logic to BaseShape
This commit is contained in:
parent
282d543a91
commit
5829085cb6
5 changed files with 170 additions and 172 deletions
|
@ -30,35 +30,6 @@ namespace ShareX.ScreenCaptureLib
|
||||||
{
|
{
|
||||||
public static class InputManager
|
public static class InputManager
|
||||||
{
|
{
|
||||||
private static MouseState mouseState = new MouseState();
|
|
||||||
private static MouseState oldMouseState;
|
|
||||||
|
|
||||||
public static void Update()
|
|
||||||
{
|
|
||||||
oldMouseState = mouseState;
|
|
||||||
mouseState.Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsMouseDown(MouseButtons button)
|
|
||||||
{
|
|
||||||
return mouseState.Buttons.HasFlag(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsBeforeMouseDown(MouseButtons button)
|
|
||||||
{
|
|
||||||
return oldMouseState.Buttons.HasFlag(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsMousePressed(MouseButtons button)
|
|
||||||
{
|
|
||||||
return IsMouseDown(button) && !IsBeforeMouseDown(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsMouseReleased(MouseButtons button)
|
|
||||||
{
|
|
||||||
return !IsMouseDown(button) && IsBeforeMouseDown(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Point MousePosition
|
public static Point MousePosition
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -106,5 +77,34 @@ public static bool IsMouseMoved
|
||||||
return MouseVelocity.X != 0 || MouseVelocity.Y != 0;
|
return MouseVelocity.X != 0 || MouseVelocity.Y != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static MouseState mouseState = new MouseState();
|
||||||
|
private static MouseState oldMouseState;
|
||||||
|
|
||||||
|
public static void Update()
|
||||||
|
{
|
||||||
|
oldMouseState = mouseState;
|
||||||
|
mouseState.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsMouseDown(MouseButtons button)
|
||||||
|
{
|
||||||
|
return mouseState.Buttons.HasFlag(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsBeforeMouseDown(MouseButtons button)
|
||||||
|
{
|
||||||
|
return oldMouseState.Buttons.HasFlag(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsMousePressed(MouseButtons button)
|
||||||
|
{
|
||||||
|
return IsMouseDown(button) && !IsBeforeMouseDown(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsMouseReleased(MouseButtons button)
|
||||||
|
{
|
||||||
|
return !IsMouseDown(button) && IsBeforeMouseDown(button);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -26,6 +26,7 @@ You should have received a copy of the GNU General Public License
|
||||||
using ShareX.HelpersLib;
|
using ShareX.HelpersLib;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.ScreenCaptureLib
|
namespace ShareX.ScreenCaptureLib
|
||||||
{
|
{
|
||||||
|
@ -89,6 +90,8 @@ public virtual bool IsValidShape
|
||||||
|
|
||||||
internal ShapeManager Manager { get; set; }
|
internal ShapeManager Manager { get; set; }
|
||||||
|
|
||||||
|
private Rectangle tempNodeRect;
|
||||||
|
|
||||||
public virtual bool Intersects(Point position)
|
public virtual bool Intersects(Point position)
|
||||||
{
|
{
|
||||||
return Rectangle.Contains(position);
|
return Rectangle.Contains(position);
|
||||||
|
@ -182,5 +185,88 @@ public virtual void OnConfigSave()
|
||||||
public virtual void OnDoubleClicked()
|
public virtual void OnDoubleClicked()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void OnNodeVisible()
|
||||||
|
{
|
||||||
|
foreach (NodeObject node in Manager.Nodes)
|
||||||
|
{
|
||||||
|
node.Shape = NodeShape.Square;
|
||||||
|
node.Visible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnNodeUpdate()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if (Manager.Nodes[i].IsDragging)
|
||||||
|
{
|
||||||
|
Manager.IsResizing = true;
|
||||||
|
|
||||||
|
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
|
||||||
|
{
|
||||||
|
tempNodeRect = Rectangle;
|
||||||
|
}
|
||||||
|
|
||||||
|
NodePosition nodePosition = (NodePosition)i;
|
||||||
|
|
||||||
|
int x = InputManager.MouseVelocity.X;
|
||||||
|
|
||||||
|
switch (nodePosition)
|
||||||
|
{
|
||||||
|
case NodePosition.TopLeft:
|
||||||
|
case NodePosition.Left:
|
||||||
|
case NodePosition.BottomLeft:
|
||||||
|
tempNodeRect.X += x;
|
||||||
|
tempNodeRect.Width -= x;
|
||||||
|
break;
|
||||||
|
case NodePosition.TopRight:
|
||||||
|
case NodePosition.Right:
|
||||||
|
case NodePosition.BottomRight:
|
||||||
|
tempNodeRect.Width += x;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int y = InputManager.MouseVelocity.Y;
|
||||||
|
|
||||||
|
switch (nodePosition)
|
||||||
|
{
|
||||||
|
case NodePosition.TopLeft:
|
||||||
|
case NodePosition.Top:
|
||||||
|
case NodePosition.TopRight:
|
||||||
|
tempNodeRect.Y += y;
|
||||||
|
tempNodeRect.Height -= y;
|
||||||
|
break;
|
||||||
|
case NodePosition.BottomLeft:
|
||||||
|
case NodePosition.Bottom:
|
||||||
|
case NodePosition.BottomRight:
|
||||||
|
tempNodeRect.Height += y;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle = CaptureHelpers.FixRectangle(tempNodeRect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
Manager.Nodes[(int)NodePosition.TopLeft].Position = new Point(xStart, yStart);
|
||||||
|
Manager.Nodes[(int)NodePosition.Top].Position = new Point(xMid, yStart);
|
||||||
|
Manager.Nodes[(int)NodePosition.TopRight].Position = new Point(xEnd, yStart);
|
||||||
|
Manager.Nodes[(int)NodePosition.Right].Position = new Point(xEnd, yMid);
|
||||||
|
Manager.Nodes[(int)NodePosition.BottomRight].Position = new Point(xEnd, yEnd);
|
||||||
|
Manager.Nodes[(int)NodePosition.Bottom].Position = new Point(xMid, yEnd);
|
||||||
|
Manager.Nodes[(int)NodePosition.BottomLeft].Position = new Point(xStart, yEnd);
|
||||||
|
Manager.Nodes[(int)NodePosition.Left].Position = new Point(xStart, yMid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -79,5 +79,33 @@ public override void Resize(int x, int y, bool fromBottomRight)
|
||||||
EndPosition = EndPosition.Add(x, y);
|
EndPosition = EndPosition.Add(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnNodeVisible()
|
||||||
|
{
|
||||||
|
Manager.Nodes[(int)NodePosition.TopLeft].Shape = Manager.Nodes[(int)NodePosition.BottomRight].Shape = NodeShape.Circle;
|
||||||
|
Manager.Nodes[(int)NodePosition.TopLeft].Visible = Manager.Nodes[(int)NodePosition.BottomRight].Visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnNodeUpdate()
|
||||||
|
{
|
||||||
|
if (Manager.Nodes[(int)NodePosition.TopLeft].IsDragging)
|
||||||
|
{
|
||||||
|
Manager.IsResizing = true;
|
||||||
|
|
||||||
|
StartPosition = InputManager.MousePosition0Based;
|
||||||
|
}
|
||||||
|
else if (Manager.Nodes[(int)NodePosition.BottomRight].IsDragging)
|
||||||
|
{
|
||||||
|
Manager.IsResizing = true;
|
||||||
|
|
||||||
|
EndPosition = InputManager.MousePosition0Based;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnNodePositionUpdate()
|
||||||
|
{
|
||||||
|
Manager.Nodes[(int)NodePosition.TopLeft].Position = StartPosition;
|
||||||
|
Manager.Nodes[(int)NodePosition.BottomRight].Position = EndPosition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -124,5 +124,26 @@ public override void Move(int x, int y)
|
||||||
public override void Resize(int x, int y, bool fromBottomRight)
|
public override void Resize(int x, int y, bool fromBottomRight)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnNodeVisible()
|
||||||
|
{
|
||||||
|
Manager.Nodes[(int)NodePosition.TopLeft].Shape = NodeShape.Circle;
|
||||||
|
Manager.Nodes[(int)NodePosition.TopLeft].Visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnNodeUpdate()
|
||||||
|
{
|
||||||
|
if (Manager.Nodes[(int)NodePosition.TopLeft].IsDragging)
|
||||||
|
{
|
||||||
|
Manager.IsCreating = true;
|
||||||
|
|
||||||
|
Manager.NodesVisible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnNodePositionUpdate()
|
||||||
|
{
|
||||||
|
Manager.Nodes[(int)NodePosition.TopLeft].Position = LastPosition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -168,9 +168,9 @@ public bool IsCurrentShapeTypeRegion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCreating { get; private set; }
|
public bool IsCreating { get; set; }
|
||||||
public bool IsMoving { get; private set; }
|
public bool IsMoving { get; private set; }
|
||||||
public bool IsResizing { get; private set; }
|
public bool IsResizing { get; set; }
|
||||||
|
|
||||||
public bool IsCornerMoving { get; private set; }
|
public bool IsCornerMoving { get; private set; }
|
||||||
public bool IsProportionalResizing { get; private set; }
|
public bool IsProportionalResizing { get; private set; }
|
||||||
|
@ -217,26 +217,8 @@ public bool NodesVisible
|
||||||
|
|
||||||
if (shape != null)
|
if (shape != null)
|
||||||
{
|
{
|
||||||
UpdateNodePositions();
|
shape.OnNodePositionUpdate();
|
||||||
|
shape.OnNodeVisible();
|
||||||
if (shape.NodeType == NodeType.Rectangle)
|
|
||||||
{
|
|
||||||
foreach (NodeObject node in Nodes)
|
|
||||||
{
|
|
||||||
node.Shape = NodeShape.Square;
|
|
||||||
node.Visible = nodesVisible;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
else if (shape.NodeType == NodeType.Freehand)
|
|
||||||
{
|
|
||||||
Nodes[(int)NodePosition.TopLeft].Shape = NodeShape.Circle;
|
|
||||||
Nodes[(int)NodePosition.TopLeft].Visible = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,7 +241,6 @@ public bool IsCursorOnNode
|
||||||
private ToolStripMenuItem tsmiDeleteSelected, tsmiDeleteAll, tsmiBorderColor, tsmiFillColor, tsmiHighlightColor;
|
private ToolStripMenuItem tsmiDeleteSelected, tsmiDeleteAll, tsmiBorderColor, tsmiFillColor, tsmiHighlightColor;
|
||||||
private ToolStripLabeledNumericUpDown tslnudBorderSize, tslnudRoundedRectangleRadius, tslnudBlurRadius, tslnudPixelateSize;
|
private ToolStripLabeledNumericUpDown tslnudBorderSize, tslnudRoundedRectangleRadius, tslnudBlurRadius, tslnudPixelateSize;
|
||||||
private bool isLeftPressed, isRightPressed, isUpPressed, isDownPressed;
|
private bool isLeftPressed, isRightPressed, isUpPressed, isDownPressed;
|
||||||
private Rectangle tempNodeRect;
|
|
||||||
|
|
||||||
public ShapeManager(RectangleRegionForm form)
|
public ShapeManager(RectangleRegionForm form)
|
||||||
{
|
{
|
||||||
|
@ -1609,132 +1590,14 @@ private void UpdateNodes()
|
||||||
{
|
{
|
||||||
if (InputManager.IsMouseDown(MouseButtons.Left))
|
if (InputManager.IsMouseDown(MouseButtons.Left))
|
||||||
{
|
{
|
||||||
if (shape.NodeType == NodeType.Rectangle)
|
shape.OnNodeUpdate();
|
||||||
{
|
|
||||||
for (int i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
if (Nodes[i].IsDragging)
|
|
||||||
{
|
|
||||||
IsResizing = true;
|
|
||||||
|
|
||||||
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
|
|
||||||
{
|
|
||||||
tempNodeRect = shape.Rectangle;
|
|
||||||
}
|
|
||||||
|
|
||||||
NodePosition nodePosition = (NodePosition)i;
|
|
||||||
|
|
||||||
int x = InputManager.MouseVelocity.X;
|
|
||||||
|
|
||||||
switch (nodePosition)
|
|
||||||
{
|
|
||||||
case NodePosition.TopLeft:
|
|
||||||
case NodePosition.Left:
|
|
||||||
case NodePosition.BottomLeft:
|
|
||||||
tempNodeRect.X += x;
|
|
||||||
tempNodeRect.Width -= x;
|
|
||||||
break;
|
|
||||||
case NodePosition.TopRight:
|
|
||||||
case NodePosition.Right:
|
|
||||||
case NodePosition.BottomRight:
|
|
||||||
tempNodeRect.Width += x;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int y = InputManager.MouseVelocity.Y;
|
|
||||||
|
|
||||||
switch (nodePosition)
|
|
||||||
{
|
|
||||||
case NodePosition.TopLeft:
|
|
||||||
case NodePosition.Top:
|
|
||||||
case NodePosition.TopRight:
|
|
||||||
tempNodeRect.Y += y;
|
|
||||||
tempNodeRect.Height -= y;
|
|
||||||
break;
|
|
||||||
case NodePosition.BottomLeft:
|
|
||||||
case NodePosition.Bottom:
|
|
||||||
case NodePosition.BottomRight:
|
|
||||||
tempNodeRect.Height += y;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
shape.Rectangle = CaptureHelpers.FixRectangle(tempNodeRect);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (shape.NodeType == NodeType.Line)
|
|
||||||
{
|
|
||||||
if (Nodes[(int)NodePosition.TopLeft].IsDragging)
|
|
||||||
{
|
|
||||||
IsResizing = true;
|
|
||||||
|
|
||||||
shape.StartPosition = InputManager.MousePosition0Based;
|
|
||||||
}
|
|
||||||
else if (Nodes[(int)NodePosition.BottomRight].IsDragging)
|
|
||||||
{
|
|
||||||
IsResizing = true;
|
|
||||||
|
|
||||||
shape.EndPosition = InputManager.MousePosition0Based;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (shape.NodeType == NodeType.Freehand)
|
|
||||||
{
|
|
||||||
if (Nodes[(int)NodePosition.TopLeft].IsDragging)
|
|
||||||
{
|
|
||||||
IsCreating = true;
|
|
||||||
|
|
||||||
NodesVisible = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IsResizing = false;
|
IsResizing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateNodePositions();
|
shape.OnNodePositionUpdate();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateNodePositions()
|
|
||||||
{
|
|
||||||
BaseShape shape = CurrentShape;
|
|
||||||
|
|
||||||
if (shape != null)
|
|
||||||
{
|
|
||||||
if (shape.NodeType == NodeType.Rectangle)
|
|
||||||
{
|
|
||||||
Rectangle rect = shape.Rectangle;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
else if (shape.NodeType == NodeType.Line)
|
|
||||||
{
|
|
||||||
Nodes[(int)NodePosition.TopLeft].Position = shape.StartPosition;
|
|
||||||
Nodes[(int)NodePosition.BottomRight].Position = shape.EndPosition;
|
|
||||||
}
|
|
||||||
else if (shape.NodeType == NodeType.Freehand)
|
|
||||||
{
|
|
||||||
FreehandRegionShape freehandRegionShape = (FreehandRegionShape)shape;
|
|
||||||
Nodes[(int)NodePosition.TopLeft].Position = freehandRegionShape.LastPosition;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue