aboutsummaryrefslogtreecommitdiff
path: root/src/SceneChanger.h
blob: fee3b486fb62a3630efe437c4961344e5ba67fbb (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef SceneChanger_h
#define SceneChanger_h

#include "GameScene.h"

class QParallelAnimationGroup;
class QTimer;
class GameView;

/**
  * Animates the change from a scene to another. Start the change
  * with SceneChanger::changeScene(). After the animation is done,
  * SceneChanger calls MainView::showScene for the scene that is
  * to be shown.
  *
  * Basically changeScene() just takes a "screenshot" of both the
  * scenes, adds the shots to itself and uses QPropertyAnimation
  * to do the animation.
  */
class SceneChanger : public GameScene
{
    Q_OBJECT
public:
    explicit SceneChanger(QString name, const QRectF &rect, GameView *parent = 0);

    /**
      * Start the scene change animation.
      *
      * @param from The scene we are changing from
      * @param to The scene we are changing to
      */
    void changeScene(GameScene *from, GameScene *to, bool rightToLeft);

    /**
      * Sets the duration of the animation in milliseconds. Default
      * duration is 250 milliseconds.
      */
    void setDuration(int msecs);

    void updateLogic();

private:

    /**
      * Center of all the animation.
      */
    QParallelAnimationGroup *m_anim;

    GameScene *m_fromScene;
    GameScene *m_toScene;

    /**
      * Time in ms how long it takes to animate from view to an other.
      */
    int m_duration;

    /**
      * Used for faster update on animating transition
      * than normal rendering needs.
      */
    QTimer *m_updateTimer;

signals:

private slots:
    /**
      * Called after m_anim has finished the animation. Calls
      * MainView::showScene() to show the new scene.
      */
    void animationFinished();

};

#endif // SceneChanger_h