From 7de921836587cdc359c2c4b84ed6446ada16c008 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 22 May 2022 17:05:00 +0200 Subject: refactor: remove window class --- src/engine/graphics/matrix.hpp | 1 + src/engine/graphics/scene.cpp | 20 +++++++++++++++----- src/engine/graphics/scene.hpp | 8 ++++---- src/engine/graphics/statusline.cpp | 12 ++++++------ src/engine/graphics/statusline.hpp | 6 +++--- src/engine/graphics/window.cpp | 13 ------------- src/engine/graphics/window.hpp | 15 --------------- 7 files changed, 29 insertions(+), 46 deletions(-) delete mode 100644 src/engine/graphics/window.cpp delete mode 100644 src/engine/graphics/window.hpp (limited to 'src/engine/graphics') diff --git a/src/engine/graphics/matrix.hpp b/src/engine/graphics/matrix.hpp index f71018b..5a7d893 100644 --- a/src/engine/graphics/matrix.hpp +++ b/src/engine/graphics/matrix.hpp @@ -7,6 +7,7 @@ #include "engine/matrix_iterator.hpp" #include + #include template diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index 73c1292..52613d8 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -5,17 +5,17 @@ #include #include + #include +#include #include Scene::Scene( IMatrixFactory matrix_factory, - std::shared_ptr cursor_controller, - std::shared_ptr window) noexcept + std::shared_ptr cursor_controller) noexcept : _is_shown(false), - _matrix(matrix_factory(window->size() - Bounds({.width = 0U, .height = 1U}))), - _cursor_controller(std::move(cursor_controller)), - _window(std::move(window)) + _matrix(matrix_factory(size() - Bounds({.width = 0U, .height = 1U}))), + _cursor_controller(std::move(cursor_controller)) { _matrix->fill(" "); } @@ -46,6 +46,16 @@ void Scene::leave() noexcept _is_shown = false; } +auto Scene::size() const noexcept -> Bounds +{ + winsize window_size = {}; + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + ioctl(0, TIOCGWINSZ, &window_size); + + return Bounds({window_size.ws_col, window_size.ws_row}); +} + auto Scene::get_matrix() const noexcept -> const std::shared_ptr> & { diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index 5e74725..268f8dc 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -3,9 +3,9 @@ #include "interfaces/cursor.hpp" #include "interfaces/matrix.hpp" #include "interfaces/scene.hpp" -#include "interfaces/window.hpp" #include + #include #include @@ -17,13 +17,14 @@ class Scene : public IScene public: explicit Scene( IMatrixFactory matrix_factory, - std::shared_ptr cursor_controller, - std::shared_ptr window) noexcept; + std::shared_ptr cursor_controller) noexcept; void enter() noexcept override; void leave() noexcept override; + [[nodiscard]] auto size() const noexcept -> Bounds override; + [[nodiscard]] auto get_matrix() const noexcept -> const std::shared_ptr> & override; @@ -32,5 +33,4 @@ private: std::shared_ptr> _matrix; std::shared_ptr _cursor_controller; - std::shared_ptr _window; }; diff --git a/src/engine/graphics/statusline.cpp b/src/engine/graphics/statusline.cpp index 3968fae..52edd8f 100644 --- a/src/engine/graphics/statusline.cpp +++ b/src/engine/graphics/statusline.cpp @@ -8,8 +8,8 @@ StatusLine::StatusLine( std::shared_ptr cursor_controller, - std::shared_ptr window) noexcept - : _cursor_controller(std::move(cursor_controller)), _window(std::move(window)) + std::shared_ptr scene) noexcept + : _cursor_controller(std::move(cursor_controller)), _scene(std::move(scene)) { } @@ -19,7 +19,7 @@ void StatusLine::initialize_background() noexcept auto background_color = get_background_esc_seq(STATUSBAR_COLOR); - fmt::print("{}{}", background_color, std::string(_window->size().get_width(), ' ')); + fmt::print("{}{}", background_color, std::string(_scene->size().get_width(), ' ')); fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); _move_back(previous_position); @@ -58,13 +58,13 @@ auto StatusLine::_move_to_statusline(int32_t x) noexcept -> Vector2 { const auto previous_position = _cursor_controller->where(); - const auto window_size = _window->size(); + const auto scene_size = _scene->size(); _cursor_controller->hide(); - auto window_height = static_cast(window_size.get_height()); + auto scene_height = static_cast(scene_size.get_height()); - _cursor_controller->move_to(Vector2({.x = x, .y = window_height}), true); + _cursor_controller->move_to(Vector2({.x = x, .y = scene_height}), true); return previous_position; } diff --git a/src/engine/graphics/statusline.hpp b/src/engine/graphics/statusline.hpp index add8e02..6f0a4c2 100644 --- a/src/engine/graphics/statusline.hpp +++ b/src/engine/graphics/statusline.hpp @@ -1,8 +1,8 @@ #pragma once #include "interfaces/cursor.hpp" +#include "interfaces/scene.hpp" #include "interfaces/statusline.hpp" -#include "interfaces/window.hpp" #include "engine/data/vector2.hpp" @@ -19,7 +19,7 @@ class StatusLine : public IStatusLine public: StatusLine( std::shared_ptr cursor_controller, - std::shared_ptr window) noexcept; + std::shared_ptr scene) noexcept; void initialize_background() noexcept override; @@ -35,7 +35,7 @@ private: std::unordered_map _sections_lengths; std::shared_ptr _cursor_controller; - std::shared_ptr _window; + std::shared_ptr _scene; auto _move_to_statusline(int32_t x) noexcept -> Vector2; diff --git a/src/engine/graphics/window.cpp b/src/engine/graphics/window.cpp deleted file mode 100644 index bb33402..0000000 --- a/src/engine/graphics/window.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "window.hpp" - -#include - -auto Window::size() const noexcept -> Bounds -{ - winsize window_size = {}; - - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - ioctl(0, TIOCGWINSZ, &window_size); - - return Bounds({window_size.ws_col, window_size.ws_row}); -} diff --git a/src/engine/graphics/window.hpp b/src/engine/graphics/window.hpp deleted file mode 100644 index 9284e5e..0000000 --- a/src/engine/graphics/window.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "interfaces/window.hpp" - -#include "engine/data/bounds.hpp" - -#include - -class Window : public IWindow, public yacppdic::AutoWirable -{ -public: - Window() noexcept = default; - - [[nodiscard]] auto size() const noexcept -> Bounds override; -}; -- cgit v1.2.3-18-g5258