|
@@ -5,11 +5,12 @@ using Drawie.Backend.Core.ColorsImpl;
|
|
|
using Drawie.Backend.Core.Surfaces;
|
|
|
using Drawie.Backend.Core.Surfaces.ImageData;
|
|
|
using Drawie.Numerics;
|
|
|
+using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
|
|
|
|
|
|
namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
|
|
|
|
|
|
[NodeInfo("CreateImage")]
|
|
|
-public class CreateImageNode : Node
|
|
|
+public class CreateImageNode : Node, IPreviewRenderable
|
|
|
{
|
|
|
public OutputProperty<Texture> Output { get; }
|
|
|
|
|
@@ -22,7 +23,7 @@ public class CreateImageNode : Node
|
|
|
public RenderOutputProperty RenderOutput { get; }
|
|
|
|
|
|
private TextureCache textureCache = new();
|
|
|
-
|
|
|
+
|
|
|
public CreateImageNode()
|
|
|
{
|
|
|
Output = CreateOutput<Texture>(nameof(Output), "IMAGE", null);
|
|
@@ -39,6 +40,15 @@ public class CreateImageNode : Node
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ var surface = Render(context);
|
|
|
+
|
|
|
+ Output.Value = surface;
|
|
|
+
|
|
|
+ RenderOutput.ChainToPainterValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Texture Render(RenderContext context)
|
|
|
+ {
|
|
|
var surface = textureCache.RequestTexture(0, Size.Value, context.ProcessingColorSpace, false);
|
|
|
|
|
|
surface.DrawingSurface.Canvas.Clear(Fill.Value);
|
|
@@ -51,10 +61,7 @@ public class CreateImageNode : Node
|
|
|
Content.Value?.Paint(ctx, surface.DrawingSurface);
|
|
|
|
|
|
surface.DrawingSurface.Canvas.RestoreToCount(saved);
|
|
|
-
|
|
|
- Output.Value = surface;
|
|
|
-
|
|
|
- RenderOutput.ChainToPainterValue();
|
|
|
+ return surface;
|
|
|
}
|
|
|
|
|
|
private void OnPaint(RenderContext context, DrawingSurface surface)
|
|
@@ -69,4 +76,33 @@ public class CreateImageNode : Node
|
|
|
base.Dispose();
|
|
|
textureCache.Dispose();
|
|
|
}
|
|
|
+
|
|
|
+ public RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
|
|
|
+ {
|
|
|
+ if (Size.Value.X <= 0 || Size.Value.Y <= 0)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return new RectD(0, 0, Size.Value.X, Size.Value.Y);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool RenderPreview(DrawingSurface renderOn, RenderContext context, string elementToRenderName)
|
|
|
+ {
|
|
|
+ if (Size.Value.X <= 0 || Size.Value.Y <= 0)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Output.Value == null)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var surface = Render(context);
|
|
|
+
|
|
|
+ renderOn.Canvas.DrawSurface(surface.DrawingSurface, 0, 0);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|