back to not using function

This commit is contained in:
foamyguy 2022-04-18 10:25:49 -05:00
parent cea55cde9f
commit 65f085709c
1 changed files with 67 additions and 1 deletions

View File

@ -145,6 +145,7 @@ static displayio_tilegrid_t *native_tilegrid(mp_obj_t tilegrid_obj) {
return MP_OBJ_TO_PTR(native_tilegrid);
}
/*
static void enforce_bitmap_size(mp_obj_t self_in, mp_obj_t bitmap) {
displayio_tilegrid_t *self = native_tilegrid(self_in);
uint16_t bitmap_width;
@ -182,6 +183,7 @@ static void enforce_bitmap_size(mp_obj_t self_in, mp_obj_t bitmap) {
mp_raise_ValueError(translate("Tile height must exactly divide bitmap height"));
}
}
*/
//| hidden: bool
//| """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
if (bitmap->height % self->tile_height != 0) {
mp_raise_ValueError(translate("Tile height must exactly divide bitmap height"));
}*/
enforce_bitmap_size(self_in, bitmap);
// enforce_bitmap_size(self_in, bitmap);
uint16_t bitmap_width;
uint16_t bitmap_height;
mp_obj_t native = mp_obj_cast_to_native_base(bitmap, &displayio_shape_type);
if (native != MP_OBJ_NULL) {
displayio_shape_t *bmp = MP_OBJ_TO_PTR(native);
bitmap_width = bmp->width;
bitmap_height = bmp->height;
} else if (mp_obj_is_type(bitmap, &displayio_bitmap_type)) {
displayio_bitmap_t *bmp = MP_OBJ_TO_PTR(bitmap);
native = bitmap;
bitmap_width = bmp->width;
bitmap_height = bmp->height;
} else if (mp_obj_is_type(bitmap, &displayio_ondiskbitmap_type)) {
displayio_ondiskbitmap_t *bmp = MP_OBJ_TO_PTR(bitmap);
native = bitmap;
bitmap_width = bmp->width;
bitmap_height = bmp->height;
} else {
mp_raise_TypeError_varg(translate("unsupported %q type"), MP_QSTR_bitmap);
}
uint16_t tile_width = self->tile_width;
uint16_t tile_height = self->tile_height;
mp_obj_t old_native = mp_obj_cast_to_native_base(self->bitmap, &displayio_shape_type);
if (old_native != MP_OBJ_NULL) {
displayio_shape_t *old_bmp = MP_OBJ_TO_PTR(old_native);
if (tile_width == old_bmp->width) {
self->tile_width = bitmap_width;
}
if (tile_height == old_bmp->width) {
self->tile_height = bitmap_height;
}
} else if (mp_obj_is_type(self->bitmap, &displayio_bitmap_type)) {
displayio_bitmap_t *old_bmp = MP_OBJ_TO_PTR(self->bitmap);
old_native = self->bitmap;
if (tile_width == old_bmp->width) {
self->tile_width = bitmap_width;
}
if (tile_height == old_bmp->width) {
self->tile_height = bitmap_height;
}
} else if (mp_obj_is_type(self->bitmap, &displayio_ondiskbitmap_type)) {
displayio_ondiskbitmap_t *old_bmp = MP_OBJ_TO_PTR(self->bitmap);
old_native = self->bitmap;
if (tile_width == old_bmp->width) {
self->tile_width = bitmap_width;
}
if (tile_height == old_bmp->width) {
self->tile_height = bitmap_height;
}
}
if (bitmap_width % tile_width != 0) {
mp_raise_ValueError(translate("Tile width must exactly divide bitmap width"));
}
if (bitmap_height % tile_height != 0) {
mp_raise_ValueError(translate("Tile height must exactly divide bitmap height"));
}
common_hal_displayio_tilegrid_set_bitmap(self, bitmap);