Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/GUIManager.cc @ 8460

Last change on this file since 8460 was 8439, checked in by rgrieder, 14 years ago

Fixed overlay drawing issue with CEGUI 0.7 (thx Crazy Eddie!).
You should now be able to see the console again in the main menu. Have fun ;)

  • Property svn:eol-style set to native
File size: 23.5 KB
RevLine 
[1638]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
[2896]24 *      Benjamin Knecht
[1638]25 *   Co-authors:
[3196]26 *      ...
[1638]27 *
28 */
29
30#include "GUIManager.h"
31
[8351]32#include <memory>
[6746]33#include <boost/bind.hpp>
[8351]34#include <OgreRenderQueue.h>
35#include <OgreRenderWindow.h>
[8079]36
[2710]37#include <CEGUIDefaultLogger.h>
[3196]38#include <CEGUIExceptions.h>
39#include <CEGUIInputEvent.h>
[5695]40#include <CEGUIMouseCursor.h>
[3196]41#include <CEGUIResourceProvider.h>
42#include <CEGUISystem.h>
[6417]43#include <CEGUIWindow.h>
[6746]44#include <CEGUIWindowManager.h>
[7648]45#include <elements/CEGUIListbox.h>
46#include <elements/CEGUIListboxItem.h>
[3196]47
[8351]48#ifdef ORXONOX_OLD_CEGUI
49#  include <CEGUILua.h>
50#  include <ogreceguirenderer/OgreCEGUIRenderer.h>
51extern "C" {
52#  include <lauxlib.h>
53}
[2710]54#else
[8351]55#  include <ScriptingModules/LuaScriptModule/CEGUILua.h>
56#  include <RendererModules/Ogre/CEGUIOgreImageCodec.h>
57#  include <RendererModules/Ogre/CEGUIOgreRenderer.h>
58#  include <RendererModules/Ogre/CEGUIOgreResourceProvider.h>
59#  include <OgreCamera.h>
60#  include <OgreRenderQueueListener.h>
[8439]61#  include <OgreRenderSystem.h>
62#  include <OgreRoot.h>
[8351]63#  include <OgreSceneManager.h>
[2710]64#endif
65
[5929]66#include "util/Clock.h"
[6417]67#include "util/Convert.h"
[3280]68#include "util/Debug.h"
[1764]69#include "util/Exception.h"
[3280]70#include "util/OrxAssert.h"
[7801]71#include "ConfigValueIncludes.h"
[6417]72#include "Core.h"
[7801]73#include "CoreIncludes.h"
[7876]74#include "Game.h"
[6746]75#include "GraphicsManager.h"
[5695]76#include "LuaState.h"
[5929]77#include "PathConfig.h"
[5695]78#include "Resource.h"
[7284]79#include "command/ConsoleCommand.h"
[6746]80#include "input/InputManager.h"
81#include "input/InputState.h"
82#include "input/KeyBinderManager.h"
[1638]83
84namespace orxonox
85{
[6417]86    static void key_esc()
87        { GUIManager::getInstance().keyESC(); }
[7284]88    SetConsoleCommand("keyESC", &key_esc);
[6417]89
[3280]90    class CEGUILogger : public CEGUI::DefaultLogger
91    {
92    public:
[5929]93        void logEvent(const CEGUI::String& message, CEGUI::LoggingLevel level = CEGUI::Standard)
[3280]94        {
[3327]95            int orxonoxLevel = CEGUI::Standard;
[3280]96            switch (level)
97            {
98                case CEGUI::Errors:      orxonoxLevel = 1; break;
99                case CEGUI::Warnings:    orxonoxLevel = 2; break;
100                case CEGUI::Standard:    orxonoxLevel = 4; break;
101                case CEGUI::Informative: orxonoxLevel = 5; break;
102                case CEGUI::Insane:      orxonoxLevel = 6; break;
[8351]103                default: OrxAssert(false, "CEGUI log level out of range, inspect immediately!");
[3280]104            }
[6105]105            OutputHandler::getOutStream(orxonoxLevel)
[3280]106                << "CEGUI: " << message << std::endl;
107
108            CEGUI::DefaultLogger::logEvent(message, level);
109        }
110    };
111
[8351]112#ifdef ORXONOX_OLD_CEGUI
113    /** Class with the same memory layout as CEGUI::LuaScriptModule. <br>
114        We need this to fix a problem with an uninitialised member variable
115        in CEGUI < 0.7 <br>
116        Notice the "public" modifier for the otherwise private variables.
117    */
118    class LuaScriptModuleWorkaround : public CEGUI::ScriptModule
119    {
120    public:
121        LuaScriptModuleWorkaround();
122        ~LuaScriptModuleWorkaround();
123
124    public:
125        bool d_ownsState;
126        lua_State* d_state;
127        CEGUI::String d_errFuncName;
128        int d_errFuncIndex;
129        CEGUI::String d_activeErrFuncName;
130        int d_activeErrFuncIndex;
131    };
132#else
133    /// RenderQueueListener based class used to hook into the ogre rendering system
134    class RQListener : public Ogre::RenderQueueListener
135    {
136    public:
137        /// Callback from Ogre invoked before other stuff in our target queue is rendered
[8419]138        void renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation, bool& skipThisQueue)
[8351]139        {
[8419]140            if (id == Ogre::RENDER_QUEUE_OVERLAY && invocation.empty())
[8439]141            {
[8351]142                CEGUI::System::getSingleton().renderGUI();
[8439]143
144                // Important workaround! (at least required by CEGUI 0.7.5)
145                // If we don't reset the scissor test, OGRE will only render overlays
146                // in the area where CEGUI last drew, which is usually nothing
147                // or a little box where the focused element is.
148                Ogre::Root::getSingleton().getRenderSystem()->setScissorTest(false);
149            }
[8351]150        }
151    };
152#endif
153
[3196]154    static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button);
[3339]155
[3366]156    GUIManager* GUIManager::singletonPtr_s = 0;
[7801]157    /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen";
[1646]158
[7403]159    SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false);
[7284]160    SetConsoleCommand("hideGUI", &GUIManager::hideGUI);
[8079]161    SetConsoleCommand("toggleGUI", &GUIManager::toggleGUI).defaultValue(1, false).defaultValue(2, false);
[6417]162
[2896]163    /**
164    @brief
[3338]165        Constructs the GUIManager by starting up CEGUI
[2896]166
167        Creates the interface to Ogre, sets up the CEGUI renderer and the Lua script module together with the Lua engine.
168        The log is set up and connected to the CEGUILogger.
169        After Lua setup tolua++-elements are linked to Lua-state to give Lua access to C++-code.
170        Finally initial Lua code is executed (maybe we can do this with the CEGUI startup script automatically).
[3338]171    @return true if success, otherwise false
[2896]172    */
[6746]173    GUIManager::GUIManager(const std::pair<int, int>& mousePosition)
[8423]174        : guiRenderer_(NULL)
[8351]175        , resourceProvider_(NULL)
176#ifndef ORXONOX_OLD_CEGUI
[8411]177        , rqListener_(NULL)
[8351]178        , imageCodec_(NULL)
179#endif
180        , luaState_(NULL)
181        , scriptModule_(NULL)
182        , guiSystem_(NULL)
[8411]183        , ceguiLogger_(NULL)
184        , rootWindow_(NULL)
185        , hudRootWindow_(NULL)
186        , menuRootWindow_(NULL)
[5929]187        , camera_(NULL)
[8423]188        , destructionHelper_(this)
[1638]189    {
[7801]190        RegisterRootObject(GUIManager);
191        this->setConfigValues();
192
[1638]193        using namespace CEGUI;
194
[3338]195        COUT(3) << "Initialising CEGUI." << std::endl;
[1638]196
[5695]197        // Note: No SceneManager specified yet
[8351]198#ifdef ORXONOX_OLD_CEGUI
199        guiRenderer_ = new OgreCEGUIRenderer(GraphicsManager::getInstance().getRenderWindow(), Ogre::RENDER_QUEUE_OVERLAY, false, 3000);
[5695]200        resourceProvider_ = guiRenderer_->createResourceProvider();
[8351]201#else
202        guiRenderer_ = &OgreRenderer::create(*GraphicsManager::getInstance().getRenderWindow());
203        // We use our own RenderQueueListener so we can draw UNDER overlays
204        guiRenderer_->setFrameControlExecutionEnabled(false);
205        rqListener_ = new RQListener();
206        resourceProvider_ = &OgreRenderer::createOgreResourceProvider();
207        imageCodec_ = &OgreRenderer::createOgreImageCodec();
208#endif
[7709]209        resourceProvider_->setDefaultResourceGroup("General");
[1776]210
[6749]211        // Setup scripting
[8351]212        luaState_ = new LuaState();
[6417]213        rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua");
214        // This is necessary to ensure that input events also use the right resource info when triggering lua functions
215        luaState_->setDefaultResourceInfo(this->rootFileInfo_);
[8351]216#ifdef ORXONOX_OLD_CEGUI
217        scriptModule_ = new LuaScriptModule(luaState_->getInternalLuaState());
218        // Ugly workaround: older CEGUILua versions don't initialise the member
219        // d_activeErrFuncIndex at all. That leads to "error in error handling"
220        // problems when a Lua error occurs.
221        // We fix this by setting the member manually.
222        reinterpret_cast<LuaScriptModuleWorkaround*>(scriptModule_)->d_activeErrFuncIndex = LUA_NOREF;
223        luaState_->doString("ORXONOX_OLD_CEGUI = true");
224#else
225        scriptModule_ = &LuaScriptModule::create(luaState_->getInternalLuaState());
226#endif
[6763]227        scriptModule_->setDefaultPCallErrorHandler(LuaState::ERROR_HANDLER_NAME);
[1638]228
[5695]229        // Create our own logger to specify the filepath
230        std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger());
[5929]231        ceguiLogger->setLogFilename(PathConfig::getLogPathString() + "cegui.log");
[8351]232        // Set the log level according to ours (translate by subtracting 1)
[5695]233        ceguiLogger->setLoggingLevel(
[6105]234            static_cast<LoggingLevel>(OutputHandler::getInstance().getSoftDebugLevel("logFile") - 1));
[5695]235        this->ceguiLogger_ = ceguiLogger.release();
[2710]236
[6749]237        // Create the CEGUI system singleton
[8351]238#ifdef ORXONOX_OLD_CEGUI
239        guiSystem_ = new System(guiRenderer_, resourceProvider_, 0, scriptModule_);
240        // Add functions that have been renamed in newer versions
241        luaState_->doString("CEGUI.SchemeManager.create = CEGUI.SchemeManager.loadScheme");
242        luaState_->doString("CEGUI.Window.getUnclippedOuterRect = CEGUI.Window.getUnclippedPixelRect");
243#else
244        guiSystem_ = &System::create(*guiRenderer_, resourceProvider_, 0, imageCodec_, scriptModule_);
245#endif
[1776]246
[5695]247        // Align CEGUI mouse with OIS mouse
[6502]248        guiSystem_->injectMousePosition((float)mousePosition.first, (float)mousePosition.second);
[5695]249
[6746]250        // Initialise the Lua framework and load the schemes
251        this->luaState_->doFile("InitialiseGUI.lua");
252
253        // Create the root nodes
254        this->rootWindow_ = CEGUI::WindowManager::getSingleton().createWindow("MenuWidgets/StaticImage", "AbsoluteRootWindow");
255        this->rootWindow_->setProperty("FrameEnabled", "False");
256        this->hudRootWindow_ = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "HUDRootWindow");
257        this->menuRootWindow_ = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "MenuRootWindow");
258        // And connect them
259        CEGUI::System::getSingleton().setGUISheet(this->rootWindow_);
260        this->rootWindow_->addChildWindow(this->hudRootWindow_);
261        this->rootWindow_->addChildWindow(this->menuRootWindow_);
262
[6749]263        // No background to start with (sets the alpha value to 0)
264        this->setBackgroundImage("");
265
[6746]266        // Set up the sheet manager in the Lua framework
267        this->luaState_->doFile("SheetManager.lua");
[3338]268    }
[1776]269
[8423]270    void GUIManager::destroy()
[3338]271    {
[8351]272        using namespace CEGUI;
273
274#ifdef ORXONOX_OLD_CEGUI
[8423]275        safeObjectDelete(&guiSystem_);
276        safeObjectDelete(&guiRenderer_);
277        safeObjectDelete(&scriptModule_);
[8351]278#else
279        System::destroy();
280        OgreRenderer::destroyOgreResourceProvider(*resourceProvider_);
281        OgreRenderer::destroyOgreImageCodec(*imageCodec_);
282        OgreRenderer::destroy(*guiRenderer_);
283        LuaScriptModule::destroy(*scriptModule_);
[8423]284        safeObjectDelete(&ceguiLogger_);
285        safeObjectDelete(&rqListener_);
[8351]286#endif
[8423]287        safeObjectDelete(&luaState_);
[1638]288    }
289
[7801]290    void GUIManager::setConfigValues(void)
291    {
292        SetConfigValue(guiScheme_, GUIManager::defaultScheme_) .description("Changes the current GUI scheme.") .callback(this, &GUIManager::changedGUIScheme);
293    }
294
295    void GUIManager::changedGUIScheme(void)
296    {
297    }
298
[2896]299    /**
300    @brief
301        used to tick the GUI
302    @param time
303        clock which provides time value for the GUI System
304
305        Ticking the GUI means updating it with a certain regularity.
306        The elapsed time since the last call is given in the time value provided by the clock.
307        This time value is then used to provide a fluent animation of the GUI.
308    */
[6417]309    void GUIManager::preUpdate(const Clock& time)
[1638]310    {
[2896]311        assert(guiSystem_);
[6746]312        this->protectedCall(boost::bind(&CEGUI::System::injectTimePulse, _1, time.getDeltaTime()));
[2896]313    }
[1638]314
[2896]315    /**
316    @brief
317        Tells the GUIManager which SceneManager to use
318    @param camera
319        The current camera on which the GUI should be displayed on.
320
321        In fact the GUIManager needs the SceneManager and not the Camera to display the GUI.
322        This means the GUI is not bound to a camera but rather to the SceneManager.
[3337]323        Hiding the GUI when needed can therefore not be resolved by just NOT setting the current camera.
[2896]324    */
325    void GUIManager::setCamera(Ogre::Camera* camera)
[1638]326    {
[8351]327#ifdef ORXONOX_OLD_CEGUI
[2927]328        if (camera == NULL)
329            this->guiRenderer_->setTargetSceneManager(0);
330        else
331            this->guiRenderer_->setTargetSceneManager(camera->getSceneManager());
[8351]332#else
333        if (camera_ != NULL && camera_->getSceneManager() != NULL)
334            camera_->getSceneManager()->removeRenderQueueListener(rqListener_);
335        if (camera != NULL && camera->getSceneManager() != NULL)
336            camera->getSceneManager()->addRenderQueueListener(rqListener_);
337#endif
338        this->camera_ = camera;
[2896]339    }
340
341    /**
342    @brief
[3338]343        Executes Lua code
344    @param str
345        reference to string object holding the Lua code which is to be executed
346    */
347    void GUIManager::executeCode(const std::string& str)
348    {
[5695]349        this->luaState_->doString(str, rootFileInfo_);
[3338]350    }
351
[6746]352    /** Loads a GUI sheet by Lua script
353    @param name
354        The name of the GUI (like the script name, but without the extension)
355    */
356    void GUIManager::loadGUI(const std::string& name)
357    {
358        this->executeCode("loadSheet(\"" + name + "\")");
359    }
360
[3338]361    /**
362    @brief
[2896]363        Displays specified GUI on screen
364    @param name
365        The name of the GUI
[7401]366    @param bHidePrevious
367        If true all displayed GUIs on the stack, that are below this GUI are hidden.
[7403]368    @param bNoInput
369        If true the GUI is transparent to input.
[2896]370
371        The function executes the Lua function with the same name in case the GUIManager is ready.
372    */
[7403]373    /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious, bool bNoInput)
[2896]374    {
[7403]375        GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ")");
[1638]376    }
377
[6417]378    /**
379    @brief
380        Hack-ish. Needed for GUIOverlay.
381    */
[7403]382    void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious, bool bNoInput)
[6417]383    {
[7403]384        this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ", " + ptr + ")");
[6417]385    }
386
387    /**
388    @brief
389        Hides specified GUI.
390    @param name
391        The name of the GUI.
392    */
393    /*static*/ void GUIManager::hideGUI(const std::string& name)
394    {
[6746]395        GUIManager::getInstance().executeCode("hideMenuSheet(\"" + name + "\")");
[6417]396    }
397
[8079]398    /**
399    @brief
400        Toggles specified GUI.
401        If the GUI with the input name is already shown and on the top, it is hidden, else it is shown.
402    */
403    /*static*/ void GUIManager::toggleGUI(const std::string& name, bool bHidePrevious, bool bNoInput)
404    {
405        GUIManager::getInstance().executeCode("getGUIFirstActive(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ")");
406    }
407
408    /**
409    @brief
410        Helper method to toggle a specified GUI.
411        Is called by lua.
412    */
413    void GUIManager::toggleGUIHelper(const std::string& name, bool bHidePrevious, bool bNoInput, bool show)
414    {
415        if(show)
416            GUIManager::showGUI(name, bHidePrevious, bNoInput);
417        else
418            GUIManager::hideGUI(name);
419    }
420
[6746]421    const std::string& GUIManager::createInputState(const std::string& name, TriBool::Value showCursor, TriBool::Value useKeyboard, bool bBlockJoyStick)
422    {
423        InputState* state = InputManager::getInstance().createInputState(name);
[7811]424        if (!state)
425            return BLANKSTRING;
[6746]426
427        /* Table that maps isFullScreen() and showCursor to mouseExclusive
428        isFullscreen / showCursor | True  | False | Dontcare
429        ----------------------------------------------------
430        true                      | True  | True  | Dontcare
431        ----------------------------------------------------
432        false                     | False | True  | Dontcare
433        */
[8351]434
435#ifdef ORXONOX_PLATFORM_APPLE
436        // There is no non exclusive mode on OS X yet
437        state->setMouseExclusive(TriBool::True);
438#else
[6746]439        if (showCursor == TriBool::Dontcare)
440            state->setMouseExclusive(TriBool::Dontcare);
441        else if (GraphicsManager::getInstance().isFullScreen() || showCursor == TriBool::False)
442            state->setMouseExclusive(TriBool::True);
443        else
444            state->setMouseExclusive(TriBool::False);
[8351]445#endif
[6746]446
447        if (showCursor == TriBool::True)
448            state->setMouseHandler(this);
449        else if (showCursor == TriBool::False)
450            state->setMouseHandler(&InputHandler::EMPTY);
451
452        if (useKeyboard == TriBool::True)
453            state->setKeyHandler(this);
454        else if (useKeyboard == TriBool::False)
455            state->setKeyHandler(&InputHandler::EMPTY);
456
457        if (bBlockJoyStick)
458            state->setJoyStickHandler(&InputHandler::EMPTY);
459
460        return state->getName();
461    }
462
[6417]463    void GUIManager::keyESC()
464    {
465        this->executeCode("keyESC()");
466    }
467
[6746]468    void GUIManager::setBackgroundImage(const std::string& imageSet, const std::string imageName)
[6417]469    {
[6746]470        if (imageSet.empty() || imageName.empty())
471            this->setBackgroundImage("");
472        else
473            this->setBackgroundImage("set: " + imageSet + " image: " + imageName);
[6417]474    }
475
[6746]476    void GUIManager::setBackgroundImage(const std::string& image)
477    {
478        if (image.empty())
479            this->rootWindow_->setProperty("Alpha", "0.0");
480        else
481            this->rootWindow_->setProperty("Alpha", "1.0");
482        this->rootWindow_->setProperty("Image", image);
483    }
484
[7163]485    void GUIManager::buttonPressed(const KeyEvent& evt)
[3196]486    {
[6746]487        this->protectedCall(boost::bind(&CEGUI::System::injectKeyDown, _1, evt.getKeyCode()));
488        this->protectedCall(boost::bind(&CEGUI::System::injectChar, _1, evt.getText()));
[3196]489    }
[6746]490
[7163]491    void GUIManager::buttonReleased(const KeyEvent& evt)
[3196]492    {
[6746]493        this->protectedCall(boost::bind(&CEGUI::System::injectKeyUp, _1, evt.getKeyCode()));
[3196]494    }
495
[2896]496    /**
497    @brief
498        Function receiving a mouse button pressed event.
499    @param id
500        ID of the mouse button which got pressed
[1638]501
[2896]502        This function is inherited by MouseHandler and injects the event into CEGUI.
503        It is for CEGUI to process the event.
504    */
[3327]505    void GUIManager::buttonPressed(MouseButtonCode::ByEnum id)
[1638]506    {
[6746]507        this->protectedCall(boost::bind(&CEGUI::System::injectMouseButtonDown, _1, convertButton(id)));
[1638]508    }
509
[2896]510    /**
511    @brief
512        Function receiving a mouse button released event.
513    @param id
514        ID of the mouse button which got released
515
516        This function is inherited by MouseHandler and injects the event into CEGUI.
517        It is for CEGUI to process the event.
518    */
[3327]519    void GUIManager::buttonReleased(MouseButtonCode::ByEnum id)
[1638]520    {
[6746]521        this->protectedCall(boost::bind(&CEGUI::System::injectMouseButtonUp, _1, convertButton(id)));
[1638]522    }
523
[3196]524    void GUIManager::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
525    {
[6746]526        this->protectedCall(boost::bind(&CEGUI::System::injectMousePosition, _1, (float)abs.x, (float)abs.y));
[3196]527    }
[6746]528
[3196]529    void GUIManager::mouseScrolled(int abs, int rel)
530    {
[6746]531        this->protectedCall(boost::bind(&CEGUI::System::injectMouseWheelChange, _1, (float)rel));
[3196]532    }
533
[2896]534    /**
[7874]535        @brief Indicates that the mouse left the application's window.
536    */
537    void GUIManager::mouseLeft()
538    {
539        this->protectedCall(boost::bind(&CEGUI::System::injectMouseLeaves, _1));
540    }
541
542    /**
[2896]543    @brief
544        converts mouse event code to CEGUI event code
545    @param button
546        code of the mouse button as we use it in Orxonox
547    @return
548        code of the mouse button as it is used by CEGUI
[1638]549
[6105]550        Simple conversion from mouse event code in Orxonox to the one used in CEGUI.
[2896]551     */
[3196]552    static inline CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button)
[1638]553    {
554        switch (button)
555        {
[1887]556        case MouseButtonCode::Left:
[1638]557            return CEGUI::LeftButton;
558
[1887]559        case MouseButtonCode::Right:
[1638]560            return CEGUI::RightButton;
561
[1887]562        case MouseButtonCode::Middle:
[1638]563            return CEGUI::MiddleButton;
564
[1887]565        case MouseButtonCode::Button3:
[1638]566            return CEGUI::X1Button;
567
[1887]568        case MouseButtonCode::Button4:
[1638]569            return CEGUI::X2Button;
570
571        default:
572            return CEGUI::NoButton;
573        }
574    }
[6417]575
[6746]576    /** Executes a CEGUI function normally, but catches CEGUI::ScriptException.
577        When a ScriptException occurs, the error message will be displayed and
578        the program carries on.
579    @remarks
580        The exception behaviour may pose problems if the code is not written
581        exception-safe (and you can forget about that in Lua). The program might
582        be left in an undefined state. But otherwise one script error would
583        terminate the whole program...
584    @note
585        Your life gets easier if you use boost::bind to create the object/function.
586    @param function
587        Any callable object/function that takes this->guiSystem_ as its only parameter.
588    @return
589        True if input was handled, false otherwise. A caught exception yields true.
590    */
591    template <typename FunctionType>
592    bool GUIManager::protectedCall(FunctionType function)
593    {
594        try
595        {
596            return function(this->guiSystem_);
597        }
598        catch (CEGUI::ScriptException& ex)
599        {
600            // Display the error and proceed. See @remarks why this can be dangerous.
601            COUT(1) << ex.getMessage() << std::endl;
602            return true;
603        }
604    }
605
[7648]606    /**
607    @brief
608        Subscribe the input function to the input event for the input window.
609        This is a helper to be used in lua, because subscribeScriptedEvent() doesn't work in lua.
610    @param window
611        The window for which the event is subscribed.
612    @param event
613        The type of event to which we subscribe.
614    @param function
615        The function that is called when the event occurs.
616    */
[6417]617    void GUIManager::subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function)
618    {
619        window->subscribeScriptedEvent(event, function);
620    }
[7648]621
622    /**
623    @brief
624        Set the input tooltip text for the input ListboxItem.
625    @param item
626        The ListboxItem for which the tooltip should be set.
627    @param tooltip
628        The tooltip text that should be set.
629    */
630    void GUIManager::setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& tooltip)
631    {
632        item->setTooltipText(tooltip);
633    }
634
635    /**
636    @brief
637        Set whether the tooltips for the input Listbox are enabled.
638    @param listbox
639        The Listbox for which to enable (or disable) tooltips.
640    @param enabled
[8351]641        Whether to enable or disable the tooltips.
[7648]642    */
643    void GUIManager::setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled)
644    {
645        listbox->setItemTooltipsEnabled(enabled);
646    }
647
[7873]648    /**
649        @brief Callback of window event listener, called if the window is resized. Sets the display size of CEGUI.
650    */
651    void GUIManager::windowResized(unsigned int newWidth, unsigned int newHeight)
652    {
[8079]653        this->guiRenderer_->setDisplaySize(CEGUI::Size((float)newWidth, (float)newHeight));
[7873]654    }
[7874]655
656    /**
[8079]657        @brief Notify CEGUI if the windows loses the focus (stops highlighting of menu items, etc).
[7874]658    */
659    void GUIManager::windowFocusChanged(bool bFocus)
660    {
661        if (!bFocus)
662            this->mouseLeft();
663    }
[7876]664
[1638]665}
Note: See TracBrowser for help on using the repository browser.