diff options
author | zaaarf <me@zaaarf.foo> | 2023-12-10 23:15:41 +0100 |
---|---|---|
committer | zaaarf <me@zaaarf.foo> | 2023-12-10 23:15:41 +0100 |
commit | 4ef33d4df6198e613b0f27406d49978c8ea2fb97 (patch) | |
tree | 7f07835485b877f3c01c52c188892499e5812f9b /src/openvic-simulation/interface | |
parent | 1eb28bd4fb959b69a30013f6438f0257a2ee7b03 (diff) |
feat: improved identifier registry macro
Diffstat (limited to 'src/openvic-simulation/interface')
-rw-r--r-- | src/openvic-simulation/interface/GUI.cpp | 8 | ||||
-rw-r--r-- | src/openvic-simulation/interface/GUI.hpp | 11 | ||||
-rw-r--r-- | src/openvic-simulation/interface/UI.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/interface/UI.hpp | 15 |
4 files changed, 11 insertions, 25 deletions
diff --git a/src/openvic-simulation/interface/GUI.cpp b/src/openvic-simulation/interface/GUI.cpp index 61b8683..244909e 100644 --- a/src/openvic-simulation/interface/GUI.cpp +++ b/src/openvic-simulation/interface/GUI.cpp @@ -42,11 +42,9 @@ bool Element::_fill_elements_key_map( return ret; } -Scene::Scene() : elements { "scene elements" } {} - bool Scene::_fill_key_map(NodeTools::key_map_t& key_map, UIManager const& ui_manager) { return Element::_fill_elements_key_map(key_map, [this](std::unique_ptr<Element>&& element) -> bool { - return elements.add_item(std::move(element)); + return scene_elements.add_item(std::move(element)); }, ui_manager); } @@ -59,11 +57,11 @@ node_callback_t Scene::expect_scene( }, ui_manager); } -Window::Window() : elements { "window elements" }, size {}, moveable { false }, fullscreen { false } {} +Window::Window() : moveable { false }, fullscreen { false } {} bool Window::_fill_key_map(NodeTools::key_map_t& key_map, UIManager const& ui_manager) { bool ret = Element::_fill_elements_key_map(key_map, [this](std::unique_ptr<Element>&& element) -> bool { - return elements.add_item(std::move(element)); + return window_elements.add_item(std::move(element)); }, ui_manager); ret &= Element::_fill_key_map(key_map, ui_manager); ret &= add_key_map_entries(key_map, diff --git a/src/openvic-simulation/interface/GUI.hpp b/src/openvic-simulation/interface/GUI.hpp index f8434f6..47bd57d 100644 --- a/src/openvic-simulation/interface/GUI.hpp +++ b/src/openvic-simulation/interface/GUI.hpp @@ -40,10 +40,10 @@ namespace OpenVic::GUI { class Scene : public Named<UIManager const&> { friend std::unique_ptr<Scene> std::make_unique<Scene>(); - NamedInstanceRegistry<Element, UIManager const&> elements; + NamedInstanceRegistry<Element, UIManager const&> IDENTIFIER_REGISTRY(scene_element); protected: - Scene(); + Scene() = default; bool _fill_key_map(NodeTools::key_map_t& key_map, UIManager const& ui_manager) override; @@ -57,13 +57,12 @@ namespace OpenVic::GUI { std::string_view scene_name, NodeTools::callback_t<std::unique_ptr<Scene>&&> callback, UIManager const& ui_manager ); - IDENTIFIER_REGISTRY_ACCESSORS(element) }; class Window final : public Element { friend std::unique_ptr<Window> std::make_unique<Window>(); - NamedInstanceRegistry<Element, UIManager const&> elements; + NamedInstanceRegistry<Element, UIManager const&> IDENTIFIER_REGISTRY(window_element); fvec2_t PROPERTY(size); bool PROPERTY(moveable); @@ -80,8 +79,6 @@ namespace OpenVic::GUI { virtual ~Window() = default; OV_DETAIL_GET_TYPE - - IDENTIFIER_REGISTRY_ACCESSORS(element) }; class Icon final : public Element { @@ -127,7 +124,7 @@ namespace OpenVic::GUI { // TODO - clicksound protected: - Button() ; + Button(); bool _fill_key_map(NodeTools::key_map_t& key_map, UIManager const& ui_manager) override; diff --git a/src/openvic-simulation/interface/UI.cpp b/src/openvic-simulation/interface/UI.cpp index 4653e5b..3fc8295 100644 --- a/src/openvic-simulation/interface/UI.cpp +++ b/src/openvic-simulation/interface/UI.cpp @@ -5,8 +5,6 @@ using namespace OpenVic::NodeTools; using namespace OpenVic::GFX; using namespace OpenVic::GUI; -UIManager::UIManager() : sprites { "sprites" }, scenes { "scenes" }, fonts { "fonts" } {} - bool UIManager::add_font(std::string_view identifier, colour_t colour, std::string_view fontname) { if (identifier.empty()) { Logger::error("Invalid font identifier - empty!"); diff --git a/src/openvic-simulation/interface/UI.hpp b/src/openvic-simulation/interface/UI.hpp index 045766b..12eadb5 100644 --- a/src/openvic-simulation/interface/UI.hpp +++ b/src/openvic-simulation/interface/UI.hpp @@ -4,21 +4,14 @@ namespace OpenVic { - class UIManager { - - NamedInstanceRegistry<GFX::Sprite> sprites; - NamedInstanceRegistry<GUI::Scene, UIManager const&> scenes; - IdentifierRegistry<GFX::Font> fonts; + class UIManager { + NamedInstanceRegistry<GFX::Sprite> IDENTIFIER_REGISTRY(sprite); + NamedInstanceRegistry<GUI::Scene, UIManager const&> IDENTIFIER_REGISTRY(scene); + IdentifierRegistry<GFX::Font> IDENTIFIER_REGISTRY(font); bool _load_font(ast::NodeCPtr node); public: - UIManager(); - - IDENTIFIER_REGISTRY_ACCESSORS(sprite) - IDENTIFIER_REGISTRY_ACCESSORS(scene) - IDENTIFIER_REGISTRY_ACCESSORS(font) - bool add_font(std::string_view identifier, colour_t colour, std::string_view fontname); bool load_gfx_file(ast::NodeCPtr root); |