diff --git a/examples/example_hud/gui/main_window.cpp b/examples/example_hud/gui/main_window.cpp index e044946..cb3cd5b 100644 --- a/examples/example_hud/gui/main_window.cpp +++ b/examples/example_hud/gui/main_window.cpp @@ -66,7 +66,7 @@ namespace imgui_desktop::gui ImGui::Begin("Controls", &m_opened, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); ImGui::PushItemWidth(160.f); - const auto draw_glow_controls = [](const char* label, GlowSettings& settings) + const auto draw_glow_controls = [](const char* label, GlowSettings& settings, const float max_radius = 30.f) { ImGui::PushID(label); ImGui::TextUnformatted(label); @@ -74,7 +74,7 @@ namespace imgui_desktop::gui if (settings.enabled) { ImGui::ColorEdit4("Color", reinterpret_cast(&settings.color), ImGuiColorEditFlags_NoInputs); - ImGui::SliderFloat("Radius", &settings.radius, 1.f, 12.f); + ImGui::SliderFloat("Radius", &settings.radius, 1.f, max_radius); ImGui::SliderFloat("Intensity", &settings.intensity, 0.f, 1.f); } ImGui::PopID(); @@ -86,6 +86,7 @@ namespace imgui_desktop::gui ImGui::SliderFloat("Top Y", &m_entity_top_y, 20.f, m_entity_bottom_y - 20.f); ImGui::SliderFloat("Bottom Y", &m_entity_bottom_y, m_entity_top_y + 20.f, vp->Size.y - 20.f); ImGui::SliderFloat("Aspect", &m_entity_aspect, 1.f, 10.f); + draw_glow_controls("Canvas light", m_canvas_glow, 500.f); } if (ImGui::CollapsingHeader("Box", ImGuiTreeNodeFlags_DefaultOpen)) @@ -256,6 +257,7 @@ namespace imgui_desktop::gui const auto cornered_box_glow = make_glow(m_cornered_box_glow); 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}; @@ -283,6 +285,7 @@ namespace imgui_desktop::gui omath::hud::EntityOverlay({m_entity_x, m_entity_top_y}, {m_entity_x, m_entity_bottom_y}, m_entity_aspect, std::make_shared()) .contents( + when(canvas_glow.has_value(), CanvasGlow{canvas_glow.value_or(Glow{m_canvas_glow.color})}), // ── Boxes ──────────────────────────────────────────────────── when(m_show_box, Box{m_box_color, box_fill, m_box_outline, m_box_thickness, box_glow}), when(m_show_cornered_box, diff --git a/examples/example_hud/gui/main_window.hpp b/examples/example_hud/gui/main_window.hpp index 26e3ef2..c6b6678 100644 --- a/examples/example_hud/gui/main_window.hpp +++ b/examples/example_hud/gui/main_window.hpp @@ -76,6 +76,7 @@ namespace imgui_desktop::gui GlowSettings m_cornered_box_glow{{1.f, 0.f, 1.f, 0.8f}}; GlowSettings m_bar_glow{{1.f, 0.f, 0.f, 0.8f}}; GlowSettings m_label_glow; + GlowSettings m_canvas_glow{{1.f, 0.5f, 0.f, 0.8f}, 100.f}; // Skeleton omath::Color m_skel_color = omath::Color::from_rgba(255, 255, 255, 200); diff --git a/include/omath/hud/entity_overlay.hpp b/include/omath/hud/entity_overlay.hpp index f8b3712..c1f644a 100644 --- a/include/omath/hud/entity_overlay.hpp +++ b/include/omath/hud/entity_overlay.hpp @@ -248,6 +248,7 @@ namespace omath::hud } void dispatch(const widget::Box& box); + void dispatch(const widget::CanvasGlow& canvas_glow); void dispatch(const widget::CorneredBox& cornered_box); void dispatch(const widget::DashedBox& dashed_box); void dispatch(const widget::RightSide& right_side); @@ -268,6 +269,7 @@ namespace omath::hud float thickness) const; void draw_glow_rectangle(const Vector2& min, const Vector2& max, const std::optional& glow) const; + void draw_canvas_glow(const widget::CanvasGlow& canvas_glow) const; void draw_filled_rectangle(const Vector2& min, const Vector2& max, const widget::Paint& paint) const; void draw_dashed_line(const Vector2& from, const Vector2& to, const Color& color, float dash_len, diff --git a/include/omath/hud/entity_overlay_widgets.hpp b/include/omath/hud/entity_overlay_widgets.hpp index 5c4d1b9..21dfdbc 100644 --- a/include/omath/hud/entity_overlay_widgets.hpp +++ b/include/omath/hud/entity_overlay_widgets.hpp @@ -39,6 +39,11 @@ namespace omath::hud::widget float intensity = 1.f; }; + struct CanvasGlow + { + Glow glow; + }; + // ── Standalone widgets ──────────────────────────────────────────────────── struct Box { diff --git a/source/hud/entity_overlay.cpp b/source/hud/entity_overlay.cpp index ef22d62..9bad505 100644 --- a/source/hud/entity_overlay.cpp +++ b/source/hud/entity_overlay.cpp @@ -476,6 +476,43 @@ namespace omath::hud draw_glow_polyline(points, *glow, 1.f); } + void EntityOverlay::draw_canvas_glow(const widget::CanvasGlow& canvas_glow) const + { + constexpr int layers = 32; + constexpr int segments = 64; + const auto min = m_canvas.top_left_corner; + const auto max = m_canvas.bottom_right_corner; + const auto center = (min + max) * 0.5f; + const float half_width = std::abs(max.x - min.x) * 0.5f; + const float half_height = std::abs(max.y - min.y) * 0.5f; + if (half_width <= 0.f || half_height <= 0.f) + return; + const float vertical_radius = std::min(std::max(canvas_glow.glow.radius, 0.f), half_height); + const float horizontal_radius = vertical_radius * half_width / half_height; + if (vertical_radius <= 0.f || horizontal_radius <= 0.f) + return; + + const auto value = canvas_glow.glow.color.value(); + const float intensity = std::clamp(canvas_glow.glow.intensity, 0.f, 1.f); + for (int layer = 0; layer < layers; ++layer) + { + const float progress = static_cast(layer) / static_cast(layers - 1); + const float scale = 1.f - progress * 0.95f; + const float alpha = value.w * intensity / static_cast(layers); + const Color color{value.x, value.y, value.z, alpha}; + std::array, segments> points; + for (int segment = 0; segment < segments; ++segment) + { + const float angle = + static_cast(segment) / static_cast(segments) * 2.f * std::numbers::pi_v; + points[segment] = center + + Vector2{std::cos(angle) * horizontal_radius * scale, + std::sin(angle) * vertical_radius * scale}; + } + m_renderer->add_filled_polyline(points, color); + } + } + void EntityOverlay::draw_filled_rectangle(const Vector2& min, const Vector2& max, const widget::Paint& paint) const { @@ -726,6 +763,11 @@ namespace omath::hud box.fill); } + void EntityOverlay::dispatch(const widget::CanvasGlow& canvas_glow) + { + draw_canvas_glow(canvas_glow); + } + void EntityOverlay::dispatch(const widget::CorneredBox& cornered_box) { if (cornered_box.glow)