mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-06 05:05:42 +13: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,31 +284,30 @@ public void Close(SurfaceResult result)
|
|||
|
||||
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++)
|
||||
{
|
||||
DrawableObject obj = objects[i];
|
||||
|
||||
obj.IsMouseHover = obj.Rectangle.Contains(InputManager.MousePosition0Based);
|
||||
|
||||
if (obj.IsMouseHover)
|
||||
if (obj.Visible)
|
||||
{
|
||||
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);
|
||||
|
||||
if (IsMouseHover)
|
||||
{
|
||||
rect.Inflate(1, 1);
|
||||
}
|
||||
|
||||
switch (Shape)
|
||||
{
|
||||
case NodeShape.Square:
|
||||
|
|
|
@ -111,60 +111,78 @@ public ResizeManager(SurfaceForm surface, AreaManager areaManager)
|
|||
|
||||
public void Update()
|
||||
{
|
||||
if (Visible && nodes != null)
|
||||
BaseShape shape = areaManager.CurrentShape;
|
||||
|
||||
if (shape != null && Visible && nodes != null)
|
||||
{
|
||||
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;
|
||||
|
||||
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
|
||||
{
|
||||
tempRect = areaManager.CurrentRectangle;
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -257,13 +275,10 @@ public void Hide()
|
|||
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.NodeType == NodeType.Rectangle)
|
||||
|
|
Loading…
Reference in a new issue