From ecfc2ff5d0fff615f6b1632e3b328d6c678fbc92 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 11 Sep 2014 23:12:38 +0200 Subject: [PATCH 01/11] Add a MyGUI plugin to register OpenMW resources, to use with MyGUI's standalone tools --- CMakeLists.txt | 52 +++++++++----- components/CMakeLists.txt | 6 ++ libs/mygui_resource_plugin/CMakeLists.txt | 24 +++++++ libs/mygui_resource_plugin/plugin.cpp | 75 ++++++++++++++++++++ libs/mygui_resource_plugin/plugin.hpp | 37 ++++++++++ libs/mygui_resource_plugin/plugin_export.cpp | 17 +++++ 6 files changed, 192 insertions(+), 19 deletions(-) create mode 100644 libs/mygui_resource_plugin/CMakeLists.txt create mode 100644 libs/mygui_resource_plugin/plugin.cpp create mode 100644 libs/mygui_resource_plugin/plugin.hpp create mode 100644 libs/mygui_resource_plugin/plugin_export.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 47575e0ce..c6ceaa668 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ option(BUILD_OPENCS "build OpenMW Construction Set" ON) option(BUILD_WITH_CODE_COVERAGE "Enable code coverage with gconv" OFF) option(BUILD_UNITTESTS "Enable Unittests with Google C++ Unittest ang GMock frameworks" OFF) option(BUILD_NIFTEST "build nif file tester" OFF) +option(BUILD_MYGUI_PLUGIN "build MyGUI plugin for OpenMW resources, to use with MyGUI tools" ON) # OS X deployment option(OPENMW_OSX_DEPLOYMENT OFF) @@ -103,32 +104,32 @@ cmake_minimum_required(VERSION 2.6) # source directory: libs -set(LIBDIR ${CMAKE_SOURCE_DIR}/libs) +set(LIBS_DIR ${CMAKE_SOURCE_DIR}/libs) set(OENGINE_OGRE - ${LIBDIR}/openengine/ogre/renderer.cpp - ${LIBDIR}/openengine/ogre/lights.cpp - ${LIBDIR}/openengine/ogre/selectionbuffer.cpp - ${LIBDIR}/openengine/ogre/imagerotate.cpp + ${LIBS_DIR}/openengine/ogre/renderer.cpp + ${LIBS_DIR}/openengine/ogre/lights.cpp + ${LIBS_DIR}/openengine/ogre/selectionbuffer.cpp + ${LIBS_DIR}/openengine/ogre/imagerotate.cpp ) set(OENGINE_GUI - ${LIBDIR}/openengine/gui/loglistener.cpp - ${LIBDIR}/openengine/gui/manager.cpp - ${LIBDIR}/openengine/gui/layout.hpp + ${LIBS_DIR}/openengine/gui/loglistener.cpp + ${LIBS_DIR}/openengine/gui/manager.cpp + ${LIBS_DIR}/openengine/gui/layout.hpp ) set(OENGINE_BULLET - ${LIBDIR}/openengine/bullet/BtOgre.cpp - ${LIBDIR}/openengine/bullet/BtOgreExtras.h - ${LIBDIR}/openengine/bullet/BtOgreGP.h - ${LIBDIR}/openengine/bullet/BtOgrePG.h - ${LIBDIR}/openengine/bullet/physic.cpp - ${LIBDIR}/openengine/bullet/physic.hpp - ${LIBDIR}/openengine/bullet/BulletShapeLoader.cpp - ${LIBDIR}/openengine/bullet/BulletShapeLoader.h - ${LIBDIR}/openengine/bullet/trace.cpp - ${LIBDIR}/openengine/bullet/trace.h + ${LIBS_DIR}/openengine/bullet/BtOgre.cpp + ${LIBS_DIR}/openengine/bullet/BtOgreExtras.h + ${LIBS_DIR}/openengine/bullet/BtOgreGP.h + ${LIBS_DIR}/openengine/bullet/BtOgrePG.h + ${LIBS_DIR}/openengine/bullet/physic.cpp + ${LIBS_DIR}/openengine/bullet/physic.hpp + ${LIBS_DIR}/openengine/bullet/BulletShapeLoader.cpp + ${LIBS_DIR}/openengine/bullet/BulletShapeLoader.h + ${LIBS_DIR}/openengine/bullet/trace.cpp + ${LIBS_DIR}/openengine/bullet/trace.h ) @@ -261,7 +262,7 @@ include_directories("." ${MYGUI_INCLUDE_DIRS} ${MYGUI_PLATFORM_INCLUDE_DIRS} ${OPENAL_INCLUDE_DIR} - ${LIBDIR} + ${LIBS_DIR} ) link_directories(${SDL2_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS} ${OGRE_LIB_DIR} ${MYGUI_LIB_DIR}) @@ -333,8 +334,10 @@ add_subdirectory(files/mygui) if (APPLE) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${APP_BUNDLE_DIR}/Contents/MacOS") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${APP_BUNDLE_DIR}/Contents/MacOS") else (APPLE) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OpenMW_BINARY_DIR}") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OpenMW_BINARY_DIR}") endif (APPLE) # Other files @@ -379,6 +382,7 @@ IF(NOT WIN32 AND NOT APPLE) # Linux building # Paths SET(BINDIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Where to install binaries") + SET(LIBDIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Where to install libraries") SET(DATAROOTDIR "${CMAKE_INSTALL_PREFIX}/share" CACHE PATH "Sets the root of data directories to a non-default location") SET(DATADIR "${DATAROOTDIR}/games/openmw" CACHE PATH "Sets the openmw data directories to a non-default location") SET(ICONDIR "${DATAROOTDIR}/pixmaps" CACHE PATH "Set icon dir") @@ -405,6 +409,9 @@ IF(NOT WIN32 AND NOT APPLE) IF(BUILD_NIFTEST) INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/niftest" DESTINATION "${BINDIR}" ) ENDIF(BUILD_NIFTEST) + if(BUILD_MYGUI_PLUGIN) + INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/Plugin_MyGUI_OpenMW_Resources.so" DESTINATION "${LIBDIR}" ) + ENDIF(BUILD_MYGUI_PLUGIN) # Install licenses INSTALL(FILES "docs/license/DejaVu Font License.txt" DESTINATION "${LICDIR}" ) @@ -454,6 +461,9 @@ if(WIN32) INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/Release/opencs.exe" DESTINATION ".") INSTALL(FILES "${OpenMW_BINARY_DIR}/opencs.ini" DESTINATION ".") ENDIF(BUILD_OPENCS) + if(BUILD_MYGUI_PLUGIN) + INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/Release/Plugin_MyGUI_OpenMW_Resources.dll" DESTINATION ".") + ENDIF(BUILD_MYGUI_PLUGIN) INSTALL(DIRECTORY "${OpenMW_BINARY_DIR}/resources" DESTINATION ".") @@ -521,6 +531,10 @@ add_subdirectory (extern/sdl4ogre) # Components add_subdirectory (components) +if (BUILD_MYGUI_PLUGIN) + add_subdirectory(libs/mygui_resource_plugin) +endif() + #Testing if (BUILD_NIFTEST) add_subdirectory(components/nif/tests/) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 1c3f442c2..beeadadbe 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -112,6 +112,12 @@ if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) QT4_WRAP_CPP(MOC_SRCS ${COMPONENT_MOC_FILES}) endif(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY) +if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE) + add_definitions(-fPIC) + endif() +endif () + include_directories(${BULLET_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR}) diff --git a/libs/mygui_resource_plugin/CMakeLists.txt b/libs/mygui_resource_plugin/CMakeLists.txt new file mode 100644 index 000000000..7288fd4b6 --- /dev/null +++ b/libs/mygui_resource_plugin/CMakeLists.txt @@ -0,0 +1,24 @@ +set (MYGUI_RESOURCE_PLUGIN_SOURCES + plugin.hpp + plugin.cpp + plugin_export.cpp +) + +set (MYGUI_RESOURCE_PLUGIN_LIBRARY + Plugin_MyGUI_OpenMW_Resources +) + +add_definitions("-D_USRDLL -DMYGUI_BUILD_DLL") + +add_library(${MYGUI_RESOURCE_PLUGIN_LIBRARY} + SHARED + ${MYGUI_RESOURCE_PLUGIN_SOURCES} + ) + +set_target_properties(${MYGUI_RESOURCE_PLUGIN_LIBRARY} PROPERTIES PREFIX "") + +target_link_libraries(${MYGUI_RESOURCE_PLUGIN_LIBRARY} + ${OGRE_LIBRARIES} + ${MYGUI_LIBRARIES} + components +) diff --git a/libs/mygui_resource_plugin/plugin.cpp b/libs/mygui_resource_plugin/plugin.cpp new file mode 100644 index 000000000..24ecf6557 --- /dev/null +++ b/libs/mygui_resource_plugin/plugin.cpp @@ -0,0 +1,75 @@ +#include "plugin.hpp" + +#include + +#include +#include + +namespace MyGUI +{ + + const std::string& ResourcePlugin::getName() const + { + static const std::string name = "OpenMW resource plugin"; + return name; + } + + void ResourcePlugin::install() + { + + } + void ResourcePlugin::uninstall() + { + + } + + void ResourcePlugin::initialize() + { + MYGUI_LOGGING("OpenMW_Resource_Plugin", Info, "initialize"); + + boost::program_options::variables_map variables; + + boost::program_options::options_description desc("Allowed options"); + desc.add_options() + ("data", boost::program_options::value()->default_value(Files::PathContainer(), "data")->multitoken()) + ("data-local", boost::program_options::value()->default_value("")) + ("fs-strict", boost::program_options::value()->implicit_value(true)->default_value(false)) + ("fallback-archive", boost::program_options::value >()-> + default_value(std::vector(), "fallback-archive")->multitoken()); + + boost::program_options::notify(variables); + + Files::ConfigurationManager cfgManager; + cfgManager.readConfiguration(variables, desc); + + std::vector archives = variables["fallback-archive"].as >(); + bool fsStrict = variables["fs-strict"].as(); + + Files::PathContainer dataDirs, dataLocal; + if (!variables["data"].empty()) { + dataDirs = Files::PathContainer(variables["data"].as()); + } + + std::string local = variables["data-local"].as(); + if (!local.empty()) { + dataLocal.push_back(Files::PathContainer::value_type(local)); + } + + cfgManager.processPaths (dataDirs); + cfgManager.processPaths (dataLocal, true); + + if (!dataLocal.empty()) + dataDirs.insert (dataDirs.end(), dataLocal.begin(), dataLocal.end()); + + Files::Collections collections (dataDirs, !fsStrict); + + Bsa::registerResources(collections, archives, true, fsStrict); + } + + void ResourcePlugin::shutdown() + { + /// \todo remove resource groups + MYGUI_LOGGING("OpenMW_Resource_Plugin", Info, "shutdown"); + } + +} diff --git a/libs/mygui_resource_plugin/plugin.hpp b/libs/mygui_resource_plugin/plugin.hpp new file mode 100644 index 000000000..5203b80ba --- /dev/null +++ b/libs/mygui_resource_plugin/plugin.hpp @@ -0,0 +1,37 @@ +#ifndef OPENMW_MYGUI_RESOURCE_PLUGIN_H +#define OPENMW_MYGUI_RESOURCE_PLUGIN_H + +#include + +namespace MyGUI +{ + + class ResourcePlugin : public MyGUI::IPlugin + { + /*! Get the name of the plugin. + @remarks An implementation must be supplied for this method to uniquely + identify the plugin + */ + virtual const std::string& getName() const; + + /*! Perform the plugin initial installation sequence + */ + virtual void install(); + + /*! Perform any tasks the plugin needs to perform on full system + initialisation. + */ + virtual void initialize(); + + /*! Perform any tasks the plugin needs to perform when the system is shut down + */ + virtual void shutdown(); + + /*! Perform the final plugin uninstallation sequence + */ + virtual void uninstall(); + }; + +} + +#endif diff --git a/libs/mygui_resource_plugin/plugin_export.cpp b/libs/mygui_resource_plugin/plugin_export.cpp new file mode 100644 index 000000000..3ca1152f3 --- /dev/null +++ b/libs/mygui_resource_plugin/plugin_export.cpp @@ -0,0 +1,17 @@ +#include "plugin.hpp" +#include "MyGUI_PluginManager.h" + +MyGUI::ResourcePlugin* plugin_item = nullptr; + +extern "C" MYGUI_EXPORT_DLL void dllStartPlugin(void) +{ + plugin_item = new MyGUI::ResourcePlugin(); + MyGUI::PluginManager::getInstance().installPlugin(plugin_item); +} + +extern "C" MYGUI_EXPORT_DLL void dllStopPlugin(void) +{ + MyGUI::PluginManager::getInstance().uninstallPlugin(plugin_item); + delete plugin_item; + plugin_item = nullptr; +} From ee3b1e800ca61800cbd062328e891d0ecdd154f3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 12 Sep 2014 04:27:23 +0200 Subject: [PATCH 02/11] Add FontLoader and transparent BG texture to the MyGUI plugin --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwgui/windowmanagerimp.cpp | 5 +- components/CMakeLists.txt | 8 ++ .../fontloader}/fontloader.cpp | 2 +- .../fontloader}/fontloader.hpp | 2 +- libs/mygui_resource_plugin/plugin.cpp | 91 +++++++++++++++++-- libs/mygui_resource_plugin/plugin.hpp | 12 ++- libs/mygui_resource_plugin/plugin_export.cpp | 4 +- 8 files changed, 112 insertions(+), 14 deletions(-) rename {apps/openmw/mwgui => components/fontloader}/fontloader.cpp (99%) rename {apps/openmw/mwgui => components/fontloader}/fontloader.hpp (97%) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index e2c1ef5c9..53c79f7c6 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -39,7 +39,7 @@ add_openmw_dir (mwgui enchantingdialog trainingwindow travelwindow imagebutton exposedwindow cursor spellicons merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview - tradeitemmodel companionitemmodel pickpocketitemmodel fontloader controllers savegamedialog + tradeitemmodel companionitemmodel pickpocketitemmodel controllers savegamedialog recharge mode videowidget backgroundimage itemwidget screenfader ) diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index f6ad6500c..5882ae2b6 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -16,6 +16,8 @@ #include +#include + #include "../mwbase/inputmanager.hpp" #include "../mwbase/statemanager.hpp" @@ -63,7 +65,6 @@ #include "inventorywindow.hpp" #include "bookpage.hpp" #include "itemview.hpp" -#include "fontloader.hpp" #include "videowidget.hpp" #include "backgroundimage.hpp" #include "itemwidget.hpp" @@ -149,7 +150,7 @@ namespace MWGui mGui = mGuiManager->getGui(); // Load fonts - FontLoader fontLoader (encoding); + Gui::FontLoader fontLoader (encoding); fontLoader.loadAllFonts(exportFonts); //Register own widgets with MyGUI diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index beeadadbe..1178a3a28 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -91,6 +91,14 @@ add_component_dir (ogreinit ogreinit ogreplugin ) +add_component_dir (widgets + box + ) + +add_component_dir (fontloader + fontloader + ) + add_component_dir (version version ) diff --git a/apps/openmw/mwgui/fontloader.cpp b/components/fontloader/fontloader.cpp similarity index 99% rename from apps/openmw/mwgui/fontloader.cpp rename to components/fontloader/fontloader.cpp index b1cb7fccf..e01e4b7bc 100644 --- a/apps/openmw/mwgui/fontloader.cpp +++ b/components/fontloader/fontloader.cpp @@ -123,7 +123,7 @@ namespace } -namespace MWGui +namespace Gui { FontLoader::FontLoader(ToUTF8::FromType encoding) diff --git a/apps/openmw/mwgui/fontloader.hpp b/components/fontloader/fontloader.hpp similarity index 97% rename from apps/openmw/mwgui/fontloader.hpp rename to components/fontloader/fontloader.hpp index 619717840..a41506dbb 100644 --- a/apps/openmw/mwgui/fontloader.hpp +++ b/components/fontloader/fontloader.hpp @@ -3,7 +3,7 @@ #include -namespace MWGui +namespace Gui { diff --git a/libs/mygui_resource_plugin/plugin.cpp b/libs/mygui_resource_plugin/plugin.cpp index 24ecf6557..02088f693 100644 --- a/libs/mygui_resource_plugin/plugin.cpp +++ b/libs/mygui_resource_plugin/plugin.cpp @@ -1,13 +1,53 @@ #include "plugin.hpp" #include +#include +#include +#include #include #include +#include -namespace MyGUI +#include +#include + +namespace MyGUIPlugin { + // Dummy - obsolete when using MyGUI git, because the ScrollBar there has autorepeat support added. + class MWScrollBar : public MyGUI::ScrollBar + { + MYGUI_RTTI_DERIVED(MWScrollBar) + }; + + // Dummy - not properly supportable without bringing in the whole ESM store + class MWSkill : public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( MWSkill ) + }; + class MWAttribute : public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( MWAttribute ) + }; + class MWSpell : public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( MWSpell ) + }; + class MWEffectList : public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( MWEffectList ) + }; + class MWSpellEffect : public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( MWSpellEffect ) + }; + class MWDynamicStat : public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( MWDynamicStat ) + }; + + const std::string& ResourcePlugin::getName() const { static const std::string name = "OpenMW resource plugin"; @@ -23,10 +63,8 @@ namespace MyGUI } - void ResourcePlugin::initialize() + void ResourcePlugin::registerResources() { - MYGUI_LOGGING("OpenMW_Resource_Plugin", Info, "initialize"); - boost::program_options::variables_map variables; boost::program_options::options_description desc("Allowed options"); @@ -35,7 +73,8 @@ namespace MyGUI ("data-local", boost::program_options::value()->default_value("")) ("fs-strict", boost::program_options::value()->implicit_value(true)->default_value(false)) ("fallback-archive", boost::program_options::value >()-> - default_value(std::vector(), "fallback-archive")->multitoken()); + default_value(std::vector(), "fallback-archive")->multitoken()) + ("encoding", boost::program_options::value()->default_value("win1252")); boost::program_options::notify(variables); @@ -64,11 +103,51 @@ namespace MyGUI Files::Collections collections (dataDirs, !fsStrict); Bsa::registerResources(collections, archives, true, fsStrict); + + std::string encoding(variables["encoding"].as()); + std::cout << ToUTF8::encodingUsingMessage(encoding) << std::endl; + + Gui::FontLoader loader(ToUTF8::calculateEncoding(encoding)); + loader.loadAllFonts(false); + } + + void ResourcePlugin::registerWidgets() + { + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + } + + void ResourcePlugin::createTransparentBGTexture() + { + // This texture is manually created in OpenMW to be able to change its opacity at runtime in the options menu + Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().createManual( + "transparent.png", + Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, + Ogre::TEX_TYPE_2D, + 1, 1, + 0, + Ogre::PF_A8R8G8B8, + Ogre::TU_WRITE_ONLY); + std::vector buffer; + buffer.resize(1); + const float val = 0.7; + buffer[0] = (int(255*val) << 24); + memcpy(tex->getBuffer()->lock(Ogre::HardwareBuffer::HBL_DISCARD), &buffer[0], 1*4); + tex->getBuffer()->unlock(); + } + + void ResourcePlugin::initialize() + { + MYGUI_LOGGING("OpenMW_Resource_Plugin", Info, "initialize"); + + registerResources(); + registerWidgets(); + createTransparentBGTexture(); } void ResourcePlugin::shutdown() { - /// \todo remove resource groups + /// \todo cleanup + MYGUI_LOGGING("OpenMW_Resource_Plugin", Info, "shutdown"); } diff --git a/libs/mygui_resource_plugin/plugin.hpp b/libs/mygui_resource_plugin/plugin.hpp index 5203b80ba..9d035f09c 100644 --- a/libs/mygui_resource_plugin/plugin.hpp +++ b/libs/mygui_resource_plugin/plugin.hpp @@ -3,9 +3,14 @@ #include -namespace MyGUI +namespace MyGUIPlugin { + /** + * @brief MyGUI plugin used to register Morrowind resources, custom widgets used in OpenMW, and load Morrowind fonts. + * @paragraph The plugin isn't used in OpenMW itself, but it is useful with the standalone MyGUI tools. To use it, + * change EditorPlugin.xml in Media/Tools/LayoutEditor/EditorPlugin.xml and add an entry for this plugin. + */ class ResourcePlugin : public MyGUI::IPlugin { /*! Get the name of the plugin. @@ -30,6 +35,11 @@ namespace MyGUI /*! Perform the final plugin uninstallation sequence */ virtual void uninstall(); + + private: + void registerResources(); + void registerWidgets(); + void createTransparentBGTexture(); }; } diff --git a/libs/mygui_resource_plugin/plugin_export.cpp b/libs/mygui_resource_plugin/plugin_export.cpp index 3ca1152f3..0d6b4b804 100644 --- a/libs/mygui_resource_plugin/plugin_export.cpp +++ b/libs/mygui_resource_plugin/plugin_export.cpp @@ -1,11 +1,11 @@ #include "plugin.hpp" #include "MyGUI_PluginManager.h" -MyGUI::ResourcePlugin* plugin_item = nullptr; +MyGUIPlugin::ResourcePlugin* plugin_item = nullptr; extern "C" MYGUI_EXPORT_DLL void dllStartPlugin(void) { - plugin_item = new MyGUI::ResourcePlugin(); + plugin_item = new MyGUIPlugin::ResourcePlugin(); MyGUI::PluginManager::getInstance().installPlugin(plugin_item); } From c6bcd75058a51fbd8d4130eed629d36231c5a4a7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 12 Sep 2014 05:14:21 +0200 Subject: [PATCH 03/11] Add various custom widgets used in OpenMW to the MyGUI plugin --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwgui/bookwindow.cpp | 2 +- apps/openmw/mwgui/bookwindow.hpp | 12 +- apps/openmw/mwgui/journalwindow.cpp | 13 +- apps/openmw/mwgui/mainmenu.cpp | 9 +- apps/openmw/mwgui/mainmenu.hpp | 8 +- apps/openmw/mwgui/scrollwindow.cpp | 2 +- apps/openmw/mwgui/scrollwindow.hpp | 7 +- apps/openmw/mwgui/waitdialog.cpp | 4 +- apps/openmw/mwgui/widgets.cpp | 406 ----------------- apps/openmw/mwgui/widgets.hpp | 112 ----- apps/openmw/mwgui/windowmanagerimp.cpp | 14 +- components/CMakeLists.txt | 2 +- components/widgets/box.cpp | 407 ++++++++++++++++++ components/widgets/box.hpp | 118 +++++ .../widgets}/imagebutton.cpp | 2 +- .../widgets}/imagebutton.hpp | 2 +- libs/mygui_resource_plugin/plugin.cpp | 17 + 18 files changed, 587 insertions(+), 552 deletions(-) create mode 100644 components/widgets/box.cpp create mode 100644 components/widgets/box.hpp rename {apps/openmw/mwgui => components/widgets}/imagebutton.cpp (99%) rename {apps/openmw/mwgui => components/widgets}/imagebutton.hpp (98%) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 53c79f7c6..308b883fd 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -36,7 +36,7 @@ add_openmw_dir (mwgui formatting inventorywindow container hud countdialog tradewindow settingswindow confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu itemselection spellbuyingwindow loadingscreen levelupdialog waitdialog spellcreationdialog - enchantingdialog trainingwindow travelwindow imagebutton exposedwindow cursor spellicons + enchantingdialog trainingwindow travelwindow exposedwindow cursor spellicons merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview tradeitemmodel companionitemmodel pickpocketitemmodel controllers savegamedialog diff --git a/apps/openmw/mwgui/bookwindow.cpp b/apps/openmw/mwgui/bookwindow.cpp index 32a5255c9..372e81844 100644 --- a/apps/openmw/mwgui/bookwindow.cpp +++ b/apps/openmw/mwgui/bookwindow.cpp @@ -193,7 +193,7 @@ namespace MWGui } } - void BookWindow::adjustButton (MWGui::ImageButton* button) + void BookWindow::adjustButton (Gui::ImageButton* button) { MyGUI::IntSize diff = button->getSize() - button->getRequestedSize(); button->setSize(button->getRequestedSize()); diff --git a/apps/openmw/mwgui/bookwindow.hpp b/apps/openmw/mwgui/bookwindow.hpp index a944f56e2..e0f921dc1 100644 --- a/apps/openmw/mwgui/bookwindow.hpp +++ b/apps/openmw/mwgui/bookwindow.hpp @@ -5,7 +5,7 @@ #include "../mwworld/ptr.hpp" -#include "imagebutton.hpp" +#include namespace MWGui { @@ -31,13 +31,13 @@ namespace MWGui void updatePages(); void clearPages(); - void adjustButton(MWGui::ImageButton* button); + void adjustButton(Gui::ImageButton* button); private: - MWGui::ImageButton* mCloseButton; - MWGui::ImageButton* mTakeButton; - MWGui::ImageButton* mNextPageButton; - MWGui::ImageButton* mPrevPageButton; + Gui::ImageButton* mCloseButton; + Gui::ImageButton* mTakeButton; + Gui::ImageButton* mNextPageButton; + Gui::ImageButton* mPrevPageButton; MyGUI::TextBox* mLeftPageNumber; MyGUI::TextBox* mRightPageNumber; MyGUI::Widget* mLeftPage; diff --git a/apps/openmw/mwgui/journalwindow.cpp b/apps/openmw/mwgui/journalwindow.cpp index 057e12414..bc7fbde15 100644 --- a/apps/openmw/mwgui/journalwindow.cpp +++ b/apps/openmw/mwgui/journalwindow.cpp @@ -15,9 +15,10 @@ #include #include "boost/lexical_cast.hpp" +#include + #include "bookpage.hpp" #include "windowbase.hpp" -#include "imagebutton.hpp" #include "journalviewmodel.hpp" #include "journalbooks.hpp" #include "list.hpp" @@ -82,7 +83,7 @@ namespace void adviseButtonClick (char const * name, void (JournalWindowImpl::*Handler) (MyGUI::Widget* _sender)) { - getWidget (name) -> + getWidget (name) -> eventMouseButtonClick += newDelegate(this, Handler); } @@ -146,12 +147,12 @@ namespace adjustButton(ShowActiveBTN, true); adjustButton(JournalBTN); - MWGui::ImageButton* optionsButton = getWidget(OptionsBTN); + Gui::ImageButton* optionsButton = getWidget(OptionsBTN); if (optionsButton->getWidth() == 0) { // If tribunal is not installed (-> no options button), we still want the Topics button available, // so place it where the options button would have been - MWGui::ImageButton* topicsButton = getWidget(TopicsBTN); + Gui::ImageButton* topicsButton = getWidget(TopicsBTN); topicsButton->detachFromWidget(); topicsButton->attachToWidget(optionsButton->getParent()); topicsButton->setPosition(optionsButton->getPosition()); @@ -159,7 +160,7 @@ namespace topicsButton->eventMouseButtonClick += MyGUI::newDelegate(this, &JournalWindowImpl::notifyOptions); } - MWGui::ImageButton* nextButton = getWidget(NextPageBTN); + Gui::ImageButton* nextButton = getWidget(NextPageBTN); if (nextButton->getSize().width == 64) { // english button has a 7 pixel wide strip of garbage on its right edge @@ -182,7 +183,7 @@ namespace void adjustButton (char const * name, bool optional = false) { - MWGui::ImageButton* button = getWidget(name); + Gui::ImageButton* button = getWidget(name); MyGUI::IntSize diff = button->getSize() - button->getRequestedSize(!optional); button->setSize(button->getRequestedSize(!optional)); diff --git a/apps/openmw/mwgui/mainmenu.cpp b/apps/openmw/mwgui/mainmenu.cpp index 7c60353d2..81b082568 100644 --- a/apps/openmw/mwgui/mainmenu.cpp +++ b/apps/openmw/mwgui/mainmenu.cpp @@ -4,6 +4,8 @@ #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/soundmanager.hpp" @@ -16,7 +18,6 @@ #include "savegamedialog.hpp" #include "confirmationdialog.hpp" -#include "imagebutton.hpp" #include "backgroundimage.hpp" #include "videowidget.hpp" @@ -249,7 +250,7 @@ namespace MWGui { if (mButtons.find(*it) == mButtons.end()) { - MWGui::ImageButton* button = mButtonBox->createWidget + Gui::ImageButton* button = mButtonBox->createWidget ("ImageBox", MyGUI::IntCoord(0, curH, 0, 0), MyGUI::Align::Default); button->setProperty("ImageHighlighted", "textures\\menu_" + *it + "_over.dds"); button->setProperty("ImageNormal", "textures\\menu_" + *it + ".dds"); @@ -262,7 +263,7 @@ namespace MWGui // Start by hiding all buttons int maxwidth = 0; - for (std::map::iterator it = mButtons.begin(); it != mButtons.end(); ++it) + for (std::map::iterator it = mButtons.begin(); it != mButtons.end(); ++it) { it->second->setVisible(false); MyGUI::IntSize requested = it->second->getRequestedSize(); @@ -274,7 +275,7 @@ namespace MWGui for (std::vector::iterator it = buttons.begin(); it != buttons.end(); ++it) { assert(mButtons.find(*it) != mButtons.end()); - MWGui::ImageButton* button = mButtons[*it]; + Gui::ImageButton* button = mButtons[*it]; button->setVisible(true); MyGUI::IntSize requested = button->getRequestedSize(); diff --git a/apps/openmw/mwgui/mainmenu.hpp b/apps/openmw/mwgui/mainmenu.hpp index ccd8df4b0..cd2050d0f 100644 --- a/apps/openmw/mwgui/mainmenu.hpp +++ b/apps/openmw/mwgui/mainmenu.hpp @@ -3,10 +3,14 @@ #include +namespace Gui +{ + class ImageButton; +} + namespace MWGui { - class ImageButton; class BackgroundImage; class SaveGameDialog; class VideoWidget; @@ -39,7 +43,7 @@ namespace MWGui MyGUI::ImageBox* mVideoBackground; VideoWidget* mVideo; // For animated main menus - std::map mButtons; + std::map mButtons; void onButtonClicked (MyGUI::Widget* sender); void onNewGameConfirmed(); diff --git a/apps/openmw/mwgui/scrollwindow.cpp b/apps/openmw/mwgui/scrollwindow.cpp index 867bef0d7..7530d7a9e 100644 --- a/apps/openmw/mwgui/scrollwindow.cpp +++ b/apps/openmw/mwgui/scrollwindow.cpp @@ -13,7 +13,7 @@ namespace { - void adjustButton (MWGui::ImageButton* button) + void adjustButton (Gui::ImageButton* button) { MyGUI::IntSize diff = button->getSize() - button->getRequestedSize(); button->setSize(button->getRequestedSize()); diff --git a/apps/openmw/mwgui/scrollwindow.hpp b/apps/openmw/mwgui/scrollwindow.hpp index 17e56f334..08ce6a905 100644 --- a/apps/openmw/mwgui/scrollwindow.hpp +++ b/apps/openmw/mwgui/scrollwindow.hpp @@ -2,7 +2,8 @@ #define MWGUI_SCROLLWINDOW_H #include "windowbase.hpp" -#include "imagebutton.hpp" + +#include #include "../mwworld/ptr.hpp" @@ -23,8 +24,8 @@ namespace MWGui void onTakeButtonClicked (MyGUI::Widget* _sender); private: - MWGui::ImageButton* mCloseButton; - MWGui::ImageButton* mTakeButton; + Gui::ImageButton* mCloseButton; + Gui::ImageButton* mTakeButton; MyGUI::ScrollView* mTextView; MWWorld::Ptr mScroll; diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index 434c6926e..ac70d3eed 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -2,6 +2,8 @@ #include +#include + #include "../mwbase/windowmanager.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" @@ -190,7 +192,7 @@ namespace MWGui mSleeping = canRest; - dynamic_cast(mMainWidget)->notifyChildrenSizeChanged(); + dynamic_cast(mMainWidget)->notifyChildrenSizeChanged(); center(); } diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 1264185a2..5c5b9b894 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -537,412 +537,6 @@ namespace MWGui assignWidget(mBarTextWidget, "BarText"); } - - - - // --------------------------------------------------------------------------------------------------------------------- - - void AutoSizedWidget::notifySizeChange (MyGUI::Widget* w) - { - MyGUI::Widget * parent = w->getParent(); - if (parent != 0) - { - if (mExpandDirection == MyGUI::Align::Left) - { - int hdiff = getRequestedSize ().width - w->getSize().width; - w->setPosition(w->getPosition() - MyGUI::IntPoint(hdiff, 0)); - } - w->setSize(getRequestedSize ()); - - while (parent != 0) - { - Box * b = dynamic_cast(parent); - if (b) - b->notifyChildrenSizeChanged(); - else - break; - parent = parent->getParent(); - } - } - } - - - MyGUI::IntSize AutoSizedTextBox::getRequestedSize() - { - return getTextSize(); - } - - void AutoSizedTextBox::setCaption(const MyGUI::UString& _value) - { - TextBox::setCaption(_value); - - notifySizeChange (this); - } - - void AutoSizedTextBox::setPropertyOverride(const std::string& _key, const std::string& _value) - { - if (_key == "ExpandDirection") - { - mExpandDirection = MyGUI::Align::parse (_value); - } - else - { - TextBox::setPropertyOverride (_key, _value); - } - } - - MyGUI::IntSize AutoSizedEditBox::getRequestedSize() - { - if (getAlign().isHStretch()) - throw std::runtime_error("AutoSizedEditBox can't have HStretch align (" + getName() + ")"); - return MyGUI::IntSize(getSize().width, getTextSize().height); - } - - void AutoSizedEditBox::setCaption(const MyGUI::UString& _value) - { - EditBox::setCaption(_value); - - notifySizeChange (this); - } - - void AutoSizedEditBox::setPropertyOverride(const std::string& _key, const std::string& _value) - { - if (_key == "ExpandDirection") - { - mExpandDirection = MyGUI::Align::parse (_value); - } - else - { - EditBox::setPropertyOverride (_key, _value); - } - } - - - MyGUI::IntSize AutoSizedButton::getRequestedSize() - { - MyGUI::IntSize padding(24, 8); - if (isUserString("TextPadding")) - padding = MyGUI::IntSize::parse(getUserString("TextPadding")); - - MyGUI::IntSize size = getTextSize() + MyGUI::IntSize(padding.width,padding.height); - return size; - } - - void AutoSizedButton::setCaption(const MyGUI::UString& _value) - { - Button::setCaption(_value); - - notifySizeChange (this); - } - - void AutoSizedButton::setPropertyOverride(const std::string& _key, const std::string& _value) - { - if (_key == "ExpandDirection") - { - mExpandDirection = MyGUI::Align::parse (_value); - } - else - { - Button::setPropertyOverride (_key, _value); - } - } - - Box::Box() - : mSpacing(4) - , mPadding(0) - , mAutoResize(false) - { - - } - - void Box::notifyChildrenSizeChanged () - { - align(); - } - - bool Box::_setPropertyImpl(const std::string& _key, const std::string& _value) - { - if (_key == "Spacing") - mSpacing = MyGUI::utility::parseValue(_value); - else if (_key == "Padding") - mPadding = MyGUI::utility::parseValue(_value); - else if (_key == "AutoResize") - mAutoResize = MyGUI::utility::parseValue(_value); - else - return false; - - return true; - } - - void HBox::align () - { - unsigned int count = getChildCount (); - size_t h_stretched_count = 0; - int total_width = 0; - int total_height = 0; - std::vector< std::pair > sizes; - sizes.resize(count); - - for (unsigned int i = 0; i < count; ++i) - { - MyGUI::Widget* w = getChildAt(i); - bool hstretch = w->getUserString ("HStretch") == "true"; - bool hidden = w->getUserString("Hidden") == "true"; - if (hidden) - continue; - h_stretched_count += hstretch; - AutoSizedWidget* aw = dynamic_cast(w); - if (aw) - { - sizes[i] = std::make_pair(aw->getRequestedSize (), hstretch); - total_width += aw->getRequestedSize ().width; - total_height = std::max(total_height, aw->getRequestedSize ().height); - } - else - { - sizes[i] = std::make_pair(w->getSize(), hstretch); - total_width += w->getSize().width; - if (!(w->getUserString("VStretch") == "true")) - total_height = std::max(total_height, w->getSize().height); - } - - if (i != count-1) - total_width += mSpacing; - } - - if (mAutoResize && (total_width+mPadding*2 != getSize().width || total_height+mPadding*2 != getSize().height)) - { - setSize(MyGUI::IntSize(total_width+mPadding*2, total_height+mPadding*2)); - return; - } - - - int curX = 0; - for (unsigned int i = 0; i < count; ++i) - { - if (i == 0) - curX += mPadding; - - MyGUI::Widget* w = getChildAt(i); - - bool hidden = w->getUserString("Hidden") == "true"; - if (hidden) - continue; - - bool vstretch = w->getUserString ("VStretch") == "true"; - int max_height = getSize().height - mPadding*2; - int height = vstretch ? max_height : sizes[i].first.height; - - MyGUI::IntCoord widgetCoord; - widgetCoord.left = curX; - widgetCoord.top = mPadding + (getSize().height-mPadding*2 - height) / 2; - int width = sizes[i].second ? sizes[i].first.width + (getSize().width-mPadding*2 - total_width)/h_stretched_count - : sizes[i].first.width; - widgetCoord.width = width; - widgetCoord.height = height; - w->setCoord(widgetCoord); - curX += width; - - if (i != count-1) - curX += mSpacing; - } - } - - void HBox::setPropertyOverride(const std::string& _key, const std::string& _value) - { - if (!Box::_setPropertyImpl (_key, _value)) - MyGUI::Widget::setPropertyOverride(_key, _value); - } - - void HBox::setSize (const MyGUI::IntSize& _value) - { - MyGUI::Widget::setSize (_value); - align(); - } - - void HBox::setCoord (const MyGUI::IntCoord& _value) - { - MyGUI::Widget::setCoord (_value); - align(); - } - - void HBox::onWidgetCreated(MyGUI::Widget* _widget) - { - align(); - } - - MyGUI::IntSize HBox::getRequestedSize () - { - MyGUI::IntSize size(0,0); - for (unsigned int i = 0; i < getChildCount (); ++i) - { - bool hidden = getChildAt(i)->getUserString("Hidden") == "true"; - if (hidden) - continue; - - AutoSizedWidget* w = dynamic_cast(getChildAt(i)); - if (w) - { - MyGUI::IntSize requested = w->getRequestedSize (); - size.height = std::max(size.height, requested.height); - size.width = size.width + requested.width; - if (i != getChildCount()-1) - size.width += mSpacing; - } - else - { - MyGUI::IntSize requested = getChildAt(i)->getSize (); - size.height = std::max(size.height, requested.height); - - if (getChildAt(i)->getUserString("HStretch") != "true") - size.width = size.width + requested.width; - - if (i != getChildCount()-1) - size.width += mSpacing; - } - size.height += mPadding*2; - size.width += mPadding*2; - } - return size; - } - - - - - void VBox::align () - { - unsigned int count = getChildCount (); - size_t v_stretched_count = 0; - int total_height = 0; - int total_width = 0; - std::vector< std::pair > sizes; - sizes.resize(count); - for (unsigned int i = 0; i < count; ++i) - { - MyGUI::Widget* w = getChildAt(i); - - bool hidden = w->getUserString("Hidden") == "true"; - if (hidden) - continue; - - bool vstretch = w->getUserString ("VStretch") == "true"; - v_stretched_count += vstretch; - AutoSizedWidget* aw = dynamic_cast(w); - if (aw) - { - sizes[i] = std::make_pair(aw->getRequestedSize (), vstretch); - total_height += aw->getRequestedSize ().height; - total_width = std::max(total_width, aw->getRequestedSize ().width); - } - else - { - sizes[i] = std::make_pair(w->getSize(), vstretch); - total_height += w->getSize().height; - - if (!(w->getUserString("HStretch") == "true")) - total_width = std::max(total_width, w->getSize().width); - } - - if (i != count-1) - total_height += mSpacing; - } - - if (mAutoResize && (total_width+mPadding*2 != getSize().width || total_height+mPadding*2 != getSize().height)) - { - setSize(MyGUI::IntSize(total_width+mPadding*2, total_height+mPadding*2)); - return; - } - - - int curY = 0; - for (unsigned int i = 0; i < count; ++i) - { - if (i==0) - curY += mPadding; - - MyGUI::Widget* w = getChildAt(i); - - bool hidden = w->getUserString("Hidden") == "true"; - if (hidden) - continue; - - bool hstretch = w->getUserString ("HStretch") == "true"; - int maxWidth = getSize().width - mPadding*2; - int width = hstretch ? maxWidth : sizes[i].first.width; - - MyGUI::IntCoord widgetCoord; - widgetCoord.top = curY; - widgetCoord.left = mPadding + (getSize().width-mPadding*2 - width) / 2; - int height = sizes[i].second ? sizes[i].first.height + (getSize().height-mPadding*2 - total_height)/v_stretched_count - : sizes[i].first.height; - widgetCoord.height = height; - widgetCoord.width = width; - w->setCoord(widgetCoord); - curY += height; - - if (i != count-1) - curY += mSpacing; - } - } - - void VBox::setPropertyOverride(const std::string& _key, const std::string& _value) - { - if (!Box::_setPropertyImpl (_key, _value)) - MyGUI::Widget::setPropertyOverride(_key, _value); - } - - void VBox::setSize (const MyGUI::IntSize& _value) - { - MyGUI::Widget::setSize (_value); - align(); - } - - void VBox::setCoord (const MyGUI::IntCoord& _value) - { - MyGUI::Widget::setCoord (_value); - align(); - } - - MyGUI::IntSize VBox::getRequestedSize () - { - MyGUI::IntSize size(0,0); - for (unsigned int i = 0; i < getChildCount (); ++i) - { - bool hidden = getChildAt(i)->getUserString("Hidden") == "true"; - if (hidden) - continue; - - AutoSizedWidget* w = dynamic_cast(getChildAt(i)); - if (w) - { - MyGUI::IntSize requested = w->getRequestedSize (); - size.width = std::max(size.width, requested.width); - size.height = size.height + requested.height; - if (i != getChildCount()-1) - size.height += mSpacing; - } - else - { - MyGUI::IntSize requested = getChildAt(i)->getSize (); - size.width = std::max(size.width, requested.width); - - if (getChildAt(i)->getUserString("VStretch") != "true") - size.height = size.height + requested.height; - - if (i != getChildCount()-1) - size.height += mSpacing; - } - size.height += mPadding*2; - size.width += mPadding*2; - } - return size; - } - - void VBox::onWidgetCreated(MyGUI::Widget* _widget) - { - align(); - } - MWScrollBar::MWScrollBar() : mEnableRepeat(true) , mRepeatTriggerTime(0.5) diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index dad49eb45..10b723cae 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -298,118 +298,6 @@ namespace MWGui }; typedef MWDynamicStat* MWDynamicStatPtr; - - - - - // --------------------------------------------------------------------------------------------------------------------- - - - - class AutoSizedWidget - { - public: - virtual MyGUI::IntSize getRequestedSize() = 0; - - protected: - void notifySizeChange(MyGUI::Widget* w); - - MyGUI::Align mExpandDirection; - }; - - class AutoSizedTextBox : public AutoSizedWidget, public MyGUI::TextBox - { - MYGUI_RTTI_DERIVED( AutoSizedTextBox ) - - public: - virtual MyGUI::IntSize getRequestedSize(); - virtual void setCaption(const MyGUI::UString& _value); - - protected: - virtual void setPropertyOverride(const std::string& _key, const std::string& _value); - }; - - class AutoSizedEditBox : public AutoSizedWidget, public MyGUI::EditBox - { - MYGUI_RTTI_DERIVED( AutoSizedEditBox ) - - public: - virtual MyGUI::IntSize getRequestedSize(); - virtual void setCaption(const MyGUI::UString& _value); - - protected: - virtual void setPropertyOverride(const std::string& _key, const std::string& _value); - }; - - class AutoSizedButton : public AutoSizedWidget, public MyGUI::Button - { - MYGUI_RTTI_DERIVED( AutoSizedButton ) - - public: - virtual MyGUI::IntSize getRequestedSize(); - virtual void setCaption(const MyGUI::UString& _value); - - protected: - virtual void setPropertyOverride(const std::string& _key, const std::string& _value); - }; - - /** - * @brief A container widget that automatically sizes its children - * @note the box being an AutoSizedWidget as well allows to put boxes inside a box - */ - class Box : public AutoSizedWidget - { - public: - Box(); - - void notifyChildrenSizeChanged(); - - protected: - virtual void align() = 0; - - virtual bool _setPropertyImpl(const std::string& _key, const std::string& _value); - - int mSpacing; // how much space to put between elements - - int mPadding; // outer padding - - bool mAutoResize; // auto resize the box so that it exactly fits all elements - }; - - class HBox : public Box, public MyGUI::Widget - { - MYGUI_RTTI_DERIVED( HBox ) - - public: - virtual void setSize (const MyGUI::IntSize &_value); - virtual void setCoord (const MyGUI::IntCoord &_value); - - protected: - virtual void align(); - virtual MyGUI::IntSize getRequestedSize(); - - virtual void setPropertyOverride(const std::string& _key, const std::string& _value); - - virtual void onWidgetCreated(MyGUI::Widget* _widget); - }; - - class VBox : public Box, public MyGUI::Widget - { - MYGUI_RTTI_DERIVED( VBox) - - public: - virtual void setSize (const MyGUI::IntSize &_value); - virtual void setCoord (const MyGUI::IntCoord &_value); - - protected: - virtual void align(); - virtual MyGUI::IntSize getRequestedSize(); - - virtual void setPropertyOverride(const std::string& _key, const std::string& _value); - - virtual void onWidgetCreated(MyGUI::Widget* _widget); - }; - class MWScrollBar : public MyGUI::ScrollBar { MYGUI_RTTI_DERIVED(MWScrollBar) diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 5882ae2b6..ab791f090 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -18,6 +18,8 @@ #include +#include + #include "../mwbase/inputmanager.hpp" #include "../mwbase/statemanager.hpp" @@ -161,12 +163,12 @@ namespace MWGui MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 1178a3a28..50d11e9bb 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -92,7 +92,7 @@ add_component_dir (ogreinit ) add_component_dir (widgets - box + box imagebutton ) add_component_dir (fontloader diff --git a/components/widgets/box.cpp b/components/widgets/box.cpp new file mode 100644 index 000000000..6ec471b65 --- /dev/null +++ b/components/widgets/box.cpp @@ -0,0 +1,407 @@ +#include "box.hpp" + +namespace Gui +{ + + void AutoSizedWidget::notifySizeChange (MyGUI::Widget* w) + { + MyGUI::Widget * parent = w->getParent(); + if (parent != 0) + { + if (mExpandDirection == MyGUI::Align::Left) + { + int hdiff = getRequestedSize ().width - w->getSize().width; + w->setPosition(w->getPosition() - MyGUI::IntPoint(hdiff, 0)); + } + w->setSize(getRequestedSize ()); + + while (parent != 0) + { + Box * b = dynamic_cast(parent); + if (b) + b->notifyChildrenSizeChanged(); + else + break; + parent = parent->getParent(); + } + } + } + + + MyGUI::IntSize AutoSizedTextBox::getRequestedSize() + { + return getTextSize(); + } + + void AutoSizedTextBox::setCaption(const MyGUI::UString& _value) + { + TextBox::setCaption(_value); + + notifySizeChange (this); + } + + void AutoSizedTextBox::setPropertyOverride(const std::string& _key, const std::string& _value) + { + if (_key == "ExpandDirection") + { + mExpandDirection = MyGUI::Align::parse (_value); + } + else + { + TextBox::setPropertyOverride (_key, _value); + } + } + + MyGUI::IntSize AutoSizedEditBox::getRequestedSize() + { + if (getAlign().isHStretch()) + throw std::runtime_error("AutoSizedEditBox can't have HStretch align (" + getName() + ")"); + return MyGUI::IntSize(getSize().width, getTextSize().height); + } + + void AutoSizedEditBox::setCaption(const MyGUI::UString& _value) + { + EditBox::setCaption(_value); + + notifySizeChange (this); + } + + void AutoSizedEditBox::setPropertyOverride(const std::string& _key, const std::string& _value) + { + if (_key == "ExpandDirection") + { + mExpandDirection = MyGUI::Align::parse (_value); + } + else + { + EditBox::setPropertyOverride (_key, _value); + } + } + + + MyGUI::IntSize AutoSizedButton::getRequestedSize() + { + MyGUI::IntSize padding(24, 8); + if (isUserString("TextPadding")) + padding = MyGUI::IntSize::parse(getUserString("TextPadding")); + + MyGUI::IntSize size = getTextSize() + MyGUI::IntSize(padding.width,padding.height); + return size; + } + + void AutoSizedButton::setCaption(const MyGUI::UString& _value) + { + Button::setCaption(_value); + + notifySizeChange (this); + } + + void AutoSizedButton::setPropertyOverride(const std::string& _key, const std::string& _value) + { + if (_key == "ExpandDirection") + { + mExpandDirection = MyGUI::Align::parse (_value); + } + else + { + Button::setPropertyOverride (_key, _value); + } + } + + Box::Box() + : mSpacing(4) + , mPadding(0) + , mAutoResize(false) + { + + } + + void Box::notifyChildrenSizeChanged () + { + align(); + } + + bool Box::_setPropertyImpl(const std::string& _key, const std::string& _value) + { + if (_key == "Spacing") + mSpacing = MyGUI::utility::parseValue(_value); + else if (_key == "Padding") + mPadding = MyGUI::utility::parseValue(_value); + else if (_key == "AutoResize") + mAutoResize = MyGUI::utility::parseValue(_value); + else + return false; + + return true; + } + + void HBox::align () + { + unsigned int count = getChildCount (); + size_t h_stretched_count = 0; + int total_width = 0; + int total_height = 0; + std::vector< std::pair > sizes; + sizes.resize(count); + + for (unsigned int i = 0; i < count; ++i) + { + MyGUI::Widget* w = getChildAt(i); + bool hstretch = w->getUserString ("HStretch") == "true"; + bool hidden = w->getUserString("Hidden") == "true"; + if (hidden) + continue; + h_stretched_count += hstretch; + AutoSizedWidget* aw = dynamic_cast(w); + if (aw) + { + sizes[i] = std::make_pair(aw->getRequestedSize (), hstretch); + total_width += aw->getRequestedSize ().width; + total_height = std::max(total_height, aw->getRequestedSize ().height); + } + else + { + sizes[i] = std::make_pair(w->getSize(), hstretch); + total_width += w->getSize().width; + if (!(w->getUserString("VStretch") == "true")) + total_height = std::max(total_height, w->getSize().height); + } + + if (i != count-1) + total_width += mSpacing; + } + + if (mAutoResize && (total_width+mPadding*2 != getSize().width || total_height+mPadding*2 != getSize().height)) + { + setSize(MyGUI::IntSize(total_width+mPadding*2, total_height+mPadding*2)); + return; + } + + + int curX = 0; + for (unsigned int i = 0; i < count; ++i) + { + if (i == 0) + curX += mPadding; + + MyGUI::Widget* w = getChildAt(i); + + bool hidden = w->getUserString("Hidden") == "true"; + if (hidden) + continue; + + bool vstretch = w->getUserString ("VStretch") == "true"; + int max_height = getSize().height - mPadding*2; + int height = vstretch ? max_height : sizes[i].first.height; + + MyGUI::IntCoord widgetCoord; + widgetCoord.left = curX; + widgetCoord.top = mPadding + (getSize().height-mPadding*2 - height) / 2; + int width = sizes[i].second ? sizes[i].first.width + (getSize().width-mPadding*2 - total_width)/h_stretched_count + : sizes[i].first.width; + widgetCoord.width = width; + widgetCoord.height = height; + w->setCoord(widgetCoord); + curX += width; + + if (i != count-1) + curX += mSpacing; + } + } + + void HBox::setPropertyOverride(const std::string& _key, const std::string& _value) + { + if (!Box::_setPropertyImpl (_key, _value)) + MyGUI::Widget::setPropertyOverride(_key, _value); + } + + void HBox::setSize (const MyGUI::IntSize& _value) + { + MyGUI::Widget::setSize (_value); + align(); + } + + void HBox::setCoord (const MyGUI::IntCoord& _value) + { + MyGUI::Widget::setCoord (_value); + align(); + } + + void HBox::onWidgetCreated(MyGUI::Widget* _widget) + { + align(); + } + + MyGUI::IntSize HBox::getRequestedSize () + { + MyGUI::IntSize size(0,0); + for (unsigned int i = 0; i < getChildCount (); ++i) + { + bool hidden = getChildAt(i)->getUserString("Hidden") == "true"; + if (hidden) + continue; + + AutoSizedWidget* w = dynamic_cast(getChildAt(i)); + if (w) + { + MyGUI::IntSize requested = w->getRequestedSize (); + size.height = std::max(size.height, requested.height); + size.width = size.width + requested.width; + if (i != getChildCount()-1) + size.width += mSpacing; + } + else + { + MyGUI::IntSize requested = getChildAt(i)->getSize (); + size.height = std::max(size.height, requested.height); + + if (getChildAt(i)->getUserString("HStretch") != "true") + size.width = size.width + requested.width; + + if (i != getChildCount()-1) + size.width += mSpacing; + } + size.height += mPadding*2; + size.width += mPadding*2; + } + return size; + } + + + + + void VBox::align () + { + unsigned int count = getChildCount (); + size_t v_stretched_count = 0; + int total_height = 0; + int total_width = 0; + std::vector< std::pair > sizes; + sizes.resize(count); + for (unsigned int i = 0; i < count; ++i) + { + MyGUI::Widget* w = getChildAt(i); + + bool hidden = w->getUserString("Hidden") == "true"; + if (hidden) + continue; + + bool vstretch = w->getUserString ("VStretch") == "true"; + v_stretched_count += vstretch; + AutoSizedWidget* aw = dynamic_cast(w); + if (aw) + { + sizes[i] = std::make_pair(aw->getRequestedSize (), vstretch); + total_height += aw->getRequestedSize ().height; + total_width = std::max(total_width, aw->getRequestedSize ().width); + } + else + { + sizes[i] = std::make_pair(w->getSize(), vstretch); + total_height += w->getSize().height; + + if (!(w->getUserString("HStretch") == "true")) + total_width = std::max(total_width, w->getSize().width); + } + + if (i != count-1) + total_height += mSpacing; + } + + if (mAutoResize && (total_width+mPadding*2 != getSize().width || total_height+mPadding*2 != getSize().height)) + { + setSize(MyGUI::IntSize(total_width+mPadding*2, total_height+mPadding*2)); + return; + } + + + int curY = 0; + for (unsigned int i = 0; i < count; ++i) + { + if (i==0) + curY += mPadding; + + MyGUI::Widget* w = getChildAt(i); + + bool hidden = w->getUserString("Hidden") == "true"; + if (hidden) + continue; + + bool hstretch = w->getUserString ("HStretch") == "true"; + int maxWidth = getSize().width - mPadding*2; + int width = hstretch ? maxWidth : sizes[i].first.width; + + MyGUI::IntCoord widgetCoord; + widgetCoord.top = curY; + widgetCoord.left = mPadding + (getSize().width-mPadding*2 - width) / 2; + int height = sizes[i].second ? sizes[i].first.height + (getSize().height-mPadding*2 - total_height)/v_stretched_count + : sizes[i].first.height; + widgetCoord.height = height; + widgetCoord.width = width; + w->setCoord(widgetCoord); + curY += height; + + if (i != count-1) + curY += mSpacing; + } + } + + void VBox::setPropertyOverride(const std::string& _key, const std::string& _value) + { + if (!Box::_setPropertyImpl (_key, _value)) + MyGUI::Widget::setPropertyOverride(_key, _value); + } + + void VBox::setSize (const MyGUI::IntSize& _value) + { + MyGUI::Widget::setSize (_value); + align(); + } + + void VBox::setCoord (const MyGUI::IntCoord& _value) + { + MyGUI::Widget::setCoord (_value); + align(); + } + + MyGUI::IntSize VBox::getRequestedSize () + { + MyGUI::IntSize size(0,0); + for (unsigned int i = 0; i < getChildCount (); ++i) + { + bool hidden = getChildAt(i)->getUserString("Hidden") == "true"; + if (hidden) + continue; + + AutoSizedWidget* w = dynamic_cast(getChildAt(i)); + if (w) + { + MyGUI::IntSize requested = w->getRequestedSize (); + size.width = std::max(size.width, requested.width); + size.height = size.height + requested.height; + if (i != getChildCount()-1) + size.height += mSpacing; + } + else + { + MyGUI::IntSize requested = getChildAt(i)->getSize (); + size.width = std::max(size.width, requested.width); + + if (getChildAt(i)->getUserString("VStretch") != "true") + size.height = size.height + requested.height; + + if (i != getChildCount()-1) + size.height += mSpacing; + } + size.height += mPadding*2; + size.width += mPadding*2; + } + return size; + } + + void VBox::onWidgetCreated(MyGUI::Widget* _widget) + { + align(); + } + +} diff --git a/components/widgets/box.hpp b/components/widgets/box.hpp new file mode 100644 index 000000000..40e76aca0 --- /dev/null +++ b/components/widgets/box.hpp @@ -0,0 +1,118 @@ +#ifndef OPENMW_WIDGETS_BOX_H +#define OPENMW_WIDGETS_BOX_H + +#include +#include +#include +#include + +namespace Gui +{ + + class AutoSizedWidget + { + public: + virtual MyGUI::IntSize getRequestedSize() = 0; + + protected: + void notifySizeChange(MyGUI::Widget* w); + + MyGUI::Align mExpandDirection; + }; + + class AutoSizedTextBox : public AutoSizedWidget, public MyGUI::TextBox + { + MYGUI_RTTI_DERIVED( AutoSizedTextBox ) + + public: + virtual MyGUI::IntSize getRequestedSize(); + virtual void setCaption(const MyGUI::UString& _value); + + protected: + virtual void setPropertyOverride(const std::string& _key, const std::string& _value); + }; + + class AutoSizedEditBox : public AutoSizedWidget, public MyGUI::EditBox + { + MYGUI_RTTI_DERIVED( AutoSizedEditBox ) + + public: + virtual MyGUI::IntSize getRequestedSize(); + virtual void setCaption(const MyGUI::UString& _value); + + protected: + virtual void setPropertyOverride(const std::string& _key, const std::string& _value); + }; + + class AutoSizedButton : public AutoSizedWidget, public MyGUI::Button + { + MYGUI_RTTI_DERIVED( AutoSizedButton ) + + public: + virtual MyGUI::IntSize getRequestedSize(); + virtual void setCaption(const MyGUI::UString& _value); + + protected: + virtual void setPropertyOverride(const std::string& _key, const std::string& _value); + }; + + /** + * @brief A container widget that automatically sizes its children + * @note the box being an AutoSizedWidget as well allows to put boxes inside a box + */ + class Box : public AutoSizedWidget + { + public: + Box(); + + void notifyChildrenSizeChanged(); + + protected: + virtual void align() = 0; + + virtual bool _setPropertyImpl(const std::string& _key, const std::string& _value); + + int mSpacing; // how much space to put between elements + + int mPadding; // outer padding + + bool mAutoResize; // auto resize the box so that it exactly fits all elements + }; + + class HBox : public Box, public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( HBox ) + + public: + virtual void setSize (const MyGUI::IntSize &_value); + virtual void setCoord (const MyGUI::IntCoord &_value); + + protected: + virtual void align(); + virtual MyGUI::IntSize getRequestedSize(); + + virtual void setPropertyOverride(const std::string& _key, const std::string& _value); + + virtual void onWidgetCreated(MyGUI::Widget* _widget); + }; + + class VBox : public Box, public MyGUI::Widget + { + MYGUI_RTTI_DERIVED( VBox) + + public: + virtual void setSize (const MyGUI::IntSize &_value); + virtual void setCoord (const MyGUI::IntCoord &_value); + + protected: + virtual void align(); + virtual MyGUI::IntSize getRequestedSize(); + + virtual void setPropertyOverride(const std::string& _key, const std::string& _value); + + virtual void onWidgetCreated(MyGUI::Widget* _widget); + }; + +} + +#endif diff --git a/apps/openmw/mwgui/imagebutton.cpp b/components/widgets/imagebutton.cpp similarity index 99% rename from apps/openmw/mwgui/imagebutton.cpp rename to components/widgets/imagebutton.cpp index f2565f5c0..24e4d9a62 100644 --- a/apps/openmw/mwgui/imagebutton.cpp +++ b/components/widgets/imagebutton.cpp @@ -2,7 +2,7 @@ #include -namespace MWGui +namespace Gui { void ImageButton::setPropertyOverride(const std::string &_key, const std::string &_value) diff --git a/apps/openmw/mwgui/imagebutton.hpp b/components/widgets/imagebutton.hpp similarity index 98% rename from apps/openmw/mwgui/imagebutton.hpp rename to components/widgets/imagebutton.hpp index f4191a3a5..bed6a2794 100644 --- a/apps/openmw/mwgui/imagebutton.hpp +++ b/components/widgets/imagebutton.hpp @@ -3,7 +3,7 @@ #include -namespace MWGui +namespace Gui { /** diff --git a/libs/mygui_resource_plugin/plugin.cpp b/libs/mygui_resource_plugin/plugin.cpp index 02088f693..a3d178051 100644 --- a/libs/mygui_resource_plugin/plugin.cpp +++ b/libs/mygui_resource_plugin/plugin.cpp @@ -4,11 +4,15 @@ #include #include #include +#include #include #include #include +#include +#include + #include #include @@ -47,6 +51,12 @@ namespace MyGUIPlugin MYGUI_RTTI_DERIVED( MWDynamicStat ) }; + // Dummy - runtime use only + class ExposedWindow : public MyGUI::Window + { + MYGUI_RTTI_DERIVED( ExposedWindow ) + }; + const std::string& ResourcePlugin::getName() const { @@ -114,6 +124,13 @@ namespace MyGUIPlugin void ResourcePlugin::registerWidgets() { MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); } void ResourcePlugin::createTransparentBGTexture() From a413e91442a212a156cce118eeb03250da8a138f Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 12 Sep 2014 05:17:45 +0200 Subject: [PATCH 04/11] ImageButton: get texture size from MyGUI, rather than from Ogre --- components/widgets/imagebutton.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/widgets/imagebutton.cpp b/components/widgets/imagebutton.cpp index 24e4d9a62..1cd882975 100644 --- a/components/widgets/imagebutton.cpp +++ b/components/widgets/imagebutton.cpp @@ -1,6 +1,6 @@ #include "imagebutton.hpp" -#include +#include namespace Gui { @@ -44,8 +44,8 @@ namespace Gui MyGUI::IntSize ImageButton::getRequestedSize(bool logError) { - Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(mImageNormal); - if (texture.isNull()) + MyGUI::ITexture* texture = MyGUI::RenderManager::getInstance().getTexture(mImageNormal); + if (!texture) { if (logError) std::cerr << "ImageButton: can't find " << mImageNormal << std::endl; From 33636e218b18201984c730fb15e3254473c2d623 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 12 Sep 2014 07:17:14 +0200 Subject: [PATCH 05/11] Remove unneeded dummies --- libs/mygui_resource_plugin/plugin.cpp | 33 --------------------------- 1 file changed, 33 deletions(-) diff --git a/libs/mygui_resource_plugin/plugin.cpp b/libs/mygui_resource_plugin/plugin.cpp index a3d178051..793b0c9a5 100644 --- a/libs/mygui_resource_plugin/plugin.cpp +++ b/libs/mygui_resource_plugin/plugin.cpp @@ -25,39 +25,6 @@ namespace MyGUIPlugin MYGUI_RTTI_DERIVED(MWScrollBar) }; - // Dummy - not properly supportable without bringing in the whole ESM store - class MWSkill : public MyGUI::Widget - { - MYGUI_RTTI_DERIVED( MWSkill ) - }; - class MWAttribute : public MyGUI::Widget - { - MYGUI_RTTI_DERIVED( MWAttribute ) - }; - class MWSpell : public MyGUI::Widget - { - MYGUI_RTTI_DERIVED( MWSpell ) - }; - class MWEffectList : public MyGUI::Widget - { - MYGUI_RTTI_DERIVED( MWEffectList ) - }; - class MWSpellEffect : public MyGUI::Widget - { - MYGUI_RTTI_DERIVED( MWSpellEffect ) - }; - class MWDynamicStat : public MyGUI::Widget - { - MYGUI_RTTI_DERIVED( MWDynamicStat ) - }; - - // Dummy - runtime use only - class ExposedWindow : public MyGUI::Window - { - MYGUI_RTTI_DERIVED( ExposedWindow ) - }; - - const std::string& ResourcePlugin::getName() const { static const std::string name = "OpenMW resource plugin"; From 9d057185157544d0cad307dff78ec04ccee4b876 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 12 Sep 2014 19:27:49 +0200 Subject: [PATCH 06/11] Move plugin to new plugins/ top level directory --- CMakeLists.txt | 3 ++- {libs => plugins}/mygui_resource_plugin/CMakeLists.txt | 0 {libs => plugins}/mygui_resource_plugin/plugin.cpp | 0 {libs => plugins}/mygui_resource_plugin/plugin.hpp | 0 {libs => plugins}/mygui_resource_plugin/plugin_export.cpp | 0 5 files changed, 2 insertions(+), 1 deletion(-) rename {libs => plugins}/mygui_resource_plugin/CMakeLists.txt (100%) rename {libs => plugins}/mygui_resource_plugin/plugin.cpp (100%) rename {libs => plugins}/mygui_resource_plugin/plugin.hpp (100%) rename {libs => plugins}/mygui_resource_plugin/plugin_export.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6ceaa668..05b8d0cd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -531,8 +531,9 @@ add_subdirectory (extern/sdl4ogre) # Components add_subdirectory (components) +# Plugins if (BUILD_MYGUI_PLUGIN) - add_subdirectory(libs/mygui_resource_plugin) + add_subdirectory(plugins/mygui_resource_plugin) endif() #Testing diff --git a/libs/mygui_resource_plugin/CMakeLists.txt b/plugins/mygui_resource_plugin/CMakeLists.txt similarity index 100% rename from libs/mygui_resource_plugin/CMakeLists.txt rename to plugins/mygui_resource_plugin/CMakeLists.txt diff --git a/libs/mygui_resource_plugin/plugin.cpp b/plugins/mygui_resource_plugin/plugin.cpp similarity index 100% rename from libs/mygui_resource_plugin/plugin.cpp rename to plugins/mygui_resource_plugin/plugin.cpp diff --git a/libs/mygui_resource_plugin/plugin.hpp b/plugins/mygui_resource_plugin/plugin.hpp similarity index 100% rename from libs/mygui_resource_plugin/plugin.hpp rename to plugins/mygui_resource_plugin/plugin.hpp diff --git a/libs/mygui_resource_plugin/plugin_export.cpp b/plugins/mygui_resource_plugin/plugin_export.cpp similarity index 100% rename from libs/mygui_resource_plugin/plugin_export.cpp rename to plugins/mygui_resource_plugin/plugin_export.cpp From cfc57d0fe0e0fd6b187f9ce29f4b4a378a5753f3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 13 Sep 2014 04:07:40 +0200 Subject: [PATCH 07/11] Use MyGUI's castType for widget casts --- apps/openmw/mwgui/dialogue.cpp | 2 +- apps/openmw/mwgui/inventorywindow.cpp | 4 ++-- apps/openmw/mwgui/list.cpp | 2 +- apps/openmw/mwgui/settingswindow.cpp | 6 +++--- apps/openmw/mwgui/statswindow.cpp | 6 +++--- apps/openmw/mwgui/statswindow.hpp | 2 +- apps/openmw/mwgui/tradewindow.cpp | 2 +- apps/openmw/mwgui/waitdialog.cpp | 5 ++++- apps/openmw/mwgui/widgets.cpp | 24 ++++++++++++------------ apps/openmw/mwgui/widgets.hpp | 10 +++++----- apps/openmw/mwgui/windowpinnablebase.cpp | 2 +- 11 files changed, 34 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 94b2c4b0e..33b768dfc 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -266,7 +266,7 @@ namespace MWGui BookPage::ClickCallback callback = boost::bind (&DialogueWindow::notifyLinkClicked, this, _1); mHistory->adviseLinkClicked(callback); - static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &DialogueWindow::onWindowResize); + mMainWidget->castType()->eventWindowChangeCoord += MyGUI::newDelegate(this, &DialogueWindow::onWindowResize); } void DialogueWindow::exit() diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 441d8c28f..4490f3db2 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -42,7 +42,7 @@ namespace MWGui , mSelectedItem(-1) , mGuiMode(GM_Inventory) { - static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize); + mMainWidget->castType()->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize); getWidget(mAvatar, "Avatar"); getWidget(mAvatarImage, "AvatarImage"); @@ -368,7 +368,7 @@ namespace MWGui mItemView->update(); - static_cast(_sender)->setStateSelected(true); + _sender->castType()->setStateSelected(true); } void InventoryWindow::onPinToggled() diff --git a/apps/openmw/mwgui/list.cpp b/apps/openmw/mwgui/list.cpp index e88d43534..ff14bcf61 100644 --- a/apps/openmw/mwgui/list.cpp +++ b/apps/openmw/mwgui/list.cpp @@ -154,7 +154,7 @@ namespace MWGui void MWList::onItemSelected(MyGUI::Widget* _sender) { - std::string name = static_cast(_sender)->getCaption(); + std::string name = _sender->castType()->getCaption(); int id = *_sender->getUserData(); eventItemSelected(name, id); eventWidgetSelected(_sender); diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index abeb6b86c..c3fbe88ab 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -370,10 +370,10 @@ namespace MWGui void SettingsWindow::onShaderModeToggled(MyGUI::Widget* _sender) { - std::string val = static_cast(_sender)->getCaption(); + std::string val = _sender->castType()->getCaption(); val = hlslGlsl(); - static_cast(_sender)->setCaption(val); + _sender->castType()->setCaption(val); Settings::Manager::setString("shader mode", "General", val); @@ -483,7 +483,7 @@ namespace MWGui { int actionId = *_sender->getUserData(); - static_cast(_sender)->setCaptionWithReplacing("#{sNone}"); + _sender->castType()->setCaptionWithReplacing("#{sNone}"); MWBase::Environment::get().getWindowManager ()->staticMessageBox ("#{sControlsMenu3}"); MWBase::Environment::get().getWindowManager ()->disallowMouse(); diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index edc85e8df..f55c96705 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -66,7 +66,7 @@ namespace MWGui mSkillWidgetMap.insert(std::pair(i, (MyGUI::TextBox*)NULL)); } - MyGUI::WindowPtr t = static_cast(mMainWidget); + MyGUI::Window* t = mMainWidget->castType(); t->eventWindowChangeCoord += MyGUI::newDelegate(this, &StatsWindow::onWindowResize); } @@ -90,7 +90,7 @@ namespace MWGui void StatsWindow::setBar(const std::string& name, const std::string& tname, int val, int max) { - MyGUI::ProgressPtr pt; + MyGUI::ProgressBar* pt; getWidget(pt, name); pt->setProgressRange(max); pt->setProgressPosition(val); @@ -102,7 +102,7 @@ namespace MWGui void StatsWindow::setPlayerName(const std::string& playerName) { - static_cast(mMainWidget)->setCaption(playerName); + mMainWidget->castType()->setCaption(playerName); adjustWindowCaption(); } diff --git a/apps/openmw/mwgui/statswindow.hpp b/apps/openmw/mwgui/statswindow.hpp index 1a62b6d6b..f41995ac0 100644 --- a/apps/openmw/mwgui/statswindow.hpp +++ b/apps/openmw/mwgui/statswindow.hpp @@ -37,7 +37,7 @@ namespace MWGui void setBounty (int bounty) { if (bounty != mBounty) mChanged = true; this->mBounty = bounty; } void updateSkillArea(); - virtual void open() { onWindowResize(static_cast(mMainWidget)); } + virtual void open() { onWindowResize(mMainWidget->castType()); } private: void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 67bdc14ac..9393446f1 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -138,7 +138,7 @@ namespace MWGui mFilterMagic->setStateSelected(false); mFilterMisc->setStateSelected(false); - static_cast(_sender)->setStateSelected(true); + _sender->castType()->setStateSelected(true); mItemView->update(); } diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index ac70d3eed..f95ec5675 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -192,7 +192,10 @@ namespace MWGui mSleeping = canRest; - dynamic_cast(mMainWidget)->notifyChildrenSizeChanged(); + Gui::Box* box = dynamic_cast(mMainWidget); + if (box == NULL) + throw std::runtime_error("main widget must be a box"); + box->notifyChildrenSizeChanged(); center(); } diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 5c5b9b894..b45f7d59c 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -59,18 +59,18 @@ namespace MWGui { if (mSkillId == ESM::Skill::Length) { - static_cast(mSkillNameWidget)->setCaption(""); + mSkillNameWidget->setCaption(""); } else { const std::string &name = MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Skill::sSkillNameIds[mSkillId], ""); - static_cast(mSkillNameWidget)->setCaption(name); + mSkillNameWidget->setCaption(name); } } if (mSkillValueWidget) { SkillValue::Type modified = mValue.getModified(), base = mValue.getBase(); - static_cast(mSkillValueWidget)->setCaption(boost::lexical_cast(modified)); + mSkillValueWidget->setCaption(boost::lexical_cast(modified)); if (modified > base) mSkillValueWidget->_setWidgetState("increased"); else if (modified < base) @@ -145,7 +145,7 @@ namespace MWGui { if (mId < 0 || mId >= 8) { - static_cast(mAttributeNameWidget)->setCaption(""); + mAttributeNameWidget->setCaption(""); } else { @@ -160,13 +160,13 @@ namespace MWGui "sAttributeLuck" }; const std::string &name = MWBase::Environment::get().getWindowManager()->getGameSettingString(attributes[mId], ""); - static_cast(mAttributeNameWidget)->setCaption(name); + mAttributeNameWidget->setCaption(name); } } if (mAttributeValueWidget) { int modified = mValue.getModified(), base = mValue.getBase(); - static_cast(mAttributeValueWidget)->setCaption(boost::lexical_cast(modified)); + mAttributeValueWidget->setCaption(boost::lexical_cast(modified)); if (modified > base) mAttributeValueWidget->_setWidgetState("increased"); else if (modified < base) @@ -256,9 +256,9 @@ namespace MWGui const ESM::Spell *spell = store.get().search(mId); if (spell) - static_cast(mSpellNameWidget)->setCaption(spell->mName); + mSpellNameWidget->setCaption(spell->mName); else - static_cast(mSpellNameWidget)->setCaption(""); + mSpellNameWidget->setCaption(""); } } @@ -310,7 +310,7 @@ namespace MWGui // ... then adjust the size for all widgets for (std::vector::iterator it = effects.begin(); it != effects.end(); ++it) { - effect = static_cast(*it); + effect = (*it)->castType(); bool needcenter = center && (maxwidth > effect->getRequestedWidth()); int diff = maxwidth - effect->getRequestedWidth(); if (needcenter) @@ -470,7 +470,7 @@ namespace MWGui } } - static_cast(mTextWidget)->setCaptionWithReplacing(spellLine); + mTextWidget->setCaptionWithReplacing(spellLine); mRequestedWidth = mTextWidget->getTextSize().width + 24; mImageWidget->setImageTexture(Misc::ResourceHelpers::correctIconPath(magicEffect->mIcon)); @@ -515,13 +515,13 @@ namespace MWGui { std::stringstream out; out << mValue << "/" << mMax; - static_cast(mBarTextWidget)->setCaption(out.str().c_str()); + mBarTextWidget->setCaption(out.str().c_str()); } } void MWDynamicStat::setTitle(const std::string& text) { if (mTextWidget) - static_cast(mTextWidget)->setCaption(text); + mTextWidget->setCaption(text); } MWDynamicStat::~MWDynamicStat() diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 10b723cae..fc13b7ce5 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -122,8 +122,8 @@ namespace MWGui ESM::Skill::SkillEnum mSkillId; SkillValue mValue; - MyGUI::Widget* mSkillNameWidget; - MyGUI::Widget* mSkillValueWidget; + MyGUI::TextBox* mSkillNameWidget; + MyGUI::TextBox* mSkillValueWidget; }; typedef MWSkill* MWSkillPtr; @@ -162,8 +162,8 @@ namespace MWGui int mId; AttributeValue mValue; - MyGUI::Widget* mAttributeNameWidget; - MyGUI::Widget* mAttributeValueWidget; + MyGUI::TextBox* mAttributeNameWidget; + MyGUI::TextBox* mAttributeValueWidget; }; typedef MWAttribute* MWAttributePtr; @@ -293,7 +293,7 @@ namespace MWGui int mValue, mMax; MyGUI::TextBox* mTextWidget; - MyGUI::ProgressPtr mBarWidget; + MyGUI::ProgressBar* mBarWidget; MyGUI::TextBox* mBarTextWidget; }; typedef MWDynamicStat* MWDynamicStatPtr; diff --git a/apps/openmw/mwgui/windowpinnablebase.cpp b/apps/openmw/mwgui/windowpinnablebase.cpp index 92ba5876d..f9bbca665 100644 --- a/apps/openmw/mwgui/windowpinnablebase.cpp +++ b/apps/openmw/mwgui/windowpinnablebase.cpp @@ -7,7 +7,7 @@ namespace MWGui WindowPinnableBase::WindowPinnableBase(const std::string& parLayout) : WindowBase(parLayout), mPinned(false) { - ExposedWindow* window = static_cast(mMainWidget); + ExposedWindow* window = mMainWidget->castType(); mPinButton = window->getSkinWidget ("Button"); mPinButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WindowPinnableBase::onPinButtonClicked); From 2b5adb325b00ea6cbd4eb5797034756ab1da2e7d Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 13 Sep 2014 07:57:15 +0200 Subject: [PATCH 08/11] Remove a useless method --- apps/openmw/mwbase/windowmanager.hpp | 2 -- apps/openmw/mwgui/windowmanagerimp.cpp | 5 +---- apps/openmw/mwgui/windowmanagerimp.hpp | 2 -- libs/openengine/gui/manager.hpp | 2 -- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index f1c69e622..b4332b0fd 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -145,8 +145,6 @@ namespace MWBase virtual MWGui::SpellWindow* getSpellWindow() = 0; virtual MWGui::Console* getConsole() = 0; - virtual MyGUI::Gui* getGui() const = 0; - virtual void wmUpdateFps(float fps, unsigned int triangleCount, unsigned int batchCount) = 0; /// Set value for the given ID. diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index ab791f090..a109c8c20 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -149,7 +149,6 @@ namespace MWGui { // Set up the GUI system mGuiManager = new OEngine::GUI::MyGUIManager(mRendering->getWindow(), mRendering->getScene(), false, logpath); - mGui = mGuiManager->getGui(); // Load fonts Gui::FontLoader fontLoader (encoding); @@ -272,7 +271,7 @@ namespace MWGui trackWindow(mCompanionWindow, "companion"); mScreenFader = new ScreenFader(); - mInputBlocker = mGui->createWidget("",0,0,w,h,MyGUI::Align::Stretch,"Overlay"); + mInputBlocker = MyGUI::Gui::getInstance().createWidget("",0,0,w,h,MyGUI::Align::Stretch,"Overlay"); mHud->setVisible(mHudEnabled); @@ -1207,8 +1206,6 @@ namespace MWGui mBatchCount = batchCount; } - MyGUI::Gui* WindowManager::getGui() const { return mGui; } - MWGui::DialogueWindow* WindowManager::getDialogueWindow() { return mDialogueWindow; } MWGui::ContainerWindow* WindowManager::getContainerWindow() { return mContainerWindow; } MWGui::InventoryWindow* WindowManager::getInventoryWindow() { return mInventoryWindow; } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 00a5ce80e..8dc9d1b38 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -161,8 +161,6 @@ namespace MWGui virtual MWGui::SpellWindow* getSpellWindow(); virtual MWGui::Console* getConsole(); - virtual MyGUI::Gui* getGui() const; - virtual void wmUpdateFps(float fps, unsigned int triangleCount, unsigned int batchCount); ///< Set value for the given ID. diff --git a/libs/openengine/gui/manager.hpp b/libs/openengine/gui/manager.hpp index 8923a5cc8..3fb5245f3 100644 --- a/libs/openengine/gui/manager.hpp +++ b/libs/openengine/gui/manager.hpp @@ -49,8 +49,6 @@ namespace GUI void setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false, const std::string& logDir = std::string("")); void shutdown(); - - MyGUI::Gui *getGui() { return mGui; } }; } } From 2c58a879ec756fddacd15c537b8a69d6079b3916 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 13 Sep 2014 07:59:29 +0200 Subject: [PATCH 09/11] Fix minor exploit when map window is shown with transparency --- apps/openmw/mwgui/mapwindow.cpp | 9 +++++++++ apps/openmw/mwgui/mapwindow.hpp | 2 ++ apps/openmw/mwgui/windowbase.cpp | 9 +++++++-- apps/openmw/mwgui/windowbase.hpp | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index 1968181ce..d93b01ce4 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -844,6 +844,15 @@ namespace MWGui } } + void MapWindow::setAlpha(float alpha) + { + NoDrop::setAlpha(alpha); + // can't allow showing map with partial transparency, as the fog of war will also go transparent + // and reveal parts of the map you shouldn't be able to see + for (std::vector::iterator it = mMapWidgets.begin(); it != mMapWidgets.end(); ++it) + (*it)->setVisible(alpha == 1); + } + // ------------------------------------------------------------------- EditNoteDialog::EditNoteDialog() diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp index a9edbe0b1..08a9118a9 100644 --- a/apps/openmw/mwgui/mapwindow.hpp +++ b/apps/openmw/mwgui/mapwindow.hpp @@ -171,6 +171,8 @@ namespace MWGui void setCellName(const std::string& cellName); + virtual void setAlpha(float alpha); + void renderGlobalMap(Loading::Listener* loadingListener); // adds the marker to the global map diff --git a/apps/openmw/mwgui/windowbase.cpp b/apps/openmw/mwgui/windowbase.cpp index 4af0afc1f..c4bda0bae 100644 --- a/apps/openmw/mwgui/windowbase.cpp +++ b/apps/openmw/mwgui/windowbase.cpp @@ -96,11 +96,16 @@ void NoDrop::onFrame(float dt) if (mTransparent) { mWidget->setNeedMouseFocus(false); // Allow click-through - mWidget->setAlpha(std::max(0.13f, mWidget->getAlpha() - dt*5)); + setAlpha(std::max(0.13f, mWidget->getAlpha() - dt*5)); } else { mWidget->setNeedMouseFocus(true); - mWidget->setAlpha(std::min(1.0f, mWidget->getAlpha() + dt*5)); + setAlpha(std::min(1.0f, mWidget->getAlpha() + dt*5)); } } + +void NoDrop::setAlpha(float alpha) +{ + mWidget->setAlpha(alpha); +} diff --git a/apps/openmw/mwgui/windowbase.hpp b/apps/openmw/mwgui/windowbase.hpp index 53b10b452..bf74c8bf0 100644 --- a/apps/openmw/mwgui/windowbase.hpp +++ b/apps/openmw/mwgui/windowbase.hpp @@ -55,6 +55,7 @@ namespace MWGui NoDrop(DragAndDrop* drag, MyGUI::Widget* widget); void onFrame(float dt); + virtual void setAlpha(float alpha); private: MyGUI::Widget* mWidget; From f82224497a00f7f4117c532bdcd9891937a86eb7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 13 Sep 2014 08:00:24 +0200 Subject: [PATCH 10/11] Compatibility fix for MyGUI git --- apps/openmw/mwgui/controllers.cpp | 14 +++++++------- apps/openmw/mwgui/controllers.hpp | 9 +++++---- apps/openmw/mwgui/tradewindow.cpp | 4 ++-- apps/openmw/mwgui/widgets.cpp | 8 ++++---- apps/openmw/mwgui/widgets.hpp | 1 + apps/openmw/mwgui/windowmanagerimp.cpp | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwgui/controllers.cpp b/apps/openmw/mwgui/controllers.cpp index a50e6496c..5ebd2b1e7 100644 --- a/apps/openmw/mwgui/controllers.cpp +++ b/apps/openmw/mwgui/controllers.cpp @@ -7,7 +7,7 @@ namespace MWGui namespace Controllers { - ControllerRepeatClick::ControllerRepeatClick() : + ControllerRepeatEvent::ControllerRepeatEvent() : mInit(0.5), mStep(0.1), mEnabled(true), @@ -15,11 +15,11 @@ namespace MWGui { } - ControllerRepeatClick::~ControllerRepeatClick() + ControllerRepeatEvent::~ControllerRepeatEvent() { } - bool ControllerRepeatClick::addTime(MyGUI::Widget* _widget, float _time) + bool ControllerRepeatEvent::addTime(MyGUI::Widget* _widget, float _time) { if(mTimeLeft == 0) mTimeLeft = mInit; @@ -33,22 +33,22 @@ namespace MWGui return true; } - void ControllerRepeatClick::setRepeat(float init, float step) + void ControllerRepeatEvent::setRepeat(float init, float step) { mInit = init; mStep = step; } - void ControllerRepeatClick::setEnabled(bool enable) + void ControllerRepeatEvent::setEnabled(bool enable) { mEnabled = enable; } - void ControllerRepeatClick::setProperty(const std::string& _key, const std::string& _value) + void ControllerRepeatEvent::setProperty(const std::string& _key, const std::string& _value) { } - void ControllerRepeatClick::prepareItem(MyGUI::Widget* _widget) + void ControllerRepeatEvent::prepareItem(MyGUI::Widget* _widget) { } diff --git a/apps/openmw/mwgui/controllers.hpp b/apps/openmw/mwgui/controllers.hpp index 937855606..003027a46 100644 --- a/apps/openmw/mwgui/controllers.hpp +++ b/apps/openmw/mwgui/controllers.hpp @@ -9,14 +9,15 @@ namespace MWGui { namespace Controllers { - class ControllerRepeatClick : + // Should be removed when upgrading to MyGUI 3.2.2 (current git), it has ControllerRepeatClick + class ControllerRepeatEvent : public MyGUI::ControllerItem { - MYGUI_RTTI_DERIVED( ControllerRepeatClick ) + MYGUI_RTTI_DERIVED( ControllerRepeatEvent ) public: - ControllerRepeatClick(); - virtual ~ControllerRepeatClick(); + ControllerRepeatEvent(); + virtual ~ControllerRepeatEvent(); void setRepeat(float init, float step); void setEnabled(bool enable); diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 9393446f1..f09aff5ac 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -393,8 +393,8 @@ namespace MWGui void TradeWindow::addRepeatController(MyGUI::Widget *widget) { - MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(Controllers::ControllerRepeatClick::getClassTypeName()); - Controllers::ControllerRepeatClick* controller = item->castType(); + MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(Controllers::ControllerRepeatEvent::getClassTypeName()); + Controllers::ControllerRepeatEvent* controller = item->castType(); controller->eventRepeatClick += MyGUI::newDelegate(this, &TradeWindow::onRepeatClick); controller->setRepeat(sBalanceChangeInitialPause, sBalanceChangeInterval); MyGUI::ControllerManager::getInstance().addItem(widget, controller); diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index b45f7d59c..6059d2d0d 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -617,8 +617,8 @@ namespace MWGui void MWScrollBar::onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { mIsIncreasing = false; - MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(MWGui::Controllers::ControllerRepeatClick::getClassTypeName()); - MWGui::Controllers::ControllerRepeatClick* controller = item->castType(); + MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(MWGui::Controllers::ControllerRepeatEvent::getClassTypeName()); + MWGui::Controllers::ControllerRepeatEvent* controller = item->castType(); controller->eventRepeatClick += newDelegate(this, &MWScrollBar::repeatClick); controller->setEnabled(mEnableRepeat); controller->setRepeat(mRepeatTriggerTime, mRepeatStepTime); @@ -633,8 +633,8 @@ namespace MWGui void MWScrollBar::onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { mIsIncreasing = true; - MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(MWGui::Controllers::ControllerRepeatClick::getClassTypeName()); - MWGui::Controllers::ControllerRepeatClick* controller = item->castType(); + MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(MWGui::Controllers::ControllerRepeatEvent::getClassTypeName()); + MWGui::Controllers::ControllerRepeatEvent* controller = item->castType(); controller->eventRepeatClick += newDelegate(this, &MWScrollBar::repeatClick); controller->setEnabled(mEnableRepeat); controller->setRepeat(mRepeatTriggerTime, mRepeatStepTime); diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index fc13b7ce5..fff7bdbfc 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -298,6 +298,7 @@ namespace MWGui }; typedef MWDynamicStat* MWDynamicStatPtr; + // Should be removed when upgrading to MyGUI 3.2.2 (current git), it has ScrollBar autorepeat support class MWScrollBar : public MyGUI::ScrollBar { MYGUI_RTTI_DERIVED(MWScrollBar) diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index a109c8c20..13c878d80 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -176,7 +176,7 @@ namespace MWGui ItemView::registerComponents(); ItemWidget::registerComponents(); - MyGUI::FactoryManager::getInstance().registerFactory("Controller"); + MyGUI::FactoryManager::getInstance().registerFactory("Controller"); MyGUI::FactoryManager::getInstance().registerFactory("Controller"); MyGUI::FactoryManager::getInstance().registerFactory("Resource", "ResourceImageSetPointer"); From bd96764229fd0d990874983f24b6caf2fcbb9087 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 14 Sep 2014 03:52:14 +0200 Subject: [PATCH 11/11] Mark code that will be obsolete when upgrading to MyGUI 3.2.2 --- apps/openmw/mwgui/console.cpp | 1 + apps/openmw/mwgui/savegamedialog.cpp | 1 + apps/openmw/mwgui/windowbase.cpp | 1 + apps/openmw/mwgui/windowmanagerimp.cpp | 1 + libs/openengine/gui/manager.cpp | 1 + 5 files changed, 5 insertions(+) diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index 9f67524ae..af0eb6ef9 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -140,6 +140,7 @@ namespace MWGui void Console::close() { // Apparently, hidden widgets can retain key focus + // Remove for MyGUI 3.2.2 MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(NULL); } diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index 84b5ca6ea..3920a5dcb 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -213,6 +213,7 @@ namespace MWGui void SaveGameDialog::accept(bool reallySure) { + // Remove for MyGUI 3.2.2 MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(NULL); if (mSaving) diff --git a/apps/openmw/mwgui/windowbase.cpp b/apps/openmw/mwgui/windowbase.cpp index c4bda0bae..432510a3e 100644 --- a/apps/openmw/mwgui/windowbase.cpp +++ b/apps/openmw/mwgui/windowbase.cpp @@ -23,6 +23,7 @@ void WindowBase::setVisible(bool visible) close(); // This is needed as invisible widgets can retain key focus. + // Remove for MyGUI 3.2.2 if (!visible) { MyGUI::Widget* keyFocus = MyGUI::InputManager::getInstance().getKeyFocusWidget(); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 13c878d80..dac000340 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1449,6 +1449,7 @@ namespace MWGui forceHide((GuiWindow)(MWGui::GW_Inventory | MWGui::GW_Magic)); } + // Remove this method for MyGUI 3.2.2 void WindowManager::setKeyFocusWidget(MyGUI::Widget *widget) { if (widget == NULL) diff --git a/libs/openengine/gui/manager.cpp b/libs/openengine/gui/manager.cpp index ca4067ca1..8238a25d4 100644 --- a/libs/openengine/gui/manager.cpp +++ b/libs/openengine/gui/manager.cpp @@ -23,6 +23,7 @@ namespace MyGUI * As of MyGUI 3.2.0, MyGUI::OgreDataManager::isDataExist is unnecessarily complex * this override fixes the resulting performance issue. */ +// Remove for MyGUI 3.2.2 class FixedOgreDataManager : public MyGUI::OgreDataManager { public: