Fix resize node issues

This commit is contained in:
Jaex 2017-11-16 12:21:05 +03:00
parent 920916c4ff
commit d8cf9f1d17
2 changed files with 22 additions and 33 deletions

View file

@ -24,10 +24,8 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
namespace ShareX.ScreenCaptureLib
{
@ -61,6 +59,18 @@ private void AdjustPoints(int centerPointCount)
Points = newPoints;
}
private void AutoPositionCenterPoints()
{
if (!CenterNodeActive)
{
for (int i = 1; i < Points.Length - 1; i++)
{
Points[i] = new Point((int)MathHelpers.Lerp(Points[0].X, Points[Points.Length - 1].X, i / (CenterPointCount + 1f)),
(int)MathHelpers.Lerp(Points[0].Y, Points[Points.Length - 1].Y, i / (CenterPointCount + 1f)));
}
}
}
public override void OnConfigLoad()
{
base.OnConfigLoad();
@ -100,7 +110,6 @@ public override void OnUpdate()
else
{
AutoPositionCenterPoints();
Rectangle = Points.CreateRectangle();
}
}
@ -187,15 +196,9 @@ public override void Resize(int x, int y, bool fromBottomRight)
public override void OnNodeVisible()
{
for (int i = 0; i < 8; i++)
for (int i = 0; i < Manager.ResizeNodes.Length; i++)
{
ResizeNode node = Manager.ResizeNodes[i];
node.Visible = false;
}
for (int i = 0; i < Points.Length; i++)
{
Manager.ResizeNodes[i].Visible = true;
Manager.ResizeNodes[i].Visible = i < Points.Length;
}
}
@ -217,30 +220,16 @@ public override void OnNodeUpdate()
}
}
private void AutoPositionCenterPoints()
{
if (!CenterNodeActive)
{
for (int i = 1; i < Points.Length - 1; i++)
{
Points[i] = new Point((int)MathHelpers.Lerp(Points[0].X, Points[Points.Length - 1].X, i / (CenterPointCount + 1f)),
(int)MathHelpers.Lerp(Points[0].Y, Points[Points.Length - 1].Y, i / (CenterPointCount + 1f)));
}
}
}
public override void OnNodePositionUpdate()
{
for (int i = 0; i < Points.Length; i++)
{
Manager.ResizeNodes[i].Position = Points[i];
}
Manager.ResizeNodes[0].Visible = !Manager.ResizeNodes[0].Rectangle.IntersectsWith(Manager.ResizeNodes[Manager.ResizeNodes.Count - 1].Rectangle);
for (int i = 1; i < Points.Length - 1; i++)
{
Manager.ResizeNodes[i].Visible = !Manager.ResizeNodes[i].Rectangle.IntersectsWith(Manager.ResizeNodes[Manager.ResizeNodes.Count - 1].Rectangle);
if (i < Points.Length - 1)
{
Manager.ResizeNodes[i].Visible = !Manager.ResizeNodes[i].Rectangle.IntersectsWith(Manager.ResizeNodes[Points.Length - 1].Rectangle);
}
}
}
}

View file

@ -168,7 +168,7 @@ private set
public AnnotationOptions AnnotationOptions => Options.AnnotationOptions;
public List<ResizeNode> ResizeNodes { get; private set; }
public ResizeNode[] ResizeNodes { get; private set; }
private bool nodesVisible;
@ -217,14 +217,14 @@ public ShapeManager(RegionCaptureForm form)
Form = form;
Options = form.Options;
ResizeNodes = new List<ResizeNode>();
ResizeNodes = new ResizeNode[9];
for (int i = 0; i < 9; i++)
for (int i = 0; i < ResizeNodes.Length; i++)
{
ResizeNode node = new ResizeNode();
node.SetCustomNode(form.CustomNodeImage);
form.DrawableObjects.Add(node);
ResizeNodes.Add(node);
ResizeNodes[i] = node;
}
ResizeNodes[(int)NodePosition.BottomRight].Order = 10;