comparison pytouhou/ui/gamerunner.pyx @ 464:36bc577b2392

Make the window resizable, and scale its content correctly.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 11 Sep 2013 15:55:19 +0200
parents 11708a1d0a1a
children 2f53be1b2f60
comparison
equal deleted inserted replaced
463:11708a1d0a1a 464:36bc577b2392
23 cdef object game, background 23 cdef object game, background
24 cdef GameRenderer renderer 24 cdef GameRenderer renderer
25 cdef Window window 25 cdef Window window
26 cdef object replay_level, save_keystates 26 cdef object replay_level, save_keystates
27 cdef long keystate 27 cdef long keystate
28 cdef bint skip, use_fixed_pipeline 28 cdef bint skip
29 29
30 def __init__(self, window, resource_loader, bint skip=False): 30 def __init__(self, Window window, resource_loader, bint skip=False):
31 self.use_fixed_pipeline = window.use_fixed_pipeline #XXX 31 self.renderer = GameRenderer(resource_loader, window.use_fixed_pipeline)
32
33 self.renderer = GameRenderer(resource_loader, self.use_fixed_pipeline)
34 32
35 self.window = window 33 self.window = window
36 self.replay_level = None 34 self.replay_level = None
37 self.skip = skip 35 self.skip = skip
38 self.keystate = 0 36 self.keystate = 0
96 scancode = event[1] 94 scancode = event[1]
97 if scancode == sdl.SCANCODE_ESCAPE: 95 if scancode == sdl.SCANCODE_ESCAPE:
98 return False #TODO: implement the pause. 96 return False #TODO: implement the pause.
99 elif type_ == sdl.QUIT: 97 elif type_ == sdl.QUIT:
100 return False 98 return False
99 elif type_ == sdl.WINDOWEVENT:
100 event_ = event[1]
101 if event_ == sdl.WINDOWEVENT_RESIZED:
102 self.window.set_size(event[2], event[3])
101 if self.game: 103 if self.game:
102 if self.replay_level is None: 104 if self.replay_level is None:
103 #TODO: allow user settings 105 #TODO: allow user settings
104 keys = sdl.get_keyboard_state() 106 keys = sdl.get_keyboard_state()
105 keystate = 0 107 keystate = 0
133 self.save_keystates.append(keystate) 135 self.save_keystates.append(keystate)
134 136
135 self.game.run_iter(keystate) 137 self.game.run_iter(keystate)
136 self.game.interface.labels['framerate'].set_text('%.2ffps' % self.window.get_fps()) 138 self.game.interface.labels['framerate'].set_text('%.2ffps' % self.window.get_fps())
137 if not self.skip: 139 if not self.skip:
138 self.renderer.render(self.game) 140 self.renderer.render(self.game, self.window)
139 return True 141 return True