@@ -52,11 +52,18 @@ void common_hal_displayio_group_set_hidden(displayio_group_t* self, bool hidden)
52
52
return ;
53
53
}
54
54
for (size_t i = 0 ; i < self -> size ; i ++ ) {
55
- mp_obj_t layer = self -> children [i ].native ;
56
- if (MP_OBJ_IS_TYPE (layer , & displayio_tilegrid_type )) {
55
+ mp_obj_t layer ;
56
+ layer = mp_instance_cast_to_native_base (
57
+ self -> children [i ].original , & displayio_tilegrid_type );
58
+ if (layer != MP_OBJ_NULL ) {
57
59
displayio_tilegrid_set_hidden_by_parent (layer , hidden );
58
- } else if (MP_OBJ_IS_TYPE (layer , & displayio_group_type )) {
60
+ continue ;
61
+ }
62
+ layer = mp_instance_cast_to_native_base (
63
+ self -> children [i ].original , & displayio_group_type );
64
+ if (layer != MP_OBJ_NULL ) {
59
65
displayio_group_set_hidden_by_parent (layer , hidden );
66
+ continue ;
60
67
}
61
68
}
62
69
}
@@ -71,11 +78,18 @@ void displayio_group_set_hidden_by_parent(displayio_group_t *self, bool hidden)
71
78
return ;
72
79
}
73
80
for (size_t i = 0 ; i < self -> size ; i ++ ) {
74
- mp_obj_t layer = self -> children [i ].native ;
75
- if (MP_OBJ_IS_TYPE (layer , & displayio_tilegrid_type )) {
81
+ mp_obj_t layer ;
82
+ layer = mp_instance_cast_to_native_base (
83
+ self -> children [i ].original , & displayio_tilegrid_type );
84
+ if (layer != MP_OBJ_NULL ) {
76
85
displayio_tilegrid_set_hidden_by_parent (layer , hidden );
77
- } else if (MP_OBJ_IS_TYPE (layer , & displayio_group_type )) {
86
+ continue ;
87
+ }
88
+ layer = mp_instance_cast_to_native_base (
89
+ self -> children [i ].original , & displayio_group_type );
90
+ if (layer != MP_OBJ_NULL ) {
78
91
displayio_group_set_hidden_by_parent (layer , hidden );
92
+ continue ;
79
93
}
80
94
}
81
95
}
@@ -87,15 +101,21 @@ uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self) {
87
101
bool displayio_group_get_previous_area (displayio_group_t * self , displayio_area_t * area ) {
88
102
bool first = true;
89
103
for (size_t i = 0 ; i < self -> size ; i ++ ) {
90
- mp_obj_t layer = self -> children [ i ]. native ;
104
+ mp_obj_t layer ;
91
105
displayio_area_t layer_area ;
92
- if (MP_OBJ_IS_TYPE (layer , & displayio_tilegrid_type )) {
106
+ layer = mp_instance_cast_to_native_base (
107
+ self -> children [i ].original , & displayio_tilegrid_type );
108
+ if (layer != MP_OBJ_NULL ) {
93
109
if (!displayio_tilegrid_get_previous_area (layer , & layer_area )) {
94
110
continue ;
95
111
}
96
- } else if (MP_OBJ_IS_TYPE (layer , & displayio_group_type )) {
97
- if (!displayio_group_get_previous_area (layer , & layer_area )) {
98
- continue ;
112
+ } else {
113
+ layer = mp_instance_cast_to_native_base (
114
+ self -> children [i ].original , & displayio_group_type );
115
+ if (layer != MP_OBJ_NULL ) {
116
+ if (!displayio_group_get_previous_area (layer , & layer_area )) {
117
+ continue ;
118
+ }
99
119
}
100
120
}
101
121
if (first ) {
@@ -121,17 +141,26 @@ static void _update_child_transforms(displayio_group_t* self) {
121
141
return ;
122
142
}
123
143
for (size_t i = 0 ; i < self -> size ; i ++ ) {
124
- mp_obj_t layer = self -> children [ i ]. native ;
144
+ mp_obj_t layer ;
125
145
#if CIRCUITPY_VECTORIO
126
- if (MP_OBJ_IS_TYPE (layer , & vectorio_vector_shape_type )) {
146
+ layer = mp_instance_cast_to_native_base (
147
+ self -> children [i ].original , & vectorio_vector_shape_type );
148
+ if (layer != MP_OBJ_NULL ) {
127
149
vectorio_vector_shape_update_transform (layer , & self -> absolute_transform );
150
+ continue ;
128
151
}
129
- else
130
152
#endif
131
- if (MP_OBJ_IS_TYPE (layer , & displayio_tilegrid_type )) {
153
+ layer = mp_instance_cast_to_native_base (
154
+ self -> children [i ].original , & displayio_tilegrid_type );
155
+ if (layer != MP_OBJ_NULL ) {
132
156
displayio_tilegrid_update_transform (layer , & self -> absolute_transform );
133
- } else if (MP_OBJ_IS_TYPE (layer , & displayio_group_type )) {
157
+ continue ;
158
+ }
159
+ layer = mp_instance_cast_to_native_base (
160
+ self -> children [i ].original , & displayio_group_type );
161
+ if (layer != MP_OBJ_NULL ) {
134
162
displayio_group_update_transform (layer , & self -> absolute_transform );
163
+ continue ;
135
164
}
136
165
}
137
166
}
@@ -210,57 +239,63 @@ void common_hal_displayio_group_set_y(displayio_group_t* self, mp_int_t y) {
210
239
_update_child_transforms (self );
211
240
}
212
241
213
- static mp_obj_t _add_layer (displayio_group_t * self , mp_obj_t layer ) {
242
+ static void _add_layer (displayio_group_t * self , mp_obj_t layer ) {
214
243
mp_obj_t native_layer ;
215
244
#if CIRCUITPY_VECTORIO
216
245
native_layer = mp_instance_cast_to_native_base (layer , & vectorio_vector_shape_type );
217
246
if (native_layer != MP_OBJ_NULL ) {
218
247
vectorio_vector_shape_update_transform (native_layer , & self -> absolute_transform );
219
- return native_layer ;
248
+ return ;
220
249
}
221
250
#endif
222
- native_layer = mp_instance_cast_to_native_base (layer , & displayio_group_type );
223
- if (native_layer == MP_OBJ_NULL ) {
224
- native_layer = mp_instance_cast_to_native_base (layer , & displayio_tilegrid_type );
225
- if (native_layer == MP_OBJ_NULL ) {
226
- mp_raise_ValueError (translate ("Layer must be a Group or TileGrid subclass." ));
227
- }
251
+ native_layer = mp_instance_cast_to_native_base (layer , & displayio_tilegrid_type );
252
+ if (native_layer != MP_OBJ_NULL ) {
228
253
displayio_tilegrid_t * tilegrid = native_layer ;
229
254
if (tilegrid -> in_group ) {
230
255
mp_raise_ValueError (translate ("Layer already in a group." ));
231
256
} else {
232
257
tilegrid -> in_group = true;
233
258
}
234
259
displayio_tilegrid_update_transform (tilegrid , & self -> absolute_transform );
235
- } else {
260
+ return ;
261
+ }
262
+ native_layer = mp_instance_cast_to_native_base (layer , & displayio_group_type );
263
+ if (native_layer != MP_OBJ_NULL ) {
236
264
displayio_group_t * group = native_layer ;
237
265
if (group -> in_group ) {
238
266
mp_raise_ValueError (translate ("Layer already in a group." ));
239
267
} else {
240
268
group -> in_group = true;
241
269
}
242
270
displayio_group_update_transform (group , & self -> absolute_transform );
271
+ return ;
243
272
}
244
- return native_layer ;
273
+ mp_raise_ValueError ( translate ( "Layer must be a Group or TileGrid subclass." )) ;
245
274
}
246
275
247
276
static void _remove_layer (displayio_group_t * self , size_t index ) {
248
- mp_obj_t layer = self -> children [ index ]. native ;
277
+ mp_obj_t layer ;
249
278
displayio_area_t layer_area ;
250
279
bool rendered_last_frame = false;
251
280
#if CIRCUITPY_VECTORIO
252
- if (MP_OBJ_IS_TYPE (layer , & vectorio_vector_shape_type )) {
281
+ layer = mp_instance_cast_to_native_base (
282
+ self -> children [index ].original , & vectorio_vector_shape_type );
283
+ if (layer != MP_OBJ_NULL ) {
253
284
bool has_dirty_area = vectorio_vector_shape_get_dirty_area (layer , & layer_area );
254
285
rendered_last_frame = has_dirty_area ;
255
286
vectorio_vector_shape_update_transform (layer , NULL );
256
287
}
257
- else
258
288
#endif
259
- if (MP_OBJ_IS_TYPE (layer , & displayio_tilegrid_type )) {
289
+ layer = mp_instance_cast_to_native_base (
290
+ self -> children [index ].original , & displayio_tilegrid_type );
291
+ if (layer != MP_OBJ_NULL ) {
260
292
displayio_tilegrid_t * tilegrid = layer ;
261
293
rendered_last_frame = displayio_tilegrid_get_previous_area (tilegrid , & layer_area );
262
294
displayio_tilegrid_update_transform (tilegrid , NULL );
263
- } else if (MP_OBJ_IS_TYPE (layer , & displayio_group_type )) {
295
+ }
296
+ layer = mp_instance_cast_to_native_base (
297
+ self -> children [index ].original , & displayio_group_type );
298
+ if (layer != MP_OBJ_NULL ) {
264
299
displayio_group_t * group = layer ;
265
300
rendered_last_frame = displayio_group_get_previous_area (group , & layer_area );
266
301
displayio_group_update_transform (group , NULL );
@@ -280,12 +315,11 @@ void common_hal_displayio_group_insert(displayio_group_t* self, size_t index, mp
280
315
if (self -> size == self -> max_size ) {
281
316
mp_raise_RuntimeError (translate ("Group full" ));
282
317
}
283
- mp_obj_t native_layer = _add_layer (self , layer );
318
+ _add_layer (self , layer );
284
319
// Shift everything right.
285
320
for (size_t i = self -> size ; i > index ; i -- ) {
286
321
self -> children [i ] = self -> children [i - 1 ];
287
322
}
288
- self -> children [index ].native = native_layer ;
289
323
self -> children [index ].original = layer ;
290
324
self -> size ++ ;
291
325
}
@@ -299,7 +333,6 @@ mp_obj_t common_hal_displayio_group_pop(displayio_group_t* self, size_t index) {
299
333
for (size_t i = index ; i < self -> size ; i ++ ) {
300
334
self -> children [i ] = self -> children [i + 1 ];
301
335
}
302
- self -> children [self -> size ].native = NULL ;
303
336
self -> children [self -> size ].original = NULL ;
304
337
return item ;
305
338
}
@@ -322,9 +355,8 @@ mp_obj_t common_hal_displayio_group_get(displayio_group_t* self, size_t index) {
322
355
}
323
356
324
357
void common_hal_displayio_group_set (displayio_group_t * self , size_t index , mp_obj_t layer ) {
325
- mp_obj_t native_layer = _add_layer (self , layer );
358
+ _add_layer (self , layer );
326
359
_remove_layer (self , index );
327
- self -> children [index ].native = native_layer ;
328
360
self -> children [index ].original = layer ;
329
361
}
330
362
@@ -341,47 +373,61 @@ void displayio_group_construct(displayio_group_t* self, displayio_group_child_t*
341
373
bool displayio_group_fill_area (displayio_group_t * self , const _displayio_colorspace_t * colorspace , const displayio_area_t * area , uint32_t * mask , uint32_t * buffer ) {
342
374
// Track if any of the layers finishes filling in the given area. We can ignore any remaining
343
375
// layers at that point.
344
- bool full_coverage = false;
345
376
for (int32_t i = self -> size - 1 ; i >= 0 ; i -- ) {
346
- mp_obj_t layer = self -> children [ i ]. native ;
377
+ mp_obj_t layer ;
347
378
#if CIRCUITPY_VECTORIO
348
- if (MP_OBJ_IS_TYPE (layer , & vectorio_vector_shape_type )) {
379
+ layer = mp_instance_cast_to_native_base (
380
+ self -> children [i ].original , & vectorio_vector_shape_type );
381
+ if (layer != MP_OBJ_NULL ) {
349
382
if (vectorio_vector_shape_fill_area (layer , colorspace , area , mask , buffer )) {
350
- full_coverage = true;
351
- break ;
383
+ return true;
352
384
}
385
+ continue ;
353
386
}
354
- else
355
387
#endif
356
- if (MP_OBJ_IS_TYPE (layer , & displayio_tilegrid_type )) {
388
+ layer = mp_instance_cast_to_native_base (
389
+ self -> children [i ].original , & displayio_tilegrid_type );
390
+ if (layer != MP_OBJ_NULL ) {
357
391
if (displayio_tilegrid_fill_area (layer , colorspace , area , mask , buffer )) {
358
- full_coverage = true;
359
- break ;
392
+ return true;
360
393
}
361
- } else if (MP_OBJ_IS_TYPE (layer , & displayio_group_type )) {
394
+ continue ;
395
+ }
396
+ layer = mp_instance_cast_to_native_base (
397
+ self -> children [i ].original , & displayio_group_type );
398
+ if (layer != MP_OBJ_NULL ) {
362
399
if (displayio_group_fill_area (layer , colorspace , area , mask , buffer )) {
363
- full_coverage = true;
364
- break ;
400
+ return true;
365
401
}
402
+ continue ;
366
403
}
367
404
}
368
- return full_coverage ;
405
+ return false ;
369
406
}
370
407
371
408
void displayio_group_finish_refresh (displayio_group_t * self ) {
372
409
self -> item_removed = false;
373
410
for (int32_t i = self -> size - 1 ; i >= 0 ; i -- ) {
374
- mp_obj_t layer = self -> children [ i ]. native ;
411
+ mp_obj_t layer ;
375
412
#if CIRCUITPY_VECTORIO
376
- if (MP_OBJ_IS_TYPE (layer , & vectorio_vector_shape_type )) {
413
+ layer = mp_instance_cast_to_native_base (
414
+ self -> children [i ].original , & vectorio_vector_shape_type );
415
+ if (layer != MP_OBJ_NULL ) {
377
416
vectorio_vector_shape_finish_refresh (layer );
417
+ continue ;
378
418
}
379
- else
380
419
#endif
381
- if (MP_OBJ_IS_TYPE (layer , & displayio_tilegrid_type )) {
420
+ layer = mp_instance_cast_to_native_base (
421
+ self -> children [i ].original , & displayio_tilegrid_type );
422
+ if (layer != MP_OBJ_NULL ) {
382
423
displayio_tilegrid_finish_refresh (layer );
383
- } else if (MP_OBJ_IS_TYPE (layer , & displayio_group_type )) {
424
+ continue ;
425
+ }
426
+ layer = mp_instance_cast_to_native_base (
427
+ self -> children [i ].original , & displayio_group_type );
428
+ if (layer != MP_OBJ_NULL ) {
384
429
displayio_group_finish_refresh (layer );
430
+ continue ;
385
431
}
386
432
}
387
433
}
@@ -393,17 +439,26 @@ displayio_area_t* displayio_group_get_refresh_areas(displayio_group_t *self, dis
393
439
}
394
440
395
441
for (int32_t i = self -> size - 1 ; i >= 0 ; i -- ) {
396
- mp_obj_t layer = self -> children [ i ]. native ;
442
+ mp_obj_t layer ;
397
443
#if CIRCUITPY_VECTORIO
398
- if (MP_OBJ_IS_TYPE (layer , & vectorio_vector_shape_type )) {
444
+ layer = mp_instance_cast_to_native_base (
445
+ self -> children [i ].original , & vectorio_vector_shape_type );
446
+ if (layer != MP_OBJ_NULL ) {
399
447
tail = vectorio_vector_shape_get_refresh_areas (layer , tail );
448
+ continue ;
400
449
}
401
- else
402
450
#endif
403
- if (MP_OBJ_IS_TYPE (layer , & displayio_tilegrid_type )) {
451
+ layer = mp_instance_cast_to_native_base (
452
+ self -> children [i ].original , & displayio_tilegrid_type );
453
+ if (layer != MP_OBJ_NULL ) {
404
454
tail = displayio_tilegrid_get_refresh_areas (layer , tail );
405
- } else if (MP_OBJ_IS_TYPE (layer , & displayio_group_type )) {
455
+ continue ;
456
+ }
457
+ layer = mp_instance_cast_to_native_base (
458
+ self -> children [i ].original , & displayio_group_type );
459
+ if (layer != MP_OBJ_NULL ) {
406
460
tail = displayio_group_get_refresh_areas (layer , tail );
461
+ continue ;
407
462
}
408
463
}
409
464
0 commit comments