SuperTuxKart
Loading...
Searching...
No Matches
engine.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_ENGINE_HPP
20#define HEADER_ENGINE_HPP
21
30namespace irr
31{
32 class IrrlichtDevice;
33 namespace gui { class IGUIEnvironment; class ScalableFont; }
34 namespace video { class IVideoDriver; class ITexture; }
35}
36
37#include <functional>
38#include <string>
39
40#include "utils/constants.hpp"
41#include "utils/ptr_vector.hpp"
42
43#include "irrString.h"
44
51namespace GUIEngine
52{
53 class Screen;
54 class Widget;
55 class Skin;
56 class AbstractStateManager;
57
63 Widget* getFocusForPlayer(const unsigned int playerID);
64
70 void focusNothingForPlayer(const unsigned int playerID);
71
77 bool isFocusedForPlayer(const Widget*w, const unsigned int playerID);
78
83 namespace Private
84 {
85 extern irr::gui::IGUIEnvironment* g_env;
86 extern Skin* g_skin;
87 extern irr::gui::ScalableFont* g_small_font;
88 extern irr::gui::ScalableFont* g_font;
89 extern irr::gui::ScalableFont* g_outline_font;
90 extern irr::gui::ScalableFont* g_large_font;
91 extern irr::gui::ScalableFont* g_title_font;
92 extern irr::gui::ScalableFont* g_small_title_font;
93 extern irr::gui::ScalableFont* g_tiny_title_font;
94 extern irr::gui::ScalableFont* g_digit_font;
95
96 extern irr::IrrlichtDevice* g_device;
97 extern irr::video::IVideoDriver* g_driver;
98 extern Screen* g_current_screen;
99 extern AbstractStateManager* g_state_manager;
100 extern Widget* g_focus_for_player[MAX_PLAYER_COUNT];
101 }
102
105
114 void init(irr::IrrlichtDevice* device, irr::video::IVideoDriver* driver,
115 AbstractStateManager* state_manager, bool loading = true);
116
117 void cleanUp();
118
119 void deallocate();
120
121 void resetGlobalVariables();
122
126 inline irr::IrrlichtDevice* getDevice() { return Private::g_device; }
127
131 inline irr::gui::IGUIEnvironment* getGUIEnv() { return Private::g_env; }
132
136 inline irr::video::IVideoDriver* getDriver() { return Private::g_driver; }
137
141 inline irr::gui::ScalableFont* getSmallFont() { return Private::g_small_font; }
142
146 inline irr::gui::ScalableFont* getFont() { return Private::g_font; }
147
148 inline irr::gui::ScalableFont* getOutlineFont() { return Private::g_outline_font; }
149
153 inline irr::gui::ScalableFont* getLargeFont() { return Private::g_large_font; }
154
158 inline irr::gui::ScalableFont* getHighresDigitFont() { return Private::g_digit_font; }
159
163 inline irr::gui::ScalableFont* getTitleFont() { return Private::g_title_font; }
164
168 inline irr::gui::ScalableFont* getSmallTitleFont() { return Private::g_small_title_font; }
169
173 inline irr::gui::ScalableFont* getTinyTitleFont() { return Private::g_tiny_title_font; }
174
178 inline Screen* getCurrentScreen() { return Private::g_current_screen; }
179
183 inline AbstractStateManager* getStateManager() { return Private::g_state_manager; }
184
185 void clearScreenCache();
186
191 inline Skin* getSkin() { return Private::g_skin; }
192
193 inline void setSkin(Skin* skin) { Private::g_skin = skin; }
194 Screen* getScreenNamed(const char* name);
195
197 int getTitleFontHeight();
198
200 int getFontHeight();
201
203 int getSmallFontHeight();
204
209 float getLatestDt();
210
216 void showMessage(const irr::core::stringw& message, const float time=5.0f);
217
219 void addScreenToList(Screen* screen);
221 void removeScreen(Screen* screen);
222
226 void switchToScreen(Screen* screen);
227
231 void clear();
232
233 void update(float dt);
234
236 void cleanForGame();
237
239 void reshowCurrentScreen();
240
244 void render(float dt, bool is_loading = false);
245
246 void clearLoadingTips();
247
249 void renderLoading(bool clearIcons = true, bool launching = false, bool update_tips = true);
250
252 void flushRenderLoading(bool launching);
253
255 void addLoadingIcon(irr::video::ITexture* icon);
256
261 Widget* getWidget(const char* name);
262
268 Widget* getWidget(const int id);
269
273 void reloadSkin();
274
278 void reloadForNewSize();
279
283 void addGUIFunctionBeforeRendering(std::function<void()> func);
284
285#ifdef SERVER_ONLY
286 inline void disableGraphics() {}
287 constexpr bool isNoGraphics() { return true; }
288#else
289 void disableGraphics();
290 bool isNoGraphics();
291#endif
292}
293
294#endif
Abstract base class you must override from to use the GUI engine.
Definition: abstract_state_manager.hpp:54
Represents a single GUI screen.
Definition: screen.hpp:97
Object used to render the GUI widgets see Overview of GUI skin for more information about skinning in...
Definition: skin.hpp:269
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:143
Definition: ptr_vector.hpp:44
Definition: scalable_font.hpp:35
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33
irr::IrrlichtDevice * getDevice()
Definition: engine.hpp:126
irr::gui::ScalableFont * getTitleFont()
Definition: engine.hpp:163
int getFontHeight()
Definition: engine.cpp:838
void renderLoading(bool clearIcons, bool launching, bool update_tips)
renders a "loading" screen
Definition: engine.cpp:1445
irr::gui::ScalableFont * getSmallFont()
Definition: engine.hpp:141
void reloadSkin()
call when skin in user config was updated
Definition: engine.cpp:1199
irr::gui::ScalableFont * getLargeFont()
Definition: engine.hpp:153
Widget * getWidget(const char *name)
Finds a widget from its name (PROP_ID) in the current screen/dialog.
Definition: engine.cpp:1596
void addLoadingIcon(irr::video::ITexture *icon)
to spice up a bit the loading icon : add icons to the loading screen
Definition: engine.cpp:1575
irr::gui::IGUIEnvironment * getGUIEnv()
Definition: engine.hpp:131
int getSmallFontHeight()
Definition: engine.cpp:844
irr::gui::ScalableFont * getTinyTitleFont()
Definition: engine.hpp:173
irr::gui::ScalableFont * getSmallTitleFont()
Definition: engine.hpp:168
void cleanUp()
Clean some of the cached data, either for a shutdown or a reload.
Definition: engine.cpp:1000
void update(float dt)
Updates all widgets that need to be updated.
Definition: engine.cpp:872
irr::gui::ScalableFont * getHighresDigitFont()
Definition: engine.hpp:158
void clear()
erases the currently displayed screen, removing all added irrLicht widgets
Definition: engine.cpp:857
Skin * getSkin()
Definition: engine.hpp:191
int getTitleFontHeight()
Definition: engine.cpp:821
void reloadForNewSize()
call when screen size changed
Definition: engine.cpp:1229
float getLatestDt()
Definition: engine.cpp:755
void switchToScreen(Screen *screen)
Low-level mean to change current screen.
Definition: engine.cpp:925
void render(float elapsed_time, bool is_loading)
called on every frame to trigger the rendering of the GUI.
Definition: engine.cpp:1259
irr::gui::ScalableFont * getFont()
Definition: engine.hpp:146
PtrVector< Widget, REF > needsUpdate
Widgets that need to be notified at every frame can add themselves there (FIXME: unclean)
Definition: engine.cpp:748
void addGUIFunctionBeforeRendering(std::function< void()> func)
Add gui-related function before rendering GUI (from other thread)
Definition: engine.cpp:1245
void deallocate()
To be called after cleanup().
Definition: engine.cpp:1075
Screen * getCurrentScreen()
Definition: engine.hpp:178
void cleanForGame()
like GUIEngine::clear, but to be called before going into game
Definition: engine.cpp:901
AbstractStateManager * getStateManager()
Definition: engine.hpp:183
void focusNothingForPlayer(const unsigned int playerID)
Focuses nothing for given player (removes any selection for this player).
Definition: engine.cpp:799
void removeScreen(Screen *screen)
Remove a screen from the list of screens known by the gui engine.
Definition: engine.cpp:969
bool isFocusedForPlayer(const Widget *w, const unsigned int playerID)
Returns whether given the widget is currently focused by given player.
Definition: engine.cpp:808
void flushRenderLoading(bool launching)
poll events during rendering to prevent unresponsive window
Definition: engine.cpp:1542
void addScreenToList(Screen *cutscene)
Add a screen to the list of screens known by the gui engine.
Definition: engine.cpp:962
irr::video::IVideoDriver * getDriver()
Definition: engine.hpp:136
Widget * getFocusForPlayer(const unsigned int playerID)
Returns the widget currently focused by given player, or NULL if none.
Definition: engine.cpp:791
void reshowCurrentScreen()
to be called after e.g.
Definition: engine.cpp:988