Browse Source

Continous curves work

flabbet 8 months ago
parent
commit
ec91ffbca3

+ 4 - 3
src/PixiEditor/Views/Overlays/Handles/Handle.cs

@@ -27,6 +27,7 @@ public abstract class Handle : IHandle
     public VecD Position { get; set; }
     public VecD Position { get; set; }
     public VecD Size { get; set; }
     public VecD Size { get; set; }
     public RectD HandleRect => new(Position, Size);
     public RectD HandleRect => new(Position, Size);
+    public bool HitTestVisible { get; set; } = true;
     public bool IsHovered => isHovered;
     public bool IsHovered => isHovered;
 
 
     public event HandleEvent OnPress;
     public event HandleEvent OnPress;
@@ -111,7 +112,7 @@ public abstract class Handle : IHandle
 
 
         VecD handlePos = Position;
         VecD handlePos = Position;
 
 
-        if (IsWithinHandle(handlePos, args.Point, ZoomScale))
+        if (IsWithinHandle(handlePos, args.Point, ZoomScale) && HitTestVisible)
         {
         {
             args.Handled = true;
             args.Handled = true;
             OnPressed(args);
             OnPressed(args);
@@ -126,7 +127,7 @@ public abstract class Handle : IHandle
     {
     {
         VecD handlePos = Position;
         VecD handlePos = Position;
 
 
-        if (args.Handled)
+        if (args.Handled || !HitTestVisible)
         {
         {
             return;
             return;
         }
         }
@@ -167,7 +168,7 @@ public abstract class Handle : IHandle
             return;
             return;
         }
         }
 
 
-        if (args.Handled)
+        if (args.Handled || !HitTestVisible)
         {
         {
             isPressed = false;
             isPressed = false;
             return;
             return;

+ 29 - 6
src/PixiEditor/Views/Overlays/PathOverlay/VectorPathOverlay.cs

@@ -119,11 +119,25 @@ public class VectorPathOverlay : Overlay
                 VecD controlPoint1 = (VecD)verb.points[1];
                 VecD controlPoint1 = (VecD)verb.points[1];
                 VecD controlPoint2 = (VecD)verb.points[2];
                 VecD controlPoint2 = (VecD)verb.points[2];
 
 
-                controlPointHandles[controlPoint].Position = controlPoint1;
-                controlPointHandles[controlPoint].Draw(context);
+                var controlPointHandle1 = controlPointHandles[controlPoint];
+                var controlPointHandle2 = controlPointHandles[controlPoint + 1];
 
 
-                controlPointHandles[controlPoint + 1].Position = controlPoint2;
-                controlPointHandles[controlPoint + 1].Draw(context);
+                controlPointHandle1.HitTestVisible = controlPoint1 != controlPointHandle1.ConnectedTo.Position;
+                controlPointHandle2.HitTestVisible = controlPoint2 != controlPointHandle2.ConnectedTo.Position;
+
+                controlPointHandle1.Position = controlPoint1;
+
+                if (controlPointHandle1.HitTestVisible)
+                {
+                    controlPointHandle1.Draw(context);
+                }
+
+                controlPointHandle2.Position = controlPoint2;
+
+                if (controlPointHandle2.HitTestVisible)
+                {
+                    controlPointHandle2.Draw(context);
+                }
 
 
                 controlPoint += 2;
                 controlPoint += 2;
             }
             }
@@ -388,7 +402,7 @@ public class VectorPathOverlay : Overlay
     private VectorPath ConvertTouchingLineVerbsToCubic(AnchorHandle anchorHandle)
     private VectorPath ConvertTouchingLineVerbsToCubic(AnchorHandle anchorHandle)
     {
     {
         bool convertNextToCubic = false;
         bool convertNextToCubic = false;
-        int i = 0;
+        int i = -1;
         VectorPath newPath = new VectorPath();
         VectorPath newPath = new VectorPath();
         int index = anchorHandles.IndexOf(anchorHandle);
         int index = anchorHandles.IndexOf(anchorHandle);
 
 
@@ -401,7 +415,11 @@ public class VectorPathOverlay : Overlay
                     newPath.CubicTo(data.points[0], data.points[1], data.points[1]);
                     newPath.CubicTo(data.points[0], data.points[1], data.points[1]);
                     convertNextToCubic = true;
                     convertNextToCubic = true;
                 }
                 }
-                else if (i == 1 && index == 0 || (Path.IsClosed && i == Path.PointCount - 1 && index == 0))
+                else if(i + 1 == index)
+                {
+                    newPath.CubicTo(data.points[0], data.points[1], data.points[1]);
+                }
+                else if (i == 0 && index == 0 || (Path.IsClosed && i == Path.PointCount - 2 && index == 0))
                 {
                 {
                     newPath.CubicTo(data.points[0], data.points[1], data.points[1]);
                     newPath.CubicTo(data.points[0], data.points[1], data.points[1]);
                 }
                 }
@@ -418,6 +436,11 @@ public class VectorPathOverlay : Overlay
                     }
                     }
                 }
                 }
             }
             }
+            else if (data.verb == PathVerb.Cubic && i == index)
+            {
+                newPath.CubicTo(data.points[1], data.points[2], data.points[3]);
+                convertNextToCubic = true;
+            }
             else
             else
             {
             {
                 DefaultPathVerb(data, newPath);
                 DefaultPathVerb(data, newPath);