|
@@ -1,45 +1,60 @@
|
|
-using PixiEditor.ChangeableDocument.Helpers;
|
|
|
|
|
|
+using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
|
|
|
|
+using PixiEditor.ChangeableDocument.Helpers;
|
|
using PixiEditor.ChangeableDocument.Rendering;
|
|
using PixiEditor.ChangeableDocument.Rendering;
|
|
using PixiEditor.DrawingApi.Core;
|
|
using PixiEditor.DrawingApi.Core;
|
|
|
|
+using PixiEditor.DrawingApi.Core.Surfaces;
|
|
using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
|
|
using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
|
|
|
|
+using PixiEditor.Numerics;
|
|
|
|
|
|
namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.FilterNodes;
|
|
namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.FilterNodes;
|
|
|
|
|
|
[NodeInfo("ApplyFilter")]
|
|
[NodeInfo("ApplyFilter")]
|
|
-public class ApplyFilterNode : Node
|
|
|
|
|
|
+public class ApplyFilterNode : RenderNode, IRenderInput
|
|
{
|
|
{
|
|
private Paint _paint = new();
|
|
private Paint _paint = new();
|
|
-
|
|
|
|
-
|
|
|
|
- public OutputProperty<Texture?> Output { get; }
|
|
|
|
-
|
|
|
|
- public InputProperty<Texture?> Input { get; }
|
|
|
|
-
|
|
|
|
public InputProperty<Filter?> Filter { get; }
|
|
public InputProperty<Filter?> Filter { get; }
|
|
-
|
|
|
|
- private Texture _workingSurface;
|
|
|
|
|
|
+
|
|
|
|
+ public RenderInputProperty Background { get; }
|
|
|
|
|
|
public ApplyFilterNode()
|
|
public ApplyFilterNode()
|
|
{
|
|
{
|
|
- Output = CreateOutput<Texture>(nameof(Output), "IMAGE", null);
|
|
|
|
- Input = CreateInput<Texture>(nameof(Input), "IMAGE", null);
|
|
|
|
- Filter = CreateInput<Filter>(nameof(Filter), "FILTER", null);
|
|
|
|
|
|
+ Background = CreateRenderInput("Input", "IMAGE");
|
|
|
|
+ Filter = CreateInput<Filter>("Filter", "FILTER", null);
|
|
}
|
|
}
|
|
-
|
|
|
|
- protected override void OnExecute(RenderContext context)
|
|
|
|
|
|
+
|
|
|
|
+ protected override void OnPaint(RenderContext context, DrawingSurface surface)
|
|
{
|
|
{
|
|
- if (Input.Value is not { } input)
|
|
|
|
|
|
+ _paint.SetFilters(Filter.Value);
|
|
|
|
+ var layer = surface.Canvas.SaveLayer(_paint);
|
|
|
|
+
|
|
|
|
+ Background.Value.Paint(context, surface);
|
|
|
|
+
|
|
|
|
+ surface.Canvas.RestoreToCount(layer);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public override RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
|
|
|
|
+ {
|
|
|
|
+ if (Background.Connection != null && Background.Connection.Node is IPreviewRenderable previousPreview)
|
|
{
|
|
{
|
|
- return;
|
|
|
|
|
|
+ return previousPreview.GetPreviewBounds(frame, elementToRenderName);
|
|
}
|
|
}
|
|
|
|
|
|
- _paint.SetFilters(Filter.Value);
|
|
|
|
-
|
|
|
|
- _workingSurface = RequestTexture(0, input.Size, true);
|
|
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public override bool RenderPreview(DrawingSurface renderOn, ChunkResolution resolution, int frame,
|
|
|
|
+ string elementToRenderName)
|
|
|
|
+ {
|
|
|
|
+ if(Background.Value == null)
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ using RenderContext context = new(renderOn, frame, ChunkResolution.Full, VecI.One);
|
|
|
|
|
|
- _workingSurface.DrawingSurface.Canvas.DrawSurface(input.DrawingSurface, 0, 0, _paint);
|
|
|
|
|
|
+ int layer = renderOn.Canvas.SaveLayer(_paint);
|
|
|
|
+ Background.Value.Paint(context, renderOn);
|
|
|
|
+ renderOn.Canvas.RestoreToCount(layer);
|
|
|
|
|
|
- Output.Value = _workingSurface;
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
public override Node CreateCopy() => new ApplyFilterNode();
|
|
public override Node CreateCopy() => new ApplyFilterNode();
|