mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-18 17:03:27 +00:00
added icon
This commit is contained in:
@@ -138,6 +138,16 @@ namespace omath::hud
|
||||
EntityOverlay& add_bottom_progress_ring(const Color& color, const Color& bg, float radius, float ratio,
|
||||
float thickness = 2.f, float offset = 5.f, int segments = 0);
|
||||
|
||||
// ── Icons ────────────────────────────────────────────────────────
|
||||
EntityOverlay& add_right_icon(const std::any& texture_id, float width, float height,
|
||||
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}, float offset = 5.f);
|
||||
EntityOverlay& add_left_icon(const std::any& texture_id, float width, float height,
|
||||
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}, float offset = 5.f);
|
||||
EntityOverlay& add_top_icon(const std::any& texture_id, float width, float height,
|
||||
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}, float offset = 5.f);
|
||||
EntityOverlay& add_bottom_icon(const std::any& texture_id, float width, float height,
|
||||
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}, float offset = 5.f);
|
||||
|
||||
// ── Misc ─────────────────────────────────────────────────────────
|
||||
EntityOverlay& add_snap_line(const Vector2<float>& start_pos, const Color& color, float width);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
#include "omath/linear_algebra/vector2.hpp"
|
||||
#include "omath/utility/color.hpp"
|
||||
#include <any>
|
||||
#include <initializer_list>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
@@ -137,11 +138,21 @@ namespace omath::hud::widget
|
||||
int segments = 32;
|
||||
};
|
||||
|
||||
struct Icon
|
||||
{
|
||||
std::any texture_id;
|
||||
float width;
|
||||
float height;
|
||||
Color tint{1.f, 1.f, 1.f, 1.f};
|
||||
float offset = 5.f;
|
||||
};
|
||||
|
||||
// ── Side widget variant ───────────────────────────────────────────────────
|
||||
struct None
|
||||
{
|
||||
}; ///< No-op placeholder — used by widget::when for disabled elements.
|
||||
using SideWidget = std::variant<None, Bar, DashedBar, Label, Centered<Label>, SpaceVertical, SpaceHorizontal, ProgressRing>;
|
||||
using SideWidget =
|
||||
std::variant<None, Bar, DashedBar, Label, Centered<Label>, SpaceVertical, SpaceHorizontal, ProgressRing, Icon>;
|
||||
|
||||
// ── Side containers ───────────────────────────────────────────────────────
|
||||
// Storing std::initializer_list<SideWidget> is safe here: the backing array
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
#include "omath/linear_algebra/vector2.hpp"
|
||||
#include "omath/utility/color.hpp"
|
||||
#include <any>
|
||||
#include <span>
|
||||
|
||||
namespace omath::hud
|
||||
@@ -34,6 +35,10 @@ namespace omath::hud
|
||||
virtual void add_arc(const Vector2<float>& center, float radius, float a_min, float a_max, const Color& color,
|
||||
float thickness, int segments = 0) = 0;
|
||||
|
||||
/// Draw a textured quad. texture_id is renderer-specific (e.g. ImTextureID for ImGui).
|
||||
virtual void add_image(const std::any& texture_id, const Vector2<float>& min, const Vector2<float>& max,
|
||||
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}) = 0;
|
||||
|
||||
virtual void add_text(const Vector2<float>& position, const Color& color, const std::string_view& text) = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace omath::hud
|
||||
int segments = 0) override;
|
||||
void add_arc(const Vector2<float>& center, float radius, float a_min, float a_max, const Color& color,
|
||||
float thickness, int segments = 0) override;
|
||||
void add_image(const std::any& texture_id, const Vector2<float>& min, const Vector2<float>& max,
|
||||
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}) 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;
|
||||
|
||||
@@ -551,6 +551,43 @@ namespace omath::hud
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ── Icons ────────────────────────────────────────────────────────────────────
|
||||
EntityOverlay& EntityOverlay::add_right_icon(const std::any& texture_id, const float width, const float height,
|
||||
const Color& tint, const float offset)
|
||||
{
|
||||
const auto pos = m_text_cursor_right + Vector2<float>{offset, 0.f};
|
||||
m_renderer->add_image(texture_id, pos, pos + Vector2<float>{width, height}, tint);
|
||||
m_text_cursor_right.y += height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
EntityOverlay& EntityOverlay::add_left_icon(const std::any& texture_id, const float width, const float height,
|
||||
const Color& tint, const float offset)
|
||||
{
|
||||
const auto pos = m_text_cursor_left + Vector2<float>{-(offset + width), 0.f};
|
||||
m_renderer->add_image(texture_id, pos, pos + Vector2<float>{width, height}, tint);
|
||||
m_text_cursor_left.y += height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
EntityOverlay& EntityOverlay::add_top_icon(const std::any& texture_id, const float width, const float height,
|
||||
const Color& tint, const float offset)
|
||||
{
|
||||
m_text_cursor_top.y -= height;
|
||||
const auto pos = m_text_cursor_top + Vector2<float>{0.f, -offset};
|
||||
m_renderer->add_image(texture_id, pos, pos + Vector2<float>{width, height}, tint);
|
||||
return *this;
|
||||
}
|
||||
|
||||
EntityOverlay& EntityOverlay::add_bottom_icon(const std::any& texture_id, const float width, const float height,
|
||||
const Color& tint, const float offset)
|
||||
{
|
||||
const auto pos = m_text_cursor_bottom + Vector2<float>{0.f, offset};
|
||||
m_renderer->add_image(texture_id, pos, pos + Vector2<float>{width, height}, tint);
|
||||
m_text_cursor_bottom.y += height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ── widget dispatch ───────────────────────────────────────────────────────
|
||||
void EntityOverlay::dispatch(const widget::Box& box)
|
||||
{
|
||||
@@ -659,6 +696,10 @@ namespace omath::hud
|
||||
add_right_progress_ring(w.color, w.bg, w.radius, w.ratio, w.thickness, w.offset,
|
||||
w.segments);
|
||||
},
|
||||
[this](const widget::Icon& w)
|
||||
{
|
||||
add_right_icon(w.texture_id, w.width, w.height, w.tint, w.offset);
|
||||
},
|
||||
},
|
||||
child);
|
||||
}
|
||||
@@ -701,6 +742,10 @@ namespace omath::hud
|
||||
add_left_progress_ring(w.color, w.bg, w.radius, w.ratio, w.thickness, w.offset,
|
||||
w.segments);
|
||||
},
|
||||
[this](const widget::Icon& w)
|
||||
{
|
||||
add_left_icon(w.texture_id, w.width, w.height, w.tint, w.offset);
|
||||
},
|
||||
},
|
||||
child);
|
||||
}
|
||||
@@ -743,6 +788,10 @@ namespace omath::hud
|
||||
add_top_progress_ring(w.color, w.bg, w.radius, w.ratio, w.thickness, w.offset,
|
||||
w.segments);
|
||||
},
|
||||
[this](const widget::Icon& w)
|
||||
{
|
||||
add_top_icon(w.texture_id, w.width, w.height, w.tint, w.offset);
|
||||
},
|
||||
},
|
||||
child);
|
||||
}
|
||||
@@ -785,6 +834,10 @@ namespace omath::hud
|
||||
add_bottom_progress_ring(w.color, w.bg, w.radius, w.ratio, w.thickness, w.offset,
|
||||
w.segments);
|
||||
},
|
||||
[this](const widget::Icon& w)
|
||||
{
|
||||
add_bottom_icon(w.texture_id, w.width, w.height, w.tint, w.offset);
|
||||
},
|
||||
},
|
||||
child);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,13 @@ namespace omath::hud
|
||||
ImGui::GetBackgroundDrawList()->PathStroke(color.to_im_color(), ImDrawFlags_None, thickness);
|
||||
}
|
||||
|
||||
void ImguiHudRenderer::add_image(const std::any& texture_id, const Vector2<float>& min, const Vector2<float>& max,
|
||||
const Color& tint)
|
||||
{
|
||||
ImGui::GetBackgroundDrawList()->AddImage(std::any_cast<ImTextureID>(texture_id), min.to_im_vec2(),
|
||||
max.to_im_vec2(), {0, 0}, {1, 1}, tint.to_im_color());
|
||||
}
|
||||
|
||||
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(),
|
||||
|
||||
Reference in New Issue
Block a user