diff --git a/include/omath/hud/hud_renderer_interface.hpp b/include/omath/hud/hud_renderer_interface.hpp index c131ba6..117cb7d 100644 --- a/include/omath/hud/hud_renderer_interface.hpp +++ b/include/omath/hud/hud_renderer_interface.hpp @@ -15,14 +15,19 @@ namespace omath::hud virtual void add_line(const Vector2& line_start, const Vector2& line_end, const Color& color, float thickness) = 0; - virtual void add_polyline(const std::span>& vertexes, const Color& color, float thickness) = 0; + virtual void add_polyline(const std::span>& vertexes, const Color& color, + float thickness) = 0; - virtual void add_filled_polyline(const std::span>& vertexes, const Color& color, float thickness) = 0; + virtual void add_filled_polyline(const std::span>& vertexes, const Color& color, + float thickness) = 0; virtual void add_rectangle(const Vector2& min, const Vector2& max, const Color& color) = 0; virtual void add_filled_rectangle(const Vector2& min, const Vector2& max, const Color& color) = 0; virtual void add_text(const Vector2& position, const Color& color, const std::string_view& text) = 0; + + [[nodiscard]] + virtual Vector2 calc_text_size(const std::string_view& text) = 0; }; } // namespace omath::hud diff --git a/include/omath/hud/renderer_realizations/imgui_renderer.hpp b/include/omath/hud/renderer_realizations/imgui_renderer.hpp index be7f637..cd4dbbe 100644 --- a/include/omath/hud/renderer_realizations/imgui_renderer.hpp +++ b/include/omath/hud/renderer_realizations/imgui_renderer.hpp @@ -3,6 +3,8 @@ // #pragma once #include + +#ifdef OMATH_IMGUI_INTEGRATION namespace omath::hud { class ImguiHudRenderer final : public HudRendererInterface @@ -16,5 +18,8 @@ namespace omath::hud void add_rectangle(const Vector2& min, const Vector2& max, const Color& color) override; void add_filled_rectangle(const Vector2& min, const Vector2& max, const Color& color) override; void add_text(const Vector2& position, const Color& color, const std::string_view& text) override; + [[nodiscard]] + virtual Vector2 calc_text_size(const std::string_view& text) override; }; -} \ No newline at end of file +} // namespace omath::hud +#endif // OMATH_IMGUI_INTEGRATION \ No newline at end of file diff --git a/source/hud/entity_overlay.cpp b/source/hud/entity_overlay.cpp index 11c8875..c560195 100644 --- a/source/hud/entity_overlay.cpp +++ b/source/hud/entity_overlay.cpp @@ -85,12 +85,12 @@ namespace omath::hud else m_renderer->add_text(m_text_cursor_right + Vector2{offset, 0.f}, color, text.data()); - m_text_cursor_right.y += ImGui::CalcTextSize(text.data()).y; + m_text_cursor_right.y += m_renderer->calc_text_size(text.data()).y; } void EntityOverlay::add_top_label(const Color& color, const float offset, const bool outlined, const std::string_view text) { - m_text_cursor_top.y -= ImGui::CalcTextSize(text.data()).y; + m_text_cursor_top.y -= m_renderer->calc_text_size(text.data()).y; if (outlined) draw_outlined_text(m_text_cursor_top + Vector2{0.f, -offset}, color, text); diff --git a/source/hud/renderer_realizations/imgui_renderer.cpp b/source/hud/renderer_realizations/imgui_renderer.cpp index 0f61f62..bfa90a9 100644 --- a/source/hud/renderer_realizations/imgui_renderer.cpp +++ b/source/hud/renderer_realizations/imgui_renderer.cpp @@ -2,6 +2,8 @@ // Created by orange on 13.03.2026. // #include "omath/hud/renderer_realizations/imgui_renderer.hpp" + +#ifdef OMATH_IMGUI_INTEGRATION #include namespace omath::hud @@ -11,26 +13,24 @@ namespace omath::hud void ImguiHudRenderer::add_line(const Vector2& line_start, const Vector2& line_end, const Color& color, const float thickness) { - ImGui::GetBackgroundDrawList()->AddLine(line_start.to_im_vec2(), line_end.to_im_vec2(), - color.to_im_color(), thickness); + ImGui::GetBackgroundDrawList()->AddLine(line_start.to_im_vec2(), line_end.to_im_vec2(), color.to_im_color(), + thickness); } void ImguiHudRenderer::add_polyline(const std::span>& vertexes, const Color& color, const float thickness) { - ImGui::GetBackgroundDrawList()->AddPolyline( - reinterpret_cast(vertexes.data()), - static_cast(vertexes.size()), - color.to_im_color(), ImDrawFlags_None, thickness); + ImGui::GetBackgroundDrawList()->AddPolyline(reinterpret_cast(vertexes.data()), + static_cast(vertexes.size()), color.to_im_color(), + ImDrawFlags_None, thickness); } void ImguiHudRenderer::add_filled_polyline(const std::span>& vertexes, const Color& color, const float thickness) { - ImGui::GetBackgroundDrawList()->AddPolyline( - reinterpret_cast(vertexes.data()), - static_cast(vertexes.size()), - color.to_im_color(), ImDrawFlags_Closed, thickness); + ImGui::GetBackgroundDrawList()->AddPolyline(reinterpret_cast(vertexes.data()), + static_cast(vertexes.size()), color.to_im_color(), + ImDrawFlags_Closed, thickness); } void ImguiHudRenderer::add_rectangle(const Vector2& min, const Vector2& max, const Color& color) @@ -39,15 +39,20 @@ namespace omath::hud } void ImguiHudRenderer::add_filled_rectangle(const Vector2& min, const Vector2& max, - const Color& color) + const Color& color) { ImGui::GetBackgroundDrawList()->AddRectFilled(min.to_im_vec2(), max.to_im_vec2(), color.to_im_color()); } - void ImguiHudRenderer::add_text(const Vector2& position, const Color& color, - const std::string_view& text) + void ImguiHudRenderer::add_text(const Vector2& position, const Color& color, const std::string_view& text) { ImGui::GetBackgroundDrawList()->AddText(position.to_im_vec2(), color.to_im_color(), text.data(), - text.data() + text.size()); + text.data() + text.size()); + } + [[nodiscard]] + virtual Vector2 calc_text_size(const std::string_view& text) + { + return Vector2::from_im_vec2(ImGui::CalcTextSize(text.data())); } } // namespace omath::hud +#endif // OMATH_IMGUI_INTEGRATION