~ubuntu-branches/ubuntu/precise/supertuxkart/precise

« back to all changes in this revision

Viewing changes to src/guiengine/engine.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2011-02-24 22:36:25 UTC
  • mfrom: (1.1.9 upstream) (6.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110224223625-ygrjfpg92obovuch
Tags: 0.7+dfsg1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  SuperTuxKart - a fun racing game with go-kart
 
2
//  Copyright (C) 2009 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
 
 
22
/**
 
23
 * \defgroup guiengine
 
24
 */
 
25
 
 
26
 
 
27
#include <irrlicht.h>
 
28
#include <string>
 
29
 
 
30
#include "utils/constants.hpp"
 
31
#include "utils/ptr_vector.hpp"
 
32
namespace irr
 
33
{
 
34
    namespace gui
 
35
    {
 
36
        class ScalableFont;
 
37
    }
 
38
}
 
39
 
 
40
/**
 
41
 * \ingroup guiengine
 
42
 * \brief Contains all GUI engine related classes and functions
 
43
 *
 
44
 * See \ref gui_overview for more information.
 
45
 */
 
46
namespace GUIEngine
 
47
{    
 
48
    class Screen;
 
49
    class Widget;
 
50
    class Skin;
 
51
    class AbstractStateManager;
 
52
    
 
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
 
56
      *       in IGUIEnvironment)
 
57
      */
 
58
    Widget* getFocusForPlayer(const int playerID);
 
59
 
 
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
 
63
      *       in IGUIEnvironment)
 
64
      */
 
65
    void focusNothingForPlayer(const int playerID);
 
66
 
 
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
 
70
      *        in IGUIEnvironment)
 
71
      */
 
72
    bool isFocusedForPlayer(const Widget*w, const int playerID);
 
73
    
 
74
    /**
 
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.
 
77
      */
 
78
    namespace Private
 
79
    {
 
80
        extern irr::gui::IGUIEnvironment* g_env;
 
81
        extern Skin* g_skin;
 
82
        extern irr::gui::ScalableFont* g_small_font;
 
83
        extern irr::gui::ScalableFont* g_font;
 
84
        extern irr::gui::ScalableFont* g_title_font;
 
85
 
 
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];
 
91
    }
 
92
    
 
93
    /** Widgets that need to be notified at every frame can add themselves there (FIXME: unclean) */
 
94
    extern ptr_vector<Widget, REF> needsUpdate;
 
95
    
 
96
    /**
 
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
 
102
      */
 
103
    void init(irr::IrrlichtDevice* device, irr::video::IVideoDriver* driver, AbstractStateManager* state_manager);
 
104
    
 
105
    /**
 
106
      * \brief frees all resources allocated by GUIEngine::init and subsequent uses of the GUI engine.
 
107
      */
 
108
    void cleanUp();
 
109
    
 
110
    
 
111
    /**
 
112
      * \return the irrlicht device object
 
113
      */
 
114
    inline irr::IrrlichtDevice*       getDevice()        { return Private::g_device;         }
 
115
    
 
116
    /**
 
117
      * \return the irrlicht GUI environment object
 
118
      */
 
119
    inline irr::gui::IGUIEnvironment* getGUIEnv()        { return Private::g_env;            }
 
120
    
 
121
    /**
 
122
      * \return the irrlicht video driver object
 
123
     */
 
124
    inline irr::video::IVideoDriver*  getDriver()        { return Private::g_driver;         }
 
125
    
 
126
    /**
 
127
      * \return the smaller font (useful for less important messages)
 
128
      */
 
129
    inline irr::gui::ScalableFont*    getSmallFont()     { return Private::g_small_font;     }
 
130
    
 
131
    /**
 
132
      * \return the "normal" font (useful for text)
 
133
      */
 
134
    inline irr::gui::ScalableFont*    getFont()          { return Private::g_font;           }
 
135
    
 
136
    /**
 
137
      * \return the "title" font (it's bigger and orange, useful for headers/captions)
 
138
      */
 
139
    inline irr::gui::ScalableFont*    getTitleFont()     { return Private::g_title_font;     }
 
140
    
 
141
    /**
 
142
      * \return the currently shown screen, or NULL if none
 
143
      */
 
144
    inline Screen*                    getCurrentScreen() { return Private::g_current_screen; }
 
145
    
 
146
    /**
 
147
      * \return the state manager being used, as passed to GUIEngine::init
 
148
      */
 
149
    inline AbstractStateManager*      getStateManager()  { return Private::g_state_manager;  }
 
150
    
 
151
    /**
 
152
      * \precondition GUIEngine::init must have been called first
 
153
      * \return       the skin object used to render widgets
 
154
      */
 
155
    inline Skin*                      getSkin()          { return Private::g_skin;           }
 
156
 
 
157
    Screen*                           getScreenNamed(const char* name);
 
158
    
 
159
    /** \return the height of the title font in pixels */
 
160
    int   getTitleFontHeight();
 
161
    
 
162
    /** \return the height of the font in pixels */
 
163
    int   getFontHeight();
 
164
    
 
165
    /** \return the height of the small font in pixels */
 
166
    int   getSmallFontHeight();
 
167
    
 
168
    /**
 
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
 
171
      */
 
172
    float getLatestDt();
 
173
    
 
174
    /**
 
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
 
178
      */
 
179
    void showMessage(const wchar_t* message, const float time=5.0f);
 
180
    
 
181
    /** \brief Add a screen to the list of screens known by the gui engine */
 
182
    void  addScreenToList(Screen* screen);
 
183
    
 
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.
 
186
      */
 
187
    void switchToScreen(const char* );
 
188
    
 
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.
 
191
      */
 
192
    void clear();
 
193
    
 
194
    /** \brief like GUIEngine::clear, but to be called before going into game */
 
195
    void cleanForGame();
 
196
    
 
197
    /** \brief to be called after e.g. a resolution switch */
 
198
    void reshowCurrentScreen();
 
199
    
 
200
    /**
 
201
      * \brief called on every frame to trigger the rendering of the GUI
 
202
      */
 
203
    void render(float dt);
 
204
    
 
205
    /** \brief renders a "loading" screen */
 
206
    void renderLoading(bool clearIcons = true);
 
207
    
 
208
    /** \brief to spice up a bit the loading icon : add icons to the loading screen */
 
209
    void addLoadingIcon(irr::video::ITexture* icon);
 
210
    
 
211
    //void transmitEvent(Widget* widget, std::string& name, const int playerID);
 
212
    
 
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
 
216
      */
 
217
    Widget* getWidget(const char* name);
 
218
    
 
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
 
223
      */
 
224
    Widget* getWidget(const int id);
 
225
    
 
226
    /**
 
227
      * \brief call when skin in user config was updated
 
228
      */
 
229
    void reloadSkin();
 
230
}
 
231
 
 
232
#endif