1
// SuperTuxKart - a fun racing game with go-kart
2
// Copyright (C) 2009 Marianne Gagnon
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.
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.
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.
19
#ifndef HEADER_ENGINE_HPP
20
#define HEADER_ENGINE_HPP
30
#include "utils/constants.hpp"
31
#include "utils/ptr_vector.hpp"
42
* \brief Contains all GUI engine related classes and functions
44
* See \ref gui_overview for more information.
51
class AbstractStateManager;
53
/** \brief Returns the widget currently focused by given player, or NULL if none.
54
* \note Do NOT use irrLicht's GUI focus facilities; it's too limited for our
55
* needs, so we use ours. (i.e. always call these functions are never those
58
Widget* getFocusForPlayer(const int playerID);
60
/** \brief Focuses nothing for given player (removes any selection for this player).
61
* \note Do NOT use irrLicht's GUI focus facilities; it's too limited for our
62
* needs, so we use ours. (i.e. always call these functions are never those
65
void focusNothingForPlayer(const int playerID);
67
/** \brief Returns whether given the widget is currently focused by given player.
68
* \note Do NOT use irrLicht's GUI focus facilities; it's too limited for our
69
* needs, so we use ours. (i.e. always call these functions are never those
72
bool isFocusedForPlayer(const Widget*w, const int playerID);
75
* In an attempt to make getters as fast as possible, by possibly still allowing inlining
76
* These fields should never be accessed outside of the GUI engine.
80
extern irr::gui::IGUIEnvironment* g_env;
82
extern irr::gui::ScalableFont* g_small_font;
83
extern irr::gui::ScalableFont* g_font;
84
extern irr::gui::ScalableFont* g_title_font;
86
extern irr::IrrlichtDevice* g_device;
87
extern irr::video::IVideoDriver* g_driver;
88
extern Screen* g_current_screen;
89
extern AbstractStateManager* g_state_manager;
90
extern Widget* g_focus_for_player[MAX_PLAYER_COUNT];
93
/** Widgets that need to be notified at every frame can add themselves there (FIXME: unclean) */
94
extern ptr_vector<Widget, REF> needsUpdate;
97
* \brief Call this method to init the GUI engine.
98
* \precondition A irrlicht device and its corresponding video drivers must have been created
99
* \param device An initialized irrlicht device object
100
* \param driver An initialized irrlicht driver object
101
* \param state_manager An instance of a class derived from abstract base AbstractStateManager
103
void init(irr::IrrlichtDevice* device, irr::video::IVideoDriver* driver, AbstractStateManager* state_manager);
106
* \brief frees all resources allocated by GUIEngine::init and subsequent uses of the GUI engine.
112
* \return the irrlicht device object
114
inline irr::IrrlichtDevice* getDevice() { return Private::g_device; }
117
* \return the irrlicht GUI environment object
119
inline irr::gui::IGUIEnvironment* getGUIEnv() { return Private::g_env; }
122
* \return the irrlicht video driver object
124
inline irr::video::IVideoDriver* getDriver() { return Private::g_driver; }
127
* \return the smaller font (useful for less important messages)
129
inline irr::gui::ScalableFont* getSmallFont() { return Private::g_small_font; }
132
* \return the "normal" font (useful for text)
134
inline irr::gui::ScalableFont* getFont() { return Private::g_font; }
137
* \return the "title" font (it's bigger and orange, useful for headers/captions)
139
inline irr::gui::ScalableFont* getTitleFont() { return Private::g_title_font; }
142
* \return the currently shown screen, or NULL if none
144
inline Screen* getCurrentScreen() { return Private::g_current_screen; }
147
* \return the state manager being used, as passed to GUIEngine::init
149
inline AbstractStateManager* getStateManager() { return Private::g_state_manager; }
152
* \precondition GUIEngine::init must have been called first
153
* \return the skin object used to render widgets
155
inline Skin* getSkin() { return Private::g_skin; }
157
Screen* getScreenNamed(const char* name);
159
/** \return the height of the title font in pixels */
160
int getTitleFontHeight();
162
/** \return the height of the font in pixels */
165
/** \return the height of the small font in pixels */
166
int getSmallFontHeight();
169
* \precondition the value returned by this function is only valid when invoked from GUIEngine::render
170
* \return the time delta between the last two frames
175
* \brief shows a message at the bottom of the screen for a while
176
* \param message the message to display
177
* \param time the time to display the message, in seconds
179
void showMessage(const wchar_t* message, const float time=5.0f);
181
/** \brief Add a screen to the list of screens known by the gui engine */
182
void addScreenToList(Screen* screen);
184
/** \brief Low-level mean to change current screen.
185
* \note Do not use directly. Use a state manager instead to get higher-level functionnality.
187
void switchToScreen(const char* );
189
/** \brief erases the currently displayed screen, removing all added irrLicht widgets
190
* \note Do not use directly. Use a state manager instead to get higher-level functionnality.
194
/** \brief like GUIEngine::clear, but to be called before going into game */
197
/** \brief to be called after e.g. a resolution switch */
198
void reshowCurrentScreen();
201
* \brief called on every frame to trigger the rendering of the GUI
203
void render(float dt);
205
/** \brief renders a "loading" screen */
206
void renderLoading(bool clearIcons = true);
208
/** \brief to spice up a bit the loading icon : add icons to the loading screen */
209
void addLoadingIcon(irr::video::ITexture* icon);
211
//void transmitEvent(Widget* widget, std::string& name, const int playerID);
213
/** \brief Finds a widget from its name (PROP_ID) in the current screen/dialog
214
* \param name the name (PROP_ID) of the widget to search for
215
* \return the widget that bears that name, or NULL if it was not found
217
Widget* getWidget(const char* name);
219
/** \brief Finds a widget from its irrlicht widget ID in the current screen/dialog
220
* \param name the irrlicht widget ID (not to be confused with PROP_ID, which is a string)
221
* of the widget to search for
222
* \return the widget that bears that irrlicht ID, or NULL if it was not found
224
Widget* getWidget(const int id);
227
* \brief call when skin in user config was updated