gradient text + box fill

This commit is contained in:
2026-07-11 18:05:20 +03:00
parent 78d92a3c0f
commit 176f5b2aa1
9 changed files with 233 additions and 87 deletions
+25 -14
View File
@@ -30,6 +30,9 @@ namespace omath::hud
EntityOverlay& add_2d_box(const Color& box_color, const Color& fill_color = Color{0.f, 0.f, 0.f, 0.f},
const Color& outline_color = Color{0.f, 0.f, 0.f, 0.f}, float thickness = 1.f);
EntityOverlay& add_2d_box(const Color& box_color, const Gradient& fill_gradient,
const Color& outline_color = Color{0.f, 0.f, 0.f, 0.f}, float thickness = 1.f);
EntityOverlay& add_cornered_2d_box(const Color& box_color, const Color& fill_color = Color{0.f, 0.f, 0.f, 0.f},
const Color& outline_color = Color{0.f, 0.f, 0.f, 0.f},
float corner_ratio_len = 0.2f, float thickness = 1.f);
@@ -65,26 +68,27 @@ namespace omath::hud
float offset = 5.f);
// ── Labels ───────────────────────────────────────────────────────
EntityOverlay& add_right_label(const Color& color, float offset, widget::Outlined outlined,
EntityOverlay& add_right_label(const widget::Paint& color, float offset, widget::Outlined outlined,
const std::string_view& text);
EntityOverlay& add_left_label(const Color& color, float offset, widget::Outlined outlined,
EntityOverlay& add_left_label(const widget::Paint& color, float offset, widget::Outlined outlined,
const std::string_view& text);
EntityOverlay& add_top_label(const Color& color, float offset, widget::Outlined outlined,
EntityOverlay& add_top_label(const widget::Paint& color, float offset, widget::Outlined outlined,
std::string_view text);
EntityOverlay& add_bottom_label(const Color& color, float offset, widget::Outlined outlined,
EntityOverlay& add_bottom_label(const widget::Paint& color, float offset, widget::Outlined outlined,
std::string_view text);
EntityOverlay& add_centered_top_label(const Color& color, float offset, widget::Outlined outlined,
EntityOverlay& add_centered_top_label(const widget::Paint& color, float offset, widget::Outlined outlined,
const std::string_view& text);
EntityOverlay& add_centered_bottom_label(const Color& color, float offset, widget::Outlined outlined,
EntityOverlay& add_centered_bottom_label(const widget::Paint& color, float offset, widget::Outlined outlined,
const std::string_view& text);
template<typename... Args>
EntityOverlay& add_right_label(const Color& color, const float offset, const widget::Outlined outlined,
requires(sizeof...(Args) > 0)
EntityOverlay& add_right_label(const widget::Paint& color, const float offset, const widget::Outlined outlined,
std::format_string<Args...> fmt, Args&&... args)
{
return add_right_label(color, offset, outlined,
@@ -92,7 +96,8 @@ namespace omath::hud
}
template<typename... Args>
EntityOverlay& add_left_label(const Color& color, const float offset, const widget::Outlined outlined,
requires(sizeof...(Args) > 0)
EntityOverlay& add_left_label(const widget::Paint& color, const float offset, const widget::Outlined outlined,
std::format_string<Args...> fmt, Args&&... args)
{
return add_left_label(color, offset, outlined,
@@ -100,7 +105,8 @@ namespace omath::hud
}
template<typename... Args>
EntityOverlay& add_top_label(const Color& color, const float offset, const widget::Outlined outlined,
requires(sizeof...(Args) > 0)
EntityOverlay& add_top_label(const widget::Paint& color, const float offset, const widget::Outlined outlined,
std::format_string<Args...> fmt, Args&&... args)
{
return add_top_label(color, offset, outlined,
@@ -108,7 +114,8 @@ namespace omath::hud
}
template<typename... Args>
EntityOverlay& add_bottom_label(const Color& color, const float offset, const widget::Outlined outlined,
requires(sizeof...(Args) > 0)
EntityOverlay& add_bottom_label(const widget::Paint& color, const float offset, const widget::Outlined outlined,
std::format_string<Args...> fmt, Args&&... args)
{
return add_bottom_label(color, offset, outlined,
@@ -116,15 +123,18 @@ namespace omath::hud
}
template<typename... Args>
EntityOverlay& add_centered_top_label(const Color& color, const float offset, const widget::Outlined outlined,
std::format_string<Args...> fmt, Args&&... args)
requires(sizeof...(Args) > 0)
EntityOverlay& add_centered_top_label(const widget::Paint& color, const float offset,
const widget::Outlined outlined, std::format_string<Args...> fmt,
Args&&... args)
{
return add_centered_top_label(color, offset, outlined,
std::string_view{std::vformat(fmt.get(), std::make_format_args(args...))});
}
template<typename... Args>
EntityOverlay& add_centered_bottom_label(const Color& color, const float offset,
requires(sizeof...(Args) > 0)
EntityOverlay& add_centered_bottom_label(const widget::Paint& color, const float offset,
const widget::Outlined outlined, std::format_string<Args...> fmt,
Args&&... args)
{
@@ -242,7 +252,8 @@ namespace omath::hud
void dispatch(const widget::AimDot& aim_dot);
void dispatch(const widget::ProjectileAim& proj_widget);
void draw_progress_ring(const Vector2<float>& center, const widget::ProgressRing& ring);
void draw_outlined_text(const Vector2<float>& position, const Color& color, const std::string_view& text);
void draw_label(const Vector2<float>& position, const widget::Paint& paint, widget::Outlined outlined,
const std::string_view& text);
void draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color, float dash_len,
float gap_len, float thickness) const;
void draw_dashed_fill(const Vector2<float>& origin, const Vector2<float>& step_dir,
+15 -5
View File
@@ -2,6 +2,7 @@
// Created by orange on 15.03.2026.
//
#pragma once
#include "gradient.hpp"
#include "omath/linear_algebra/vector2.hpp"
#include "omath/utility/color.hpp"
#include <any>
@@ -12,6 +13,16 @@
namespace omath::hud::widget
{
struct Paint : std::variant<Color, Gradient>
{
using std::variant<Color, Gradient>::variant;
constexpr Paint(const float red, const float green, const float blue, const float alpha)
: std::variant<Color, Gradient>(Color{red, green, blue, alpha})
{
}
};
// ── Overloaded helper for std::visit ──────────────────────────────────────
template<typename... Ts>
struct Overloaded : Ts...
@@ -25,7 +36,7 @@ namespace omath::hud::widget
struct Box
{
Color color;
Color fill{0.f, 0.f, 0.f, 0.f};
Paint fill{Color{0.f, 0.f, 0.f, 0.f}};
Color outline{0.f, 0.f, 0.f, 0.f};
float thickness = 1.f;
};
@@ -92,7 +103,6 @@ namespace omath::hud::widget
Figure figure = Figure::SQUARE;
};
// ── Side-agnostic widgets (used inside XxxSide containers) ────────────────
/// A filled bar. `size` is width for left/right sides, height for top/bottom.
@@ -121,7 +131,7 @@ namespace omath::hud::widget
struct Label
{
Color color;
Paint color;
float offset;
Outlined outlined;
std::string_view text;
@@ -172,8 +182,8 @@ namespace omath::hud::widget
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, Icon>;
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
+13
View File
@@ -0,0 +1,13 @@
#pragma once
#include "omath/utility/color.hpp"
namespace omath::hud
{
struct Gradient
{
Color top_left;
Color top_right;
Color bottom_right;
Color bottom_left;
};
} // namespace omath::hud
@@ -2,6 +2,7 @@
// Created by orange on 13.03.2026.
//
#pragma once
#include "gradient.hpp"
#include "omath/linear_algebra/vector2.hpp"
#include "omath/utility/color.hpp"
#include <any>
@@ -25,6 +26,12 @@ namespace omath::hud
virtual void add_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) = 0;
virtual void add_gradient_rectangle(const Vector2<float>& min, const Vector2<float>& max,
const Gradient& gradient)
{
add_filled_rectangle(min, max, gradient.top_left);
}
virtual void add_circle(const Vector2<float>& center, float radius, const Color& color, float thickness,
int segments = 0) = 0;
@@ -41,6 +48,12 @@ namespace omath::hud
virtual void add_text(const Vector2<float>& position, const Color& color, const std::string_view& text) = 0;
virtual void add_gradient_text(const Vector2<float>& position, const Gradient& gradient,
const std::string_view& text)
{
add_text(position, gradient.top_left, text);
}
[[nodiscard]]
virtual Vector2<float> calc_text_size(const std::string_view& text) = 0;
};
@@ -13,10 +13,13 @@ namespace omath::hud
~ImguiHudRenderer() override;
void add_line(const Vector2<float>& line_start, const Vector2<float>& line_end, const Color& color,
float thickness) override;
void add_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color, float thickness) override;
void add_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color,
float thickness) override;
void add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color) override;
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_gradient_rectangle(const Vector2<float>& min, const Vector2<float>& max,
const Gradient& gradient) override;
void add_circle(const Vector2<float>& center, float radius, const Color& color, float thickness,
int segments = 0) override;
void add_filled_circle(const Vector2<float>& center, float radius, const Color& color,
@@ -26,8 +29,10 @@ namespace omath::hud
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;
void add_gradient_text(const Vector2<float>& position, const Gradient& gradient,
const std::string_view& text) override;
[[nodiscard]]
Vector2<float> calc_text_size(const std::string_view& text) override;
};
} // namespace omath::hud
#endif // OMATH_IMGUI_INTEGRATION
#endif // OMATH_IMGUI_INTEGRATION