adde dash box

This commit is contained in:
2026-03-15 04:49:01 +03:00
parent 69bdfc3307
commit adad66599a
3 changed files with 44 additions and 2 deletions

View File

@@ -66,6 +66,11 @@ namespace imgui_desktop::gui
bool show_top_labels = true, show_bottom_labels = true;
bool show_centered_top = true, show_centered_bottom = true;
// Dashed box
omath::Color dash_color = omath::Color::from_rgba(255, 200, 0, 255);
float dash_len = 8.f, dash_gap = 5.f, dash_thickness = 1.f;
bool show_dashed_box = false;
// Snap line
omath::Color snap_color = omath::Color::from_rgba(255, 50, 50, 255);
float snap_width = 1.5f;
@@ -101,12 +106,17 @@ namespace imgui_desktop::gui
if (ImGui::CollapsingHeader("Box", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::Checkbox("Show box", &show_box);
ImGui::Checkbox("Show box", &show_box);
ImGui::Checkbox("Show cornered box", &show_cornered_box);
ImGui::Checkbox("Show dashed box", &show_dashed_box);
ImGui::ColorEdit4("Color##box", reinterpret_cast<float*>(&box_color), ImGuiColorEditFlags_NoInputs);
ImGui::ColorEdit4("Fill##box", reinterpret_cast<float*>(&box_fill), ImGuiColorEditFlags_NoInputs);
ImGui::SliderFloat("Thickness", &box_thickness, 0.5f, 5.f);
ImGui::SliderFloat("Corner ratio", &corner_ratio, 0.05f, 0.5f);
ImGui::SliderFloat("Corner ratio", &corner_ratio, 0.05f, 0.5f);
ImGui::ColorEdit4("Dash color", reinterpret_cast<float*>(&dash_color), ImGuiColorEditFlags_NoInputs);
ImGui::SliderFloat("Dash length", &dash_len, 2.f, 30.f);
ImGui::SliderFloat("Dash gap", &dash_gap, 1.f, 20.f);
ImGui::SliderFloat("Dash thickness", &dash_thickness, 0.5f, 5.f);
}
if (ImGui::CollapsingHeader("Bars", ImGuiTreeNodeFlags_DefaultOpen))
@@ -154,6 +164,8 @@ namespace imgui_desktop::gui
ent.add_2d_box(box_color, box_fill, box_thickness);
if (show_cornered_box)
ent.add_cornered_2d_box(omath::Color::from_rgba(255, 0, 255, 255), box_fill, corner_ratio, box_thickness);
if (show_dashed_box)
ent.add_dashed_box(dash_color, dash_len, dash_gap, dash_thickness);
if (show_right_bar)
ent.add_right_bar(bar_color, bar_outline_color, bar_bg_color, bar_width, bar_value, bar_offset);

View File

@@ -55,6 +55,9 @@ namespace omath::hud
void add_snap_line(const Vector2<float>& start_pos, const Color& color, float width);
void add_dashed_box(const Color& color, float dash_len = 8.f, float gap_len = 5.f,
float thickness = 1.f) const;
void add_bottom_bar(const Color& color, const Color& outline_color, const Color& bg_color, float height,
float ratio, float offset = 5.f);
@@ -101,6 +104,8 @@ namespace omath::hud
private:
void draw_outlined_text(const Vector2<float>& position, const Color& color,
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;
CanvasBox m_canvas;
Vector2<float> m_text_cursor_right;
Vector2<float> m_text_cursor_top;

View File

@@ -122,6 +122,31 @@ namespace omath::hud
+ Vector2<float>{m_canvas.bottom_right_corner.x - m_canvas.bottom_left_corner.x, 0.f} / 2;
m_renderer->add_line(start_pos, line_end, color, width);
}
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
{
const auto edge = to - from;
const auto total = edge.length();
const auto dir = edge.normalized();
const float step = dash_len + gap_len;
for (float pos = 0.f; pos < total; pos += step)
{
const auto dash_start = from + dir * pos;
const auto dash_end = from + dir * std::min(pos + dash_len, total);
m_renderer->add_line(dash_start, dash_end, color, thickness);
}
}
void EntityOverlay::add_dashed_box(const Color& color, const float dash_len, const float gap_len,
const float thickness) const
{
draw_dashed_line(m_canvas.top_left_corner, m_canvas.top_right_corner, color, dash_len, gap_len, thickness);
draw_dashed_line(m_canvas.top_right_corner, m_canvas.bottom_right_corner, color, dash_len, gap_len, thickness);
draw_dashed_line(m_canvas.bottom_right_corner,m_canvas.bottom_left_corner, color, dash_len, gap_len, thickness);
draw_dashed_line(m_canvas.bottom_left_corner, m_canvas.top_left_corner, color, dash_len, gap_len, thickness);
}
void EntityOverlay::draw_outlined_text(const Vector2<float>& position, const Color& color,
const std::string_view& text)
{