1 /*
2  * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org
3  *
4  * Solarus is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Solarus is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef SOLARUS_TRANSITION_H
18 #define SOLARUS_TRANSITION_H
19 
20 #include "solarus/core/Common.h"
21 #include "solarus/core/EnumInfo.h"
22 #include "solarus/core/Rectangle.h"
23 #include "solarus/graphics/ShaderPtr.h"
24 #include "solarus/graphics/Drawable.h"
25 
26 #include <map>
27 #include <string>
28 
29 namespace Solarus {
30 
31 class Game;
32 class Surface;
33 
34 /**
35  * \brief Abstract class for a transition effect between two phases.
36  *
37  * The transitions may be applied to maps or any surface.
38  */
39 class SOLARUS_API Transition : public DrawProxy {
40 
41   public:
42 
43     /**
44      * \brief Styles of transitions.
45      */
46     enum class Style {
47       IMMEDIATE = 0,  /**< No transition between the two surfaces. */
48       FADE      = 1,  /**< Fade-out and fade-in effect. */
49       SCROLLING = 2   /**< Scrolling between two maps. */
50     };
51 
52     /**
53      * \brief Possible directions of a transition.
54      */
55     enum class Direction {
56       OPENING  = 0,
57       CLOSING = 1
58     };
59 
60     virtual ~Transition();
61     static Transition* create(Style style,
62         Direction direction,
63         Game* game = nullptr);
64 
65     Game* get_game() const;
66     Direction get_direction() const;
67     void set_previous_surface(Surface* previous_surface);
68     virtual bool needs_previous_surface() const;
69 
70     bool is_suspended() const;
71     void set_suspended(bool suspended);
72 
73     /**
74      * \brief Starts this transition effect.
75      */
76     virtual void start() = 0;
77 
78     /**
79      * \brief Returns whether the transition effect is started.
80      * \return true if the transition effect is started
81      */
82     virtual bool is_started() const = 0;
83 
84     /**
85      * \brief Returns whether the transition effect is finished.
86      * \return true if the transition effect is finished
87      */
88     virtual bool is_finished() const = 0;
89 
90     /**
91      * \brief Updates this transition effect.
92      */
93     virtual void update() = 0;
94 
95     /**
96      * @brief edit target Drawable to reflect transition side effects
97      */
finish(Drawable & target)98     virtual void finish(Drawable& target) const {(void)target;}
99 
100     /**
101      * \brief Draws the transition effect on a surface.
102      * \param dst_surface the surface to draw
103      */
104     //virtual void draw(Surface& dst_surface, const Surface& src_surface, const Rectangle& region, const Point& destination) = 0;
105 
106   protected:
107 
108     explicit Transition(Direction direction);
109 
110     Surface* get_previous_surface() const;
111 
112     uint32_t get_when_suspended() const;
113 
114     /**
115      * \brief Notifies the transition effect that it was just suspended
116      * or resumed.
117      */
118     virtual void notify_suspended(bool suspended) = 0;
119 
120   private:
121 
122     Game* game;                   /**< The current game if any (required by some kinds of transitions). */
123     Direction direction;          /**< Direction of the transition (in or out). */
124     Surface* previous_surface;    /**< During an in transition, this is the surface that was displayed
125                                     * when the out transition was played. */
126     bool suspended;               /**< Indicates that the transition is currently paused. */
127     uint32_t when_suspended;      /**< Date when the transition was suspended. */
128 
129 };
130 
131 template <>
132 struct SOLARUS_API EnumInfoTraits<Transition::Style> {
133   static const std::string pretty_name;
134 
135   static const EnumInfo<Transition::Style>::names_type names;
136 };
137 
138 }
139 
140 #endif
141 
142