fixed #1714: Center resize nodes to cursor that way magnifier can show exact pixel

This commit is contained in:
Jaex 2016-08-09 19:16:48 +03:00
parent 2537316a33
commit 5b077d4871
2 changed files with 18 additions and 34 deletions

View file

@ -221,28 +221,6 @@ public static Rectangle CreateRectangle(Point pos, Point pos2)
return CreateRectangle(pos.X, pos.Y, pos2.X, pos2.Y);
}
public static Rectangle FixRectangle(int x, int y, int width, int height)
{
if (width < 0)
{
x += width;
width = -width;
}
if (height < 0)
{
y += height;
height = -height;
}
return new Rectangle(x, y, width, height);
}
public static Rectangle FixRectangle(Rectangle rect)
{
return FixRectangle(rect.X, rect.Y, rect.Width, rect.Height);
}
public static Point ProportionalPosition(Point pos, Point pos2)
{
Point newPosition = Point.Empty;

View file

@ -80,7 +80,7 @@ public Point EndPosition
internal ShapeManager Manager { get; set; }
private Rectangle tempNodeRect;
private Point tempNodePos, tempStartPos, tempEndPos;
public virtual bool Intersects(Point position)
{
@ -195,52 +195,58 @@ public virtual void OnNodeUpdate()
{
for (int i = 0; i < 8; i++)
{
if (Manager.Nodes[i].IsDragging)
NodeObject node = Manager.Nodes[i];
if (node.IsDragging)
{
Manager.IsResizing = true;
if (!InputManager.IsBeforeMouseDown(MouseButtons.Left))
{
tempNodeRect = Rectangle;
tempNodePos = node.Position;
tempStartPos = Rectangle.Location;
tempEndPos = new Point(Rectangle.X + Rectangle.Width - 1, Rectangle.Y + Rectangle.Height - 1);
}
Point pos = InputManager.MousePosition0Based;
Point startPos = tempStartPos;
Point endPos = tempEndPos;
NodePosition nodePosition = (NodePosition)i;
int x = InputManager.MouseVelocity.X;
int x = pos.X - tempNodePos.X;
switch (nodePosition)
{
case NodePosition.TopLeft:
case NodePosition.Left:
case NodePosition.BottomLeft:
tempNodeRect.X += x;
tempNodeRect.Width -= x;
startPos.X += x;
break;
case NodePosition.TopRight:
case NodePosition.Right:
case NodePosition.BottomRight:
tempNodeRect.Width += x;
endPos.X += x;
break;
}
int y = InputManager.MouseVelocity.Y;
int y = pos.Y - tempNodePos.Y;
switch (nodePosition)
{
case NodePosition.TopLeft:
case NodePosition.Top:
case NodePosition.TopRight:
tempNodeRect.Y += y;
tempNodeRect.Height -= y;
startPos.Y += y;
break;
case NodePosition.BottomLeft:
case NodePosition.Bottom:
case NodePosition.BottomRight:
tempNodeRect.Height += y;
endPos.Y += y;
break;
}
Rectangle = CaptureHelpers.FixRectangle(tempNodeRect);
Rectangle = CaptureHelpers.CreateRectangle(startPos, endPos);
}
}
}