Browse Source

Added Color Picker right click and erase on transparent paint

Krzysztof Krysiński 2 months ago
parent
commit
e79fea9b7a

+ 4 - 0
src/PixiEditor.ChangeableDocument/Changes/Drawing/LineBasedPen_UpdateableChange.cs

@@ -59,6 +59,10 @@ internal class LineBasedPen_UpdateableChange : UpdateableChange
         else if (erasing)
         else if (erasing)
         {
         {
             srcPaint.BlendMode = BlendMode.DstOut;
             srcPaint.BlendMode = BlendMode.DstOut;
+            if (this.color.A == 0)
+            {
+                this.color = color.WithAlpha(255);
+            }
         }
         }
     }
     }
 
 

+ 3 - 1
src/PixiEditor.Extensions.CommonApi/UserPreferences/Settings/PixiEditor/RightClickMode.cs

@@ -9,5 +9,7 @@ public enum RightClickMode
     [Description("SHOW_CONTEXT_MENU")]
     [Description("SHOW_CONTEXT_MENU")]
     ContextMenu,
     ContextMenu,
     [Description("ERASE")]
     [Description("ERASE")]
-    Erase
+    Erase,
+    [Description("COLOR_PICKER")]
+    ColorPicker,
 }
 }

+ 2 - 1
src/PixiEditor/Data/Localization/Languages/en.json

@@ -1046,5 +1046,6 @@
   "IS_DEFAULT_EXPORT": "Is Default Export",
   "IS_DEFAULT_EXPORT": "Is Default Export",
   "EXPORT_OUTPUT": "Export Output",
   "EXPORT_OUTPUT": "Export Output",
   "RENDER_OUTPUT_SIZE": "Render Output Size",
   "RENDER_OUTPUT_SIZE": "Render Output Size",
-  "RENDER_OUTPUT_CENTER": "Render Output Center"
+  "RENDER_OUTPUT_CENTER": "Render Output Center",
+  "COLOR_PICKER": "Color Picker"
 }
 }

+ 9 - 3
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/PenToolExecutor.cs

@@ -22,6 +22,7 @@ internal class PenToolExecutor : UpdateableChangeExecutor
     private bool antiAliasing;
     private bool antiAliasing;
     private float hardness;
     private float hardness;
     private float spacing = 1;
     private float spacing = 1;
+    private bool transparentErase;
 
 
     private IPenToolbar penToolbar;
     private IPenToolbar penToolbar;
 
 
@@ -47,10 +48,15 @@ internal class PenToolExecutor : UpdateableChangeExecutor
         hardness = toolbar.Hardness;
         hardness = toolbar.Hardness;
         spacing = toolbar.Spacing;
         spacing = toolbar.Spacing;
 
 
-        colorsHandler.AddSwatch(new PaletteColor(color.R, color.G, color.B));
+        if (color.A > 0)
+        {
+            colorsHandler.AddSwatch(new PaletteColor(color.R, color.G, color.B));
+        }
+
+        transparentErase = color.A == 0;
         IAction? action = pixelPerfect switch
         IAction? action = pixelPerfect switch
         {
         {
-            false => new LineBasedPen_Action(guidValue, color, controller!.LastPixelPosition, (float)ToolSize, false, antiAliasing, hardness, spacing, SquareBrush, drawOnMask, document!.AnimationHandler.ActiveFrameBindable),
+            false => new LineBasedPen_Action(guidValue, color, controller!.LastPixelPosition, (float)ToolSize, transparentErase, antiAliasing, hardness, spacing, SquareBrush, 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);
@@ -62,7 +68,7 @@ internal class PenToolExecutor : UpdateableChangeExecutor
     {
     {
         IAction? action = pixelPerfect switch
         IAction? action = pixelPerfect switch
         {
         {
-            false => new LineBasedPen_Action(guidValue, color, pos, (float)ToolSize, false, antiAliasing, hardness, spacing, SquareBrush, drawOnMask, document!.AnimationHandler.ActiveFrameBindable),
+            false => new LineBasedPen_Action(guidValue, color, pos, (float)ToolSize, transparentErase, antiAliasing, hardness, spacing, SquareBrush, 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);

+ 16 - 2
src/PixiEditor/ViewModels/SubViewModels/IoViewModel.cs

@@ -256,6 +256,9 @@ internal class IoViewModel : SubViewModel<ViewModelMain>
 
 
                 Owner.ColorsSubViewModel.SwapColors(true);
                 Owner.ColorsSubViewModel.SwapColors(true);
                 return true;
                 return true;
+            case RightClickMode.ColorPicker when tools.ActiveTool is not ColorPickerToolViewModel:
+                HandleRightMouseColorPickerDown(tools);
+                return true;
             case RightClickMode.Erase when tools.ActiveTool is ColorPickerToolViewModel:
             case RightClickMode.Erase when tools.ActiveTool is ColorPickerToolViewModel:
                 Owner.ColorsSubViewModel.SwapColors(true);
                 Owner.ColorsSubViewModel.SwapColors(true);
                 return true;
                 return true;
@@ -316,6 +319,17 @@ internal class IoViewModel : SubViewModel<ViewModelMain>
         tools.SetActiveTool<EraserToolViewModel>(true);
         tools.SetActiveTool<EraserToolViewModel>(true);
     }
     }
 
 
+    private void HandleRightMouseColorPickerDown(IToolsHandler tools)
+    {
+        ColorPickerToolViewModel? colorPickerTool = tools.GetTool<ColorPickerToolViewModel>();
+        if (colorPickerTool == null)
+        {
+            return;
+        }
+
+        tools.SetActiveTool<ColorPickerToolViewModel>(true);
+    }
+
     private void OnMiddleMouseButton()
     private void OnMiddleMouseButton()
     {
     {
         Owner.ToolsSubViewModel.SetActiveTool<MoveViewportToolViewModel>(true);
         Owner.ToolsSubViewModel.SetActiveTool<MoveViewportToolViewModel>(true);
@@ -344,7 +358,7 @@ internal class IoViewModel : SubViewModel<ViewModelMain>
         var tools = Owner.ToolsSubViewModel;
         var tools = Owner.ToolsSubViewModel;
 
 
         var rightCanUp = (button == MouseButton.Right) &&
         var rightCanUp = (button == MouseButton.Right) &&
-                         tools.RightClickMode is RightClickMode.Erase or RightClickMode.SecondaryColor;
+                         tools.RightClickMode is RightClickMode.Erase or RightClickMode.SecondaryColor or RightClickMode.ColorPicker;
 
 
         if (button == MouseButton.Left || rightCanUp)
         if (button == MouseButton.Left || rightCanUp)
         {
         {
@@ -383,7 +397,7 @@ internal class IoViewModel : SubViewModel<ViewModelMain>
                 }
                 }
 
 
                 break;
                 break;
-            case MouseButton.Right when tools.RightClickMode == RightClickMode.Erase:
+            case MouseButton.Right when tools.RightClickMode is RightClickMode.Erase or RightClickMode.ColorPicker:
                 HandleRightMouseEraseUp(tools);
                 HandleRightMouseEraseUp(tools);
                 break;
                 break;
         }
         }

+ 4 - 3
src/PixiEditor/Views/Main/ViewportControls/Viewport.axaml.cs

@@ -663,10 +663,11 @@ internal partial class Viewport : UserControl, INotifyPropertyChanged
         }
         }
 
 
         var useContextMenu = vm.Owner.Owner.ToolsSubViewModel.RightClickMode == RightClickMode.ContextMenu;
         var useContextMenu = vm.Owner.Owner.ToolsSubViewModel.RightClickMode == RightClickMode.ContextMenu;
-        var usesErase = tools.RightClickMode == RightClickMode.Erase && tools.ActiveTool.IsErasable;
-        var usesSecondaryColor = tools.RightClickMode == RightClickMode.SecondaryColor && tools.ActiveTool.UsesColor;
+        var usesErase = tools is { RightClickMode: RightClickMode.Erase, ActiveTool.IsErasable: true };
+        bool usesColorPicker = vm.Owner.Owner.ToolsSubViewModel.RightClickMode == RightClickMode.ColorPicker;
+        var usesSecondaryColor = tools is { RightClickMode: RightClickMode.SecondaryColor, ActiveTool.UsesColor: true };
 
 
-        if (!useContextMenu && (usesErase || usesSecondaryColor))
+        if (!useContextMenu && (usesErase || usesSecondaryColor || usesColorPicker))
         {
         {
             return;
             return;
         }
         }