ModifyImageLeftNode.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using PixiEditor.ChangeableDocument.Changeables.Animations;
  2. using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
  3. using PixiEditor.DrawingApi.Core.ColorsImpl;
  4. using PixiEditor.Numerics;
  5. namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
  6. public class ModifyImageLeftNode : Node
  7. {
  8. public InputProperty<ChunkyImage?> Image { get; }
  9. public FieldOutputProperty<VecD> Coordinate { get; }
  10. public FieldOutputProperty<Color> Color { get; }
  11. public ModifyImageLeftNode()
  12. {
  13. Image = CreateInput<ChunkyImage>(nameof(Image), "IMAGE", null);
  14. Coordinate = CreateFieldOutput(nameof(Coordinate), "COORDINATE", ctx => ctx.Position);
  15. Color = CreateFieldOutput(nameof(Color), "COLOR", GetColor);
  16. }
  17. private Color GetColor(FieldContext context)
  18. {
  19. if (Image.Value is not { } image)
  20. {
  21. return new Color();
  22. }
  23. var pos = new VecI(
  24. (int)(context.Position.X * context.Size.X),
  25. (int)(context.Position.Y * context.Size.Y));
  26. return image.GetCommittedPixel(pos);
  27. }
  28. protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
  29. {
  30. return Image.Value;
  31. }
  32. public override bool Validate() => Image.Value != null;
  33. public override Node CreateCopy() => new ModifyImageLeftNode();
  34. }