diff --git a/libs/gfx/include/psemek/gfx/painter.hpp b/libs/gfx/include/psemek/gfx/painter.hpp index 1b36159d..e671685c 100644 --- a/libs/gfx/include/psemek/gfx/painter.hpp +++ b/libs/gfx/include/psemek/gfx/painter.hpp @@ -59,6 +59,7 @@ namespace psemek::gfx 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 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); + void polygon(util::span const> points, color const & c); // 2D text geom::vector text_size(std::string_view str, font f = font::font_9x12); diff --git a/libs/gfx/source/painter.cpp b/libs/gfx/source/painter.cpp index 1e9ccf13..31a6cac5 100644 --- a/libs/gfx/source/painter.cpp +++ b/libs/gfx/source/painter.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -282,6 +283,21 @@ namespace psemek::gfx } } + void painter::polygon(util::span const> points, color const & c) + { + auto dcel = cg::ear_clipping(points.begin(), points.end()); + + for (std::uint32_t i = 0; i < dcel.faces.size(); ++i) + { + auto e = dcel.face(i).edge(); + auto p0 = points[e.origin().index()]; e = e.next(); + auto p1 = points[e.origin().index()]; e = e.next(); + auto p2 = points[e.origin().index()]; + + triangle(p0, p1, p2, c); + } + } + geom::vector painter::text_size(std::string_view str, font f) { // TODO: multiline text