Compare commits

..

4 Commits

Author SHA1 Message Date
orange 945f80241c Merge pull request #202 from orange-cpp/feature/gradient
Feature/gradient
2026-07-12 18:09:44 +03:00
orange 238d6aef4e improve skeleton esp 2026-07-12 11:27:34 +03:00
orange feb26e01c6 improved bars 2026-07-12 11:17:50 +03:00
orange 2c6d7c2dfa bar fixes 2026-07-12 11:10:13 +03:00
4 changed files with 180 additions and 44 deletions
+45 -16
View File
@@ -237,6 +237,44 @@ namespace imgui_desktop::gui
const auto* vp = ImGui::GetMainViewport();
const DashedBar dbar{m_bar_color, m_bar_outline_color, m_bar_bg_color, m_bar_width,
m_bar_value, m_bar_dash_len, m_bar_dash_gap, m_bar_offset};
const float entity_height = m_entity_bottom_y - m_entity_top_y;
const float entity_half_width = entity_height / m_entity_aspect;
const auto joint = [&](const float x, const float y)
{
return omath::Vector2<float>{m_entity_x + (x * 2.f - 1.f) * entity_half_width,
m_entity_top_y + y * entity_height};
};
const auto head = joint(0.5f, 0.1f);
const auto neck = joint(0.5f, 0.22f);
const auto torso = joint(0.5f, 0.5f);
const auto left_shoulder = joint(0.3f, 0.25f);
const auto right_shoulder = joint(0.7f, 0.25f);
const auto left_elbow = joint(0.18f, 0.42f);
const auto right_elbow = joint(0.82f, 0.42f);
const auto left_hand = joint(0.1f, 0.58f);
const auto right_hand = joint(0.9f, 0.58f);
const auto left_hip = joint(0.4f, 0.55f);
const auto right_hip = joint(0.6f, 0.55f);
const auto left_knee = joint(0.36f, 0.75f);
const auto right_knee = joint(0.64f, 0.75f);
const auto left_foot = joint(0.3f, 0.95f);
const auto right_foot = joint(0.7f, 0.95f);
const std::array skeleton_bones = {
Bone{head, neck},
Bone{neck, torso},
Bone{neck, left_shoulder},
Bone{left_shoulder, left_elbow},
Bone{left_elbow, left_hand},
Bone{neck, right_shoulder},
Bone{right_shoulder, right_elbow},
Bone{right_elbow, right_hand},
Bone{torso, left_hip},
Bone{left_hip, left_knee},
Bone{left_knee, left_foot},
Bone{torso, right_hip},
Bone{right_hip, right_knee},
Bone{right_knee, right_foot},
};
const auto animated_color = [&](const omath::Color& color, const float hue_offset)
{
if (!m_animate_gradients)
@@ -251,7 +289,6 @@ namespace imgui_desktop::gui
const auto box_gradient_bottom = animated_color(m_box_gradient_bottom, 0.5f);
const auto red = omath::Color{1.f, 0.f, 0.f, 1.f};
const auto green = omath::Color{0.f, 1.f, 0.f, 1.f};
const auto bar_value_color = omath::Color{red.value() * (1.f - m_bar_value) + green.value() * m_bar_value};
const auto make_glow = [](const GlowSettings& settings) -> std::optional<Glow>
{
if (!settings.enabled)
@@ -263,16 +300,8 @@ namespace imgui_desktop::gui
const auto bar_glow = make_glow(m_bar_glow);
const auto label_glow = make_glow(m_label_glow);
const auto canvas_glow = make_glow(m_canvas_glow);
const Paint vertical_bar_color =
m_gradient_bars ? Paint{omath::hud::Gradient{bar_value_color, bar_value_color, red, red}}
: Paint{m_bar_color};
const Paint horizontal_bar_color =
m_gradient_bars ? Paint{omath::hud::Gradient{red, bar_value_color, bar_value_color, red}}
: Paint{m_bar_color};
const Bar vertical_bar{vertical_bar_color, m_bar_outline_color, m_bar_bg_color, m_bar_width,
m_bar_value, m_bar_offset, bar_glow};
const Bar horizontal_bar{horizontal_bar_color, m_bar_outline_color, m_bar_bg_color, m_bar_width,
m_bar_value, m_bar_offset, bar_glow};
const BarPaint bar_color = m_gradient_bars ? BarPaint{BarGradient{red, green}} : BarPaint{m_bar_color};
const Bar bar{bar_color, m_bar_outline_color, m_bar_bg_color, m_bar_width, m_bar_value, m_bar_offset, bar_glow};
const Paint box_fill = m_gradient_box_fill
? Paint{omath::hud::Gradient{box_gradient_top, box_gradient_top,
box_gradient_bottom, box_gradient_bottom}}
@@ -299,7 +328,7 @@ namespace imgui_desktop::gui
m_corner_ratio, m_box_thickness, cornered_box_glow}),
when(m_show_dashed_box, DashedBox{m_dash_color, m_dash_len, m_dash_gap, m_dash_thickness}),
RightSide{
when(m_show_right_bar, vertical_bar),
when(m_show_right_bar, bar),
when(m_show_right_dashed_bar, dbar),
when(m_show_right_labels, Label{{0.f, 1.f, 0.f, 1.f},
m_label_offset,
@@ -319,7 +348,7 @@ namespace imgui_desktop::gui
m_ring_thickness, m_ring_offset}),
},
LeftSide{
when(m_show_left_bar, vertical_bar),
when(m_show_left_bar, bar),
when(m_show_left_dashed_bar, dbar),
when(m_show_left_labels,
Label{omath::Color::from_rgba(255, 128, 0, 255), m_label_offset,
@@ -329,7 +358,7 @@ namespace imgui_desktop::gui
outline_helper(m_outlined), "Level: 42"}),
},
TopSide{
when(m_show_top_bar, horizontal_bar),
when(m_show_top_bar, bar),
when(m_show_top_dashed_bar, dbar),
when(m_show_centered_top,
Centered{Label{omath::Color::from_rgba(0, 255, 255, 255), m_label_offset,
@@ -340,7 +369,7 @@ namespace imgui_desktop::gui
outline_helper(m_outlined), "*BLEEDING*"}),
},
BottomSide{
when(m_show_bottom_bar, horizontal_bar),
when(m_show_bottom_bar, bar),
when(m_show_bottom_dashed_bar, dbar),
when(m_show_centered_bottom,
Centered{Label{centered_label_color, m_label_offset, outline_helper(m_outlined),
@@ -350,7 +379,7 @@ namespace imgui_desktop::gui
},
when(m_show_aim, AimDot{{m_entity_x, m_entity_top_y + 40.f}, m_aim_color, m_aim_radius}),
when(m_show_scan, ScanMarker{m_scan_color, m_scan_outline, m_scan_outline_thickness}),
when(m_show_skeleton, Skeleton{m_skel_color, m_skel_thickness}),
when(m_show_skeleton, Skeleton{skeleton_bones, m_skel_color, m_skel_thickness}),
when(m_show_proj, ProjectileAim{{m_proj_pos_x, m_proj_pos_y},
m_proj_color,
m_proj_size,
+7 -4
View File
@@ -41,19 +41,19 @@ namespace omath::hud
float thickness = 1.f);
// ── Bars ─────────────────────────────────────────────────────────
EntityOverlay& add_right_bar(const widget::Paint& color, const Color& outline_color, const Color& bg_color,
EntityOverlay& add_right_bar(const widget::BarPaint& color, const Color& outline_color, const Color& bg_color,
float width, float ratio, float offset = 5.f,
const std::optional<widget::Glow>& glow = std::nullopt);
EntityOverlay& add_left_bar(const widget::Paint& color, const Color& outline_color, const Color& bg_color,
EntityOverlay& add_left_bar(const widget::BarPaint& color, const Color& outline_color, const Color& bg_color,
float width, float ratio, float offset = 5.f,
const std::optional<widget::Glow>& glow = std::nullopt);
EntityOverlay& add_top_bar(const widget::Paint& color, const Color& outline_color, const Color& bg_color,
EntityOverlay& add_top_bar(const widget::BarPaint& color, const Color& outline_color, const Color& bg_color,
float height, float ratio, float offset = 5.f,
const std::optional<widget::Glow>& glow = std::nullopt);
EntityOverlay& add_bottom_bar(const widget::Paint& color, const Color& outline_color, const Color& bg_color,
EntityOverlay& add_bottom_bar(const widget::BarPaint& color, const Color& outline_color, const Color& bg_color,
float height, float ratio, float offset = 5.f,
const std::optional<widget::Glow>& glow = std::nullopt);
@@ -184,6 +184,7 @@ namespace omath::hud
EntityOverlay& add_snap_line(const Vector2<float>& start_pos, const Color& color, float width);
EntityOverlay& add_skeleton(const Color& color, float thickness = 1.f);
EntityOverlay& add_skeleton(std::span<const widget::Bone> bones, const Color& color, float thickness = 1.f);
// ── Declarative interface ─────────────────────────────────────────
/// Pass any combination of widget:: descriptor structs (and std::optional<W>
@@ -272,6 +273,8 @@ namespace omath::hud
void draw_canvas_glow(const widget::CanvasGlow& canvas_glow) const;
void draw_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max,
const widget::Paint& paint) const;
[[nodiscard]]
static widget::Paint resolve_bar_paint(const widget::BarPaint& paint, float ratio, bool vertical);
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,
+58 -1
View File
@@ -6,10 +6,14 @@
#include "omath/linear_algebra/vector2.hpp"
#include "omath/utility/color.hpp"
#include <any>
#include <array>
#include <initializer_list>
#include <optional>
#include <span>
#include <string_view>
#include <type_traits>
#include <variant>
#include <vector>
namespace omath::hud::widget
{
@@ -23,6 +27,32 @@ namespace omath::hud::widget
}
};
struct BarGradient
{
Color empty_color;
Color full_color;
};
struct BarPaint : std::variant<Color, Gradient, BarGradient>
{
using std::variant<Color, Gradient, BarGradient>::variant;
constexpr BarPaint(const float red, const float green, const float blue, const float alpha)
: std::variant<Color, Gradient, BarGradient>(Color{red, green, blue, alpha})
{
}
BarPaint(const Paint& paint)
{
std::visit(
[this](const auto& value)
{
this->template emplace<std::decay_t<decltype(value)>>(value);
},
paint);
}
};
// ── Overloaded helper for std::visit ──────────────────────────────────────
template<typename... Ts>
struct Overloaded : Ts...
@@ -79,10 +109,37 @@ namespace omath::hud::widget
float thickness = 1.f;
};
struct Bone
{
Vector2<float> start;
Vector2<float> end;
};
struct Skeleton
{
std::vector<Bone> bones;
Color color;
float thickness = 1.f;
Skeleton(const Color& color, const float thickness = 1.f): color(color), thickness(thickness)
{
}
Skeleton(const std::span<const Bone> bones, const Color& color, const float thickness = 1.f)
: bones(bones.begin(), bones.end()), color(color), thickness(thickness)
{
}
Skeleton(const std::initializer_list<Bone> bones, const Color& color, const float thickness = 1.f)
: bones(bones), color(color), thickness(thickness)
{
}
template<std::size_t Size>
Skeleton(const std::array<Bone, Size>& bones, const Color& color, const float thickness = 1.f)
: Skeleton(std::span<const Bone>{bones}, color, thickness)
{
}
};
struct SnapLine
{
@@ -124,7 +181,7 @@ namespace omath::hud::widget
/// A filled bar. `size` is width for left/right sides, height for top/bottom.
struct Bar
{
Paint color;
BarPaint color;
Color outline;
Color bg;
float size;
+69 -22
View File
@@ -77,7 +77,7 @@ namespace omath::hud
return *this;
}
EntityOverlay& EntityOverlay::add_right_bar(const widget::Paint& color, const Color& outline_color,
EntityOverlay& EntityOverlay::add_right_bar(const widget::BarPaint& color, const Color& outline_color,
const Color& bg_color, const float width, float ratio,
const float offset, const std::optional<widget::Glow>& glow)
{
@@ -85,18 +85,20 @@ namespace omath::hud
const auto max_bar_height = std::abs(m_canvas.top_right_corner.y - m_canvas.bottom_right_corner.y);
const auto bar_start = Vector2<float>{m_text_cursor_right.x + offset, m_canvas.bottom_right_corner.y};
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height), bg_color);
const auto bar_min = bar_start - Vector2<float>{0.f, max_bar_height};
const auto bar_max = bar_start + Vector2<float>{width, 0.f};
const auto fill_min = bar_start - Vector2<float>{0.f, max_bar_height * ratio};
m_renderer->add_filled_rectangle(bar_min, bar_max, bg_color);
draw_glow_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height * ratio), glow);
draw_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),
bar_start + Vector2<float>(width, -max_bar_height), outline_color);
draw_glow_rectangle(fill_min, bar_max, glow);
draw_filled_rectangle(fill_min, bar_max, resolve_bar_paint(color, ratio, true));
m_renderer->add_rectangle(bar_min, bar_max, outline_color);
m_text_cursor_right.x += offset + width;
return *this;
}
EntityOverlay& EntityOverlay::add_left_bar(const widget::Paint& color, const Color& outline_color,
EntityOverlay& EntityOverlay::add_left_bar(const widget::BarPaint& color, const Color& outline_color,
const Color& bg_color, const float width, float ratio,
const float offset, const std::optional<widget::Glow>& glow)
{
@@ -104,12 +106,14 @@ namespace omath::hud
const auto max_bar_height = std::abs(m_canvas.top_left_corner.y - m_canvas.bottom_right_corner.y);
const auto bar_start = Vector2<float>{m_text_cursor_left.x - (offset + width), m_canvas.bottom_left_corner.y};
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height), bg_color);
const auto bar_min = bar_start - Vector2<float>{0.f, max_bar_height};
const auto bar_max = bar_start + Vector2<float>{width, 0.f};
const auto fill_min = bar_start - Vector2<float>{0.f, max_bar_height * ratio};
m_renderer->add_filled_rectangle(bar_min, bar_max, bg_color);
draw_glow_rectangle(bar_start, bar_start + Vector2<float>(width, -max_bar_height * ratio), glow);
draw_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),
bar_start + Vector2<float>(width, -max_bar_height), outline_color);
draw_glow_rectangle(fill_min, bar_max, glow);
draw_filled_rectangle(fill_min, bar_max, resolve_bar_paint(color, ratio, true));
m_renderer->add_rectangle(bar_min, bar_max, outline_color);
m_text_cursor_left.x -= offset + width;
@@ -135,7 +139,7 @@ namespace omath::hud
return *this;
}
EntityOverlay& EntityOverlay::add_top_bar(const widget::Paint& color, const Color& outline_color,
EntityOverlay& EntityOverlay::add_top_bar(const widget::BarPaint& color, const Color& outline_color,
const Color& bg_color, const float height, float ratio,
const float offset, const std::optional<widget::Glow>& glow)
{
@@ -143,11 +147,14 @@ namespace omath::hud
const auto max_bar_width = std::abs(m_canvas.top_left_corner.x - m_canvas.bottom_right_corner.x);
const auto bar_start = Vector2<float>{m_canvas.top_left_corner.x, m_text_cursor_top.y - offset};
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width, -height), bg_color);
const auto bar_min = bar_start - Vector2<float>{0.f, height};
const auto bar_max = bar_start + Vector2<float>{max_bar_width, 0.f};
const auto fill_max = Vector2<float>{bar_start.x + max_bar_width * ratio, bar_start.y};
m_renderer->add_filled_rectangle(bar_min, bar_max, bg_color);
draw_glow_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width * ratio, -height), glow);
draw_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);
draw_glow_rectangle(bar_min, fill_max, glow);
draw_filled_rectangle(bar_min, fill_max, resolve_bar_paint(color, ratio, false));
m_renderer->add_rectangle(bar_min, bar_max, outline_color);
m_text_cursor_top.y -= offset + height;
@@ -330,6 +337,14 @@ namespace omath::hud
return *this;
}
EntityOverlay& EntityOverlay::add_skeleton(const std::span<const widget::Bone> bones, const Color& color,
const float thickness)
{
for (const auto& bone : bones)
m_renderer->add_line(bone.start, bone.end, color, thickness);
return *this;
}
void EntityOverlay::draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color,
const float dash_len, const float gap_len, const float thickness) const
{
@@ -545,7 +560,33 @@ namespace omath::hud
},
paint);
}
EntityOverlay& EntityOverlay::add_bottom_bar(const widget::Paint& color, const Color& outline_color,
widget::Paint EntityOverlay::resolve_bar_paint(const widget::BarPaint& paint, const float ratio,
const bool vertical)
{
return std::visit(
widget::Overloaded{
[](const Color& color) -> widget::Paint
{
return color;
},
[](const Gradient& gradient) -> widget::Paint
{
return gradient;
},
[&](const widget::BarGradient& gradient) -> widget::Paint
{
const float value = std::clamp(ratio, 0.f, 1.f);
const auto current = Color{gradient.empty_color.value() * (1.f - value)
+ gradient.full_color.value() * value};
if (vertical)
return Gradient{current, current, gradient.empty_color, gradient.empty_color};
return Gradient{gradient.empty_color, current, current, gradient.empty_color};
},
},
paint);
}
EntityOverlay& EntityOverlay::add_bottom_bar(const widget::BarPaint& color, const Color& outline_color,
const Color& bg_color, const float height, float ratio,
const float offset, const std::optional<widget::Glow>& glow)
{
@@ -553,10 +594,13 @@ namespace omath::hud
const auto max_bar_width = std::abs(m_canvas.bottom_right_corner.x - m_canvas.bottom_left_corner.x);
const auto bar_start = Vector2<float>{m_canvas.bottom_left_corner.x, m_text_cursor_bottom.y + offset};
m_renderer->add_filled_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width, height), bg_color);
draw_glow_rectangle(bar_start, bar_start + Vector2<float>(max_bar_width * ratio, height), glow);
draw_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);
const auto bar_min = bar_start;
const auto bar_max = bar_start + Vector2<float>{max_bar_width, height};
const auto fill_max = bar_start + Vector2<float>{max_bar_width * ratio, height};
m_renderer->add_filled_rectangle(bar_min, bar_max, bg_color);
draw_glow_rectangle(bar_min, fill_max, glow);
draw_filled_rectangle(bar_min, fill_max, resolve_bar_paint(color, ratio, false));
m_renderer->add_rectangle(bar_min, bar_max, outline_color);
m_text_cursor_bottom.y += offset + height;
@@ -812,7 +856,10 @@ namespace omath::hud
void EntityOverlay::dispatch(const widget::Skeleton& skeleton)
{
if (skeleton.bones.empty())
add_skeleton(skeleton.color, skeleton.thickness);
else
add_skeleton(skeleton.bones, skeleton.color, skeleton.thickness);
}
void EntityOverlay::dispatch(const widget::SnapLine& snap_line)