Support interpolated line color in gfx::painter

This commit is contained in:
Nikita Lisitsa 2021-06-20 15:53:08 +03:00
parent 4ab4788eca
commit 6994b23fdb
2 changed files with 12 additions and 6 deletions

View file

@ -57,6 +57,7 @@ namespace psemek::gfx
void rect(geom::box<float, 2> const & box, color const & c);
void circle(geom::point<float, 2> const & center, float radius, color const & c, int quality = 24);
void line(geom::point<float, 2> const & p0, geom::point<float, 2> const & p1, float width, color const & c, bool smooth = true);
void line(geom::point<float, 2> const & p0, geom::point<float, 2> const & p1, float width, color const & c0, color const & c1, bool smooth = true);
void besier(geom::point<float, 2> const & p0, geom::point<float, 2> const & p1, geom::point<float, 2> const & p2, float width, color const & c, int quality = 8, bool smooth = true);
// 2D text

View file

@ -238,6 +238,11 @@ namespace psemek::gfx
}
void painter::line(geom::point<float, 2> const & p0, geom::point<float, 2> const & p1, float width, color const & c, bool smooth)
{
line(p0, p1, width, c, c, smooth);
}
void painter::line(geom::point<float, 2> const & p0, geom::point<float, 2> const & p1, float width, color const & c0, color const & c1, bool smooth)
{
std::uint32_t const base = impl().vertices.size();
float const r = width / 2.f;
@ -245,10 +250,10 @@ namespace psemek::gfx
auto const d = geom::normalized(p1 - p0);
geom::vector<float, 2> const o { -d[1], d[0] };
impl().vertices.push_back({{p0[0] + r * o[0], p0[1] + r * o[1], 0.f}, c});
impl().vertices.push_back({{p0[0] - r * o[0], p0[1] - r * o[1], 0.f}, c});
impl().vertices.push_back({{p1[0] + r * o[0], p1[1] + r * o[1], 0.f}, c});
impl().vertices.push_back({{p1[0] - r * o[0], p1[1] - r * o[1], 0.f}, c});
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().indices.push_back(base + 0);
impl().indices.push_back(base + 1);
@ -259,8 +264,8 @@ namespace psemek::gfx
if (smooth)
{
circle(p0, r, c);
circle(p1, r, c);
circle(p0, r, c0);
circle(p1, r, c1);
}
}