Stage: add support for viewport scrolling

This commit is contained in:
Radomir Dopieralski 2021-10-09 00:05:49 +02:00
parent 6d2114bed7
commit caa3d3726f
4 changed files with 17 additions and 15 deletions

@ -1 +1 @@
Subproject commit 2b9b9f0a80810b0c4ff0feebbbe07312251de144
Subproject commit 2c89a329063848bcd7dba6af6fb6c9d6036dd4f2

View File

@ -81,21 +81,17 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) {
mp_raise_TypeError(translate("argument num/types mismatch"));
}
displayio_display_obj_t *display = MP_OBJ_TO_PTR(native_display);
uint8_t scale = 1;
if (n_args > 7) {
scale = mp_obj_get_int(args[7]);
}
uint8_t scale = mp_obj_get_int(args[7]);
int16_t vx = mp_obj_get_int(args[8]);
int16_t vy = mp_obj_get_int(args[9]);
uint16_t background = 0;
if (n_args > 8) {
background = mp_obj_get_int(args[8]);
}
render_stage(x0, y0, x1, y1, layers, layers_size, buffer, buffer_size,
display, scale, background);
render_stage(x0, y0, x1, y1, vx, vy, layers, layers_size,
buffer, buffer_size, display, scale, background);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stage_render_obj, 7, 8, stage_render);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stage_render_obj, 10, 10, stage_render);
STATIC const mp_rom_map_elem_t stage_module_globals_table[] = {

View File

@ -31,7 +31,10 @@
#include "shared-bindings/_stage/Text.h"
void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
void render_stage(
uint16_t x0, uint16_t y0,
uint16_t x1, uint16_t y1,
int16_t vx, int16_t vy,
mp_obj_t *layers, size_t layers_size,
uint16_t *buffer, size_t buffer_size,
displayio_display_obj_t *display,
@ -55,9 +58,9 @@ void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
CHIP_SELECT_TOGGLE_EVERY_BYTE,
&display->write_ram_command, 1);
size_t index = 0;
for (uint16_t y = y0; y < y1; ++y) {
for (int16_t y = y0 + vy; y < y1 + vy; ++y) {
for (uint8_t yscale = 0; yscale < scale; ++yscale) {
for (uint16_t x = x0; x < x1; ++x) {
for (int16_t x = x0 + vx; x < x1 + vx; ++x) {
uint16_t c = TRANSPARENT;
for (size_t layer = 0; layer < layers_size; ++layer) {
layer_obj_t *obj = MP_OBJ_TO_PTR(layers[layer]);

View File

@ -34,7 +34,10 @@
#define TRANSPARENT (0x1ff8)
void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
void render_stage(
uint16_t x0, uint16_t y0,
uint16_t x1, uint16_t y1,
int16_t vx, int16_t vy,
mp_obj_t *layers, size_t layers_size,
uint16_t *buffer, size_t buffer_size,
displayio_display_obj_t *display,