diff options
Diffstat (limited to 'source/frontend/StarInterfaceCursor.cpp')
-rw-r--r-- | source/frontend/StarInterfaceCursor.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/source/frontend/StarInterfaceCursor.cpp b/source/frontend/StarInterfaceCursor.cpp new file mode 100644 index 0000000..8844da2 --- /dev/null +++ b/source/frontend/StarInterfaceCursor.cpp @@ -0,0 +1,62 @@ +#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()); + } +} + +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; +} + +void InterfaceCursor::update(float dt) { + if (m_drawable.is<Animation>()) { + m_drawable.get<Animation>().update(dt); + } +} + +} |