From 19d796cd4e66f32eff5d695288d31297979e2af9 Mon Sep 17 00:00:00 2001 From: Orange Date: Sun, 15 Mar 2026 04:23:07 +0300 Subject: [PATCH] improvement --- include/omath/hud/entity_overlay.hpp | 18 ++++++++++++++---- source/hud/entity_overlay.cpp | 20 ++++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/omath/hud/entity_overlay.hpp b/include/omath/hud/entity_overlay.hpp index 3d868d6..b06fd62 100644 --- a/include/omath/hud/entity_overlay.hpp +++ b/include/omath/hud/entity_overlay.hpp @@ -79,14 +79,24 @@ namespace omath::hud void add_left_label(const Color& color, float offset, bool outlined, const std::string_view& text); template - void add_centered_label(const Color& color, const float offset, const bool outlined, - std::format_string fmt, Args&&... args) + void add_centered_bottom_label(const Color& color, const float offset, const bool outlined, + std::format_string fmt, Args&&... args) { const std::string label = std::vformat(fmt.get(), std::make_format_args(args...)); - add_centered_label(color, offset, outlined, std::string_view{label}); + add_centered_bottom_label(color, offset, outlined, std::string_view{label}); } - void add_centered_label(const Color& color, float offset, bool outlined, const std::string_view& text); + void add_centered_bottom_label(const Color& color, float offset, bool outlined, const std::string_view& text); + + template + void add_centered_top_label(const Color& color, const float offset, const bool outlined, + std::format_string fmt, Args&&... args) + { + const std::string label = std::vformat(fmt.get(), std::make_format_args(args...)); + add_centered_top_label(color, offset, outlined, std::string_view{label}); + } + + void add_centered_top_label(const Color& color, float offset, bool outlined, const std::string_view& text); private: void draw_outlined_text(const Vector2& position, const Color& color, diff --git a/source/hud/entity_overlay.cpp b/source/hud/entity_overlay.cpp index bb06b23..7049508 100644 --- a/source/hud/entity_overlay.cpp +++ b/source/hud/entity_overlay.cpp @@ -172,8 +172,8 @@ namespace omath::hud m_text_cursor_left.y += text_size.y; } - void EntityOverlay::add_centered_label(const Color& color, const float offset, const bool outlined, - const std::string_view& text) + void EntityOverlay::add_centered_bottom_label(const Color& color, const float offset, const bool outlined, + const std::string_view& text) { const auto text_size = m_renderer->calc_text_size(text); const auto box_center_x = m_canvas.bottom_left_corner.x @@ -188,6 +188,22 @@ namespace omath::hud m_text_cursor_bottom.y += text_size.y; } + void EntityOverlay::add_centered_top_label(const Color& color, const float offset, const bool outlined, + const std::string_view& text) + { + const auto text_size = m_renderer->calc_text_size(text); + const auto box_center_x = m_canvas.top_left_corner.x + + (m_canvas.top_right_corner.x - m_canvas.top_left_corner.x) / 2.f; + + m_text_cursor_top.y -= text_size.y; + const auto pos = Vector2{box_center_x - text_size.x / 2.f, m_text_cursor_top.y - offset}; + + if (outlined) + draw_outlined_text(pos, color, text); + else + m_renderer->add_text(pos, color, text); + } + EntityOverlay::EntityOverlay(const Vector2& top, const Vector2& bottom, const std::shared_ptr& renderer) : m_canvas(top, bottom), m_text_cursor_right(m_canvas.top_right_corner),