mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Add layer size, make layers API more flexible
This commit is contained in:
parent
4be1e3deb1
commit
5d1fe6c2bc
4 changed files with 135 additions and 62 deletions
|
@ -6,50 +6,63 @@
|
|||
|
||||
#include <MyGUI_LayerManager.h>
|
||||
#include <MyGUI_OverlappedLayer.h>
|
||||
#include <osg/Vec2f>
|
||||
|
||||
namespace LuaUi
|
||||
{
|
||||
namespace Layers
|
||||
// this wrapper is necessary, because the MyGUI LayerManager
|
||||
// stores layers in a vector and their indices could change
|
||||
class Layer
|
||||
{
|
||||
struct Options {
|
||||
bool mInteractive;
|
||||
};
|
||||
public:
|
||||
Layer(size_t index)
|
||||
: mName(at(index)->getName())
|
||||
, mCachedIndex(index)
|
||||
{}
|
||||
|
||||
size_t size()
|
||||
{
|
||||
return MyGUI::LayerManager::getInstance().getLayerCount();
|
||||
}
|
||||
|
||||
std::string at(size_t index)
|
||||
{
|
||||
if (index >= size())
|
||||
throw std::logic_error("Invalid layer index");
|
||||
return MyGUI::LayerManager::getInstance().getLayer(index)->getName();
|
||||
}
|
||||
|
||||
size_t indexOf(std::string_view name)
|
||||
{
|
||||
for (size_t i = 0; i < size(); i++)
|
||||
if (at(i) == name)
|
||||
return i;
|
||||
return size();
|
||||
}
|
||||
|
||||
void insert(size_t index, std::string_view name, Options options)
|
||||
{
|
||||
if (index > size())
|
||||
throw std::logic_error("Invalid layer index");
|
||||
if (indexOf(name) < size())
|
||||
Log(Debug::Error) << "Layer \"" << name << "\" already exists";
|
||||
else
|
||||
const std::string& name() const noexcept { return mName; };
|
||||
const osg::Vec2f size()
|
||||
{
|
||||
auto layer = MyGUI::LayerManager::getInstance()
|
||||
.createLayerAt(std::string(name), "OverlappedLayer", index);
|
||||
auto overlappedLayer = dynamic_cast<MyGUI::OverlappedLayer*>(layer);
|
||||
overlappedLayer->setPick(options.mInteractive);
|
||||
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()
|
||||
{
|
||||
MyGUI::ILayer* p = at(mCachedIndex);
|
||||
if (p->getName() != mName)
|
||||
{
|
||||
mCachedIndex = indexOf(mName);
|
||||
p = at(mCachedIndex);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
std::string mName;
|
||||
size_t mCachedIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OPENMW_LUAUI_LAYERS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue