Merge branch 'gui_cleanup' into 'master'

GUI cleanup

See merge request OpenMW/openmw!2169
check_span
psi29a 2 years ago
commit bbcf7809f0

@ -194,8 +194,9 @@ namespace MWGui
, mWindowVisible(true)
{
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->initialise("mygui", (std::filesystem::path(logpath) / "MyGUI.log").generic_string());
mGuiPlatform = new osgMyGUI::Platform(viewer, guiRoot, resourceSystem->getImageManager(),
resourceSystem->getVFS(), mScalingFactor, "mygui",
(std::filesystem::path(logpath) / "MyGUI.log").generic_string());
mGui = new MyGUI::Gui;
mGui->initialise("");

@ -177,10 +177,6 @@ namespace Gui
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)
{
try
@ -318,15 +314,6 @@ namespace Gui
memcpy(texData, &textureData[0], textureData.size());
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
MyGUI::xml::Document xmlDocument;
MyGUI::xml::ElementPtr root = xmlDocument.createRoot("ResourceManualFont");

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

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

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

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

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

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

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

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

Loading…
Cancel
Save