Browse Source

Added mask node

Krzysztof Krysiński 5 months ago
parent
commit
f098be91cf

+ 51 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Image/MaskNode.cs

@@ -0,0 +1,51 @@
+using Drawie.Backend.Core.Surfaces;
+using Drawie.Backend.Core.Surfaces.PaintImpl;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
+using PixiEditor.ChangeableDocument.Rendering;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Image;
+
+[NodeInfo("Mask")]
+public class MaskNode : RenderNode, IRenderInput
+{
+    public RenderInputProperty Background { get; }
+    public RenderInputProperty Mask { get; }
+
+    protected Paint maskPaint = new Paint()
+    {
+        BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.DstIn, ColorFilter = Nodes.Filters.MaskFilter
+    };
+
+    public MaskNode()
+    {
+        Background = CreateRenderInput("Background", "INPUT");
+        Mask = CreateRenderInput("Mask", "MASK");
+        AllowHighDpiRendering = true;
+        Output.FirstInChain = null;
+    }
+
+    protected override void OnPaint(RenderContext context, DrawingSurface surface)
+    {
+        if (Background.Value == null)
+        {
+            return;
+        }
+
+        Background.Value.Paint(context, surface);
+
+        if (Mask.Value == null)
+        {
+            return;
+        }
+
+        int layer = surface.Canvas.SaveLayer(maskPaint);
+        Mask.Value.Paint(context, surface);
+        surface.Canvas.RestoreToCount(layer);
+    }
+
+
+    public override Node CreateCopy()
+    {
+        return new MaskNode();
+    }
+}

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/TileNode.cs

@@ -19,7 +19,7 @@ public class TileNode : RenderNode
     public InputProperty<ShaderTileMode> TileModeY { get; }
     public InputProperty<ShaderTileMode> TileModeY { get; }
     public InputProperty<Matrix3X3> Matrix { get; }
     public InputProperty<Matrix3X3> Matrix { get; }
 
 
-    private Image lastImage;
+    private Drawie.Backend.Core.Surfaces.ImageData.Image lastImage;
     private Shader tileShader;
     private Shader tileShader;
     private Paint paint;
     private Paint paint;
 
 

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

@@ -888,5 +888,6 @@
   "TRANSFORM_NODE": "Transform",
   "TRANSFORM_NODE": "Transform",
   "UNIT": "Unit",
   "UNIT": "Unit",
   "ANGLE": "Angle",
   "ANGLE": "Angle",
-  "DOCUMENT_INFO_NODE": "Document Info"
+  "DOCUMENT_INFO_NODE": "Document Info",
+  "MASK_NODE": "Mask"
 }
 }

+ 8 - 0
src/PixiEditor/ViewModels/Document/Nodes/Image/MaskNodeViewModel.cs

@@ -0,0 +1,8 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Image;
+using PixiEditor.UI.Common.Fonts;
+using PixiEditor.ViewModels.Nodes;
+
+namespace PixiEditor.ViewModels.Document.Nodes.Image;
+
+[NodeViewModel("MASK_NODE", "IMAGE", PixiPerfectIcons.CreateMask)]
+internal class MaskNodeViewModel : NodeViewModel<MaskNode>;