Equbuxu 3 years ago
parent
commit
f39d88f432

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

@@ -6,6 +6,7 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
     private readonly Guid memberGuid;
     private readonly Guid memberGuid;
     private readonly SKColor color;
     private readonly SKColor color;
     private readonly int strokeWidth;
     private readonly int strokeWidth;
+    private readonly bool replacing;
     private readonly bool drawOnMask;
     private readonly bool drawOnMask;
 
 
     bool firstApply = true;
     bool firstApply = true;
@@ -14,11 +15,12 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
     private readonly List<VecI> points = new();
     private readonly List<VecI> points = new();
 
 
     [GenerateUpdateableChangeActions]
     [GenerateUpdateableChangeActions]
-    public LineBasedPen_UpdateableChange(Guid memberGuid, SKColor color, VecI pos, int strokeWidth, bool drawOnMask)
+    public LineBasedPen_UpdateableChange(Guid memberGuid, SKColor color, VecI pos, int strokeWidth, bool replacing, bool drawOnMask)
     {
     {
         this.memberGuid = memberGuid;
         this.memberGuid = memberGuid;
         this.color = color;
         this.color = color;
         this.strokeWidth = strokeWidth;
         this.strokeWidth = strokeWidth;
+        this.replacing = replacing;
         this.drawOnMask = drawOnMask;
         this.drawOnMask = drawOnMask;
         points.Add(pos);
         points.Add(pos);
     }
     }
@@ -36,7 +38,8 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
         if (strokeWidth < 1)
         if (strokeWidth < 1)
             return new Error();
             return new Error();
         var image = DrawingChangeHelper.GetTargetImageOrThrow(target, memberGuid, drawOnMask);
         var image = DrawingChangeHelper.GetTargetImageOrThrow(target, memberGuid, drawOnMask);
-        image.SetBlendMode(SKBlendMode.SrcOver);
+        if (!replacing)
+            image.SetBlendMode(SKBlendMode.SrcOver);
         DrawingChangeHelper.ApplyClipsSymmetriesEtc(target, image, memberGuid, drawOnMask);
         DrawingChangeHelper.ApplyClipsSymmetriesEtc(target, image, memberGuid, drawOnMask);
         return new Success();
         return new Success();
     }
     }
@@ -96,7 +99,8 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
         }
         }
         else
         else
         {
         {
-            image.SetBlendMode(SKBlendMode.SrcOver);
+            if (!replacing)
+                image.SetBlendMode(SKBlendMode.SrcOver);
             DrawingChangeHelper.ApplyClipsSymmetriesEtc(target, image, memberGuid, drawOnMask);
             DrawingChangeHelper.ApplyClipsSymmetriesEtc(target, image, memberGuid, drawOnMask);
 
 
             FastforwardEnqueueDrawLines(image);
             FastforwardEnqueueDrawLines(image);

+ 1 - 0
src/PixiEditorPrototype/Models/Tool.cs

@@ -6,6 +6,7 @@ internal enum Tool
     Ellipse,
     Ellipse,
     PathBasedPen,
     PathBasedPen,
     LineBasedPen,
     LineBasedPen,
+    Eraser,
     Select,
     Select,
     Lasso,
     Lasso,
     ShiftLayer,
     ShiftLayer,

+ 3 - 2
src/PixiEditorPrototype/ViewModels/DocumentViewModel.cs

@@ -313,7 +313,7 @@ internal class DocumentViewModel : INotifyPropertyChanged
         Helpers.ActionAccumulator.AddFinishedActions(new EndPathBasedPen_Action());
         Helpers.ActionAccumulator.AddFinishedActions(new EndPathBasedPen_Action());
     }
     }
 
 
-    public void StartUpdateLineBasedPen(VecI pos)
+    public void StartUpdateLineBasedPen(VecI pos, SKColor color, bool replacing = false)
     {
     {
         if (!CanStartUpdate())
         if (!CanStartUpdate())
             return;
             return;
@@ -321,9 +321,10 @@ internal class DocumentViewModel : INotifyPropertyChanged
         drawingLineBasedPen = true;
         drawingLineBasedPen = true;
         Helpers.ActionAccumulator.AddActions(new LineBasedPen_Action(
         Helpers.ActionAccumulator.AddActions(new LineBasedPen_Action(
             SelectedStructureMember!.GuidValue,
             SelectedStructureMember!.GuidValue,
-            new SKColor(owner.SelectedColor.R, owner.SelectedColor.G, owner.SelectedColor.B, owner.SelectedColor.A),
+            color,
             pos,
             pos,
             (int)owner.StrokeWidth,
             (int)owner.StrokeWidth,
+            replacing,
             SelectedStructureMember.ShouldDrawOnMask));
             SelectedStructureMember.ShouldDrawOnMask));
     }
     }
 
 

+ 10 - 2
src/PixiEditorPrototype/ViewModels/ViewModelMain.cs

@@ -136,7 +136,11 @@ internal class ViewModelMain : INotifyPropertyChanged
         }
         }
         else if (toolOnMouseDown == Tool.LineBasedPen)
         else if (toolOnMouseDown == Tool.LineBasedPen)
         {
         {
-            ActiveDocument!.StartUpdateLineBasedPen((VecI)pos);
+            ActiveDocument!.StartUpdateLineBasedPen((VecI)pos, new SKColor(SelectedColor.R, SelectedColor.G, SelectedColor.B, SelectedColor.A));
+        }
+        else if (toolOnMouseDown == Tool.Eraser)
+        {
+            ActiveDocument!.StartUpdateLineBasedPen((VecI)pos, SKColors.Transparent, true);
         }
         }
     }
     }
 
 
@@ -195,7 +199,10 @@ internal class ViewModelMain : INotifyPropertyChanged
                 ActiveDocument!.StartUpdatePathBasedPen(canvasPos);
                 ActiveDocument!.StartUpdatePathBasedPen(canvasPos);
                 break;
                 break;
             case Tool.LineBasedPen:
             case Tool.LineBasedPen:
-                ActiveDocument!.StartUpdateLineBasedPen((VecI)canvasPos);
+                ActiveDocument!.StartUpdateLineBasedPen((VecI)canvasPos, new SKColor(SelectedColor.R, SelectedColor.G, SelectedColor.B, SelectedColor.A));
+                break;
+            case Tool.Eraser:
+                ActiveDocument!.StartUpdateLineBasedPen((VecI)canvasPos, SKColors.Transparent, true);
                 break;
                 break;
         }
         }
     }
     }
@@ -239,6 +246,7 @@ internal class ViewModelMain : INotifyPropertyChanged
                 ActiveDocument!.EndPathBasedPen();
                 ActiveDocument!.EndPathBasedPen();
                 break;
                 break;
             case Tool.LineBasedPen:
             case Tool.LineBasedPen:
+            case Tool.Eraser:
                 ActiveDocument!.EndLineBasedPen();
                 ActiveDocument!.EndLineBasedPen();
                 break;
                 break;
         }
         }

+ 1 - 0
src/PixiEditorPrototype/Views/MainWindow.xaml

@@ -215,6 +215,7 @@
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.Ellipse}">Ellipse</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.Ellipse}">Ellipse</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.PathBasedPen}">Path Pen</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.PathBasedPen}">Path Pen</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.LineBasedPen}">Line Pen</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.LineBasedPen}">Line Pen</Button>
+                <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.Eraser}">Eraser</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.Select}">Select</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.Select}">Select</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.Lasso}">Lasso</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.Lasso}">Lasso</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.ShiftLayer}">Shift Layer</Button>
                 <Button Width="70" Margin="5" Command="{Binding ChangeActiveToolCommand}" CommandParameter="{x:Static models:Tool.ShiftLayer}">Shift Layer</Button>

+ 0 - 1
src/README.md

@@ -97,7 +97,6 @@ Decouples the state of a document from the UI.
         - [x] Path-based pen
         - [x] Path-based pen
         - [x] Regular pen
         - [x] Regular pen
         - [ ] Pixel-perfect pen
         - [ ] Pixel-perfect pen
-        - [ ] Eraser (same as pen?)
         - [ ] Fill
         - [ ] Fill
         - [ ] Brightness
         - [ ] Brightness
         - [x] Basic selection changes
         - [x] Basic selection changes