[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 | |
---|
[8467] | 32 | #include <fstream> |
---|
[8351] | 33 | #include <memory> |
---|
[11071] | 34 | #include <functional> |
---|
[8351] | 35 | #include <OgreRenderQueue.h> |
---|
| 36 | #include <OgreRenderWindow.h> |
---|
[8079] | 37 | |
---|
[11052] | 38 | extern "C" { |
---|
| 39 | #include <lua.h> |
---|
| 40 | } |
---|
| 41 | |
---|
[9675] | 42 | #if CEGUI_VERSION >= 0x000800 |
---|
| 43 | # include <CEGUI/DefaultLogger.h> |
---|
| 44 | # include <CEGUI/Exceptions.h> |
---|
| 45 | # include <CEGUI/FontManager.h> |
---|
| 46 | # include <CEGUI/InputEvent.h> |
---|
| 47 | # include <CEGUI/MouseCursor.h> |
---|
| 48 | # include <CEGUI/ResourceProvider.h> |
---|
| 49 | # include <CEGUI/System.h> |
---|
| 50 | # include <CEGUI/Window.h> |
---|
| 51 | # include <CEGUI/WindowManager.h> |
---|
| 52 | # include <CEGUI/XMLAttributes.h> |
---|
| 53 | # include <CEGUI/widgets/Listbox.h> |
---|
| 54 | # include <CEGUI/widgets/ListboxItem.h> |
---|
| 55 | #else |
---|
| 56 | # include <CEGUIDefaultLogger.h> |
---|
| 57 | # include <CEGUIExceptions.h> |
---|
| 58 | # include <CEGUIFontManager.h> |
---|
| 59 | # include <CEGUIInputEvent.h> |
---|
| 60 | # include <CEGUIMouseCursor.h> |
---|
| 61 | # include <CEGUIResourceProvider.h> |
---|
| 62 | # include <CEGUISystem.h> |
---|
| 63 | # include <CEGUIWindow.h> |
---|
| 64 | # include <CEGUIWindowManager.h> |
---|
| 65 | # include <CEGUIXMLAttributes.h> |
---|
| 66 | # include <elements/CEGUIListbox.h> |
---|
| 67 | # include <elements/CEGUIListboxItem.h> |
---|
| 68 | #endif |
---|
[3196] | 69 | |
---|
[8351] | 70 | #ifdef ORXONOX_OLD_CEGUI |
---|
[9675] | 71 | # include <CEGUILua.h> |
---|
| 72 | # include <ogreceguirenderer/OgreCEGUIRenderer.h> |
---|
[8351] | 73 | extern "C" { |
---|
[9675] | 74 | # include <lauxlib.h> |
---|
[8351] | 75 | } |
---|
[2710] | 76 | #else |
---|
[9675] | 77 | # if CEGUI_VERSION >= 0x000800 |
---|
| 78 | # include <CEGUI/ScriptModules/Lua/ScriptModule.h> |
---|
| 79 | # include <CEGUI/RendererModules/Ogre/ImageCodec.h> |
---|
| 80 | # include <CEGUI/RendererModules/Ogre/Renderer.h> |
---|
| 81 | # include <CEGUI/RendererModules/Ogre/ResourceProvider.h> |
---|
| 82 | # else |
---|
| 83 | # include <ScriptingModules/LuaScriptModule/CEGUILua.h> |
---|
| 84 | # include <RendererModules/Ogre/CEGUIOgreImageCodec.h> |
---|
| 85 | # include <RendererModules/Ogre/CEGUIOgreRenderer.h> |
---|
| 86 | # include <RendererModules/Ogre/CEGUIOgreResourceProvider.h> |
---|
| 87 | # endif |
---|
| 88 | # include <OgreCamera.h> |
---|
| 89 | # include <OgreRenderQueueListener.h> |
---|
| 90 | # include <OgreRenderSystem.h> |
---|
| 91 | # include <OgreRoot.h> |
---|
| 92 | # include <OgreSceneManager.h> |
---|
[2710] | 93 | #endif |
---|
| 94 | |
---|
[8527] | 95 | #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_COMPILER_MINGW) |
---|
[8467] | 96 | # include <windows.h> |
---|
| 97 | #endif |
---|
| 98 | |
---|
[5929] | 99 | #include "util/Clock.h" |
---|
[6417] | 100 | #include "util/Convert.h" |
---|
[8858] | 101 | #include "util/Output.h" |
---|
[1764] | 102 | #include "util/Exception.h" |
---|
[8530] | 103 | #include "util/Math.h" |
---|
[3280] | 104 | #include "util/OrxAssert.h" |
---|
[8858] | 105 | #include "util/output/BaseWriter.h" |
---|
[9667] | 106 | #include "config/ConfigValueIncludes.h" |
---|
[6417] | 107 | #include "Core.h" |
---|
[7801] | 108 | #include "CoreIncludes.h" |
---|
[7876] | 109 | #include "Game.h" |
---|
[6746] | 110 | #include "GraphicsManager.h" |
---|
[5695] | 111 | #include "LuaState.h" |
---|
[10624] | 112 | #include "ConfigurablePaths.h" |
---|
[5695] | 113 | #include "Resource.h" |
---|
[10624] | 114 | #include "command/ConsoleCommandIncludes.h" |
---|
[6746] | 115 | #include "input/InputManager.h" |
---|
| 116 | #include "input/InputState.h" |
---|
| 117 | #include "input/KeyBinderManager.h" |
---|
[1638] | 118 | |
---|
| 119 | namespace orxonox |
---|
| 120 | { |
---|
[11071] | 121 | namespace arg = std::placeholders; |
---|
| 122 | |
---|
[6417] | 123 | static void key_esc() |
---|
| 124 | { GUIManager::getInstance().keyESC(); } |
---|
[7284] | 125 | SetConsoleCommand("keyESC", &key_esc); |
---|
[6417] | 126 | |
---|
[3280] | 127 | class CEGUILogger : public CEGUI::DefaultLogger |
---|
| 128 | { |
---|
| 129 | public: |
---|
[11071] | 130 | virtual void logEvent(const CEGUI::String& message, CEGUI::LoggingLevel level = CEGUI::Standard) override |
---|
[3280] | 131 | { |
---|
[8858] | 132 | OutputLevel orxonoxLevel = level::debug_output; |
---|
[3280] | 133 | switch (level) |
---|
| 134 | { |
---|
[8858] | 135 | case CEGUI::Errors: orxonoxLevel = level::internal_error; break; |
---|
| 136 | case CEGUI::Warnings: orxonoxLevel = level::internal_warning; break; |
---|
| 137 | case CEGUI::Standard: orxonoxLevel = level::verbose; break; |
---|
| 138 | case CEGUI::Informative: orxonoxLevel = level::verbose_more; break; |
---|
| 139 | case CEGUI::Insane: orxonoxLevel = level::verbose_ultra; break; |
---|
[8351] | 140 | default: OrxAssert(false, "CEGUI log level out of range, inspect immediately!"); |
---|
[3280] | 141 | } |
---|
| 142 | |
---|
[8858] | 143 | orxout(orxonoxLevel, context::cegui) << message << endl; |
---|
| 144 | |
---|
[3280] | 145 | CEGUI::DefaultLogger::logEvent(message, level); |
---|
| 146 | } |
---|
[8467] | 147 | |
---|
| 148 | /// Carbon copy from CEGUIDefaultLogger.cpp with a bugfix for Windows |
---|
[11071] | 149 | virtual void setLogFilename(const CEGUI::String& filename, bool append = false) override |
---|
[8467] | 150 | { |
---|
| 151 | // Close current log file (if any) |
---|
| 152 | if (d_ostream.is_open()) |
---|
| 153 | d_ostream.close(); |
---|
| 154 | |
---|
[8527] | 155 | #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_COMPILER_MINGW) |
---|
[8467] | 156 | // filename.c_str() is UTF-8 encoded, but Windows expects characters |
---|
| 157 | // according to the current codepage or UTF-16 (wchar) |
---|
| 158 | d_ostream.open(utf8ToUtf16(filename.c_str()).c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc)); |
---|
| 159 | #else |
---|
| 160 | d_ostream.open(filename.c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc)); |
---|
| 161 | #endif |
---|
| 162 | if (!d_ostream) |
---|
| 163 | ThrowException(General, "Setting the CEGUI log filename failed"); |
---|
| 164 | |
---|
| 165 | // Initialise width for date & time alignment. |
---|
| 166 | d_ostream.width(2); |
---|
| 167 | |
---|
| 168 | // Write out cached log strings. |
---|
| 169 | if (d_caching) |
---|
| 170 | { |
---|
| 171 | d_caching = false; |
---|
| 172 | |
---|
[11071] | 173 | std::vector<std::pair<CEGUI::String, CEGUI::LoggingLevel>>::iterator it = d_cache.begin(); |
---|
[8467] | 174 | |
---|
| 175 | while (it != d_cache.end()) |
---|
| 176 | { |
---|
| 177 | if (d_level >= it->second) |
---|
| 178 | { |
---|
| 179 | d_ostream << it->first; |
---|
| 180 | // Ensure new event is written to the file, rather than just being buffered. |
---|
| 181 | d_ostream.flush(); |
---|
| 182 | } |
---|
| 183 | ++it; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | d_cache.clear(); |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | |
---|
[8527] | 190 | #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_COMPILER_MINGW) |
---|
[8467] | 191 | /// Converts a UTF-8 character sequence to Windows UTF-16 |
---|
| 192 | static std::wstring utf8ToUtf16(const std::string& utf8text) |
---|
| 193 | { |
---|
| 194 | const int textLen = MultiByteToWideChar(CP_UTF8, 0, utf8text.c_str(), |
---|
| 195 | utf8text.size() + 1, 0, 0); |
---|
| 196 | |
---|
| 197 | if (textLen == 0) |
---|
| 198 | ThrowException(General, "Utf8ToUtf16 - MultiByteToWideChar failed"); |
---|
| 199 | |
---|
| 200 | std::wstring wideStr(textLen, 0); |
---|
| 201 | MultiByteToWideChar(CP_UTF8, 0, utf8text.c_str(), utf8text.size() + 1, |
---|
| 202 | &wideStr[0], wideStr.size()); |
---|
| 203 | return wideStr; |
---|
| 204 | } |
---|
| 205 | #endif |
---|
[3280] | 206 | }; |
---|
| 207 | |
---|
[8351] | 208 | #ifdef ORXONOX_OLD_CEGUI |
---|
| 209 | /** Class with the same memory layout as CEGUI::LuaScriptModule. <br> |
---|
| 210 | We need this to fix a problem with an uninitialised member variable |
---|
| 211 | in CEGUI < 0.7 <br> |
---|
| 212 | Notice the "public" modifier for the otherwise private variables. |
---|
| 213 | */ |
---|
| 214 | class LuaScriptModuleWorkaround : public CEGUI::ScriptModule |
---|
| 215 | { |
---|
| 216 | public: |
---|
| 217 | LuaScriptModuleWorkaround(); |
---|
| 218 | ~LuaScriptModuleWorkaround(); |
---|
| 219 | |
---|
| 220 | public: |
---|
| 221 | bool d_ownsState; |
---|
| 222 | lua_State* d_state; |
---|
| 223 | CEGUI::String d_errFuncName; |
---|
| 224 | int d_errFuncIndex; |
---|
| 225 | CEGUI::String d_activeErrFuncName; |
---|
| 226 | int d_activeErrFuncIndex; |
---|
| 227 | }; |
---|
| 228 | #else |
---|
| 229 | /// RenderQueueListener based class used to hook into the ogre rendering system |
---|
| 230 | class RQListener : public Ogre::RenderQueueListener |
---|
| 231 | { |
---|
| 232 | public: |
---|
| 233 | /// Callback from Ogre invoked before other stuff in our target queue is rendered |
---|
[11071] | 234 | virtual void renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation, bool& skipThisQueue) override |
---|
[8351] | 235 | { |
---|
[8419] | 236 | if (id == Ogre::RENDER_QUEUE_OVERLAY && invocation.empty()) |
---|
[8439] | 237 | { |
---|
[9675] | 238 | #if CEGUI_VERSION >= 0x000800 |
---|
| 239 | CEGUI::System::getSingleton().renderAllGUIContexts(); |
---|
| 240 | #else |
---|
[8351] | 241 | CEGUI::System::getSingleton().renderGUI(); |
---|
[9675] | 242 | #endif |
---|
[8439] | 243 | |
---|
| 244 | // Important workaround! (at least required by CEGUI 0.7.5) |
---|
| 245 | // If we don't reset the scissor test, OGRE will only render overlays |
---|
| 246 | // in the area where CEGUI last drew, which is usually nothing |
---|
| 247 | // or a little box where the focused element is. |
---|
| 248 | Ogre::Root::getSingleton().getRenderSystem()->setScissorTest(false); |
---|
| 249 | } |
---|
[8351] | 250 | } |
---|
| 251 | }; |
---|
| 252 | #endif |
---|
| 253 | |
---|
[3196] | 254 | static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button); |
---|
[3339] | 255 | |
---|
[11071] | 256 | GUIManager* GUIManager::singletonPtr_s = nullptr; |
---|
[9016] | 257 | /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen"; //Alternative: Orxonox (not fully complete yet, see the graphics menu) |
---|
[1646] | 258 | |
---|
[11052] | 259 | namespace autocompletion |
---|
| 260 | { |
---|
| 261 | /** |
---|
| 262 | @brief Returns the names of all currently existing OverlayGroups. |
---|
| 263 | */ |
---|
| 264 | ARGUMENT_COMPLETION_FUNCTION_DECLARATION(guinames)(); |
---|
| 265 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(guinames)() |
---|
| 266 | { |
---|
| 267 | ArgumentCompletionList names; |
---|
| 268 | const std::vector<std::string> guis = GUIManager::getInstance().getLoadedGUIs(); |
---|
[11071] | 269 | for (const std::string gui : guis) |
---|
| 270 | names.push_back(ArgumentCompletionListElement(gui, getLowercase(gui))); |
---|
[11052] | 271 | return names; |
---|
| 272 | } |
---|
| 273 | } |
---|
[6417] | 274 | |
---|
[11052] | 275 | SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false) |
---|
| 276 | .argumentCompleter(0, autocompletion::guinames()); |
---|
| 277 | SetConsoleCommand("hideGUI", &GUIManager::hideGUI) |
---|
| 278 | .argumentCompleter(0, autocompletion::guinames()); |
---|
| 279 | SetConsoleCommand("toggleGUI", &GUIManager::toggleGUI).defaultValue(1, false).defaultValue(2, false) |
---|
| 280 | .argumentCompleter(0, autocompletion::guinames()); |
---|
| 281 | |
---|
[10624] | 282 | RegisterAbstractClass(GUIManager).inheritsFrom<WindowEventListener>(); |
---|
| 283 | |
---|
[2896] | 284 | /** |
---|
| 285 | @brief |
---|
[3338] | 286 | Constructs the GUIManager by starting up CEGUI |
---|
[2896] | 287 | |
---|
| 288 | Creates the interface to Ogre, sets up the CEGUI renderer and the Lua script module together with the Lua engine. |
---|
| 289 | The log is set up and connected to the CEGUILogger. |
---|
| 290 | After Lua setup tolua++-elements are linked to Lua-state to give Lua access to C++-code. |
---|
| 291 | Finally initial Lua code is executed (maybe we can do this with the CEGUI startup script automatically). |
---|
[3338] | 292 | @return true if success, otherwise false |
---|
[2896] | 293 | */ |
---|
[6746] | 294 | GUIManager::GUIManager(const std::pair<int, int>& mousePosition) |
---|
[11071] | 295 | : guiRenderer_(nullptr) |
---|
| 296 | , resourceProvider_(nullptr) |
---|
[8351] | 297 | #ifndef ORXONOX_OLD_CEGUI |
---|
[11071] | 298 | , rqListener_(nullptr) |
---|
| 299 | , imageCodec_(nullptr) |
---|
[8351] | 300 | #endif |
---|
[11071] | 301 | , luaState_(nullptr) |
---|
| 302 | , scriptModule_(nullptr) |
---|
| 303 | , guiSystem_(nullptr) |
---|
| 304 | , ceguiLogger_(nullptr) |
---|
| 305 | , rootWindow_(nullptr) |
---|
| 306 | , hudRootWindow_(nullptr) |
---|
| 307 | , menuRootWindow_(nullptr) |
---|
| 308 | , camera_(nullptr) |
---|
[8423] | 309 | , destructionHelper_(this) |
---|
[1638] | 310 | { |
---|
[9667] | 311 | RegisterObject(GUIManager); |
---|
[8858] | 312 | |
---|
| 313 | orxout(internal_status) << "initializing GUIManager..." << endl; |
---|
| 314 | |
---|
[7801] | 315 | this->setConfigValues(); |
---|
| 316 | |
---|
[1638] | 317 | using namespace CEGUI; |
---|
| 318 | |
---|
[8858] | 319 | orxout(internal_info) << "Initialising CEGUI." << endl; |
---|
[1638] | 320 | |
---|
[8706] | 321 | this->oldCEGUI_ = false; |
---|
[8858] | 322 | |
---|
[5695] | 323 | // Note: No SceneManager specified yet |
---|
[8351] | 324 | #ifdef ORXONOX_OLD_CEGUI |
---|
| 325 | guiRenderer_ = new OgreCEGUIRenderer(GraphicsManager::getInstance().getRenderWindow(), Ogre::RENDER_QUEUE_OVERLAY, false, 3000); |
---|
[5695] | 326 | resourceProvider_ = guiRenderer_->createResourceProvider(); |
---|
[8706] | 327 | this->oldCEGUI_ = true; |
---|
[8351] | 328 | #else |
---|
| 329 | guiRenderer_ = &OgreRenderer::create(*GraphicsManager::getInstance().getRenderWindow()); |
---|
| 330 | // We use our own RenderQueueListener so we can draw UNDER overlays |
---|
| 331 | guiRenderer_->setFrameControlExecutionEnabled(false); |
---|
| 332 | rqListener_ = new RQListener(); |
---|
| 333 | resourceProvider_ = &OgreRenderer::createOgreResourceProvider(); |
---|
| 334 | imageCodec_ = &OgreRenderer::createOgreImageCodec(); |
---|
| 335 | #endif |
---|
[7709] | 336 | resourceProvider_->setDefaultResourceGroup("General"); |
---|
[1776] | 337 | |
---|
[6749] | 338 | // Setup scripting |
---|
[8351] | 339 | luaState_ = new LuaState(); |
---|
[6417] | 340 | rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua"); |
---|
| 341 | // This is necessary to ensure that input events also use the right resource info when triggering lua functions |
---|
| 342 | luaState_->setDefaultResourceInfo(this->rootFileInfo_); |
---|
[8351] | 343 | #ifdef ORXONOX_OLD_CEGUI |
---|
| 344 | scriptModule_ = new LuaScriptModule(luaState_->getInternalLuaState()); |
---|
| 345 | // Ugly workaround: older CEGUILua versions don't initialise the member |
---|
| 346 | // d_activeErrFuncIndex at all. That leads to "error in error handling" |
---|
| 347 | // problems when a Lua error occurs. |
---|
| 348 | // We fix this by setting the member manually. |
---|
| 349 | reinterpret_cast<LuaScriptModuleWorkaround*>(scriptModule_)->d_activeErrFuncIndex = LUA_NOREF; |
---|
| 350 | luaState_->doString("ORXONOX_OLD_CEGUI = true"); |
---|
| 351 | #else |
---|
| 352 | scriptModule_ = &LuaScriptModule::create(luaState_->getInternalLuaState()); |
---|
| 353 | #endif |
---|
[6763] | 354 | scriptModule_->setDefaultPCallErrorHandler(LuaState::ERROR_HANDLER_NAME); |
---|
[1638] | 355 | |
---|
[5695] | 356 | // Create our own logger to specify the filepath |
---|
[11071] | 357 | std::unique_ptr<CEGUILogger> ceguiLogger(new CEGUILogger()); |
---|
[10624] | 358 | ceguiLogger->setLogFilename(ConfigurablePaths::getLogPathString() + "cegui.log"); |
---|
[8858] | 359 | ceguiLogger->setLoggingLevel(static_cast<CEGUI::LoggingLevel>(this->outputLevelCeguiLog_)); |
---|
[5695] | 360 | this->ceguiLogger_ = ceguiLogger.release(); |
---|
[2710] | 361 | |
---|
[6749] | 362 | // Create the CEGUI system singleton |
---|
[8351] | 363 | #ifdef ORXONOX_OLD_CEGUI |
---|
[11071] | 364 | guiSystem_ = new System(guiRenderer_, resourceProvider_, nullptr, scriptModule_); |
---|
[8351] | 365 | // Add functions that have been renamed in newer versions |
---|
| 366 | luaState_->doString("CEGUI.SchemeManager.create = CEGUI.SchemeManager.loadScheme"); |
---|
| 367 | luaState_->doString("CEGUI.Window.getUnclippedOuterRect = CEGUI.Window.getUnclippedPixelRect"); |
---|
[9050] | 368 | luaState_->doString("CEGUI.ImagesetManager.createFromImageFile= CEGUI.ImagesetManager.createImagesetFromImageFile"); |
---|
[8351] | 369 | #else |
---|
[11071] | 370 | guiSystem_ = &System::create(*guiRenderer_, resourceProvider_, nullptr, imageCodec_, scriptModule_); |
---|
[8351] | 371 | #endif |
---|
[1776] | 372 | |
---|
[9576] | 373 | CEGUI::String defaultXMLParserName = CEGUI::System::getSingleton().getDefaultXMLParserName(); |
---|
| 374 | try |
---|
| 375 | { |
---|
| 376 | // Force Xerces parser (CEGUI 0.7.5+) |
---|
| 377 | CEGUI::System::getSingleton().setXMLParser("XercesParser"); |
---|
| 378 | } |
---|
[9759] | 379 | catch (const CEGUI::GenericException&) |
---|
[9576] | 380 | { |
---|
| 381 | // Fall back to default parser |
---|
| 382 | orxout(internal_warning) << "Cannot use XercesParser for CEGUI - using " << defaultXMLParserName << " instead" << endl; |
---|
| 383 | CEGUI::System::getSingleton().setXMLParser(defaultXMLParserName); |
---|
| 384 | } |
---|
[9575] | 385 | |
---|
[5695] | 386 | // Align CEGUI mouse with OIS mouse |
---|
[9675] | 387 | #if CEGUI_VERSION >= 0x000800 |
---|
| 388 | guiSystem_->getDefaultGUIContext().injectMousePosition((float)mousePosition.first, (float)mousePosition.second); |
---|
| 389 | #else |
---|
[6502] | 390 | guiSystem_->injectMousePosition((float)mousePosition.first, (float)mousePosition.second); |
---|
[9675] | 391 | #endif |
---|
[5695] | 392 | |
---|
[6746] | 393 | // Initialise the Lua framework and load the schemes |
---|
[8861] | 394 | orxout(user_info) << "Loading user interface..." << endl; |
---|
[6746] | 395 | this->luaState_->doFile("InitialiseGUI.lua"); |
---|
| 396 | |
---|
| 397 | // Create the root nodes |
---|
| 398 | this->rootWindow_ = CEGUI::WindowManager::getSingleton().createWindow("MenuWidgets/StaticImage", "AbsoluteRootWindow"); |
---|
| 399 | this->rootWindow_->setProperty("FrameEnabled", "False"); |
---|
| 400 | this->hudRootWindow_ = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "HUDRootWindow"); |
---|
| 401 | this->menuRootWindow_ = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "MenuRootWindow"); |
---|
| 402 | // And connect them |
---|
[9675] | 403 | #if CEGUI_VERSION >= 0x000800 |
---|
| 404 | CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(this->rootWindow_); |
---|
| 405 | this->rootWindow_->addChild(this->hudRootWindow_); |
---|
| 406 | this->rootWindow_->addChild(this->menuRootWindow_); |
---|
| 407 | #else |
---|
[6746] | 408 | CEGUI::System::getSingleton().setGUISheet(this->rootWindow_); |
---|
| 409 | this->rootWindow_->addChildWindow(this->hudRootWindow_); |
---|
| 410 | this->rootWindow_->addChildWindow(this->menuRootWindow_); |
---|
[9675] | 411 | #endif |
---|
[6746] | 412 | |
---|
[6749] | 413 | // No background to start with (sets the alpha value to 0) |
---|
| 414 | this->setBackgroundImage(""); |
---|
| 415 | |
---|
[6746] | 416 | // Set up the sheet manager in the Lua framework |
---|
| 417 | this->luaState_->doFile("SheetManager.lua"); |
---|
[8858] | 418 | |
---|
| 419 | orxout(internal_status) << "finished initializing GUIManager" << endl; |
---|
[3338] | 420 | } |
---|
[1776] | 421 | |
---|
[8423] | 422 | void GUIManager::destroy() |
---|
[3338] | 423 | { |
---|
[8858] | 424 | orxout(internal_status) << "destroying GUIManager..." << endl; |
---|
| 425 | |
---|
[8351] | 426 | using namespace CEGUI; |
---|
| 427 | |
---|
| 428 | #ifdef ORXONOX_OLD_CEGUI |
---|
[8423] | 429 | safeObjectDelete(&guiSystem_); |
---|
| 430 | safeObjectDelete(&guiRenderer_); |
---|
| 431 | safeObjectDelete(&scriptModule_); |
---|
[8351] | 432 | #else |
---|
| 433 | System::destroy(); |
---|
| 434 | OgreRenderer::destroyOgreResourceProvider(*resourceProvider_); |
---|
| 435 | OgreRenderer::destroyOgreImageCodec(*imageCodec_); |
---|
| 436 | OgreRenderer::destroy(*guiRenderer_); |
---|
| 437 | LuaScriptModule::destroy(*scriptModule_); |
---|
[8423] | 438 | safeObjectDelete(&ceguiLogger_); |
---|
| 439 | safeObjectDelete(&rqListener_); |
---|
[8351] | 440 | #endif |
---|
[8423] | 441 | safeObjectDelete(&luaState_); |
---|
[8858] | 442 | |
---|
| 443 | orxout(internal_status) << "finished destroying GUIManager" << endl; |
---|
[1638] | 444 | } |
---|
| 445 | |
---|
[7801] | 446 | void GUIManager::setConfigValues(void) |
---|
| 447 | { |
---|
[8858] | 448 | SetConfigValue(guiScheme_, GUIManager::defaultScheme_).description("Changes the current GUI scheme.").callback(this, &GUIManager::changedGUIScheme); |
---|
[8530] | 449 | SetConfigValue(numScrollLines_, 1).description("How many lines to scroll in a list if the scroll wheel is used"); |
---|
[8862] | 450 | SetConfigValue(bPreloadMenuSheets_, false).description("Pre-load menu sheets during startup"); |
---|
| 451 | |
---|
[8858] | 452 | SetConfigValueExternal(outputLevelCeguiLog_, BaseWriter::getConfigurableSectionName(), "outputLevelCeguiLog", CEGUI::Standard).description("The log level of the CEGUI log file").callback(this, &GUIManager::changedCeguiOutputLevel); |
---|
[7801] | 453 | } |
---|
| 454 | |
---|
| 455 | void GUIManager::changedGUIScheme(void) |
---|
| 456 | { |
---|
| 457 | } |
---|
| 458 | |
---|
[8858] | 459 | void GUIManager::changedCeguiOutputLevel() |
---|
| 460 | { |
---|
| 461 | if (this->ceguiLogger_) |
---|
| 462 | this->ceguiLogger_->setLoggingLevel(static_cast<CEGUI::LoggingLevel>(this->outputLevelCeguiLog_)); |
---|
| 463 | } |
---|
| 464 | |
---|
[2896] | 465 | /** |
---|
| 466 | @brief |
---|
| 467 | used to tick the GUI |
---|
| 468 | @param time |
---|
| 469 | clock which provides time value for the GUI System |
---|
| 470 | |
---|
| 471 | Ticking the GUI means updating it with a certain regularity. |
---|
| 472 | The elapsed time since the last call is given in the time value provided by the clock. |
---|
| 473 | This time value is then used to provide a fluent animation of the GUI. |
---|
| 474 | */ |
---|
[6417] | 475 | void GUIManager::preUpdate(const Clock& time) |
---|
[1638] | 476 | { |
---|
[2896] | 477 | assert(guiSystem_); |
---|
[11071] | 478 | this->protectedCeguiSystemCall(std::bind(&CEGUI::System::injectTimePulse, arg::_1, time.getDeltaTime())); |
---|
[2896] | 479 | } |
---|
[1638] | 480 | |
---|
[2896] | 481 | /** |
---|
| 482 | @brief |
---|
| 483 | Tells the GUIManager which SceneManager to use |
---|
| 484 | @param camera |
---|
| 485 | The current camera on which the GUI should be displayed on. |
---|
| 486 | |
---|
| 487 | In fact the GUIManager needs the SceneManager and not the Camera to display the GUI. |
---|
| 488 | This means the GUI is not bound to a camera but rather to the SceneManager. |
---|
[3337] | 489 | Hiding the GUI when needed can therefore not be resolved by just NOT setting the current camera. |
---|
[2896] | 490 | */ |
---|
| 491 | void GUIManager::setCamera(Ogre::Camera* camera) |
---|
[1638] | 492 | { |
---|
[8351] | 493 | #ifdef ORXONOX_OLD_CEGUI |
---|
[11071] | 494 | if (camera == nullptr) |
---|
| 495 | this->guiRenderer_->setTargetSceneManager(nullptr); |
---|
[2927] | 496 | else |
---|
| 497 | this->guiRenderer_->setTargetSceneManager(camera->getSceneManager()); |
---|
[8351] | 498 | #else |
---|
[11071] | 499 | if (camera_ != nullptr && camera_->getSceneManager() != nullptr) |
---|
[8351] | 500 | camera_->getSceneManager()->removeRenderQueueListener(rqListener_); |
---|
[11071] | 501 | if (camera != nullptr && camera->getSceneManager() != nullptr) |
---|
[8351] | 502 | camera->getSceneManager()->addRenderQueueListener(rqListener_); |
---|
| 503 | #endif |
---|
| 504 | this->camera_ = camera; |
---|
[2896] | 505 | } |
---|
| 506 | |
---|
| 507 | /** |
---|
| 508 | @brief |
---|
[3338] | 509 | Executes Lua code |
---|
| 510 | @param str |
---|
| 511 | reference to string object holding the Lua code which is to be executed |
---|
| 512 | */ |
---|
| 513 | void GUIManager::executeCode(const std::string& str) |
---|
| 514 | { |
---|
[5695] | 515 | this->luaState_->doString(str, rootFileInfo_); |
---|
[3338] | 516 | } |
---|
| 517 | |
---|
[11052] | 518 | std::vector<std::string> GUIManager::getLoadedGUIs() |
---|
| 519 | { |
---|
| 520 | // TODO: is there a better way to read back a return value from lua? i.e. by using LuaState? |
---|
| 521 | lua_State* L = this->luaState_->getInternalLuaState(); |
---|
| 522 | |
---|
| 523 | // push function |
---|
| 524 | lua_getglobal(L, "getLoadedSheets"); |
---|
| 525 | |
---|
| 526 | // do the call (0 arguments, 1 result) |
---|
| 527 | if (lua_pcall(L, 0, 1, 0) != 0) |
---|
| 528 | orxout(internal_error) << "error running function: " << lua_tostring(L, -1) << endl; |
---|
| 529 | |
---|
| 530 | // retrieve result |
---|
| 531 | if (!lua_isstring(L, -1)) |
---|
| 532 | orxout(internal_error) << "function must return a string" << endl; |
---|
| 533 | std::string value = lua_tostring(L, -1); |
---|
| 534 | lua_pop(L, 1); |
---|
| 535 | |
---|
| 536 | SubString tokens(value, ","); |
---|
| 537 | return tokens.getAllStrings(); |
---|
| 538 | } |
---|
| 539 | |
---|
[6746] | 540 | /** Loads a GUI sheet by Lua script |
---|
| 541 | @param name |
---|
| 542 | The name of the GUI (like the script name, but without the extension) |
---|
| 543 | */ |
---|
| 544 | void GUIManager::loadGUI(const std::string& name) |
---|
| 545 | { |
---|
| 546 | this->executeCode("loadSheet(\"" + name + "\")"); |
---|
| 547 | } |
---|
| 548 | |
---|
[3338] | 549 | /** |
---|
| 550 | @brief |
---|
[2896] | 551 | Displays specified GUI on screen |
---|
| 552 | @param name |
---|
| 553 | The name of the GUI |
---|
[7401] | 554 | @param bHidePrevious |
---|
| 555 | If true all displayed GUIs on the stack, that are below this GUI are hidden. |
---|
[7403] | 556 | @param bNoInput |
---|
| 557 | If true the GUI is transparent to input. |
---|
[2896] | 558 | |
---|
| 559 | The function executes the Lua function with the same name in case the GUIManager is ready. |
---|
| 560 | */ |
---|
[7403] | 561 | /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious, bool bNoInput) |
---|
[2896] | 562 | { |
---|
[7403] | 563 | GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ")"); |
---|
[1638] | 564 | } |
---|
| 565 | |
---|
[6417] | 566 | /** |
---|
| 567 | @brief |
---|
| 568 | Hack-ish. Needed for GUIOverlay. |
---|
| 569 | */ |
---|
[7403] | 570 | void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious, bool bNoInput) |
---|
[6417] | 571 | { |
---|
[7403] | 572 | this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ", " + ptr + ")"); |
---|
[6417] | 573 | } |
---|
| 574 | |
---|
| 575 | /** |
---|
| 576 | @brief |
---|
| 577 | Hides specified GUI. |
---|
| 578 | @param name |
---|
| 579 | The name of the GUI. |
---|
| 580 | */ |
---|
| 581 | /*static*/ void GUIManager::hideGUI(const std::string& name) |
---|
| 582 | { |
---|
[6746] | 583 | GUIManager::getInstance().executeCode("hideMenuSheet(\"" + name + "\")"); |
---|
[6417] | 584 | } |
---|
| 585 | |
---|
[8079] | 586 | /** |
---|
| 587 | @brief |
---|
| 588 | Toggles specified GUI. |
---|
| 589 | If the GUI with the input name is already shown and on the top, it is hidden, else it is shown. |
---|
| 590 | */ |
---|
| 591 | /*static*/ void GUIManager::toggleGUI(const std::string& name, bool bHidePrevious, bool bNoInput) |
---|
| 592 | { |
---|
| 593 | GUIManager::getInstance().executeCode("getGUIFirstActive(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ")"); |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | /** |
---|
| 597 | @brief |
---|
| 598 | Helper method to toggle a specified GUI. |
---|
| 599 | Is called by lua. |
---|
| 600 | */ |
---|
| 601 | void GUIManager::toggleGUIHelper(const std::string& name, bool bHidePrevious, bool bNoInput, bool show) |
---|
| 602 | { |
---|
| 603 | if(show) |
---|
| 604 | GUIManager::showGUI(name, bHidePrevious, bNoInput); |
---|
| 605 | else |
---|
| 606 | GUIManager::hideGUI(name); |
---|
| 607 | } |
---|
| 608 | |
---|
[8729] | 609 | const std::string& GUIManager::createInputState(const std::string& name, tribool showCursor, tribool useKeyboard, bool bBlockJoyStick) |
---|
[6746] | 610 | { |
---|
| 611 | InputState* state = InputManager::getInstance().createInputState(name); |
---|
[7811] | 612 | if (!state) |
---|
| 613 | return BLANKSTRING; |
---|
[6746] | 614 | |
---|
| 615 | /* Table that maps isFullScreen() and showCursor to mouseExclusive |
---|
| 616 | isFullscreen / showCursor | True | False | Dontcare |
---|
| 617 | ---------------------------------------------------- |
---|
| 618 | true | True | True | Dontcare |
---|
| 619 | ---------------------------------------------------- |
---|
| 620 | false | False | True | Dontcare |
---|
| 621 | */ |
---|
[8351] | 622 | |
---|
| 623 | #ifdef ORXONOX_PLATFORM_APPLE |
---|
| 624 | // There is no non exclusive mode on OS X yet |
---|
[8729] | 625 | state->setMouseExclusive(true); |
---|
[8351] | 626 | #else |
---|
[8729] | 627 | if (showCursor == dontcare) |
---|
| 628 | state->setMouseExclusive(dontcare); |
---|
| 629 | else if (GraphicsManager::getInstance().isFullScreen() || showCursor == false) |
---|
| 630 | state->setMouseExclusive(true); |
---|
[6746] | 631 | else |
---|
[8729] | 632 | state->setMouseExclusive(false); |
---|
[8351] | 633 | #endif |
---|
[6746] | 634 | |
---|
[8729] | 635 | if (showCursor == true) |
---|
[6746] | 636 | state->setMouseHandler(this); |
---|
[8729] | 637 | else if (showCursor == false) |
---|
[6746] | 638 | state->setMouseHandler(&InputHandler::EMPTY); |
---|
| 639 | |
---|
[8729] | 640 | if (useKeyboard == true) |
---|
[6746] | 641 | state->setKeyHandler(this); |
---|
[8729] | 642 | else if (useKeyboard == false) |
---|
[6746] | 643 | state->setKeyHandler(&InputHandler::EMPTY); |
---|
| 644 | |
---|
| 645 | if (bBlockJoyStick) |
---|
| 646 | state->setJoyStickHandler(&InputHandler::EMPTY); |
---|
| 647 | |
---|
| 648 | return state->getName(); |
---|
| 649 | } |
---|
| 650 | |
---|
[6417] | 651 | void GUIManager::keyESC() |
---|
| 652 | { |
---|
| 653 | this->executeCode("keyESC()"); |
---|
| 654 | } |
---|
| 655 | |
---|
[6746] | 656 | void GUIManager::setBackgroundImage(const std::string& imageSet, const std::string imageName) |
---|
[6417] | 657 | { |
---|
[6746] | 658 | if (imageSet.empty() || imageName.empty()) |
---|
| 659 | this->setBackgroundImage(""); |
---|
| 660 | else |
---|
| 661 | this->setBackgroundImage("set: " + imageSet + " image: " + imageName); |
---|
[6417] | 662 | } |
---|
| 663 | |
---|
[6746] | 664 | void GUIManager::setBackgroundImage(const std::string& image) |
---|
| 665 | { |
---|
| 666 | if (image.empty()) |
---|
| 667 | this->rootWindow_->setProperty("Alpha", "0.0"); |
---|
| 668 | else |
---|
| 669 | this->rootWindow_->setProperty("Alpha", "1.0"); |
---|
| 670 | this->rootWindow_->setProperty("Image", image); |
---|
| 671 | } |
---|
| 672 | |
---|
[7163] | 673 | void GUIManager::buttonPressed(const KeyEvent& evt) |
---|
[3196] | 674 | { |
---|
[9675] | 675 | #if CEGUI_VERSION >= 0x000800 |
---|
[11071] | 676 | this->protectedCeguiContextCall(std::bind(&CEGUI::GUIContext::injectKeyDown, arg::_1, (CEGUI::Key::Scan) evt.getKeyCode())); // TODO: will this cast always work? |
---|
| 677 | this->protectedCeguiContextCall(std::bind(&CEGUI::GUIContext::injectChar, arg::_1, evt.getText())); |
---|
[9675] | 678 | #else |
---|
[11071] | 679 | this->protectedCeguiSystemCall(std::bind(&CEGUI::System::injectKeyDown, arg::_1, evt.getKeyCode())); |
---|
| 680 | this->protectedCeguiSystemCall(std::bind(&CEGUI::System::injectChar, arg::_1, evt.getText())); |
---|
[9675] | 681 | #endif |
---|
[3196] | 682 | } |
---|
[6746] | 683 | |
---|
[7163] | 684 | void GUIManager::buttonReleased(const KeyEvent& evt) |
---|
[3196] | 685 | { |
---|
[9675] | 686 | #if CEGUI_VERSION >= 0x000800 |
---|
[11071] | 687 | this->protectedCeguiContextCall(std::bind(&CEGUI::GUIContext::injectKeyUp, arg::_1, (CEGUI::Key::Scan) evt.getKeyCode())); // TODO: will this cast always work? |
---|
[9675] | 688 | #else |
---|
[11071] | 689 | this->protectedCeguiSystemCall(std::bind(&CEGUI::System::injectKeyUp, arg::_1, evt.getKeyCode())); |
---|
[9675] | 690 | #endif |
---|
[3196] | 691 | } |
---|
| 692 | |
---|
[2896] | 693 | /** |
---|
| 694 | @brief |
---|
| 695 | Function receiving a mouse button pressed event. |
---|
| 696 | @param id |
---|
| 697 | ID of the mouse button which got pressed |
---|
[1638] | 698 | |
---|
[2896] | 699 | This function is inherited by MouseHandler and injects the event into CEGUI. |
---|
| 700 | It is for CEGUI to process the event. |
---|
| 701 | */ |
---|
[3327] | 702 | void GUIManager::buttonPressed(MouseButtonCode::ByEnum id) |
---|
[1638] | 703 | { |
---|
[9675] | 704 | #if CEGUI_VERSION >= 0x000800 |
---|
[11071] | 705 | this->protectedCeguiContextCall(std::bind(&CEGUI::GUIContext::injectMouseButtonDown, arg::_1, convertButton(id))); |
---|
[9675] | 706 | #else |
---|
[11071] | 707 | this->protectedCeguiSystemCall(std::bind(&CEGUI::System::injectMouseButtonDown, arg::_1, convertButton(id))); |
---|
[9675] | 708 | #endif |
---|
[1638] | 709 | } |
---|
| 710 | |
---|
[2896] | 711 | /** |
---|
| 712 | @brief |
---|
| 713 | Function receiving a mouse button released event. |
---|
| 714 | @param id |
---|
| 715 | ID of the mouse button which got released |
---|
| 716 | |
---|
| 717 | This function is inherited by MouseHandler and injects the event into CEGUI. |
---|
| 718 | It is for CEGUI to process the event. |
---|
| 719 | */ |
---|
[3327] | 720 | void GUIManager::buttonReleased(MouseButtonCode::ByEnum id) |
---|
[1638] | 721 | { |
---|
[9675] | 722 | #if CEGUI_VERSION >= 0x000800 |
---|
[11071] | 723 | this->protectedCeguiContextCall(std::bind(&CEGUI::GUIContext::injectMouseButtonUp, arg::_1, convertButton(id))); |
---|
[9675] | 724 | #else |
---|
[11071] | 725 | this->protectedCeguiSystemCall(std::bind(&CEGUI::System::injectMouseButtonUp, arg::_1, convertButton(id))); |
---|
[9675] | 726 | #endif |
---|
[1638] | 727 | } |
---|
| 728 | |
---|
[3196] | 729 | void GUIManager::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) |
---|
| 730 | { |
---|
[9675] | 731 | #if CEGUI_VERSION >= 0x000800 |
---|
[11071] | 732 | this->protectedCeguiContextCall(std::bind(&CEGUI::GUIContext::injectMousePosition, arg::_1, (float)abs.x, (float)abs.y)); |
---|
[9675] | 733 | #else |
---|
[11071] | 734 | this->protectedCeguiSystemCall(std::bind(&CEGUI::System::injectMousePosition, arg::_1, (float)abs.x, (float)abs.y)); |
---|
[9675] | 735 | #endif |
---|
[3196] | 736 | } |
---|
[6746] | 737 | |
---|
[3196] | 738 | void GUIManager::mouseScrolled(int abs, int rel) |
---|
| 739 | { |
---|
[9675] | 740 | #if CEGUI_VERSION >= 0x000800 |
---|
[11071] | 741 | this->protectedCeguiContextCall(std::bind(&CEGUI::GUIContext::injectMouseWheelChange, arg::_1, (float)sgn(rel) * this->numScrollLines_)); |
---|
[9675] | 742 | #else |
---|
[11071] | 743 | this->protectedCeguiSystemCall(std::bind(&CEGUI::System::injectMouseWheelChange, arg::_1, (float)sgn(rel) * this->numScrollLines_)); |
---|
[9675] | 744 | #endif |
---|
[3196] | 745 | } |
---|
| 746 | |
---|
[2896] | 747 | /** |
---|
[7874] | 748 | @brief Indicates that the mouse left the application's window. |
---|
| 749 | */ |
---|
| 750 | void GUIManager::mouseLeft() |
---|
| 751 | { |
---|
[9675] | 752 | #if CEGUI_VERSION >= 0x000800 |
---|
[11071] | 753 | this->protectedCeguiContextCall(std::bind(&CEGUI::GUIContext::injectMouseLeaves, arg::_1)); |
---|
[9675] | 754 | #else |
---|
[11071] | 755 | this->protectedCeguiSystemCall(std::bind(&CEGUI::System::injectMouseLeaves, arg::_1)); |
---|
[9675] | 756 | #endif |
---|
[7874] | 757 | } |
---|
| 758 | |
---|
| 759 | /** |
---|
[2896] | 760 | @brief |
---|
| 761 | converts mouse event code to CEGUI event code |
---|
| 762 | @param button |
---|
| 763 | code of the mouse button as we use it in Orxonox |
---|
| 764 | @return |
---|
| 765 | code of the mouse button as it is used by CEGUI |
---|
[1638] | 766 | |
---|
[6105] | 767 | Simple conversion from mouse event code in Orxonox to the one used in CEGUI. |
---|
[2896] | 768 | */ |
---|
[3196] | 769 | static inline CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button) |
---|
[1638] | 770 | { |
---|
| 771 | switch (button) |
---|
| 772 | { |
---|
[1887] | 773 | case MouseButtonCode::Left: |
---|
[1638] | 774 | return CEGUI::LeftButton; |
---|
| 775 | |
---|
[1887] | 776 | case MouseButtonCode::Right: |
---|
[1638] | 777 | return CEGUI::RightButton; |
---|
| 778 | |
---|
[1887] | 779 | case MouseButtonCode::Middle: |
---|
[1638] | 780 | return CEGUI::MiddleButton; |
---|
| 781 | |
---|
[1887] | 782 | case MouseButtonCode::Button3: |
---|
[1638] | 783 | return CEGUI::X1Button; |
---|
| 784 | |
---|
[1887] | 785 | case MouseButtonCode::Button4: |
---|
[1638] | 786 | return CEGUI::X2Button; |
---|
| 787 | |
---|
| 788 | default: |
---|
| 789 | return CEGUI::NoButton; |
---|
| 790 | } |
---|
| 791 | } |
---|
[6417] | 792 | |
---|
[6746] | 793 | /** Executes a CEGUI function normally, but catches CEGUI::ScriptException. |
---|
| 794 | When a ScriptException occurs, the error message will be displayed and |
---|
| 795 | the program carries on. |
---|
| 796 | @remarks |
---|
| 797 | The exception behaviour may pose problems if the code is not written |
---|
| 798 | exception-safe (and you can forget about that in Lua). The program might |
---|
| 799 | be left in an undefined state. But otherwise one script error would |
---|
| 800 | terminate the whole program... |
---|
| 801 | @note |
---|
[11071] | 802 | Your life gets easier if you use std::bind to create the object/function. |
---|
[6746] | 803 | @param function |
---|
| 804 | Any callable object/function that takes this->guiSystem_ as its only parameter. |
---|
| 805 | @return |
---|
| 806 | True if input was handled, false otherwise. A caught exception yields true. |
---|
| 807 | */ |
---|
[9675] | 808 | template <typename FunctionType, typename ObjectType> |
---|
| 809 | bool GUIManager::protectedCall(FunctionType function, ObjectType object) |
---|
[6746] | 810 | { |
---|
| 811 | try |
---|
| 812 | { |
---|
[9675] | 813 | return function(object); |
---|
[6746] | 814 | } |
---|
| 815 | catch (CEGUI::ScriptException& ex) |
---|
| 816 | { |
---|
| 817 | // Display the error and proceed. See @remarks why this can be dangerous. |
---|
[8858] | 818 | orxout(internal_error) << ex.getMessage() << endl; |
---|
[6746] | 819 | return true; |
---|
| 820 | } |
---|
| 821 | } |
---|
| 822 | |
---|
[9675] | 823 | template <typename FunctionType> |
---|
| 824 | bool GUIManager::protectedCeguiSystemCall(FunctionType function) |
---|
| 825 | { |
---|
| 826 | return this->protectedCall(function, this->guiSystem_); |
---|
| 827 | } |
---|
| 828 | |
---|
| 829 | #if CEGUI_VERSION >= 0x000800 |
---|
| 830 | template <typename FunctionType> |
---|
| 831 | bool GUIManager::protectedCeguiContextCall(FunctionType function) |
---|
| 832 | { |
---|
| 833 | return this->protectedCall(function, this->guiSystem_->getDefaultGUIContext()); |
---|
| 834 | } |
---|
| 835 | #endif |
---|
| 836 | |
---|
[7648] | 837 | /** |
---|
| 838 | @brief |
---|
| 839 | Subscribe the input function to the input event for the input window. |
---|
| 840 | This is a helper to be used in lua, because subscribeScriptedEvent() doesn't work in lua. |
---|
| 841 | @param window |
---|
| 842 | The window for which the event is subscribed. |
---|
| 843 | @param event |
---|
| 844 | The type of event to which we subscribe. |
---|
| 845 | @param function |
---|
| 846 | The function that is called when the event occurs. |
---|
| 847 | */ |
---|
[6417] | 848 | void GUIManager::subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function) |
---|
| 849 | { |
---|
| 850 | window->subscribeScriptedEvent(event, function); |
---|
| 851 | } |
---|
[7648] | 852 | |
---|
| 853 | /** |
---|
| 854 | @brief |
---|
| 855 | Set the input tooltip text for the input ListboxItem. |
---|
| 856 | @param item |
---|
| 857 | The ListboxItem for which the tooltip should be set. |
---|
| 858 | @param tooltip |
---|
| 859 | The tooltip text that should be set. |
---|
| 860 | */ |
---|
| 861 | void GUIManager::setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& tooltip) |
---|
| 862 | { |
---|
| 863 | item->setTooltipText(tooltip); |
---|
| 864 | } |
---|
| 865 | |
---|
| 866 | /** |
---|
| 867 | @brief |
---|
| 868 | Set whether the tooltips for the input Listbox are enabled. |
---|
| 869 | @param listbox |
---|
| 870 | The Listbox for which to enable (or disable) tooltips. |
---|
| 871 | @param enabled |
---|
[8351] | 872 | Whether to enable or disable the tooltips. |
---|
[7648] | 873 | */ |
---|
| 874 | void GUIManager::setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled) |
---|
| 875 | { |
---|
| 876 | listbox->setItemTooltipsEnabled(enabled); |
---|
| 877 | } |
---|
| 878 | |
---|
[8729] | 879 | /** Helper method to get the developer's mode without having to export Core.h. |
---|
| 880 | @see Core::inDevMode |
---|
| 881 | */ |
---|
| 882 | /*static*/ bool GUIManager::inDevMode() |
---|
| 883 | { |
---|
[10624] | 884 | return Core::getInstance().getConfig()->inDevMode(); |
---|
[8729] | 885 | } |
---|
| 886 | |
---|
[7873] | 887 | /** |
---|
| 888 | @brief Callback of window event listener, called if the window is resized. Sets the display size of CEGUI. |
---|
| 889 | */ |
---|
| 890 | void GUIManager::windowResized(unsigned int newWidth, unsigned int newHeight) |
---|
| 891 | { |
---|
[9675] | 892 | #if CEGUI_VERSION >= 0x000800 |
---|
| 893 | this->guiRenderer_->setDisplaySize(CEGUI::Sizef((float)newWidth, (float)newHeight)); |
---|
| 894 | #else |
---|
[8079] | 895 | this->guiRenderer_->setDisplaySize(CEGUI::Size((float)newWidth, (float)newHeight)); |
---|
[9675] | 896 | #endif |
---|
[10279] | 897 | this->rootWindow_->setSize(CEGUI::UVector2(CEGUI::UDim(1, (float)newWidth), CEGUI::UDim(1, (float)newHeight))); |
---|
[7873] | 898 | } |
---|
[7874] | 899 | |
---|
| 900 | /** |
---|
[8079] | 901 | @brief Notify CEGUI if the windows loses the focus (stops highlighting of menu items, etc). |
---|
[7874] | 902 | */ |
---|
| 903 | void GUIManager::windowFocusChanged(bool bFocus) |
---|
| 904 | { |
---|
| 905 | if (!bFocus) |
---|
| 906 | this->mouseLeft(); |
---|
| 907 | } |
---|
[7876] | 908 | |
---|
[8706] | 909 | /** |
---|
| 910 | @brief |
---|
| 911 | Adds a new freetype font to the CEGUI system. |
---|
| 912 | @param name |
---|
| 913 | The name of the new font. |
---|
| 914 | @param size |
---|
| 915 | The font size of the new font in pixels. |
---|
| 916 | @param fontName |
---|
| 917 | The filename of the font. |
---|
| 918 | */ |
---|
| 919 | /*static*/ void GUIManager::addFontHelper(const std::string& name, int size, const std::string& fontName) |
---|
| 920 | { |
---|
| 921 | #ifdef ORXONOX_OLD_CEGUI |
---|
| 922 | if(CEGUI::FontManager::getSingleton().isFontPresent(name)) // If a font with that name already exists. |
---|
| 923 | return; |
---|
| 924 | |
---|
[11071] | 925 | CEGUI::Font* font = nullptr; |
---|
[8706] | 926 | CEGUI::XMLAttributes xmlAttributes; |
---|
| 927 | |
---|
| 928 | // Attributes specified within CEGUIFont |
---|
| 929 | xmlAttributes.add("Name", name); |
---|
| 930 | xmlAttributes.add("Filename", fontName); |
---|
| 931 | xmlAttributes.add("ResourceGroup", ""); |
---|
| 932 | xmlAttributes.add("AutoScaled", "true"); |
---|
| 933 | xmlAttributes.add("NativeHorzRes", "800"); |
---|
| 934 | xmlAttributes.add("NativeVertRes", "600"); |
---|
| 935 | |
---|
| 936 | // Attributes specified within CEGUIXMLAttributes |
---|
| 937 | xmlAttributes.add("Size", multi_cast<std::string>(size)); |
---|
| 938 | xmlAttributes.add("AntiAlias", "true"); |
---|
| 939 | |
---|
| 940 | font = CEGUI::FontManager::getSingleton().createFont("FreeType", xmlAttributes); |
---|
[11071] | 941 | if(font != nullptr) |
---|
[8706] | 942 | font->load(); |
---|
| 943 | #else |
---|
| 944 | if(CEGUI::FontManager::getSingleton().isDefined(name)) // If a font with that name already exists. |
---|
| 945 | return; |
---|
| 946 | |
---|
[9675] | 947 | #if CEGUI_VERSION >= 0x000800 |
---|
| 948 | CEGUI::FontManager::getSingleton().createFreeTypeFont(name, (float)size, true, fontName, "", CEGUI::ASM_Both, CEGUI::Sizef(800.0f, 600.0f)); |
---|
| 949 | #else |
---|
[8706] | 950 | CEGUI::FontManager::getSingleton().createFreeTypeFont(name, (float)size, true, fontName, "", true, 800.0f, 600.0f); |
---|
[9675] | 951 | #endif |
---|
[8706] | 952 | #endif |
---|
| 953 | } |
---|
| 954 | |
---|
[1638] | 955 | } |
---|