OutputNode.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using PixiEditor.ChangeableDocument.Changeables.Animations;
  2. using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
  3. using PixiEditor.ChangeableDocument.Rendering;
  4. using Drawie.Backend.Core;
  5. using Drawie.Backend.Core.Surfaces;
  6. using Drawie.Numerics;
  7. namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
  8. [NodeInfo("Output")]
  9. public class OutputNode : Node, IRenderInput, IPreviewRenderable
  10. {
  11. public const string UniqueName = "PixiEditor.Output";
  12. public const string InputPropertyName = "Background";
  13. public RenderInputProperty Input { get; }
  14. private VecI? lastDocumentSize;
  15. public OutputNode()
  16. {
  17. Input = new RenderInputProperty(this, InputPropertyName, "BACKGROUND", null);
  18. AddInputProperty(Input);
  19. }
  20. public override Node CreateCopy()
  21. {
  22. return new OutputNode();
  23. }
  24. protected override void OnExecute(RenderContext context)
  25. {
  26. if (!string.IsNullOrEmpty(context.TargetOutput)) return;
  27. lastDocumentSize = context.DocumentSize;
  28. int saved = context.RenderSurface.Canvas.Save();
  29. context.RenderSurface.Canvas.ClipRect(new RectD(0, 0, context.DocumentSize.X, context.DocumentSize.Y));
  30. Input.Value?.Paint(context, context.RenderSurface);
  31. context.RenderSurface.Canvas.RestoreToCount(saved);
  32. }
  33. RenderInputProperty IRenderInput.Background => Input;
  34. public RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
  35. {
  36. if (lastDocumentSize == null)
  37. {
  38. return null;
  39. }
  40. return new RectD(0, 0, lastDocumentSize.Value.X, lastDocumentSize.Value.Y);
  41. }
  42. public bool RenderPreview(DrawingSurface renderOn, RenderContext context, string elementToRenderName)
  43. {
  44. if (Input.Value == null)
  45. {
  46. return false;
  47. }
  48. int saved = renderOn.Canvas.Save();
  49. Input.Value.Paint(context, renderOn);
  50. renderOn.Canvas.RestoreToCount(saved);
  51. return true;
  52. }
  53. }