From 19f5d93dba74dda1fd1a9211707d98b6dd9b19ba Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 10 Mar 2022 21:03:50 +0100 Subject: feat: add status bar background color --- src/CMakeLists.txt | 1 + src/engine/graphics/scene.cpp | 8 +++++++- src/engine/graphics/scene.hpp | 2 ++ src/util/color.cpp | 15 +++++++++++++++ src/util/color.hpp | 10 ++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/util/color.cpp create mode 100644 src/util/color.hpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0ef0c8e..152272f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,7 @@ file(GLOB SOURCES conversion.cpp argument_parser.cpp input_actions.cpp + util/color.cpp game/game.cpp engine/engine.cpp engine/data/vector2.cpp diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index c4a398c..6b85915 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -1,7 +1,9 @@ #include "scene.hpp" #include "engine/escape.hpp" +#include "util/color.hpp" +#include #include #include #include @@ -49,10 +51,14 @@ void Scene::write_status(const std::string_view &str) noexcept const auto window_size = _window->size(); _cursor_controller->move_to( - Vector2({.x = 1, .y = static_cast(window_size.get_height())})); + Vector2({.x = 2, .y = static_cast(window_size.get_height())})); + const auto background_color = get_background_esc_seq(STATUSBAR_COLOR); + + fmt::print("{}", background_color); fmt::print(ERASE_ENTIRE_LINE, fmt::arg("esc", ESC)); fmt::print(fmt::runtime(str.data())); + fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); _cursor_controller->move_to(previous_position); } diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index 3d05cd9..22a96a4 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -14,6 +14,8 @@ constexpr fmt::string_view DISABLE_ALT_BUFFER = "{esc}[?1049l"; constexpr fmt::string_view ERASE_ENTIRE_LINE = "{esc}[2K"; +constexpr uint32_t STATUSBAR_COLOR = 0x1A1A1AU; + class Scene : public IScene { public: diff --git a/src/util/color.cpp b/src/util/color.cpp new file mode 100644 index 0000000..17665de --- /dev/null +++ b/src/util/color.cpp @@ -0,0 +1,15 @@ +#include "color.hpp" + +#include + +std::string get_foreground_esc_seq(const uint32_t &color) noexcept +{ + return std::string( + fmt::detail::make_foreground_color(fmt::detail::color_type(color)).begin()); +} + +std::string get_background_esc_seq(const uint32_t &color) noexcept +{ + return std::string( + fmt::detail::make_background_color(fmt::detail::color_type(color)).begin()); +} diff --git a/src/util/color.hpp b/src/util/color.hpp new file mode 100644 index 0000000..5511893 --- /dev/null +++ b/src/util/color.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +constexpr fmt::string_view RESET_ALL_MODES = "{esc}[0m"; + +std::string get_foreground_esc_seq(const uint32_t &color) noexcept; + +std::string get_background_esc_seq(const uint32_t &color) noexcept; -- cgit v1.2.3-18-g5258