diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-10 20:16:14 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:55 +0200 |
commit | c988905add09cf8baf46dc61279528f6f39f7a1a (patch) | |
tree | 0c53a36569875f8d4c6e53392876e10fa695c35e /src/engine/graphics | |
parent | 38f14606c78c119d452f302f17329455e29a9a6f (diff) |
feat: add status bar
Diffstat (limited to 'src/engine/graphics')
-rw-r--r-- | src/engine/graphics/scene.cpp | 31 | ||||
-rw-r--r-- | src/engine/graphics/scene.hpp | 22 |
2 files changed, 41 insertions, 12 deletions
diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index a8e7b88..c4a398c 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -4,13 +4,19 @@ #include <fmt/core.h> #include <iostream> - -Scene::Scene(IMatrixFactory<std::string_view> matrix_factory) - : _is_shown(false), _matrix_factory(matrix_factory) +#include <utility> + +Scene::Scene(IMatrixFactory<std::string_view> matrix_factory, + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IWindow> window) noexcept + : _is_shown(false), + _matrix_factory(matrix_factory), + _cursor_controller(std::move(cursor_controller)), + _window(std::move(window)) { } -void Scene::enter() +void Scene::enter() noexcept { if (_is_shown) { @@ -23,7 +29,7 @@ void Scene::enter() _is_shown = true; } -void Scene::leave() +void Scene::leave() noexcept { if (!_is_shown) { @@ -35,3 +41,18 @@ void Scene::leave() _is_shown = false; } + +void Scene::write_status(const std::string_view &str) noexcept +{ + const auto previous_position = _cursor_controller->where(); + + const auto window_size = _window->size(); + + _cursor_controller->move_to( + Vector2({.x = 1, .y = static_cast<Vector2::Value>(window_size.get_height())})); + + fmt::print(ERASE_ENTIRE_LINE, fmt::arg("esc", ESC)); + fmt::print(fmt::runtime(str.data())); + + _cursor_controller->move_to(previous_position); +} diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index c4c217f..3d05cd9 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -1,29 +1,37 @@ #pragma once -#include "DI/auto_wirable.hpp" +#include "interfaces/cursor.hpp" #include "interfaces/matrix.hpp" #include "interfaces/scene.hpp" +#include "interfaces/window.hpp" #include <fmt/core.h> +#include <memory> #include <string_view> constexpr fmt::string_view ENABLE_ALT_BUFFER = "{esc}[?1049h"; constexpr fmt::string_view DISABLE_ALT_BUFFER = "{esc}[?1049l"; -class Scene : public IScene, - public AutoWirable<IScene, Scene, IMatrixFactory<std::string_view>> +constexpr fmt::string_view ERASE_ENTIRE_LINE = "{esc}[2K"; + +class Scene : public IScene { public: - explicit Scene(IMatrixFactory<std::string_view> matrix_factory); + explicit Scene(IMatrixFactory<std::string_view> matrix_factory, + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IWindow> window) noexcept; - void enter() override; + void enter() noexcept override; - void leave() override; + void leave() noexcept override; - // void do_in_statusbar(const std::function<void()> &routine); + void write_status(const std::string_view &str) noexcept override; private: bool _is_shown; IMatrixFactory<std::string_view> _matrix_factory; + + std::shared_ptr<ICursorController> _cursor_controller; + std::shared_ptr<IWindow> _window; }; |