mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-15 03:16:05 +12:00
Two point node dragging support
This commit is contained in:
parent
c4f7268106
commit
67643f5b0f
|
@ -284,31 +284,30 @@ protected new virtual void Update()
|
||||||
|
|
||||||
DrawableObject[] objects = DrawableObjects.OrderByDescending(x => x.Order).ToArray();
|
DrawableObject[] objects = DrawableObjects.OrderByDescending(x => x.Order).ToArray();
|
||||||
|
|
||||||
if (objects.All(x => x.Visible && !x.IsDragging))
|
if (objects.All(x => !x.IsDragging))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < objects.Count(); i++)
|
for (int i = 0; i < objects.Count(); i++)
|
||||||
{
|
{
|
||||||
DrawableObject obj = objects[i];
|
DrawableObject obj = objects[i];
|
||||||
|
|
||||||
obj.IsMouseHover = obj.Rectangle.Contains(InputManager.MousePosition0Based);
|
if (obj.Visible)
|
||||||
|
|
||||||
if (obj.IsMouseHover)
|
|
||||||
{
|
{
|
||||||
for (int y = i + 1; y < objects.Count(); y++)
|
obj.IsMouseHover = obj.Rectangle.Contains(InputManager.MousePosition0Based);
|
||||||
|
|
||||||
|
if (obj.IsMouseHover)
|
||||||
{
|
{
|
||||||
objects[y].IsMouseHover = false;
|
if (InputManager.IsMousePressed(MouseButtons.Left))
|
||||||
|
{
|
||||||
|
obj.IsDragging = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int y = i + 1; y < objects.Count(); y++)
|
||||||
|
{
|
||||||
|
objects[y].IsMouseHover = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (DrawableObject obj in objects)
|
|
||||||
{
|
|
||||||
if (obj.IsMouseHover && InputManager.IsMousePressed(MouseButtons.Left))
|
|
||||||
{
|
|
||||||
obj.IsDragging = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,11 @@ public override void Draw(Graphics g)
|
||||||
{
|
{
|
||||||
Rectangle rect = new Rectangle((int)Rectangle.X, (int)Rectangle.Y, (int)Rectangle.Width - 1, (int)Rectangle.Height - 1);
|
Rectangle rect = new Rectangle((int)Rectangle.X, (int)Rectangle.Y, (int)Rectangle.Width - 1, (int)Rectangle.Height - 1);
|
||||||
|
|
||||||
|
if (IsMouseHover)
|
||||||
|
{
|
||||||
|
rect.Inflate(1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
switch (Shape)
|
switch (Shape)
|
||||||
{
|
{
|
||||||
case NodeShape.Square:
|
case NodeShape.Square:
|
||||||
|
|
|
@ -111,60 +111,78 @@ public ResizeManager(SurfaceForm surface, AreaManager areaManager)
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
if (Visible && nodes != null)
|
BaseShape shape = areaManager.CurrentShape;
|
||||||
|
|
||||||
|
if (shape != null && Visible && nodes != null)
|
||||||
{
|
{
|
||||||
if (InputManager.IsMouseDown(MouseButtons.Left))
|
if (InputManager.IsMouseDown(MouseButtons.Left))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 8; i++)
|
if (shape.NodeType == NodeType.Rectangle)
|
||||||
{
|
{
|
||||||
if (nodes[i].IsDragging)
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if (nodes[i].IsDragging)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (shape.NodeType == NodeType.Line)
|
||||||
|
{
|
||||||
|
if (nodes[(int)NodePosition.TopLeft].IsDragging)
|
||||||
{
|
{
|
||||||
IsResizing = true;
|
IsResizing = true;
|
||||||
|
shape.StartPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y);
|
||||||
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
|
}
|
||||||
{
|
else if (nodes[(int)NodePosition.BottomRight].IsDragging)
|
||||||
tempRect = areaManager.CurrentRectangle;
|
{
|
||||||
}
|
IsResizing = true;
|
||||||
|
shape.EndPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
areaManager.CurrentRectangle = CaptureHelpers.FixRectangle(tempRect);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,13 +275,10 @@ public void Hide()
|
||||||
Visible = false;
|
Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateNodePositions()
|
private void UpdateNodePositions()
|
||||||
{
|
{
|
||||||
UpdateNodePositions(areaManager.CurrentShape);
|
BaseShape shape = areaManager.CurrentShape;
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateNodePositions(BaseShape shape)
|
|
||||||
{
|
|
||||||
if (shape != null)
|
if (shape != null)
|
||||||
{
|
{
|
||||||
if (shape.NodeType == NodeType.Rectangle)
|
if (shape.NodeType == NodeType.Rectangle)
|
||||||
|
|
Loading…
Reference in a new issue