Skip to content

Commit 65f0857

Browse files
committed
back to not using function
1 parent cea55cd commit 65f0857

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

shared-bindings/displayio/TileGrid.c

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ static displayio_tilegrid_t *native_tilegrid(mp_obj_t tilegrid_obj) {
145145
return MP_OBJ_TO_PTR(native_tilegrid);
146146
}
147147

148+
/*
148149
static void enforce_bitmap_size(mp_obj_t self_in, mp_obj_t bitmap) {
149150
displayio_tilegrid_t *self = native_tilegrid(self_in);
150151
uint16_t bitmap_width;
@@ -182,6 +183,7 @@ static void enforce_bitmap_size(mp_obj_t self_in, mp_obj_t bitmap) {
182183
mp_raise_ValueError(translate("Tile height must exactly divide bitmap height"));
183184
}
184185
}
186+
*/
185187

186188
//| hidden: bool
187189
//| """True when the TileGrid is hidden. This may be False even when a part of a hidden Group."""
@@ -443,7 +445,71 @@ STATIC mp_obj_t displayio_tilegrid_obj_set_bitmap(mp_obj_t self_in, mp_obj_t bit
443445
if (bitmap->height % self->tile_height != 0) {
444446
mp_raise_ValueError(translate("Tile height must exactly divide bitmap height"));
445447
}*/
446-
enforce_bitmap_size(self_in, bitmap);
448+
// enforce_bitmap_size(self_in, bitmap);
449+
450+
uint16_t bitmap_width;
451+
uint16_t bitmap_height;
452+
mp_obj_t native = mp_obj_cast_to_native_base(bitmap, &displayio_shape_type);
453+
if (native != MP_OBJ_NULL) {
454+
displayio_shape_t *bmp = MP_OBJ_TO_PTR(native);
455+
bitmap_width = bmp->width;
456+
bitmap_height = bmp->height;
457+
} else if (mp_obj_is_type(bitmap, &displayio_bitmap_type)) {
458+
displayio_bitmap_t *bmp = MP_OBJ_TO_PTR(bitmap);
459+
native = bitmap;
460+
bitmap_width = bmp->width;
461+
bitmap_height = bmp->height;
462+
} else if (mp_obj_is_type(bitmap, &displayio_ondiskbitmap_type)) {
463+
displayio_ondiskbitmap_t *bmp = MP_OBJ_TO_PTR(bitmap);
464+
native = bitmap;
465+
bitmap_width = bmp->width;
466+
bitmap_height = bmp->height;
467+
} else {
468+
mp_raise_TypeError_varg(translate("unsupported %q type"), MP_QSTR_bitmap);
469+
}
470+
471+
uint16_t tile_width = self->tile_width;
472+
uint16_t tile_height = self->tile_height;
473+
mp_obj_t old_native = mp_obj_cast_to_native_base(self->bitmap, &displayio_shape_type);
474+
if (old_native != MP_OBJ_NULL) {
475+
displayio_shape_t *old_bmp = MP_OBJ_TO_PTR(old_native);
476+
if (tile_width == old_bmp->width) {
477+
self->tile_width = bitmap_width;
478+
}
479+
if (tile_height == old_bmp->width) {
480+
self->tile_height = bitmap_height;
481+
}
482+
483+
} else if (mp_obj_is_type(self->bitmap, &displayio_bitmap_type)) {
484+
displayio_bitmap_t *old_bmp = MP_OBJ_TO_PTR(self->bitmap);
485+
old_native = self->bitmap;
486+
if (tile_width == old_bmp->width) {
487+
self->tile_width = bitmap_width;
488+
}
489+
if (tile_height == old_bmp->width) {
490+
self->tile_height = bitmap_height;
491+
}
492+
493+
} else if (mp_obj_is_type(self->bitmap, &displayio_ondiskbitmap_type)) {
494+
displayio_ondiskbitmap_t *old_bmp = MP_OBJ_TO_PTR(self->bitmap);
495+
old_native = self->bitmap;
496+
if (tile_width == old_bmp->width) {
497+
self->tile_width = bitmap_width;
498+
}
499+
if (tile_height == old_bmp->width) {
500+
self->tile_height = bitmap_height;
501+
}
502+
}
503+
504+
505+
506+
if (bitmap_width % tile_width != 0) {
507+
mp_raise_ValueError(translate("Tile width must exactly divide bitmap width"));
508+
}
509+
if (bitmap_height % tile_height != 0) {
510+
mp_raise_ValueError(translate("Tile height must exactly divide bitmap height"));
511+
}
512+
447513

448514
common_hal_displayio_tilegrid_set_bitmap(self, bitmap);
449515

0 commit comments

Comments
 (0)