summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-01-14 13:56:04 -0800
committerScott Shawcroft <scott@tannewt.org>2019-01-14 17:29:18 -0800
commit619bc4caae15ceb7b6de547a5264c9eca9086fe9 (patch)
treed5f2ba70cfe276a41f287eddc2245f3fc0988c3e /shared-bindings
parenta14762a16ca6e60fc2d26f028a08bcced597553b (diff)
Support subclasses of Shape as bitmaps.
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/displayio/Sprite.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/shared-bindings/displayio/Sprite.c b/shared-bindings/displayio/Sprite.c
index e739b48b7..8aa9586ea 100644
--- a/shared-bindings/displayio/Sprite.c
+++ b/shared-bindings/displayio/Sprite.c
@@ -86,16 +86,19 @@ STATIC mp_obj_t displayio_sprite_make_new(const mp_obj_type_t *type, size_t n_ar
uint16_t width;
uint16_t height;
- if (MP_OBJ_IS_TYPE(bitmap, &displayio_bitmap_type)) {
+ mp_obj_t native = mp_instance_cast_to_native_base(bitmap, &displayio_shape_type);
+ if (native != MP_OBJ_NULL) {
+ displayio_shape_t* bmp = MP_OBJ_TO_PTR(native);
+ width = bmp->width;
+ height = bmp->height;
+ } else if (MP_OBJ_IS_TYPE(bitmap, &displayio_bitmap_type)) {
displayio_bitmap_t* bmp = MP_OBJ_TO_PTR(bitmap);
+ native = bitmap;
width = bmp->width;
height = bmp->height;
} else if (MP_OBJ_IS_TYPE(bitmap, &displayio_ondiskbitmap_type)) {
displayio_ondiskbitmap_t* bmp = MP_OBJ_TO_PTR(bitmap);
- width = bmp->width;
- height = bmp->height;
- } else if (MP_OBJ_IS_TYPE(bitmap, &displayio_shape_type)) {
- displayio_shape_t* bmp = MP_OBJ_TO_PTR(bitmap);
+ native = bitmap;
width = bmp->width;
height = bmp->height;
} else {
@@ -108,7 +111,7 @@ STATIC mp_obj_t displayio_sprite_make_new(const mp_obj_type_t *type, size_t n_ar
displayio_sprite_t *self = m_new_obj(displayio_sprite_t);
self->base.type = &displayio_sprite_type;
- common_hal_displayio_sprite_construct(self, bitmap, args[ARG_pixel_shader].u_obj,
+ common_hal_displayio_sprite_construct(self, native, args[ARG_pixel_shader].u_obj,
width, height, x, y);
return MP_OBJ_FROM_PTR(self);
}