pimoroni-pico/libraries/pico_vector/pico_vector.hpp

43 wiersze
1.5 KiB
C++

#include "pretty_poly.hpp"
#include "alright_fonts.hpp"
#include "pico_graphics.hpp"
namespace pimoroni {
class PicoVector {
private:
PicoGraphics *graphics;
alright_fonts::text_metrics_t text_metrics;
public:
PicoVector(PicoGraphics *graphics, void *mem = nullptr) : graphics(graphics) {
pretty_poly::init(mem);
set_options([this](const pretty_poly::tile_t &tile) -> void {
for(auto y = 0; y < tile.bounds.h; y++) {
for(auto x = 0; x < tile.bounds.w; x++) {
uint8_t alpha = tile.get_value(x, y);
if (alpha > 0) {
this->graphics->pixel({x + tile.bounds.x, y + tile.bounds.y});
}
}
}
}, pretty_poly::NONE, {0, 0, graphics->bounds.w, graphics->bounds.h});
};
bool set_font(std::string_view font_path, unsigned int font_size) {
bool result = text_metrics.face.load(font_path);
text_metrics.set_size(font_size);
return result;
}
Point text(std::string_view text, Point origin);
void polygon(std::vector<pretty_poly::contour_t<int>> contours, Point origin = Point(0, 0), int scale=65536);
static constexpr size_t pretty_poly_buffer_size() {
return pretty_poly::buffer_size();
};
};
}