Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/toonshader/src/orxonox/gui/GUIManager.h @ 10227

Last change on this file since 10227 was 2896, checked in by landauf, 16 years ago

Merged gui branch back to trunk.

I did 2 small changes in IngameManager.cc on line 777 and 888 (yes, really), because const_reverse_iterator strangely doesn't work on MinGW.

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