mirror of
https://github.com/ShareX/ShareX.git
synced 2024-08-17 03:02:00 +12:00
Two point node dragging support
This commit is contained in:
parent
c4f7268106
commit
67643f5b0f
3 changed files with 89 additions and 70 deletions
|
@ -284,16 +284,23 @@ public void Close(SurfaceResult result)
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
|
if (obj.Visible)
|
||||||
|
{
|
||||||
obj.IsMouseHover = obj.Rectangle.Contains(InputManager.MousePosition0Based);
|
obj.IsMouseHover = obj.Rectangle.Contains(InputManager.MousePosition0Based);
|
||||||
|
|
||||||
if (obj.IsMouseHover)
|
if (obj.IsMouseHover)
|
||||||
{
|
{
|
||||||
|
if (InputManager.IsMousePressed(MouseButtons.Left))
|
||||||
|
{
|
||||||
|
obj.IsDragging = true;
|
||||||
|
}
|
||||||
|
|
||||||
for (int y = i + 1; y < objects.Count(); y++)
|
for (int y = i + 1; y < objects.Count(); y++)
|
||||||
{
|
{
|
||||||
objects[y].IsMouseHover = false;
|
objects[y].IsMouseHover = false;
|
||||||
|
@ -302,14 +309,6 @@ public void Close(SurfaceResult result)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (DrawableObject obj in objects)
|
|
||||||
{
|
|
||||||
if (obj.IsMouseHover && InputManager.IsMousePressed(MouseButtons.Left))
|
|
||||||
{
|
|
||||||
obj.IsDragging = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -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,9 +111,13 @@ 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))
|
||||||
|
{
|
||||||
|
if (shape.NodeType == NodeType.Rectangle)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
|
@ -123,7 +127,7 @@ public void Update()
|
||||||
|
|
||||||
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
|
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
|
||||||
{
|
{
|
||||||
tempRect = areaManager.CurrentRectangle;
|
tempRect = shape.Rectangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePosition nodePosition = (NodePosition)i;
|
NodePosition nodePosition = (NodePosition)i;
|
||||||
|
@ -162,12 +166,26 @@ public void Update()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
areaManager.CurrentRectangle = CaptureHelpers.FixRectangle(tempRect);
|
shape.Rectangle = CaptureHelpers.FixRectangle(tempRect);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (shape.NodeType == NodeType.Line)
|
||||||
|
{
|
||||||
|
if (nodes[(int)NodePosition.TopLeft].IsDragging)
|
||||||
|
{
|
||||||
|
IsResizing = true;
|
||||||
|
shape.StartPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y);
|
||||||
|
}
|
||||||
|
else if (nodes[(int)NodePosition.BottomRight].IsDragging)
|
||||||
|
{
|
||||||
|
IsResizing = true;
|
||||||
|
shape.EndPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IsResizing = false;
|
IsResizing = false;
|
||||||
|
@ -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