Browse Source

Added DocumentInfo, Transform Node and rect to structure

Krzysztof Krysiński 5 months ago
parent
commit
097d28e38c

+ 28 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/DocumentInfoNode.cs

@@ -0,0 +1,28 @@
+using Drawie.Numerics;
+using PixiEditor.ChangeableDocument.Rendering;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
+
+[NodeInfo("DocumentInfo")]
+public class DocumentInfoNode : Node
+{
+    public OutputProperty<VecI> Size { get; }
+    public OutputProperty<VecD> Center { get; }
+
+    public DocumentInfoNode()
+    {
+        Size = CreateOutput("Size", "SIZE", new VecI(0, 0));
+        Center = CreateOutput("Center", "CENTER", new VecD(0, 0));
+    }
+
+    protected override void OnExecute(RenderContext context)
+    {
+        Size.Value = context.DocumentSize;
+        Center.Value = new VecD(context.DocumentSize.X / 2.0, context.DocumentSize.Y / 2.0);
+    }
+
+    public override Node CreateCopy()
+    {
+        return new DocumentInfoNode();
+    }
+}

+ 46 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Matrix/TransformNode.cs

@@ -1,6 +1,50 @@
-namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Matrix;
+using Drawie.Backend.Core.Numerics;
+using Drawie.Backend.Core.Surfaces;
+using Drawie.Numerics;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
+using PixiEditor.ChangeableDocument.Rendering;
 
-public class TransformNode
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Matrix;
+
+[NodeInfo("Transform")]
+public class TransformNode : RenderNode, IRenderInput
 {
+    public RenderInputProperty Background { get; }
+    public InputProperty<Matrix3X3> Matrix { get; }
+
+    public TransformNode()
+    {
+        Background = CreateRenderInput("Background", "IMAGE");
+        Matrix = CreateInput("Matrix", "INPUT", Matrix3X3.Identity);
+
+        Output.FirstInChain = null;
+    }
+
+    protected override void OnPaint(RenderContext context, DrawingSurface surface)
+    {
+        if (Background.Value == null)
+            return;
+
+        int layer = surface.Canvas.Save();
+
+        surface.Canvas.SetMatrix(surface.Canvas.TotalMatrix.PostConcat(Matrix.Value));
+        Background.Value?.Paint(context, surface);
+
+        surface.Canvas.RestoreToCount(layer);
+    }
+
+    public override RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
+    {
+        return null;
+    }
+
+    public override bool RenderPreview(DrawingSurface renderOn, RenderContext context, string elementToRenderName)
+    {
+        return false;
+    }
 
+    public override Node CreateCopy()
+    {
+        return new TransformNode();
+    }
 }

+ 21 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/StructureNode.cs

@@ -39,6 +39,9 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
     public RenderOutputProperty FilterlessOutput { get; }
     public RenderOutputProperty RawOutput { get; }
 
+    public OutputProperty<VecD> TightSize { get; }
+    public OutputProperty<VecD> CenterPosition { get; }
+
     public ChunkyImage? EmbeddedMask { get; set; }
 
     protected Texture renderedMask;
@@ -94,9 +97,27 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
 
         RawOutput = CreateRenderOutput(RawOutputPropertyName, "RAW_LAYER_OUTPUT", () => rawPainter);
 
+        CenterPosition = CreateOutput<VecD>("CenterPosition", "CENTER_POSITION", VecD.Zero);
+        TightSize = CreateOutput<VecD>("Size", "SIZE", VecD.Zero);
+
         MemberName = DefaultMemberName;
     }
 
+    protected override void OnExecute(RenderContext context)
+    {
+        base.OnExecute(context);
+
+        if (TightSize.Connections.Count > 0)
+        {
+            TightSize.Value = GetSceneSize(context.FrameTime);
+        }
+
+        if (CenterPosition.Connections.Count > 0)
+        {
+            CenterPosition.Value = GetScenePosition(context.FrameTime);
+        }
+    }
+
     protected override void OnPaint(RenderContext context, DrawingSurface renderTarget)
     {
         if (Output.Connections.Count > 0)

+ 7 - 0
src/PixiEditor/ViewModels/Document/Nodes/DocumentInfoNodeViewModel.cs

@@ -0,0 +1,7 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
+using PixiEditor.ViewModels.Nodes;
+
+namespace PixiEditor.ViewModels.Document.Nodes;
+
+[NodeViewModel("DOCUMENT_INFO_NODE", "", "")]
+internal class DocumentInfoNodeViewModel : NodeViewModel<DocumentInfoNode>;

+ 7 - 0
src/PixiEditor/ViewModels/Document/Nodes/Matrix/TransformNodeViewModel.cs

@@ -0,0 +1,7 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Matrix;
+using PixiEditor.ViewModels.Nodes;
+
+namespace PixiEditor.ViewModels.Document.Nodes.Matrix;
+
+[NodeViewModel("TRANSFORM_NODE", "MATRIX", "")]
+internal class TransformNodeViewModel : NodeViewModel<TransformNode>;