_stage: use 16 bit for coordinates to support larger screens

This commit is contained in:
Radomir Dopieralski 2018-03-11 12:01:48 +01:00
parent dde5ade524
commit 493c1452f3
7 changed files with 12 additions and 15 deletions

View File

@ -71,10 +71,10 @@
//| This function is intended for internal use in the ``stage`` library //| This function is intended for internal use in the ``stage`` library
//| and all the necessary checks are performed there. //| and all the necessary checks are performed there.
STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) {
uint8_t x0 = mp_obj_get_int(args[0]); uint16_t x0 = mp_obj_get_int(args[0]);
uint8_t y0 = mp_obj_get_int(args[1]); uint16_t y0 = mp_obj_get_int(args[1]);
uint8_t x1 = mp_obj_get_int(args[2]); uint16_t x1 = mp_obj_get_int(args[2]);
uint8_t y1 = mp_obj_get_int(args[3]); uint16_t y1 = mp_obj_get_int(args[3]);
size_t layers_size = 0; size_t layers_size = 0;
mp_obj_t *layers; mp_obj_t *layers;

View File

@ -29,7 +29,7 @@
// Get the color of the pixel on the layer. // Get the color of the pixel on the layer.
uint16_t get_layer_pixel(layer_obj_t *layer, int16_t x, uint16_t y) { uint16_t get_layer_pixel(layer_obj_t *layer, uint16_t x, uint16_t y) {
// Shift by the layer's position offset. // Shift by the layer's position offset.
x -= layer->x; x -= layer->x;

View File

@ -43,6 +43,6 @@ typedef struct {
uint8_t rotation; uint8_t rotation;
} layer_obj_t; } layer_obj_t;
uint16_t get_layer_pixel(layer_obj_t *layer, int16_t x, uint16_t y); uint16_t get_layer_pixel(layer_obj_t *layer, uint16_t x, uint16_t y);
#endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE_LAYER #endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE_LAYER

View File

@ -29,7 +29,7 @@
// Get the color of the pixel on the text. // Get the color of the pixel on the text.
uint16_t get_text_pixel(text_obj_t *text, int16_t x, uint16_t y) { uint16_t get_text_pixel(text_obj_t *text, uint16_t x, uint16_t y) {
// Shift by the text's position offset. // Shift by the text's position offset.
x -= text->x; x -= text->x;

View File

@ -41,6 +41,6 @@ typedef struct {
uint8_t width, height; uint8_t width, height;
} text_obj_t; } text_obj_t;
uint16_t get_text_pixel(text_obj_t *text, int16_t x, uint16_t y); uint16_t get_text_pixel(text_obj_t *text, uint16_t x, uint16_t y);
#endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE_TEXT #endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE_TEXT

View File

@ -31,17 +31,14 @@
#include "shared-bindings/_stage/Text.h" #include "shared-bindings/_stage/Text.h"
bool render_stage(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
mp_obj_t *layers, size_t layers_size, mp_obj_t *layers, size_t layers_size,
uint16_t *buffer, size_t buffer_size, uint16_t *buffer, size_t buffer_size,
busio_spi_obj_t *spi) { busio_spi_obj_t *spi) {
// TODO(deshipu): Do a collision check of each layer with the
// rectangle, and only process the layers that overlap with it.
size_t index = 0; size_t index = 0;
for (uint8_t y = y0; y < y1; ++y) { for (uint16_t y = y0; y < y1; ++y) {
for (uint8_t x = x0; x < x1; ++x) { for (uint16_t x = x0; x < x1; ++x) {
for (size_t layer = 0; layer < layers_size; ++layer) { for (size_t layer = 0; layer < layers_size; ++layer) {
uint16_t c = TRANSPARENT; uint16_t c = TRANSPARENT;
layer_obj_t *obj = MP_OBJ_TO_PTR(layers[layer]); layer_obj_t *obj = MP_OBJ_TO_PTR(layers[layer]);

View File

@ -34,7 +34,7 @@
#define TRANSPARENT (0x1ff8) #define TRANSPARENT (0x1ff8)
bool render_stage(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
mp_obj_t *layers, size_t layers_size, mp_obj_t *layers, size_t layers_size,
uint16_t *buffer, size_t buffer_size, uint16_t *buffer, size_t buffer_size,
busio_spi_obj_t *spi); busio_spi_obj_t *spi);