Пример #1
0
void
draw_msgf(const char title[], const char ctrl_msg[], int recommended_width,
		const char format[], ...)
{
	char msg[8192];
	va_list pa;

	va_start(pa, format);
	vsnprintf(msg, sizeof(msg), format, pa);
	va_end(pa);

	draw_msg(title, msg, ctrl_msg, 0, recommended_width);
	touch_all_windows();
	wrefresh(error_win);
}
Пример #2
0
void ofApp::draw()
{
	ofBackground(0);
	if (gen_fb)
	{
		draw_fb();
	}
	if (gen_tw)
	{
		draw_tw();
	}
	
	draw_block();
	if(centering)
		center_map();
	
	ofSetColor(255, 155, 0, 255);
	ofDrawRectangle(0, 0, map_win_x1, 1000);
	ofSetColor(0, 0, 0);
	ofDrawRectangle(0, 0, (map_win_x1-2), 1000);
	
	ofSetColor(255, 155, 0, 255);
	ofDrawRectangle(0, 0, 10000, 200); 
	ofSetColor(0, 0, 0);
	ofDrawRectangle(0, 0, 10000, 198);
	
	ofSetColor(255, 155, 0, 255);
	ofDrawRectangle(0, map_win_y2, 10000, 150);
	ofSetColor(0, 0, 0);
	ofDrawRectangle(0, (map_win_y2+2), 10000, 150);
	
	ofDrawRectangle(0, 0, (map_win_x1-2), 1000);
	
	ofSetColor(255, 155, 0, 255);
	ofDrawRectangle(map_win_x2, 0, 10000, 800);
	ofSetColor(0, 0, 0);
	ofDrawRectangle((map_win_x2+2), 0, 10000, 800);
	
	ofDrawRectangle(0, 0, 1000, (map_win_y1-2));
	ofDrawRectangle(0, (map_win_y2+2), 10000, 1000);
	
	/*draw GUI*/
	gui.draw();
	print_fb_users();
	print_tw_users();
	draw_msg();
	update();
}
Пример #3
0
/* Draws error message on the screen or redraws the last message when both
 * title_arg and message_arg are NULL. */
static void
redraw_error_msg(const char title_arg[], const char message_arg[],
		int prompt_skip, int lazy)
{
	/* TODO: refactor this function redraw_error_msg() */

	static const char *title;
	static const char *message;
	static int ctrl_c;

	const char *ctrl_msg;
	const int centered = (msg_kind == D_QUERY);

	if(title_arg != NULL && message_arg != NULL)
	{
		title = title_arg;
		message = message_arg;
		ctrl_c = prompt_skip;
	}

	if(title == NULL || message == NULL)
	{
		assert(title != NULL && "Asked to redraw dialog, but no title is set.");
		assert(message != NULL && "Asked to redraw dialog, but no message is set.");
		return;
	}

	ctrl_msg = get_control_msg(msg_kind, ctrl_c);
	draw_msg(title, message, ctrl_msg, centered, 0);

	if(lazy)
	{
		wnoutrefresh(error_win);
	}
	else
	{
		wrefresh(error_win);
	}
}
Пример #4
0
static void refresh_display(void)
{
    struct xy pos;
    int i;

    do_refresh = 0;

    draw_clear();

    draw_activity(1);

    switch (visual) {
    case VIEW_SATS:
	draw_sats(&gps_state);
	break;

    case VIEW_MAP:
	/* show map scale */
	if (show_scale)
	    draw_scale();

	/* show gps coordinates */
	if (show_gpscoords)
	    draw_gpscoords();

	vfdlib_setClipArea(0, 0, VFD_WIDTH - VFD_HEIGHT, VFD_HEIGHT);

	/* draw tracklog */
	if (show_track)
	    track_draw();

	/* draw route we're following */
	route_draw(&gps_coord.xy);

	/* highlight waypoints */
	i = 0;
	while (route_getwp(i, &pos, NULL, NULL)) {
	    draw_point(&pos, VFDSHADE_BRIGHT);
	    if (i++ != nextwp) continue;

	    /* add focus to next waypoint */
	    draw_mark(&pos, -1, VFDSHADE_MEDIUM);
	}

	/* draw our own location */
	draw_mark(&gps_coord.xy, gps_bearing, VFDSHADE_BRIGHT);

	vfdlib_setClipArea(0, 0, VFD_WIDTH, VFD_HEIGHT);
	draw_info();
	break;

    case VIEW_ROUTE:
	draw_wpstext();
	break;
    }

    if (load_route)
	routes_list();
    else if (menu) 
	draw_msg(menu_msg[menu_pos]);

    else if (lastmenu) {
	char *msg=NULL;
	lastmenu--;
	switch(menu_pos) {
	case 2: switch (show_popups) {
		case 0: msg = "No Popups"; break;
		case 1: msg = "Popups"; break;
		case 2: msg = "Permanent Popups"; break;
		}
		break;
	case 3: msg = (show_metric?"Meters":"Miles"); break;
	case 4: msg = (show_gpscoords?"Coordinates":"No Coordinates"); break;
	case 5: msg = (show_time?"Time":"Distance"); break;
	case 6: msg = (show_track?"Track":"No Track"); break;
	case 7: switch (coord_format) {
		case 0: msg = "DDD Coords"; break;
		case 1: msg = "DMM Coords"; break;
		case 2: msg = "DMS Coords"; break;
		}
		break;
	}
	if (msg)
	    draw_msg(msg);
    }

    draw_display();

#ifndef __arm__
    {
	extern int stats_toTM;
	extern int stats_distance;
	extern int stats_bearing;

	fprintf(stderr, "conv stats: GPS>TM %d DIST %d HDG %d\n",
		stats_toTM, stats_distance, stats_bearing);
	stats_toTM = stats_distance = stats_bearing = 0;
    }
#endif
}
Пример #5
0
int main(int argc, char **argv)
{
    const char *menu[] = { "GPSapp", NULL };
    struct timeval timeout;
    int rc = 0;

    if (empeg_init() == -1)
	exit(0);

    /* set a default protocol, now we only complain when the user specifies an
     * unknown protocol in config.ini */
    serial_protocol("NMEA");

    /* For backward compatibility as the user can specify the protocol in
     * config.ini */
    if (argc > 1)
	serial_protocol(argv[1]);

    init_gpsapp();

    printf("GPS app started\n");

    vfdlib_registerFont("empeg/lib/fonts/small.bf", 0);
    vfdlib_registerFont("empeg/lib/fonts/large.bf", 1);
    h0 = vfdlib_getTextHeight(0);

    route_init();

    while (rc != -1) {
	if (empeg_waitmenu(menu) == -1)
	    break;

	serial_open();

	draw_msg("Waiting for data from GPS receiver");
	draw_display();

	while(1) {
	    rc = handle_input();
	    if (rc) break;

	    if (do_refresh)
		refresh_display();

	    /* pause a bit to avoid burning CPU cycles */
	    timeout.tv_sec = 0;
	    timeout.tv_usec = 100000;
	    select(0, NULL, NULL, NULL, &timeout);
	}
#ifndef __arm__
	break;
#endif
    }

    serial_close();
    route_init();

    draw_msg("GPS app dying...");
    draw_display();
    sleep(5);

    vfdlib_unregisterAllFonts();
    empeg_free();
    exit(0);
}
Пример #6
0
//Draws the main GUI
static void draw_window()
{
	/**0**************************/
	/**1*XXX    BlackJack    XXX**/
	/**2*******XXXXX Wins!********/
	/**3**************************/
	/**4**************************/
	/**5**************************/
	/**6**************************/
	/**7**************************/
	/**8***Dealer*****Your Hand***/
	/**9***#######****#######*****/
	/*10*****(##)*******(##)******/
	/*11**************************/
	/*12*Bid      STAY       Pot**/
	/*13*110               11100**/
	/*14**************************/

	char buf[128];
	int i, width, height, depth;

	GrSetGCUseBackground(blackjack_gc, GR_TRUE);
	GrSetGCBackground(blackjack_gc, WHITE);

	GrSelectEvents(blackjack_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_KEY_DOWN|
				   GR_EVENT_MASK_KEY_UP|GR_EVENT_MASK_TIMER);

	GrSetGCForeground(blackjack_gc, WHITE);

	GrFillRect(blackjack_wid, blackjack_gc, 0, 0,
			   screen_info.cols, screen_info.rows - HEADER_TOPLINE);

	GrSetGCForeground(blackjack_gc, BLACK);

	/*1*/		draw_header();

	/*2*/		draw_msg();


	/*8-9-10*/	if(gameRunning == 1)
				{
					/*8-1*/	GrGetGCTextSize (blackjack_gc, "Dealer", -1, GR_TFASCII, &width, &height, &depth);
							GrText(blackjack_wid, blackjack_gc,
								  (screen_info.cols / 3.5) - (width / 2),
								   45, "Dealer",  -1, GR_TFASCII);

					/*9-1*/ strcpy(buf, " ");

							for(i=0;i<dealer_ncards;i++)
							{
								if(winner == NONE)
								{
									sprintf(buf, "%s%s ", buf, (i == 1) ? cardLetter(dealer_cards[i]) : "X");
								}else{
									sprintf(buf, "%s%s ", buf, cardLetter(dealer_cards[i]));
								}
							}

							GrGetGCTextSize (blackjack_gc, buf, -1, GR_TFASCII, &width, &height, &depth);
							GrText(blackjack_wid, blackjack_gc,
								  (screen_info.cols / 3.5) - (width / 2),
								   58, buf,  -1, GR_TFASCII);

					/*10-1*/if(winner != NONE)
							{
								sprintf(buf, "(%i)", dealer_hand);
								GrGetGCTextSize (blackjack_gc, buf, -1, GR_TFASCII, &width, &height, &depth);
								GrText(blackjack_wid, blackjack_gc,
									  (screen_info.cols / 3.5) - (width / 2),
									   70, buf,  -1, GR_TFASCII);
							}


					/*8-2*/	GrGetGCTextSize (blackjack_gc, "You Hand", -1, GR_TFASCII, &width, &height, &depth);
							GrText(blackjack_wid, blackjack_gc,
								  (screen_info.cols / 1.5) - (width / 2),
								   45, "Your Hand",  -1, GR_TFASCII);

					/*9-2*/ strcpy(buf, " ");

							for(i=0;i<player_ncards;i++)
							{
								sprintf(buf, "%s%s ", buf, cardLetter(player_cards[i]));
							}

							GrGetGCTextSize (blackjack_gc, buf, -1, GR_TFASCII, &width, &height, &depth);
							GrText(blackjack_wid, blackjack_gc,
								  (screen_info.cols / 1.5) - (width / 2),
								   58, buf,  -1, GR_TFASCII);

					/*10-2*/sprintf(buf, "(%i)", player_hand);
							GrGetGCTextSize (blackjack_gc, buf, -1, GR_TFASCII, &width, &height, &depth);
								GrText(blackjack_wid, blackjack_gc,
								  	  (screen_info.cols / 1.5) - (width / 2),
								   	   70, buf,  -1, GR_TFASCII);
				}


	/*12-1*/	GrText(blackjack_wid, blackjack_gc, 1,
				   screen_info.rows - 37, "Bet",  -1, GR_TFASCII);

	/*12-2*/	if(player_stay == 1 && winner == NONE)
				{
					GrGetGCTextSize (blackjack_gc, "STAY", -1, GR_TFASCII, &width, &height, &depth);
					GrText(blackjack_wid, blackjack_gc,
						  (screen_info.cols / 2) - (width / 2),
						   screen_info.rows - 37, "STAY",  -1, GR_TFASCII);
				}

	/*12-3*/	GrText(blackjack_wid, blackjack_gc,
					   screen_info.cols - 18,
					   screen_info.rows - 37, "Pot",  -1, GR_TFASCII);


	/*13-1*/		sprintf(buf, "%ld", player_bet);
				GrText(blackjack_wid, blackjack_gc, 1,
				screen_info.rows - 25, buf,  -1, GR_TFASCII);

	/*13-2*/		sprintf(buf, "%ld", player_pot);
				GrGetGCTextSize (blackjack_gc, buf, -1, GR_TFASCII, &width, &height, &depth);
				GrText(blackjack_wid, blackjack_gc,
					   screen_info.cols - (width + 2),
					   screen_info.rows - 25, buf,  -1, GR_TFASCII);

}
Пример #7
0
int main()
{
    srand( time(NULL) );
    
    struct termios defs;    //Se guarda el estado actual de termios.
    tcgetattr(0,&defs);     //No queremos contaminar el tty del usuario
                            //(Asi es, el tty, no solo el proceso!)                          
	int startx, starty;

	initscr();			/* Start curses mode 		*/
	cbreak();			/* Line buffering disabled, Pass on */
					    /* everty thing to me 		*/
    start_color();
    use_default_colors();
    init_pair(1, COLOR_GREEN, -1);
    init_pair(2, COLOR_RED, -1);
    init_pair(3, COLOR_YELLOW, COLOR_RED);
    init_pair(4, COLOR_YELLOW,-1);
	keypad(stdscr, TRUE);		/* Activa las teclas de control. */

	starty = (LINES - HEIGHT) / 4;	/* Calcula la posición del centro de la pantalla */
	startx = (COLS - WIDTH) / 2;
	printw("Presione Q para salir");
	refresh();
	my_win = create_newwin(HEIGHT, WIDTH, starty, startx);
	stats = create_newwin(6,30,starty, startx+60);
	msgs = create_newwin(9,80,starty+30,startx-13);
	struct Animal *player;
    player = (struct Animal *)malloc(sizeof(struct Animal));
	draw_welcome(my_win,msgs,&player);
	my_win = create_newwin(HEIGHT, WIDTH, starty, startx);
    struct Nodo *cList = NULL;      //  ]
    struct Nodo *hList = NULL;      //   -> Los animales leidos se guardan en éstas listas.
    struct Nodo *pList = NULL;      //  ]
    int lim = loadData(&cList,&hList,&pList); //Carga las listas de animales, y devuelve el número de comidas.
    struct Cell matrix[9][9];
    initMatrix(matrix);
    int px = matrix[4][4].xpos;
    int py = matrix[4][4].ypos;
    
    //GAME LOOP:
    //Primero, setear modo no-canonico
    //Esto permite obtener input en tiempo real
    //y no bloquar la ejecución mientras el usuario juega.

    nonCanonical();
    char ch; int end = 0; int i = 0; int j = 0;
    while(!end)
	{
	    ch = '0';
	    read(0,&ch,1);      //Se lée el (posible) input del usuario.
	    if(!(i % 3))
    	    iterateMatrix(matrix,player);   //Los NPC reaccionan cada 3 ticks.
    	i++;
	    switch(ch)
		{	case 'a':
		        if(!apply(matrix,player,&cList,&hList,&pList,'l'))
	                draw_matrix(my_win,matrix,player);
               	wrefresh(my_win);
				break;
			case 'd':
			    if(!apply(matrix,player,&cList,&hList,&pList,'r'))
    	            draw_matrix(my_win,matrix,player);
	            wrefresh(my_win);
				break;
			case 'w':
			    if(!apply(matrix,player,&cList,&hList,&pList,'u'))
	                draw_matrix(my_win,matrix,player);
	            wrefresh(my_win);
   				break;
			case 's':
			    if(!apply(matrix,player,&cList,&hList,&pList,'d'))
	                draw_matrix(my_win,matrix,player);
	            wrefresh(my_win);
				break;
		    case 'q':
		        end = 1;
		        break;
		    default: draw_matrix(my_win,matrix,player);
		}
		if(player->eat(player,0) >= lim)
		{
		    draw_msg("Limite de comidas alcanzado! Felicitaciones!",msg_buffer);
            draw_msg("                                            ",msg_buffer);
            draw_msg("                                            ",msg_buffer);
		    canonical(&defs);
            getch();
		    end = 1;
		}
		if(player)
		    draw_stats(stats, player, lim);
		if(player->getHP(player) < 1)
		{
            wattron(my_win,COLOR_PAIR(3));
            for(i=-1;i<2;i++)
                for(j=-1;j<2;j++)
                    mvwprintw(my_win,px+i,py+j," ");
            mvwprintw(my_win,px,py,"X");
            wattroff(my_win,COLOR_PAIR(3));
            wrefresh(my_win);
            draw_msg("Has sido devorado...                      ",msg_buffer);
            draw_msg("                                          ",msg_buffer);
            draw_msg("                                          ",msg_buffer);
            end = 1;
            canonical(&defs);
            getch();
        }		    
	}
    canonical(&defs);
	endwin();			/* End curses mode		  */
    
    return 0;
}