aboutsummaryrefslogtreecommitdiff
path: root/src/game/components/statusline.hpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-06-08 16:29:16 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:57:01 +0200
commit45e3ae285c63d91dcac426cffdd9d9648e48399b (patch)
treea3d483027356fec5a953545e691ea07ef417bf63 /src/game/components/statusline.hpp
parentdcc6d3d5cafe47d53d1b321476bf73bb2d65ae9b (diff)
refactor: move components to game folder
Diffstat (limited to 'src/game/components/statusline.hpp')
-rw-r--r--src/game/components/statusline.hpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/game/components/statusline.hpp b/src/game/components/statusline.hpp
new file mode 100644
index 0000000..8c1969b
--- /dev/null
+++ b/src/game/components/statusline.hpp
@@ -0,0 +1,48 @@
+#pragma once
+
+#include "interfaces/matrix.hpp"
+#include "interfaces/statusline.hpp"
+
+#include "engine/data/vector2.hpp"
+
+#include <memory>
+#include <string_view>
+#include <unordered_map>
+
+constexpr uint32_t STATUSLINE_COLOR = 0x1A1A1AU;
+
+class StatusLine : public IStatusLine
+{
+public:
+ explicit StatusLine(std::shared_ptr<ComponentMatrix> component_matrix) noexcept;
+
+ auto get() const noexcept -> const std::shared_ptr<ComponentMatrix> & override;
+
+ [[nodiscard]] auto get_need_render() const noexcept -> bool override;
+
+ void set_need_render(bool need_render) noexcept override;
+
+ auto get_foreground_color() const noexcept -> uint32_t override;
+
+ auto get_background_color() const noexcept -> uint32_t override;
+
+ void set_status(
+ StatusLineSection section,
+ const std::string_view &status,
+ int32_t start) noexcept override;
+
+ void set_section_length(StatusLineSection section, int32_t length) noexcept override;
+
+private:
+ std::shared_ptr<ComponentMatrix> _component_matrix;
+ std::unordered_map<StatusLineSection, int32_t> _section_lengths;
+ bool _need_render;
+
+ void
+ _matrix_write_string(const Vector2 &position, const std::string_view &str) noexcept;
+
+ [[nodiscard]] auto _get_section_start_x(StatusLineSection section) const noexcept
+ -> int32_t;
+
+ void _clear_section(StatusLineSection section, int32_t start) noexcept;
+};