aboutsummaryrefslogtreecommitdiff
path: root/src/engine/graphics
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-22 17:05:00 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:59 +0200
commit7de921836587cdc359c2c4b84ed6446ada16c008 (patch)
treec4ec20b4769817c41ce7d939956da297bf787597 /src/engine/graphics
parent723ea6535b4c4e5605e5592137a898d6ffa458c1 (diff)
refactor: remove window class
Diffstat (limited to 'src/engine/graphics')
-rw-r--r--src/engine/graphics/matrix.hpp1
-rw-r--r--src/engine/graphics/scene.cpp20
-rw-r--r--src/engine/graphics/scene.hpp8
-rw-r--r--src/engine/graphics/statusline.cpp12
-rw-r--r--src/engine/graphics/statusline.hpp6
-rw-r--r--src/engine/graphics/window.cpp13
-rw-r--r--src/engine/graphics/window.hpp15
7 files changed, 29 insertions, 46 deletions
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 <gsl/pointers>
+
#include <memory>
template <typename Element>
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 <fmt/color.h>
#include <fmt/core.h>
+
#include <iostream>
+#include <sys/ioctl.h>
#include <utility>
Scene::Scene(
IMatrixFactory<std::string_view> matrix_factory,
- std::shared_ptr<ICursorController> cursor_controller,
- std::shared_ptr<IWindow> window) noexcept
+ std::shared_ptr<ICursorController> 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<IMatrix<std::string_view>> &
{
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 <fmt/core.h>
+
#include <memory>
#include <string_view>
@@ -17,13 +17,14 @@ class Scene : public IScene
public:
explicit Scene(
IMatrixFactory<std::string_view> matrix_factory,
- std::shared_ptr<ICursorController> cursor_controller,
- std::shared_ptr<IWindow> window) noexcept;
+ std::shared_ptr<ICursorController> 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<IMatrix<std::string_view>> & override;
@@ -32,5 +33,4 @@ private:
std::shared_ptr<IMatrix<std::string_view>> _matrix;
std::shared_ptr<ICursorController> _cursor_controller;
- std::shared_ptr<IWindow> _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<ICursorController> cursor_controller,
- std::shared_ptr<IWindow> window) noexcept
- : _cursor_controller(std::move(cursor_controller)), _window(std::move(window))
+ std::shared_ptr<IScene> 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<Vector2::Value>(window_size.get_height());
+ auto scene_height = static_cast<Vector2::Value>(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<ICursorController> cursor_controller,
- std::shared_ptr<IWindow> window) noexcept;
+ std::shared_ptr<IScene> scene) noexcept;
void initialize_background() noexcept override;
@@ -35,7 +35,7 @@ private:
std::unordered_map<StatusLineSection, uint32_t> _sections_lengths;
std::shared_ptr<ICursorController> _cursor_controller;
- std::shared_ptr<IWindow> _window;
+ std::shared_ptr<IScene> _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 <sys/ioctl.h>
-
-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 <yacppdic/auto_wirable.hpp>
-
-class Window : public IWindow, public yacppdic::AutoWirable<IWindow, Window>
-{
-public:
- Window() noexcept = default;
-
- [[nodiscard]] auto size() const noexcept -> Bounds override;
-};