X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka_Displayio.git/blobdiff_plain/8dc304ff4f82d37e493b9500e17fb13799dc200f..a53c930973a24a7c55db9448e45d7ca7974cb56e:/displayio/_group.py diff --git a/displayio/_group.py b/displayio/_group.py index 903d721..2c104f5 100644 --- a/displayio/_group.py +++ b/displayio/_group.py @@ -19,6 +19,7 @@ displayio for Blinka from __future__ import annotations from typing import Union, Callable +from circuitpython_typing import WriteableBuffer from ._structs import TransformStruct from ._tilegrid import TileGrid from ._colorspace import Colorspace @@ -29,6 +30,7 @@ __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git" class Group: + # pylint: disable=too-many-instance-attributes """ Manage a group of sprites and groups and how they are inter-related. @@ -49,6 +51,7 @@ class Group: self._group_x = x self._group_y = y self._hidden_group = False + self._hidden_by_parent = False self._layers = [] self._supported_types = (TileGrid, Group) self._in_group = False @@ -145,11 +148,14 @@ class Group: del self._layers[index] def _fill_area( - self, colorspace: Colorspace, area: Area, mask: int, buffer: bytearray + self, + colorspace: Colorspace, + area: Area, + mask: WriteableBuffer, + buffer: WriteableBuffer, ) -> bool: if self._hidden_group: return False - for layer in self._layers: if isinstance(layer, (Group, TileGrid)): if layer._fill_area( # pylint: disable=protected-access @@ -168,10 +174,33 @@ class Group: layer._finish_refresh() # pylint: disable=protected-access def _get_refresh_areas(self, areas: list[Area]) -> None: + # pylint: disable=protected-access + for layer in self._layers: + if isinstance(layer, Group): + layer._get_refresh_areas(areas) + elif isinstance(layer, TileGrid): + if not layer._get_rendered_hidden(): + layer._get_refresh_areas(areas) + + def _set_hidden(self, hidden: bool) -> None: + if self._hidden_group == hidden: + return + self._hidden_group = hidden + if self._hidden_by_parent: + return for layer in self._layers: if isinstance(layer, (Group, TileGrid)): - if not layer.hidden: - layer._get_refresh_areas(areas) # pylint: disable=protected-access + layer._set_hidden_by_parent(hidden) # pylint: disable=protected-access + + def _set_hidden_by_parent(self, hidden: bool) -> None: + if self._hidden_by_parent == hidden: + return + self._hidden_by_parent = hidden + if self._hidden_group: + return + for layer in self._layers: + if isinstance(layer, (Group, TileGrid)): + layer._set_hidden_by_parent(hidden) # pylint: disable=protected-access @property def hidden(self) -> bool: @@ -181,10 +210,11 @@ class Group: return self._hidden_group @hidden.setter - def hidden(self, value: bool): + def hidden(self, value: bool) -> None: if not isinstance(value, (bool, int)): raise ValueError("Expecting a boolean or integer value") - self._hidden_group = bool(value) + value = bool(value) + self._set_hidden(value) @property def scale(self) -> int: @@ -252,3 +282,6 @@ class Group: self._absolute_transform.y += dy_value * (value - self._group_y) self._group_y = value self._update_child_transforms() + + +circuitpython_splash = Group(scale=2, x=0, y=0)