Browse Source

Fixed applying settings to other layer

flabbet 8 months ago
parent
commit
c52aa45459

+ 11 - 2
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/DrawableShapeToolExecutor.cs

@@ -77,7 +77,8 @@ internal abstract class DrawableShapeToolExecutor<T> : SimpleShapeToolExecutor w
         if (member is IVectorLayerHandler vectorLayerHandler)
         {
             var shapeData = vectorLayerHandler.GetShapeData(document.AnimationHandler.ActiveFrameTime);
-            if (shapeData == null || !InitShapeData(shapeData))
+            bool shapeIsValid = InitShapeData(shapeData);
+            if (shapeData == null || !shapeIsValid)
             {
                 ActiveMode = ShapeToolMode.Preview;
                 return ExecutionState.Success;
@@ -103,6 +104,7 @@ internal abstract class DrawableShapeToolExecutor<T> : SimpleShapeToolExecutor w
     protected abstract IAction SettingsChangedAction();
     protected abstract IAction TransformMovedAction(ShapeData data, ShapeCorners corners);
     protected virtual bool InitShapeData(IReadOnlyShapeVectorData data) { return true; }
+    protected abstract bool CanEditShape(IStructureMemberHandler layer);
     protected abstract IAction EndDrawAction();
     protected virtual DocumentTransformMode TransformMode => DocumentTransformMode.Scale_Rotate_NoShear_NoPerspective;
 
@@ -297,7 +299,14 @@ internal abstract class DrawableShapeToolExecutor<T> : SimpleShapeToolExecutor w
 
     public override void OnSettingsChanged(string name, object value)
     {
-        internals!.ActionAccumulator.AddActions(SettingsChangedAction());
+        var layer = document.StructureHelper.Find(memberId);
+        if (layer is null)
+            return;
+        
+        if (CanEditShape(layer))
+        {
+            internals!.ActionAccumulator.AddActions(SettingsChangedAction());
+        }
     }
 
     public override void OnLeftMouseButtonUp(VecD argsPositionOnCanvas)

+ 6 - 0
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/RasterEllipseToolExecutor.cs

@@ -6,6 +6,7 @@ using Drawie.Backend.Core.Numerics;
 using PixiEditor.Models.Handlers.Tools;
 using PixiEditor.Models.Tools;
 using Drawie.Numerics;
+using PixiEditor.Models.Handlers;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 #nullable enable
@@ -46,5 +47,10 @@ internal class RasterEllipseToolExecutor : DrawableShapeToolExecutor<IRasterElli
             FillColor, (float)StrokeWidth, toolbar.AntiAliasing, drawOnMask, document!.AnimationHandler.ActiveFrameBindable);
     }
 
+    protected override bool CanEditShape(IStructureMemberHandler layer)
+    {
+        return true;
+    }
+
     protected override IAction EndDrawAction() => new EndDrawRasterEllipse_Action();
 }

+ 6 - 0
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/RasterRectangleToolExecutor.cs

@@ -5,6 +5,7 @@ using Drawie.Backend.Core.Numerics;
 using PixiEditor.Models.Handlers.Tools;
 using PixiEditor.Models.Tools;
 using Drawie.Numerics;
+using PixiEditor.Models.Handlers;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 #nullable enable
@@ -57,5 +58,10 @@ internal class RasterRectangleToolExecutor : DrawableShapeToolExecutor<IRasterRe
             document!.AnimationHandler.ActiveFrameBindable);
     }
 
+    protected override bool CanEditShape(IStructureMemberHandler layer)
+    {
+        return true;
+    }
+
     protected override IAction EndDrawAction() => new EndDrawRasterRectangle_Action();
 }

+ 11 - 0
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorEllipseToolExecutor.cs

@@ -8,6 +8,7 @@ using PixiEditor.Models.Handlers.Tools;
 using PixiEditor.Models.Tools;
 using Drawie.Numerics;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
+using PixiEditor.Models.Handlers;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 
@@ -35,6 +36,16 @@ internal class VectorEllipseToolExecutor : DrawableShapeToolExecutor<IVectorElli
         return true;
     }
 
+    protected override bool CanEditShape(IStructureMemberHandler layer)
+    {
+        IVectorLayerHandler vectorLayer = layer as IVectorLayerHandler;
+        if (vectorLayer is null)
+            return false;
+        
+        var shapeData = vectorLayer.GetShapeData(document.AnimationHandler.ActiveFrameTime);
+        return shapeData is EllipseVectorData;
+    }
+
     protected override void DrawShape(VecD curPos, double rotationRad, bool firstDraw)
     {
         RectD rect;

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

@@ -185,7 +185,10 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutorF
 
     public override void OnSettingsChanged(string name, object value)
     {
-        internals.ActionAccumulator.AddActions(new SetShapeGeometry_Action(member.Id, ConstructShapeData()));
+        if (document.PathOverlayHandler.IsActive)
+        {
+            internals.ActionAccumulator.AddActions(new SetShapeGeometry_Action(member.Id, ConstructShapeData()));
+        }
     }
 
     public override void ForceStop()

+ 16 - 4
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorRectangleToolExecutor.cs

@@ -8,6 +8,7 @@ using PixiEditor.Models.Handlers.Tools;
 using PixiEditor.Models.Tools;
 using Drawie.Numerics;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
+using PixiEditor.Models.Handlers;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 
@@ -34,6 +35,16 @@ internal class VectorRectangleToolExecutor : DrawableShapeToolExecutor<IVectorRe
         return true;
     }
 
+    protected override bool CanEditShape(IStructureMemberHandler layer)
+    {
+        IVectorLayerHandler vectorLayer = layer as IVectorLayerHandler;
+        if (vectorLayer is null)
+            return false;
+
+        var shapeData = vectorLayer.GetShapeData(document.AnimationHandler.ActiveFrameTime);
+        return shapeData is RectangleVectorData;
+    }
+
     protected override void DrawShape(VecD curPos, double rotationRad, bool firstDraw)
     {
         RectD rect;
@@ -81,7 +92,7 @@ internal class VectorRectangleToolExecutor : DrawableShapeToolExecutor<IVectorRe
         }
 
         Matrix3X3 matrix = Matrix3X3.Identity;
-        
+
         if (!corners.IsRect)
         {
             RectD firstRect = RectD.FromCenterAndSize(firstCenter, firstSize);
@@ -93,9 +104,10 @@ internal class VectorRectangleToolExecutor : DrawableShapeToolExecutor<IVectorRe
         {
             firstCenter = data.Center;
             firstSize = data.Size;
-            
-            if(corners.RectRotation != 0)
-                matrix = Matrix3X3.CreateRotation((float)corners.RectRotation, (float)firstCenter.X, (float)firstCenter.Y);
+
+            if (corners.RectRotation != 0)
+                matrix = Matrix3X3.CreateRotation((float)corners.RectRotation, (float)firstCenter.X,
+                    (float)firstCenter.Y);
         }
 
         RectangleVectorData newData = new RectangleVectorData(firstCenter, firstSize)

+ 5 - 2
src/PixiEditor/ViewModels/Document/DocumentViewModel.cs

@@ -256,8 +256,11 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
             if (args.LayerChangeType == LayerAction.Add)
             {
                 IReadOnlyStructureNode layer = Internals.Tracker.Document.FindMember(args.LayerAffectedGuid);
-                SnappingViewModel.AddFromBounds(layer.Id.ToString(),
-                    () => layer.GetTightBounds(AnimationDataViewModel.ActiveFrameTime) ?? RectD.Empty);
+                if (layer is not null)
+                {
+                    SnappingViewModel.AddFromBounds(layer.Id.ToString(),
+                        () => layer.GetTightBounds(AnimationDataViewModel.ActiveFrameTime) ?? RectD.Empty);
+                }
             }
             else if (args.LayerChangeType == LayerAction.Remove)
             {