Skip to content

Commit 1f4704a

Browse files
authored
Merge pull request #843 from pimoroni/feature/picovector
PicoVector - Fixes & Improvements
2 parents c3919bd + ae7e6e8 commit 1f4704a

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

libraries/pico_vector/pico_vector.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

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

@@ -109,6 +112,8 @@ namespace pimoroni {
109112
}
110113

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

libraries/pico_vector/pico_vector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace pimoroni {
5050
tile_data += tile.stride - tile.bounds.w;
5151
}
5252
}
53-
}, graphics->supports_alpha_blend() ? pretty_poly::X4 : pretty_poly::NONE, {0, 0, graphics->bounds.w, graphics->bounds.h});
53+
}, graphics->supports_alpha_blend() ? pretty_poly::X4 : pretty_poly::NONE, {graphics->clip.x, graphics->clip.y, graphics->clip.w, graphics->clip.h});
5454
}
5555

5656
void set_antialiasing(pretty_poly::antialias_t antialias) {

micropython/modules/picovector/picovector.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
STATIC MP_DEFINE_CONST_FUN_OBJ_1(POLYGON__del__obj, POLYGON__del__);
66
STATIC MP_DEFINE_CONST_FUN_OBJ_1(POLYGON_centroid_obj, POLYGON_centroid);
7+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(POLYGON_bounds_obj, POLYGON_bounds);
78

89

910
STATIC const mp_rom_map_elem_t POLYGON_locals_dict_table[] = {
1011
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&POLYGON__del__obj) },
1112
{ MP_ROM_QSTR(MP_QSTR_centroid), MP_ROM_PTR(&POLYGON_centroid_obj) },
13+
{ MP_ROM_QSTR(MP_QSTR_bounds), MP_ROM_PTR(&POLYGON_bounds_obj) },
1214
};
1315

1416
STATIC MP_DEFINE_CONST_DICT(POLYGON_locals_dict, POLYGON_locals_dict_table);

micropython/modules/picovector/picovector.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ mp_obj_t POLYGON_centroid(mp_obj_t self_in) {
232232
return mp_obj_new_tuple(2, tuple);
233233
}
234234

235+
mp_obj_t POLYGON_bounds(mp_obj_t self_in) {
236+
_POLYGON_obj_t *self = MP_OBJ_TO_PTR2(self_in, _POLYGON_obj_t);
237+
238+
mp_obj_t tuple[4];
239+
tuple[0] = mp_obj_new_int((int)(self->contour.bounds().x));
240+
tuple[1] = mp_obj_new_int((int)(self->contour.bounds().y));
241+
tuple[2] = mp_obj_new_int((int)(self->contour.bounds().w));
242+
tuple[3] = mp_obj_new_int((int)(self->contour.bounds().h));
243+
244+
return mp_obj_new_tuple(4, tuple);
245+
}
246+
235247
void POLYGON_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
236248
(void)kind;
237249
_POLYGON_obj_t *self = MP_OBJ_TO_PTR2(self_in, _POLYGON_obj_t);

micropython/modules/picovector/picovector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern mp_obj_t REGULAR_POLYGON_make_new(const mp_obj_type_t *type, size_t n_arg
1111
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);
1212
extern void POLYGON_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind);
1313
extern mp_obj_t POLYGON_centroid(mp_obj_t self_in);
14+
extern mp_obj_t POLYGON_bounds(mp_obj_t self_in);
1415
extern mp_obj_t POLYGON_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf);
1516

1617
extern mp_obj_t POLYGON__del__(mp_obj_t self_in);

0 commit comments

Comments
 (0)