2018-01-02 21:25:41 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Radomir Dopieralski
|
|
|
|
*
|
|
|
|
* 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 "Layer.h"
|
|
|
|
#include "Text.h"
|
|
|
|
#include "__init__.h"
|
|
|
|
#include "shared-bindings/_stage/Layer.h"
|
|
|
|
#include "shared-bindings/_stage/Text.h"
|
|
|
|
|
|
|
|
|
2021-10-08 18:05:49 -04:00
|
|
|
void render_stage(
|
|
|
|
uint16_t x0, uint16_t y0,
|
|
|
|
uint16_t x1, uint16_t y1,
|
|
|
|
int16_t vx, int16_t vy,
|
2021-03-15 09:57:36 -04:00
|
|
|
mp_obj_t *layers, size_t layers_size,
|
|
|
|
uint16_t *buffer, size_t buffer_size,
|
|
|
|
displayio_display_obj_t *display,
|
|
|
|
uint8_t scale, uint16_t background) {
|
2018-01-02 21:25:41 -05:00
|
|
|
|
2019-09-04 10:41:58 -04:00
|
|
|
|
|
|
|
displayio_area_t area;
|
2021-10-07 06:58:43 -04:00
|
|
|
area.x1 = x0 * scale;
|
|
|
|
area.y1 = y0 * scale;
|
|
|
|
area.x2 = x1 * scale;
|
|
|
|
area.y2 = y1 * scale;
|
2019-09-04 10:41:58 -04:00
|
|
|
displayio_display_core_set_region_to_update(
|
|
|
|
&display->core, display->set_column_command, display->set_row_command,
|
2021-10-07 06:58:43 -04:00
|
|
|
NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area,
|
|
|
|
display->SH1107_addressing);
|
2019-09-04 10:41:58 -04:00
|
|
|
|
|
|
|
while (!displayio_display_core_begin_transaction(&display->core)) {
|
|
|
|
RUN_BACKGROUND_TASKS;
|
|
|
|
}
|
|
|
|
display->core.send(display->core.bus, DISPLAY_COMMAND,
|
2021-03-15 09:57:36 -04:00
|
|
|
CHIP_SELECT_TOGGLE_EVERY_BYTE,
|
|
|
|
&display->write_ram_command, 1);
|
2018-01-02 21:25:41 -05:00
|
|
|
size_t index = 0;
|
2021-10-08 18:05:49 -04:00
|
|
|
for (int16_t y = y0 + vy; y < y1 + vy; ++y) {
|
2019-08-02 06:36:34 -04:00
|
|
|
for (uint8_t yscale = 0; yscale < scale; ++yscale) {
|
2021-10-08 18:05:49 -04:00
|
|
|
for (int16_t x = x0 + vx; x < x1 + vx; ++x) {
|
2018-01-02 21:25:41 -05:00
|
|
|
uint16_t c = TRANSPARENT;
|
2019-08-02 06:36:34 -04:00
|
|
|
for (size_t layer = 0; layer < layers_size; ++layer) {
|
|
|
|
layer_obj_t *obj = MP_OBJ_TO_PTR(layers[layer]);
|
|
|
|
if (obj->base.type == &mp_type_layer) {
|
|
|
|
c = get_layer_pixel(obj, x, y);
|
|
|
|
} else if (obj->base.type == &mp_type_text) {
|
|
|
|
c = get_text_pixel((text_obj_t *)obj, x, y);
|
|
|
|
}
|
|
|
|
if (c != TRANSPARENT) {
|
|
|
|
break;
|
|
|
|
}
|
2018-01-02 21:25:41 -05:00
|
|
|
}
|
2020-01-30 09:24:04 -05:00
|
|
|
if (c == TRANSPARENT) {
|
|
|
|
c = background;
|
|
|
|
}
|
2019-08-02 06:36:34 -04:00
|
|
|
for (uint8_t xscale = 0; xscale < scale; ++xscale) {
|
2018-01-02 21:25:41 -05:00
|
|
|
buffer[index] = c;
|
2019-08-02 06:36:34 -04:00
|
|
|
index += 1;
|
|
|
|
// The buffer is full, send it.
|
|
|
|
if (index >= buffer_size) {
|
2019-09-04 10:41:58 -04:00
|
|
|
display->core.send(display->core.bus, DISPLAY_DATA,
|
2021-03-15 09:57:36 -04:00
|
|
|
CHIP_SELECT_UNTOUCHED,
|
|
|
|
((uint8_t *)buffer), buffer_size * 2);
|
2019-08-02 06:36:34 -04:00
|
|
|
index = 0;
|
|
|
|
}
|
2018-01-02 21:25:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Send the remaining data.
|
|
|
|
if (index) {
|
2019-09-04 10:41:58 -04:00
|
|
|
display->core.send(display->core.bus, DISPLAY_DATA,
|
2021-03-15 09:57:36 -04:00
|
|
|
CHIP_SELECT_UNTOUCHED,
|
|
|
|
((uint8_t *)buffer), index * 2);
|
2018-01-02 21:25:41 -05:00
|
|
|
}
|
2019-09-04 10:41:58 -04:00
|
|
|
|
|
|
|
displayio_display_core_end_transaction(&display->core);
|
2018-01-02 21:25:41 -05:00
|
|
|
}
|