def mouse_resize(self, mouse): brx, bry = 0, 0 root = tc.R.active_root self.raise_window(True) utils.copy_windows_to_console([win for win in self.wmanager.window_stack if win is not self], tc.R.scratch) tc.R.scratch.blit(tc.R.temp_console, self.tlx, self.tly, self.width, self.height, 0, 0, 1.0, 1.0) tc.R.scratch.copy_to_console(root) # copy-console-to-console self.copy_to_console(root) # copy-window-to-console root.flush() key = tcod.Key() while mouse.lbutton: tcod.sys_check_for_event(tcod.EVENT_MOUSE, key, mouse) brx = utils.clamp(self.tlx, tc.R.screen_width() - 1, mouse.cx) bry = utils.clamp(self.tly, tc.R.screen_height() - 1, mouse.cy) if not (brx == self.brx and bry == self.bry): # Erase window tc.R.temp_console.blit(root, 0, 0, self.width, self.height, self.tlx, self.tly, 1.0, 1.0) self.resize(brx - self.tlx, bry - self.tly) self.prepare() # Save part of root console that win is covering tc.R.scratch.blit(tc.R.temp_console, self.tlx, self.tly, self.width, self.height, 0, 0, 1.0, 1.0) # Copy win to root self.copy_to_console(root) root.flush()
def dirty_window(self): tlx, tly = self.tlx, self.tly w, h = self.width, self.height tcod.console_set_dirty(utils.clamp(0, (tc.R.screen_width() - 1), tlx), utils.clamp(0, (tc.R.screen_height() - 1), tly), utils.clamp(0, (tc.R.screen_width() - tlx), w), utils.clamp(0, (tc.R.screen_height() - tly), h))
def mouse_drag(self, mouse): root = tc.R.active_root width, height = self.width, self.height offset_x, offset_y = mouse.cx - self.tlx, mouse.cy - self.tly tlx, tly = 0, 0 swidth = tc.R.screen_width() sheight = tc.R.screen_height() tc.R.scratch.clear() tc.R.temp_console.clear() self.raise_window(self.wmanager.auto_redraw) utils.copy_windows_to_console([win for win in self.wmanager.window_stack if win is not self], tc.R.scratch) tc.R.scratch.blit(tc.R.temp_console, self.tlx, self.tly, self.width, self.height, 0, 0, 1.0, 1.0) tc.R.scratch.copy_to_console(root) # copy-console-to-console self.copy_to_console(root) # copy-window-to-console root.flush() key = tcod.Key() while mouse.lbutton: tcod.sys_check_for_event(tcod.EVENT_MOUSE, key, mouse) tlx = utils.clamp(0, swidth - self.width - 1, mouse.cx - offset_x) tly = utils.clamp(0, sheight - self.height - 1, mouse.cy - offset_y) if not (tlx == self.tlx and tly == self.tly): # Erase window tc.R.temp_console.blit(root, 0, 0, width, height, self.tlx, self.tly, 1.0, 1.0) self.move_window(tlx, tly) # Save part of root console that win is covering tc.R.scratch.blit(tc.R.temp_console, tlx, tly, width, height, 0, 0, 1.0, 1.0) # Copy win to root self.copy_to_console(root) root.flush()
def dirty_window(self): tlx, tly = self.tlx, self.tly w, h = self.width, self.height tcod.loader.lib.TCOD_console_set_dirty( utils.clamp(0, (tc.R.screen_width() - 1), tlx), utils.clamp(0, (tc.R.screen_height() - 1), tly), utils.clamp(0, (tc.R.screen_width() - tlx), w), utils.clamp(0, (tc.R.screen_height() - tly), h))
def handle_drag(self, mouse): logger.debug("handle_mouse_drag: {}".format(mouse)) root = tc.R.active_root width, height = self.width, self.height offset = mouse.tile[0] - self.tlx swidth = tc.R.screen_width() sheight = tc.R.screen_height() tc.R.scratch.clear() tc.R.temp_console.clear() self.raise_window(self.wmanager.auto_redraw) utils.copy_windows_to_console( [win for win in self.wmanager.window_stack if win is not self], tc.R.scratch) tc.R.scratch.blit(tc.R.temp_console, self.tlx, self.tly, self.width, self.height, 0, 0, 1.0, 1.0) tc.R.scratch.copy_to_console(root) # copy-console-to-console self.copy_to_console(root) # copy-window-to-console root.flush() end_drag = False while not end_drag: n_tlx = self.tlx n_tly = self.tly mouse_events = [ m for m in tcod.event.get() if m.type == "MOUSEMOTION" or m.type == "MOUSEBUTTONUP" ] if len(mouse_events) > 0: mouse = mouse_events[-1] if mouse.type == "MOUSEMOTION": mx, my = mouse.tile n_tlx = utils.clamp(0, swidth - self.width - 1, mx - offset) n_tly = utils.clamp(0, sheight - self.height - 1, my) if mouse.type == "MOUSEBUTTONUP": self.__active_drag = False end_drag = True if not (n_tlx == self.tlx and n_tly == self.tly): # Erase window tc.R.temp_console.blit(root, 0, 0, width, height, self.tlx, self.tly, 1.0, 1.0) self.move_window(n_tlx, n_tly) # Save part of root console that win is covering tc.R.scratch.blit(tc.R.temp_console, n_tlx, n_tly, width, height, 0, 0, 1.0, 1.0) # Copy win to root self.copy_to_console(root) root.flush()
def prepare(self): super().prepare() pagelen = self.page_length linecnt = self.all_items_line_cnt if pagelen > self.all_items_line_cnt: self.offset = 0 self.cursor = utils.clamp(0, linecnt, self.cursor) if self.cursor < self.offset: self.offset = self.cursor if self.cursor >= pagelen + self.offset: self.offset = self.cursor - pagelen - 1 offset = self.offset # This needs to account for items that are # wrapped, i.e. printed over multiple lines. border_offset = 0 if self.use_borders else 1 last_item_idx = len(self.items) last_view_idx = offset+pagelen-1 last_idx = last_view_idx if last_view_idx < last_item_idx \ else last_item_idx print_offset = 0 for i in range(offset,last_idx): if i+print_offset+border_offset > pagelen: break print_offset += self.draw_item(self.items[i], border_offset, i + print_offset + border_offset, i == self.cursor)
def prepare(self): super().prepare() pagelen = self.page_length linecnt = self.all_items_line_cnt if pagelen > self.all_items_line_cnt: self.offset = 0 self.cursor = utils.clamp(0, linecnt, self.cursor) if self.cursor < self.offset: self.offset = self.cursor if self.cursor >= pagelen + self.offset: self.offset = self.cursor - pagelen - 1 offset = self.offset # This needs to account for items that are # wrapped, i.e. printed over multiple lines. border_offset = 0 if self.use_borders else 1 last_item_idx = len(self.items) last_view_idx = offset + pagelen - 1 last_idx = last_view_idx if last_view_idx < last_item_idx \ else last_item_idx print_offset = 0 for i in range(offset, last_idx): if i + print_offset + border_offset > pagelen: break print_offset += self.draw_item(self.items[i], border_offset, i + print_offset + border_offset, i == self.cursor)
def move_cursor_to(self, idx: int): """Move ListWindow cursor to new index <idx>. """ old_cursor = self.cursor self.cursor = utils.clamp(0, max((0, len(self.items)-1)), idx) if old_cursor != self.cursor and self.item_at_cursor(): self.cursor_moved_to_item(self.item_at_cursor())
def move_cursor_to(self, idx: int): """Move ListWindow cursor to new index <idx>. """ old_cursor = self.cursor self.cursor = utils.clamp(0, max((0, len(self.items) - 1)), idx) if old_cursor != self.cursor and self.item_at_cursor(): self.cursor_moved_to_item(self.item_at_cursor())
def handle_resize(self, mouse): brx, bry = 0, 0 root = tc.R.active_root self.raise_window(True) utils.copy_windows_to_console( [win for win in self.wmanager.window_stack if win is not self], tc.R.scratch) tc.R.scratch.blit(tc.R.temp_console, self.tlx, self.tly, self.width, self.height, 0, 0, 1.0, 1.0) tc.R.scratch.copy_to_console(root) # copy-console-to-console self.copy_to_console(root) # copy-window-to-console root.flush() end_resize = False while not end_resize: n_tlx = self.tlx n_tly = self.tly mouse_events = [ m for m in tcod.event.get() if m.type == "MOUSEMOTION" or m.type == "MOUSEBUTTONUP" ] if len(mouse_events) > 0: mouse = mouse_events[-1] if mouse.type == "MOUSEMOTION": m_x, m_y = mouse.tile brx = utils.clamp(self.tlx, tc.R.screen_width() - 1, m_x) bry = utils.clamp(self.tly, tc.R.screen_height() - 1, m_y) if not (brx == self.brx and bry == self.bry): # Erase window tc.R.temp_console.blit(root, 0, 0, self.width, self.height, self.tlx, self.tly, 1.0, 1.0) self.resize(brx - self.tlx, bry - self.tly) self.prepare() # Save part of root console that win is covering tc.R.scratch.blit(tc.R.temp_console, self.tlx, self.tly, self.width, self.height, 0, 0, 1.0, 1.0) # Copy win to root self.copy_to_console(root) root.flush() if mouse.type == "MOUSEBUTTONUP": self.__active_resize = False end_resize = True
def scroll_horizontally(self, dx): """Scroll the view a given number of columns left or right.""" self.view_tlx = utils.clamp(0, self.view_width, self.view_tlx + dx) return self.view_tlx
def scroll_vertically(self, dy): """Scroll the view a given number of rows up or down.""" self.view_tly = utils.clamp(0, self.view_height, self.view_tly + dy) return self.view_tly