Matrix3X3BaseNode.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Drawie.Backend.Core.Numerics;
  2. using Drawie.Backend.Core.Surfaces;
  3. using Drawie.Backend.Core.Surfaces.PaintImpl;
  4. using Drawie.Numerics;
  5. using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
  6. using PixiEditor.ChangeableDocument.Rendering;
  7. namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Matrix;
  8. public abstract class Matrix3X3BaseNode : RenderNode, IRenderInput
  9. {
  10. public RenderInputProperty Background { get; }
  11. public InputProperty<Matrix3X3> Input { get; }
  12. public OutputProperty<Matrix3X3> Matrix { get; }
  13. private Paint? paint;
  14. public Matrix3X3BaseNode()
  15. {
  16. Background = CreateRenderInput("Background", "IMAGE");
  17. Input = CreateInput("Input", "INPUT_MATRIX", Matrix3X3.Identity);
  18. Matrix = CreateOutput("Matrix", "OUTPUT_MATRIX", Matrix3X3.Identity);
  19. Output.FirstInChain = null;
  20. AllowHighDpiRendering = true;
  21. }
  22. protected override void OnExecute(RenderContext context)
  23. {
  24. Matrix.Value = CalculateMatrix(Input.Value);
  25. if (Background.Value == null)
  26. return;
  27. paint ??= new();
  28. base.OnExecute(context);
  29. }
  30. protected override void OnPaint(RenderContext context, DrawingSurface surface)
  31. {
  32. if (paint == null)
  33. return;
  34. int layer = surface.Canvas.Save();
  35. surface.Canvas.SetMatrix(surface.Canvas.TotalMatrix.Concat(Matrix.Value));
  36. Background.Value?.Paint(context, surface);
  37. surface.Canvas.RestoreToCount(layer);
  38. }
  39. protected abstract Matrix3X3 CalculateMatrix(Matrix3X3 input);
  40. }