summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-01-29 15:04:07 -0800
committerScott Shawcroft <scott@tannewt.org>2019-01-31 11:42:14 -0800
commit601a910f4eb83cf1ae7516a25c011b469ac76b8b (patch)
tree54b8921c1f6efb0826fe9c011956d79dbfb292f5 /shared-bindings
parent6145f08cc89946d138737b149d390265def67077 (diff)
More improvements to Terminal:
* Fix Hallowing. * Fix builds without displayio. * Fix y bounds that appears as untrollable row of pixels. * Add scrolling to TileGrid. * Remove Sprite to save space. TileGrid is a drop in replacement.
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/displayio/Sprite.c195
-rw-r--r--shared-bindings/displayio/Sprite.h43
-rw-r--r--shared-bindings/displayio/TileGrid.h1
-rw-r--r--shared-bindings/displayio/__init__.c1
4 files changed, 1 insertions, 239 deletions
diff --git a/shared-bindings/displayio/Sprite.c b/shared-bindings/displayio/Sprite.c
deleted file mode 100644
index 864ecc959..000000000
--- a/shared-bindings/displayio/Sprite.c
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * This file is part of the Micro Python project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "shared-bindings/displayio/Sprite.h"
-
-#include <stdint.h>
-
-#include "lib/utils/context_manager_helpers.h"
-#include "py/binary.h"
-#include "py/objproperty.h"
-#include "py/runtime.h"
-#include "shared-bindings/displayio/Bitmap.h"
-#include "shared-bindings/displayio/ColorConverter.h"
-#include "shared-bindings/displayio/OnDiskBitmap.h"
-#include "shared-bindings/displayio/Palette.h"
-#include "shared-bindings/displayio/Shape.h"
-#include "supervisor/shared/translate.h"
-
-static void unpack_position(mp_obj_t position_obj, int16_t* x, int16_t* y) {
- // TODO(tannewt): Support any value sequence such as bytearray or bytes.
- mp_obj_tuple_t *position = MP_OBJ_TO_PTR(position_obj);
- if (MP_OBJ_IS_TYPE(position_obj, &mp_type_tuple) && position->len == 2) {
- *x = mp_obj_get_int(position->items[0]);
- *y = mp_obj_get_int(position->items[1]);
- } else if (position != mp_const_none) {
- mp_raise_TypeError(translate("position must be 2-tuple"));
- }
-}
-
-//| .. currentmodule:: displayio
-//|
-//| :class:`Sprite` -- A particular copy of an image to display
-//| ==========================================================================
-//|
-//| Position a particular image and pixel_shader combination. Multiple sprites can share bitmaps
-//| pixel shaders.
-//|
-//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
-//|
-//| .. class:: Sprite(bitmap, *, pixel_shader, position, width, height)
-//|
-//| Create a Sprite object. The bitmap is source for 2d pixels. The pixel_shader is used to
-//| convert the value and its location to a display native pixel color. This may be a simple color
-//| palette lookup, a gradient, a pattern or a color transformer.
-//|
-//|
-STATIC mp_obj_t displayio_sprite_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
- enum { ARG_bitmap, ARG_pixel_shader, ARG_position, ARG_width, ARG_height };
- static const mp_arg_t allowed_args[] = {
- { MP_QSTR_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ },
- { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY },
- { MP_QSTR_position, MP_ARG_OBJ | MP_ARG_KW_ONLY },
- { MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
- { MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
- };
- mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
- mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
-
- mp_obj_t bitmap = args[ARG_bitmap].u_obj;
-
- uint16_t width;
- uint16_t height;
- 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);
- native = bitmap;
- width = bmp->width;
- height = bmp->height;
- } else {
- mp_raise_TypeError(translate("unsupported bitmap type"));
- }
- int16_t x = 0;
- int16_t y = 0;
- mp_obj_t position_obj = args[ARG_position].u_obj;
- unpack_position(position_obj, &x, &y);
-
- displayio_sprite_t *self = m_new_obj(displayio_sprite_t);
- self->base.type = &displayio_sprite_type;
- common_hal_displayio_sprite_construct(self, native, args[ARG_pixel_shader].u_obj,
- width, height, x, y);
- return MP_OBJ_FROM_PTR(self);
-}
-
-//| .. attribute:: position
-//|
-//| The position of the top-left corner of the sprite.
-//|
-STATIC mp_obj_t displayio_sprite_obj_get_position(mp_obj_t self_in) {
- displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
- int16_t x;
- int16_t y;
- common_hal_displayio_sprite_get_position(self, &x, &y);
-
- mp_obj_t coords[2];
- coords[0] = mp_obj_new_int(x);
- coords[1] = mp_obj_new_int(y);
-
- return mp_obj_new_tuple(2, coords);
-}
-MP_DEFINE_CONST_FUN_OBJ_1(displayio_sprite_get_position_obj, displayio_sprite_obj_get_position);
-
-STATIC mp_obj_t displayio_sprite_obj_set_position(mp_obj_t self_in, mp_obj_t value) {
- displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
-
- int16_t x = 0;
- int16_t y = 0;
- unpack_position(value, &x, &y);
-
- common_hal_displayio_sprite_set_position(self, x, y);
-
- return mp_const_none;
-}
-MP_DEFINE_CONST_FUN_OBJ_2(displayio_sprite_set_position_obj, displayio_sprite_obj_set_position);
-
-const mp_obj_property_t displayio_sprite_position_obj = {
- .base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&displayio_sprite_get_position_obj,
- (mp_obj_t)&displayio_sprite_set_position_obj,
- (mp_obj_t)&mp_const_none_obj},
-};
-
-//| .. attribute:: pixel_shader
-//|
-//| The pixel shader of the sprite.
-//|
-STATIC mp_obj_t displayio_sprite_obj_get_pixel_shader(mp_obj_t self_in) {
- displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
- return common_hal_displayio_sprite_get_pixel_shader(self);
-}
-MP_DEFINE_CONST_FUN_OBJ_1(displayio_sprite_get_pixel_shader_obj, displayio_sprite_obj_get_pixel_shader);
-
-STATIC mp_obj_t displayio_sprite_obj_set_pixel_shader(mp_obj_t self_in, mp_obj_t pixel_shader) {
- displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
- if (!MP_OBJ_IS_TYPE(pixel_shader, &displayio_palette_type) && !MP_OBJ_IS_TYPE(pixel_shader, &displayio_colorconverter_type)) {
- mp_raise_TypeError(translate("pixel_shader must be displayio.Palette or displayio.ColorConverter"));
- }
-
- common_hal_displayio_sprite_set_pixel_shader(self, pixel_shader);
-
- return mp_const_none;
-}
-MP_DEFINE_CONST_FUN_OBJ_2(displayio_sprite_set_pixel_shader_obj, displayio_sprite_obj_set_pixel_shader);
-
-const mp_obj_property_t displayio_sprite_pixel_shader_obj = {
- .base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&displayio_sprite_get_pixel_shader_obj,
- (mp_obj_t)&displayio_sprite_set_pixel_shader_obj,
- (mp_obj_t)&mp_const_none_obj},
-};
-
-STATIC const mp_rom_map_elem_t displayio_sprite_locals_dict_table[] = {
- // Properties
- { MP_ROM_QSTR(MP_QSTR_position), MP_ROM_PTR(&displayio_sprite_position_obj) },
- { MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&displayio_sprite_pixel_shader_obj) },
-};
-STATIC MP_DEFINE_CONST_DICT(displayio_sprite_locals_dict, displayio_sprite_locals_dict_table);
-
-const mp_obj_type_t displayio_sprite_type = {
- { &mp_type_type },
- .name = MP_QSTR_Sprite,
- .make_new = displayio_sprite_make_new,
- .locals_dict = (mp_obj_dict_t*)&displayio_sprite_locals_dict,
-};
diff --git a/shared-bindings/displayio/Sprite.h b/shared-bindings/displayio/Sprite.h
deleted file mode 100644
index 1944e1d74..000000000
--- a/shared-bindings/displayio/Sprite.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * This file is part of the Micro Python project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_SPRITE_H
-#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_SPRITE_H
-
-#include "shared-module/displayio/Sprite.h"
-
-extern const mp_obj_type_t displayio_sprite_type;
-
-void common_hal_displayio_sprite_construct(displayio_sprite_t *self, mp_obj_t bitmap,
- mp_obj_t pixel_shader, uint16_t width, uint16_t height, uint16_t x, uint16_t y);
-
-void common_hal_displayio_sprite_get_position(displayio_sprite_t *self, int16_t* x, int16_t* y);
-void common_hal_displayio_sprite_set_position(displayio_sprite_t *self, int16_t x, int16_t y);
-
-mp_obj_t common_hal_displayio_sprite_get_pixel_shader(displayio_sprite_t *self);
-void common_hal_displayio_sprite_set_pixel_shader(displayio_sprite_t *self, mp_obj_t pixel_shader);
-
-#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_SPRITE_H
diff --git a/shared-bindings/displayio/TileGrid.h b/shared-bindings/displayio/TileGrid.h
index a74fa4d39..2260db413 100644
--- a/shared-bindings/displayio/TileGrid.h
+++ b/shared-bindings/displayio/TileGrid.h
@@ -42,5 +42,6 @@ mp_obj_t common_hal_displayio_tilegrid_get_pixel_shader(displayio_tilegrid_t *se
void common_hal_displayio_tilegrid_set_pixel_shader(displayio_tilegrid_t *self, mp_obj_t pixel_shader);
void common_hal_displayio_textgrid_set_tile(displayio_tilegrid_t *self, uint16_t x, uint16_t y, uint8_t tile_index);
+void common_hal_displayio_textgrid_set_top_left(displayio_tilegrid_t *self, uint16_t x, uint16_t y);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_TILEGRID_H
diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c
index 749f21803..e164d9b8f 100644
--- a/shared-bindings/displayio/__init__.c
+++ b/shared-bindings/displayio/__init__.c
@@ -96,7 +96,6 @@ STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_OnDiskBitmap), MP_ROM_PTR(&displayio_ondiskbitmap_type) },
{ MP_ROM_QSTR(MP_QSTR_Palette), MP_ROM_PTR(&displayio_palette_type) },
{ MP_ROM_QSTR(MP_QSTR_Shape), MP_ROM_PTR(&displayio_shape_type) },
- { MP_ROM_QSTR(MP_QSTR_Sprite), MP_ROM_PTR(&displayio_sprite_type) },
{ MP_ROM_QSTR(MP_QSTR_TileGrid), MP_ROM_PTR(&displayio_tilegrid_type) },
{ MP_ROM_QSTR(MP_QSTR_FourWire), MP_ROM_PTR(&displayio_fourwire_type) },