Browse Source

Added fill mode to path tool

flabbet 8 months ago
parent
commit
97243b1396

+ 8 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/EllipseVectorData.cs

@@ -49,11 +49,15 @@ public class EllipseVectorData : ShapeVectorData, IReadOnlyEllipseData
             ApplyTransformTo(drawingSurface);
             ApplyTransformTo(drawingSurface);
         }
         }
 
 
-        using Paint shapePaint = new Paint() { IsAntiAliased = true };
+        using Paint shapePaint = new Paint();
+        shapePaint.IsAntiAliased = true;
 
 
-        shapePaint.Color = FillColor;
-        shapePaint.Style = PaintStyle.Fill;
-        drawingSurface.Canvas.DrawOval(Center, Radius, shapePaint);
+        if (Fill)
+        {
+            shapePaint.Color = FillColor;
+            shapePaint.Style = PaintStyle.Fill;
+            drawingSurface.Canvas.DrawOval(Center, Radius, shapePaint);
+        }
 
 
         if (StrokeWidth > 0)
         if (StrokeWidth > 0)
         {
         {

+ 9 - 6
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/PathVectorData.cs

@@ -46,7 +46,7 @@ public class PathVectorData : ShapeVectorData, IReadOnlyPathData
             IsAntiAliased = true, StrokeJoin = StrokeJoin.Round, StrokeCap = StrokeCap.Round
             IsAntiAliased = true, StrokeJoin = StrokeJoin.Round, StrokeCap = StrokeCap.Round
         };
         };
 
 
-        if (FillColor.A > 0)
+        if (Fill && FillColor.A > 0)
         {
         {
             paint.Color = FillColor;
             paint.Color = FillColor;
             paint.Style = PaintStyle.Fill;
             paint.Style = PaintStyle.Fill;
@@ -54,11 +54,14 @@ public class PathVectorData : ShapeVectorData, IReadOnlyPathData
             drawingSurface.Canvas.DrawPath(Path, paint);
             drawingSurface.Canvas.DrawPath(Path, paint);
         }
         }
 
 
-        paint.Color = StrokeColor;
-        paint.Style = PaintStyle.Stroke;
-        paint.StrokeWidth = StrokeWidth;
-
-        drawingSurface.Canvas.DrawPath(Path, paint);
+        if (StrokeWidth > 0)
+        {
+            paint.Color = StrokeColor;
+            paint.Style = PaintStyle.Stroke;
+            paint.StrokeWidth = StrokeWidth;
+            
+            drawingSurface.Canvas.DrawPath(Path, paint);
+        }
 
 
         if (applyTransform)
         if (applyTransform)
         {
         {

+ 8 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/RectangleVectorData.cs

@@ -54,11 +54,15 @@ public class RectangleVectorData : ShapeVectorData, IReadOnlyRectangleData
             ApplyTransformTo(drawingSurface);
             ApplyTransformTo(drawingSurface);
         }
         }
 
 
-        using Paint paint = new Paint() { IsAntiAliased = true };
+        using Paint paint = new Paint();
+        paint.IsAntiAliased = true;
 
 
-        paint.Color = FillColor;
-        paint.Style = PaintStyle.Fill;
-        drawingSurface.Canvas.DrawRect(RectD.FromCenterAndSize(Center, Size), paint);
+        if (Fill && FillColor.A > 0)
+        {
+            paint.Color = FillColor;
+            paint.Style = PaintStyle.Fill;
+            drawingSurface.Canvas.DrawRect(RectD.FromCenterAndSize(Center, Size), paint);
+        }
 
 
         if (StrokeWidth > 0)
         if (StrokeWidth > 0)
         {
         {

+ 1 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/ShapeVectorData.cs

@@ -16,6 +16,7 @@ public abstract class ShapeVectorData : ICacheable, ICloneable, IReadOnlyShapeVe
     public Color StrokeColor { get; set; } = Colors.White;
     public Color StrokeColor { get; set; } = Colors.White;
     public Color FillColor { get; set; } = Colors.White;
     public Color FillColor { get; set; } = Colors.White;
     public float StrokeWidth { get; set; } = 1;
     public float StrokeWidth { get; set; } = 1;
+    public bool Fill { get; set; } = true;
     public abstract RectD GeometryAABB { get; } 
     public abstract RectD GeometryAABB { get; } 
     public abstract RectD VisualAABB { get; }
     public abstract RectD VisualAABB { get; }
     public RectD TransformedAABB => new ShapeCorners(GeometryAABB).WithMatrix(TransformationMatrix).AABBBounds;
     public RectD TransformedAABB => new ShapeCorners(GeometryAABB).WithMatrix(TransformationMatrix).AABBBounds;

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

@@ -778,5 +778,6 @@
   "COPY_COLOR_TO_CLIPBOARD": "Copy color to clipboard",
   "COPY_COLOR_TO_CLIPBOARD": "Copy color to clipboard",
   "VIEWPORT_ROTATION": "Viewport rotation",
   "VIEWPORT_ROTATION": "Viewport rotation",
   "NEXT_TOOL_SET": "Next tool set",
   "NEXT_TOOL_SET": "Next tool set",
-  "PREVIOUS_TOOL_SET": "Previous tool set"
+  "PREVIOUS_TOOL_SET": "Previous tool set",
+  "FILL_MODE": "Fill mode"
 }
 }

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

@@ -15,6 +15,7 @@ using PixiEditor.Models.Controllers.InputDevice;
 using PixiEditor.Models.DocumentModels.UpdateableChangeExecutors.Features;
 using PixiEditor.Models.DocumentModels.UpdateableChangeExecutors.Features;
 using PixiEditor.Models.Handlers.Toolbars;
 using PixiEditor.Models.Handlers.Toolbars;
 using PixiEditor.Models.Tools;
 using PixiEditor.Models.Tools;
+using PixiEditor.ViewModels.Tools.Tools;
 using Color = Drawie.Backend.Core.ColorsImpl.Color;
 using Color = Drawie.Backend.Core.ColorsImpl.Color;
 using Colors = Drawie.Backend.Core.ColorsImpl.Colors;
 using Colors = Drawie.Backend.Core.ColorsImpl.Colors;
 
 
@@ -199,7 +200,7 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutorF
     {
     {
         if(startingPath == null)
         if(startingPath == null)
         {
         {
-            return new PathVectorData(new VectorPath())
+            return new PathVectorData(new VectorPath() { FillType = vectorPathToolHandler.FillMode })
             {
             {
                 StrokeWidth = (float)toolbar.ToolSize,
                 StrokeWidth = (float)toolbar.ToolSize,
                 StrokeColor = toolbar.StrokeColor.ToColor(),
                 StrokeColor = toolbar.StrokeColor.ToColor(),
@@ -207,7 +208,7 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutorF
             };
             };
         }
         }
         
         
-        return new PathVectorData(new VectorPath(startingPath))
+        return new PathVectorData(new VectorPath(startingPath) { FillType = vectorPathToolHandler.FillMode })
         {
         {
             StrokeWidth = (float)toolbar.ToolSize,
             StrokeWidth = (float)toolbar.ToolSize,
             StrokeColor = toolbar.StrokeColor.ToColor(),
             StrokeColor = toolbar.StrokeColor.ToColor(),
@@ -268,7 +269,8 @@ internal class VectorPathToolExecutor : UpdateableChangeExecutor, IPathExecutorF
         toolbar.ToolSize = pathData.StrokeWidth;
         toolbar.ToolSize = pathData.StrokeWidth;
         toolbar.StrokeColor = pathData.StrokeColor.ToColor();
         toolbar.StrokeColor = pathData.StrokeColor.ToColor();
         toolbar.ToolSize = pathData.StrokeWidth;
         toolbar.ToolSize = pathData.StrokeWidth;
-        toolbar.Fill = pathData.FillColor.A > 0;
+        toolbar.Fill = pathData.Fill;
         toolbar.FillColor = pathData.FillColor.ToColor();
         toolbar.FillColor = pathData.FillColor.ToColor();
+        toolbar.GetSetting(nameof(VectorPathToolViewModel.FillMode)).Value = pathData.Path.FillType;
     }
     }
 }
 }

+ 4 - 2
src/PixiEditor/Models/Handlers/Tools/IVectorPathToolHandler.cs

@@ -1,6 +1,8 @@
-namespace PixiEditor.Models.Handlers.Tools;
+using Drawie.Backend.Core.Vector;
+
+namespace PixiEditor.Models.Handlers.Tools;
 
 
 internal interface IVectorPathToolHandler : IToolHandler
 internal interface IVectorPathToolHandler : IToolHandler
 {
 {
-    
+    public PathFillType FillMode { get; }
 }
 }

+ 1 - 0
src/PixiEditor/ViewModels/Tools/ToolSettings/Toolbars/FillableShapeToolbar.cs

@@ -34,5 +34,6 @@ internal class FillableShapeToolbar : ShapeToolbar, IFillableShapeToolbar
     {
     {
         AddSetting(new BoolSettingViewModel(nameof(Fill), "FILL_SHAPE_LABEL") { Value = true });
         AddSetting(new BoolSettingViewModel(nameof(Fill), "FILL_SHAPE_LABEL") { Value = true });
         AddSetting(new ColorSettingViewModel(nameof(FillColor), "FILL_COLOR_LABEL"));
         AddSetting(new ColorSettingViewModel(nameof(FillColor), "FILL_COLOR_LABEL"));
+        GetSetting<SizeSettingViewModel>(nameof(ToolSize)).Value = 0;
     }
     }
 }
 }

+ 8 - 0
src/PixiEditor/ViewModels/Tools/Tools/VectorPathToolViewModel.cs

@@ -1,4 +1,5 @@
 using Avalonia.Input;
 using Avalonia.Input;
+using Drawie.Backend.Core.Vector;
 using Drawie.Numerics;
 using Drawie.Numerics;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 using PixiEditor.Extensions.Common.Localization;
 using PixiEditor.Extensions.Common.Localization;
@@ -30,8 +31,15 @@ internal class VectorPathToolViewModel : ShapeTool, IVectorPathToolHandler
     private LocalizedString actionDisplayCtrl;
     private LocalizedString actionDisplayCtrl;
     private LocalizedString actionDisplayAlt;
     private LocalizedString actionDisplayAlt;
 
 
+    [Settings.Enum("FILL_MODE", PathFillType.Winding)]
+    public PathFillType FillMode
+    {
+        get => GetValue<PathFillType>();
+    }
+
     public VectorPathToolViewModel()
     public VectorPathToolViewModel()
     {
     {
+        Toolbar = ToolbarFactory.Create<VectorPathToolViewModel, FillableShapeToolbar>(this);
         var fillSetting = Toolbar.GetSetting(nameof(FillableShapeToolbar.Fill));
         var fillSetting = Toolbar.GetSetting(nameof(FillableShapeToolbar.Fill));
         if (fillSetting != null)
         if (fillSetting != null)
         {
         {