SuperTuxKart
screen.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2010-2015 Marianne Gagnon
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (at your option) any later version.
8 //
9 // This program 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
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 
19 #ifndef HEADER_SCREEN_HPP
20 #define HEADER_SCREEN_HPP
21 
22 #include <map>
23 #include <string>
24 #include <typeinfo>
25 #include "utils/cpp2011.hpp"
26 
27 #include <irrString.h>
28 #include <IXMLReader.h>
29 
30 namespace irr
31 {
32  namespace gui { class IGUIElement; }
33 }
34 using namespace irr;
35 
36 #include "config/stk_config.hpp"
37 #include "guiengine/abstract_top_level_container.hpp"
38 #include "guiengine/engine.hpp"
39 #include "guiengine/event_handler.hpp"
40 #include "guiengine/widget.hpp"
41 #include "input/input.hpp"
42 #include "utils/ptr_vector.hpp"
43 
44 #include "utils/leak_check.hpp"
45 
49 namespace GUIEngine
50 {
56  template<typename SCREEN>
58  {
59  protected:
60  static SCREEN* singleton;
61 
62  public:
63 
65  {
66  singleton = NULL;
67  }
68 
69  static SCREEN* getInstance()
70  {
71  if (singleton == NULL)
72  {
73  singleton = new SCREEN();
74  GUIEngine::addScreenToList(singleton);
75  }
76 
77  return singleton;
78  }
79 
80  };
81  template <typename SCREEN> SCREEN*
83 
95  {
96  private:
101 
102  friend class Skin;
103 
104  bool m_loaded;
105 
106  std::string m_filename;
107 
112 
114  unsigned int m_magic_number;
115 
120 
121  protected:
122  bool m_throttle_FPS;
123 
124  public:
125 
126  LEAK_CHECK()
127 
128 
136  static void parseScreenFileDiv(irr::io::IXMLReader* xml,
137  PtrVector<Widget>& append_to,
138  irr::gui::IGUIElement* parent = NULL);
139 
140 
141  Screen(bool pause_race=true);
142 
143  Screen(const char* filename, bool pause_race=true);
144 
145  virtual ~Screen();
146 
147  bool operator ==(const char* filename) const { return m_filename == filename; }
148 
149  void loadFromFile();
150 
152  bool isLoaded() const { return m_loaded; }
153 
154  bool throttleFPS() const { return m_throttle_FPS; }
155 
156  void addWidgets();
157 
158  void calculateLayout();
159 
160  void manualAddWidget(Widget* w);
161 
162  void manualRemoveWidget(Widget* w);
163 
167  void setUpdateInBackground(bool value) {m_update_in_background = value;}
168  bool getUpdateInBackground() {return m_update_in_background;}
169 
171  const std::string& getName() const { return m_filename; }
172 
173  virtual void unload();
174 
178  bool needs3D() { return m_render_3d; }
179 
190  void setNeeds3D(bool needs3D) { m_render_3d = needs3D; }
191 
207  virtual void loadedFromFile() = 0;
208 
219  virtual void unloaded() {}
220 
226  virtual void beforeAddingWidget() {}
227 
237  virtual void init();
238 
241  void push();
242 
251  virtual void tearDown();
252 
258  virtual bool onEscapePressed() { return true; }
259 
270  virtual void eventCallback(Widget* widget, const std::string& name, const int playerID) = 0;
271 
275  virtual void onUpdate(float dt) { };
276 
280  virtual void onDraw(float dt) { };
281 
285  virtual MusicInformation* getMusic() const { return stk_config->m_title_music; }
286 
290  virtual MusicInformation* getInGameMenuMusic() const { return NULL; }
291 
292  virtual int getWidth();
293 
294  virtual int getHeight();
295 
300  virtual EventPropagation filterActions(PlayerAction action,
301  int deviceID,
302  const unsigned int value,
303  Input::InputType type,
304  int playerId)
305  { return EVENT_LET; }
306 
311  virtual void onDisabledItemClicked(const std::string& item) {}
312 
317  virtual void filterInput(Input::InputType type,
318  int deviceID,
319  int btnID,
320  int axisDir,
321  int value) {}
322 
326  virtual void onDialogClose() {}
327 
329  virtual void onFocusChanged(Widget* previous, Widget* focus, int playerID) {}
330  };
331 
332  class CutsceneScreen : public Screen
333  {
334  public:
335  CutsceneScreen(const char* name) : Screen(name, false)
336  {
337  setNeeds3D(true);
338  m_throttle_FPS = false;
339  }
340 
341  virtual void onCutsceneEnd() = 0;
342  };
343 }
344 
345 #endif
Wrapper around an instance of the Music interface Adds information like composer, song title,...
Definition: music_information.hpp:42
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:31
void addScreenToList(Screen *cutscene)
Add a screen to the list of screens known by the gui engine.
Definition: engine.cpp:936
PlayerAction
types of input events / what actions the players can do
Definition: input.hpp:116
virtual EventPropagation filterActions(PlayerAction action, int deviceID, const unsigned int value, Input::InputType type, int playerId)
Override this if you need to be notified of player actions in subclasses.
Definition: screen.hpp:300
Represents a GUI widgets container.
Definition: abstract_top_level_container.hpp:42
virtual void onDisabledItemClicked(const std::string &item)
Callback you can use if you want to know when the user pressed on a disabled ribbon item.
Definition: screen.hpp:311
void setUpdateInBackground(bool value)
When set to true it updates the screen even if modal dialog is opened.
Definition: screen.hpp:167
bool m_update_in_background
When set to true it updates the screen even if modal dialog is opened.
Definition: screen.hpp:119
virtual void onFocusChanged(Widget *previous, Widget *focus, int playerID)
Callback called when focus changes.
Definition: screen.hpp:329
bool isLoaded() const
Definition: screen.hpp:152
virtual void onUpdate(float dt)
optional callback you can override to be notified at every frame.
Definition: screen.hpp:275
virtual bool onEscapePressed()
Called when escape is pressed.
Definition: screen.hpp:258
bool m_pause_race
True if the race (if it is running) should be paused when this screen is shown.
Definition: screen.hpp:100
virtual void onDialogClose()
Callback that gets called when a dialog is closed.
Definition: screen.hpp:326
const std::string & getName() const
Definition: screen.hpp:171
virtual void beforeAddingWidget()
Optional callback invoked very early, before widgets have been added (contrast with init(),...
Definition: screen.hpp:226
virtual MusicInformation * getMusic() const
Definition: screen.hpp:285
Definition: screen.hpp:332
Object used to render the GUI widgets see Overview of GUI skin for more information about skinning in...
Definition: skin.hpp:265
bool needs3D()
Will be called to determine if the 3D scene must be rendered when at this screen.
Definition: screen.hpp:178
virtual void unloaded()
Callback invoked when this screen is being unloaded.
Definition: screen.hpp:219
Definition: ptr_vector.hpp:43
Represents a single GUI screen.
Definition: screen.hpp:94
Declares a class to be a singleton.
Definition: screen.hpp:57
virtual void onDraw(float dt)
optional callback you can override to be notified at every frame.
Definition: screen.hpp:280
virtual MusicInformation * getInGameMenuMusic() const
Definition: screen.hpp:290
virtual void filterInput(Input::InputType type, int deviceID, int btnID, int axisDir, int value)
Override this if you need to be notified of raw input in subclasses.
Definition: screen.hpp:317
void setNeeds3D(bool needs3D)
Invoke this method for screens that use a 3D scene as background.
Definition: screen.hpp:190
unsigned int m_magic_number
to catch errors as early as possible, for debugging purposes only
Definition: screen.hpp:114
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:138
bool m_render_3d
Will be called to determine if the 3D scene must be rendered when at this screen.
Definition: screen.hpp:111
MusicInformation * m_title_music
Filename of the title music to play.
Definition: stk_config.hpp:165