예제 #1
0
파일: gui.c 프로젝트: pasoev/innfin
static void gui_render(struct engine *engine)
{
    /* Clear the gui console */
    TCOD_console_set_default_background(engine->gui->con, TCOD_black);
    TCOD_console_clear(engine->gui->con);

    /* Render health bar */
    engine->gui->render_bar(engine, 1, 1, BAR_W, "HP",
                            engine->player->life->hp,
                            engine->player->life->max_hp,
                            TCOD_white, TCOD_lighter_gray);

    /* Render XP bar */
    double next_level_xp = calc_next_level_xp(engine, engine->player);
    char xp_txt[20];
    sprintf(xp_txt, "level %d XP", engine->player->ai->xp_level);
    engine->gui->render_bar(engine, 1, 2, BAR_W, xp_txt, engine->player->ai->xp,
                            next_level_xp, TCOD_white, TCOD_lighter_gray);


    render_status(engine->gui->con, 1, 4, engine->player);

    engine->gui->render_log(engine, MSG_X, 1);
    engine->gui->render_mouse_look(engine);

    TCOD_console_blit(engine->gui->con, 0, 0, engine->window_w,
                      PANEL_H, NULL, 0, engine->window_h - PANEL_H,
                      1.f, 1.f);
}
예제 #2
0
파일: lights.c 프로젝트: witheld9/Torch
void startLights() {
	LIGHT_MAP = TCOD_map_new(WINDOW_WIDTH, WINDOW_HEIGHT);
	DYNAMIC_LIGHT_CONSOLE = TCOD_console_new(WINDOW_WIDTH, WINDOW_HEIGHT);

	printf("Starting up lights...\n");

	TCOD_console_set_default_background(DYNAMIC_LIGHT_CONSOLE, TCOD_color_RGB(0, 0, 0));
	TCOD_console_set_key_color(DYNAMIC_LIGHT_CONSOLE, TCOD_color_RGB(255, 0, 255));
	TCOD_console_clear(DYNAMIC_LIGHT_CONSOLE);
}
예제 #3
0
파일: ui.c 프로젝트: witheld9/Torch
void setupUi() {
    UI_CONSOLE = TCOD_console_new(WINDOW_WIDTH, WINDOW_HEIGHT);

    TCOD_console_set_color_control(TCOD_COLCTRL_1, TCOD_color_RGB(200, 200, 200), TCOD_color_RGB(25, 25, 25));
    TCOD_console_set_default_background(UI_CONSOLE, TCOD_color_RGB(0, 0, 0));
    TCOD_console_set_key_color(UI_CONSOLE, TCOD_color_RGB(0, 0, 0));
    TCOD_console_clear(UI_CONSOLE);

    DISPLAY_TEXT = calloc(WINDOW_WIDTH, sizeof(char));
    DISPLAY_TEXT[0] = '\0';
}
예제 #4
0
파일: gui.c 프로젝트: pasoev/innfin
static void render_bar(struct engine *engine, int x, int y, int w,
                       const char *name, double value, const double max_value,
                       TCOD_color_t bar_col, TCOD_color_t back_col)
{
    TCOD_console_set_default_background(engine->gui->con, back_col);
    TCOD_console_rect(engine->gui->con, x, y, w, 1, false,
                      TCOD_BKGND_SET);

    int bar_w = (int) (value / max_value * w);
    if (bar_w > 0) {
        /* Draw the bar */
        TCOD_console_set_default_background(engine->gui->con, bar_col);
        TCOD_console_rect(engine->gui->con, x, y, bar_w, 1, false,
                          TCOD_BKGND_SET);
    }

    /* Print text on top of a bar */
    TCOD_color_t hp_color = TCOD_black;
    TCOD_console_set_default_foreground(engine->gui->con, hp_color);
    TCOD_console_print_ex(engine->gui->con, x + w / 2, y,
                          TCOD_BKGND_NONE, TCOD_CENTER, "%s : %.0f/%.0f",
                          name, value, max_value);
}
예제 #5
0
파일: ui.c 프로젝트: witheld9/Torch
void _drawMenu() {
    int i, fadeValue;
    TCOD_color_t cursorColor;

    if (!MENU_CALLBACK) {
        return;
    }

    fadeValue = abs(getAnimateFrame() - 30) * 2;
    cursorColor = TCOD_color_RGB(120 + fadeValue, 120 + fadeValue, 120 + fadeValue);

    TCOD_console_set_default_background(UI_CONSOLE, TCOD_color_RGB(15, 10, 10));
    TCOD_console_set_default_foreground(UI_CONSOLE, TCOD_color_RGB(200, 200, 200));

    for (i = 0; i < MENU_ITEM_COUNT; i ++) {
        if (MENU_ITEM_INDEX == i) {
            drawChar(UI_CONSOLE, 1, 2 + i, '>', cursorColor, TCOD_color_RGB(1, 1, 1));
        }

        TCOD_console_print(UI_CONSOLE, 3, 2 + i, MENU_ITEMS[i]);
    }

    TCOD_console_set_default_background(UI_CONSOLE, TCOD_color_RGB(0, 0, 0));
}
예제 #6
0
void TCOD_console_set_default_background_wrapper(TCOD_console_t con,
						   colornum_t col)
{
   TCOD_console_set_default_background (con,
				      int_to_color(col));
}
예제 #7
0
/* 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);
}
예제 #8
0
파일: image_c.c 프로젝트: Amarna/libtcod
void TCOD_image_blit_2x(TCOD_image_t image, TCOD_console_t con, int dx, int dy, int sx, int sy, int w, int h) {
	TCOD_color_t grid[4];
	TCOD_color_t cols[2];
	int nbCols;
	int width,height,ascii,cx,cy;
	TCOD_console_data_t *dat = con ? (TCOD_console_data_t *)(con) : TCOD_ctx.root;
	image_data_t *img=(image_data_t *)image;
	int maxx,maxy;
	TCOD_IFNOT(image != NULL && dat != NULL) return;

	TCOD_image_get_size(image,&width,&height);
	if ( w == -1 ) w=width;
	if ( h == -1 ) h=height;

	/* check that the sx,sy/w,h rectangle is inside the image */
	TCOD_ASSERT(sx >= 0 && sy >= 0 && sx+w <= width && sy+h <= height);
	TCOD_IFNOT(w > 0 && h > 0) return;

	sx=MAX(0,sx);
	sy=MAX(0,sy);
	w = MIN(w,width-sx);
	h = MIN(h,height-sy);

	maxx=dx+w/2 <= dat->w ? w : (dat->w-dx)*2;
	maxy=dy+h/2 <= dat->h ? h : (dat->h-dy)*2;
	/* check that the image is not blitted outside the console */
	TCOD_IFNOT(dx+maxx/2 >= 0 && dy+maxy/2 >= 0 && dx < dat->w && dy < dat->h) return;
	maxx+=sx;
	maxy+=sy;

	for (cx=sx; cx < maxx; cx += 2) {
		for (cy=sy; cy < maxy; cy += 2) {
			/* get the 2x2 super pixel colors from the image */
			int conx=dx+(cx-sx)/2;
			int cony=dy+(cy-sy)/2;
			TCOD_color_t consoleBack=TCOD_console_get_char_background(con,conx,cony);
			grid[0]=TCOD_image_get_pixel(image,cx,cy);
			if ( img->has_key_color && grid[0].r == img->key_color.r  && grid[0].g == img->key_color.g && grid[0].b == img->key_color.b)
				grid[0]=consoleBack;
			if ( cx < maxx-1 ) {
				grid[1]=TCOD_image_get_pixel(image,cx+1,cy);
				if ( img->has_key_color && grid[1].r == img->key_color.r  && grid[1].g == img->key_color.g && grid[1].b == img->key_color.b)
					grid[1]=consoleBack;
			} else grid[1]=consoleBack;
			if ( cy < maxy-1 ) {
				grid[2]=TCOD_image_get_pixel(image,cx,cy+1);
				if ( img->has_key_color && grid[2].r == img->key_color.r  && grid[2].g == img->key_color.g && grid[2].b == img->key_color.b)
					grid[2]=consoleBack;
			} else grid[2]=consoleBack;
			if ( cx < maxx-1 && cy < maxy-1 ) {
				grid[3]=TCOD_image_get_pixel(image,cx+1,cy+1);
				if ( img->has_key_color && grid[3].r == img->key_color.r  && grid[3].g == img->key_color.g && grid[3].b == img->key_color.b)
					grid[3]=consoleBack;
			} else grid[3]=consoleBack;
			/* analyse color, posterize, get pattern */
			getPattern(grid,cols,&nbCols,&ascii);
			if ( nbCols == 1 ) {
				/* single color */
				TCOD_console_set_char_background(con,conx,cony,cols[0],TCOD_BKGND_SET);
				TCOD_console_set_char(con,conx,cony,' ');
			} else {
				if ( ascii >= 0 ) {
					TCOD_console_set_default_background(con,cols[0]);
					TCOD_console_set_default_foreground(con,cols[1]);
					TCOD_console_put_char(con,conx,cony,ascii,TCOD_BKGND_SET);
				} else {
					/* negative ascii code means we need to invert back/fore colors */
					TCOD_console_set_default_background(con,cols[1]);
					TCOD_console_set_default_foreground(con,cols[0]);
					TCOD_console_put_char(con,conx,cony,-ascii,TCOD_BKGND_SET);
				}
			}
		}
	}
}
예제 #9
0
void TCODConsole::setDefaultBackground(TCODColor back) {
	TCOD_color_t b={back.r,back.g,back.b};
	TCOD_console_set_default_background(data,b);
}