2018-08-15 14:01:01 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the Micro Python project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
|
|
|
*
|
|
|
|
* 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 "shared-bindings/displayio/Group.h"
|
|
|
|
|
|
|
|
#include "py/runtime.h"
|
2021-02-21 10:25:17 -05:00
|
|
|
#include "py/objlist.h"
|
2019-01-24 16:43:39 -05:00
|
|
|
#include "shared-bindings/displayio/TileGrid.h"
|
2018-08-15 14:01:01 -04:00
|
|
|
|
2020-05-02 05:21:35 -04:00
|
|
|
#if CIRCUITPY_VECTORIO
|
|
|
|
#include "shared-bindings/vectorio/VectorShape.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void common_hal_displayio_group_construct(displayio_group_t *self, uint32_t scale, mp_int_t x, mp_int_t y) {
|
2021-02-21 07:43:28 -05:00
|
|
|
mp_obj_list_t *members = mp_obj_new_list(0, NULL);
|
|
|
|
displayio_group_construct(self, members, scale, x, y);
|
2018-08-15 14:01:01 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
bool common_hal_displayio_group_get_hidden(displayio_group_t *self) {
|
2019-08-27 19:03:05 -04:00
|
|
|
return self->hidden;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void common_hal_displayio_group_set_hidden(displayio_group_t *self, bool hidden) {
|
2019-08-27 19:03:05 -04:00
|
|
|
if (self->hidden == hidden) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self->hidden = hidden;
|
|
|
|
if (self->hidden_by_parent) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-21 07:43:28 -05:00
|
|
|
for (size_t i = 0; i < self->members->len; i++) {
|
2021-02-20 17:04:06 -05:00
|
|
|
mp_obj_t layer;
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[i], &displayio_tilegrid_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2019-08-27 19:03:05 -04:00
|
|
|
displayio_tilegrid_set_hidden_by_parent(layer, hidden);
|
2021-02-20 17:04:06 -05:00
|
|
|
continue;
|
|
|
|
}
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[i], &displayio_group_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2019-08-27 19:03:05 -04:00
|
|
|
displayio_group_set_hidden_by_parent(layer, hidden);
|
2021-02-20 17:04:06 -05:00
|
|
|
continue;
|
2019-08-27 19:03:05 -04:00
|
|
|
}
|
2022-05-07 12:49:07 -04:00
|
|
|
#if CIRCUITPY_VECTORIO
|
2022-05-08 13:02:59 -04:00
|
|
|
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, self->members->items[i]);
|
|
|
|
if (draw_protocol != NULL) {
|
|
|
|
layer = draw_protocol->draw_get_protocol_self(self->members->items[i]);
|
|
|
|
draw_protocol->draw_protocol_impl->draw_set_dirty(layer);
|
2022-05-07 12:49:07 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2019-08-27 19:03:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void displayio_group_set_hidden_by_parent(displayio_group_t *self, bool hidden) {
|
|
|
|
if (self->hidden_by_parent == hidden) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self->hidden_by_parent = hidden;
|
|
|
|
// If we're already hidden, then we're done.
|
|
|
|
if (self->hidden) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-21 07:43:28 -05:00
|
|
|
for (size_t i = 0; i < self->members->len; i++) {
|
2021-02-20 17:04:06 -05:00
|
|
|
mp_obj_t layer;
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[i], &displayio_tilegrid_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2019-08-27 19:03:05 -04:00
|
|
|
displayio_tilegrid_set_hidden_by_parent(layer, hidden);
|
2021-02-20 17:04:06 -05:00
|
|
|
continue;
|
|
|
|
}
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[i], &displayio_group_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2019-08-27 19:03:05 -04:00
|
|
|
displayio_group_set_hidden_by_parent(layer, hidden);
|
2021-02-20 17:04:06 -05:00
|
|
|
continue;
|
2019-08-27 19:03:05 -04:00
|
|
|
}
|
2022-05-07 13:27:36 -04:00
|
|
|
#if CIRCUITPY_VECTORIO
|
2022-05-08 13:14:28 -04:00
|
|
|
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, self->members->items[i]);
|
|
|
|
if (draw_protocol != NULL) {
|
|
|
|
layer = draw_protocol->draw_get_protocol_self(self->members->items[i]);
|
|
|
|
draw_protocol->draw_protocol_impl->draw_set_dirty(layer);
|
2022-05-07 13:27:36 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2019-08-27 19:03:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
uint32_t common_hal_displayio_group_get_scale(displayio_group_t *self) {
|
2019-02-06 15:13:17 -05:00
|
|
|
return self->scale;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
bool displayio_group_get_previous_area(displayio_group_t *self, displayio_area_t *area) {
|
2019-06-06 18:11:02 -04:00
|
|
|
bool first = true;
|
2021-02-21 07:43:28 -05:00
|
|
|
for (size_t i = 0; i < self->members->len; i++) {
|
2021-02-20 17:04:06 -05:00
|
|
|
mp_obj_t layer;
|
2019-06-06 18:11:02 -04:00
|
|
|
displayio_area_t layer_area;
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[i], &displayio_tilegrid_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2019-06-06 18:11:02 -04:00
|
|
|
if (!displayio_tilegrid_get_previous_area(layer, &layer_area)) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-02-20 17:04:06 -05:00
|
|
|
} else {
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[i], &displayio_group_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
|
|
|
if (!displayio_group_get_previous_area(layer, &layer_area)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-06-06 18:11:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (first) {
|
|
|
|
displayio_area_copy(&layer_area, area);
|
|
|
|
first = false;
|
|
|
|
} else {
|
2021-03-25 12:21:39 -04:00
|
|
|
displayio_area_union(area, &layer_area, area);
|
2019-06-06 18:11:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (self->item_removed) {
|
|
|
|
if (first) {
|
|
|
|
displayio_area_copy(&self->dirty_area, area);
|
|
|
|
first = false;
|
|
|
|
} else {
|
2021-03-25 12:21:39 -04:00
|
|
|
displayio_area_union(area, &self->dirty_area, area);
|
2019-06-06 18:11:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return !first;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
static void _update_child_transforms(displayio_group_t *self) {
|
2019-06-06 18:11:02 -04:00
|
|
|
if (!self->in_group) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-21 07:43:28 -05:00
|
|
|
for (size_t i = 0; i < self->members->len; i++) {
|
2021-02-20 17:04:06 -05:00
|
|
|
mp_obj_t layer;
|
2021-03-15 09:57:36 -04:00
|
|
|
#if CIRCUITPY_VECTORIO
|
2021-08-01 16:01:57 -04:00
|
|
|
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, self->members->items[i]);
|
|
|
|
if (draw_protocol != NULL) {
|
|
|
|
layer = draw_protocol->draw_get_protocol_self(self->members->items[i]);
|
|
|
|
draw_protocol->draw_protocol_impl->draw_update_transform(layer, &self->absolute_transform);
|
2021-02-20 17:04:06 -05:00
|
|
|
continue;
|
2020-05-09 02:03:15 -04:00
|
|
|
}
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[i], &displayio_tilegrid_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2019-06-06 18:11:02 -04:00
|
|
|
displayio_tilegrid_update_transform(layer, &self->absolute_transform);
|
2021-02-20 17:04:06 -05:00
|
|
|
continue;
|
|
|
|
}
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[i], &displayio_group_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2019-06-06 18:11:02 -04:00
|
|
|
displayio_group_update_transform(layer, &self->absolute_transform);
|
2021-02-20 17:04:06 -05:00
|
|
|
continue;
|
2019-06-06 18:11:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void displayio_group_update_transform(displayio_group_t *self,
|
2021-03-15 09:57:36 -04:00
|
|
|
const displayio_buffer_transform_t *parent_transform) {
|
2019-06-06 18:11:02 -04:00
|
|
|
self->in_group = parent_transform != NULL;
|
|
|
|
if (self->in_group) {
|
|
|
|
int16_t x = self->x;
|
|
|
|
int16_t y = self->y;
|
|
|
|
if (parent_transform->transpose_xy) {
|
|
|
|
x = y;
|
|
|
|
y = self->x;
|
|
|
|
}
|
|
|
|
self->absolute_transform.x = parent_transform->x + parent_transform->dx * x;
|
|
|
|
self->absolute_transform.y = parent_transform->y + parent_transform->dy * y;
|
|
|
|
self->absolute_transform.dx = parent_transform->dx * self->scale;
|
|
|
|
self->absolute_transform.dy = parent_transform->dy * self->scale;
|
|
|
|
self->absolute_transform.transpose_xy = parent_transform->transpose_xy;
|
|
|
|
self->absolute_transform.mirror_x = parent_transform->mirror_x;
|
|
|
|
self->absolute_transform.mirror_y = parent_transform->mirror_y;
|
|
|
|
|
|
|
|
self->absolute_transform.scale = parent_transform->scale * self->scale;
|
|
|
|
}
|
|
|
|
_update_child_transforms(self);
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void common_hal_displayio_group_set_scale(displayio_group_t *self, uint32_t scale) {
|
2019-06-06 18:11:02 -04:00
|
|
|
if (self->scale == scale) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t parent_scale = self->absolute_transform.scale / self->scale;
|
|
|
|
self->absolute_transform.dx = self->absolute_transform.dx / self->scale * scale;
|
|
|
|
self->absolute_transform.dy = self->absolute_transform.dy / self->scale * scale;
|
|
|
|
self->absolute_transform.scale = parent_scale * scale;
|
2019-02-06 15:13:17 -05:00
|
|
|
self->scale = scale;
|
2019-06-06 18:11:02 -04:00
|
|
|
_update_child_transforms(self);
|
2019-02-06 15:13:17 -05:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
mp_int_t common_hal_displayio_group_get_x(displayio_group_t *self) {
|
2019-02-06 15:13:17 -05:00
|
|
|
return self->x;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void common_hal_displayio_group_set_x(displayio_group_t *self, mp_int_t x) {
|
2019-06-06 18:11:02 -04:00
|
|
|
if (self->x == x) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (self->absolute_transform.transpose_xy) {
|
2019-06-13 03:34:19 -04:00
|
|
|
int16_t dy = self->absolute_transform.dy / self->scale;
|
2019-06-06 18:11:02 -04:00
|
|
|
self->absolute_transform.y += dy * (x - self->x);
|
2021-03-15 09:57:36 -04:00
|
|
|
} else {
|
2019-06-13 03:34:19 -04:00
|
|
|
int16_t dx = self->absolute_transform.dx / self->scale;
|
2019-06-06 18:11:02 -04:00
|
|
|
self->absolute_transform.x += dx * (x - self->x);
|
|
|
|
}
|
|
|
|
|
2019-02-06 15:13:17 -05:00
|
|
|
self->x = x;
|
2019-06-06 18:11:02 -04:00
|
|
|
_update_child_transforms(self);
|
2019-02-06 15:13:17 -05:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
mp_int_t common_hal_displayio_group_get_y(displayio_group_t *self) {
|
2019-02-06 15:13:17 -05:00
|
|
|
return self->y;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void common_hal_displayio_group_set_y(displayio_group_t *self, mp_int_t y) {
|
2019-06-06 18:11:02 -04:00
|
|
|
if (self->y == y) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (self->absolute_transform.transpose_xy) {
|
|
|
|
int8_t dx = self->absolute_transform.dx / self->scale;
|
|
|
|
self->absolute_transform.x += dx * (y - self->y);
|
2021-03-15 09:57:36 -04:00
|
|
|
} else {
|
2019-06-06 18:11:02 -04:00
|
|
|
int8_t dy = self->absolute_transform.dy / self->scale;
|
|
|
|
self->absolute_transform.y += dy * (y - self->y);
|
|
|
|
}
|
2019-02-06 15:13:17 -05:00
|
|
|
self->y = y;
|
2019-06-06 18:11:02 -04:00
|
|
|
_update_child_transforms(self);
|
2019-02-06 15:13:17 -05:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
static void _add_layer(displayio_group_t *self, mp_obj_t layer) {
|
|
|
|
#if CIRCUITPY_VECTORIO
|
2021-08-01 16:01:57 -04:00
|
|
|
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, layer);
|
|
|
|
if (draw_protocol != NULL) {
|
|
|
|
draw_protocol->draw_protocol_impl->draw_update_transform(draw_protocol->draw_get_protocol_self(layer), &self->absolute_transform);
|
2021-02-20 17:04:06 -05:00
|
|
|
return;
|
2020-05-02 05:21:35 -04:00
|
|
|
}
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
2021-08-01 16:01:57 -04:00
|
|
|
mp_obj_t native_layer = mp_obj_cast_to_native_base(layer, &displayio_tilegrid_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (native_layer != MP_OBJ_NULL) {
|
2021-03-15 09:57:36 -04:00
|
|
|
displayio_tilegrid_t *tilegrid = native_layer;
|
2019-06-06 18:11:02 -04:00
|
|
|
if (tilegrid->in_group) {
|
2023-10-30 04:49:06 -04:00
|
|
|
mp_raise_ValueError(MP_ERROR_TEXT("Layer already in a group"));
|
2019-06-06 18:11:02 -04:00
|
|
|
} else {
|
|
|
|
tilegrid->in_group = true;
|
|
|
|
}
|
|
|
|
displayio_tilegrid_update_transform(tilegrid, &self->absolute_transform);
|
2021-06-24 10:13:15 -04:00
|
|
|
displayio_tilegrid_set_hidden_by_parent(
|
|
|
|
tilegrid, self->hidden || self->hidden_by_parent);
|
2021-02-20 17:04:06 -05:00
|
|
|
return;
|
|
|
|
}
|
2021-05-05 20:51:52 -04:00
|
|
|
native_layer = mp_obj_cast_to_native_base(layer, &displayio_group_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (native_layer != MP_OBJ_NULL) {
|
2021-03-15 09:57:36 -04:00
|
|
|
displayio_group_t *group = native_layer;
|
2019-06-06 18:11:02 -04:00
|
|
|
if (group->in_group) {
|
2023-10-30 04:49:06 -04:00
|
|
|
mp_raise_ValueError(MP_ERROR_TEXT("Layer already in a group"));
|
2019-06-06 18:11:02 -04:00
|
|
|
} else {
|
|
|
|
group->in_group = true;
|
|
|
|
}
|
|
|
|
displayio_group_update_transform(group, &self->absolute_transform);
|
2021-06-24 10:13:15 -04:00
|
|
|
displayio_group_set_hidden_by_parent(
|
|
|
|
group, self->hidden || self->hidden_by_parent);
|
2021-02-20 17:04:06 -05:00
|
|
|
return;
|
2019-01-24 16:43:39 -05:00
|
|
|
}
|
2023-10-30 04:49:06 -04:00
|
|
|
mp_raise_ValueError(MP_ERROR_TEXT("Layer must be a Group or TileGrid subclass"));
|
2019-06-06 18:11:02 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
static void _remove_layer(displayio_group_t *self, size_t index) {
|
2021-02-20 17:04:06 -05:00
|
|
|
mp_obj_t layer;
|
2019-06-06 18:11:02 -04:00
|
|
|
displayio_area_t layer_area;
|
|
|
|
bool rendered_last_frame = false;
|
2021-03-15 09:57:36 -04:00
|
|
|
#if CIRCUITPY_VECTORIO
|
2021-08-01 16:01:57 -04:00
|
|
|
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, self->members->items[index]);
|
|
|
|
if (draw_protocol != NULL) {
|
|
|
|
layer = draw_protocol->draw_get_protocol_self(self->members->items[index]);
|
|
|
|
bool has_dirty_area = draw_protocol->draw_protocol_impl->draw_get_dirty_area(layer, &layer_area);
|
2020-05-10 18:36:23 -04:00
|
|
|
rendered_last_frame = has_dirty_area;
|
2021-08-01 16:01:57 -04:00
|
|
|
draw_protocol->draw_protocol_impl->draw_update_transform(layer, NULL);
|
2020-05-10 17:17:57 -04:00
|
|
|
}
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[index], &displayio_tilegrid_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2021-03-15 09:57:36 -04:00
|
|
|
displayio_tilegrid_t *tilegrid = layer;
|
2022-12-10 20:44:35 -05:00
|
|
|
tilegrid->in_group = false;
|
2019-06-06 18:11:02 -04:00
|
|
|
rendered_last_frame = displayio_tilegrid_get_previous_area(tilegrid, &layer_area);
|
|
|
|
displayio_tilegrid_update_transform(tilegrid, NULL);
|
2021-02-20 17:04:06 -05:00
|
|
|
}
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[index], &displayio_group_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2021-03-15 09:57:36 -04:00
|
|
|
displayio_group_t *group = layer;
|
2022-12-10 20:44:35 -05:00
|
|
|
group->in_group = false;
|
2019-06-06 18:11:02 -04:00
|
|
|
rendered_last_frame = displayio_group_get_previous_area(group, &layer_area);
|
|
|
|
displayio_group_update_transform(group, NULL);
|
|
|
|
}
|
|
|
|
if (!rendered_last_frame) {
|
|
|
|
return;
|
2019-01-14 20:26:36 -05:00
|
|
|
}
|
2019-06-06 18:11:02 -04:00
|
|
|
if (!self->item_removed) {
|
|
|
|
displayio_area_copy(&layer_area, &self->dirty_area);
|
|
|
|
} else {
|
2021-03-25 12:21:39 -04:00
|
|
|
displayio_area_union(&self->dirty_area, &layer_area, &self->dirty_area);
|
2019-06-06 18:11:02 -04:00
|
|
|
}
|
|
|
|
self->item_removed = true;
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void common_hal_displayio_group_insert(displayio_group_t *self, size_t index, mp_obj_t layer) {
|
2021-02-20 17:04:06 -05:00
|
|
|
_add_layer(self, layer);
|
2021-02-27 15:13:55 -05:00
|
|
|
mp_obj_list_insert(self->members, index, layer);
|
2018-09-11 01:00:21 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
mp_obj_t common_hal_displayio_group_pop(displayio_group_t *self, size_t index) {
|
2019-06-06 18:11:02 -04:00
|
|
|
_remove_layer(self, index);
|
2021-02-21 10:25:17 -05:00
|
|
|
return mp_obj_list_pop(self->members, index);
|
2018-08-15 14:01:01 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
mp_int_t common_hal_displayio_group_index(displayio_group_t *self, mp_obj_t layer) {
|
2021-02-21 07:43:28 -05:00
|
|
|
mp_obj_t args[] = {self->members, layer};
|
|
|
|
mp_obj_t *index = mp_seq_index_obj(
|
|
|
|
self->members->items, self->members->len, 2, args);
|
|
|
|
return MP_OBJ_SMALL_INT_VALUE(index);
|
2019-05-15 14:33:16 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
size_t common_hal_displayio_group_get_len(displayio_group_t *self) {
|
2021-02-21 07:43:28 -05:00
|
|
|
return self->members->len;
|
2019-02-06 15:13:17 -05:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
mp_obj_t common_hal_displayio_group_get(displayio_group_t *self, size_t index) {
|
2021-02-21 07:43:28 -05:00
|
|
|
return self->members->items[index];
|
2019-02-06 15:13:17 -05:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void common_hal_displayio_group_set(displayio_group_t *self, size_t index, mp_obj_t layer) {
|
2021-02-20 17:04:06 -05:00
|
|
|
_add_layer(self, layer);
|
2019-06-06 18:11:02 -04:00
|
|
|
_remove_layer(self, index);
|
2021-03-03 17:36:48 -05:00
|
|
|
mp_obj_list_store(self->members, MP_OBJ_NEW_SMALL_INT(index), layer);
|
2019-02-06 15:13:17 -05:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void displayio_group_construct(displayio_group_t *self, mp_obj_list_t *members, uint32_t scale, mp_int_t x, mp_int_t y) {
|
2019-03-12 17:39:46 -04:00
|
|
|
self->x = x;
|
|
|
|
self->y = y;
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members = members;
|
2019-06-06 18:11:02 -04:00
|
|
|
self->item_removed = false;
|
2019-02-06 15:13:17 -05:00
|
|
|
self->scale = scale;
|
2019-06-06 18:11:02 -04:00
|
|
|
self->in_group = false;
|
2018-08-15 14:01:01 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
bool displayio_group_fill_area(displayio_group_t *self, const _displayio_colorspace_t *colorspace, const displayio_area_t *area, uint32_t *mask, uint32_t *buffer) {
|
2019-05-22 18:00:47 -04:00
|
|
|
// Track if any of the layers finishes filling in the given area. We can ignore any remaining
|
|
|
|
// layers at that point.
|
2022-05-07 12:59:26 -04:00
|
|
|
if (self->hidden == false) {
|
2022-04-09 11:09:46 -04:00
|
|
|
for (int32_t i = self->members->len - 1; i >= 0; i--) {
|
|
|
|
mp_obj_t layer;
|
|
|
|
#if CIRCUITPY_VECTORIO
|
|
|
|
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, self->members->items[i]);
|
|
|
|
if (draw_protocol != NULL) {
|
|
|
|
layer = draw_protocol->draw_get_protocol_self(self->members->items[i]);
|
|
|
|
if (draw_protocol->draw_protocol_impl->draw_fill_area(layer, colorspace, area, mask, buffer)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
continue;
|
2020-05-02 05:21:35 -04:00
|
|
|
}
|
2022-04-09 11:09:46 -04:00
|
|
|
#endif
|
|
|
|
layer = mp_obj_cast_to_native_base(
|
|
|
|
self->members->items[i], &displayio_tilegrid_type);
|
|
|
|
if (layer != MP_OBJ_NULL) {
|
|
|
|
if (displayio_tilegrid_fill_area(layer, colorspace, area, mask, buffer)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
continue;
|
2019-01-24 16:43:39 -05:00
|
|
|
}
|
2022-04-09 11:09:46 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
|
|
|
self->members->items[i], &displayio_group_type);
|
|
|
|
if (layer != MP_OBJ_NULL) {
|
|
|
|
if (displayio_group_fill_area(layer, colorspace, area, mask, buffer)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
continue;
|
2019-01-10 20:22:08 -05:00
|
|
|
}
|
2018-08-15 14:01:01 -04:00
|
|
|
}
|
|
|
|
}
|
2021-02-20 17:04:06 -05:00
|
|
|
return false;
|
2018-08-15 14:01:01 -04:00
|
|
|
}
|
|
|
|
|
2019-06-06 18:11:02 -04:00
|
|
|
void displayio_group_finish_refresh(displayio_group_t *self) {
|
|
|
|
self->item_removed = false;
|
2021-03-15 09:57:36 -04:00
|
|
|
for (int32_t i = self->members->len - 1; i >= 0; i--) {
|
2021-02-20 17:04:06 -05:00
|
|
|
mp_obj_t layer;
|
2021-03-15 09:57:36 -04:00
|
|
|
#if CIRCUITPY_VECTORIO
|
2021-08-01 16:01:57 -04:00
|
|
|
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, self->members->items[i]);
|
|
|
|
if (draw_protocol != NULL) {
|
|
|
|
layer = draw_protocol->draw_get_protocol_self(self->members->items[i]);
|
|
|
|
draw_protocol->draw_protocol_impl->draw_finish_refresh(layer);
|
2021-02-20 17:04:06 -05:00
|
|
|
continue;
|
2020-05-02 05:21:35 -04:00
|
|
|
}
|
2021-03-15 09:57:36 -04:00
|
|
|
#endif
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[i], &displayio_tilegrid_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2019-06-06 18:11:02 -04:00
|
|
|
displayio_tilegrid_finish_refresh(layer);
|
2021-02-20 17:04:06 -05:00
|
|
|
continue;
|
|
|
|
}
|
2021-05-05 20:51:52 -04:00
|
|
|
layer = mp_obj_cast_to_native_base(
|
2021-02-21 07:43:28 -05:00
|
|
|
self->members->items[i], &displayio_group_type);
|
2021-02-20 17:04:06 -05:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
2019-06-06 18:11:02 -04:00
|
|
|
displayio_group_finish_refresh(layer);
|
2021-02-20 17:04:06 -05:00
|
|
|
continue;
|
2018-08-15 14:01:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
displayio_area_t *displayio_group_get_refresh_areas(displayio_group_t *self, displayio_area_t *tail) {
|
2023-06-16 17:50:01 -04:00
|
|
|
if (self->item_removed) {
|
|
|
|
self->dirty_area.next = tail;
|
|
|
|
tail = &self->dirty_area;
|
|
|
|
}
|
2023-05-30 20:25:08 -04:00
|
|
|
|
2023-06-16 17:50:01 -04:00
|
|
|
for (int32_t i = self->members->len - 1; i >= 0; i--) {
|
|
|
|
mp_obj_t layer;
|
|
|
|
#if CIRCUITPY_VECTORIO
|
|
|
|
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, self->members->items[i]);
|
|
|
|
if (draw_protocol != NULL) {
|
|
|
|
layer = draw_protocol->draw_get_protocol_self(self->members->items[i]);
|
|
|
|
tail = draw_protocol->draw_protocol_impl->draw_get_refresh_areas(layer, tail);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
layer = mp_obj_cast_to_native_base(
|
2023-06-16 17:57:37 -04:00
|
|
|
self->members->items[i], &displayio_tilegrid_type);
|
2023-06-16 17:50:01 -04:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
|
|
|
if (!displayio_tilegrid_get_rendered_hidden(layer)) {
|
|
|
|
tail = displayio_tilegrid_get_refresh_areas(layer, tail);
|
2023-05-30 20:25:08 -04:00
|
|
|
}
|
2023-06-16 17:50:01 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
layer = mp_obj_cast_to_native_base(
|
2023-06-16 17:57:37 -04:00
|
|
|
self->members->items[i], &displayio_group_type);
|
2023-06-16 17:50:01 -04:00
|
|
|
if (layer != MP_OBJ_NULL) {
|
|
|
|
tail = displayio_group_get_refresh_areas(layer, tail);
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-15 14:01:01 -04:00
|
|
|
}
|
2019-06-06 18:11:02 -04:00
|
|
|
|
|
|
|
return tail;
|
2018-08-15 14:01:01 -04:00
|
|
|
}
|