supertux
screen_manager.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // 2014 Ingo Ruhnke <grumbel@gmail.com>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HEADER_SUPERTUX_SUPERTUX_SCREEN_MANAGER_HPP
19 #define HEADER_SUPERTUX_SUPERTUX_SCREEN_MANAGER_HPP
20 
21 #include <memory>
22 
23 #include "squirrel/squirrel_thread_queue.hpp"
24 #include "supertux/screen.hpp"
25 #include "util/currenton.hpp"
26 
27 class Compositor;
28 class ControllerHUD;
29 class DrawingContext;
30 class InputManager;
31 class MenuManager;
32 class MenuStorage;
33 class ScreenFade;
34 class VideoSystem;
35 
39 class ScreenManager final : public Currenton<ScreenManager>
40 {
41 public:
42  ScreenManager(VideoSystem& video_system, InputManager& input_manager);
43  ~ScreenManager();
44 
45  void run();
46  void quit(std::unique_ptr<ScreenFade> fade = {});
47  void set_speed(float speed);
48  void set_target_framerate(float framerate);
49  float get_target_framerate() const;
50  float get_speed() const;
51  bool has_pending_fadeout() const;
52 
53  // push new screen on screen_stack
54  void push_screen(std::unique_ptr<Screen> screen, std::unique_ptr<ScreenFade> fade = {});
55  void pop_screen(std::unique_ptr<ScreenFade> fade = {});
56  void set_screen_fade(std::unique_ptr<ScreenFade> fade);
57 
58 private:
59  struct FPS_Stats;
60  void draw_fps(DrawingContext& context, FPS_Stats& fps_statistics);
61  void draw_player_pos(DrawingContext& context);
62  void draw(Compositor& compositor, FPS_Stats& fps_statistics);
63  void update_gamelogic(float dt_sec);
64  void process_events();
65  void handle_screen_switch();
66 
67 private:
68  VideoSystem& m_video_system;
69  InputManager& m_input_manager;
70  std::unique_ptr<MenuStorage> m_menu_storage;
71  std::unique_ptr<MenuManager> m_menu_manager;
72  std::unique_ptr<ControllerHUD> m_controller_hud;
73 
74  float m_speed;
75  float m_target_framerate;
76 
77  struct Action
78  {
79  enum Type { PUSH_ACTION, POP_ACTION, QUIT_ACTION };
80  Type type;
81  std::unique_ptr<Screen> screen;
82 
83  Action(Type type_,
84  std::unique_ptr<Screen> screen_ = {}) :
85  type(type_),
86  screen(std::move(screen_))
87  {}
88  };
89 
90  std::vector<Action> m_actions;
91 
92  std::unique_ptr<ScreenFade> m_screen_fade;
93  std::vector<std::unique_ptr<Screen> > m_screen_stack;
94 };
95 
96 #endif
97 
98 /* EOF */
Definition: menu_storage.hpp:28
Manages, updates and draws all Screens, Controllers, Menus and the Console.
Definition: screen_manager.hpp:39
Definition: screen_manager.cpp:130
Definition: input_manager.hpp:38
Definition: menu_manager.hpp:30
A &#39;Currenton&#39; allows access to the currently active instance of a class via the static current() func...
Definition: currenton.hpp:30
Definition: compositor.hpp:29
Definition: video_system.hpp:36
Definition: controller_hud.hpp:27
Definition: tree.hpp:53
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
Screen to be displayed simultaneously with another Screen.
Definition: screen_fade.hpp:27