Browse Source

Some hopefully final adjustments

flabbet 8 months ago
parent
commit
230f236183

+ 4 - 2
src/PixiEditor/Data/Localization/Languages/en.json

@@ -768,7 +768,9 @@
   "PATH_TOOL": "Path",
   "PATH_TOOL_TOOLTIP": "Create vector paths and curves ({0}).",
   "PATH_TOOL_ACTION_DISPLAY": "Click to add a point.",
-  "PATH_TOOL_ACTION_DISPLAY_CTRL": "Click on existing point and drag to make it a curve.", 
+  "PATH_TOOL_ACTION_DISPLAY_CTRL": "Click on existing point and drag to make it a curve. Tap on a control point to select it.",
+  "PATH_TOOL_ACTION_DISPLAY_SHIFT": "Click on a path to insert a point.",
+  "PATH_TOOL_ACTION_DISPLAY_CTRL_SHIFT": "Tap on a control point to add it to the selection.",
   "PATH_TOOL_ACTION_DISPLAY_ALT": "Click on a control point and move to adjust only one side of the curve.",
   "DEFAULT_PATH_LAYER_NAME": "Path",
   "DELETE_NODES": "Delete nodes",
@@ -781,5 +783,5 @@
   "PREVIOUS_TOOL_SET": "Previous tool set",
   "FILL_MODE": "Fill mode",
   "USE_LINEAR_SRGB_PROCESSING": "Use linear sRGB for processing colors",
-    "USE_LINEAR_SRGB_PROCESSING_DESC": "Convert document using legacy blending mode to linear sRGB for processing colors. This will affect the colors of the document, but will make blending more accurate."
+  "USE_LINEAR_SRGB_PROCESSING_DESC": "Convert document using legacy blending mode to linear sRGB for processing colors. This will affect the colors of the document, but will make blending more accurate."
 }

+ 2 - 26
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorPathToolExecutor.cs

@@ -99,9 +99,9 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutorF
                 }
 
                 //below forces undo before starting new path
-                internals.ActionAccumulator.AddFinishedActions(new EndSetShapeGeometry_Action());
+                //internals.ActionAccumulator.AddFinishedActions(new EndSetShapeGeometry_Action());
 
-                internals.ActionAccumulator.AddActions(new SetShapeGeometry_Action(member.Id, ConstructShapeData()));
+                //internals.ActionAccumulator.AddActions(new SetShapeGeometry_Action(member.Id, ConstructShapeData()));
             }
         }
         else
@@ -149,31 +149,7 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutorF
 
                 document.Operations.SetSelectedMember(created.Value);
             }
-
-            return;
         }
-
-        /*if (args.KeyModifiers == KeyModifiers.None)
-        {
-
-            VecD mouseSnap =
-                document.SnappingHandler.SnappingController.GetSnapPoint(args.PositionOnCanvas, out _,
-                    out _);
-
-            if (startingPath.Points.Count > 0 && startingPath.Points[0] == (VecF)mouseSnap)
-            {
-                startingPath.Close();
-            }
-            else
-            {
-                startingPath.LineTo((VecF)mouseSnap);
-            }
-
-            PathVectorData vectorData = ConstructShapeData();
-
-            internals.ActionAccumulator.AddActions(new SetShapeGeometry_Action(member.Id, vectorData));
-            mouseDown = true;
-        }*/
     }
     
     private bool WholePathClosed()

+ 16 - 1
src/PixiEditor/ViewModels/Tools/Tools/VectorPathToolViewModel.cs

@@ -30,6 +30,8 @@ internal class VectorPathToolViewModel : ShapeTool, IVectorPathToolHandler
     private LocalizedString actionDisplayDefault;
     private LocalizedString actionDisplayCtrl;
     private LocalizedString actionDisplayAlt;
+    private LocalizedString actionDisplayShift;
+    private LocalizedString actionDisplayCtrlShift;
 
     [Settings.Enum("FILL_MODE", PathFillType.Winding)]
     public PathFillType FillMode
@@ -49,6 +51,8 @@ internal class VectorPathToolViewModel : ShapeTool, IVectorPathToolHandler
         actionDisplayDefault = new LocalizedString("PATH_TOOL_ACTION_DISPLAY");
         actionDisplayCtrl = new LocalizedString("PATH_TOOL_ACTION_DISPLAY_CTRL");
         actionDisplayAlt = new LocalizedString("PATH_TOOL_ACTION_DISPLAY_ALT");
+        actionDisplayShift = new LocalizedString("PATH_TOOL_ACTION_DISPLAY_SHIFT");
+        actionDisplayCtrlShift = new LocalizedString("PATH_TOOL_ACTION_DISPLAY_CTRL_SHIFT");
     }
 
     public override void UseTool(VecD pos)
@@ -69,12 +73,23 @@ internal class VectorPathToolViewModel : ShapeTool, IVectorPathToolHandler
     {
         if (ctrlIsDown)
         {
-            ActionDisplay = actionDisplayCtrl;
+            if (shiftIsDown)
+            {
+                ActionDisplay = actionDisplayCtrlShift;
+            }
+            else
+            {
+                ActionDisplay = actionDisplayCtrl;
+            }
         }
         else if (altIsDown)
         {
             ActionDisplay = actionDisplayAlt;
         }
+        else if (shiftIsDown)
+        {
+            ActionDisplay = actionDisplayShift;
+        }
         else
         {
             ActionDisplay = actionDisplayDefault;

+ 41 - 27
src/PixiEditor/Views/Overlays/PathOverlay/VectorPathOverlay.cs

@@ -111,7 +111,7 @@ public class VectorPathOverlay : Overlay
 
     public override bool CanRender()
     {
-        return Path != null;
+        return Path is { IsEmpty: false };
     }
 
     private void RenderHandles(Canvas context)
@@ -367,27 +367,34 @@ public class VectorPathOverlay : Overlay
 
     private void DeleteSelectedPoints()
     {
-        var selectedHandle = anchorHandles.FirstOrDefault(h => h.IsSelected);
-        if (selectedHandle == null)
+        var selectedHandles = anchorHandles.Where(h => h.IsSelected).ToList();
+        if (selectedHandles == null || selectedHandles.Count == 0)
         {
             return;
         }
+        
+        int handleAdjustment = 0;
 
-        int index = anchorHandles.IndexOf(selectedHandle);
-        SubShape subShapeContainingIndex = editableVectorPath.GetSubShapeContainingIndex(index);
-        int localIndex = editableVectorPath.GetSubShapePointIndex(index, subShapeContainingIndex);
-
-        if (subShapeContainingIndex.Points.Count == 1)
+        foreach (var handle in selectedHandles)
         {
-            editableVectorPath.RemoveSubShape(subShapeContainingIndex);
-        }
-        else
-        {
-            subShapeContainingIndex.RemovePoint(localIndex);
-        }
+            int index = anchorHandles.IndexOf(handle) - handleAdjustment;
+            SubShape subShapeContainingIndex = editableVectorPath.GetSubShapeContainingIndex(index);
+            int localIndex = editableVectorPath.GetSubShapePointIndex(index, subShapeContainingIndex);
 
-        AddToUndoCommand.Execute(Path);
+            if (subShapeContainingIndex.Points.Count == 1)
+            {
+                editableVectorPath.RemoveSubShape(subShapeContainingIndex);
+            }
+            else
+            {
+                subShapeContainingIndex.RemovePoint(localIndex);
+            }
+            
+            handleAdjustment++;
+        }
+        
         Path = editableVectorPath.ToVectorPath();
+        AddToUndoCommand.Execute(Path);
     }
 
     private void CreateHandle(int atIndex, bool isControlPoint = false)
@@ -429,7 +436,8 @@ public class VectorPathOverlay : Overlay
 
         if (args.Modifiers.HasFlag(KeyModifiers.Control))
         {
-            SelectAnchor(anchorHandle);
+            bool append = args.Modifiers.HasFlag(KeyModifiers.Shift);
+            SelectAnchor(anchorHandle, append);
             return;
         }
 
@@ -469,8 +477,14 @@ public class VectorPathOverlay : Overlay
         Path = editableVectorPath.ToVectorPath();
     }
 
-    private void SelectAnchor(AnchorHandle handle)
+    private void SelectAnchor(AnchorHandle handle, bool append = false)
     {
+        if (append)
+        {
+            handle.IsSelected = !handle.IsSelected;
+            return;
+        }
+
         foreach (var anchorHandle in anchorHandles)
         {
             anchorHandle.IsSelected = anchorHandle == handle;
@@ -484,7 +498,7 @@ public class VectorPathOverlay : Overlay
             return;
         }
 
-        if (args.Modifiers.HasFlag(KeyModifiers.Shift) && IsOverPath(args.Point, out VecD closestPoint))
+        if (args.Modifiers == KeyModifiers.Shift && IsOverPath(args.Point, out VecD closestPoint))
         {
             AddPointAt(closestPoint);
             AddToUndoCommand.Execute(Path);
@@ -492,15 +506,14 @@ public class VectorPathOverlay : Overlay
         }
         else if (args.Modifiers == KeyModifiers.None)
         {
-            AddNewPointFromClick(args.Point);
+            args.Handled = AddNewPointFromClick(args.Point);
             AddToUndoCommand.Execute(Path);
-            args.Handled = true;
         }
     }
 
     protected override void OnOverlayPointerMoved(OverlayPointerArgs args)
     {
-        if (args.Modifiers.HasFlag(KeyModifiers.Shift) && IsOverPath(args.Point, out VecD closestPoint))
+        if (args.Modifiers == KeyModifiers.Shift && IsOverPath(args.Point, out VecD closestPoint))
         {
             insertPreviewHandle.Position = closestPoint;
             canInsert = true;
@@ -511,20 +524,20 @@ public class VectorPathOverlay : Overlay
         }
     }
 
-    private void AddNewPointFromClick(VecD point)
+    private bool AddNewPointFromClick(VecD point)
     {
         var selectedHandle = anchorHandles.FirstOrDefault(h => h.IsSelected);
         SubShape subShape = editableVectorPath.GetSubShapeContainingIndex(anchorHandles.IndexOf(selectedHandle));
 
         if (subShape.IsClosed)
         {
-            return;
+            return false;
         }
 
         if (Path.IsEmpty)
         {
             Path = new VectorPath();
-            Path.LineTo((VecF)point);
+            Path.MoveTo((VecF)point);
             SelectAnchor(anchorHandles[0]);
         }
         else
@@ -533,6 +546,8 @@ public class VectorPathOverlay : Overlay
             Path = editableVectorPath.ToVectorPath();
             SelectAnchor(anchorHandles.Last());
         }
+        
+        return true;
     }
 
     private void AddPointAt(VecD point)
@@ -554,7 +569,6 @@ public class VectorPathOverlay : Overlay
         if (source is AnchorHandle anchorHandle)
         {
             SnappingController.RemoveAll($"editingPath[{anchorHandles.IndexOf(anchorHandle)}]");
-            SelectAnchor(anchorHandle);
             CaptureHandle(source);
             args.Handled = true;
         }
@@ -604,10 +618,10 @@ public class VectorPathOverlay : Overlay
         if (isDraggingControlPoints)
         {
             var newPath = ConvertTouchingVerbsToCubic(handle);
-            
+
             subShapeContainingIndex = newPath.GetSubShapeContainingIndex(index);
             localIndex = newPath.GetSubShapePointIndex(index, subShapeContainingIndex);
-            
+
             HandleContinousCubicDrag(targetPos, handle, subShapeContainingIndex, localIndex, true);
         }
         else