From 0e40bc7ce8c3b3be083002f88c3317d65f6570ad Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 6 Mar 2022 13:16:05 +0100 Subject: refactor: make vector2 & bounds data classes --- src/engine/user/cursor.cpp | 13 ++++--------- src/engine/user/cursor.hpp | 15 ++++++--------- 2 files changed, 10 insertions(+), 18 deletions(-) (limited to 'src/engine/user') diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp index 9d6e28c..d4a2997 100644 --- a/src/engine/user/cursor.cpp +++ b/src/engine/user/cursor.cpp @@ -5,29 +5,24 @@ #include #include -CursorController::CursorController(IVector2Factory vector2_factory) - : _vector2_factory(vector2_factory) -{ -} - -void CursorController::move_to(const IVector2 &pos) +void CursorController::move_to(const Vector2 &pos) { fmt::print(MOVE_CURSOR_TO, fmt::arg("esc", ESC), fmt::arg("row", pos.y()), fmt::arg("column", pos.x())); std::cout.flush(); } -std::shared_ptr CursorController::where() +Vector2 CursorController::where() { fmt::print(REQUEST_CURSOR_POSITION, fmt::arg("esc", ESC)); std::cout.flush(); - IVector2Options vector2_options = {}; + Vector2Options vector2_options = {}; // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) scanf("\033[%u;%uR", &vector2_options.y, &vector2_options.x); - return _vector2_factory(vector2_options); + return Vector2(vector2_options); } void CursorController::hide() diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp index 0317dc5..69d639a 100644 --- a/src/engine/user/cursor.hpp +++ b/src/engine/user/cursor.hpp @@ -2,7 +2,8 @@ #include "DI/auto_wirable.hpp" #include "interfaces/direction.hpp" -#include "interfaces/vector2.hpp" + +#include "engine/data/vector2.hpp" #include "fmt/core.h" #include @@ -21,25 +22,21 @@ constexpr fmt::string_view REQUEST_CURSOR_POSITION = "{esc}[6n"; constexpr fmt::string_view CURSOR_VISIBLE = "{esc}[?25h"; constexpr fmt::string_view CURSOR_INVISIBLE = "{esc}[?25l"; -class CursorController - : public AutoWirable +class CursorController : public AutoWirable { public: - explicit CursorController(IVector2Factory vector2_factory); + CursorController() = default; template constexpr void move(const unsigned int &amount) const; - static void move_to(const IVector2 &pos); + static void move_to(const Vector2 &pos); static void hide(); static void show(); - [[nodiscard]] std::shared_ptr where(); - -private: - IVector2Factory _vector2_factory; + [[nodiscard]] static Vector2 where(); }; #include "cursor.tpp" -- cgit v1.2.3-18-g5258