def draw_terminal(): y = Terminal.top W.puttext(Terminal.left, y, Terminal.left + Terminal.width -1, y + Terminal.height -1, Terminal.clear_buffer) for line in Terminal.buffer[Terminal.scroll_offset:Terminal.scroll_offset+Terminal.height]: W.puttext(Terminal.left, y, min(Terminal.width, Terminal.left + line.width - 1), y, line.buf) y += 1
def draw_buffer(buf, x, y): if buf.dirty: #generate a wconio buffer buf._text = render_buffer(buf) buf.dirty = False W.puttext(x, y, x + buf.width-1, y + buf.height-1, buf._text )
def draw_condition_bar(base): x, y = base.x + len(base.text), base.y hp, max_hp = game.player.hp, game.player.max_hp buf = [] for i in range(1, max_hp + 1): if hp >= i: color = draw.color_char(W.GREEN) else: color = draw.color_char(W.RED) buf.extend([C.Characters.half_box, color]) buf = "".join(buf) W.puttext(x, y, x + max_hp - 1, y, buf)
def draw_box(left=None, top=None, width=None, height=None, box=None, **kwargs): if width is None and box: #box is a Box namedtuple width = box.width height = box.height if left is None and box: #and can also have positioning left = box.left top = box.top if box is None and width: #or you can just give w/h and let it make you one box = create_box(width, height, left=left, top=top, **kwargs) W.puttext(left, top, left+width-1, top+height-1, box.buf) return box
def show_confirmation(line1=' ', line2=' '): line1 = terminal.Line.parse(line1)[0] line2 = terminal.Line.parse(line2)[0] width = max(14, max(line1.width, line2.width) + 2) height = 8 left = (C.width - width) / 2 top = (C.height - height) / 2 previous_buf = W.gettext(left, top, left + width, top + height) btn_width = 7 btn_height = 4 btn_offset = 3 try: container = draw.draw_box(left, top, width, height, border_color=W.LIGHTBLUE, border_background_color = W.BLUE) W.puttext(left+1, top + 1, left + line1.width, top + 1, line1.buf) W.puttext(left+1, top + 2, left + line2.width, top + 2, line2.buf) yes_button = draw.draw_box(left + btn_offset, top + height - btn_height, btn_width, btn_height, border_color=W.LIGHTBLUE, border_background_color = W.BLUE, corners = {'bl': 'teeup', 'br': 'teeup'}) no_button = draw.draw_box(left + width - btn_offset - btn_width, top + height - btn_height, btn_width, btn_height, border_color=W.LIGHTBLUE, border_background_color = W.BLUE, corners = {'bl': 'teeup', 'br': 'teeup'}) yes_text = draw.Text(W.DARKGREY, 1, 1, "YES".center(btn_width -2 )) no_text = draw.Text(W.WHITE, 1, 1, "NO".center(btn_width -2 )) yes_button.text.append(yes_text) no_button.text.append(no_text) selected_button = no_button while True: if selected_button == yes_button: yes_text.color = W.WHITE no_text.color = W.DARKGREY else: no_text.color = W.WHITE yes_text.color = W.DARKGREY draw.draw_box_text(yes_button) draw.draw_box_text(no_button) (chn, chs) = W.getch() #figure out if we're done if chs == '\r': #enter, exit break if chs == 'y': selected_button = yes_button break if chs == 'n': selected_button = no_button break if chn == 0 or chn == 224: #special keys come in two parts (chn2, _) = W.getch() if chn2 in W.__keydict: name = W.__keydict[chn2] if 'left' in name or 'right' in name: selected_button = (selected_button == yes_button and no_button or yes_button) return (selected_button == yes_button and True or False) finally: #Restore what we scribbled on W.puttext(left, top, left + width, top + height, previous_buf)
def draw_scrollbar(): buf = ''.join(['%s%s' % (a,b) for a,b in Scrollbar.arr]) W.puttext(Scrollbar.left, Scrollbar.top, Scrollbar.left, Scrollbar.top + Terminal.height - 1, buf)
def _conio_puttext(self, a, b, c, d, t): import WConio #pylint: disable = import-error WConio.puttext(a, b, c, d, t)
def close(self): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if self.buffer: wc.puttext(self.sx, self.sy, self.ex, self.ey, self.buffer)
def close(self): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if self.buffer: wc.puttext(self.sx, self.sy, self.ex, self.ey, self.buffer)