osb/source/frontend/StarInterfaceCursor.cpp

69 lines
1.7 KiB
C++
Raw Normal View History

2023-06-20 04:33:09 +00:00
#include "StarInterfaceCursor.hpp"
#include "StarJsonExtra.hpp"
#include "StarRoot.hpp"
#include "StarAssets.hpp"
#include "StarImageMetadataDatabase.hpp"
namespace Star {
InterfaceCursor::InterfaceCursor() {
resetCursor();
}
void InterfaceCursor::resetCursor() {
auto& root = Root::singleton();
auto assets = root.assets();
setCursor(assets->json("/interface.config:defaultCursor").toString());
}
void InterfaceCursor::setCursor(String const& configFile) {
if (m_configFile == configFile)
return;
m_configFile = configFile;
auto& root = Root::singleton();
auto assets = root.assets();
auto imageMetadata = root.imageMetadataDatabase();
auto config = assets->json(m_configFile);
m_offset = jsonToVec2I(config.get("offset"));
if (config.contains("image")) {
m_drawable = config.getString("image");
m_size = Vec2I{imageMetadata->imageSize(config.getString("image"))};
} else {
m_drawable = Animation(config.get("animation"), "/interface");
m_size = Vec2I(m_drawable.get<Animation>().drawable(1.0f).boundBox(false).size());
}
2023-06-26 08:39:40 +00:00
m_scale = config.getUInt("scale", 0);
2023-06-20 04:33:09 +00:00
}
Drawable InterfaceCursor::drawable() const {
if (m_drawable.is<String>())
return Drawable::makeImage(m_drawable.get<String>(), 1.0f, false, {});
else
return m_drawable.get<Animation>().drawable(1.0f);
}
Vec2I InterfaceCursor::size() const {
return m_size;
}
Vec2I InterfaceCursor::offset() const {
return m_offset;
}
2023-06-26 08:39:40 +00:00
unsigned int InterfaceCursor::scale(unsigned int interfaceScale) const {
return m_scale ? m_scale : interfaceScale;
}
2023-06-20 04:33:09 +00:00
void InterfaceCursor::update(float dt) {
if (m_drawable.is<Animation>()) {
m_drawable.get<Animation>().update(dt);
}
}
}