Commits

Devin Jeanpierre committed c58c145 Draft

Moved display-specific rendering code to display-specific class

Comments (0)

Files changed (1)

pygame_display.py

         if font_size is None:
             font_size = get_monospace_size(font)
         
-        super(PartialScreen, self).__init__()
+        super(BaseSurfaceScreen, self).__init__()
         self.register_palette_entry(None, 'default','default')
         
         self._font = font
         self._cursor_position = None
         
         self._m_ctrl = self._m_shift = self._m_meta = False
-        
-        self._init_chargrid(surface.get_size())
     
     def _init_chargrid(self, size):
         """Initialize the character grid that's used to divide the screen"""
             for y in xrange(self._height))
         
         self._grid_dirty = set()
-
-        # goes here so it gets reset when surface is changed
-        events = [evt for evt in self._listening_events
-            if evt != pygame.VIDEORESIZE]
-        root_screen = False
-        
-        if pygame.display.get_surface() is self._surface:
-            events.append(pygame.VIDEORESIZE)
-            root_screen = True
-
-        self._listening_events = tuple(events)
-        self._root_screen = root_screen
     
     def change_surface(self, surface, size=None):
         """
         Initialize the screen and input mode.
         """
         
-        super(PartialScreen, self).start()
+        super(BaseSurfaceScreen, self).start()
         assert hasattr(self, '_surface')
 
     
         Restore the screen.
         """
         
-        super(PartialScreen, self).stop()
+        super(BaseSurfaceScreen, self).stop()
 
     
     def run_wrapper(self,fn):
             if (x, y) == cursor:
                 pygame.draw.rect(self._surface, fg, dirty_rect, 1)
         
-        if self._root_screen:
-            pygame.display.update(dirty_rects)
+        return dirty_rects
     
     def _get_color(self, attr):
         """Find (RGB_foreground, RGB_background) given an attr"""
         bold_font = pygame.font.SysFont('monospace', 12, True)
         font_size = get_monospace_size(font, bold_font)
 
+        self._resolution = resolution
+        self._resolution_in_pixels = resolution_in_pixels
+        self._clamp_resolution = clamp_resolution
+        self._window_title = window_title
+
         super(Screen, self).__init__(font, bold_font, font_size)
 
+        self._listening_events += (pygame.VIDEORESIZE,)
+
     def start(self):
         resolution = compute_resolution(
             self._resolution,
         pygame.display.init()
         screen = pygame.display.set_mode(resolution, pygame.RESIZABLE)
         pygame.display.set_caption(self._window_title)
+        self._surface = screen
+        self._init_chargrid(screen.get_size())
         super(Screen, self).start()
 
     def stop(self):
         super(Screen, self).stop()
         pygame.display.quit()
         
+    def _refresh(self, *args, **kwargs):
+        dirty_rects = super(Screen, self)._refresh(*args, **kwargs)
+        pygame.display.update(dirty_rects)
+        return dirty_rects