mirror of
https://github.com/orange-cpp/omath.git
synced 2026-08-09 06:22:06 +00:00
Compare commits
3 Commits
26823609e7
...
fb1ffac240
| Author | SHA1 | Date | |
|---|---|---|---|
| fb1ffac240 | |||
| cbe220664f | |||
| 1618a41318 |
@@ -74,8 +74,8 @@ namespace imgui_desktop::gui
|
|||||||
if (settings.enabled)
|
if (settings.enabled)
|
||||||
{
|
{
|
||||||
ImGui::ColorEdit4("Color", reinterpret_cast<float*>(&settings.color), ImGuiColorEditFlags_NoInputs);
|
ImGui::ColorEdit4("Color", reinterpret_cast<float*>(&settings.color), ImGuiColorEditFlags_NoInputs);
|
||||||
ImGui::SliderFloat("Radius", &settings.radius, 1.f, 12.f);
|
ImGui::InputFloat("Radius", &settings.radius);
|
||||||
ImGui::SliderFloat("Intensity", &settings.intensity, 0.f, 1.f);
|
ImGui::InputFloat("Intensity", &settings.intensity);
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
};
|
};
|
||||||
@@ -86,6 +86,12 @@ namespace imgui_desktop::gui
|
|||||||
ImGui::SliderFloat("Top Y", &m_entity_top_y, 20.f, m_entity_bottom_y - 20.f);
|
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("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);
|
ImGui::SliderFloat("Aspect", &m_entity_aspect, 1.f, 10.f);
|
||||||
|
draw_glow_controls("Canvas light", m_canvas_glow);
|
||||||
|
if (m_canvas_glow.enabled)
|
||||||
|
{
|
||||||
|
ImGui::InputInt("Blur layers##canvas", &m_canvas_glow_layers);
|
||||||
|
ImGui::InputFloat("Rounding##canvas", &m_canvas_glow_rounding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::CollapsingHeader("Box", ImGuiTreeNodeFlags_DefaultOpen))
|
if (ImGui::CollapsingHeader("Box", ImGuiTreeNodeFlags_DefaultOpen))
|
||||||
@@ -256,6 +262,7 @@ namespace imgui_desktop::gui
|
|||||||
const auto cornered_box_glow = make_glow(m_cornered_box_glow);
|
const auto cornered_box_glow = make_glow(m_cornered_box_glow);
|
||||||
const auto bar_glow = make_glow(m_bar_glow);
|
const auto bar_glow = make_glow(m_bar_glow);
|
||||||
const auto label_glow = make_glow(m_label_glow);
|
const auto label_glow = make_glow(m_label_glow);
|
||||||
|
const auto canvas_glow = make_glow(m_canvas_glow);
|
||||||
const Paint vertical_bar_color =
|
const Paint vertical_bar_color =
|
||||||
m_gradient_bars ? Paint{omath::hud::Gradient{bar_value_color, bar_value_color, red, red}}
|
m_gradient_bars ? Paint{omath::hud::Gradient{bar_value_color, bar_value_color, red, red}}
|
||||||
: Paint{m_bar_color};
|
: Paint{m_bar_color};
|
||||||
@@ -283,6 +290,8 @@ namespace imgui_desktop::gui
|
|||||||
omath::hud::EntityOverlay({m_entity_x, m_entity_top_y}, {m_entity_x, m_entity_bottom_y}, m_entity_aspect,
|
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>())
|
std::make_shared<omath::hud::ImguiHudRenderer>())
|
||||||
.contents(
|
.contents(
|
||||||
|
when(canvas_glow.has_value(), CanvasGlow{canvas_glow.value_or(Glow{m_canvas_glow.color}),
|
||||||
|
m_canvas_glow_layers, m_canvas_glow_rounding}),
|
||||||
// ── Boxes ────────────────────────────────────────────────────
|
// ── Boxes ────────────────────────────────────────────────────
|
||||||
when(m_show_box, Box{m_box_color, box_fill, m_box_outline, m_box_thickness, box_glow}),
|
when(m_show_box, Box{m_box_color, box_fill, m_box_outline, m_box_thickness, box_glow}),
|
||||||
when(m_show_cornered_box,
|
when(m_show_cornered_box,
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ namespace imgui_desktop::gui
|
|||||||
GlowSettings m_cornered_box_glow{{1.f, 0.f, 1.f, 0.8f}};
|
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_bar_glow{{1.f, 0.f, 0.f, 0.8f}};
|
||||||
GlowSettings m_label_glow;
|
GlowSettings m_label_glow;
|
||||||
|
GlowSettings m_canvas_glow{{1.f, 0.5f, 0.f, 0.8f}, 100.f};
|
||||||
|
int m_canvas_glow_layers = 64;
|
||||||
|
float m_canvas_glow_rounding = 40.f;
|
||||||
|
|
||||||
// Skeleton
|
// Skeleton
|
||||||
omath::Color m_skel_color = omath::Color::from_rgba(255, 255, 255, 200);
|
omath::Color m_skel_color = omath::Color::from_rgba(255, 255, 255, 200);
|
||||||
|
|||||||
@@ -248,6 +248,7 @@ namespace omath::hud
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dispatch(const widget::Box& box);
|
void dispatch(const widget::Box& box);
|
||||||
|
void dispatch(const widget::CanvasGlow& canvas_glow);
|
||||||
void dispatch(const widget::CorneredBox& cornered_box);
|
void dispatch(const widget::CorneredBox& cornered_box);
|
||||||
void dispatch(const widget::DashedBox& dashed_box);
|
void dispatch(const widget::DashedBox& dashed_box);
|
||||||
void dispatch(const widget::RightSide& right_side);
|
void dispatch(const widget::RightSide& right_side);
|
||||||
@@ -268,6 +269,7 @@ namespace omath::hud
|
|||||||
float thickness) const;
|
float thickness) const;
|
||||||
void draw_glow_rectangle(const Vector2<float>& min, const Vector2<float>& max,
|
void draw_glow_rectangle(const Vector2<float>& min, const Vector2<float>& max,
|
||||||
const std::optional<widget::Glow>& glow) const;
|
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,
|
void draw_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max,
|
||||||
const widget::Paint& paint) const;
|
const widget::Paint& paint) const;
|
||||||
void draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color, float dash_len,
|
void draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color, float dash_len,
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ namespace omath::hud::widget
|
|||||||
float intensity = 1.f;
|
float intensity = 1.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CanvasGlow
|
||||||
|
{
|
||||||
|
Glow glow;
|
||||||
|
int layers = 64;
|
||||||
|
float rounding = 20.f;
|
||||||
|
};
|
||||||
|
|
||||||
// ── Standalone widgets ────────────────────────────────────────────────────
|
// ── Standalone widgets ────────────────────────────────────────────────────
|
||||||
struct Box
|
struct Box
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ namespace omath::hud
|
|||||||
virtual void add_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color,
|
virtual void add_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color,
|
||||||
float thickness) = 0;
|
float thickness) = 0;
|
||||||
|
|
||||||
|
virtual void add_polyline_clipped(const std::span<const Vector2<float>>& vertexes, const Vector2<float>&,
|
||||||
|
const Vector2<float>&, const Color& color, float thickness)
|
||||||
|
{
|
||||||
|
add_polyline(vertexes, color, thickness);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color) = 0;
|
virtual void add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color) = 0;
|
||||||
|
|
||||||
virtual void add_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) = 0;
|
virtual void add_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) = 0;
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ namespace omath::hud
|
|||||||
float thickness) override;
|
float thickness) override;
|
||||||
void add_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color,
|
void add_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color,
|
||||||
float thickness) override;
|
float thickness) override;
|
||||||
|
void add_polyline_clipped(const std::span<const Vector2<float>>& vertexes, const Vector2<float>& clip_min,
|
||||||
|
const Vector2<float>& clip_max, const Color& color, float thickness) override;
|
||||||
void add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color) 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_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_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) override;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// Created by orange on 13.03.2026.
|
// Created by orange on 13.03.2026.
|
||||||
//
|
//
|
||||||
#include "omath/hud/entity_overlay.hpp"
|
#include "omath/hud/entity_overlay.hpp"
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
namespace omath::hud
|
namespace omath::hud
|
||||||
{
|
{
|
||||||
@@ -388,7 +389,7 @@ namespace omath::hud
|
|||||||
const int radius = static_cast<int>(std::ceil(std::max(glow->radius, 0.f)));
|
const int radius = static_cast<int>(std::ceil(std::max(glow->radius, 0.f)));
|
||||||
for (int layer = radius; layer > 0; --layer)
|
for (int layer = radius; layer > 0; --layer)
|
||||||
{
|
{
|
||||||
const float alpha = glow->color.value().w * std::clamp(glow->intensity, 0.f, 1.f)
|
const float alpha = glow->color.value().w * std::max(glow->intensity, 0.f)
|
||||||
* (1.f - static_cast<float>(layer - 1) / static_cast<float>(radius + 1));
|
* (1.f - static_cast<float>(layer - 1) / static_cast<float>(radius + 1));
|
||||||
const auto value = glow->color.value();
|
const auto value = glow->color.value();
|
||||||
const Color color{value.x, value.y, value.z, alpha / static_cast<float>(radius)};
|
const Color color{value.x, value.y, value.z, alpha / static_cast<float>(radius)};
|
||||||
@@ -442,7 +443,7 @@ namespace omath::hud
|
|||||||
{
|
{
|
||||||
const float falloff = 1.f - static_cast<float>(layer - 1) / static_cast<float>(radius + 1);
|
const float falloff = 1.f - static_cast<float>(layer - 1) / static_cast<float>(radius + 1);
|
||||||
const Color color{value.x, value.y, value.z,
|
const Color color{value.x, value.y, value.z,
|
||||||
value.w * std::clamp(glow.intensity, 0.f, 1.f) * falloff / static_cast<float>(radius)};
|
value.w * std::max(glow.intensity, 0.f) * falloff / static_cast<float>(radius)};
|
||||||
m_renderer->add_polyline(points, color, thickness + static_cast<float>(layer) * 2.f);
|
m_renderer->add_polyline(points, color, thickness + static_cast<float>(layer) * 2.f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -456,7 +457,7 @@ namespace omath::hud
|
|||||||
{
|
{
|
||||||
const float falloff = 1.f - static_cast<float>(layer - 1) / static_cast<float>(radius + 1);
|
const float falloff = 1.f - static_cast<float>(layer - 1) / static_cast<float>(radius + 1);
|
||||||
const Color color{value.x, value.y, value.z,
|
const Color color{value.x, value.y, value.z,
|
||||||
value.w * std::clamp(glow.intensity, 0.f, 1.f) * falloff / static_cast<float>(radius)};
|
value.w * std::max(glow.intensity, 0.f) * falloff / static_cast<float>(radius)};
|
||||||
m_renderer->add_line(from, to, color, thickness + static_cast<float>(layer) * 2.f);
|
m_renderer->add_line(from, to, color, thickness + static_cast<float>(layer) * 2.f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -476,6 +477,56 @@ namespace omath::hud
|
|||||||
draw_glow_polyline(points, *glow, 1.f);
|
draw_glow_polyline(points, *glow, 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityOverlay::draw_canvas_glow(const widget::CanvasGlow& canvas_glow) const
|
||||||
|
{
|
||||||
|
const int layers = std::max(canvas_glow.layers, 2);
|
||||||
|
const auto min = m_canvas.top_left_corner;
|
||||||
|
const auto max = m_canvas.bottom_right_corner;
|
||||||
|
const auto value = canvas_glow.glow.color.value();
|
||||||
|
const float intensity = std::max(canvas_glow.glow.intensity, 0.f);
|
||||||
|
|
||||||
|
constexpr int corner_segments = 12;
|
||||||
|
const float max_rounding = std::min(std::abs(max.x - min.x), std::abs(max.y - min.y)) * 0.5f;
|
||||||
|
const float rounding = std::clamp(canvas_glow.rounding, 0.f, max_rounding);
|
||||||
|
const float extent = std::max(canvas_glow.glow.radius, 0.f);
|
||||||
|
const float stroke = std::max(extent / static_cast<float>(layers - 1) * 2.f, 1.f);
|
||||||
|
for (int layer = 0; layer < layers; ++layer)
|
||||||
|
{
|
||||||
|
const float progress = static_cast<float>(layer) / static_cast<float>(layers - 1);
|
||||||
|
const float expansion = extent * (1.f - progress);
|
||||||
|
const float falloff = progress * progress * (3.f - 2.f * progress);
|
||||||
|
const Color color{value.x, value.y, value.z, value.w * intensity * falloff * 0.35f};
|
||||||
|
const auto expanded_min = min - Vector2<float>{expansion, expansion};
|
||||||
|
const auto expanded_max = max + Vector2<float>{expansion, expansion};
|
||||||
|
const float expanded_rounding = rounding + expansion;
|
||||||
|
const std::array corner_centers = {
|
||||||
|
expanded_min + Vector2<float>{expanded_rounding, expanded_rounding},
|
||||||
|
Vector2<float>{expanded_max.x - expanded_rounding, expanded_min.y + expanded_rounding},
|
||||||
|
expanded_max - Vector2<float>{expanded_rounding, expanded_rounding},
|
||||||
|
Vector2<float>{expanded_min.x + expanded_rounding, expanded_max.y - expanded_rounding},
|
||||||
|
};
|
||||||
|
std::array<Vector2<float>, corner_segments * 4> points;
|
||||||
|
for (int corner = 0; corner < 4; ++corner)
|
||||||
|
{
|
||||||
|
const float start_angle =
|
||||||
|
std::numbers::pi_v<float> + static_cast<float>(corner) * std::numbers::pi_v<float> * 0.5f;
|
||||||
|
for (int segment = 0; segment < corner_segments; ++segment)
|
||||||
|
{
|
||||||
|
const float arc_progress = static_cast<float>(segment) / static_cast<float>(corner_segments - 1);
|
||||||
|
const float angle = start_angle + arc_progress * std::numbers::pi_v<float> * 0.5f;
|
||||||
|
points[corner * corner_segments + segment] =
|
||||||
|
corner_centers[corner]
|
||||||
|
+ Vector2<float>{std::cos(angle) * expanded_rounding, std::sin(angle) * expanded_rounding};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
constexpr float clip_extent = std::numeric_limits<float>::max() * 0.25f;
|
||||||
|
m_renderer->add_polyline_clipped(points, {-clip_extent, -clip_extent}, {clip_extent, min.y}, color, stroke);
|
||||||
|
m_renderer->add_polyline_clipped(points, {-clip_extent, max.y}, {clip_extent, clip_extent}, color, stroke);
|
||||||
|
m_renderer->add_polyline_clipped(points, {-clip_extent, min.y}, {min.x, max.y}, color, stroke);
|
||||||
|
m_renderer->add_polyline_clipped(points, {max.x, min.y}, {clip_extent, max.y}, color, stroke);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EntityOverlay::draw_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max,
|
void EntityOverlay::draw_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max,
|
||||||
const widget::Paint& paint) const
|
const widget::Paint& paint) const
|
||||||
{
|
{
|
||||||
@@ -726,6 +777,11 @@ namespace omath::hud
|
|||||||
box.fill);
|
box.fill);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityOverlay::dispatch(const widget::CanvasGlow& canvas_glow)
|
||||||
|
{
|
||||||
|
draw_canvas_glow(canvas_glow);
|
||||||
|
}
|
||||||
|
|
||||||
void EntityOverlay::dispatch(const widget::CorneredBox& cornered_box)
|
void EntityOverlay::dispatch(const widget::CorneredBox& cornered_box)
|
||||||
{
|
{
|
||||||
if (cornered_box.glow)
|
if (cornered_box.glow)
|
||||||
|
|||||||
@@ -27,6 +27,17 @@ namespace omath::hud
|
|||||||
ImDrawFlags_Closed, thickness);
|
ImDrawFlags_Closed, thickness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImguiHudRenderer::add_polyline_clipped(const std::span<const Vector2<float>>& vertexes,
|
||||||
|
const Vector2<float>& clip_min, const Vector2<float>& clip_max,
|
||||||
|
const Color& color, const float thickness)
|
||||||
|
{
|
||||||
|
auto* draw_list = ImGui::GetBackgroundDrawList();
|
||||||
|
draw_list->PushClipRect(clip_min.to_im_vec2(), clip_max.to_im_vec2(), true);
|
||||||
|
draw_list->AddPolyline(reinterpret_cast<const ImVec2*>(vertexes.data()), static_cast<int>(vertexes.size()),
|
||||||
|
color.to_im_color(), ImDrawFlags_Closed, thickness);
|
||||||
|
draw_list->PopClipRect();
|
||||||
|
}
|
||||||
|
|
||||||
void ImguiHudRenderer::add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color)
|
void ImguiHudRenderer::add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color)
|
||||||
{
|
{
|
||||||
ImGui::GetBackgroundDrawList()->AddConvexPolyFilled(reinterpret_cast<const ImVec2*>(vertexes.data()),
|
ImGui::GetBackgroundDrawList()->AddConvexPolyFilled(reinterpret_cast<const ImVec2*>(vertexes.data()),
|
||||||
|
|||||||
Reference in New Issue
Block a user