diff --git a/libs/gfx/include/psemek/gfx/painter.hpp b/libs/gfx/include/psemek/gfx/painter.hpp index 0068c5b8..edf12ffe 100644 --- a/libs/gfx/include/psemek/gfx/painter.hpp +++ b/libs/gfx/include/psemek/gfx/painter.hpp @@ -57,6 +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 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 geom::vector text_size(std::string_view str, font f = font::font_9x12, float scale = 1.f); diff --git a/libs/gfx/source/painter.cpp b/libs/gfx/source/painter.cpp index e307fd94..2aead2b1 100644 --- a/libs/gfx/source/painter.cpp +++ b/libs/gfx/source/painter.cpp @@ -264,6 +264,22 @@ namespace psemek::gfx } } + void painter::besier(geom::point const & p0, geom::point const & p1, geom::point 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 painter::text_size(std::string_view str, font f, float scale) { // TODO: multiline text