1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 19:53:53 +00:00
openmw/components/lua_ui/layers.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.6 KiB
C++
Raw Normal View History

2021-12-14 17:38:06 +00:00
#ifndef OPENMW_LUAUI_LAYERS
#define OPENMW_LUAUI_LAYERS
#include <string>
#include <string_view>
#include <MyGUI_LayerManager.h>
#include <MyGUI_OverlappedLayer.h>
#include <osg/Vec2f>
2021-12-14 17:38:06 +00:00
namespace LuaUi
{
// this wrapper is necessary, because the MyGUI LayerManager
// stores layers in a vector and their indices could change
class Layer
2021-12-14 17:38:06 +00:00
{
public:
Layer(size_t index)
: mName(at(index)->getName())
, mCachedIndex(index)
{
}
2022-10-05 21:45:17 +00:00
const std::string& name() const noexcept { return mName; }
const osg::Vec2f size()
{
MyGUI::ILayer* p = refresh();
MyGUI::IntSize size = p->getSize();
return osg::Vec2f(size.width, size.height);
}
struct Options
{
bool mInteractive;
};
static size_t count() { return MyGUI::LayerManager::getInstance().getLayerCount(); }
static size_t indexOf(std::string_view name);
static void insert(size_t index, std::string_view name, Options options);
private:
static MyGUI::ILayer* at(size_t index)
{
if (index >= count())
throw std::logic_error("Invalid layer index");
return MyGUI::LayerManager::getInstance().getLayer(index);
}
MyGUI::ILayer* refresh()
2022-09-22 18:26:05 +00:00
{
MyGUI::ILayer* p = at(mCachedIndex);
if (p->getName() != mName)
2021-12-14 17:38:06 +00:00
{
mCachedIndex = indexOf(mName);
p = at(mCachedIndex);
2021-12-14 17:38:06 +00:00
}
return p;
2022-09-22 18:26:05 +00:00
}
std::string mName;
size_t mCachedIndex;
};
2021-12-14 17:38:06 +00:00
}
#endif // OPENMW_LUAUI_LAYERS