Skip to content

Commit d22e95e

Browse files
authored
Merge pull request #2561 from pewpew-game/stage-background
circuitpython-stage: allow choosing background color
2 parents 298bca3 + 27c36ee commit d22e95e

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

shared-bindings/_stage/__init__.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
//| Layer
5252
//| Text
5353
//|
54-
//| .. function:: render(x0, y0, x1, y1, layers, buffer, display[, scale])
54+
//| .. function:: render(x0, y0, x1, y1, layers, buffer, display[, scale[, background]])
5555
//|
5656
//| Render and send to the display a fragment of the screen.
5757
//|
@@ -63,6 +63,7 @@
6363
//| :param bytearray buffer: A buffer to use for rendering.
6464
//| :param ~displayio.Display display: The display to use.
6565
//| :param int scale: How many times should the image be scaled up.
66+
//| :param int background: What color to display when nothing is there.
6667
//|
6768
//| There are also no sanity checks, outside of the basic overflow
6869
//| checking. The caller is responsible for making the passed parameters
@@ -92,12 +93,16 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) {
9293
}
9394
displayio_display_obj_t *display = MP_OBJ_TO_PTR(native_display);
9495
uint8_t scale = 1;
95-
if (n_args >= 8) {
96+
if (n_args > 7) {
9697
scale = mp_obj_get_int(args[7]);
9798
}
99+
uint16_t background = 0;
100+
if (n_args > 8) {
101+
background = mp_obj_get_int(args[8]);
102+
}
98103

99104
render_stage(x0, y0, x1, y1, layers, layers_size, buffer, buffer_size,
100-
display, scale);
105+
display, scale, background);
101106

102107
return mp_const_none;
103108
}

shared-module/_stage/__init__.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
3535
mp_obj_t *layers, size_t layers_size,
3636
uint16_t *buffer, size_t buffer_size,
37-
displayio_display_obj_t *display, uint8_t scale) {
37+
displayio_display_obj_t *display,
38+
uint8_t scale, uint16_t background) {
3839

3940

4041
displayio_area_t area;
@@ -68,6 +69,9 @@ void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
6869
break;
6970
}
7071
}
72+
if (c == TRANSPARENT) {
73+
c = background;
74+
}
7175
for (uint8_t xscale = 0; xscale < scale; ++xscale) {
7276
buffer[index] = c;
7377
index += 1;

shared-module/_stage/__init__.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
3838
mp_obj_t *layers, size_t layers_size,
3939
uint16_t *buffer, size_t buffer_size,
40-
displayio_display_obj_t *display, uint8_t scale);
40+
displayio_display_obj_t *display,
41+
uint8_t scale, uint16_t background);
4142

4243
#endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE

0 commit comments

Comments
 (0)