Browse Source

Added possibility to change tool size during drawing

flabbet 1 year ago
parent
commit
12f2657301

+ 3 - 2
src/PixiEditor.ChangeableDocument/Changes/Drawing/LineBasedPen_UpdateableChange.cs

@@ -9,7 +9,7 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
 {
 {
     private readonly Guid memberGuid;
     private readonly Guid memberGuid;
     private readonly Color color;
     private readonly Color color;
-    private readonly int strokeWidth;
+    private int strokeWidth;
     private readonly bool replacing;
     private readonly bool replacing;
     private readonly bool drawOnMask;
     private readonly bool drawOnMask;
     private readonly Paint srcPaint = new Paint() { BlendMode = BlendMode.Src };
     private readonly Paint srcPaint = new Paint() { BlendMode = BlendMode.Src };
@@ -32,9 +32,10 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
 }
 }
 
 
     [UpdateChangeMethod]
     [UpdateChangeMethod]
-    public void Update(VecI pos)
+    public void Update(VecI pos, int strokeWidth)
     {
     {
         points.Add(pos);
         points.Add(pos);
+        this.strokeWidth = strokeWidth;
     }
     }
 
 
     public override bool InitializeAndValidate(Document target)
     public override bool InitializeAndValidate(Document target)

+ 7 - 4
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/PenToolExecutor.cs

@@ -8,6 +8,7 @@ using PixiEditor.Models.Handlers.Toolbars;
 using PixiEditor.Models.Handlers.Tools;
 using PixiEditor.Models.Handlers.Tools;
 using PixiEditor.Models.Tools;
 using PixiEditor.Models.Tools;
 using PixiEditor.Numerics;
 using PixiEditor.Numerics;
+using PixiEditor.ViewModels.Tools.ToolSettings.Toolbars;
 
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 #nullable enable
 #nullable enable
@@ -15,10 +16,12 @@ internal class PenToolExecutor : UpdateableChangeExecutor
 {
 {
     private Guid guidValue;
     private Guid guidValue;
     private Color color;
     private Color color;
-    private int toolSize;
+    public int ToolSize => basicToolbar.ToolSize;
     private bool drawOnMask;
     private bool drawOnMask;
     private bool pixelPerfect;
     private bool pixelPerfect;
 
 
+    private IBasicToolbar basicToolbar;
+
     public override ExecutionState Start()
     public override ExecutionState Start()
     {
     {
         IStructureMemberHandler? member = document!.SelectedStructureMember;
         IStructureMemberHandler? member = document!.SelectedStructureMember;
@@ -33,15 +36,15 @@ internal class PenToolExecutor : UpdateableChangeExecutor
         if (!drawOnMask && member is not ILayerHandler)
         if (!drawOnMask && member is not ILayerHandler)
             return ExecutionState.Error;
             return ExecutionState.Error;
 
 
+        basicToolbar = toolbar;
         guidValue = member.Id;
         guidValue = member.Id;
         color = colorsHandler.PrimaryColor;
         color = colorsHandler.PrimaryColor;
-        toolSize = toolbar.ToolSize;
         pixelPerfect = penTool.PixelPerfectEnabled;
         pixelPerfect = penTool.PixelPerfectEnabled;
 
 
         colorsHandler.AddSwatch(new PaletteColor(color.R, color.G, color.B));
         colorsHandler.AddSwatch(new PaletteColor(color.R, color.G, color.B));
         IAction? action = pixelPerfect switch
         IAction? action = pixelPerfect switch
         {
         {
-            false => new LineBasedPen_Action(guidValue, color, controller!.LastPixelPosition, toolSize, false, drawOnMask, document!.AnimationHandler.ActiveFrameBindable),
+            false => new LineBasedPen_Action(guidValue, color, controller!.LastPixelPosition, ToolSize, false, drawOnMask, document!.AnimationHandler.ActiveFrameBindable),
             true => new PixelPerfectPen_Action(guidValue, controller!.LastPixelPosition, color, drawOnMask, document!.AnimationHandler.ActiveFrameBindable)
             true => new PixelPerfectPen_Action(guidValue, controller!.LastPixelPosition, color, drawOnMask, document!.AnimationHandler.ActiveFrameBindable)
         };
         };
         internals!.ActionAccumulator.AddActions(action);
         internals!.ActionAccumulator.AddActions(action);
@@ -53,7 +56,7 @@ internal class PenToolExecutor : UpdateableChangeExecutor
     {
     {
         IAction? action = pixelPerfect switch
         IAction? action = pixelPerfect switch
         {
         {
-            false => new LineBasedPen_Action(guidValue, color, pos, toolSize, false, drawOnMask, document!.AnimationHandler.ActiveFrameBindable),
+            false => new LineBasedPen_Action(guidValue, color, pos, ToolSize, false, drawOnMask, document!.AnimationHandler.ActiveFrameBindable),
             true => new PixelPerfectPen_Action(guidValue, pos, color, drawOnMask, document!.AnimationHandler.ActiveFrameBindable)
             true => new PixelPerfectPen_Action(guidValue, pos, color, drawOnMask, document!.AnimationHandler.ActiveFrameBindable)
         };
         };
         internals!.ActionAccumulator.AddActions(action);
         internals!.ActionAccumulator.AddActions(action);