UILinearAnimation.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. namespace Microsoft.Windows.Forms.Animate
  2. {
  3. /// <summary>
  4. /// 线性动画
  5. /// </summary>
  6. public sealed class UILinearAnimation : Animation<float>
  7. {
  8. /// <summary>
  9. /// 默认动画执行时间
  10. /// </summary>
  11. public const int DEFAULT_ANIMATION_SPAN = 200;
  12. private float m_From;
  13. /// <summary>
  14. /// 获取或设置起点
  15. /// </summary>
  16. public float From
  17. {
  18. get { return this.m_From; }
  19. set { this.m_From = value; }
  20. }
  21. private float m_To;
  22. /// <summary>
  23. /// 获取或设置终点
  24. /// </summary>
  25. public float To
  26. {
  27. get { return this.m_To; }
  28. set { this.m_To = value; }
  29. }
  30. private float m_Current;
  31. /// <summary>
  32. /// 获取动画当前帧
  33. /// </summary>
  34. public override float Current
  35. {
  36. get
  37. {
  38. if (this.m_From >= this.m_To)
  39. {
  40. this.Stop();
  41. return this.m_Current = this.m_To;
  42. }
  43. double percentage = this.Percentage;
  44. return this.m_Current = (percentage == STOPPED ? this.m_To : (float)(this.m_From + (this.m_To - this.m_From) * percentage));
  45. }
  46. }
  47. /// <summary>
  48. /// 构造函数
  49. /// </summary>
  50. public UILinearAnimation()
  51. {
  52. base.Span = DEFAULT_ANIMATION_SPAN;
  53. }
  54. /// <summary>
  55. /// 继续动画
  56. /// </summary>
  57. /// <param name="to">终点</param>
  58. public void Continue(float to)
  59. {
  60. this.m_From = this.m_Current;
  61. this.m_To = to;
  62. this.Start();
  63. }
  64. /// <summary>
  65. /// 重新开始动画
  66. /// </summary>
  67. public void Next()
  68. {
  69. base.Start();
  70. }
  71. /// <summary>
  72. /// 停止动画
  73. /// </summary>
  74. public new void Stop()
  75. {
  76. base.Stop();
  77. }
  78. /// <summary>
  79. /// 释放资源
  80. /// </summary>
  81. /// <param name="disposing">释放托管资源为 true,否则为 false</param>
  82. protected override void Dispose(bool disposing)
  83. {
  84. }
  85. }
  86. }