]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/blobdiff - displayio/tilegrid.py
Fix link in Readme
[hackapet/Adafruit_Blinka_Displayio.git] / displayio / tilegrid.py
index 04ceb08463550a3ea9e342c90d55b101eb2dabc7..2c815a4f9280e92558ffab6d70e4373327ab9076 100644 (file)
@@ -215,7 +215,7 @@ class TileGrid:
         )
         image.putalpha(alpha.convert("L"))
 
-    # pylint: disable=too-many-locals
+    # pylint: disable=too-many-locals,too-many-branches
     def _fill_area(self, buffer):
         """Draw onto the image"""
         if self._hidden:
@@ -276,9 +276,27 @@ class TileGrid:
             y *= self._absolute_transform.dy
             x += self._absolute_transform.x
             y += self._absolute_transform.y
-        buffer.alpha_composite(image, (int(x), int(y)))
 
-    # pylint: enable=too-many-locals
+        source_x = source_y = 0
+        if x < 0:
+            source_x = round(0 - x)
+            x = 0
+        if y < 0:
+            source_y = round(0 - y)
+            y = 0
+
+        x = round(x)
+        y = round(y)
+
+        if (
+            x <= buffer.width
+            and y <= buffer.height
+            and source_x <= image.width
+            and source_y <= image.height
+        ):
+            buffer.alpha_composite(image, (x, y), source=(source_x, source_y))
+
+    # pylint: enable=too-many-locals,too-many-branches
 
     @property
     def hidden(self):