From 78f5d8cf644383adf20933ad64c160c07c2c54fb Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 20 Mar 2022 13:17:16 +0100 Subject: refactor: improve input configuring structure --- src/commands/move_cursor.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/commands/move_cursor.cpp (limited to 'src/commands/move_cursor.cpp') diff --git a/src/commands/move_cursor.cpp b/src/commands/move_cursor.cpp new file mode 100644 index 0000000..8dd7db7 --- /dev/null +++ b/src/commands/move_cursor.cpp @@ -0,0 +1,37 @@ +#include "move_cursor.hpp" + +#include "strings.hpp" + +#include + +MoveCursorCommand::MoveCursorCommand( + const Vector2 &direction, const std::shared_ptr &cursor_controller, + const std::shared_ptr &scene, const std::shared_ptr &window) noexcept + : _direction(direction), + _cursor_controller(cursor_controller), + _scene(scene), + _window(window) + +{ +} + +void MoveCursorCommand::execute() noexcept +{ + constexpr int32_t amount = 1; + + const auto new_position = + _cursor_controller->where().to_direction(_direction, amount); + + const auto window_size = _window->size(); + + if (window_size.validate_coords(new_position) != CoordsValidation::VALID) + { + return; + } + + _cursor_controller->move_to(new_position); + + _scene->write_status(fmt::format(STATUS_BAR_COORDINATES, + fmt::arg("x", new_position.get_x()), + fmt::arg("y", new_position.get_y()))); +} -- cgit v1.2.3-18-g5258