From ee3b1e800ca61800cbd062328e891d0ecdd154f3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 12 Sep 2014 04:27:23 +0200 Subject: [PATCH] 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 e2c1ef5c96..53c79f7c66 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 f6ad6500cc..5882ae2b68 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 beeadadbe0..1178a3a284 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 b1cb7fccf2..e01e4b7bc2 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 6197178401..a41506dbb4 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 24ecf65578..02088f6933 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 5203b80ba0..9d035f09c4 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 3ca1152f38..0d6b4b8044 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); }