2
0
flabbet 9 сар өмнө
parent
commit
f82f6d26f4

+ 1 - 1
src/PixiEditor/Models/DocumentModels/ChangeExecutionController.cs

@@ -284,7 +284,7 @@ internal class ChangeExecutionController
 
     public void PathOverlayChangedInlet(VectorPath path)
     {
-        if (currentSession is IPathExecutor vectorPathToolExecutor)
+        if (currentSession is IPathExecutorFeature vectorPathToolExecutor)
         {
             vectorPathToolExecutor.OnPathChanged(path);
         }

+ 6 - 1
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/ComplexShapeToolExecutor.cs → src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/DrawableShapeToolExecutor.cs

@@ -15,7 +15,7 @@ namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 
 #nullable enable
 
-internal abstract class ComplexShapeToolExecutor<T> : SimpleShapeToolExecutor where T : IShapeToolHandler
+internal abstract class DrawableShapeToolExecutor<T> : SimpleShapeToolExecutor where T : IShapeToolHandler
 {
     protected int StrokeWidth => toolbar.ToolSize;
 
@@ -296,4 +296,9 @@ internal abstract class ComplexShapeToolExecutor<T> : SimpleShapeToolExecutor wh
         base.ForceStop();
         internals!.ActionAccumulator.AddFinishedActions(EndDrawAction());
     }
+
+    protected override void StopTransformMode()
+    {
+        document!.TransformHandler.HideTransform();
+    }
 }

+ 1 - 1
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/Features/IPathExecutor.cs → src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/Features/IPathExecutorFeature.cs

@@ -2,7 +2,7 @@
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors.Features;
 
-public interface IPathExecutor : IExecutorFeature
+public interface IPathExecutorFeature : IExecutorFeature
 {
     public void OnPathChanged(VectorPath path);
 }

+ 5 - 1
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/LineExecutor.cs

@@ -72,7 +72,6 @@ internal abstract class LineExecutor<T> : SimpleShapeToolExecutor where T : ILin
                 return ExecutionState.Success;
             }
 
-
             if (!InitShapeData(data))
             {
                 ActiveMode = ShapeToolMode.Preview;
@@ -208,4 +207,9 @@ internal abstract class LineExecutor<T> : SimpleShapeToolExecutor where T : ILin
         var endDrawAction = EndDraw();
         internals!.ActionAccumulator.AddFinishedActions(endDrawAction);
     }
+
+    protected override void StopTransformMode()
+    {
+        document!.LineToolOverlayHandler.Hide();
+    }
 }

+ 1 - 1
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/RasterEllipseToolExecutor.cs

@@ -9,7 +9,7 @@ using Drawie.Numerics;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 #nullable enable
-internal class RasterEllipseToolExecutor : ComplexShapeToolExecutor<IRasterEllipseToolHandler>
+internal class RasterEllipseToolExecutor : DrawableShapeToolExecutor<IRasterEllipseToolHandler>
 {
     private void DrawEllipseOrCircle(VecI curPos, double rotationRad, bool firstDraw)
     {

+ 1 - 1
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/RasterRectangleToolExecutor.cs

@@ -8,7 +8,7 @@ using Drawie.Numerics;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 #nullable enable
-internal class RasterRectangleToolExecutor : ComplexShapeToolExecutor<IRasterRectangleToolHandler>
+internal class RasterRectangleToolExecutor : DrawableShapeToolExecutor<IRasterRectangleToolHandler>
 {
     private ShapeData lastData;
     public override ExecutorType Type => ExecutorType.ToolLinked;

+ 2 - 6
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/SimpleShapeToolExecutor.cs

@@ -102,11 +102,7 @@ internal abstract class SimpleShapeToolExecutor : UpdateableChangeExecutor,
         }
     }
 
-    private void StopTransformMode()
-    {
-        document!.TransformHandler.HideTransform();
-        document!.LineToolOverlayHandler.Hide();
-    }
+    protected abstract void StopTransformMode();
 
     public override void OnLeftMouseButtonDown(MouseOnCanvasEventArgs args)
     {
@@ -211,7 +207,7 @@ internal abstract class SimpleShapeToolExecutor : UpdateableChangeExecutor,
     public abstract bool CanUndo { get; } 
     public abstract bool CanRedo { get; }
 
-    public bool IsFeatureEnabled(IExecutorFeature feature)
+    public virtual bool IsFeatureEnabled(IExecutorFeature feature)
     {
         if (feature is ITransformableExecutor)
         {

+ 1 - 1
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorEllipseToolExecutor.cs

@@ -11,7 +11,7 @@ using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 
-internal class VectorEllipseToolExecutor : ComplexShapeToolExecutor<IVectorEllipseToolHandler>
+internal class VectorEllipseToolExecutor : DrawableShapeToolExecutor<IVectorEllipseToolHandler>
 {
     public override ExecutorType Type => ExecutorType.ToolLinked;
     protected override DocumentTransformMode TransformMode => DocumentTransformMode.Scale_Rotate_Shear_NoPerspective;

+ 21 - 5
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorPathToolExecutor.cs

@@ -1,4 +1,5 @@
 using Avalonia.Media;
+using ChunkyImageLib.DataHolders;
 using Drawie.Backend.Core.Vector;
 using Drawie.Numerics;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
@@ -15,7 +16,7 @@ using Colors = Drawie.Backend.Core.ColorsImpl.Colors;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 
-internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutor, IMidChangeUndoableExecutor
+internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutorFeature, IMidChangeUndoableExecutor
 {
     private IStructureMemberHandler member;
     private VectorPath startingPath;
@@ -45,6 +46,7 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutor,
         if (member is IVectorLayerHandler vectorLayerHandler)
         {
             var shapeData = vectorLayerHandler.GetShapeData(document.AnimationHandler.ActiveFrameTime);
+            bool wasNull = false;
             if (shapeData is PathVectorData pathData)
             {
                 startingPath = new VectorPath(pathData.Path);
@@ -52,6 +54,7 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutor,
             }
             else if (shapeData is null)
             {
+                wasNull = true;
                 startingPath = new VectorPath();
             }
             else
@@ -61,11 +64,22 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutor,
 
             if (controller.LeftMousePressed)
             {
-                startingPath.MoveTo((VecF)controller.LastPrecisePosition);
+                if (wasNull)
+                {
+                    startingPath.MoveTo((VecF)controller.LastPrecisePosition);
+                }
+                else
+                {
+                    startingPath.LineTo((VecF)controller.LastPrecisePosition);
+                }
+
+                //below forces undo before starting new path
+                internals.ActionAccumulator.AddFinishedActions(new EndSetShapeGeometry_Action());
+                
                 internals.ActionAccumulator.AddActions(new SetShapeGeometry_Action(member.Id, ConstructShapeData()));
             }
 
-            document.PathOverlayHandler.Show(startingPath);
+            document.PathOverlayHandler.Show(startingPath, false);
         }
         else
         {
@@ -108,7 +122,7 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutor,
     {
         document.PathOverlayHandler.Hide();
         document.SnappingHandler.AddFromBounds(member.Id.ToString(), () => member.TightBounds ?? RectD.Empty);
-        internals.ActionAccumulator.AddActions(new EndSetShapeGeometry_Action());
+        internals.ActionAccumulator.AddFinishedActions(new EndSetShapeGeometry_Action());
     }
 
     private PathVectorData ConstructShapeData()
@@ -134,7 +148,9 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutor,
     {
         return feature switch
         {
-            IPathExecutor _ => true,
+            IPathExecutorFeature _ => true,
+            IMidChangeUndoableExecutor _ => true,
+            ITransformableExecutor _ => true,
             _ => false
         };
     }

+ 1 - 1
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorRectangleToolExecutor.cs

@@ -11,7 +11,7 @@ using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 
-internal class VectorRectangleToolExecutor : ComplexShapeToolExecutor<IVectorRectangleToolHandler>
+internal class VectorRectangleToolExecutor : DrawableShapeToolExecutor<IVectorRectangleToolHandler>
 {
     public override ExecutorType Type => ExecutorType.ToolLinked;
     protected override DocumentTransformMode TransformMode => DocumentTransformMode.Scale_Rotate_Shear_NoPerspective;

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

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

+ 11 - 1
src/PixiEditor/ViewModels/Document/TransformOverlays/PathOverlayViewModel.cs

@@ -45,6 +45,14 @@ internal class PathOverlayViewModel : ObservableObject, IPathOverlayHandler
     public bool HasRedo => undoStack.RedoCount > 0;
 
     public RelayCommand<VectorPath> AddToUndoCommand { get; }
+    
+    private bool showApplyButton;
+
+    public bool ShowApplyButton
+    {
+        get => showApplyButton;
+        set => SetProperty(ref showApplyButton, value);
+    }
 
     private bool suppressUndo = false;
 
@@ -57,7 +65,7 @@ internal class PathOverlayViewModel : ObservableObject, IPathOverlayHandler
         undoStack = new PathOverlayUndoStack<VectorPath>();
     }
 
-    public void Show(VectorPath newPath)
+    public void Show(VectorPath newPath, bool showApplyButton)
     {
         if (IsActive)
         {
@@ -69,12 +77,14 @@ internal class PathOverlayViewModel : ObservableObject, IPathOverlayHandler
         undoStack.AddState(new VectorPath(newPath));
         Path = newPath;
         IsActive = true;
+        ShowApplyButton = showApplyButton;
     }
 
     public void Hide()
     {
         IsActive = false;
         Path = null;
+        ShowApplyButton = false;
     }
 
     public void Undo()

+ 5 - 3
src/PixiEditor/ViewModels/Tools/Tools/VectorPathToolViewModel.cs

@@ -50,10 +50,12 @@ internal class VectorPathToolViewModel : ShapeTool, IVectorPathToolHandler
                 OnSelected(false);
             });
         }
-
-        if (!doc.PathOverlayViewModel.IsActive)
+        else
         {
-            doc?.Tools.UseVectorPathTool();
+            if (!doc.PathOverlayViewModel.IsActive)
+            {
+                doc?.Tools.UseVectorPathTool();
+            }
         }
     }
     

+ 1 - 0
src/PixiEditor/Views/Main/ViewportControls/Viewport.axaml

@@ -182,6 +182,7 @@
                     <MultiBinding.Bindings>
                         <Binding ElementName="vpUc" Path="Document.TransformViewModel.ShowTransformControls" />
                         <Binding ElementName="vpUc" Path="Document.LineToolOverlayViewModel.ShowApplyButton" />
+                        <Binding ElementName="vpUc" Path="Document.PathOverlayViewModel.ShowApplyButton" />
                     </MultiBinding.Bindings>
                 </MultiBinding>
             </Button.IsVisible>