From 57dee6406d890b31e29ec7fc35efbb9d0fc664df Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Thu, 7 Oct 2021 12:58:43 +0200 Subject: [PATCH] _stage: Fix handling of scaled display in the stage library The "scale" parameter wasn't exposed in the library, and there were some problems in how it was handled. This also fixes some types in the pixel-drawing functions. --- frozen/circuitpython-stage | 2 +- shared-module/_stage/Layer.c | 2 +- shared-module/_stage/Layer.h | 2 +- shared-module/_stage/Text.c | 2 +- shared-module/_stage/Text.h | 2 +- shared-module/_stage/__init__.c | 11 ++++++----- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/frozen/circuitpython-stage b/frozen/circuitpython-stage index d0f1c46d7f..ab28481aca 160000 --- a/frozen/circuitpython-stage +++ b/frozen/circuitpython-stage @@ -1 +1 @@ -Subproject commit d0f1c46d7f879cd60562ee69900d619499d4d206 +Subproject commit ab28481acaac4a38b3066bd90249ae6fcf4aeda5 diff --git a/shared-module/_stage/Layer.c b/shared-module/_stage/Layer.c index df2b27fa13..6d06e7261f 100644 --- a/shared-module/_stage/Layer.c +++ b/shared-module/_stage/Layer.c @@ -29,7 +29,7 @@ // Get the color of the pixel on the layer. -uint16_t get_layer_pixel(layer_obj_t *layer, uint16_t x, uint16_t y) { +uint16_t get_layer_pixel(layer_obj_t *layer, int16_t x, int16_t y) { // Shift by the layer's position offset. x -= layer->x; diff --git a/shared-module/_stage/Layer.h b/shared-module/_stage/Layer.h index 17d101263f..4233847641 100644 --- a/shared-module/_stage/Layer.h +++ b/shared-module/_stage/Layer.h @@ -43,6 +43,6 @@ typedef struct { uint8_t rotation; } layer_obj_t; -uint16_t get_layer_pixel(layer_obj_t *layer, uint16_t x, uint16_t y); +uint16_t get_layer_pixel(layer_obj_t *layer, int16_t x, int16_t y); #endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE_LAYER diff --git a/shared-module/_stage/Text.c b/shared-module/_stage/Text.c index 91223f5258..a803b85de4 100644 --- a/shared-module/_stage/Text.c +++ b/shared-module/_stage/Text.c @@ -29,7 +29,7 @@ // Get the color of the pixel on the text. -uint16_t get_text_pixel(text_obj_t *text, uint16_t x, uint16_t y) { +uint16_t get_text_pixel(text_obj_t *text, int16_t x, int16_t y) { // Shift by the text's position offset. x -= text->x; diff --git a/shared-module/_stage/Text.h b/shared-module/_stage/Text.h index b263fc7108..dd75465d17 100644 --- a/shared-module/_stage/Text.h +++ b/shared-module/_stage/Text.h @@ -41,6 +41,6 @@ typedef struct { uint8_t width, height; } text_obj_t; -uint16_t get_text_pixel(text_obj_t *text, uint16_t x, uint16_t y); +uint16_t get_text_pixel(text_obj_t *text, int16_t x, int16_t y); #endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE_TEXT diff --git a/shared-module/_stage/__init__.c b/shared-module/_stage/__init__.c index 06a12aa0a7..69f7812c0e 100644 --- a/shared-module/_stage/__init__.c +++ b/shared-module/_stage/__init__.c @@ -39,13 +39,14 @@ void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, displayio_area_t area; - area.x1 = x0; - area.y1 = y0; - area.x2 = x1; - area.y2 = y1; + area.x1 = x0 * scale; + area.y1 = y0 * scale; + area.x2 = x1 * scale; + area.y2 = y1 * scale; displayio_display_core_set_region_to_update( &display->core, display->set_column_command, display->set_row_command, - NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area, display->SH1107_addressing); + NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area, + display->SH1107_addressing); while (!displayio_display_core_begin_transaction(&display->core)) { RUN_BACKGROUND_TASKS;