GBE.TimeLine.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. unit GBE.TimeLine;
  2. interface
  3. uses
  4. System.SysUtils,
  5. System.Classes,
  6. FMX.Types,
  7. FMX.Ani,
  8. System.Generics.Collections;
  9. type
  10. TGBEStep = record
  11. Duration, Delay: single;
  12. PropertyName: string;
  13. StartValue, StopValue: single;
  14. AutoReverse, Inverse, StartFromCurrent: boolean;
  15. Interpolation: TInterpolationType;
  16. AnimationType: TAnimationType;
  17. end;
  18. TGBETimeline = class(TFloatAnimation)
  19. private
  20. fListeAnimation: TList<TGBEStep>;
  21. fLoopSteps: boolean;
  22. function GetCount: integer;
  23. procedure RunAnimation(Indice: integer);
  24. procedure Finish(Sender: TObject);
  25. protected
  26. public
  27. constructor Create(AOwner: TComponent); override;
  28. destructor Destroy; override;
  29. procedure Clear;
  30. procedure AddStep(aStep: TGBEStep);
  31. procedure Run;
  32. published
  33. property count: integer read GetCount;
  34. property loopSteps: boolean read fLoopSteps write fLoopSteps;
  35. end;
  36. procedure Register;
  37. implementation // -------------------------------------------------------------
  38. // TGBETimeline
  39. procedure TGBETimeline.AddStep(aStep: TGBEStep);
  40. begin
  41. fListeAnimation.Add(aStep);
  42. end;
  43. procedure TGBETimeline.Clear;
  44. begin
  45. fListeAnimation.Clear;
  46. end;
  47. constructor TGBETimeline.Create(AOwner: TComponent);
  48. begin
  49. inherited;
  50. fListeAnimation := TList<TGBEStep>.Create;
  51. fLoopSteps := false;
  52. end;
  53. destructor TGBETimeline.Destroy;
  54. begin
  55. fListeAnimation.Free;
  56. inherited;
  57. end;
  58. function TGBETimeline.GetCount: integer;
  59. begin
  60. result := fListeAnimation.count;
  61. end;
  62. procedure TGBETimeline.Run;
  63. begin
  64. if fListeAnimation.count > 0 then
  65. RunAnimation(0);
  66. end;
  67. procedure TGBETimeline.RunAnimation(Indice: integer);
  68. begin
  69. if indice < fListeAnimation.count then
  70. begin
  71. self.Duration := fListeAnimation[indice].Duration;
  72. self.Delay := fListeAnimation[indice].Delay;
  73. self.PropertyName := fListeAnimation[indice].PropertyName;
  74. self.StartValue := fListeAnimation[indice].StartValue;
  75. self.StopValue := fListeAnimation[indice].StopValue;
  76. self.AutoReverse := fListeAnimation[indice].AutoReverse;
  77. self.Inverse := fListeAnimation[indice].Inverse;
  78. self.StartFromCurrent := fListeAnimation[indice].StartFromCurrent;
  79. self.Interpolation := fListeAnimation[indice].Interpolation;
  80. self.AnimationType := fListeAnimation[indice].AnimationType;
  81. self.Tag := Indice;
  82. self.OnFinish := Finish;
  83. self.Start;
  84. end
  85. else
  86. begin
  87. if fLoopSteps then
  88. RunAnimation(0);
  89. end;
  90. end;
  91. procedure TGBETimeline.Finish(Sender: TObject);
  92. begin
  93. RunAnimation((Sender as TFloatAnimation).Tag + 1);
  94. end;
  95. // ---------------------------------------------------------------------------
  96. procedure Register;
  97. begin
  98. RegisterComponents('GXScene GBE', [TGBETimeline]);
  99. end;
  100. end.