From 8805b1fe27344e8086cebabf869b7a02d2376f05 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 7 Jun 2022 19:45:17 +0200 Subject: refactor: decouple statusline from scene & cursor controller Might be slightly slower than previously though... --- src/interfaces/component.hpp | 25 +++++++++++++++++++++++++ src/interfaces/component_renderer.hpp | 24 ++++++++++++++++++++++++ src/interfaces/matrix.hpp | 4 +++- src/interfaces/scene.hpp | 11 +++++++++++ src/interfaces/status_manager.hpp | 3 +++ src/interfaces/statusline.hpp | 23 ++++++++++------------- 6 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 src/interfaces/component.hpp create mode 100644 src/interfaces/component_renderer.hpp (limited to 'src/interfaces') diff --git a/src/interfaces/component.hpp b/src/interfaces/component.hpp new file mode 100644 index 0000000..7e1b132 --- /dev/null +++ b/src/interfaces/component.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "interfaces/matrix.hpp" + +#include + +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) +class IComponent +{ +public: + using ComponentMatrix = IMatrix; + + virtual ~IComponent() = default; + + [[nodiscard]] virtual auto get() const noexcept + -> const std::shared_ptr & = 0; + + [[nodiscard]] virtual auto get_need_render() const noexcept -> bool = 0; + + virtual void set_need_render(bool need_render) noexcept = 0; + + [[nodiscard]] virtual auto get_foreground_color() const noexcept -> uint32_t = 0; + + [[nodiscard]] virtual auto get_background_color() const noexcept -> uint32_t = 0; +}; diff --git a/src/interfaces/component_renderer.hpp b/src/interfaces/component_renderer.hpp new file mode 100644 index 0000000..fa8bc18 --- /dev/null +++ b/src/interfaces/component_renderer.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "interfaces/component.hpp" +#include "interfaces/cursor.hpp" + +#include "engine/data/vector2.hpp" + +#include + +#include + +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) +class IComponentRenderer +{ +public: + virtual ~IComponentRenderer() = default; + + virtual void render( + const std::shared_ptr &component, + const Vector2 &position) noexcept = 0; +}; + +using IComponentRendererFactory = yacppdic::Factory( + const std::shared_ptr &)>; diff --git a/src/interfaces/matrix.hpp b/src/interfaces/matrix.hpp index 010138f..3ab102c 100644 --- a/src/interfaces/matrix.hpp +++ b/src/interfaces/matrix.hpp @@ -8,11 +8,13 @@ #include -template +template // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class IMatrix { public: + using Element = ElementType; + virtual ~IMatrix() noexcept = default; virtual void fill(Element element) noexcept = 0; diff --git a/src/interfaces/scene.hpp b/src/interfaces/scene.hpp index 903a299..daabb10 100644 --- a/src/interfaces/scene.hpp +++ b/src/interfaces/scene.hpp @@ -1,14 +1,18 @@ #pragma once +#include "interfaces/component.hpp" #include "interfaces/cursor.hpp" #include "interfaces/matrix.hpp" #include "engine/data/bounds.hpp" +#include "engine/data/vector2.hpp" #include #include #include +#include +#include // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class IScene @@ -26,6 +30,13 @@ public: [[nodiscard]] virtual auto get_matrix() const noexcept -> const std::shared_ptr> & = 0; + + virtual void register_component( + const std::shared_ptr &component, + const Vector2 &position) noexcept = 0; + + [[nodiscard]] virtual auto get_components() const noexcept + -> std::vector, Vector2>> = 0; }; using ISceneFactory = yacppdic::Factory( diff --git a/src/interfaces/status_manager.hpp b/src/interfaces/status_manager.hpp index 18d6928..9c7234e 100644 --- a/src/interfaces/status_manager.hpp +++ b/src/interfaces/status_manager.hpp @@ -22,6 +22,9 @@ public: virtual void set_section_body( const StatusLineSection §ion, const std::string_view &body) noexcept = 0; + + [[nodiscard]] virtual auto get_statusline() const noexcept + -> std::shared_ptr = 0; }; using IStatusManagerFactory = yacppdic::Factory( diff --git a/src/interfaces/statusline.hpp b/src/interfaces/statusline.hpp index a71699e..ae25fd9 100644 --- a/src/interfaces/statusline.hpp +++ b/src/interfaces/statusline.hpp @@ -1,7 +1,8 @@ #pragma once -#include "interfaces/cursor.hpp" -#include "interfaces/scene.hpp" +#include "interfaces/component.hpp" + +#include "engine/data/bounds.hpp" #include @@ -20,22 +21,18 @@ enum StatusLineSection }; // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) -class IStatusLine +class IStatusLine : public IComponent { public: - virtual ~IStatusLine() noexcept = default; - - virtual void initialize_background() noexcept = 0; - + // NOLINTNEXTLINE(google-default-arguments) virtual void set_status( - const StatusLineSection §ion, + StatusLineSection section, const std::string_view &status, - std::size_t start = 1UL) noexcept = 0; + int32_t start = 1) noexcept = 0; virtual void - set_section_length(const StatusLineSection §ion, uint32_t length) noexcept = 0; + set_section_length(StatusLineSection section, int32_t length) noexcept = 0; }; -using IStatusLineFactory = yacppdic::Factory( - const std::shared_ptr &cursor_controller, - const std::shared_ptr &scene)>; +using IStatusLineFactory = + yacppdic::Factory(const Bounds &size)>; -- cgit v1.2.3-18-g5258