1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-17 10:21:11 +00:00

Merge branch 'gui_cleanup' into 'master'

GUI cleanup

See merge request OpenMW/openmw!2169
This commit is contained in:
psi29a 2022-07-26 13:39:33 +00:00
commit bbcf7809f0
10 changed files with 48 additions and 100 deletions

View File

@ -194,8 +194,9 @@ namespace MWGui
, mWindowVisible(true) , mWindowVisible(true)
{ {
mScalingFactor = std::clamp(Settings::Manager::getFloat("scaling factor", "GUI"), 0.5f, 8.f); mScalingFactor = std::clamp(Settings::Manager::getFloat("scaling factor", "GUI"), 0.5f, 8.f);
mGuiPlatform = new osgMyGUI::Platform(viewer, guiRoot, resourceSystem->getImageManager(), resourceSystem->getVFS(), mScalingFactor); mGuiPlatform = new osgMyGUI::Platform(viewer, guiRoot, resourceSystem->getImageManager(),
mGuiPlatform->initialise("mygui", (std::filesystem::path(logpath) / "MyGUI.log").generic_string()); resourceSystem->getVFS(), mScalingFactor, "mygui",
(std::filesystem::path(logpath) / "MyGUI.log").generic_string());
mGui = new MyGUI::Gui; mGui = new MyGUI::Gui;
mGui->initialise(""); mGui->initialise("");

View File

@ -177,10 +177,6 @@ namespace Gui
Log(Debug::Error) << "Error in the FontLoader destructor: " << e.what(); Log(Debug::Error) << "Error in the FontLoader destructor: " << e.what();
} }
for (std::vector<MyGUI::ITexture*>::iterator it = mTextures.begin(); it != mTextures.end(); ++it)
delete *it;
mTextures.clear();
for (std::vector<MyGUI::ResourceManualFont*>::iterator it = mFonts.begin(); it != mFonts.end(); ++it) for (std::vector<MyGUI::ResourceManualFont*>::iterator it = mFonts.begin(); it != mFonts.end(); ++it)
{ {
try try
@ -318,15 +314,6 @@ namespace Gui
memcpy(texData, &textureData[0], textureData.size()); memcpy(texData, &textureData[0], textureData.size());
tex->unlock(); tex->unlock();
// Using ResourceManualFont::setTexture, enable for MyGUI 3.2.3
/*
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setImage(image);
osgMyGUI::OSGTexture* myguiTex = new osgMyGUI::OSGTexture(texture);
mTextures.push_back(myguiTex);
font->setTexture(myguiTex);
*/
// We need to emulate loading from XML because the data members are private as of mygui 3.2.0 // We need to emulate loading from XML because the data members are private as of mygui 3.2.0
MyGUI::xml::Document xmlDocument; MyGUI::xml::Document xmlDocument;
MyGUI::xml::ElementPtr root = xmlDocument.createRoot("ResourceManualFont"); MyGUI::xml::ElementPtr root = xmlDocument.createRoot("ResourceManualFont");

View File

@ -43,7 +43,6 @@ namespace Gui
int mFontHeight; int mFontHeight;
float mScalingFactor; float mScalingFactor;
std::vector<MyGUI::ITexture*> mTextures;
std::vector<MyGUI::ResourceManualFont*> mFonts; std::vector<MyGUI::ResourceManualFont*> mFonts;
std::string getInternalFontName(const std::string& name); std::string getInternalFontName(const std::string& name);

View File

@ -2,13 +2,11 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <stdexcept>
#include <MyGUI_DataFileStream.h> #include <MyGUI_DataFileStream.h>
#include <filesystem> #include <components/vfs/manager.hpp>
#include <fstream>
#include <components/debug/debuglog.hpp>
namespace namespace
{ {
@ -33,8 +31,9 @@ void DataManager::setResourcePath(const std::string &path)
mResourcePath = path; mResourcePath = path;
} }
DataManager::DataManager(const VFS::Manager* vfs) DataManager::DataManager(const std::string& resourcePath, const VFS::Manager* vfs)
: mVfs(vfs) : mResourcePath(resourcePath)
, mVfs(vfs)
{ {
} }

View File

@ -5,7 +5,10 @@
#include <string> #include <string>
#include <components/vfs/manager.hpp> namespace VFS
{
class Manager;
}
namespace osgMyGUI namespace osgMyGUI
{ {
@ -13,10 +16,7 @@ namespace osgMyGUI
class DataManager : public MyGUI::DataManager class DataManager : public MyGUI::DataManager
{ {
public: public:
void initialise() {} explicit DataManager(const std::string& path, const VFS::Manager* vfs);
void shutdown() {}
DataManager(const VFS::Manager* vfs);
void setResourcePath(const std::string& path); void setResourcePath(const std::string& path);

View File

@ -7,58 +7,34 @@
namespace osgMyGUI namespace osgMyGUI
{ {
Platform::Platform(osgViewer::Viewer *viewer, osg::Group *guiRoot, Resource::ImageManager *imageManager, const VFS::Manager* vfs, float uiScalingFactor) Platform::Platform(osgViewer::Viewer *viewer, osg::Group* guiRoot, Resource::ImageManager* imageManager,
: mRenderManager(nullptr) const VFS::Manager* vfs, float uiScalingFactor, const std::string& resourcePath, const std::string& logName)
, mDataManager(nullptr) : mLogFacility(logName.empty() ? nullptr : std::make_unique<LogFacility>(logName, false))
, mLogManager(nullptr) , mLogManager(std::make_unique<MyGUI::LogManager>())
, mLogFacility(nullptr) , mDataManager(std::make_unique<DataManager>(resourcePath, vfs))
, mRenderManager(std::make_unique<RenderManager>(viewer, guiRoot, imageManager, uiScalingFactor))
{ {
mLogManager = new MyGUI::LogManager(); if (mLogFacility != nullptr)
mRenderManager = new RenderManager(viewer, guiRoot, imageManager, uiScalingFactor);
mDataManager = new DataManager(vfs);
}
Platform::~Platform()
{
delete mRenderManager;
mRenderManager = nullptr;
delete mDataManager;
mDataManager = nullptr;
delete mLogManager;
mLogManager = nullptr;
delete mLogFacility;
mLogFacility = nullptr;
}
void Platform::initialise(const std::string &resourcePath, const std::string &_logName)
{
if (!_logName.empty() && !mLogFacility)
{
mLogFacility = new LogFacility(_logName, false);
mLogManager->addLogSource(mLogFacility->getSource()); mLogManager->addLogSource(mLogFacility->getSource());
}
mDataManager->setResourcePath(resourcePath);
mRenderManager->initialise(); mRenderManager->initialise();
mDataManager->initialise();
} }
Platform::~Platform() = default;
void Platform::shutdown() void Platform::shutdown()
{ {
mRenderManager->shutdown(); mRenderManager->shutdown();
mDataManager->shutdown();
} }
RenderManager *Platform::getRenderManagerPtr() RenderManager *Platform::getRenderManagerPtr()
{ {
return mRenderManager; return mRenderManager.get();
} }
DataManager *Platform::getDataManagerPtr() DataManager *Platform::getDataManagerPtr()
{ {
return mDataManager; return mDataManager.get();
} }
} }

View File

@ -2,8 +2,7 @@
#define OPENMW_COMPONENTS_MYGUIPLATFORM_MYGUIPLATFORM_H #define OPENMW_COMPONENTS_MYGUIPLATFORM_MYGUIPLATFORM_H
#include <string> #include <string>
#include <memory>
#include <components/vfs/manager.hpp>
namespace osgViewer namespace osgViewer
{ {
@ -21,6 +20,10 @@ namespace MyGUI
{ {
class LogManager; class LogManager;
} }
namespace VFS
{
class Manager;
}
namespace osgMyGUI namespace osgMyGUI
{ {
@ -32,12 +35,12 @@ namespace osgMyGUI
class Platform class Platform
{ {
public: public:
Platform(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ImageManager* imageManager, const VFS::Manager* vfs, float uiScalingFactor); Platform(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ImageManager* imageManager,
const VFS::Manager* vfs, float uiScalingFactor, const std::string& resourcePath,
const std::string& logName = "MyGUI.log");
~Platform(); ~Platform();
void initialise(const std::string& resourcePath, const std::string& _logName = "MyGUI.log");
void shutdown(); void shutdown();
RenderManager* getRenderManagerPtr(); RenderManager* getRenderManagerPtr();
@ -45,13 +48,10 @@ namespace osgMyGUI
DataManager* getDataManagerPtr(); DataManager* getDataManagerPtr();
private: private:
RenderManager* mRenderManager; std::unique_ptr<LogFacility> mLogFacility;
DataManager* mDataManager; std::unique_ptr<MyGUI::LogManager> mLogManager;
MyGUI::LogManager* mLogManager; std::unique_ptr<DataManager> mDataManager;
LogFacility* mLogFacility; std::unique_ptr<RenderManager> mRenderManager;
void operator=(const Platform&);
Platform(const Platform&);
}; };
} }

View File

@ -380,8 +380,6 @@ RenderManager::~RenderManager()
mSceneRoot = nullptr; mSceneRoot = nullptr;
mViewer = nullptr; mViewer = nullptr;
destroyAllResources();
MYGUI_PLATFORM_LOG(Info, getClassTypeName()<<" successfully shutdown"); MYGUI_PLATFORM_LOG(Info, getClassTypeName()<<" successfully shutdown");
mIsInitialise = false; mIsInitialise = false;
} }
@ -532,16 +530,13 @@ bool RenderManager::isFormatSupported(MyGUI::PixelFormat /*format*/, MyGUI::Text
MyGUI::ITexture* RenderManager::createTexture(const std::string &name) MyGUI::ITexture* RenderManager::createTexture(const std::string &name)
{ {
MapTexture::iterator item = mTextures.find(name); auto item = mTextures.find(name);
if (item != mTextures.end()) if (item != mTextures.end())
{
delete item->second;
mTextures.erase(item); mTextures.erase(item);
}
OSGTexture* texture = new OSGTexture(name, mImageManager); item = mTextures.emplace_hint(item, name, OSGTexture(name, mImageManager));
mTextures.insert(std::make_pair(name, texture));
return texture; return &item->second;
} }
void RenderManager::destroyTexture(MyGUI::ITexture *texture) void RenderManager::destroyTexture(MyGUI::ITexture *texture)
@ -549,11 +544,10 @@ void RenderManager::destroyTexture(MyGUI::ITexture *texture)
if(texture == nullptr) if(texture == nullptr)
return; return;
MapTexture::iterator item = mTextures.find(texture->getName()); const auto item = mTextures.find(texture->getName());
MYGUI_PLATFORM_ASSERT(item != mTextures.end(), "Texture '"<<texture->getName()<<"' not found"); MYGUI_PLATFORM_ASSERT(item != mTextures.end(), "Texture '"<<texture->getName()<<"' not found");
mTextures.erase(item); mTextures.erase(item);
delete texture;
} }
MyGUI::ITexture* RenderManager::getTexture(const std::string &name) MyGUI::ITexture* RenderManager::getTexture(const std::string &name)
@ -561,21 +555,14 @@ MyGUI::ITexture* RenderManager::getTexture(const std::string &name)
if (name.empty()) if (name.empty())
return nullptr; return nullptr;
MapTexture::const_iterator item = mTextures.find(name); const auto item = mTextures.find(name);
if(item == mTextures.end()) if(item == mTextures.end())
{ {
MyGUI::ITexture* tex = createTexture(name); MyGUI::ITexture* tex = createTexture(name);
tex->loadFromFile(name); tex->loadFromFile(name);
return tex; return tex;
} }
return item->second; return &item->second;
}
void RenderManager::destroyAllResources()
{
for (MapTexture::iterator it = mTextures.begin(); it != mTextures.end(); ++it)
delete it->second;
mTextures.clear();
} }
bool RenderManager::checkTexture(MyGUI::ITexture* _texture) bool RenderManager::checkTexture(MyGUI::ITexture* _texture)

View File

@ -32,6 +32,7 @@ namespace osgMyGUI
{ {
class Drawable; class Drawable;
class OSGTexture;
class RenderManager : public MyGUI::RenderManager, public MyGUI::IRenderTarget class RenderManager : public MyGUI::RenderManager, public MyGUI::IRenderTarget
{ {
@ -45,8 +46,7 @@ class RenderManager : public MyGUI::RenderManager, public MyGUI::IRenderTarget
MyGUI::VertexColourType mVertexFormat; MyGUI::VertexColourType mVertexFormat;
MyGUI::RenderTargetInfo mInfo; MyGUI::RenderTargetInfo mInfo;
typedef std::map<std::string, MyGUI::ITexture*> MapTexture; std::map<std::string, OSGTexture> mTextures;
MapTexture mTextures;
bool mIsInitialise; bool mIsInitialise;
@ -56,8 +56,6 @@ class RenderManager : public MyGUI::RenderManager, public MyGUI::IRenderTarget
osg::StateSet* mInjectState; osg::StateSet* mInjectState;
void destroyAllResources();
public: public:
RenderManager(osgViewer::Viewer *viewer, osg::Group *sceneroot, Resource::ImageManager* imageManager, float scalingFactor); RenderManager(osgViewer::Viewer *viewer, osg::Group *sceneroot, Resource::ImageManager* imageManager, float scalingFactor);
virtual ~RenderManager(); virtual ~RenderManager();

View File

@ -20,7 +20,8 @@ namespace Resource
namespace osgMyGUI namespace osgMyGUI
{ {
class OSGTexture : public MyGUI::ITexture { class OSGTexture final : public MyGUI::ITexture
{
std::string mName; std::string mName;
Resource::ImageManager* mImageManager; Resource::ImageManager* mImageManager;
@ -37,7 +38,7 @@ namespace osgMyGUI
public: public:
OSGTexture(const std::string &name, Resource::ImageManager* imageManager); OSGTexture(const std::string &name, Resource::ImageManager* imageManager);
OSGTexture(osg::Texture2D* texture, osg::StateSet* injectState = nullptr); OSGTexture(osg::Texture2D* texture, osg::StateSet* injectState = nullptr);
virtual ~OSGTexture(); ~OSGTexture() override;
osg::StateSet* getInjectState() { return mInjectState; } osg::StateSet* getInjectState() { return mInjectState; }