summaryrefslogtreecommitdiff
path: root/src/animator.hh
blob: c8072ac60ac53d9a108093e74684d01fd37f6999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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