Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutoriallevel3/src/libraries/core/GUIManager.cc @ 8453

Last change on this file since 8453 was 8453, checked in by dafrick, 13 years ago

Merging tutoriallevel2 branch into tutoriallevel3 branch.

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