@@ -125,6 +125,24 @@ static void _get_screen_area(vectorio_vector_shape_t *self, displayio_area_t *ou
125125}
126126
127127
128+ STATIC
129+ void check_bounds_and_set_x (vectorio_vector_shape_t * self , mp_int_t x ) {
130+ if (x < SHRT_MIN || x > SHRT_MAX ) {
131+ mp_raise_ValueError_varg (translate ("%q must be between %d and %d" ), MP_QSTR_x , SHRT_MIN , SHRT_MAX );
132+ }
133+ self -> x = x ;
134+ }
135+
136+
137+ STATIC
138+ void check_bounds_and_set_y (vectorio_vector_shape_t * self , mp_int_t y ) {
139+ if (y < SHRT_MIN || y > SHRT_MAX ) {
140+ mp_raise_ValueError_varg (translate ("%q must be between %d and %d" ), MP_QSTR_y , SHRT_MIN , SHRT_MAX );
141+ }
142+ self -> y = y ;
143+ }
144+
145+
128146// For use by Group to know where it needs to redraw on layer removal.
129147bool vectorio_vector_shape_get_dirty_area (vectorio_vector_shape_t * self , displayio_area_t * out_area ) {
130148 out_area -> x1 = out_area -> x2 ;
@@ -164,10 +182,10 @@ void common_hal_vectorio_vector_shape_set_dirty(void *vector_shape) {
164182
165183void common_hal_vectorio_vector_shape_construct (vectorio_vector_shape_t * self ,
166184 vectorio_ishape_t ishape ,
167- mp_obj_t pixel_shader , uint16_t x , uint16_t y ) {
185+ mp_obj_t pixel_shader , int32_t x , int32_t y ) {
168186 VECTORIO_SHAPE_DEBUG ("%p vector_shape_construct x:%3d, y:%3d\n" , self , x , y );
169- self -> x = x ;
170- self -> y = y ;
187+ check_bounds_and_set_x ( self , x ) ;
188+ check_bounds_and_set_y ( self , y ) ;
171189 self -> pixel_shader = pixel_shader ;
172190 self -> ishape = ishape ;
173191 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
189207 if (self -> x == x ) {
190208 return ;
191209 }
192- self -> x = x ;
210+ check_bounds_and_set_x ( self , x ) ;
193211 common_hal_vectorio_vector_shape_set_dirty (self );
194212}
195213
@@ -205,7 +223,7 @@ void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_in
205223 if (self -> y == y ) {
206224 return ;
207225 }
208- self -> y = y ;
226+ check_bounds_and_set_y ( self , y ) ;
209227 common_hal_vectorio_vector_shape_set_dirty (self );
210228}
211229
@@ -224,20 +242,27 @@ void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self
224242 mp_obj_t * tuple_items ;
225243 mp_obj_tuple_get (xy , & tuple_len , & tuple_items );
226244 if (tuple_len != 2 ) {
227- mp_raise_TypeError_varg (translate ("(x,y) integers required" ));
245+ mp_raise_TypeError (translate ("(x,y) integers required" ));
228246 }
229247
230248 mp_int_t x ;
231249 mp_int_t y ;
232250 if (!mp_obj_get_int_maybe (tuple_items [ 0 ], & x )
233- || !mp_obj_get_int_maybe (tuple_items [ 1 ], & y )
234- || x < SHRT_MIN || x > SHRT_MAX || y < SHRT_MIN || y > SHRT_MAX
235- ) {
251+ || !mp_obj_get_int_maybe (tuple_items [ 1 ], & y )) {
236252 mp_raise_ValueError_varg (translate ("unsupported %q type" ), MP_QSTR_point );
237253 }
238- self -> x = (int16_t )x ;
239- self -> y = (int16_t )y ;
240- common_hal_vectorio_vector_shape_set_dirty (self );
254+ bool dirty = false;
255+ if (self -> x != x ) {
256+ check_bounds_and_set_x (self , x );
257+ dirty = true;
258+ }
259+ if (self -> y != y ) {
260+ check_bounds_and_set_y (self , y );
261+ dirty = true;
262+ }
263+ if (dirty ) {
264+ common_hal_vectorio_vector_shape_set_dirty (self );
265+ }
241266}
242267
243268
0 commit comments