mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Snap line to every 45 degrees
This commit is contained in:
parent
9f7f66d56e
commit
13bde6b875
2 changed files with 18 additions and 1 deletions
|
@ -282,6 +282,16 @@ public static Point ProportionalPosition(Point pos, Point pos2)
|
|||
return newPosition;
|
||||
}
|
||||
|
||||
public static Point SnapPositionToDegree(Point pos, Point pos2, float degree, float startDegree)
|
||||
{
|
||||
float angle = MathHelpers.LookAtRadian(pos, pos2);
|
||||
float startAngle = MathHelpers.DegreeToRadian(startDegree);
|
||||
float snapAngle = MathHelpers.DegreeToRadian(degree);
|
||||
float newAngle = (float)Math.Round((angle + startAngle) / snapAngle) * snapAngle - startAngle;
|
||||
float distance = MathHelpers.Distance(pos, pos2);
|
||||
return (Point)(pos + MathHelpers.RadianToVector2(newAngle, distance));
|
||||
}
|
||||
|
||||
public static Point CalculateNewPosition(Point posOnClick, Point posCurrent, Size size)
|
||||
{
|
||||
if (posCurrent.X > posOnClick.X)
|
||||
|
|
|
@ -935,7 +935,14 @@ public void Update()
|
|||
|
||||
if (IsProportionalResizing)
|
||||
{
|
||||
newPosition = CaptureHelpers.ProportionalPosition(PositionOnClick, CurrentPosition);
|
||||
if (shape.NodeType == NodeType.Rectangle)
|
||||
{
|
||||
newPosition = CaptureHelpers.SnapPositionToDegree(PositionOnClick, CurrentPosition, 90, 45);
|
||||
}
|
||||
else if (shape.NodeType == NodeType.Line)
|
||||
{
|
||||
newPosition = CaptureHelpers.SnapPositionToDegree(PositionOnClick, CurrentPosition, 45, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsSnapResizing)
|
||||
|
|
Loading…
Reference in a new issue