2023-09-26 12:37:55 +00:00
|
|
|
#define PP_IMPLEMENTATION
|
2024-04-18 11:37:33 +00:00
|
|
|
#define AF_IMPLEMENTATION
|
2024-07-25 14:07:26 +00:00
|
|
|
#define PPP_IMPLEMENTATION
|
2023-08-14 14:58:40 +00:00
|
|
|
#include "pico_vector.hpp"
|
|
|
|
#include <vector>
|
|
|
|
|
2024-07-25 14:07:26 +00:00
|
|
|
|
2023-08-14 14:58:40 +00:00
|
|
|
namespace pimoroni {
|
2023-09-26 12:37:55 +00:00
|
|
|
PicoGraphics *PicoVector::graphics = nullptr;
|
2023-08-14 14:58:40 +00:00
|
|
|
|
2023-09-26 12:37:55 +00:00
|
|
|
void PicoVector::draw(pp_poly_t *poly) {
|
|
|
|
pp_transform(NULL);
|
|
|
|
pp_render(poly);
|
2023-08-15 16:34:46 +00:00
|
|
|
}
|
|
|
|
|
2023-09-26 12:37:55 +00:00
|
|
|
void PicoVector::draw(pp_poly_t *poly, pp_mat3_t *t) {
|
|
|
|
pp_transform(t);
|
|
|
|
pp_render(poly);
|
2023-08-15 16:34:46 +00:00
|
|
|
}
|
|
|
|
|
2023-09-26 12:37:55 +00:00
|
|
|
void PicoVector::rotate(pp_path_t *path, pp_point_t origin, float angle) {
|
|
|
|
pp_mat3_t t = pp_mat3_identity();
|
|
|
|
pp_mat3_translate(&t, origin.x, origin.y);
|
2024-04-18 09:57:37 +00:00
|
|
|
pp_mat3_rotate(&t, angle);
|
|
|
|
pp_mat3_translate(&t, -origin.x, -origin.y);
|
2023-09-26 12:37:55 +00:00
|
|
|
transform(path, &t);
|
2023-08-16 12:10:53 +00:00
|
|
|
}
|
|
|
|
|
2023-09-26 12:37:55 +00:00
|
|
|
void PicoVector::translate(pp_path_t *path, pp_point_t translation) {
|
|
|
|
pp_mat3_t t = pp_mat3_identity();
|
|
|
|
pp_mat3_translate(&t, translation.x, translation.y);
|
|
|
|
transform(path, &t);
|
2023-08-16 12:10:53 +00:00
|
|
|
}
|
|
|
|
|
2023-09-26 12:37:55 +00:00
|
|
|
void PicoVector::transform(pp_path_t *path, pp_mat3_t *t) {
|
2024-07-22 16:33:52 +00:00
|
|
|
for (auto j = 0; j < path->count; j++) {
|
2023-09-26 12:37:55 +00:00
|
|
|
path->points[j] = pp_point_transform(&path->points[j], t);
|
2023-08-15 10:42:19 +00:00
|
|
|
}
|
2023-09-26 12:37:55 +00:00
|
|
|
}
|
2023-08-15 10:42:19 +00:00
|
|
|
|
2023-09-26 12:37:55 +00:00
|
|
|
void PicoVector::rotate(pp_poly_t *poly, pp_point_t origin, float angle) {
|
|
|
|
pp_mat3_t t = pp_mat3_identity();
|
|
|
|
pp_mat3_translate(&t, origin.x, origin.y);
|
2024-04-18 09:57:37 +00:00
|
|
|
pp_mat3_rotate(&t, angle);
|
|
|
|
pp_mat3_translate(&t, -origin.x, -origin.y);
|
2023-09-26 12:37:55 +00:00
|
|
|
transform(poly, &t);
|
|
|
|
}
|
2023-08-15 10:42:19 +00:00
|
|
|
|
2023-09-26 12:37:55 +00:00
|
|
|
void PicoVector::translate(pp_poly_t *poly, pp_point_t translation) {
|
|
|
|
pp_mat3_t t = pp_mat3_identity();
|
|
|
|
pp_mat3_translate(&t, translation.x, translation.y);
|
|
|
|
transform(poly, &t);
|
|
|
|
}
|
2023-08-15 10:42:19 +00:00
|
|
|
|
2023-09-26 12:37:55 +00:00
|
|
|
void PicoVector::transform(pp_poly_t *poly, pp_mat3_t *t) {
|
2024-07-22 16:33:52 +00:00
|
|
|
pp_path_t *path = poly->paths;
|
|
|
|
while(path) {
|
|
|
|
transform(path, t);
|
|
|
|
path = path->next;
|
2023-08-14 14:58:40 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-17 12:46:13 +00:00
|
|
|
|
2024-11-17 13:11:56 +00:00
|
|
|
pp_point_t PicoVector::text(std::string_view text, int max_width, int max_height, pp_mat3_t *t) {
|
2023-09-26 12:37:55 +00:00
|
|
|
pp_point_t caret = {0, 0};
|
2023-08-17 12:46:13 +00:00
|
|
|
|
2024-04-19 11:28:11 +00:00
|
|
|
text_metrics.transform = t;
|
|
|
|
|
2024-11-17 13:11:56 +00:00
|
|
|
af_render(text_metrics.face, text.data(), text.size(), max_width, max_height, &text_metrics);
|
2024-04-19 11:28:11 +00:00
|
|
|
|
|
|
|
return caret;
|
2023-08-17 12:46:13 +00:00
|
|
|
}
|
2023-08-14 14:58:40 +00:00
|
|
|
}
|