def dotext(con, x, y, text, fg=ltc.white, bg=None, flag=None, align=ltc.LEFT): if not flag: flag = ltc.BKGND_SET if bg else ltc.BKGND_NONE if not bg: bg = ltc.black # if there are any colour coded in the text, replace them with the libtcod colour chars if '$' in text: # replace common colour codes text = text.replace(colctr_stop, chr(ltc.COLCTRL_STOP)) text = text.replace(colctr_fg, chr(ltc.COLCTRL_FORE_RGB)) text = text.replace(colctr_bg, chr(ltc.COLCTRL_BACK_RGB)) # note that libtcod can only handle 5 colour codes in the same print operation i = 1 for code, colour in __colours__.iteritems(): if code in text: if i > 5: # too many colour codes, just remove the control sequences text = text.replace(code, '') else: # replace the control sequence with the libtcod code # and assign the correct colour to the libtcod code ltc_code = __ltc_colour_codes__[i] text = text.replace(code, chr(ltc_code)) ltc.console_set_color_control(ltc_code, colour, bg) ltc.console_set_default_foreground(con, fg) ltc.console_set_default_background(con, bg) ltc.console_print_ex(con, x, y, flag, align, text)
def draw_str(self, string, coord=(0, 0), color=None): y, x = coord if color is None: fg, bg = Pair.Normal else: fg, bg = color libtcod.console_set_color_control(libtcod.COLCTRL_1, self.color_map[fg], self.color_map[bg]) string = chr(libtcod.COLCTRL_1) + string + chr(libtcod.COLCTRL_STOP) libtcod.console_print(self.win, x, y, string)
def printex(self,x,y,string,color,flush): if color: libtcod.console_set_color_control(libtcod.COLCTRL_1,color,False) libtcod.console_print(self.console,x,y,string) if flush: self.flush()