ModifyImageLeftNode.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
  2. using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
  3. using PixiEditor.ChangeableDocument.Rendering;
  4. using Drawie.Backend.Core;
  5. using Drawie.Backend.Core.ColorsImpl;
  6. using Drawie.Backend.Core.Shaders.Generation.Expressions;
  7. using Drawie.Backend.Core.Surfaces;
  8. using Drawie.Numerics;
  9. namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
  10. [NodeInfo("ModifyImageLeft")]
  11. [PairNode(typeof(ModifyImageRightNode), "ModifyImageZone", true)]
  12. public class ModifyImageLeftNode : Node, IPairNode, IPreviewRenderable
  13. {
  14. public InputProperty<Texture?> Image { get; }
  15. public FuncOutputProperty<Float2> Coordinate { get; }
  16. public FuncOutputProperty<Half4> Color { get; }
  17. public Guid OtherNode { get; set; }
  18. public ModifyImageLeftNode()
  19. {
  20. Image = CreateInput<Texture?>("Surface", "IMAGE", null);
  21. Coordinate = CreateFuncOutput("Coordinate", "UV", ctx => ctx.OriginalPosition);
  22. Color = CreateFuncOutput("Color", "COLOR", GetColor);
  23. }
  24. private Half4 GetColor(FuncContext context)
  25. {
  26. context.ThrowOnMissingContext();
  27. if(Image.Value == null)
  28. {
  29. return new Half4("") { ConstantValue = Colors.Transparent };
  30. }
  31. return context.SampleSurface(Image.Value.DrawingSurface, context.SamplePosition);
  32. }
  33. protected override void OnExecute(RenderContext context)
  34. {
  35. }
  36. public override Node CreateCopy() => new ModifyImageLeftNode();
  37. public RectD? GetPreviewBounds(int frame, string elementToRenderName = "")
  38. {
  39. if(Image.Value == null)
  40. {
  41. return null;
  42. }
  43. return new RectD(0, 0, Image.Value.Size.X, Image.Value.Size.Y);
  44. }
  45. public bool RenderPreview(DrawingSurface renderOn, RenderContext context, string elementToRenderName)
  46. {
  47. if(Image.Value is null)
  48. {
  49. return false;
  50. }
  51. renderOn.Canvas.DrawSurface(Image.Value.DrawingSurface, 0, 0);
  52. return true;
  53. }
  54. }