Support drawing quadratic besier lines in gfx::painter
This commit is contained in:
parent
ebda20ff9c
commit
4ab4788eca
2 changed files with 17 additions and 0 deletions
|
|
@ -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 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
|
||||
geom::vector<float, 2> text_size(std::string_view str, font f = font::font_9x12, float scale = 1.f);
|
||||
|
|
|
|||
|
|
@ -264,6 +264,22 @@ namespace psemek::gfx
|
|||
}
|
||||
}
|
||||
|
||||
void painter::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, bool smooth)
|
||||
{
|
||||
auto at = [&](float t)
|
||||
{
|
||||
return p0 + (2.f * t) * (p1 - p0) + (t * t) * ((p2 - p1) + (p0 - p1));
|
||||
};
|
||||
|
||||
for (int i = 0; i < quality; ++i)
|
||||
{
|
||||
float t0 = (i * 1.f) / quality;
|
||||
float t1 = ((i + 1) * 1.f) / quality;
|
||||
|
||||
line(at(t0), at(t1), width, c, smooth);
|
||||
}
|
||||
}
|
||||
|
||||
geom::vector<float, 2> painter::text_size(std::string_view str, font f, float scale)
|
||||
{
|
||||
// TODO: multiline text
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue