]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/blobdiff - displayio/_tilegrid.py
bitmap getter and setter. pixel_shader setter
[hackapet/Adafruit_Blinka_Displayio.git] / displayio / _tilegrid.py
index f2ccde23ab827dcc0525fe596f157e6e049535bb..ca3a31f0d7340512075b2f693675d42b74c172dc 100644 (file)
@@ -18,20 +18,17 @@ displayio for Blinka
 """
 
 from typing import Union, Optional, Tuple
-from recordclass import recordclass
 from PIL import Image
 from ._bitmap import Bitmap
 from ._colorconverter import ColorConverter
 from ._ondiskbitmap import OnDiskBitmap
 from ._shape import Shape
 from ._palette import Palette
+from ._structs import RectangleStruct, TransformStruct
 
 __version__ = "0.0.0-auto.0"
 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
 
-Rectangle = recordclass("Rectangle", "x1 y1 x2 y2")
-Transform = recordclass("Transform", "x y dx dy scale transpose_xy mirror_x mirror_y")
-
 
 class TileGrid:
     # pylint: disable=too-many-instance-attributes
@@ -100,9 +97,11 @@ class TileGrid:
         self._pixel_width = width * tile_width
         self._pixel_height = height * tile_height
         self._tiles = (self._width * self._height) * [default_tile]
-        self.in_group = False
-        self._absolute_transform = Transform(0, 0, 1, 1, 1, False, False, False)
-        self._current_area = Rectangle(0, 0, self._pixel_width, self._pixel_height)
+        self._in_group = False
+        self._absolute_transform = TransformStruct(0, 0, 1, 1, 1, False, False, False)
+        self._current_area = RectangleStruct(
+            0, 0, self._pixel_width, self._pixel_height
+        )
         self._moved = False
 
     def _update_transform(self, absolute_transform):
@@ -296,6 +295,9 @@ class TileGrid:
         ):
             buffer.alpha_composite(image, (x, y), source=(source_x, source_y))
 
+    def _finish_refresh(self):
+        pass
+
     @property
     def hidden(self) -> bool:
         """True when the TileGrid is hidden. This may be False even
@@ -379,6 +381,42 @@ class TileGrid:
         """The pixel shader of the tilegrid."""
         return self._pixel_shader
 
+    @pixel_shader.setter
+    def pixel_shader(self, new_pixel_shader: Union[ColorConverter, Palette]) -> None:
+        if not isinstance(new_pixel_shader, ColorConverter) and not isinstance(
+            new_pixel_shader, Palette
+        ):
+            raise TypeError(
+                "Unsupported Type: new_pixel_shader must be ColorConverter or Palette"
+            )
+
+        self._pixel_shader = new_pixel_shader
+
+    @property
+    def bitmap(self) -> Union[Bitmap, OnDiskBitmap, Shape]:
+        """The Bitmap, OnDiskBitmap, or Shape that is assigned to this TileGrid"""
+        return self._bitmap
+
+    @bitmap.setter
+    def bitmap(self, new_bitmap: Union[Bitmap, OnDiskBitmap, Shape]) -> None:
+
+        if (
+            not isinstance(new_bitmap, Bitmap)
+            and not isinstance(new_bitmap, OnDiskBitmap)
+            and not isinstance(new_bitmap, Shape)
+        ):
+            raise TypeError(
+                "Unsupported Type: new_bitmap must be Bitmap, OnDiskBitmap, or Shape"
+            )
+
+        if (
+            new_bitmap.width != self.bitmap.width
+            or new_bitmap.height != self.bitmap.height
+        ):
+            raise ValueError("New bitmap must be same size as old bitmap")
+
+        self._bitmap = new_bitmap
+
     def _extract_and_check_index(self, index):
         if isinstance(index, (tuple, list)):
             x = index[0]