adding bitmap property to TileGrid

This commit is contained in:
foamyguy 2022-04-09 11:26:36 -05:00
parent 1f5744377c
commit 16b81c855d
4 changed files with 50 additions and 1 deletions

View File

@ -2717,6 +2717,11 @@ msgstr ""
msgid "binary op %q not implemented"
msgstr ""
#: shared-bindings/displayio/TileGrid.c
msgid ""
"bitmap must be displayio.Bitmap, displayio.Shape, or displayio.OnDiskBitmap"
msgstr ""
#: shared-bindings/bitmaptools/__init__.c
msgid "bitmap sizes must match"
msgstr ""

View File

@ -379,6 +379,37 @@ const mp_obj_property_t displayio_tilegrid_pixel_shader_obj = {
MP_ROM_NONE},
};
//| bitmap: Union[Bitmap,OnDiskBitmap,Shape]
//| """The bitmap of the tilegrid."""
//|
STATIC mp_obj_t displayio_tilegrid_obj_get_bitmap(mp_obj_t self_in) {
displayio_tilegrid_t *self = native_tilegrid(self_in);
return common_hal_displayio_tilegrid_get_bitmap(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_tilegrid_get_bitmap_obj, displayio_tilegrid_obj_get_bitmap);
STATIC mp_obj_t displayio_tilegrid_obj_set_bitmap(mp_obj_t self_in, mp_obj_t bitmap) {
displayio_tilegrid_t *self = native_tilegrid(self_in);
if (!mp_obj_is_type(bitmap, &displayio_bitmap_type) &&
!mp_obj_is_type(bitmap, &displayio_ondiskbitmap_type) &&
!mp_obj_is_type(bitmap, &displayio_shape_type)) {
mp_raise_TypeError(translate("bitmap must be displayio.Bitmap, displayio.Shape, or displayio.OnDiskBitmap"));
}
common_hal_displayio_tilegrid_set_bitmap(self, bitmap);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_tilegrid_set_bitmap_obj, displayio_tilegrid_obj_set_bitmap);
const mp_obj_property_t displayio_tilegrid_bitmap_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_tilegrid_get_bitmap_obj,
(mp_obj_t)&displayio_tilegrid_set_bitmap_obj,
MP_ROM_NONE},
};
//| def __getitem__(self, index: Union[Tuple[int, int], int]) -> int:
//| """Returns the tile index at the given index. The index can either be an x,y tuple or an int equal
//| to ``y * width + x``.
@ -454,7 +485,8 @@ STATIC const mp_rom_map_elem_t displayio_tilegrid_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_flip_x), MP_ROM_PTR(&displayio_tilegrid_flip_x_obj) },
{ MP_ROM_QSTR(MP_QSTR_flip_y), MP_ROM_PTR(&displayio_tilegrid_flip_y_obj) },
{ MP_ROM_QSTR(MP_QSTR_transpose_xy), MP_ROM_PTR(&displayio_tilegrid_transpose_xy_obj) },
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&displayio_tilegrid_pixel_shader_obj) },
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&displayio_tilegrid_pixel_shader_obj) },
{ MP_ROM_QSTR(MP_QSTR_bitmap), MP_ROM_PTR(&displayio_tilegrid_bitmap_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_tilegrid_locals_dict, displayio_tilegrid_locals_dict_table);

View File

@ -45,6 +45,9 @@ void common_hal_displayio_tilegrid_set_y(displayio_tilegrid_t *self, mp_int_t y)
mp_obj_t common_hal_displayio_tilegrid_get_pixel_shader(displayio_tilegrid_t *self);
void common_hal_displayio_tilegrid_set_pixel_shader(displayio_tilegrid_t *self, mp_obj_t pixel_shader);
mp_obj_t common_hal_displayio_tilegrid_get_bitmap(displayio_tilegrid_t *self);
void common_hal_displayio_tilegrid_set_bitmap(displayio_tilegrid_t *self, mp_obj_t bitmap);
bool common_hal_displayio_tilegrid_get_flip_x(displayio_tilegrid_t *self);
void common_hal_displayio_tilegrid_set_flip_x(displayio_tilegrid_t *self, bool flip_x);

View File

@ -221,6 +221,15 @@ void common_hal_displayio_tilegrid_set_pixel_shader(displayio_tilegrid_t *self,
self->full_change = true;
}
mp_obj_t common_hal_displayio_tilegrid_get_bitmap(displayio_tilegrid_t *self) {
return self->bitmap;
}
void common_hal_displayio_tilegrid_set_bitmap(displayio_tilegrid_t *self, mp_obj_t bitmap) {
self->bitmap = bitmap;
self->full_change = true;
}
uint16_t common_hal_displayio_tilegrid_get_width(displayio_tilegrid_t *self) {
return self->width_in_tiles;
}