This commit is contained in:
2026-03-13 22:16:42 +03:00
parent af399a14ed
commit 746f1b84a8
4 changed files with 34 additions and 19 deletions

View File

@@ -15,14 +15,19 @@ namespace omath::hud
virtual void add_line(const Vector2<float>& line_start, const Vector2<float>& line_end, const Color& color,
float thickness) = 0;
virtual void add_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color, float thickness) = 0;
virtual void add_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color,
float thickness) = 0;
virtual void add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color, float thickness) = 0;
virtual void add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color,
float thickness) = 0;
virtual void add_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) = 0;
virtual void add_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) = 0;
virtual void add_text(const Vector2<float>& position, const Color& color, const std::string_view& text) = 0;
[[nodiscard]]
virtual Vector2<float> calc_text_size(const std::string_view& text) = 0;
};
} // namespace omath::hud

View File

@@ -3,6 +3,8 @@
//
#pragma once
#include <omath/hud/hud_renderer_interface.hpp>
#ifdef OMATH_IMGUI_INTEGRATION
namespace omath::hud
{
class ImguiHudRenderer final : public HudRendererInterface
@@ -16,5 +18,8 @@ namespace omath::hud
void add_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) override;
void add_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) override;
void add_text(const Vector2<float>& position, const Color& color, const std::string_view& text) override;
[[nodiscard]]
virtual Vector2<float> calc_text_size(const std::string_view& text) override;
};
}
} // namespace omath::hud
#endif // OMATH_IMGUI_INTEGRATION

View File

@@ -85,12 +85,12 @@ namespace omath::hud
else
m_renderer->add_text(m_text_cursor_right + Vector2<float>{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<float>{0.f, -offset}, color, text);

View File

@@ -2,6 +2,8 @@
// Created by orange on 13.03.2026.
//
#include "omath/hud/renderer_realizations/imgui_renderer.hpp"
#ifdef OMATH_IMGUI_INTEGRATION
#include <imgui.h>
namespace omath::hud
@@ -11,26 +13,24 @@ namespace omath::hud
void ImguiHudRenderer::add_line(const Vector2<float>& line_start, const Vector2<float>& 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<const Vector2<float>>& vertexes, const Color& color,
const float thickness)
{
ImGui::GetBackgroundDrawList()->AddPolyline(
reinterpret_cast<const ImVec2*>(vertexes.data()),
static_cast<int>(vertexes.size()),
color.to_im_color(), ImDrawFlags_None, thickness);
ImGui::GetBackgroundDrawList()->AddPolyline(reinterpret_cast<const ImVec2*>(vertexes.data()),
static_cast<int>(vertexes.size()), color.to_im_color(),
ImDrawFlags_None, thickness);
}
void ImguiHudRenderer::add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color,
const float thickness)
{
ImGui::GetBackgroundDrawList()->AddPolyline(
reinterpret_cast<const ImVec2*>(vertexes.data()),
static_cast<int>(vertexes.size()),
color.to_im_color(), ImDrawFlags_Closed, thickness);
ImGui::GetBackgroundDrawList()->AddPolyline(reinterpret_cast<const ImVec2*>(vertexes.data()),
static_cast<int>(vertexes.size()), color.to_im_color(),
ImDrawFlags_Closed, thickness);
}
void ImguiHudRenderer::add_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color)
@@ -39,15 +39,20 @@ namespace omath::hud
}
void ImguiHudRenderer::add_filled_rectangle(const Vector2<float>& min, const Vector2<float>& 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<float>& position, const Color& color,
const std::string_view& text)
void ImguiHudRenderer::add_text(const Vector2<float>& 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<float> calc_text_size(const std::string_view& text)
{
return Vector2<float>::from_im_vec2(ImGui::CalcTextSize(text.data()));
}
} // namespace omath::hud
#endif // OMATH_IMGUI_INTEGRATION