Ejemplo n.º 1
0
 def ui_loop(self):
     self.render_init()
     while True:
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 pygame.quit()
                 sys.exit()
             elif event.type == pygame.KEYDOWN:
                 if event.key == K_DELETE:
                     self.render_init()
                 elif event.key == K_TAB:
                     self.disp_shadow = not self.disp_shadow
             elif event.type == pygame.MOUSEBUTTONDOWN:
                 if event.button == 4:
                     self.mag = Utils.interval(
                         1, Const.UI_max_magnification, self.mag + 1)
                     self.update_anchor()
                 elif event.button == 5:
                     self.mag = Utils.interval(
                         1, Const.UI_max_magnification, self.mag - 1)
                     self.update_anchor()
             elif event.type == pygame.MOUSEMOTION:
                 if any(event.buttons):
                     self.update_anchor(*event.rel)
         self.render()
         pygame.display.update()
         time.sleep(Const.UI_flush_interval)
Ejemplo n.º 2
0
 def update_anchor(self, dx=0, dy=0):
     nx = Utils.interval(self.width - self.mag *
                         Const.BOARD_size[0], 0, self.anchor[0] + dx)
     ny = Utils.interval(self.height - self.mag *
                         Const.BOARD_size[1], 0, self.anchor[1] + dy)
     self.anchor = [nx, ny]