Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shader_HS18/src/libraries/core/GUIManager.h @ 12098

Last change on this file since 12098 was 11809, checked in by landauf, 7 years ago

added work around for a bug in cegui 0.8 (the cegui lua scripts expect a "Font*" pointer to call getTextExtent(), but cegui 0.8 only returns "const Font*")

  • Property svn:eol-style set to native
File size: 9.7 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *      Benjamin Knecht
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30/**
31    @file
32    @ingroup Graphics
33*/
34
35#ifndef _GUIManager_H__
36#define _GUIManager_H__
37
38#include "CorePrereqs.h"
39
40#include <map>
41#include <string>
42#include <memory>
43
44#if CEGUI_VERSION >= 0x000800
45#   include <CEGUI/ForwardRefs.h>
46#   include <CEGUI/Version.h>
47#else
48#   include <CEGUIForwardRefs.h>
49#   include <CEGUIVersion.h>
50#endif
51
52#include "util/DestructionHelper.h"
53#include "util/OgreForwardRefs.h"
54#include "util/tribool.h"
55#include "util/Singleton.h"
56#include "input/InputHandler.h"
57#include "WindowEventListener.h"
58
59#if CEGUI_VERSION_MAJOR < 1 && CEGUI_VERSION_MINOR < 7
60#  define ORXONOX_OLD_CEGUI
61#endif
62
63namespace orxonox // tolua_export
64{ // tolua_export
65    class PlayerInfo; // Forward declaration
66
67    // Acquaint Tolua with tribool
68    /* tolua_begin
69    struct dontcare_keyword_t
70    {
71        dontcare_keyword_t();
72    };
73    class tribool
74    {
75        tribool(bool value);
76        tribool(dontcare_keyword_t);
77        bool operator==(tribool);
78    };
79    tolua_end */
80
81    /**
82    @class GUIManager
83    @brief
84        Provides a simple interface to CEGUI with tolua methods and console commands. It also acts as a key and mouse handler.
85
86        The GUIManager is a singleton and can be called anywhere when access on the GUI is needed.
87
88        Since the GUI needs user input, the GUIManager implements the functions needed to act as a key and/or mouse handler.
89        Those input events are then injected into CEGUI in Lua.
90    */
91    class _CoreExport GUIManager // tolua_export
92        : public Singleton<GUIManager>, public InputHandler, public WindowEventListener
93    { // tolua_export
94        friend class Singleton<GUIManager>;
95    public:
96        GUIManager(const std::pair<int, int>& mousePosition);
97
98        //! Leave empty and use cleanup() instead
99        ~GUIManager() = default;
100        /// Destructor that also executes when object fails to construct
101        void destroy();
102
103        void setConfigValues(void);
104        void changedGUIScheme(void);
105
106        void preUpdate(const Clock& time);
107
108        std::vector<std::string> getLoadedGUIs();
109
110        void loadGUI(const std::string& name);
111        static void showGUI(const std::string& name, bool bHidePrevious = false, bool bNoInput = false);
112        void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false, bool bNoInput = false);
113        static void hideGUI(const std::string& name);
114        static void toggleGUI(const std::string& name, bool bHidePrevious = false, bool bNoInput = false);
115        void toggleGUIHelper(const std::string& name, bool bHidePrevious, bool bNoInput, bool show); // tolua_export
116        void keyESC();
117        void setBackgroundImage(const std::string& imageSet, const std::string imageName); // tolua_export
118        void setBackgroundImage(const std::string& image);
119
120        static bool preloadMenuSheets() { return GUIManager::getInstance().bPreloadMenuSheets_; } // tolua_export
121        static bool inDevMode(void); // tolua_export
122
123        //! Creates a new InputState to be used with a GUI Sheet
124        const std::string& createInputState(const std::string& name, tribool showCursor = tribool(true), tribool useKeyboard = tribool(true), bool bBlockJoyStick = false); // tolua_export
125        LuaState* getLuaState(void)
126            { return this->luaState_; }
127
128        //! Returns the root window for all menu sheets
129        CEGUI::Window* getMenuRootWindow() { return this->menuRootWindow_; } // tolua_export
130        //! Returns the root window for all HUD sheets
131        CEGUI::Window* getHUDRootWindow() { return this->hudRootWindow_; } // tolua_export
132
133        void setCamera(Ogre::Camera* camera);
134        Ogre::Camera* getCamera() { return this->camera_; }
135
136        inline void setPlayer(const std::string& guiname, PlayerInfo* player)
137            { this->players_[guiname] = player; }
138        inline orxonox::PlayerInfo* getPlayer(const std::string& guiname) const { std::map<std::string, PlayerInfo*>::const_iterator it = this->players_.find(guiname); return (it != this->players_.end()) ? it->second : nullptr; } // tolua_export
139
140        // TODO: Temporary hack because the tolua exported CEGUI method does not seem to work
141        static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); // tolua_export
142        static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); // tolua_export
143        static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); // tolua_export
144        static void addFontHelper(const std::string& name, int size, const std::string& fontName); // tolua_export
145        static float getFontTextExtent(const CEGUI::Font* font, const std::string& text, float x_scale = 1.0f); // tolua_export
146
147        static GUIManager& getInstance() { return Singleton<GUIManager>::getInstance(); } // tolua_export
148
149        /**
150        @brief Check whether CEGUI is version < 0.7.
151        @return Returns true if the CEGUI version is < 0.7. False otherwise.
152        */
153        inline bool usingOldCEGUI(void) { return this->oldCEGUI_; } // tolua_export
154
155    private:
156        // non-copyable:
157        GUIManager(const GUIManager&) = delete;
158        GUIManager& operator=(const GUIManager&) = delete;
159
160        void executeCode(const std::string& str);
161
162        template <typename FunctionType, typename ObjectType>
163        bool protectedCall(FunctionType function, ObjectType object);
164
165        template <typename FunctionType>
166        bool protectedCeguiSystemCall(FunctionType function);
167
168#if CEGUI_VERSION >= 0x000800
169        template <typename FunctionType>
170        bool protectedCeguiContextCall(FunctionType function);
171#endif
172
173        void changedCeguiOutputLevel();
174
175        // keyHandler functions
176        virtual void buttonPressed (const KeyEvent& evt) override;
177        virtual void buttonReleased(const KeyEvent& evt) override;
178
179        // mouseHandler functions
180        virtual void buttonPressed (MouseButtonCode::ByEnum id) override;
181        virtual void buttonReleased(MouseButtonCode::ByEnum id) override;
182        virtual void mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) override;
183        virtual void mouseScrolled (int abs, int rel) override;
184        void mouseLeft     ();
185
186        // window event handler
187        virtual void windowResized(unsigned int newWidth, unsigned int newHeight) override;
188        virtual void windowFocusChanged(bool bFocus) override;
189
190#ifdef ORXONOX_OLD_CEGUI
191        CEGUI::OgreCEGUIRenderer*            guiRenderer_;          //!< CEGUI's interface to the Ogre Engine
192        CEGUI::ResourceProvider*             resourceProvider_;     //!< CEGUI's resource provider
193#else
194        CEGUI::OgreRenderer*                 guiRenderer_;          //!< CEGUI's interface to the Ogre Engine
195        CEGUI::OgreResourceProvider*         resourceProvider_;     //!< CEGUI's resource provider
196        Ogre::RenderQueueListener*           rqListener_;           //!< RQ listener so we can draw UNDER Ogre overlays
197        CEGUI::OgreImageCodec*               imageCodec_;
198#endif
199        LuaState*                            luaState_;             //!< LuaState, access point to the Lua engine
200        CEGUI::LuaScriptModule*              scriptModule_;         //!< CEGUI's script module to use Lua
201        CEGUI::System*                       guiSystem_;            //!< CEGUI's main system
202        std::shared_ptr<ResourceInfo>        rootFileInfo_;         //!< Resource information about the root script
203        CEGUI::Logger*                       ceguiLogger_;          //!< CEGUI's logger to be able to log CEGUI errors in our log
204        int                                  outputLevelCeguiLog_;  //!< CEGUI's log level
205        CEGUI::Window*                       rootWindow_;           //!< Root node for all windows
206        CEGUI::Window*                       hudRootWindow_;        //!< Root node for the HUD sheets
207        CEGUI::Window*                       menuRootWindow_;       //!< Root node for the menu sheets (used by Lua)
208        std::map<std::string, PlayerInfo*>   players_;              //!< Stores the player (owner) for each GUI
209        Ogre::Camera*                        camera_;               //!< Camera used to render the scene with the GUI
210
211        /// Helper object that executes the surrogate destructor destroy()
212        DestructionHelper<GUIManager>        destructionHelper_;
213
214        static GUIManager*                   singletonPtr_s;        //!< Singleton reference to GUIManager
215
216        // The used CEGUI scheme.
217        static const std::string defaultScheme_;
218        std::string guiScheme_;
219        bool oldCEGUI_;
220
221        int numScrollLines_;        ///< How many lines to scroll in a list if the scroll wheel is used
222        bool bPreloadMenuSheets_;   ///< If true, menu sheets are pre-loaded during startup
223
224    }; // tolua_export
225} // tolua_export
226
227#endif /* _GUIManager_H__ */
Note: See TracBrowser for help on using the repository browser.