def on_display_resize(self, event): """ * also used when switching Levels * also used when changing a Level's grid size """ disp_surf = self.dm.screen disp_w, disp_h = disp_surf.get_size() # The board is where the current level is shown # in the top left. self.board_surface = disp_surf.subsurface( pygame.Rect((0,0), (disp_w/2, disp_h*7/8))) self.board_view = BoardView(self.board_surface, self.lm, self.tm, self.em) # "buttons" is the collection of buttons across the bottom. self.buttons_surface = disp_surf.subsurface( pygame.Rect((0, disp_h*7/8), (disp_w, disp_h/8))) self.buttons = Buttons(self.buttons_surface, self.em) self.buttons.calc_rects() # "tao" means "tiles and objects" # It's the selection control for tiles and objects # in the top right. self.tao_surface = disp_surf.subsurface( pygame.Rect((disp_w/2, 0), (disp_w/2, disp_h*7/8))) self.tao = TAO(self.tao_surface, self.tm, self.em)
class PygameView: def __init__(self, event_manager, display_manager, tile_manager, level_manager): self.em = event_manager self.connections = [ self.em.register(DisplayResizeEvent, self.on_display_resize), self.em.register(LevelKeyChangeEvent, self.on_display_resize), self.em.register(LevelSizeChangeEvent, self.on_display_resize), self.em.register(TickEvent, self.on_tick), ] self.dm = display_manager self.tm = tile_manager self.lm = level_manager self.board_surface = None self.board_view = None self.buttons_surface = None self.tao_surface = None self.buttons = None self.tao = None def on_display_resize(self, event): """ * also used when switching Levels * also used when changing a Level's grid size """ disp_surf = self.dm.screen disp_w, disp_h = disp_surf.get_size() # The board is where the current level is shown # in the top left. self.board_surface = disp_surf.subsurface( pygame.Rect((0,0), (disp_w/2, disp_h*7/8))) self.board_view = BoardView(self.board_surface, self.lm, self.tm, self.em) # "buttons" is the collection of buttons across the bottom. self.buttons_surface = disp_surf.subsurface( pygame.Rect((0, disp_h*7/8), (disp_w, disp_h/8))) self.buttons = Buttons(self.buttons_surface, self.em) self.buttons.calc_rects() # "tao" means "tiles and objects" # It's the selection control for tiles and objects # in the top right. self.tao_surface = disp_surf.subsurface( pygame.Rect((disp_w/2, 0), (disp_w/2, disp_h*7/8))) self.tao = TAO(self.tao_surface, self.tm, self.em) def on_tick(self, event): #LOGGER.info("[[render]]") screen = self.dm.screen screen.fill((0, 0, 0)) tm = self.tm self.board_view.draw_edit_grid() self.board_view.draw() self.buttons.draw() self.tao.draw() pygame.display.update()