Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutoriallevel2/src/libraries/core/GUIManager.cc @ 8707

Last change on this file since 8707 was 8371, checked in by dafrick, 14 years ago

Merging tutoriallevel branch into tutoriallevel2 branch.

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