diff options
Diffstat (limited to 'src/engine/user/cursor.cpp')
-rw-r--r-- | src/engine/user/cursor.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp index 97e9104..70828c3 100644 --- a/src/engine/user/cursor.cpp +++ b/src/engine/user/cursor.cpp @@ -5,7 +5,10 @@ #include <cstdlib> #include <iostream> -CursorController::CursorController() noexcept : _position({.x = 0, .y = 0}) {} +CursorController::CursorController() noexcept + : _position({.x = 0, .y = 0}), _bounds({0, 0}) +{ +} void CursorController::move(const Vector2 &direction, const uint32_t &amount) noexcept { @@ -22,11 +25,13 @@ void CursorController::move(const Vector2 &direction, const uint32_t &amount) no void CursorController::move_to(const Vector2 &position) noexcept { + const auto inverted_pos = _invert_position_y(position); + fmt::print( MOVE_CURSOR_TO, fmt::arg("esc", ESC), - fmt::arg("row", position.get_y()), - fmt::arg("column", position.get_x())); + fmt::arg("row", inverted_pos.get_y()), + fmt::arg("column", inverted_pos.get_x())); std::cout.flush(); _position = position; @@ -47,7 +52,7 @@ void CursorController::ensure_position() noexcept // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) scanf("\033[%u;%uR", &vector2_options.y, &vector2_options.x); - _position = Vector2(vector2_options); + _position = _invert_position_y(Vector2(vector2_options)); } void CursorController::hide() noexcept @@ -61,3 +66,17 @@ void CursorController::show() noexcept fmt::print(CURSOR_VISIBLE, fmt::arg("esc", ESC)); std::cout.flush(); } + +void CursorController::set_bounds(const Bounds &bounds) noexcept +{ + _bounds = bounds; +} + +auto CursorController::_invert_position_y(const Vector2 &position) const noexcept + -> Vector2 +{ + const auto bounds_height = static_cast<Vector2::Value>(_bounds.get_height()); + + return Vector2({.x = position.get_x(), .y = bounds_height - position.get_y()}); +} + |