/* renders the textfield */ void TCOD_text_render (TCOD_text_t txt, TCOD_console_t con) { text_t * data = (text_t*)txt; uint32 time; bool cursor_on; char back=0; int curx,cury,cursorx,cursory, curpos; char *ptr; TCOD_IFNOT(data && data->con ) return; time = TCOD_sys_elapsed_milli(); cursor_on = (int)( time % data->interval ) > data->halfinterval; TCOD_console_set_default_background(data->con, data->back); TCOD_console_set_default_foreground(data->con, data->fore); TCOD_console_clear(data->con); /* compute cursor position */ get_cursor_coords(data,&cursorx,&cursory); if ( cursor_on && data->ascii_cursor) { /* save the character under cursor position */ back = data->text[data->cursor_pos]; data->text[data->cursor_pos] = data->ascii_cursor; } /* render prompt */ if (data->prompt) TCOD_console_print_rect_ex(data->con,0,0,data->w,data->h,TCOD_BKGND_SET,TCOD_LEFT,"%s",data->prompt); /* render text */ curx=data->textx; cury=data->texty; ptr=data->text; curpos=0; while (*ptr) { if ( *ptr == '\n') { if ( (curx == 0 || curpos == 0 ) && curpos >= data->sel_start && curpos < data->sel_end ) { /* inverted colors for selected empty lines */ TCOD_console_set_char_background(data->con, curx, cury, data->fore, TCOD_BKGND_SET); TCOD_console_set_char_foreground(data->con, curx, cury, data->back); } curx=0; cury++; } else { if ( curpos >= data->sel_start && curpos < data->sel_end ) { /* inverted colors for selection */ TCOD_console_set_char_background(data->con, curx, cury, data->fore, TCOD_BKGND_SET); TCOD_console_set_char_foreground(data->con, curx, cury, data->back); } TCOD_console_set_char(data->con,curx,cury,*ptr); curx++; if ( curx == data->w ) { curx=0; cury++; } } ptr++; curpos++; } if ( cursor_on ) { if ( data->ascii_cursor) { /* restore the character under cursor */ data->text[data->cursor_pos] = back; } else { /* invert colors at cursor position */ TCOD_console_set_char_background(data->con,cursorx,cursory,data->fore,TCOD_BKGND_SET); TCOD_console_set_char_foreground(data->con,cursorx,cursory,data->back); } } else if (! cursor_on && ! data->ascii_cursor && data->multiline ) { /* normal colors for cursor ( might be inside selection ) */ TCOD_console_set_char_background(data->con,cursorx,cursory,data->back,TCOD_BKGND_SET); TCOD_console_set_char_foreground(data->con,cursorx,cursory,data->fore); } TCOD_console_blit(data->con,0,0,data->w,data->h,con,data->x,data->y,1.0f,data->transparency); }
void TCOD_console_set_char_foreground_wrapper(TCOD_console_t con,int x, int y, colornum_t col) { TCOD_console_set_char_foreground (con, x, y, int_to_color(col)); }
void TCODConsole::setCharForeground(int x,int y, const TCODColor &col) { TCOD_color_t c={col.r,col.g,col.b}; TCOD_console_set_char_foreground(data,x,y,c); }