]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
root_group properties/functions on Display object and displaycore.
authorfoamyguy <foamyguy@gmail.com>
Fri, 9 Dec 2022 23:51:58 +0000 (17:51 -0600)
committerfoamyguy <foamyguy@gmail.com>
Fri, 9 Dec 2022 23:51:58 +0000 (17:51 -0600)
displayio/_display.py
displayio/_displaycore.py

index 1e429954a9851a16196f783e506299cf0c9997e9..fe680d76671649a7800a165018caedc4e99abef6 100644 (file)
@@ -23,7 +23,7 @@ import threading
 from typing import Optional
 from dataclasses import astuple
 import digitalio
 from typing import Optional
 from dataclasses import astuple
 import digitalio
-from PIL import Image
+from PIL import Image, ImageDraw
 import numpy
 import microcontroller
 import circuitpython_typing
 import numpy
 import microcontroller
 import circuitpython_typing
@@ -158,7 +158,7 @@ class Display:
         self._buffer = Image.new("RGB", (width, height))
         self._subrectangles = []
         self._bounds_encoding = ">BB" if single_byte_bounds else ">HH"
         self._buffer = Image.new("RGB", (width, height))
         self._subrectangles = []
         self._bounds_encoding = ">BB" if single_byte_bounds else ">HH"
-        self._current_group = None
+
         displays.append(self)
         self._refresh_thread = None
         if self._auto_refresh:
         displays.append(self)
         self._refresh_thread = None
         if self._auto_refresh:
@@ -240,7 +240,7 @@ class Display:
         """Switches to displaying the given group of layers. When group is None, the
         default CircuitPython terminal will be shown.
         """
         """Switches to displaying the given group of layers. When group is None, the
         default CircuitPython terminal will be shown.
         """
-        self._core.show(group)
+        self._core.set_root_group(group)
 
     def refresh(
         self,
 
     def refresh(
         self,
@@ -263,6 +263,7 @@ class Display:
         if not self._core.start_refresh():
             return False
 
         if not self._core.start_refresh():
             return False
 
+        force_full_refresh = False
         # Go through groups and and add each to buffer
         if self._core._current_group is not None:
             buffer = Image.new("RGBA", (self._core._width, self._core._height))
         # Go through groups and and add each to buffer
         if self._core._current_group is not None:
             buffer = Image.new("RGBA", (self._core._width, self._core._height))
@@ -274,14 +275,19 @@ class Display:
             self._buffer.paste(buffer)
         else:
             # show nothing
             self._buffer.paste(buffer)
         else:
             # show nothing
-            print("show nothing")
             buffer = Image.new("RGBA", (self._core._width, self._core._height))
             buffer = Image.new("RGBA", (self._core._width, self._core._height))
+            draw = ImageDraw.Draw(buffer)
+            draw.rectangle([(0, 0), buffer.size], fill=(0, 0, 0))
             self._buffer.paste(buffer)
             self._buffer.paste(buffer)
+            force_full_refresh = True
 
 
-        self._subrectangles = self._core.get_refresh_areas()
-
-        for area in self._subrectangles:
-            self._refresh_display_area(area)
+        if force_full_refresh:
+            full_rect = RectangleStruct(0, 0, self._width, self._height)
+            self._refresh_display_area(full_rect)
+        else:
+            self._subrectangles = self._core.get_refresh_areas()
+            for area in self._subrectangles:
+                self._refresh_display_area(area)
 
         self._core.finish_refresh()
 
 
         self._core.finish_refresh()
 
@@ -460,8 +466,12 @@ class Display:
 
     @property
     def root_group(self) -> Group:
 
     @property
     def root_group(self) -> Group:
-        return self._current_group
+        """The root group on the display."""
+        return self._core.get_root_group()
 
     @root_group.setter
     def root_group(self, new_group):
 
     @root_group.setter
     def root_group(self, new_group):
-        self._current_group = new_group
\ No newline at end of file
+        """Switches to displaying the given group of layers. When group is None,
+        a blank screen will be shown.
+        """
+        self._core.set_root_group(new_group)
index 3753b3ccd8ca5fbea8d49c696cbce778a11b8678..ffdc9e4a1701ff8197c271bcae12e4badd4d5e38 100644 (file)
@@ -151,44 +151,9 @@ class _DisplayCore:
         if self._current_group is not None:
             self._current_group._update_transform(self._transform)
 
         if self._current_group is not None:
             self._current_group._update_transform(self._transform)
 
-    def show(self, root_group: Group) -> bool:
-        # pylint: disable=protected-access
-
-        """
-        Switches to displaying the given group of layers. When group is `None`, the
-        default CircuitPython terminal will be shown.
-
-        :param Optional[displayio.Group] root_group: The group to show.
-        """
-
-        """
-        # TODO: Implement Supervisor
-        if root_group is None:
-            circuitpython_splash = _Supervisor().circuitpython_splash
-            if not circuitpython_splash._in_group:
-                root_group = circuitpython_splash
-            elif self._current_group == circuitpython_splash:
-                return True
-        """
-
-        if root_group == self._current_group:
-            return True
-
-        if root_group is not None and root_group._in_group:
-            return False
-
-        if self._current_group is not None:
-            self._current_group._in_group = False
-
-        if root_group is not None:
-            root_group._update_transform(self._transform)
-            root_group._in_group = True
-
-        self._current_group = root_group
-        self._full_refresh = True
-
-        print(f"end of show: {root_group}")
-        return True
+    def get_root_group(self):
+        """The root group on the display."""
+        return self._current_group
 
     def set_root_group(self, root_group: Group) -> bool:
         # pylint: disable=protected-access
 
     def set_root_group(self, root_group: Group) -> bool:
         # pylint: disable=protected-access