@@ -125,6 +125,24 @@ static void _get_screen_area(vectorio_vector_shape_t *self, displayio_area_t *ou
125
125
}
126
126
127
127
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
+
128
146
// For use by Group to know where it needs to redraw on layer removal.
129
147
bool vectorio_vector_shape_get_dirty_area (vectorio_vector_shape_t * self , displayio_area_t * out_area ) {
130
148
out_area -> x1 = out_area -> x2 ;
@@ -164,10 +182,10 @@ void common_hal_vectorio_vector_shape_set_dirty(void *vector_shape) {
164
182
165
183
void common_hal_vectorio_vector_shape_construct (vectorio_vector_shape_t * self ,
166
184
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 ) {
168
186
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 ) ;
171
189
self -> pixel_shader = pixel_shader ;
172
190
self -> ishape = ishape ;
173
191
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
189
207
if (self -> x == x ) {
190
208
return ;
191
209
}
192
- self -> x = x ;
210
+ check_bounds_and_set_x ( self , x ) ;
193
211
common_hal_vectorio_vector_shape_set_dirty (self );
194
212
}
195
213
@@ -205,7 +223,7 @@ void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_in
205
223
if (self -> y == y ) {
206
224
return ;
207
225
}
208
- self -> y = y ;
226
+ check_bounds_and_set_y ( self , y ) ;
209
227
common_hal_vectorio_vector_shape_set_dirty (self );
210
228
}
211
229
@@ -224,20 +242,27 @@ void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self
224
242
mp_obj_t * tuple_items ;
225
243
mp_obj_tuple_get (xy , & tuple_len , & tuple_items );
226
244
if (tuple_len != 2 ) {
227
- mp_raise_TypeError_varg (translate ("(x,y) integers required" ));
245
+ mp_raise_TypeError (translate ("(x,y) integers required" ));
228
246
}
229
247
230
248
mp_int_t x ;
231
249
mp_int_t y ;
232
250
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 )) {
236
252
mp_raise_ValueError_varg (translate ("unsupported %q type" ), MP_QSTR_point );
237
253
}
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
+ }
241
266
}
242
267
243
268
0 commit comments