added blur

This commit is contained in:
2026-07-11 22:20:26 +03:00
parent 26823609e7
commit 1618a41318
5 changed files with 55 additions and 2 deletions
+5 -2
View File
@@ -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<float*>(&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<omath::hud::ImguiHudRenderer>())
.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,
+1
View File
@@ -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);
+2
View File
@@ -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<float>& min, const Vector2<float>& max,
const std::optional<widget::Glow>& glow) const;
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;
void draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color, float dash_len,
@@ -39,6 +39,11 @@ namespace omath::hud::widget
float intensity = 1.f;
};
struct CanvasGlow
{
Glow glow;
};
// ── Standalone widgets ────────────────────────────────────────────────────
struct Box
{
+42
View File
@@ -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<float>(layer) / static_cast<float>(layers - 1);
const float scale = 1.f - progress * 0.95f;
const float alpha = value.w * intensity / static_cast<float>(layers);
const Color color{value.x, value.y, value.z, alpha};
std::array<Vector2<float>, segments> points;
for (int segment = 0; segment < segments; ++segment)
{
const float angle =
static_cast<float>(segment) / static_cast<float>(segments) * 2.f * std::numbers::pi_v<float>;
points[segment] = center
+ Vector2<float>{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<float>& min, const Vector2<float>& 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)