KeyFrame.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using Avalonia.Collections;
  4. namespace Avalonia.Animation
  5. {
  6. internal enum KeyFrameTimingMode
  7. {
  8. TimeSpan = 1,
  9. Cue
  10. }
  11. /// <summary>
  12. /// Stores data regarding a specific key
  13. /// point and value in an animation.
  14. /// </summary>
  15. public class KeyFrame : AvaloniaList<IAnimationSetter>
  16. {
  17. private TimeSpan _ktimeSpan;
  18. private Cue _kCue;
  19. public KeyFrame()
  20. {
  21. }
  22. public KeyFrame(IEnumerable<IAnimationSetter> items) : base(items)
  23. {
  24. }
  25. public KeyFrame(params IAnimationSetter[] items) : base(items)
  26. {
  27. }
  28. internal KeyFrameTimingMode TimingMode { get; private set; }
  29. /// <summary>
  30. /// Gets or sets the key time of this <see cref="KeyFrame"/>.
  31. /// </summary>
  32. /// <value>The key time.</value>
  33. public TimeSpan KeyTime
  34. {
  35. get
  36. {
  37. return _ktimeSpan;
  38. }
  39. set
  40. {
  41. if (TimingMode == KeyFrameTimingMode.Cue)
  42. {
  43. throw new InvalidOperationException($"You can only set either {nameof(KeyTime)} or {nameof(Cue)}.");
  44. }
  45. TimingMode = KeyFrameTimingMode.TimeSpan;
  46. _ktimeSpan = value;
  47. }
  48. }
  49. /// <summary>
  50. /// Gets or sets the cue of this <see cref="KeyFrame"/>.
  51. /// </summary>
  52. /// <value>The cue.</value>
  53. public Cue Cue
  54. {
  55. get
  56. {
  57. return _kCue;
  58. }
  59. set
  60. {
  61. if (TimingMode == KeyFrameTimingMode.TimeSpan)
  62. {
  63. throw new InvalidOperationException($"You can only set either {nameof(KeyTime)} or {nameof(Cue)}.");
  64. }
  65. TimingMode = KeyFrameTimingMode.Cue;
  66. _kCue = value;
  67. }
  68. }
  69. }
  70. }