You.i Engine
YiAnimation.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_ANIMATION_H_
3 #define _YI_ANIMATION_H_
4 
5 #include "framework/YiPredef.h"
6 #include "utility/YiTime.h"
7 
8 #include <limits>
9 
10 class CYIAnimationPriv;
12 
32 {
33 public:
34  enum class RepeatMode : uint8_t
35  {
36  Restart = 0,
37  Reverse
38  };
39 
40  enum class Status : uint8_t
41  {
42  NotStarted = 0,
43  Running,
44  Paused,
45  Ended
46  };
47 
48  enum class Direction : uint8_t
49  {
50  Forward = 0,
51  Reverse,
52  };
53 
61  class Listener
62  {
63  public:
64  virtual ~Listener(){};
65 
69  virtual void OnAnimate(CYIAnimation *pAnim, float dataPosition);
70 
76  virtual void OnAnimationBegin(CYIAnimation *pAnimation);
77 
83  virtual void OnAnimationEnd(CYIAnimation *pAnimation);
84  };
85 
86  static const uint64_t ANIMATION_TIME_UNDEFINED;
87  static const uint64_t ANIMATION_REPEAT_COUNT_INFINITE;
88 
89  CYIAnimation();
90  virtual ~CYIAnimation();
91 
95  void ChangeDirection();
96 
101  Direction GetDirection() const;
102 
106  uint64_t GetDuration() const;
107 
111  uint64_t GetLastDeltaTime() const;
112 
116  CYIAnimation *GetNext() const;
117 
121  CYIAnimation *GetPrevious() const;
122 
127  void *GetUserData() const;
128 
133  Status GetStatus() const;
134 
139 
143  void InsertInList(CYIAnimation **ppFirstAnimation);
144 
150  void RemoveFromList(CYIAnimation **ppFirstAnimation);
151 
156  void Pause();
157 
162  void Reset();
163 
168  void AddListener(CYIAnimation::Listener *pListener);
169 
173  void RemoveListener(CYIAnimation::Listener *pListener);
174 
184  void ScaleDuration(uint64_t newSimpleDur);
185 
190  void SetDirection(Direction direction);
191 
197  void SetDuration(uint64_t dur);
198 
211  void SetRepeatCount(uint64_t repeatCount);
212 
220  void SetRepeatMode(RepeatMode repeatMode);
221 
228  void SetStartTime(uint64_t startTime);
229 
236  void SetTimeInterpolator(CYITimeInterpolator *pTimeInterpolator);
237 
241  void SetNext(CYIAnimation *pAnimation);
242 
246  void SetPrevious(CYIAnimation *pAnimation);
247 
254  void SetUserData(void *pPrivData);
255 
262  void Start();
263 
274  void Terminate();
275 
276 private:
277  // tells the animation that a number of milliseconds have elapsed
278  virtual bool OnFrameTimeUpdated(std::chrono::microseconds frameTime) override;
279 
280  CYIAnimation(const CYIAnimation &);
281  const CYIAnimation &operator=(const CYIAnimation &);
282 
283 private:
284  std::unique_ptr<CYIAnimationPriv> m_pPriv;
285 };
286 
289 inline void CYIAnimation::Listener::OnAnimate(CYIAnimation * /*pAnimation*/, float /*dataPosition*/) {}
291 inline void CYIAnimation::Listener::OnAnimationEnd(CYIAnimation * /*pAnimation*/) {}
292 
293 #endif // _YI_ANIMATION_H_
virtual ~Listener()
Definition: YiAnimation.h:64
uint64_t GetLastDeltaTime() const
void SetDuration(uint64_t dur)
static const uint64_t ANIMATION_TIME_UNDEFINED
Definition: YiAnimation.h:86
void ChangeDirection()
void InsertInList(CYIAnimation **ppFirstAnimation)
static const uint64_t ANIMATION_REPEAT_COUNT_INFINITE
Definition: YiAnimation.h:87
Container for basic interpolator functions.
Definition: YiTimeInterpolator.h:20
virtual ~CYIAnimation()
virtual void OnAnimate(CYIAnimation *pAnim, float dataPosition)
Definition: YiAnimation.h:289
The data position restarts from 0.0 and increases. (modulo the effects of the time interpolator) ...
void SetDirection(Direction direction)
void RemoveListener(CYIAnimation::Listener *pListener)
uint64_t GetDuration() const
virtual void OnAnimationBegin(CYIAnimation *pAnimation)
Definition: YiAnimation.h:290
CYIAnimation * GetNext() const
Direction
Definition: YiAnimation.h:48
void SetRepeatMode(RepeatMode repeatMode)
CYIAnimation * GetPrevious() const
void SetStartTime(uint64_t startTime)
Definition: YiTime.h:28
void SetNext(CYIAnimation *pAnimation)
Status GetStatus() const
RepeatMode
Definition: YiAnimation.h:34
void SetUserData(void *pPrivData)
Status
Definition: YiAnimation.h:40
void AddListener(CYIAnimation::Listener *pListener)
void * GetUserData() const
void ScaleDuration(uint64_t newSimpleDur)
The animation inverses its progression direction from the previous cycle.
void Terminate()
Used to create animations programatically.
Definition: YiAnimation.h:31
void SetPrevious(CYIAnimation *pAnimation)
CYITimeInterpolator * GetTimeInterpolator() const
void SetTimeInterpolator(CYITimeInterpolator *pTimeInterpolator)
Direction GetDirection() const
Base class used to listen to one or more CYIAnimations as they update over time.
Definition: YiAnimation.h:61
void SetRepeatCount(uint64_t repeatCount)
virtual void OnAnimationEnd(CYIAnimation *pAnimation)
Definition: YiAnimation.h:291
void RemoveFromList(CYIAnimation **ppFirstAnimation)