comparison pytouhou/ui/gamerunner.pyx @ 592:19d930f9e3f0

Add the screenshot feature, using P or Home like the original game.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 23 Apr 2014 19:19:32 +0200
parents 00f228b57840
children 12756994a92c
comparison
equal deleted inserted replaced
591:2dfa4aa135d2 592:19d930f9e3f0
106 if self.renderer is not None: 106 if self.renderer is not None:
107 self.set_renderer_size(self.width, self.height) 107 self.set_renderer_size(self.width, self.height)
108 self.renderer.start(self.common) 108 self.renderer.start(self.common)
109 109
110 110
111 cdef void capture(self) except *:
112 if self.renderer is not None:
113 filename = 'screenshot/frame%06d.ppm' % self.game.frame
114 self.renderer.capture(filename, self.width, self.height)
115
116
111 cpdef bint update(self) except? False: 117 cpdef bint update(self) except? False:
112 cdef long keystate 118 cdef long keystate
119 capture = False
113 120
114 if self.background is not None: 121 if self.background is not None:
115 self.background.update(self.game.frame) 122 self.background.update(self.game.frame)
116 for event in sdl.poll_events(): 123 for event in sdl.poll_events():
117 type_ = event[0] 124 type_ = event[0]
118 if type_ == sdl.KEYDOWN: 125 if type_ == sdl.KEYDOWN:
119 scancode = event[1] 126 scancode = event[1]
120 if scancode == sdl.SCANCODE_ESCAPE: 127 if scancode == sdl.SCANCODE_ESCAPE:
121 return False #TODO: implement the pause. 128 return False #TODO: implement the pause.
129 elif scancode == sdl.SCANCODE_P or scancode == sdl.SCANCODE_HOME:
130 capture = True
122 elif type_ == sdl.QUIT: 131 elif type_ == sdl.QUIT:
123 return False 132 return False
124 elif type_ == sdl.WINDOWEVENT: 133 elif type_ == sdl.WINDOWEVENT:
125 event_ = event[1] 134 event_ = event[1]
126 if event_ == sdl.WINDOWEVENT_RESIZED: 135 if event_ == sdl.WINDOWEVENT_RESIZED:
170 labels['framerate'].set_text('%.2ffps' % self.window.get_fps()) 179 labels['framerate'].set_text('%.2ffps' % self.window.get_fps())
171 180
172 if not self.skip and self.renderer is not None: 181 if not self.skip and self.renderer is not None:
173 self.renderer.render(self.game) 182 self.renderer.render(self.game)
174 183
184 if capture:
185 self.capture()
186
175 return True 187 return True