def help(self): """Show a help window and wait for a key or a mouse press.""" margin_x = margin_y = 64 padding_x = padding_y = 8 fgcolor = self.HELP_FGCOLOR bgcolor = self.HELP_BGCOLOR helpmsg = self.HELP_MSG width = self.width - 2 * margin_x height = self.height - 2 * margin_y lines = rendertext(helpmsg, self.font, fgcolor, width - 2 * padding_x, height - 2 * padding_y) block = pygame.Surface((width, height), SWSURFACE | SRCALPHA) block.fill(bgcolor) sx = padding_x sy = padding_y for img in lines: w, h = img.get_size() block.blit(img, (sx, sy)) sy += h block.set_alpha(int(255 * self.HELP_ALPHA)) self.screen.blit(block, (margin_x, margin_y)) pygame.display.flip() while True: wait_for_events() e = EventQueue.pop(0) if e.type in (MOUSEBUTTONDOWN, KEYDOWN, QUIT): break if e.type == QUIT: EventQueue.insert(0, e) # re-insert a QUIT self.must_redraw = True
def help(self): """Show a help window and wait for a key or a mouse press.""" margin_x = margin_y = 64 padding_x = padding_y = 8 fgcolor = self.HELP_FGCOLOR bgcolor = self.HELP_BGCOLOR helpmsg = self.HELP_MSG width = self.width - 2*margin_x height = self.height - 2*margin_y lines = rendertext(helpmsg, self.font, fgcolor, width - 2*padding_x, height - 2*padding_y) block = pygame.Surface((width, height), SWSURFACE | SRCALPHA) block.fill(bgcolor) sx = padding_x sy = padding_y for img in lines: w, h = img.get_size() block.blit(img, (sx, sy)) sy += h block.set_alpha(int(255 * self.HELP_ALPHA)) self.screen.blit(block, (margin_x, margin_y)) pygame.display.flip() while True: wait_for_events() e = EventQueue.pop(0) if e.type in (MOUSEBUTTONDOWN, KEYDOWN, QUIT): break if e.type == QUIT: EventQueue.insert(0, e) # re-insert a QUIT self.must_redraw = True
def run1(self): self.dragging = self.click_origin = self.click_time = None try: while True: if self.must_redraw and not EventQueue: self.redraw_now() if not EventQueue: wait_for_events() self.process_event(EventQueue.pop(0)) except StopIteration: pass