コード例 #1
0
ファイル: ss.c プロジェクト: mpatraw/bzzd
static void draw_tile(int x, int y, unsigned tile, bool vis)
{
	if (vis) {
		TCOD_console_set_default_foreground(NULL, tiles[tile].lit);
	} else {
		TCOD_console_set_default_foreground(NULL, tiles[tile].unlit);
	}
	TCOD_console_put_char(NULL, x, y, tiles[tile].face, TCOD_BKGND_NONE);
}
コード例 #2
0
ファイル: building.c プロジェクト: thasmin/apocscientist
void building_draw(building *b)
{
    TCOD_color_t old_color = TCOD_console_get_default_foreground(NULL);
	TCOD_console_set_default_foreground(NULL, b->model->color);
	TCOD_console_print_frame(NULL, b->p.x, b->p.y,
		b->model->width, b->model->height,
		false, TCOD_BKGND_NONE, NULL);
	TCOD_console_print(NULL, b->p.x + 1, b->p.y, b->model->code);
	TCOD_console_set_default_foreground(NULL, old_color);
}
コード例 #3
0
ファイル: gui.c プロジェクト: pasoev/innfin
static void render_mouse_look(struct engine *engine)
{
    if (!is_in_fov(engine->map, engine->mouse.cx, engine->mouse.cy))
        /* if mouse is out of fov, nothing to render */
        return;

    char buf[128] = {'\0'};
    bool first = true;

    struct actor **iterator;
    for (iterator = (struct actor **) TCOD_list_begin(engine->actors);
         iterator != (struct actor **) TCOD_list_end(engine->actors);
         iterator++) {
        struct actor *actor = *iterator;
        /* Find actors under the mouse cursor */
        if (actor->x == engine->mouse.cx
            && actor->y == engine->mouse.cy) {
            if (!first)
                strcat(buf, ", ");
            else
                first = false;

            strcat(buf, actor->name);
        }
    }
    /*  display the list of actors under the mouse cursor */
    TCOD_console_set_default_foreground(engine->gui->con,
                                        TCOD_light_grey);
    TCOD_console_print(engine->gui->con, 1, 0, buf);
}
コード例 #4
0
ファイル: gui.c プロジェクト: pasoev/innfin
static void render_log(struct engine *engine, int start_x, int start_y)
{
    /* draw the message log */
    double color_coef = 0.4f;
    int y = start_y;

    TCOD_list_t log = engine->gui->log;

    struct message **iter;
    for (iter = (struct message **) TCOD_list_begin(log);
         iter != (struct message **) TCOD_list_end(log);
         iter++) {
        struct message *message = *iter;
        // TCOD_color_t col = TCOD_color_multiply_scalar(message->col, color_coef);
        TCOD_console_set_default_foreground(engine->gui->con, message->col);
        TCOD_console_print(engine->gui->con, start_x, y,
                           message->text);
        y++;
        if (color_coef < 1.0f)
            color_coef += 0.3f;
    }
}
コード例 #5
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);
}
コード例 #6
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));
}
コード例 #7
0
ファイル: wrappers.c プロジェクト: LeonBlade/DCPUToolchain
void TCOD_console_set_default_foreground_wrapper(TCOD_console_t con,
						   colornum_t col)
{
  TCOD_console_set_default_foreground (con,
				     int_to_color(col));
}
コード例 #8
0
ファイル: txtfield_c.c プロジェクト: chilamkatana/ASCIIWar
/* 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);
}
コード例 #9
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);
				}
			}
		}
	}
}
コード例 #10
0
ファイル: gui.c プロジェクト: pasoev/innfin
static void render_fixed_text(TCOD_console_t con, int x, int y,
                              TCOD_color_t col, const char *text)
{
    TCOD_console_set_default_foreground(con, col);
    TCOD_console_print_ex(con, x, y, TCOD_BKGND_NONE, TCOD_LEFT, "%s", text);
}
コード例 #11
0
ファイル: console.cpp プロジェクト: mkniffen/Roguelike
void TCODConsole::setDefaultForeground(TCODColor fore) {
	TCOD_color_t b={fore.r,fore.g,fore.b};
	TCOD_console_set_default_foreground(data,b);
}