EffectTemplate.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. namespace Terminal.Gui.TextEffects;
  2. public class EffectConfig
  3. {
  4. public Color ColorSingle { get; set; }
  5. public List<Color> ColorList { get; set; }
  6. public Color FinalColor { get; set; }
  7. public List<Color> FinalGradientStops { get; set; }
  8. public List<int> FinalGradientSteps { get; set; }
  9. public int FinalGradientFrames { get; set; }
  10. public float MovementSpeed { get; set; }
  11. public EasingFunction Easing { get; set; }
  12. }
  13. public class NamedEffectIterator : BaseEffectIterator<EffectConfig>
  14. {
  15. public NamedEffectIterator (NamedEffect effect) : base (effect)
  16. {
  17. Build ();
  18. }
  19. private void Build ()
  20. {
  21. var finalGradient = new Gradient (Config.FinalGradientStops, Config.FinalGradientSteps);
  22. foreach (var character in Terminal.GetCharacters ())
  23. {
  24. CharacterFinalColorMap [character] = finalGradient.GetColorAtFraction (
  25. character.InputCoord.Row / (float)Terminal.Canvas.Top
  26. );
  27. }
  28. }
  29. public override string Next ()
  30. {
  31. if (PendingChars.Any () || ActiveCharacters.Any ())
  32. {
  33. Update ();
  34. return Frame;
  35. }
  36. else
  37. {
  38. throw new InvalidOperationException ("No more elements in effect iterator.");
  39. }
  40. }
  41. private List<EffectCharacter> PendingChars = new List<EffectCharacter> ();
  42. private Dictionary<EffectCharacter, Color> CharacterFinalColorMap = new Dictionary<EffectCharacter, Color> ();
  43. }
  44. public class NamedEffect : BaseEffect<EffectConfig>
  45. {
  46. public NamedEffect (string inputData) : base (inputData)
  47. {
  48. }
  49. protected override Type ConfigCls => typeof (EffectConfig);
  50. protected override Type IteratorCls => typeof (NamedEffectIterator);
  51. }