diff --git a/libs/gfx/include/psemek/gfx/painter.hpp b/libs/gfx/include/psemek/gfx/painter.hpp index 9560f647..1b36159d 100644 --- a/libs/gfx/include/psemek/gfx/painter.hpp +++ b/libs/gfx/include/psemek/gfx/painter.hpp @@ -57,7 +57,7 @@ namespace psemek::gfx void rect(geom::box const & box, color const & c); void circle(geom::point const & center, float radius, color const & c, int quality = 24); void line(geom::point const & p0, geom::point const & p1, float width, color const & c, bool smooth = true); - void line(geom::point const & p0, geom::point const & p1, float width, color const & c0, color const & c1, bool smooth = true); + void line(geom::point const & p0, geom::point const & p1, float w0, float w1, color const & c0, color const & c1, bool smooth = true); void besier(geom::point const & p0, geom::point const & p1, geom::point const & p2, float width, color const & c, int quality = 8, bool smooth = true); // 2D text diff --git a/libs/gfx/source/painter.cpp b/libs/gfx/source/painter.cpp index 19b84603..1e9ccf13 100644 --- a/libs/gfx/source/painter.cpp +++ b/libs/gfx/source/painter.cpp @@ -235,21 +235,22 @@ namespace psemek::gfx void painter::line(geom::point const & p0, geom::point const & p1, float width, color const & c, bool smooth) { - line(p0, p1, width, c, c, smooth); + line(p0, p1, width, width, c, c, smooth); } - void painter::line(geom::point const & p0, geom::point const & p1, float width, color const & c0, color const & c1, bool smooth) + void painter::line(geom::point const & p0, geom::point const & p1, float width0, float width1, color const & c0, color const & c1, bool smooth) { std::uint32_t const base = impl().vertices.size(); - float const r = width / 2.f; + float const r0 = width0 / 2.f; + float const r1 = width1 / 2.f; auto const d = geom::normalized(p1 - p0); geom::vector const o { -d[1], d[0] }; - impl().vertices.push_back({{p0[0] + r * o[0], p0[1] + r * o[1], 0.f}, c0}); - impl().vertices.push_back({{p0[0] - r * o[0], p0[1] - r * o[1], 0.f}, c0}); - impl().vertices.push_back({{p1[0] + r * o[0], p1[1] + r * o[1], 0.f}, c1}); - impl().vertices.push_back({{p1[0] - r * o[0], p1[1] - r * o[1], 0.f}, c1}); + impl().vertices.push_back({{p0[0] + r0 * o[0], p0[1] + r0 * o[1], 0.f}, c0}); + impl().vertices.push_back({{p0[0] - r0 * o[0], p0[1] - r0 * o[1], 0.f}, c0}); + impl().vertices.push_back({{p1[0] + r1 * o[0], p1[1] + r1 * o[1], 0.f}, c1}); + impl().vertices.push_back({{p1[0] - r1 * o[0], p1[1] - r1 * o[1], 0.f}, c1}); impl().indices.push_back(base + 0); impl().indices.push_back(base + 1); @@ -260,8 +261,8 @@ namespace psemek::gfx if (smooth) { - circle(p0, r, c0); - circle(p1, r, c1); + circle(p0, r0, c0); + circle(p1, r1, c1); } }