Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8423 was 8423, checked in by rgrieder, 13 years ago

Added and incorporated new class DestructionHelper: instead of doing the destruction of certain singletons implicitly via scoped_ptrs and ScopeGuards, use a method named destroy() that essentially achieves the same, but makes the destruction sequence obvious.

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