summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Matocha <kmatocha@icloud.com>2021-03-16 20:43:23 -0500
committerKevin Matocha <kmatocha@icloud.com>2021-03-16 20:43:23 -0500
commit5c3cce6f5d8ca15aeef486f903da6531f5d53ba5 (patch)
treecb8eb7d529f62addb16355a9904670ea279ff128
parent75ba26ee7c74cded73985212075c6eb4d8071af4 (diff)
add is_transparent getter to displayio.Palette
-rw-r--r--shared-bindings/displayio/Palette.c18
-rw-r--r--shared-bindings/displayio/Palette.h1
-rw-r--r--shared-module/displayio/Palette.c4
3 files changed, 22 insertions, 1 deletions
diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c
index d5acf1ed6..01c700070 100644
--- a/shared-bindings/displayio/Palette.c
+++ b/shared-bindings/displayio/Palette.c
@@ -84,7 +84,7 @@ STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
}
//| def __getitem__(self, index: int) -> Optional[int]:
-//| r"""Return the pixel color at the given index as an integer."""
+//| """Return the pixel color at the given index as an integer."""
//| ...
//|
//| def __setitem__(self, index: int, value: Union[int, ReadableBuffer, Tuple[int, int, int]]) -> None:
@@ -180,9 +180,25 @@ STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t pal
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_make_opaque_obj, displayio_palette_obj_make_opaque);
+//| def is_transparent(self, palette_index: int) -> bool:
+//| """Returns `True` if the palette index is transparent. Returns `False` if opaque."""
+//| ...
+//|
+STATIC mp_obj_t displayio_palette_obj_is_transparent(mp_obj_t self_in, mp_obj_t palette_index_obj) {
+ displayio_palette_t *self = MP_OBJ_TO_PTR(self_in);
+
+ mp_int_t palette_index;
+ if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) {
+ mp_raise_ValueError(translate("palette_index should be an int"));
+ }
+ return mp_obj_new_bool(common_hal_displayio_palette_is_transparent(self, palette_index));
+}
+MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_is_transparent_obj, displayio_palette_obj_is_transparent);
+
STATIC const mp_rom_map_elem_t displayio_palette_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_make_transparent), MP_ROM_PTR(&displayio_palette_make_transparent_obj) },
{ MP_ROM_QSTR(MP_QSTR_make_opaque), MP_ROM_PTR(&displayio_palette_make_opaque_obj) },
+ { MP_ROM_QSTR(MP_QSTR_is_transparent), MP_ROM_PTR(&displayio_palette_is_transparent_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_palette_locals_dict, displayio_palette_locals_dict_table);
diff --git a/shared-bindings/displayio/Palette.h b/shared-bindings/displayio/Palette.h
index 62b8f3600..d9a798016 100644
--- a/shared-bindings/displayio/Palette.h
+++ b/shared-bindings/displayio/Palette.h
@@ -38,5 +38,6 @@ uint32_t common_hal_displayio_palette_get_len(displayio_palette_t *self);
void common_hal_displayio_palette_make_opaque(displayio_palette_t *self, uint32_t palette_index);
void common_hal_displayio_palette_make_transparent(displayio_palette_t *self, uint32_t palette_index);
+bool common_hal_displayio_palette_is_transparent(displayio_palette_t *self, uint32_t palette_index);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_PALETTE_H
diff --git a/shared-module/displayio/Palette.c b/shared-module/displayio/Palette.c
index 6dde3a80f..9b6374ac3 100644
--- a/shared-module/displayio/Palette.c
+++ b/shared-module/displayio/Palette.c
@@ -43,6 +43,10 @@ void common_hal_displayio_palette_make_transparent(displayio_palette_t *self, ui
self->needs_refresh = true;
}
+bool common_hal_displayio_palette_is_transparent(displayio_palette_t *self, uint32_t palette_index) {
+ return self->colors[palette_index].transparent;
+}
+
uint32_t common_hal_displayio_palette_get_len(displayio_palette_t *self) {
return self->color_count;
}