Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_animation.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_ANIMATION_H
7 #define TB_ANIMATION_H
8 
9 #include "tb_linklist.h"
10 #include "tb_object.h"
11 
12 namespace tb {
13 
14 class TBAnimationObject;
15 
23 };
24 
27 
30 
45 };
46 
47 #define ANIMATION_DEFAULT_CURVE ANIMATION_CURVE_SLOW_DOWN
48 #define ANIMATION_DEFAULT_DURATION 200
49 
52 class TBAnimationListener : public TBLinkOf<TBAnimationListener>
53 {
54 public:
55  virtual ~TBAnimationListener() {};
56 
59  virtual void OnAnimationStart(TBAnimationObject *obj) = 0;
60 
63  virtual void OnAnimationUpdate(TBAnimationObject *obj, float progress) = 0;
64 
67  virtual void OnAnimationStop(TBAnimationObject *obj, bool aborted) = 0;
68 };
69 
72 class TBAnimationObject : public TBTypedObject, public TBLinkOf<TBAnimationObject>
73 {
74 public:
75  ANIMATION_CURVE animation_curve;
76  double animation_start_time;
77  double animation_duration;
78  bool adjust_start_time;
79 public:
80  // For safe typecasting
81  TBOBJECT_SUBCLASS(TBAnimationObject, TBTypedObject);
82 
83  virtual ~TBAnimationObject() {}
84 
86  bool IsAnimating() const { return linklist ? true : false; }
87 
89  virtual void OnAnimationStart() = 0;
90 
94  virtual void OnAnimationUpdate(float progress) = 0;
95 
99  virtual void OnAnimationStop(bool aborted) = 0;
100 
102  void AddListener(TBAnimationListener *listener) { m_listeners.AddLast(listener); }
103 
105  void RemoveListener(TBAnimationListener *listener) { m_listeners.Remove(listener); }
106 private:
107  friend class TBAnimationManager;
109  void InvokeOnAnimationStart();
110  void InvokeOnAnimationUpdate(float progress);
111  void InvokeOnAnimationStop(bool aborted);
112 };
113 
117 {
118 private:
119  static TBLinkListOf<TBAnimationObject> animating_objects;
120 public:
122  static void Update();
123 
125  static bool HasAnimationsRunning();
126 
127  static void StartAnimation(TBAnimationObject *obj,
128  ANIMATION_CURVE animation_curve = ANIMATION_DEFAULT_CURVE,
129  double animation_duration = ANIMATION_DEFAULT_DURATION,
135  static void AbortAnimation(TBAnimationObject *obj, bool delete_animation);
136 
138  static void AbortAllAnimations();
139 
141  static bool IsAnimationsBlocked();
142 
146  static void BeginBlockAnimations();
147 
149  static void EndBlockAnimations();
150 };
151 
156 {
157 public:
160 };
161 
162 } // namespace tb
163 
164 #endif // TB_ANIMATION_H
ANIMATION_TIME
Defines what the animation duration time is relative to.
Definition: tb_animation.h:26
static void BeginBlockAnimations()
Begin a period of blocking new animations.
Definition: tb_animation.cpp:171
Slow start, slow end. Almost linear.
Definition: tb_animation.h:21
TBAnimationManager - System class that manages all animated object.
Definition: tb_animation.h:116
static void Update()
Update all running animations.
Definition: tb_animation.cpp:71
static void EndBlockAnimations()
End a period of blocking new animations that was started with BeginBlockAnimations.
Definition: tb_animation.cpp:177
bool IsAnimating() const
Return true if the object is currently animating.
Definition: tb_animation.h:86
Fast start, slow end.
Definition: tb_animation.h:19
The animation start in StartAnimation just as with ANIMATION_TIME_IMMEDIATELY, but the start time is ...
Definition: tb_animation.h:44
TBAnimationBlocker blocks new animations during its lifetime.
Definition: tb_animation.h:155
TBAnimationListener - Listens to the progress of TBAnimationObject.
Definition: tb_animation.h:52
virtual void OnAnimationStop(TBAnimationObject *obj, bool aborted)=0
Called after the animation object handled its own OnAnimationStart.
The start time begins when the animation start in TBAnimationManager::StartAnimation.
Definition: tb_animation.h:29
virtual void OnAnimationUpdate(float progress)=0
Called on animation update.
Slow start, slow end. Stronger than ANIMATION_CURVE_BEZIER.
Definition: tb_animation.h:22
Definition: tb_object.h:21
static void AbortAllAnimations()
Abort and delete all animations.
Definition: tb_animation.cpp:64
Slow start, fast end.
Definition: tb_animation.h:20
static bool IsAnimationsBlocked()
Return true if new animations are blocked.
Definition: tb_animation.cpp:165
static void AbortAnimation(TBAnimationObject *obj, bool delete_animation)
Abort the animation.
Definition: tb_animation.cpp:153
ANIMATION_CURVE
Defines how the animation progress value is interpolated.
Definition: tb_animation.h:17
virtual void OnAnimationUpdate(TBAnimationObject *obj, float progress)=0
Called after the animation object handled its own OnAnimationStart.
void RemoveListener(TBAnimationListener *listener)
Remove a listener from this animation object.
Definition: tb_animation.h:105
void AddListener(TBAnimationListener *listener)
Add a listener to this animation object.
Definition: tb_animation.h:102
TBAnimationObject - Base class for all animated object.
Definition: tb_animation.h:72
virtual void OnAnimationStop(bool aborted)=0
Called on animation stop.
virtual void OnAnimationStart(TBAnimationObject *obj)=0
Called after the animation object handled its own OnAnimationStart.
static bool HasAnimationsRunning()
Return true if there are running animations.
Definition: tb_animation.cpp:129
Linear.
Definition: tb_animation.h:18
virtual void OnAnimationStart()=0
Called on animation start.