diff options
Diffstat (limited to 'src/animator.hh')
| -rw-r--r-- | src/animator.hh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/animator.hh b/src/animator.hh new file mode 100644 index 0000000..c8072ac --- /dev/null +++ b/src/animator.hh @@ -0,0 +1,60 @@ +#ifndef ANIMATOR_HH +#define ANIMATOR_HH + +#include <memory> + +class Animation; +class Looper; + +class Animator { +public: + class Observer { + public: + virtual ~Observer() {} + + // Called after all active animations callbacks has been called. + // Not called if there are no active animations. + virtual void tick(Animator* animator) = 0; + + protected: + Observer() {} + }; + + class AnimationObserver { + public: + virtual ~AnimationObserver() {} + + // Called after the animation has been updated with the new value + virtual void ticked(Animator* animator, Animation* animation, + double value) = 0; + // Called after the animation stopped, either because stop() was called + // or because animation->tick() return false. + // If animation->tick() returned false ticked method above is always called + // first + virtual void stopped(Animator* animator, Animation* animation) = 0; + + protected: + AnimationObserver() {} + }; + + virtual ~Animator() {} + + static Animator* create(std::shared_ptr<Looper> const& looper); + + virtual void start(std::shared_ptr<Animation> const& animation, + AnimationObserver* observer) = 0; + virtual bool observe(Animation* animation, AnimationObserver* observer) = 0; + virtual bool stop(Animation* animation) = 0; + virtual bool active(Animation* animation) const = 0; + virtual bool active() const = 0; + + virtual void add_observer(Observer* observer) = 0; + virtual void remove_observer(Observer* observer) = 0; + +protected: + Animator() {} + Animator(Animator const&) = delete; + Animator& operator=(Animator const&) = delete; +}; + +#endif // ANIMATOR_HH |
