From 7f8f78bfbce3406981c203c878a892e1065e4e4d Mon Sep 17 00:00:00 2001 From: Wade Brainerd Date: Sat, 21 Nov 2009 17:17:08 +0000 Subject: Make Pygame display size match the widget size. Also rename _canvas member to _pygamecanvas to avoid conflict with Sugar. --- diff --git a/sugargame/event.py b/sugargame/event.py index 42fca1e..b315c1c 100644 --- a/sugargame/event.py +++ b/sugargame/event.py @@ -70,6 +70,12 @@ class Translator(object): self._inner_evb.connect('expose-event', self._expose_cb) self._inner_evb.connect('configure-event', self._resize_cb) + # Fake the first VIDEORESIZE event to set the initial screen dimensions. + r = self._inner_evb.get_allocation() + evt = pygame.event.Event(pygame.VIDEORESIZE, + size=(r.width,r.height), width=r.width, height=r.height) + pygame.event.post(evt) + # Internal data self.__stopped = False self.__keystate = [0] * 323 @@ -92,7 +98,7 @@ class Translator(object): return True def _resize_cb(self, widget, event): - evt = pygame.event.Event(pygame.event.VIDEORESIZE, + evt = pygame.event.Event(pygame.VIDEORESIZE, size=(event.width,event.height), width=event.width, height=event.height) pygame.event.post(evt) return False # continue processing diff --git a/test/TestActivity.py b/test/TestActivity.py index 693789a..ccc0e35 100644 --- a/test/TestActivity.py +++ b/test/TestActivity.py @@ -25,12 +25,12 @@ class TestActivity(sugar.activity.activity.Activity): self.build_toolbar() # Build the Pygame canvas. - self._canvas = sugargame.canvas.PygameCanvas(self) + self._pygamecanvas = sugargame.canvas.PygameCanvas(self) # Note that set_canvas implicitly calls read_file when resuming from the Journal. - self.set_canvas(self._canvas) + self.set_canvas(self._pygamecanvas) # Start the game running. - self._canvas.run_pygame(self.game.run) + self._pygamecanvas.run_pygame(self.game.run) def build_toolbar(self): stop_play = sugar.graphics.toolbutton.ToolButton('media-playback-stop') diff --git a/test/TestGame.py b/test/TestGame.py index 2c96803..d9dbc2e 100755 --- a/test/TestGame.py +++ b/test/TestGame.py @@ -41,7 +41,9 @@ class TestGame: for event in pygame.event.get(): if event.type == pygame.QUIT: return - + elif event.type == pygame.VIDEORESIZE: + pygame.display.set_mode(event.size, pygame.RESIZABLE) + # Move the ball if not self.paused: self.x += self.vx -- cgit v0.9.1