Support drawing polygons in gfx::painter
This commit is contained in:
parent
a2c83633ae
commit
c16194c95c
2 changed files with 17 additions and 0 deletions
|
|
@ -59,6 +59,7 @@ namespace psemek::gfx
|
||||||
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 & c, bool smooth = true);
|
||||||
void line(geom::point<float, 2> const & p0, geom::point<float, 2> const & p1, float w0, float w1, color const & c0, color const & c1, bool smooth = true);
|
void line(geom::point<float, 2> const & p0, geom::point<float, 2> const & p1, float w0, float w1, 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);
|
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);
|
||||||
|
void polygon(util::span<geom::point<float, 2> const> points, color const & c);
|
||||||
|
|
||||||
// 2D text
|
// 2D text
|
||||||
geom::vector<float, 2> text_size(std::string_view str, font f = font::font_9x12);
|
geom::vector<float, 2> text_size(std::string_view str, font f = font::font_9x12);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <psemek/gfx/mesh.hpp>
|
#include <psemek/gfx/mesh.hpp>
|
||||||
#include <psemek/gfx/texture.hpp>
|
#include <psemek/gfx/texture.hpp>
|
||||||
#include <psemek/gfx/resource/font_9x12_png.hpp>
|
#include <psemek/gfx/resource/font_9x12_png.hpp>
|
||||||
|
#include <psemek/cg/triangulation/ear_clipping.hpp>
|
||||||
#include <psemek/geom/constants.hpp>
|
#include <psemek/geom/constants.hpp>
|
||||||
#include <psemek/io/memory_stream.hpp>
|
#include <psemek/io/memory_stream.hpp>
|
||||||
#include <psemek/util/enum.hpp>
|
#include <psemek/util/enum.hpp>
|
||||||
|
|
@ -282,6 +283,21 @@ namespace psemek::gfx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void painter::polygon(util::span<geom::point<float, 2> const> points, color const & c)
|
||||||
|
{
|
||||||
|
auto dcel = cg::ear_clipping<std::uint32_t>(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<float, 2> painter::text_size(std::string_view str, font f)
|
geom::vector<float, 2> painter::text_size(std::string_view str, font f)
|
||||||
{
|
{
|
||||||
// TODO: multiline text
|
// TODO: multiline text
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue