Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/gui/GUIManager.h @ 2992

Last change on this file since 2992 was 2962, checked in by dafrick, 16 years ago

Created collecting of GUIOverlays in the GUIManager to make the accessible through the GUIManager.

  • Property svn:eol-style set to native
File size: 5.3 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 *   Co-authors:
25 *      Benjamin Knecht
26 *
27 */
28
29/**
30    @file
31    @brief Declaration of the GUIManager class.
32*/
33
34#ifndef _GUIManager_H__
35#define _GUIManager_H__
36
37#include "OrxonoxPrereqs.h"
38#include <OgrePrerequisites.h>
39#include <CEGUIForwardRefs.h>
40#include <CEGUIInputEvent.h>
41#include <CEGUISystem.h>
42#include "core/input/InputInterfaces.h"
43#include <map>
44#include "overlays/GUIOverlay.h"
45
46// Forward declaration
47namespace CEGUI { class DefaultLogger; }
48
49// tolua_begin
50namespace orxonox
51{
52    /**
53    @class GUIManager
54    @brief
55        Provides a simple interface to CEGUI with tolua methods and console commands. It also acts as a key and mouse handler.
56
57        The GUIManager is a singleton and can be called anywhere when access on the GUI is needed.
58        Creation of the GUIManager is therefore not possible and the cunstructor is private.
59
60        Since the GUI needs user input, the GUIManager implements the functions needed to act as a key and/or mouse handler.
61        Those input events are then injected into CEGUI in Lua.
62    */
63    class _OrxonoxExport GUIManager
64// tolua_end
65        : public KeyHandler, public MouseHandler
66// tolua_begin
67    {
68// tolua_end
69    public:
70        /**
71        @enum State
72            The current state of the GUIManager. There should maybe be more (or we can omit this totally).
73        */
74        enum State
75        {
76            Uninitialised,  //!< Initial state of the GUIManager
77            Ready,          //!< State after initialisation if ready
78            OnDisplay       //!< State if GUI is displayed
79        };
80
81        GUIManager();
82        ~GUIManager();
83
84        bool initialise(Ogre::RenderWindow* renderWindow);
85
86        void update(const Clock& time);
87
88        void showGUI(const std::string& name);
89        void executeCode(const std::string& str);
90
91        bool registerOverlay(std::string name, GUIOverlay* overlay); //!< Register a GUIOverlay with the GUIManager.
92        GUIOverlay* getOverlay(std::string name); // Get the GUIOverlay of the GUI with the given name.
93
94        void setCamera(Ogre::Camera* camera);
95
96        static GUIManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; } // tolua_export
97        static GUIManager* getInstancePtr() { return singletonRef_s; }
98
99    private:
100        GUIManager(const GUIManager& instance);                 //!< private constructor (this is a singleton class)
101
102        void loadLuaCode();
103
104        // keyHandler functions
105        void keyPressed (const KeyEvent& evt)
106            { guiSystem_->injectKeyDown(evt.key); guiSystem_->injectChar(evt.text); }
107        void keyReleased(const KeyEvent& evt)
108            { guiSystem_->injectKeyUp(evt.key); }
109        void keyHeld    (const KeyEvent& evt) { }
110
111        // mouseHandler functions
112        void mouseButtonPressed (MouseButtonCode::ByEnum id);
113        void mouseButtonReleased(MouseButtonCode::ByEnum id);
114        void mouseButtonHeld    (MouseButtonCode::ByEnum id) { }
115        void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
116            { guiSystem_->injectMouseMove(rel.x, rel.y); }
117        void mouseScrolled      (int abs, int rel)
118            { guiSystem_->injectMouseWheelChange(rel);}
119
120        void updateInput(float dt)  { }
121        void updateKey  (float dt)  { }
122        void updateMouse(float dt)  { }
123
124        static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button);
125
126        Ogre::RenderWindow*         renderWindow_;      //!< Ogre's render window to give CEGUI access to it
127        CEGUI::OgreCEGUIRenderer*   guiRenderer_;       //!< CEGUI's interface to the Ogre Engine
128        CEGUI::ResourceProvider*    resourceProvider_;  //!< CEGUI's resource provider
129        CEGUI::LuaScriptModule*     scriptModule_;      //!< CEGUI's script module to use Lua
130        CEGUI::DefaultLogger*       ceguiLogger_;       //!< CEGUI's logger to be able to log CEGUI errors in our log
131        CEGUI::System*              guiSystem_;         //!< CEGUI's main system
132        lua_State*                  luaState_;          //!< Lua state, access point to the Lua engine
133
134        State                       state_;             //!< reflects state of the GUIManager
135
136        std::map<std::string, GUIOverlay*> guiOverlays_;//!< A list of all GUIOverlay's.
137
138        static GUIManager*          singletonRef_s;     //!< Singleton reference to GUIManager
139
140    }; // tolua_export
141} // tolua_export
142
143#endif /* _GUIManager_H__ */
Note: See TracBrowser for help on using the repository browser.