Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PicoVector - Fixes & Improvements #843

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libraries/pico_vector/pico_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace pimoroni {
void PicoVector::polygon(std::vector<pretty_poly::contour_t<picovector_point_type>> contours, Point origin, int scale) {
pretty_poly::settings::clip = {graphics->clip.x, graphics->clip.y, graphics->clip.w, graphics->clip.h};
pretty_poly::draw_polygon<picovector_point_type>(
contours,
pretty_poly::point_t<int>(origin.x, origin.y),
Expand Down Expand Up @@ -50,6 +51,8 @@ namespace pimoroni {
}

Point PicoVector::text(std::string_view text, Point origin) {
// Copy clipping bounds from the PicoGraphics instance
pretty_poly::settings::clip = {graphics->clip.x, graphics->clip.y, graphics->clip.w, graphics->clip.h};
// TODO: Normalize types somehow, so we're not converting?
pretty_poly::point_t<int> caret = pretty_poly::point_t<int>(origin.x, origin.y);

Expand Down Expand Up @@ -109,6 +112,8 @@ namespace pimoroni {
}

Point PicoVector::text(std::string_view text, Point origin, float angle) {
// Copy clipping bounds from the PicoGraphics instance
pretty_poly::settings::clip = {graphics->clip.x, graphics->clip.y, graphics->clip.w, graphics->clip.h};
// TODO: Normalize types somehow, so we're not converting?
pretty_poly::point_t<float> caret(0, 0);

Expand Down
2 changes: 1 addition & 1 deletion libraries/pico_vector/pico_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace pimoroni {
tile_data += tile.stride - tile.bounds.w;
}
}
}, graphics->supports_alpha_blend() ? pretty_poly::X4 : pretty_poly::NONE, {0, 0, graphics->bounds.w, graphics->bounds.h});
}, graphics->supports_alpha_blend() ? pretty_poly::X4 : pretty_poly::NONE, {graphics->clip.x, graphics->clip.y, graphics->clip.w, graphics->clip.h});
}

void set_antialiasing(pretty_poly::antialias_t antialias) {
Expand Down
2 changes: 2 additions & 0 deletions micropython/modules/picovector/picovector.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

STATIC MP_DEFINE_CONST_FUN_OBJ_1(POLYGON__del__obj, POLYGON__del__);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(POLYGON_centroid_obj, POLYGON_centroid);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(POLYGON_bounds_obj, POLYGON_bounds);


STATIC const mp_rom_map_elem_t POLYGON_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&POLYGON__del__obj) },
{ MP_ROM_QSTR(MP_QSTR_centroid), MP_ROM_PTR(&POLYGON_centroid_obj) },
{ MP_ROM_QSTR(MP_QSTR_bounds), MP_ROM_PTR(&POLYGON_bounds_obj) },
};

STATIC MP_DEFINE_CONST_DICT(POLYGON_locals_dict, POLYGON_locals_dict_table);
Expand Down
12 changes: 12 additions & 0 deletions micropython/modules/picovector/picovector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ mp_obj_t POLYGON_centroid(mp_obj_t self_in) {
return mp_obj_new_tuple(2, tuple);
}

mp_obj_t POLYGON_bounds(mp_obj_t self_in) {
_POLYGON_obj_t *self = MP_OBJ_TO_PTR2(self_in, _POLYGON_obj_t);

mp_obj_t tuple[4];
tuple[0] = mp_obj_new_int((int)(self->contour.bounds().x));
tuple[1] = mp_obj_new_int((int)(self->contour.bounds().y));
tuple[2] = mp_obj_new_int((int)(self->contour.bounds().w));
tuple[3] = mp_obj_new_int((int)(self->contour.bounds().h));

return mp_obj_new_tuple(4, tuple);
}

void POLYGON_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind;
_POLYGON_obj_t *self = MP_OBJ_TO_PTR2(self_in, _POLYGON_obj_t);
Expand Down
1 change: 1 addition & 0 deletions micropython/modules/picovector/picovector.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern mp_obj_t REGULAR_POLYGON_make_new(const mp_obj_type_t *type, size_t n_arg
extern mp_obj_t RECTANGLE_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
extern void POLYGON_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind);
extern mp_obj_t POLYGON_centroid(mp_obj_t self_in);
extern mp_obj_t POLYGON_bounds(mp_obj_t self_in);
extern mp_obj_t POLYGON_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf);

extern mp_obj_t POLYGON__del__(mp_obj_t self_in);
Expand Down