Forráskód Böngészése

Added boolean operation node

Krzysztof Krysiński 5 hónapja
szülő
commit
9f131cb62f

+ 61 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/BoolOperationNode.cs

@@ -0,0 +1,61 @@
+using Drawie.Backend.Core.Vector;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
+using PixiEditor.ChangeableDocument.Rendering;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes;
+
+[NodeInfo("BoolOperation")]
+public class BoolOperationNode : Node
+{
+    public InputProperty<ShapeVectorData> ShapeA { get; }
+    public InputProperty<ShapeVectorData> ShapeB { get; }
+    public InputProperty<VectorPathOp> Operation { get; }
+    public OutputProperty<ShapeVectorData> Result { get; }
+
+    protected override bool ExecuteOnlyOnCacheChange => true;
+
+    public BoolOperationNode()
+    {
+        ShapeA = CreateInput<ShapeVectorData>("ShapeA", "FIRST_SHAPE", null);
+        ShapeB = CreateInput<ShapeVectorData>("ShapeB", "SECOND_SHAPE", null);
+        Operation = CreateInput<VectorPathOp>("Operation", "OPERATION", VectorPathOp.Union);
+        Result = CreateOutput<ShapeVectorData>("Result", "RESULT", null);
+    }
+
+    protected override void OnExecute(RenderContext context)
+    {
+        if (ShapeA.Value == null && ShapeB.Value == null)
+        {
+            Result.Value = null;
+            return;
+        }
+
+        if (ShapeA.Value == null)
+        {
+            Result.Value = ShapeB.Value;
+            return;
+        }
+
+        if (ShapeB.Value == null)
+        {
+            Result.Value = ShapeA.Value;
+            return;
+        }
+
+        ShapeVectorData shapeA = ShapeA.Value;
+        ShapeVectorData shapeB = ShapeB.Value;
+
+        Result.Value = new PathVectorData(shapeA.ToPath(true).Op(shapeB.ToPath(true), Operation.Value))
+        {
+            Fill = shapeA.Fill,
+            Stroke = shapeA.Stroke,
+            StrokeWidth = shapeA.StrokeWidth,
+            FillPaintable = shapeA.FillPaintable,
+        };
+    }
+
+    public override Node CreateCopy()
+    {
+        return new BoolOperationNode();
+    }
+}

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

@@ -55,7 +55,7 @@
   "APPLY_TRANSFORM": "Apply transform",
   "INCREASE_TOOL_SIZE": "Increase tool size",
   "DECREASE_TOOL_SIZE": "Decrease tool size",
- "UPDATE_READY": "Update is ready to be installed. Do you want to install it now?",
+  "UPDATE_READY": "Update is ready to be installed. Do you want to install it now?",
   "NEW_UPDATE": "New update",
   "COULD_NOT_UPDATE_WITHOUT_ADMIN": "Couldn't update without admin privileges. Please run PixiEditor as administrator.",
   "INSUFFICIENT_PERMISSIONS": "Insufficient permissions",
@@ -998,5 +998,14 @@
   "DOWNLOAD_UPDATE": "Download",
   "DOWNLOADING_UPDATE": "Downloading update...",
   "CHECKING_FOR_UPDATES": "Checking for updates...",
-  "PAINT_SHAPE_SETTING": "Brush shape"
+  "PAINT_SHAPE_SETTING": "Brush shape",
+  "BOOL_OPERATION_NODE": "Boolean Operation",
+  "FIRST_SHAPE": "First shape",
+  "SECOND_SHAPE": "Second shape",
+  "OPERATION": "Operation",
+  "UNION_VECTOR_PATH_OP": "Union",
+  "DIFFERENCE_VECTOR_PATH_OP": "Difference",
+  "INTERSECT_VECTOR_PATH_OP": "Intersect",
+  "XOR_VECTOR_PATH_OP": "XOR",
+  "REVERSE_DIFFERENCE_VECTOR_PATH_OP": "Reverse Difference"
 }

+ 11 - 0
src/PixiEditor/ViewModels/Document/Nodes/Shapes/BoolOperationNodeViewModel.cs

@@ -0,0 +1,11 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes;
+using PixiEditor.UI.Common.Fonts;
+using PixiEditor.ViewModels.Nodes;
+
+namespace PixiEditor.ViewModels.Document.Nodes.Shapes;
+
+[NodeViewModel("BOOL_OPERATION_NODE", "SHAPE", PixiPerfectIcons.Intersect)]
+internal class BoolOperationNodeViewModel : NodeViewModel<BoolOperationNode>
+{
+
+}