diff --git a/shared-bindings/vectorio/Circle.c b/shared-bindings/vectorio/Circle.c index c0cc0bbcc216..cdf8965e7541 100644 --- a/shared-bindings/vectorio/Circle.c +++ b/shared-bindings/vectorio/Circle.c @@ -42,8 +42,8 @@ static mp_obj_t vectorio_circle_make_new(const mp_obj_type_t *type, size_t n_arg // VectorShape parts mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj; - int16_t x = args[ARG_x].u_int; - int16_t y = args[ARG_y].u_int; + int32_t x = args[ARG_x].u_int; + int32_t y = args[ARG_y].u_int; mp_obj_t vector_shape = vectorio_vector_shape_make_new(self, pixel_shader, x, y); self->draw_protocol_instance = vector_shape; diff --git a/shared-bindings/vectorio/Polygon.c b/shared-bindings/vectorio/Polygon.c index 5d493a30b63f..17d293c7a39e 100644 --- a/shared-bindings/vectorio/Polygon.c +++ b/shared-bindings/vectorio/Polygon.c @@ -47,8 +47,8 @@ static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_ar // VectorShape parts mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj; - int16_t x = args[ARG_x].u_int; - int16_t y = args[ARG_y].u_int; + int32_t x = args[ARG_x].u_int; + int32_t y = args[ARG_y].u_int; mp_obj_t vector_shape = vectorio_vector_shape_make_new(self, pixel_shader, x, y); self->draw_protocol_instance = vector_shape; diff --git a/shared-bindings/vectorio/Rectangle.c b/shared-bindings/vectorio/Rectangle.c index aa2c166a6d8e..c6f45874bdf9 100644 --- a/shared-bindings/vectorio/Rectangle.c +++ b/shared-bindings/vectorio/Rectangle.c @@ -46,8 +46,8 @@ static mp_obj_t vectorio_rectangle_make_new(const mp_obj_type_t *type, size_t n_ // VectorShape parts mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj; - int16_t x = args[ARG_x].u_int; - int16_t y = args[ARG_y].u_int; + int32_t x = args[ARG_x].u_int; + int32_t y = args[ARG_y].u_int; mp_obj_t vector_shape = vectorio_vector_shape_make_new(self, pixel_shader, x, y); self->draw_protocol_instance = vector_shape; diff --git a/shared-bindings/vectorio/VectorShape.c b/shared-bindings/vectorio/VectorShape.c index 6e4299a6d3bc..c9cbf0a114fb 100644 --- a/shared-bindings/vectorio/VectorShape.c +++ b/shared-bindings/vectorio/VectorShape.c @@ -23,7 +23,7 @@ // pixel_shader: The pixel shader that produces colors from values. The shader can be a displayio.Palette(1); it will be asked to color pixel value 0. // x: Initial x position of the center axis of the shape within the parent. // y: Initial y position of the center axis of the shape within the parent.""" -mp_obj_t vectorio_vector_shape_make_new(const mp_obj_t shape, const mp_obj_t pixel_shader, int16_t x, int16_t y) { +mp_obj_t vectorio_vector_shape_make_new(const mp_obj_t shape, const mp_obj_t pixel_shader, int32_t x, int32_t y) { if (!mp_obj_is_type(pixel_shader, &displayio_colorconverter_type) && !mp_obj_is_type(pixel_shader, &displayio_palette_type)) { mp_raise_TypeError_varg(translate("unsupported %q type"), MP_QSTR_pixel_shader); diff --git a/shared-bindings/vectorio/VectorShape.h b/shared-bindings/vectorio/VectorShape.h index 9ac69060000d..12c7e628ad63 100644 --- a/shared-bindings/vectorio/VectorShape.h +++ b/shared-bindings/vectorio/VectorShape.h @@ -11,12 +11,12 @@ extern const mp_obj_type_t vectorio_vector_shape_type; // Python shared bindings constructor -mp_obj_t vectorio_vector_shape_make_new(const mp_obj_t shape, const mp_obj_t pixel_shader, int16_t x, int16_t y); +mp_obj_t vectorio_vector_shape_make_new(const mp_obj_t shape, const mp_obj_t pixel_shader, int32_t x, int32_t y); // C data constructor void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self, vectorio_ishape_t ishape, - mp_obj_t pixel_shader, uint16_t x, uint16_t y); + mp_obj_t pixel_shader, int32_t x, int32_t y); void common_hal_vectorio_vector_shape_set_dirty(void *self); diff --git a/shared-module/vectorio/Polygon.c b/shared-module/vectorio/Polygon.c index f7199c7f8334..f0b241e35198 100644 --- a/shared-module/vectorio/Polygon.c +++ b/shared-module/vectorio/Polygon.c @@ -22,7 +22,7 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple VECTORIO_POLYGON_DEBUG(" self.len: %d, len: %d, ", self->len, len); if (len < 3) { - mp_raise_TypeError_varg(translate("Polygon needs at least 3 points")); + mp_raise_TypeError(translate("Polygon needs at least 3 points")); } if (self->len < 2 * len) { diff --git a/shared-module/vectorio/VectorShape.c b/shared-module/vectorio/VectorShape.c index 9d0279cf14e4..7899e2710cf6 100644 --- a/shared-module/vectorio/VectorShape.c +++ b/shared-module/vectorio/VectorShape.c @@ -125,6 +125,24 @@ static void _get_screen_area(vectorio_vector_shape_t *self, displayio_area_t *ou } +STATIC +void check_bounds_and_set_x(vectorio_vector_shape_t *self, mp_int_t x) { + if (x < SHRT_MIN || x > SHRT_MAX) { + mp_raise_ValueError_varg(translate("%q must be between %d and %d"), MP_QSTR_x, SHRT_MIN, SHRT_MAX); + } + self->x = x; +} + + +STATIC +void check_bounds_and_set_y(vectorio_vector_shape_t *self, mp_int_t y) { + if (y < SHRT_MIN || y > SHRT_MAX) { + mp_raise_ValueError_varg(translate("%q must be between %d and %d"), MP_QSTR_y, SHRT_MIN, SHRT_MAX); + } + self->y = y; +} + + // For use by Group to know where it needs to redraw on layer removal. bool vectorio_vector_shape_get_dirty_area(vectorio_vector_shape_t *self, displayio_area_t *out_area) { out_area->x1 = out_area->x2; @@ -164,10 +182,10 @@ void common_hal_vectorio_vector_shape_set_dirty(void *vector_shape) { void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self, vectorio_ishape_t ishape, - mp_obj_t pixel_shader, uint16_t x, uint16_t y) { + mp_obj_t pixel_shader, int32_t x, int32_t y) { VECTORIO_SHAPE_DEBUG("%p vector_shape_construct x:%3d, y:%3d\n", self, x, y); - self->x = x; - self->y = y; + check_bounds_and_set_x(self, x); + check_bounds_and_set_y(self, y); self->pixel_shader = pixel_shader; self->ishape = ishape; self->absolute_transform = &null_transform; // Critical to have a valid transform before getting screen area. @@ -189,7 +207,7 @@ void common_hal_vectorio_vector_shape_set_x(vectorio_vector_shape_t *self, mp_in if (self->x == x) { return; } - self->x = x; + check_bounds_and_set_x(self, x); common_hal_vectorio_vector_shape_set_dirty(self); } @@ -205,7 +223,7 @@ void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_in if (self->y == y) { return; } - self->y = y; + check_bounds_and_set_y(self, y); common_hal_vectorio_vector_shape_set_dirty(self); } @@ -224,20 +242,27 @@ void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self mp_obj_t *tuple_items; mp_obj_tuple_get(xy, &tuple_len, &tuple_items); if (tuple_len != 2) { - mp_raise_TypeError_varg(translate("(x,y) integers required")); + mp_raise_TypeError(translate("(x,y) integers required")); } mp_int_t x; mp_int_t y; if (!mp_obj_get_int_maybe(tuple_items[ 0 ], &x) - || !mp_obj_get_int_maybe(tuple_items[ 1 ], &y) - || x < SHRT_MIN || x > SHRT_MAX || y < SHRT_MIN || y > SHRT_MAX - ) { + || !mp_obj_get_int_maybe(tuple_items[ 1 ], &y)) { mp_raise_ValueError_varg(translate("unsupported %q type"), MP_QSTR_point); } - self->x = (int16_t)x; - self->y = (int16_t)y; - common_hal_vectorio_vector_shape_set_dirty(self); + bool dirty = false; + if (self->x != x) { + check_bounds_and_set_x(self, x); + dirty = true; + } + if (self->y != y) { + check_bounds_and_set_y(self, y); + dirty = true; + } + if (dirty) { + common_hal_vectorio_vector_shape_set_dirty(self); + } }