2
0
Эх сурвалжийг харах

Enable disable overlay on select/deselect

flabbet 9 сар өмнө
parent
commit
82701f1373

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit a98c9d433dd46e0c8462e407d76c22fe39305f02
+Subproject commit c28dcaa0cc2b31c4ccbb239e739de46f455282d4

+ 17 - 4
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorPathToolExecutor.cs

@@ -22,6 +22,8 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutor
     private IVectorPathToolHandler vectorPathToolHandler;
     private IVectorPathToolHandler vectorPathToolHandler;
     private IBasicShapeToolbar toolbar;
     private IBasicShapeToolbar toolbar;
 
 
+    public override ExecutorType Type => ExecutorType.ToolLinked;
+
     public override ExecutionState Start()
     public override ExecutionState Start()
     {
     {
         vectorPathToolHandler = GetHandler<IVectorPathToolHandler>();
         vectorPathToolHandler = GetHandler<IVectorPathToolHandler>();
@@ -51,11 +53,18 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutor
                 return ExecutionState.Error;
                 return ExecutionState.Error;
             }
             }
 
 
-            startingPath.MoveTo((VecF)controller.LastPrecisePosition);
-            internals.ActionAccumulator.AddActions(new SetShapeGeometry_Action(member.Id, ConstructShapeData()));
+            if (controller.LeftMousePressed)
+            {
+                startingPath.MoveTo((VecF)controller.LastPrecisePosition);
+                internals.ActionAccumulator.AddActions(new SetShapeGeometry_Action(member.Id, ConstructShapeData()));
+            }
 
 
             document.PathOverlayHandler.Show(startingPath);
             document.PathOverlayHandler.Show(startingPath);
         }
         }
+        else
+        {
+            return ExecutionState.Error;
+        }
 
 
         return ExecutionState.Success;
         return ExecutionState.Success;
     }
     }
@@ -85,6 +94,7 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutor
 
 
     public override void ForceStop()
     public override void ForceStop()
     {
     {
+        document.PathOverlayHandler.Hide();
         internals.ActionAccumulator.AddActions(new EndSetShapeGeometry_Action());
         internals.ActionAccumulator.AddActions(new EndSetShapeGeometry_Action());
     }
     }
 
 
@@ -100,7 +110,10 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutor
 
 
     public void OnPathChanged(VectorPath path)
     public void OnPathChanged(VectorPath path)
     {
     {
-        startingPath = path;
-        internals.ActionAccumulator.AddActions(new SetShapeGeometry_Action(member.Id, ConstructShapeData()));
+        if (document.PathOverlayHandler.IsActive)
+        {
+            startingPath = path;
+            internals.ActionAccumulator.AddActions(new SetShapeGeometry_Action(member.Id, ConstructShapeData()));
+        }
     }
     }
 }
 }

+ 3 - 1
src/PixiEditor/Models/Handlers/IPathOverlayHandler.cs

@@ -5,5 +5,7 @@ namespace PixiEditor.Models.Handlers;
 public interface IPathOverlayHandler : IHandler
 public interface IPathOverlayHandler : IHandler
 {
 {
     public void Show(VectorPath path);
     public void Show(VectorPath path);
-    public event Action<VectorPath> PathChanged; 
+    public void Hide();
+    public event Action<VectorPath> PathChanged;
+    public bool IsActive { get; }
 }
 }

+ 65 - 0
src/PixiEditor/ViewModels/Document/TransformOverlays/PathOverlayUndoStack.cs

@@ -0,0 +1,65 @@
+using System.Collections.Generic;
+
+namespace PixiEditor.ViewModels.Document.TransformOverlays;
+
+internal class PathOverlayUndoStack<TState> where TState : class
+{
+    private struct StackItem<TState>
+    {
+        public TState State { get; set; }
+
+        public StackItem(TState state)
+        {
+            State = state;
+        }
+    }
+
+    private Stack<StackItem<TState>> undoStack = new();
+    private Stack<StackItem<TState>> redoStack = new();
+    private StackItem<TState>? current;
+
+    public void AddState(TState state)
+    {
+        redoStack.Clear();
+        if (current is not null)
+            undoStack.Push(current.Value);
+
+        current = new(state);
+    }
+
+    public TState? PeekCurrent() => current?.State;
+
+    public int UndoCount => undoStack.Count;
+    public int RedoCount => redoStack.Count;
+
+    public TState? Undo()
+    {
+        if (current is null || undoStack.Count == 0)
+            return null;
+
+        DoUndoStep();
+        return current.Value.State;
+    }
+
+    public TState? Redo()
+    {
+        if (current is null || redoStack.Count == 0)
+            return null;
+
+        DoRedoStep();
+
+        return current.Value.State;
+    }
+
+    private void DoUndoStep()
+    {
+        redoStack.Push(current.Value);
+        current = undoStack.Pop();
+    }
+
+    private void DoRedoStep()
+    {
+        undoStack.Push(current.Value);
+        current = redoStack.Pop();
+    }
+}

+ 15 - 3
src/PixiEditor/ViewModels/Document/TransformOverlays/PathOverlayViewModel.cs

@@ -9,8 +9,12 @@ internal class PathOverlayViewModel : ObservableObject, IPathOverlayHandler
 {
 {
     private DocumentViewModel documentViewModel;
     private DocumentViewModel documentViewModel;
     private DocumentInternalParts internals;
     private DocumentInternalParts internals;
-    
+
+
+    private PathOverlayUndoStack<VectorPath>? undoStack = null;
+
     private VectorPath path;
     private VectorPath path;
+
     public VectorPath Path
     public VectorPath Path
     {
     {
         get => path;
         get => path;
@@ -24,7 +28,8 @@ internal class PathOverlayViewModel : ObservableObject, IPathOverlayHandler
     }
     }
 
 
     public event Action<VectorPath>? PathChanged;
     public event Action<VectorPath>? PathChanged;
-    
+    public bool IsActive { get; set; }
+
     public PathOverlayViewModel(DocumentViewModel documentViewModel, DocumentInternalParts internals)
     public PathOverlayViewModel(DocumentViewModel documentViewModel, DocumentInternalParts internals)
     {
     {
         this.documentViewModel = documentViewModel;
         this.documentViewModel = documentViewModel;
@@ -33,6 +38,13 @@ internal class PathOverlayViewModel : ObservableObject, IPathOverlayHandler
 
 
     public void Show(VectorPath path)
     public void Show(VectorPath path)
     {
     {
-        Path = path;        
+        Path = path;
+        IsActive = true;
+    }
+    
+    public void Hide()
+    {
+        IsActive = false;
+        Path = null;
     }
     }
 }
 }

+ 1 - 3
src/PixiEditor/ViewModels/Document/TransformOverlays/TransformOverlayUndoStack.cs

@@ -1,6 +1,4 @@
-using System.Collections.Generic;
-
-namespace PixiEditor.ViewModels.Document.TransformOverlays;
+namespace PixiEditor.ViewModels.Document.TransformOverlays;
 internal class TransformOverlayUndoStack<TState> where TState : struct
 internal class TransformOverlayUndoStack<TState> where TState : struct
 {
 {
     private struct StackItem<TState>
     private struct StackItem<TState>

+ 15 - 0
src/PixiEditor/ViewModels/Tools/Tools/VectorPathToolViewModel.cs

@@ -27,4 +27,19 @@ internal class VectorPathToolViewModel : ShapeTool, IVectorPathToolHandler
     {
     {
         ViewModelMain.Current?.DocumentManagerSubViewModel.ActiveDocument?.Tools.UseVectorPathTool();
         ViewModelMain.Current?.DocumentManagerSubViewModel.ActiveDocument?.Tools.UseVectorPathTool();
     }
     }
+
+    public override void OnSelected(bool restoring)
+    {
+        if (restoring) return;
+
+        ViewModelMain.Current?.DocumentManagerSubViewModel.ActiveDocument?.Tools.UseVectorPathTool();
+    }
+
+    public override void OnDeselecting(bool transient)
+    {
+        if (!transient)
+        {
+            ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument?.Operations.TryStopToolLinkedExecutor();
+        }
+    }
 }
 }

+ 5 - 0
src/PixiEditor/Views/Overlays/PathOverlay/VectorPathOverlay.cs

@@ -24,6 +24,11 @@ public class VectorPathOverlay : Overlay
     private DashedStroke dashedStroke = new DashedStroke();
     private DashedStroke dashedStroke = new DashedStroke();
 
 
     private List<AnchorHandle> pointsHandles = new List<AnchorHandle>();
     private List<AnchorHandle> pointsHandles = new List<AnchorHandle>();
+    
+    static VectorPathOverlay()
+    {
+        AffectsOverlayRender(PathProperty);
+    }
 
 
     protected override void ZoomChanged(double newZoom)
     protected override void ZoomChanged(double newZoom)
     {
     {