mirror of
https://github.com/orange-cpp/omath.git
synced 2026-06-09 00:34:34 +00:00
added outlined option for box
This commit is contained in:
@@ -5,10 +5,14 @@
|
||||
|
||||
namespace omath::hud
|
||||
{
|
||||
EntityOverlay& EntityOverlay::add_2d_box(const Color& box_color, const Color& fill_color, const float thickness)
|
||||
EntityOverlay& EntityOverlay::add_2d_box(const Color& box_color, const Color& fill_color,
|
||||
const Color& outline_color, const float thickness)
|
||||
{
|
||||
const auto points = m_canvas.as_array();
|
||||
|
||||
if (outline_color.value().w > 0.f)
|
||||
m_renderer->add_polyline({points.data(), points.size()}, outline_color, thickness + 2.f);
|
||||
|
||||
m_renderer->add_polyline({points.data(), points.size()}, box_color, thickness);
|
||||
|
||||
if (fill_color.value().w > 0.f)
|
||||
@@ -17,41 +21,46 @@ namespace omath::hud
|
||||
return *this;
|
||||
}
|
||||
EntityOverlay& EntityOverlay::add_cornered_2d_box(const Color& box_color, const Color& fill_color,
|
||||
const float corner_ratio_len, const float thickness)
|
||||
const Color& outline_color, const float corner_ratio_len,
|
||||
const float thickness)
|
||||
{
|
||||
const auto corner_line_length =
|
||||
std::abs((m_canvas.top_left_corner - m_canvas.top_right_corner).x * corner_ratio_len);
|
||||
|
||||
if (fill_color.value().w > 0.f)
|
||||
add_2d_box(fill_color, fill_color);
|
||||
|
||||
const auto draw_corner_line = [&](const Vector2<float>& a, const Vector2<float>& b)
|
||||
{
|
||||
if (outline_color.value().w > 0.f)
|
||||
m_renderer->add_line(a, b, outline_color, thickness + 2.f);
|
||||
m_renderer->add_line(a, b, box_color, thickness);
|
||||
};
|
||||
|
||||
// Left Side
|
||||
m_renderer->add_line(m_canvas.top_left_corner,
|
||||
m_canvas.top_left_corner + Vector2<float>{corner_line_length, 0.f}, box_color, thickness);
|
||||
draw_corner_line(m_canvas.top_left_corner,
|
||||
m_canvas.top_left_corner + Vector2<float>{corner_line_length, 0.f});
|
||||
|
||||
m_renderer->add_line(m_canvas.top_left_corner,
|
||||
m_canvas.top_left_corner + Vector2<float>{0.f, corner_line_length}, box_color, thickness);
|
||||
draw_corner_line(m_canvas.top_left_corner,
|
||||
m_canvas.top_left_corner + Vector2<float>{0.f, corner_line_length});
|
||||
|
||||
m_renderer->add_line(m_canvas.bottom_left_corner,
|
||||
m_canvas.bottom_left_corner - Vector2<float>{0.f, corner_line_length}, box_color,
|
||||
thickness);
|
||||
draw_corner_line(m_canvas.bottom_left_corner,
|
||||
m_canvas.bottom_left_corner - Vector2<float>{0.f, corner_line_length});
|
||||
|
||||
m_renderer->add_line(m_canvas.bottom_left_corner,
|
||||
m_canvas.bottom_left_corner + Vector2<float>{corner_line_length, 0.f}, box_color,
|
||||
thickness);
|
||||
draw_corner_line(m_canvas.bottom_left_corner,
|
||||
m_canvas.bottom_left_corner + Vector2<float>{corner_line_length, 0.f});
|
||||
// Right Side
|
||||
m_renderer->add_line(m_canvas.top_right_corner,
|
||||
m_canvas.top_right_corner - Vector2<float>{corner_line_length, 0.f}, box_color, thickness);
|
||||
draw_corner_line(m_canvas.top_right_corner,
|
||||
m_canvas.top_right_corner - Vector2<float>{corner_line_length, 0.f});
|
||||
|
||||
m_renderer->add_line(m_canvas.top_right_corner,
|
||||
m_canvas.top_right_corner + Vector2<float>{0.f, corner_line_length}, box_color, thickness);
|
||||
draw_corner_line(m_canvas.top_right_corner,
|
||||
m_canvas.top_right_corner + Vector2<float>{0.f, corner_line_length});
|
||||
|
||||
m_renderer->add_line(m_canvas.bottom_right_corner,
|
||||
m_canvas.bottom_right_corner - Vector2<float>{0.f, corner_line_length}, box_color,
|
||||
thickness);
|
||||
draw_corner_line(m_canvas.bottom_right_corner,
|
||||
m_canvas.bottom_right_corner - Vector2<float>{0.f, corner_line_length});
|
||||
|
||||
m_renderer->add_line(m_canvas.bottom_right_corner,
|
||||
m_canvas.bottom_right_corner - Vector2<float>{corner_line_length, 0.f}, box_color,
|
||||
thickness);
|
||||
draw_corner_line(m_canvas.bottom_right_corner,
|
||||
m_canvas.bottom_right_corner - Vector2<float>{corner_line_length, 0.f});
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -591,12 +600,13 @@ namespace omath::hud
|
||||
// ── widget dispatch ───────────────────────────────────────────────────────
|
||||
void EntityOverlay::dispatch(const widget::Box& box)
|
||||
{
|
||||
add_2d_box(box.color, box.fill, box.thickness);
|
||||
add_2d_box(box.color, box.fill, box.outline, box.thickness);
|
||||
}
|
||||
|
||||
void EntityOverlay::dispatch(const widget::CorneredBox& cornered_box)
|
||||
{
|
||||
add_cornered_2d_box(cornered_box.color, cornered_box.fill, cornered_box.corner_ratio, cornered_box.thickness);
|
||||
add_cornered_2d_box(cornered_box.color, cornered_box.fill, cornered_box.outline, cornered_box.corner_ratio,
|
||||
cornered_box.thickness);
|
||||
}
|
||||
|
||||
void EntityOverlay::dispatch(const widget::DashedBox& dashed_box)
|
||||
|
||||
@@ -285,17 +285,20 @@ namespace omath::lua
|
||||
|
||||
"add_2d_box",
|
||||
[](omath::hud::EntityOverlay& overlay, const omath::Color& box_color,
|
||||
sol::optional<omath::Color> fill_color, sol::optional<float> thickness) -> omath::hud::EntityOverlay&
|
||||
sol::optional<omath::Color> fill_color, sol::optional<omath::Color> outline_color,
|
||||
sol::optional<float> thickness) -> omath::hud::EntityOverlay&
|
||||
{
|
||||
return overlay.add_2d_box(box_color, fill_color.value_or(transparent_black()),
|
||||
thickness.value_or(1.f));
|
||||
outline_color.value_or(transparent_black()), thickness.value_or(1.f));
|
||||
},
|
||||
"add_cornered_2d_box",
|
||||
[](omath::hud::EntityOverlay& overlay, const omath::Color& box_color,
|
||||
sol::optional<omath::Color> fill_color, sol::optional<float> corner_ratio_len,
|
||||
sol::optional<omath::Color> fill_color, sol::optional<omath::Color> outline_color,
|
||||
sol::optional<float> corner_ratio_len,
|
||||
sol::optional<float> thickness) -> omath::hud::EntityOverlay&
|
||||
{
|
||||
return overlay.add_cornered_2d_box(box_color, fill_color.value_or(transparent_black()),
|
||||
outline_color.value_or(transparent_black()),
|
||||
corner_ratio_len.value_or(0.2f), thickness.value_or(1.f));
|
||||
},
|
||||
"add_dashed_box",
|
||||
|
||||
Reference in New Issue
Block a user