示例#1
0
void AltitudeGraph::createGraph()
{
    image_ptr graphImg;

    memory_image* image = new memory_image(width, height);

    graphImg.reset(image);

    color bgcolor(255, 255, 255, 255);
    color fgcolor(150,0,0,255);
    color axiscolor(0,0,0,255);
    color seacolor(0,0,255,255);

    text::font_face ffsea(s.ttf_path, 8, seacolor);
    ffsea.init();
    text::font_face ff12(s.ttf_path, 12, axiscolor);
    ff12.init();

    // fill background
    graphImg->fill(bgcolor);

    int _w = width - BORDER_X;
    int _h = height - BORDER_Y;

    long maxVal = this->getMax();

    int x_step = _w / mc::MapY;

    std::stringstream maxss;
    maxss << "MAX = " << maxVal;
    ff12.draw(graphImg, "NB of blocks", BORDER_X - 30 , BORDER_Y - 25);
    ff12.draw(graphImg, maxss.str(), BORDER_X - 20 , BORDER_Y - 10);

    ff12.draw(graphImg, "Altitude", _w - 2*BORDER_X , _h + 17);

    int x=0, y=0, x0=BORDER_X, y0=_h;

    for(int i = 0; i < mc::MapY; i++)
    {
       x =  BORDER_X + x_step*i;
       y = _h - (int)( ( (float)altitudeRegistry[i] / (float)maxVal ) * (_h-BORDER_Y) );
       graphImg->drawLine(x, y, x0, y0, fgcolor);
       x0 = x;
       y0 = y;
    }

    // draw axis
    graphImg->drawLine(BORDER_X, BORDER_Y, BORDER_X, _h, axiscolor);
    graphImg->drawLine(BORDER_X, _h, _w, _h, axiscolor);

    // draw axis labels
    for(int i=0; i < mc::MapY; i++)
    {
        color _axiscolor = axiscolor;
        x =  BORDER_X + x_step*i;
        int size = 2;
        if(i == 63)
        {
            _axiscolor = seacolor;
            ffsea.draw(graphImg, "Sea", x+4, _h+25);
            size = 25;
        }
        if(i%10 == 0)
        {
            size = 5;
        }
        graphImg->drawLine(x, _h, x, _h+size, _axiscolor);
    }

    png_format::opt_type opts;
    graphImg->save<png_format>(s.statistics_path.string() + "_graph.png", opts);
}
示例#2
0
文件: gfx.c 项目: linehan/barnacle
void take_bgcolor_yx(WINDOW *win, int y, int x, short pair)
{
        short fg = fgcolor(pair);
        init_pair(pair, fg, bgcolor_yx(win, y, x));
}
示例#3
0
文件: gfx.c 项目: linehan/barnacle
/**
 * fgcolor_yx -- return the foreground color of a window at (y,x) */
short fgcolor_yx(WINDOW *win, int y, int x)
{
        return (fgcolor(winpair_yx(win, y, x)));
}
示例#4
0
/*----------------------------------------------------------------------*/
static int list_single(struct dnode *dn)
{
	int i, column = 0;

#ifdef CONFIG_FEATURE_LS_USERNAME
	char scratch[16];
#endif
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
	char *filetime;
	time_t ttime, age;
#endif
#if defined(CONFIG_FEATURE_LS_FILETYPES) || defined (CONFIG_FEATURE_LS_COLOR)
	struct stat info;
	char append;
#endif

	if (dn->fullname == NULL)
		return (0);

#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
	ttime = dn->dstat.st_mtime;	/* the default time */
	if (all_fmt & TIME_ACCESS)
		ttime = dn->dstat.st_atime;
	if (all_fmt & TIME_CHANGE)
		ttime = dn->dstat.st_ctime;
	filetime = ctime(&ttime);
#endif
#ifdef CONFIG_FEATURE_LS_FILETYPES
	append = append_char(dn->dstat.st_mode);
#endif

	for (i = 0; i <= 31; i++) {
		switch (all_fmt & (1 << i)) {
		case LIST_INO:
			column += printf("%7ld ", (long int) dn->dstat.st_ino);
			break;
		case LIST_BLOCKS:
#if _FILE_OFFSET_BITS == 64
			column += printf("%4lld ", dn->dstat.st_blocks >> 1);
#else
			column += printf("%4ld ", dn->dstat.st_blocks >> 1);
#endif
			break;
		case LIST_MODEBITS:
			column += printf("%-10s ", (char *) bb_mode_string(dn->dstat.st_mode));
			break;
		case LIST_NLINKS:
			column += printf("%4ld ", (long) dn->dstat.st_nlink);
			break;
		case LIST_ID_NAME:
#ifdef CONFIG_FEATURE_LS_USERNAME
			my_getpwuid(scratch, dn->dstat.st_uid);
			printf("%-8.8s ", scratch);
			my_getgrgid(scratch, dn->dstat.st_gid);
			printf("%-8.8s", scratch);
			column += 17;
			break;
#endif
		case LIST_ID_NUMERIC:
			column += printf("%-8d %-8d", dn->dstat.st_uid, dn->dstat.st_gid);
			break;
		case LIST_SIZE:
		case LIST_DEV:
			if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) {
				column += printf("%4d, %3d ", (int) MAJOR(dn->dstat.st_rdev),
					   (int) MINOR(dn->dstat.st_rdev));
			} else {
#ifdef CONFIG_FEATURE_HUMAN_READABLE
				if (all_fmt & LS_DISP_HR) {
					column += printf("%9s ",
							make_human_readable_str(dn->dstat.st_size, 1, 0));
				} else
#endif
				{
#if _FILE_OFFSET_BITS == 64
					column += printf("%9lld ", (long long) dn->dstat.st_size);
#else
					column += printf("%9ld ", dn->dstat.st_size);
#endif
				}
			}
			break;
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
		case LIST_FULLTIME:
			printf("%24.24s ", filetime);
			column += 25;
			break;
		case LIST_DATE_TIME:
			if ((all_fmt & LIST_FULLTIME) == 0) {
				age = time(NULL) - ttime;
				printf("%6.6s ", filetime + 4);
				if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
					/* hh:mm if less than 6 months old */
					printf("%5.5s ", filetime + 11);
				} else {
					printf(" %4.4s ", filetime + 20);
				}
				column += 13;
			}
			break;
#endif
#ifdef CONFIG_SELINUX
		case LIST_CONTEXT:
			{
				char context[64];
				int len = sizeof(context);
				if(security_sid_to_context(dn->sid, context, &len))
				{
					strcpy(context, "unknown");
					len = 7;
				}
				printf("%-32s ", context);
				column += MAX(33, len);
			}
			break;
#endif
		case LIST_FILENAME:
#ifdef CONFIG_FEATURE_LS_COLOR
			errno = 0;
			if (show_color && !lstat(dn->fullname, &info)) {
				printf("\033[%d;%dm", bgcolor(info.st_mode),
					   fgcolor(info.st_mode));
			}
#endif
			column += printf("%s", dn->name);
#ifdef CONFIG_FEATURE_LS_COLOR
			if (show_color) {
				printf("\033[0m");
			}
#endif
			break;
		case LIST_SYMLINK:
			if (S_ISLNK(dn->dstat.st_mode)) {
				char *lpath = xreadlink(dn->fullname);

				if (lpath) {
					printf(" -> ");
#if defined(CONFIG_FEATURE_LS_FILETYPES) || defined (CONFIG_FEATURE_LS_COLOR)
					if (!stat(dn->fullname, &info)) {
						append = append_char(info.st_mode);
					}
#endif
#ifdef CONFIG_FEATURE_LS_COLOR
					if (show_color) {
						errno = 0;
						printf("\033[%d;%dm", bgcolor(info.st_mode),
							   fgcolor(info.st_mode));
					}
#endif
					column += printf("%s", lpath) + 4;
#ifdef CONFIG_FEATURE_LS_COLOR
					if (show_color) {
						printf("\033[0m");
					}
#endif
					free(lpath);
				}
			}
			break;
#ifdef CONFIG_FEATURE_LS_FILETYPES
		case LIST_FILETYPE:
			if (append != '\0') {
				printf("%1c", append);
				column++;
			}
			break;
#endif
		}
	}

	return column;
}
示例#5
0
文件: game.c 项目: jdp/psionrl
bool quit(void) {
	fgcolor(NULL, C_MSG);
	putstr(NULL, 1, 1, "Really quit? [yn]");
	update();
	return (choice("yn") == 'n');
}
示例#6
0
文件: game.c 项目: jdp/psionrl
/* The main game loop */
void play(void) {
	int playing = 1;
	int x, y, vpx, vpy;
	
	/* A messy way to do the map, works for now */
	map_t *map = map_new(50, 50);
	generate_cave(map);
	map_fov_build(map);
	
	/* Set up the offscreen consoles */
	map_layer = TCOD_console_new(ui_viewport_width, ui_viewport_height);
	psion_layer = TCOD_console_new(ui_viewport_width, ui_viewport_height);
	TCOD_console_set_key_color(psion_layer, C_KEY);
	bgcolor(psion_layer, C_KEY);
	
	/* Set up the player */
	init_player();
	rename_player("Gu the Cabeboy");
	blink_player(map);
	
	/* Initialize the inventory */
	
	
	/* Enter the main game loop! */
	while (playing) {
	
		/* Prepare the screen for drawing */
		clear(NULL);
		
		/* Calculate the position of the viewport */
		vpx = player->x - ui_viewport_width/2 > 0 ?
			  player->x - ui_viewport_width/2 : 0;
		vpy = player->y - ui_viewport_height/2 > 0 ?
			  player->y - ui_viewport_height/2 : 0;
		if ((vpx + ui_viewport_width) > map->width) {
			vpx = map->width - ui_viewport_width;
		}
		if ((vpy + ui_viewport_height) > map->height) {
			vpy = map->height - ui_viewport_height;
		}
		if (ui_viewport_width > map->width) {
			vpx = 0;
		}
		if (ui_viewport_height > map->height) {
			vpy = 0;
		}
			
		/* Calculate the field of view */
		map_fov_do(map, player->x, player->y);
		
		/* Only display the part of the map inside the viewport */
		for (y = 0; y < ui_viewport_height; y++) {
			for (x = 0; x < ui_viewport_width; x++) {
				if (((vpy+y) < map->height) && ((vpx+x) < map->width)) {
					tile_t *tile = tile_at(map, vpx+x, vpy+y);
					if (TCOD_map_is_in_fov(map->fov, vpx+x, vpy+y)) {
						fgcolor(map_layer, tile->fg_lit);
					}
					else {
						fgcolor(map_layer, tile->fg_dark);
					}
					putch(map_layer, x, y, tile->glyph);
				}
			}
		}
		
		TCOD_console_blit(map_layer, 0, 0, ui_viewport_width,
		                  ui_viewport_height, NULL, ui_viewport_x,
		                  ui_viewport_y, 255);
		
		/* Draw the player and status */
		fgcolor(NULL, C_WHITE);
		putch(NULL, ui_viewport_x+player->x-vpx, ui_viewport_y+player->y-vpy, '@');
		fgcolor(NULL, C_MSG);
		putstr(NULL, 1, 23, player->name);
		
		/* Redraw the screen */
		update();
		
		/* Handle keypress */
		TCOD_key_t k = getkey();
		if (k.c == 0) {
			switch (k.vk) {
				/* Move around */
				case TCODK_KP7: /* up left */
					attempt_move(map, player->x-1, player->y-1);
					break;
					
				case TCODK_KP8: /* up */
				case TCODK_UP:
					attempt_move(map, player->x, player->y-1);
					break;
					
				case TCODK_KP9: /* up right */
					attempt_move(map, player->x+1, player->y-1);
					break;
					
				case TCODK_KP1: /* down left */
					attempt_move(map, player->x-1, player->y+1);
					break;
				
				case TCODK_KP2: /* down */
				case TCODK_DOWN:
					attempt_move(map, player->x, player->y+1);
					break;
					
				case TCODK_KP3: /* down right */
					attempt_move(map, player->x+1, player->y+1);
					break;
				
				case TCODK_KP4: /* left */
				case TCODK_LEFT:
					attempt_move(map, player->x-1, player->y);
					break;
				
				case TCODK_KP6: /* right */
				case TCODK_RIGHT:
					attempt_move(map, player->x+1, player->y);
					break;
				
				/* View character summary */
				case TCODK_TAB:
					character();
					break;
				
				default:
					printf("%d %d\n", TCODK_TAB, k.vk);
					break;
			}
		}
		else {
			switch (k.c) {
				
				/* Quit the game */
				case 'Q':
					playing = quit();
					break;
				
				/* Open up the inventory */
				case 'i':
					inventory();
					break;
				
				/* View character summary */
				case 'c':
					character();
					break;
					
				/* Use scan ability */
				case 's':
					psion_scan(map);
					break;
				
				default:
					break;
			}
		}
	}
	
	/* Clean up, the game is over */
	map_destroy(map);
}