From 8805b1fe27344e8086cebabf869b7a02d2376f05 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 7 Jun 2022 19:45:17 +0200 Subject: refactor: decouple statusline from scene & cursor controller Might be slightly slower than previously though... --- src/engine/graphics/statusline.cpp | 112 ------------------------------------- 1 file changed, 112 deletions(-) delete mode 100644 src/engine/graphics/statusline.cpp (limited to 'src/engine/graphics/statusline.cpp') diff --git a/src/engine/graphics/statusline.cpp b/src/engine/graphics/statusline.cpp deleted file mode 100644 index bc83993..0000000 --- a/src/engine/graphics/statusline.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "statusline.hpp" - -#include "engine/escape.hpp" -#include "util/color.hpp" - -#include -#include - -StatusLine::StatusLine( - std::shared_ptr cursor_controller, - std::shared_ptr scene) noexcept - : _cursor_controller(std::move(cursor_controller)), _scene(std::move(scene)) -{ -} - -void StatusLine::initialize_background() noexcept -{ - const auto previous_position = _move_to_statusline(0); - - auto background_color = get_background_esc_seq(STATUSBAR_COLOR); - - fmt::print("{}{}", background_color, std::string(_scene->size().get_width(), ' ')); - fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); - - _move_back(previous_position); -} - -void StatusLine::set_status( - const StatusLineSection §ion, - const std::string_view &status, - std::size_t start) noexcept -{ - _clear_section(section, start); - - auto section_start = _get_section_start_x(section); - - const auto previous_position = - _move_to_statusline(section_start + static_cast(start)); - - auto background_color = get_background_esc_seq(STATUSBAR_COLOR); - - auto section_length = _sections_lengths[section]; - - fmt::print("{}{}", background_color, status); - fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); - - _move_back(previous_position); -} - -void StatusLine::set_section_length( - const StatusLineSection §ion, - uint32_t length) noexcept -{ - _sections_lengths[section] = length; -} - -auto StatusLine::_move_to_statusline(int32_t x) noexcept -> Vector2 -{ - const auto previous_position = _cursor_controller->where(); - - _cursor_controller->hide(); - - _cursor_controller->move_to(Vector2({.x = x, .y = 0})); - - return previous_position; -} - -void StatusLine::_move_back(Vector2 previous_position) noexcept -{ - _cursor_controller->move_to(previous_position); - _cursor_controller->show(); -} - -auto StatusLine::_get_section_start_x(const StatusLineSection §ion) const noexcept - -> int32_t -{ - int32_t section_start = 0; - - auto section_index = static_cast(section); - - while (section_index > 0) - { - section_start += static_cast( - _sections_lengths.at(StatusLineSection(section_index - 1))); - - section_index--; - } - - return section_start; -} - -void StatusLine::_clear_section( - const StatusLineSection §ion, - std::size_t start) noexcept -{ - auto section_start = _get_section_start_x(section); - - auto start_int32 = static_cast(start); - - const auto previous_position = _move_to_statusline(section_start + start_int32); - - auto background_color = get_background_esc_seq(STATUSBAR_COLOR); - - auto section_length = _sections_lengths[section]; - - auto start_uint32 = static_cast(start); - - fmt::print("{}{}", background_color, std::string(section_length - start_uint32, ' ')); - fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); - - _move_back(previous_position); -} -- cgit v1.2.3-18-g5258