[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 | |
---|
[7941] | 32 | #include <memory> |
---|
[6746] | 33 | #include <boost/bind.hpp> |
---|
[7939] | 34 | |
---|
[2710] | 35 | #include <CEGUIDefaultLogger.h> |
---|
[3196] | 36 | #include <CEGUIExceptions.h> |
---|
| 37 | #include <CEGUIInputEvent.h> |
---|
[5695] | 38 | #include <CEGUIMouseCursor.h> |
---|
[3196] | 39 | #include <CEGUIResourceProvider.h> |
---|
| 40 | #include <CEGUISystem.h> |
---|
[6417] | 41 | #include <CEGUIWindow.h> |
---|
[6746] | 42 | #include <CEGUIWindowManager.h> |
---|
[7648] | 43 | #include <elements/CEGUIListbox.h> |
---|
| 44 | #include <elements/CEGUIListboxItem.h> |
---|
[7941] | 45 | |
---|
| 46 | #include <CEGUILua.h> |
---|
[2710] | 47 | #include <ogreceguirenderer/OgreCEGUIRenderer.h> |
---|
[3196] | 48 | |
---|
[5929] | 49 | #include "util/Clock.h" |
---|
[6417] | 50 | #include "util/Convert.h" |
---|
[3280] | 51 | #include "util/Debug.h" |
---|
[1764] | 52 | #include "util/Exception.h" |
---|
[3280] | 53 | #include "util/OrxAssert.h" |
---|
[7801] | 54 | #include "ConfigValueIncludes.h" |
---|
[6417] | 55 | #include "Core.h" |
---|
[7801] | 56 | #include "CoreIncludes.h" |
---|
[7876] | 57 | #include "Game.h" |
---|
[6746] | 58 | #include "GraphicsManager.h" |
---|
[5695] | 59 | #include "LuaState.h" |
---|
[5929] | 60 | #include "PathConfig.h" |
---|
[5695] | 61 | #include "Resource.h" |
---|
[7284] | 62 | #include "command/ConsoleCommand.h" |
---|
[6746] | 63 | #include "input/InputManager.h" |
---|
| 64 | #include "input/InputState.h" |
---|
| 65 | #include "input/KeyBinderManager.h" |
---|
[1638] | 66 | |
---|
| 67 | namespace orxonox |
---|
| 68 | { |
---|
[6417] | 69 | static void key_esc() |
---|
| 70 | { GUIManager::getInstance().keyESC(); } |
---|
[7284] | 71 | SetConsoleCommand("keyESC", &key_esc); |
---|
[6417] | 72 | |
---|
[3280] | 73 | class CEGUILogger : public CEGUI::DefaultLogger |
---|
| 74 | { |
---|
| 75 | public: |
---|
[5929] | 76 | void logEvent(const CEGUI::String& message, CEGUI::LoggingLevel level = CEGUI::Standard) |
---|
[3280] | 77 | { |
---|
[3327] | 78 | int orxonoxLevel = CEGUI::Standard; |
---|
[3280] | 79 | switch (level) |
---|
| 80 | { |
---|
| 81 | case CEGUI::Errors: orxonoxLevel = 1; break; |
---|
| 82 | case CEGUI::Warnings: orxonoxLevel = 2; break; |
---|
| 83 | case CEGUI::Standard: orxonoxLevel = 4; break; |
---|
| 84 | case CEGUI::Informative: orxonoxLevel = 5; break; |
---|
| 85 | case CEGUI::Insane: orxonoxLevel = 6; break; |
---|
| 86 | default: OrxAssert(false, "CEGUI log level out of range, inpect immediately!"); |
---|
| 87 | } |
---|
[6105] | 88 | OutputHandler::getOutStream(orxonoxLevel) |
---|
[3280] | 89 | << "CEGUI: " << message << std::endl; |
---|
| 90 | |
---|
| 91 | CEGUI::DefaultLogger::logEvent(message, level); |
---|
| 92 | } |
---|
| 93 | }; |
---|
| 94 | |
---|
[3196] | 95 | static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button); |
---|
[3339] | 96 | |
---|
[3366] | 97 | GUIManager* GUIManager::singletonPtr_s = 0; |
---|
[7801] | 98 | /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen"; |
---|
[1646] | 99 | |
---|
[7403] | 100 | SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false); |
---|
[7284] | 101 | SetConsoleCommand("hideGUI", &GUIManager::hideGUI); |
---|
[6417] | 102 | |
---|
[2896] | 103 | /** |
---|
| 104 | @brief |
---|
[3338] | 105 | Constructs the GUIManager by starting up CEGUI |
---|
[2896] | 106 | |
---|
| 107 | Creates the interface to Ogre, sets up the CEGUI renderer and the Lua script module together with the Lua engine. |
---|
| 108 | The log is set up and connected to the CEGUILogger. |
---|
| 109 | After Lua setup tolua++-elements are linked to Lua-state to give Lua access to C++-code. |
---|
| 110 | Finally initial Lua code is executed (maybe we can do this with the CEGUI startup script automatically). |
---|
[3338] | 111 | @return true if success, otherwise false |
---|
[2896] | 112 | */ |
---|
[6746] | 113 | GUIManager::GUIManager(const std::pair<int, int>& mousePosition) |
---|
| 114 | : resourceProvider_(NULL) |
---|
[5929] | 115 | , camera_(NULL) |
---|
[1638] | 116 | { |
---|
[7801] | 117 | RegisterRootObject(GUIManager); |
---|
| 118 | this->setConfigValues(); |
---|
| 119 | |
---|
[1638] | 120 | using namespace CEGUI; |
---|
| 121 | |
---|
[3338] | 122 | COUT(3) << "Initialising CEGUI." << std::endl; |
---|
[1638] | 123 | |
---|
[5695] | 124 | // Note: No SceneManager specified yet |
---|
[6746] | 125 | guiRenderer_.reset(new OgreCEGUIRenderer(GraphicsManager::getInstance().getRenderWindow(), Ogre::RENDER_QUEUE_OVERLAY, false, 3000)); |
---|
[5695] | 126 | resourceProvider_ = guiRenderer_->createResourceProvider(); |
---|
[7709] | 127 | resourceProvider_->setDefaultResourceGroup("General"); |
---|
[1776] | 128 | |
---|
[6749] | 129 | // Setup scripting |
---|
[5695] | 130 | luaState_.reset(new LuaState()); |
---|
[6417] | 131 | rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua"); |
---|
| 132 | // This is necessary to ensure that input events also use the right resource info when triggering lua functions |
---|
| 133 | luaState_->setDefaultResourceInfo(this->rootFileInfo_); |
---|
[5695] | 134 | scriptModule_.reset(new LuaScriptModule(luaState_->getInternalLuaState())); |
---|
[6763] | 135 | scriptModule_->setDefaultPCallErrorHandler(LuaState::ERROR_HANDLER_NAME); |
---|
[1638] | 136 | |
---|
[5695] | 137 | // Create our own logger to specify the filepath |
---|
| 138 | std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger()); |
---|
[5929] | 139 | ceguiLogger->setLogFilename(PathConfig::getLogPathString() + "cegui.log"); |
---|
[5695] | 140 | // set the log level according to ours (translate by subtracting 1) |
---|
| 141 | ceguiLogger->setLoggingLevel( |
---|
[6105] | 142 | static_cast<LoggingLevel>(OutputHandler::getInstance().getSoftDebugLevel("logFile") - 1)); |
---|
[5695] | 143 | this->ceguiLogger_ = ceguiLogger.release(); |
---|
[2710] | 144 | |
---|
[6749] | 145 | // Create the CEGUI system singleton |
---|
[5695] | 146 | guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get())); |
---|
[1776] | 147 | |
---|
[5695] | 148 | // Align CEGUI mouse with OIS mouse |
---|
[6502] | 149 | guiSystem_->injectMousePosition((float)mousePosition.first, (float)mousePosition.second); |
---|
[5695] | 150 | |
---|
[6746] | 151 | // Initialise the Lua framework and load the schemes |
---|
| 152 | this->luaState_->doFile("InitialiseGUI.lua"); |
---|
| 153 | |
---|
| 154 | // Create the root nodes |
---|
| 155 | this->rootWindow_ = CEGUI::WindowManager::getSingleton().createWindow("MenuWidgets/StaticImage", "AbsoluteRootWindow"); |
---|
| 156 | this->rootWindow_->setProperty("FrameEnabled", "False"); |
---|
| 157 | this->hudRootWindow_ = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "HUDRootWindow"); |
---|
| 158 | this->menuRootWindow_ = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "MenuRootWindow"); |
---|
| 159 | // And connect them |
---|
| 160 | CEGUI::System::getSingleton().setGUISheet(this->rootWindow_); |
---|
| 161 | this->rootWindow_->addChildWindow(this->hudRootWindow_); |
---|
| 162 | this->rootWindow_->addChildWindow(this->menuRootWindow_); |
---|
| 163 | |
---|
[6749] | 164 | // No background to start with (sets the alpha value to 0) |
---|
| 165 | this->setBackgroundImage(""); |
---|
| 166 | |
---|
[6746] | 167 | // Set up the sheet manager in the Lua framework |
---|
| 168 | this->luaState_->doFile("SheetManager.lua"); |
---|
[3338] | 169 | } |
---|
[1776] | 170 | |
---|
[3338] | 171 | /** |
---|
| 172 | @brief |
---|
[3339] | 173 | Basically shuts down CEGUI (member smart pointers) but first unloads our Tolua modules. |
---|
[3338] | 174 | */ |
---|
| 175 | GUIManager::~GUIManager() |
---|
| 176 | { |
---|
[1638] | 177 | } |
---|
| 178 | |
---|
[7801] | 179 | void GUIManager::setConfigValues(void) |
---|
| 180 | { |
---|
| 181 | SetConfigValue(guiScheme_, GUIManager::defaultScheme_) .description("Changes the current GUI scheme.") .callback(this, &GUIManager::changedGUIScheme); |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | void GUIManager::changedGUIScheme(void) |
---|
| 185 | { |
---|
[7873] | 186 | |
---|
[7801] | 187 | } |
---|
| 188 | |
---|
[2896] | 189 | /** |
---|
| 190 | @brief |
---|
| 191 | used to tick the GUI |
---|
| 192 | @param time |
---|
| 193 | clock which provides time value for the GUI System |
---|
| 194 | |
---|
| 195 | Ticking the GUI means updating it with a certain regularity. |
---|
| 196 | The elapsed time since the last call is given in the time value provided by the clock. |
---|
| 197 | This time value is then used to provide a fluent animation of the GUI. |
---|
| 198 | */ |
---|
[6417] | 199 | void GUIManager::preUpdate(const Clock& time) |
---|
[1638] | 200 | { |
---|
[2896] | 201 | assert(guiSystem_); |
---|
[6746] | 202 | this->protectedCall(boost::bind(&CEGUI::System::injectTimePulse, _1, time.getDeltaTime())); |
---|
[2896] | 203 | } |
---|
[1638] | 204 | |
---|
[2896] | 205 | /** |
---|
| 206 | @brief |
---|
| 207 | Tells the GUIManager which SceneManager to use |
---|
| 208 | @param camera |
---|
| 209 | The current camera on which the GUI should be displayed on. |
---|
| 210 | |
---|
| 211 | In fact the GUIManager needs the SceneManager and not the Camera to display the GUI. |
---|
| 212 | This means the GUI is not bound to a camera but rather to the SceneManager. |
---|
[3337] | 213 | Hiding the GUI when needed can therefore not be resolved by just NOT setting the current camera. |
---|
[2896] | 214 | */ |
---|
| 215 | void GUIManager::setCamera(Ogre::Camera* camera) |
---|
[1638] | 216 | { |
---|
[5929] | 217 | this->camera_ = camera; |
---|
[2927] | 218 | if (camera == NULL) |
---|
| 219 | this->guiRenderer_->setTargetSceneManager(0); |
---|
| 220 | else |
---|
| 221 | this->guiRenderer_->setTargetSceneManager(camera->getSceneManager()); |
---|
[2896] | 222 | } |
---|
| 223 | |
---|
| 224 | /** |
---|
| 225 | @brief |
---|
[3338] | 226 | Executes Lua code |
---|
| 227 | @param str |
---|
| 228 | reference to string object holding the Lua code which is to be executed |
---|
| 229 | */ |
---|
| 230 | void GUIManager::executeCode(const std::string& str) |
---|
| 231 | { |
---|
[5695] | 232 | this->luaState_->doString(str, rootFileInfo_); |
---|
[3338] | 233 | } |
---|
| 234 | |
---|
[6746] | 235 | /** Loads a GUI sheet by Lua script |
---|
| 236 | @param name |
---|
| 237 | The name of the GUI (like the script name, but without the extension) |
---|
| 238 | */ |
---|
| 239 | void GUIManager::loadGUI(const std::string& name) |
---|
| 240 | { |
---|
| 241 | this->executeCode("loadSheet(\"" + name + "\")"); |
---|
| 242 | } |
---|
| 243 | |
---|
[3338] | 244 | /** |
---|
| 245 | @brief |
---|
[2896] | 246 | Displays specified GUI on screen |
---|
| 247 | @param name |
---|
| 248 | The name of the GUI |
---|
[7401] | 249 | @param bHidePrevious |
---|
| 250 | If true all displayed GUIs on the stack, that are below this GUI are hidden. |
---|
[7403] | 251 | @param bNoInput |
---|
| 252 | If true the GUI is transparent to input. |
---|
[2896] | 253 | |
---|
| 254 | The function executes the Lua function with the same name in case the GUIManager is ready. |
---|
| 255 | */ |
---|
[7403] | 256 | /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious, bool bNoInput) |
---|
[2896] | 257 | { |
---|
[7403] | 258 | GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ")"); |
---|
[1638] | 259 | } |
---|
| 260 | |
---|
[6417] | 261 | /** |
---|
| 262 | @brief |
---|
| 263 | Hack-ish. Needed for GUIOverlay. |
---|
| 264 | */ |
---|
[7403] | 265 | void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious, bool bNoInput) |
---|
[6417] | 266 | { |
---|
[7403] | 267 | this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ", " + ptr + ")"); |
---|
[6417] | 268 | } |
---|
| 269 | |
---|
| 270 | /** |
---|
| 271 | @brief |
---|
| 272 | Hides specified GUI. |
---|
| 273 | @param name |
---|
| 274 | The name of the GUI. |
---|
| 275 | */ |
---|
| 276 | /*static*/ void GUIManager::hideGUI(const std::string& name) |
---|
| 277 | { |
---|
[6746] | 278 | GUIManager::getInstance().executeCode("hideMenuSheet(\"" + name + "\")"); |
---|
[6417] | 279 | } |
---|
| 280 | |
---|
[6746] | 281 | const std::string& GUIManager::createInputState(const std::string& name, TriBool::Value showCursor, TriBool::Value useKeyboard, bool bBlockJoyStick) |
---|
| 282 | { |
---|
| 283 | InputState* state = InputManager::getInstance().createInputState(name); |
---|
[7811] | 284 | if (!state) |
---|
| 285 | return BLANKSTRING; |
---|
[6746] | 286 | |
---|
| 287 | /* Table that maps isFullScreen() and showCursor to mouseExclusive |
---|
| 288 | isFullscreen / showCursor | True | False | Dontcare |
---|
| 289 | ---------------------------------------------------- |
---|
| 290 | true | True | True | Dontcare |
---|
| 291 | ---------------------------------------------------- |
---|
| 292 | false | False | True | Dontcare |
---|
| 293 | */ |
---|
| 294 | if (showCursor == TriBool::Dontcare) |
---|
| 295 | state->setMouseExclusive(TriBool::Dontcare); |
---|
| 296 | else if (GraphicsManager::getInstance().isFullScreen() || showCursor == TriBool::False) |
---|
| 297 | state->setMouseExclusive(TriBool::True); |
---|
| 298 | else |
---|
| 299 | state->setMouseExclusive(TriBool::False); |
---|
| 300 | |
---|
| 301 | if (showCursor == TriBool::True) |
---|
| 302 | state->setMouseHandler(this); |
---|
| 303 | else if (showCursor == TriBool::False) |
---|
| 304 | state->setMouseHandler(&InputHandler::EMPTY); |
---|
| 305 | |
---|
| 306 | if (useKeyboard == TriBool::True) |
---|
| 307 | state->setKeyHandler(this); |
---|
| 308 | else if (useKeyboard == TriBool::False) |
---|
| 309 | state->setKeyHandler(&InputHandler::EMPTY); |
---|
| 310 | |
---|
| 311 | if (bBlockJoyStick) |
---|
| 312 | state->setJoyStickHandler(&InputHandler::EMPTY); |
---|
| 313 | |
---|
| 314 | return state->getName(); |
---|
| 315 | } |
---|
| 316 | |
---|
[6417] | 317 | void GUIManager::keyESC() |
---|
| 318 | { |
---|
| 319 | this->executeCode("keyESC()"); |
---|
| 320 | } |
---|
| 321 | |
---|
[6746] | 322 | void GUIManager::setBackgroundImage(const std::string& imageSet, const std::string imageName) |
---|
[6417] | 323 | { |
---|
[6746] | 324 | if (imageSet.empty() || imageName.empty()) |
---|
| 325 | this->setBackgroundImage(""); |
---|
| 326 | else |
---|
| 327 | this->setBackgroundImage("set: " + imageSet + " image: " + imageName); |
---|
[6417] | 328 | } |
---|
| 329 | |
---|
[6746] | 330 | void GUIManager::setBackgroundImage(const std::string& image) |
---|
| 331 | { |
---|
| 332 | if (image.empty()) |
---|
| 333 | this->rootWindow_->setProperty("Alpha", "0.0"); |
---|
| 334 | else |
---|
| 335 | this->rootWindow_->setProperty("Alpha", "1.0"); |
---|
| 336 | this->rootWindow_->setProperty("Image", image); |
---|
| 337 | } |
---|
| 338 | |
---|
[7163] | 339 | void GUIManager::buttonPressed(const KeyEvent& evt) |
---|
[3196] | 340 | { |
---|
[6746] | 341 | this->protectedCall(boost::bind(&CEGUI::System::injectKeyDown, _1, evt.getKeyCode())); |
---|
| 342 | this->protectedCall(boost::bind(&CEGUI::System::injectChar, _1, evt.getText())); |
---|
[3196] | 343 | } |
---|
[6746] | 344 | |
---|
[7163] | 345 | void GUIManager::buttonReleased(const KeyEvent& evt) |
---|
[3196] | 346 | { |
---|
[6746] | 347 | this->protectedCall(boost::bind(&CEGUI::System::injectKeyUp, _1, evt.getKeyCode())); |
---|
[3196] | 348 | } |
---|
| 349 | |
---|
[2896] | 350 | /** |
---|
| 351 | @brief |
---|
| 352 | Function receiving a mouse button pressed event. |
---|
| 353 | @param id |
---|
| 354 | ID of the mouse button which got pressed |
---|
[1638] | 355 | |
---|
[2896] | 356 | This function is inherited by MouseHandler and injects the event into CEGUI. |
---|
| 357 | It is for CEGUI to process the event. |
---|
| 358 | */ |
---|
[3327] | 359 | void GUIManager::buttonPressed(MouseButtonCode::ByEnum id) |
---|
[1638] | 360 | { |
---|
[6746] | 361 | this->protectedCall(boost::bind(&CEGUI::System::injectMouseButtonDown, _1, convertButton(id))); |
---|
[1638] | 362 | } |
---|
| 363 | |
---|
[2896] | 364 | /** |
---|
| 365 | @brief |
---|
| 366 | Function receiving a mouse button released event. |
---|
| 367 | @param id |
---|
| 368 | ID of the mouse button which got released |
---|
| 369 | |
---|
| 370 | This function is inherited by MouseHandler and injects the event into CEGUI. |
---|
| 371 | It is for CEGUI to process the event. |
---|
| 372 | */ |
---|
[3327] | 373 | void GUIManager::buttonReleased(MouseButtonCode::ByEnum id) |
---|
[1638] | 374 | { |
---|
[6746] | 375 | this->protectedCall(boost::bind(&CEGUI::System::injectMouseButtonUp, _1, convertButton(id))); |
---|
[1638] | 376 | } |
---|
| 377 | |
---|
[3196] | 378 | void GUIManager::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) |
---|
| 379 | { |
---|
[6746] | 380 | this->protectedCall(boost::bind(&CEGUI::System::injectMousePosition, _1, (float)abs.x, (float)abs.y)); |
---|
[3196] | 381 | } |
---|
[6746] | 382 | |
---|
[3196] | 383 | void GUIManager::mouseScrolled(int abs, int rel) |
---|
| 384 | { |
---|
[6746] | 385 | this->protectedCall(boost::bind(&CEGUI::System::injectMouseWheelChange, _1, (float)rel)); |
---|
[3196] | 386 | } |
---|
| 387 | |
---|
[2896] | 388 | /** |
---|
[7874] | 389 | @brief Indicates that the mouse left the application's window. |
---|
| 390 | */ |
---|
| 391 | void GUIManager::mouseLeft() |
---|
| 392 | { |
---|
| 393 | this->protectedCall(boost::bind(&CEGUI::System::injectMouseLeaves, _1)); |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | /** |
---|
[2896] | 397 | @brief |
---|
| 398 | converts mouse event code to CEGUI event code |
---|
| 399 | @param button |
---|
| 400 | code of the mouse button as we use it in Orxonox |
---|
| 401 | @return |
---|
| 402 | code of the mouse button as it is used by CEGUI |
---|
[1638] | 403 | |
---|
[6105] | 404 | Simple conversion from mouse event code in Orxonox to the one used in CEGUI. |
---|
[2896] | 405 | */ |
---|
[3196] | 406 | static inline CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button) |
---|
[1638] | 407 | { |
---|
| 408 | switch (button) |
---|
| 409 | { |
---|
[1887] | 410 | case MouseButtonCode::Left: |
---|
[1638] | 411 | return CEGUI::LeftButton; |
---|
| 412 | |
---|
[1887] | 413 | case MouseButtonCode::Right: |
---|
[1638] | 414 | return CEGUI::RightButton; |
---|
| 415 | |
---|
[1887] | 416 | case MouseButtonCode::Middle: |
---|
[1638] | 417 | return CEGUI::MiddleButton; |
---|
| 418 | |
---|
[1887] | 419 | case MouseButtonCode::Button3: |
---|
[1638] | 420 | return CEGUI::X1Button; |
---|
| 421 | |
---|
[1887] | 422 | case MouseButtonCode::Button4: |
---|
[1638] | 423 | return CEGUI::X2Button; |
---|
| 424 | |
---|
| 425 | default: |
---|
| 426 | return CEGUI::NoButton; |
---|
| 427 | } |
---|
| 428 | } |
---|
[6417] | 429 | |
---|
[6746] | 430 | /** Executes a CEGUI function normally, but catches CEGUI::ScriptException. |
---|
| 431 | When a ScriptException occurs, the error message will be displayed and |
---|
| 432 | the program carries on. |
---|
| 433 | @remarks |
---|
| 434 | The exception behaviour may pose problems if the code is not written |
---|
| 435 | exception-safe (and you can forget about that in Lua). The program might |
---|
| 436 | be left in an undefined state. But otherwise one script error would |
---|
| 437 | terminate the whole program... |
---|
| 438 | @note |
---|
| 439 | Your life gets easier if you use boost::bind to create the object/function. |
---|
| 440 | @param function |
---|
| 441 | Any callable object/function that takes this->guiSystem_ as its only parameter. |
---|
| 442 | @return |
---|
| 443 | True if input was handled, false otherwise. A caught exception yields true. |
---|
| 444 | */ |
---|
| 445 | template <typename FunctionType> |
---|
| 446 | bool GUIManager::protectedCall(FunctionType function) |
---|
| 447 | { |
---|
| 448 | try |
---|
| 449 | { |
---|
| 450 | return function(this->guiSystem_); |
---|
| 451 | } |
---|
| 452 | catch (CEGUI::ScriptException& ex) |
---|
| 453 | { |
---|
| 454 | // Display the error and proceed. See @remarks why this can be dangerous. |
---|
| 455 | COUT(1) << ex.getMessage() << std::endl; |
---|
| 456 | return true; |
---|
| 457 | } |
---|
| 458 | } |
---|
| 459 | |
---|
[7648] | 460 | /** |
---|
| 461 | @brief |
---|
| 462 | Subscribe the input function to the input event for the input window. |
---|
| 463 | This is a helper to be used in lua, because subscribeScriptedEvent() doesn't work in lua. |
---|
| 464 | @param window |
---|
| 465 | The window for which the event is subscribed. |
---|
| 466 | @param event |
---|
| 467 | The type of event to which we subscribe. |
---|
| 468 | @param function |
---|
| 469 | The function that is called when the event occurs. |
---|
| 470 | */ |
---|
[6417] | 471 | void GUIManager::subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function) |
---|
| 472 | { |
---|
| 473 | window->subscribeScriptedEvent(event, function); |
---|
| 474 | } |
---|
[7648] | 475 | |
---|
| 476 | /** |
---|
| 477 | @brief |
---|
| 478 | Set the input tooltip text for the input ListboxItem. |
---|
| 479 | @param item |
---|
| 480 | The ListboxItem for which the tooltip should be set. |
---|
| 481 | @param tooltip |
---|
| 482 | The tooltip text that should be set. |
---|
| 483 | */ |
---|
| 484 | void GUIManager::setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& tooltip) |
---|
| 485 | { |
---|
| 486 | item->setTooltipText(tooltip); |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | /** |
---|
| 490 | @brief |
---|
| 491 | Set whether the tooltips for the input Listbox are enabled. |
---|
| 492 | @param listbox |
---|
| 493 | The Listbox for which to enable (or disable) tooltips. |
---|
| 494 | @param enabled |
---|
| 495 | Whether to enable or disabel the tooltips. |
---|
| 496 | */ |
---|
| 497 | void GUIManager::setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled) |
---|
| 498 | { |
---|
| 499 | listbox->setItemTooltipsEnabled(enabled); |
---|
| 500 | } |
---|
| 501 | |
---|
[7873] | 502 | /** |
---|
| 503 | @brief Callback of window event listener, called if the window is resized. Sets the display size of CEGUI. |
---|
| 504 | */ |
---|
| 505 | void GUIManager::windowResized(unsigned int newWidth, unsigned int newHeight) |
---|
| 506 | { |
---|
| 507 | this->guiRenderer_->setDisplaySize(CEGUI::Size(newWidth, newHeight)); |
---|
| 508 | } |
---|
[7874] | 509 | |
---|
| 510 | /** |
---|
| 511 | @brief Notify CEGUI if the windows loses the focus (stops higlight of menu items, etc). |
---|
| 512 | */ |
---|
| 513 | void GUIManager::windowFocusChanged(bool bFocus) |
---|
| 514 | { |
---|
| 515 | if (!bFocus) |
---|
| 516 | this->mouseLeft(); |
---|
| 517 | } |
---|
[7876] | 518 | |
---|
[1638] | 519 | } |
---|