mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-19 07:43:27 +00:00
added more stuff
This commit is contained in:
@@ -26,7 +26,7 @@ namespace omath::hud
|
|||||||
float ratio, float offset = 5.f);
|
float ratio, float offset = 5.f);
|
||||||
|
|
||||||
void add_left_bar(const Color& color, const Color& outline_color, const Color& bg_color, float width,
|
void add_left_bar(const Color& color, const Color& outline_color, const Color& bg_color, float width,
|
||||||
float ratio, float offset = 5.f) const;
|
float ratio, float offset = 5.f);
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void add_right_label(const Color& color, const float offset, const bool outlined,
|
void add_right_label(const Color& color, const float offset, const bool outlined,
|
||||||
@@ -55,12 +55,47 @@ namespace omath::hud
|
|||||||
|
|
||||||
void add_snap_line(const Vector2<float>& start_pos, const Color& color, float width);
|
void add_snap_line(const Vector2<float>& start_pos, const Color& color, float width);
|
||||||
|
|
||||||
|
void add_bottom_bar(const Color& color, const Color& outline_color, const Color& bg_color, float height,
|
||||||
|
float ratio, float offset = 5.f);
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void add_bottom_label(const Color& color, const float offset, const bool outlined,
|
||||||
|
std::format_string<Args...> fmt, Args&&... args)
|
||||||
|
{
|
||||||
|
const std::string label = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||||
|
add_bottom_label(color, offset, outlined, std::string_view{label});
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_bottom_label(const Color& color, float offset, bool outlined, std::string_view text);
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void add_left_label(const Color& color, const float offset, const bool outlined,
|
||||||
|
std::format_string<Args...> fmt, Args&&... args)
|
||||||
|
{
|
||||||
|
const std::string label = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||||
|
add_left_label(color, offset, outlined, std::string_view{label});
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_left_label(const Color& color, float offset, bool outlined, const std::string_view& text);
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void add_centered_label(const Color& color, const float offset, const bool outlined,
|
||||||
|
std::format_string<Args...> 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});
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_centered_label(const Color& color, float offset, bool outlined, const std::string_view& text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void draw_outlined_text(const Vector2<float>& position, const Color& color,
|
void draw_outlined_text(const Vector2<float>& position, const Color& color,
|
||||||
const std::string_view& text);
|
const std::string_view& text);
|
||||||
CanvasBox m_canvas;
|
CanvasBox m_canvas;
|
||||||
Vector2<float> m_text_cursor_right;
|
Vector2<float> m_text_cursor_right;
|
||||||
Vector2<float> m_text_cursor_top;
|
Vector2<float> m_text_cursor_top;
|
||||||
|
Vector2<float> m_text_cursor_bottom;
|
||||||
|
Vector2<float> m_text_cursor_left;
|
||||||
std::shared_ptr<HudRendererInterface> m_renderer;
|
std::shared_ptr<HudRendererInterface> m_renderer;
|
||||||
};
|
};
|
||||||
} // namespace omath::hud
|
} // namespace omath::hud
|
||||||
@@ -65,7 +65,7 @@ namespace omath::hud
|
|||||||
m_text_cursor_right.x += offset + width;
|
m_text_cursor_right.x += offset + width;
|
||||||
}
|
}
|
||||||
void EntityOverlay::add_left_bar(const Color& color, const Color& outline_color, const Color& bg_color,
|
void EntityOverlay::add_left_bar(const Color& color, const Color& outline_color, const Color& bg_color,
|
||||||
const float width, float ratio, const float offset) const
|
const float width, float ratio, const float offset)
|
||||||
{
|
{
|
||||||
ratio = std::clamp(ratio, 0.f, 1.f);
|
ratio = std::clamp(ratio, 0.f, 1.f);
|
||||||
const auto max_bar_height = std::abs(m_canvas.top_left_corner.y - m_canvas.bottom_right_corner.y);
|
const auto max_bar_height = std::abs(m_canvas.top_left_corner.y - m_canvas.bottom_right_corner.y);
|
||||||
@@ -76,6 +76,8 @@ namespace omath::hud
|
|||||||
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height * ratio), color);
|
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height * ratio), color);
|
||||||
m_renderer->add_rectangle(bar_start - Vector2<float>(1.f, 0.f),
|
m_renderer->add_rectangle(bar_start - Vector2<float>(1.f, 0.f),
|
||||||
bar_start + Vector2<float>(width, -max_bar_height), outline_color);
|
bar_start + Vector2<float>(width, -max_bar_height), outline_color);
|
||||||
|
|
||||||
|
m_text_cursor_left.x -= offset + width;
|
||||||
}
|
}
|
||||||
void EntityOverlay::add_right_label(const Color& color, const float offset, const bool outlined,
|
void EntityOverlay::add_right_label(const Color& color, const float offset, const bool outlined,
|
||||||
const std::string_view& text)
|
const std::string_view& text)
|
||||||
@@ -129,10 +131,68 @@ namespace omath::hud
|
|||||||
m_renderer->add_text(position + outline_offset, Color{0.f, 0.f, 0.f, 1.f}, text.data());
|
m_renderer->add_text(position + outline_offset, Color{0.f, 0.f, 0.f, 1.f}, text.data());
|
||||||
m_renderer->add_text(position, color, text.data());
|
m_renderer->add_text(position, color, text.data());
|
||||||
}
|
}
|
||||||
|
void EntityOverlay::add_bottom_bar(const Color& color, const Color& outline_color, const Color& bg_color,
|
||||||
|
const float height, float ratio, const float offset)
|
||||||
|
{
|
||||||
|
ratio = std::clamp(ratio, 0.f, 1.f);
|
||||||
|
const auto max_bar_width = std::abs(m_canvas.bottom_right_corner.x - m_canvas.bottom_left_corner.x);
|
||||||
|
|
||||||
|
const auto bar_start = m_canvas.bottom_left_corner + Vector2<float>{0.f, offset};
|
||||||
|
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width, height), bg_color);
|
||||||
|
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width * ratio, height), color);
|
||||||
|
m_renderer->add_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width, height), outline_color);
|
||||||
|
|
||||||
|
m_text_cursor_bottom.y += offset + height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityOverlay::add_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);
|
||||||
|
|
||||||
|
if (outlined)
|
||||||
|
draw_outlined_text(m_text_cursor_bottom + Vector2<float>{0.f, offset}, color, text);
|
||||||
|
else
|
||||||
|
m_renderer->add_text(m_text_cursor_bottom + Vector2<float>{0.f, offset}, color, text);
|
||||||
|
|
||||||
|
m_text_cursor_bottom.y += text_size.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityOverlay::add_left_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 pos = m_text_cursor_left + Vector2<float>{-(offset + text_size.x), 0.f};
|
||||||
|
|
||||||
|
if (outlined)
|
||||||
|
draw_outlined_text(pos, color, text);
|
||||||
|
else
|
||||||
|
m_renderer->add_text(pos, color, text);
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
const auto text_size = m_renderer->calc_text_size(text);
|
||||||
|
const auto box_center_x = m_canvas.bottom_left_corner.x
|
||||||
|
+ (m_canvas.bottom_right_corner.x - m_canvas.bottom_left_corner.x) / 2.f;
|
||||||
|
const auto pos = Vector2<float>{box_center_x - text_size.x / 2.f, m_text_cursor_bottom.y + offset};
|
||||||
|
|
||||||
|
if (outlined)
|
||||||
|
draw_outlined_text(pos, color, text);
|
||||||
|
else
|
||||||
|
m_renderer->add_text(pos, color, text);
|
||||||
|
|
||||||
|
m_text_cursor_bottom.y += text_size.y;
|
||||||
|
}
|
||||||
|
|
||||||
EntityOverlay::EntityOverlay(const Vector2<float>& top, const Vector2<float>& bottom,
|
EntityOverlay::EntityOverlay(const Vector2<float>& top, const Vector2<float>& bottom,
|
||||||
const std::shared_ptr<HudRendererInterface>& renderer)
|
const std::shared_ptr<HudRendererInterface>& renderer)
|
||||||
: m_canvas(top, bottom), m_text_cursor_right(m_canvas.top_right_corner),
|
: m_canvas(top, bottom), m_text_cursor_right(m_canvas.top_right_corner),
|
||||||
m_text_cursor_top(m_canvas.top_left_corner), m_renderer(renderer)
|
m_text_cursor_top(m_canvas.top_left_corner), m_text_cursor_bottom(m_canvas.bottom_left_corner),
|
||||||
|
m_text_cursor_left(m_canvas.top_left_corner), m_renderer(renderer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
} // namespace omath::hud
|
} // namespace omath::hud
|
||||||
@@ -22,7 +22,7 @@ namespace omath::hud
|
|||||||
{
|
{
|
||||||
ImGui::GetBackgroundDrawList()->AddPolyline(reinterpret_cast<const ImVec2*>(vertexes.data()),
|
ImGui::GetBackgroundDrawList()->AddPolyline(reinterpret_cast<const ImVec2*>(vertexes.data()),
|
||||||
static_cast<int>(vertexes.size()), color.to_im_color(),
|
static_cast<int>(vertexes.size()), color.to_im_color(),
|
||||||
ImDrawFlags_None, thickness);
|
ImDrawFlags_Closed, thickness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImguiHudRenderer::add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color,
|
void ImguiHudRenderer::add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color,
|
||||||
@@ -50,7 +50,7 @@ namespace omath::hud
|
|||||||
text.data() + text.size());
|
text.data() + text.size());
|
||||||
}
|
}
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector2<float> calc_text_size(const std::string_view& text)
|
Vector2<float> ImguiHudRenderer::calc_text_size(const std::string_view& text)
|
||||||
{
|
{
|
||||||
return Vector2<float>::from_im_vec2(ImGui::CalcTextSize(text.data()));
|
return Vector2<float>::from_im_vec2(ImGui::CalcTextSize(text.data()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user