Browse Source

Renamed the Sample and Create Nodes to Modify Image

CPKreuz 1 year ago
parent
commit
e6dea50b8a

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

@@ -0,0 +1,28 @@
+using PixiEditor.ChangeableDocument.Changeables.Animations;
+using PixiEditor.Numerics;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
+
+public class EmptyImageNode : Node
+{
+    public OutputProperty<ChunkyImage> Output { get; }
+
+    public InputProperty<VecI> Size { get; }
+
+    public EmptyImageNode()
+    {
+        Output = CreateOutput<ChunkyImage>(nameof(Output), "EMPTY_IMAGE", null);
+        Size = CreateInput(nameof(Size), "SIZE", new VecI(32, 32));
+    }
+    
+    protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
+    {
+        Output.Value = new ChunkyImage(Size.Value);
+
+        return Output.Value;
+    }
+
+    public override bool Validate() => Size.Value is { X: > 0, Y: > 0 };
+
+    public override Node CreateCopy() => new EmptyImageNode();
+}

+ 5 - 5
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/SampleImageNode.cs → src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ModifyImageLeftNode.cs

@@ -5,18 +5,18 @@ using PixiEditor.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
-public class SampleImageNode : Node
+public class ModifyImageLeftNode : Node
 {
     public InputProperty<ChunkyImage?> Image { get; }
     
-    public FieldInputProperty<VecD> Coordinate { get; }
+    public FieldOutputProperty<VecD> Coordinate { get; }
     
     public FieldOutputProperty<Color> Color { get; }
     
-    public SampleImageNode()
+    public ModifyImageLeftNode()
     {
         Image = CreateInput<ChunkyImage>(nameof(Image), "IMAGE", null);
-        Coordinate = CreateFieldInput(nameof(Coordinate), "COORDINATE", ctx => ctx.Position);
+        Coordinate = CreateFieldOutput(nameof(Coordinate), "COORDINATE", ctx => ctx.Position);
         Color = CreateFieldOutput(nameof(Color), "COLOR", GetColor);
     }
 
@@ -41,5 +41,5 @@ public class SampleImageNode : Node
 
     public override bool Validate() => Image.Value != null;
 
-    public override Node CreateCopy() => new SampleImageNode();
+    public override Node CreateCopy() => new ModifyImageLeftNode();
 }

+ 14 - 9
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/CreateImageNode.cs → src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ModifyImageRightNode.cs

@@ -6,28 +6,33 @@ using PixiEditor.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
-public class CreateImageNode : Node
+public class ModifyImageRightNode : Node
 {
-    public InputProperty<VecI> Size { get; }
+    public InputProperty<ChunkyImage?> _InternalImage { get; }
     
     public FieldInputProperty<Color> Color { get; }
     
     public OutputProperty<ChunkyImage> Output { get; }
     
-    
-    public CreateImageNode() 
+    public ModifyImageRightNode() 
     {
-        Size = CreateInput(nameof(Size), "SIZE", new VecI(32, 32));
+        _InternalImage = CreateInput<ChunkyImage>(nameof(_InternalImage), "_InternalImage", null);
         Color = CreateFieldInput(nameof(Color), "COLOR", _ => new Color(0, 0, 0, 255));
         Output = CreateOutput<ChunkyImage>(nameof(Output), "OUTPUT", null);
     }
 
     protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
     {
-        var width = Size.Value.X;
-        var height = Size.Value.Y;
+        if (_InternalImage.Value == null)
+        {
+            return null;
+        }
+        
+        var size = _InternalImage.Value.CommittedSize;
+        var width = size.X;
+        var height = size.Y;
 
-        Output.Value = new ChunkyImage(Size.Value);
+        Output.Value = new ChunkyImage(size);
 
         for (int y = 0; y < width; y++)
         {
@@ -47,7 +52,7 @@ public class CreateImageNode : Node
 
     public override bool Validate() => true;
 
-    public override Node CreateCopy() => new CreateImageNode();
+    public override Node CreateCopy() => new ModifyImageRightNode();
 
     record CreateImageContext(VecD Position, VecI Size) : IFieldContext
     {