]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
Merge pull request #51 from FoamyGuy/tilegrid_fix 0.5.7
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Tue, 16 Mar 2021 19:20:43 +0000 (12:20 -0700)
committerGitHub <noreply@github.com>
Tue, 16 Mar 2021 19:20:43 +0000 (12:20 -0700)
tilegrid size fix

1  2 
displayio/tilegrid.py

diff --combined displayio/tilegrid.py
index 552277b73551ef148435a5d5fea1b34cd9b71367,47a2a9b0f39fbc1d1fe472fd53ad25fda3d72ca3..26a420293e0ed0e22d7804db7399487cbcc5e86d
@@@ -89,7 -89,7 +89,7 @@@ class TileGrid
          self._pixel_shader = pixel_shader
          if isinstance(self._pixel_shader, ColorConverter):
              self._pixel_shader._rgba = True  # pylint: disable=protected-access
 -        self._hidden = False
 +        self._hidden_tilegrid = False
          self._x = x
          self._y = y
          self._width = width  # Number of Tiles Wide
      # pylint: disable=too-many-locals,too-many-branches,too-many-statements
      def _fill_area(self, buffer):
          """Draw onto the image"""
 -        if self._hidden:
 +        if self._hidden_tilegrid:
              return
  
          if self._bitmap.width <= 0 or self._bitmap.height <= 0:
                      source=(
                          tile_index_x * tile_width,
                          tile_index_y * tile_height,
+                         tile_index_x * tile_width + tile_width,
+                         tile_index_y * tile_height + tile_height,
                      ),
                  )
  
      def hidden(self):
          """True when the TileGrid is hidden. This may be False even
          when a part of a hidden Group."""
 -        return self._hidden
 +        return self._hidden_tilegrid
  
      @hidden.setter
      def hidden(self, value):
          if not isinstance(value, (bool, int)):
              raise ValueError("Expecting a boolean or integer value")
 -        self._hidden = bool(value)
 +        self._hidden_tilegrid = bool(value)
  
      @property
      def x(self):
          """The pixel shader of the tilegrid."""
          return self._pixel_shader
  
 -    def __getitem__(self, index):
 -        """Returns the tile index at the given index. The index can either be
 -        an x,y tuple or an int equal to ``y * width + x``'.
 -        """
 +    def _extract_and_check_index(self, index):
          if isinstance(index, (tuple, list)):
              x = index[0]
              y = index[1]
              y = index // self._width
          if x > self._width or y > self._height or index >= len(self._tiles):
              raise ValueError("Tile index out of bounds")
 +        return index
 +
 +    def __getitem__(self, index):
 +        """Returns the tile index at the given index. The index can either be
 +        an x,y tuple or an int equal to ``y * width + x``'.
 +        """
 +        index = self._extract_and_check_index(index)
          return self._tiles[index]
  
      def __setitem__(self, index, value):
          """Sets the tile index at the given index. The index can either be
          an x,y tuple or an int equal to ``y * width + x``.
          """
 -        if isinstance(index, (tuple, list)):
 -            x = index[0]
 -            y = index[1]
 -            index = y * self._width + x
 -        elif isinstance(index, int):
 -            x = index % self._width
 -            y = index // self._width
 -        if x > self._width or y > self._height or index >= len(self._tiles):
 -            raise ValueError("Tile index out of bounds")
 +        index = self._extract_and_check_index(index)
          if not 0 <= value <= 255:
              raise ValueError("Tile value out of bounds")
          self._tiles[index] = value