Ejemplo n.º 1
0
int main()
{
		WINDOW *menubar, *statusbar, *about;
		int key;
		init_scr();
		bkgd(COLOR_PAIR(1));
		menubar = subwin(stdscr, 1, 80, 0, 0);
		statusbar = subwin(stdscr, 1, 79, 23, 1);
		make_menubar(menubar);
		move(2, 1);
		printw("Press 'a' or 'h' to open the menus. ");
		printw("ESC or 'q' quits.");
		refresh();    
		while(1)
		{
				WINDOW **menu_items;            
				int selected_item;

				key = getch();
				werase(statusbar);
				wrefresh(statusbar);

				if (key == 'a')
				{
						menu_items=file_menu_list(0);
						selected_item = scroll_menu(menu_items, 4, 20, 0); 
						delete_menu(menu_items, 5);
						if (selected_item < 0)
								wprintw(statusbar, "You haven't selected any item");
						else
								wprintw(statusbar, "You have selected menu item %d.", selected_item);
						touchwin(stdscr);
						refresh();    
				}
				if (key == 'h')
				{
						menu_items=help_menu_list(20);
						selected_item = scroll_menu(menu_items, 2, 0, 1); 
						delete_menu(menu_items, 3);
						if (selected_item == 1)
						{
								about_window();
						}
						if (selected_item < 0)
								wprintw(statusbar, "You haven't selected any item");

				}
				if (key == ESCAPE || key == 'q')
				{
						if (check_quit() == 1)
								break;
				}
				touchwin(stdscr);
				refresh();    
		}
		endwin();
}
Ejemplo n.º 2
0
void	exit_rsrc( void )
{
	delete_menu();
	
	if( vdi_handle != -1 )
	{
		if (gl_gdos)
			vst_unload_fonts(vdi_handle, 0);

		v_clsvwk(vdi_handle);		
	}
}
Ejemplo n.º 3
0
/* menu handler */
void menu_handler(void) {

  int c;

  keypad(sub_window,TRUE);  /* enable keypad on the menu */
  wtimeout(sub_window,-1);  /* wait for input */

  while((c=wgetch(sub_window))) {
    switch (c) {
      case KEY_MOUSE:
        menu_driver(menu_ptr,KEY_MOUSE);
        break;
      case 9: /* TAB */
      case 'k':
      case KEY_DOWN:
        menu_driver(menu_ptr,REQ_DOWN_ITEM);
        break;
      case 'j':
      case KEY_UP:
        menu_driver(menu_ptr,REQ_UP_ITEM);
        break;
      case 27:  /* ESC */
      case 'q':
        delete_menu();
        finish(0);
        break;
      case 13:
      case KEY_ENTER:
      case KEY_RIGHT:
        func_ptr = item_userptr(current_item(menu_ptr));
        delete_menu();
        return;
      default: break;
    }
  }
  
  return;
}
Ejemplo n.º 4
0
/*Le menu de séléction de fichier*/
int select_file_menu()
{
	int nb = NB_LEVEL, i;
	Menu menu;
	init_menu(&menu, nb+1);
	menu.font_size=25;
	menu.space=30;
	strcpy(menu.title, "Choississez un niveau");
	for(i=0; i<nb; i++) sprintf(menu.options[i], "%s", LEVEL_FILE[i]);
	strcpy(menu.options[i], "Annuler");
	int selection = draw_menu(menu);
	delete_menu(&menu);
	return selection;
}
Ejemplo n.º 5
0
/*Quand on appuis echap lors d'une partie*/
int game_menu()
{
	int nb = 3;
	Menu menu;
	init_menu(&menu, nb);
	strcpy(menu.title, "PAUSE");
	strcpy(menu.options[0], "CONTINUER");
	strcpy(menu.options[1], "SAUVER");
	strcpy(menu.options[2], "MENU PRINCIPAL");
	if(!SAVE_ENABLE) menu.available[1]=0;
	int selection = draw_menu(menu);
	delete_menu(&menu);
	return selection;
}
Ejemplo n.º 6
0
/*Loersque l'on appuie echap dans l'editeur*/
int edit_menu()
{
	int nb=6;
	Menu menu;
	init_menu(&menu, nb);
	strcpy(menu.title, "MENU EDITEUR");
	strcpy(menu.options[0], "CONTINUER");
	strcpy(menu.options[1], "SAUVER");
	strcpy(menu.options[2], "CHARGER");
	strcpy(menu.options[3], "EFFACER");
	strcpy(menu.options[4], "TESTER");
	strcpy(menu.options[5], "QUITTER");
	menu.available[4]=0;
	int selection = draw_menu(menu);
	delete_menu(&menu);
	return selection;
}
Ejemplo n.º 7
0
/*Menu principal du jeu*/
int main_menu()
{
	int nb=9;
	Menu menu;
	init_menu(&menu, nb);
	strcpy(menu.title, "BIENVENUE DANS PACMAN!!");
	strcpy(menu.options[0], "CAMPAGNE");
	strcpy(menu.options[1], "EDIT CAMPAGNE");
	strcpy(menu.options[2], "PARTIE UNIQUE");
	strcpy(menu.options[3], "SURVIVOR");
	strcpy(menu.options[4], "CHARGER");
	strcpy(menu.options[5], "EDITER");
	strcpy(menu.options[6], "OPTIONS");
	strcpy(menu.options[7], "HIGH SCORE");
	strcpy(menu.options[8], "QUITTER");
	if(!has_saved_game()) menu.available[4]=0;
	int selection = draw_menu(menu);
	delete_menu(&menu);
	return selection;
}
Ejemplo n.º 8
0
int save_menu(int level)
{
	int nb=3;
	Menu menu;
	init_menu(&menu, nb);
	strcpy(menu.title, "SAVE MENU");
	if(level>=0)
	{
		strcpy(menu.options[0], LEVEL_FILE[level]);
	}
	else
	{
		strcpy(menu.options[0], " ");
		menu.available[0]=0;
	}
	strcpy(menu.options[1], "NEW FILE");
	strcpy(menu.options[2], "ANNULER");
	int selection = draw_menu(menu);
	delete_menu(&menu);
	return selection;
}
Ejemplo n.º 9
0
void start_menu_destruct(){
	delete_menu(start_menu);
	bitmap_delete(title);
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: mikhama/Ntris
int main(int argc, char *argv[]) {
    int mode = 0;
    initscr();  /* Start curses mode */
    start_color(); /* Start color functionality */
    
    init_pair(10,COLOR_WHITE,COLOR_WHITE);
    init_pair(11,COLOR_YELLOW,COLOR_YELLOW);
    init_pair(12,COLOR_MAGENTA,COLOR_MAGENTA);
    init_pair(13,COLOR_CYAN,COLOR_CYAN);
    init_pair(14,COLOR_GREEN,COLOR_GREEN);
    init_pair(15,COLOR_RED,COLOR_RED);
    init_pair(16,COLOR_BLUE,COLOR_BLUE);
    init_pair(17,COLOR_WHITE,COLOR_WHITE);
    init_pair(18,COLOR_YELLOW,COLOR_YELLOW);
    init_pair(19,COLOR_MAGENTA,COLOR_MAGENTA);
    init_pair(20,COLOR_BLACK,COLOR_WHITE);
    init_pair(21,COLOR_BLACK,COLOR_YELLOW);
    init_pair(22,COLOR_WHITE,COLOR_MAGENTA);
    init_pair(23,COLOR_WHITE,COLOR_CYAN);
    init_pair(24,COLOR_WHITE,COLOR_GREEN);
    init_pair(25,COLOR_WHITE,COLOR_RED);
    init_pair(26,COLOR_WHITE,COLOR_BLUE);
    
    curs_set(0);
    noecho();
    keypad(stdscr,TRUE);
    refresh();
    
    WINDOW **logo;
    WINDOW **menu;

    int i = 0;
    int score = 0;
    while (i == 0) {
        logo = draw_logo();
        menu = draw_menu();
        if (score > 0 ) {
            mode = 1;
        }
        else {
            mode = scroll_menu(menu);
        }
        switch (mode) {
            case 0:
                delete_menu(menu,5);
                delete_menu(logo,169);
                score = tetris_init();
                break;
            case 1:
                delete_menu(menu,5);
                if (score > 0) {
                    draw_hiscores(1,score);
                } 
                else {
                    draw_hiscores(0,score);
                }
                score = 0;
                break;
            case 2:
                delete_menu(menu,5);
                draw_help();
                break;
            case 3:
                delete_menu(menu,5);
                delete_menu(logo,169);
                i = 1;
                break;
        }
    }

    /*getch();*/
    
    endwin(); /* End curses mode */
}
Ejemplo n.º 11
0
static int
create_menu(const char *fname, const char *shellcmd) 
{
	FILE *fp;
	long fidx;
	unsigned int idx = 0;
	unsigned long tlen;
	char buf[MAX_LINE_LENGTH];
	char *pbuf;
	unsigned int readTitle = 1;
	unsigned int headerLine = 0;
 
	//call the script if available
	if (shellcmd != NULL)
	{
		char menu_file_var[256];	
		char* extra_env_vars[] = 
		{ 
			menu_file_var, 
			NULL 
		};
		
		fprintf(stderr, "Running menu script %s.\n", shellcmd);		
		sprintf(menu_file_var, "MENU_FILE="CUSTOM_MENU_PATH"/%s", fname);
		run_shell_script(shellcmd, 0, extra_env_vars);
	}	

	sprintf(buf, CUSTOM_MENU_PATH"/%s", fname);
	fp = fopen(buf, "r");

	if(fp == NULL)
	{
		fprintf(stderr, "Unable to open %s.\n", buf);
		LOGE("Failed to open the menu %s.\n", fname);
		return -1;
	}
	else
		fprintf(stderr, "Opening %s.\n", buf);
		
	delete_menu();	

	while((idx<MAX_MENU_ITEMS)&&(fgets(buf, sizeof(buf), fp)!=NULL)) 
	{
		if((*buf == '\0') || (*buf == '#')) 
			continue;
	
		if (readTitle)
		{
			fidx = strlen(buf) - 1;
			
			while(fidx >= 0 && (buf[fidx] == ' ' || buf[fidx] == '\r' || buf[fidx] == '\n'))
			{
		 		buf[fidx] = '\0';
		 		fidx--;
			}
		
			//right now, just one line is used
			MENU_HEADERS[0] = malloc(strlen(buf) + 1);
			MENU_HEADERS[1] = malloc(1);
			MENU_HEADERS[2] = NULL;
			strcpy(MENU_HEADERS[0], buf);
			strcpy(MENU_HEADERS[1], "");
			fprintf(stderr, "Menu Title: %s.\n", MENU_HEADERS[0]);
			readTitle = 0;
			continue;
		}

		if(strstr(buf, ":") == NULL) 
			continue;

		pbuf = strtok(buf, ":");
		if(pbuf == NULL) 
			continue;
		
		MENU_ITEMS[idx] = malloc(strlen(pbuf) + 1);
		strcpy(MENU_ITEMS[idx], pbuf);

		pbuf = strtok(NULL, ":");
		if(pbuf == NULL) 
		{
			free(MENU_ITEMS[idx]);
			MENU_ITEMS[idx] = NULL;
			
			fprintf(stderr, "Invalid line: %s", buf);
			continue;
		}
		
		MENU_ITEMS_ACTION[idx] = malloc(strlen(pbuf) + 1);
		strcpy(MENU_ITEMS_ACTION[idx], pbuf);

		pbuf = strtok(NULL, "\n");
		if(pbuf == NULL) 
		{
			free(MENU_ITEMS[idx]);
			MENU_ITEMS[idx] = NULL;
			
			free(MENU_ITEMS_ACTION[idx]);
			MENU_ITEMS_ACTION[idx] = NULL;
			
			fprintf(stderr, "Invalid line: %s", buf);
			continue;
		}

		if(strlen(pbuf) > 0) 
		{
			fidx = strlen(pbuf) - 1;

			while(fidx >= 0 && (pbuf[fidx] == ' ' || pbuf[fidx] == '\r'))
			{
		 		pbuf[fidx] = '\0';
		 		fidx--;
			}

			MENU_ITEMS_SELECTABLE[idx] = 0x01; 

			if(!strcmp(MENU_ITEMS_ACTION[idx], ITEM_NAME_SHELL_SCRIPT))
			{
				if (pbuf[0] == '/' || (pbuf[0] == '\"' && pbuf[1] == '/'))
				{			
					MENU_ITEMS_TARGET[idx] = malloc(strlen(pbuf)+1);
					strcpy(MENU_ITEMS_TARGET[idx], pbuf);
				}
				else
				{
					MENU_ITEMS_TARGET[idx] = malloc(strlen(CUSTOM_SHELL_SCRIPT_PATH) + strlen(pbuf) + 2);
					
					if (pbuf[0] == '\"')
						sprintf(MENU_ITEMS_TARGET[idx], "\"%s/%s", CUSTOM_SHELL_SCRIPT_PATH, pbuf+1);	
					else
						sprintf(MENU_ITEMS_TARGET[idx], "%s/%s", CUSTOM_SHELL_SCRIPT_PATH, pbuf);					
				}
			}
			else if(!strcmp(MENU_ITEMS_ACTION[idx], ITEM_NAME_TAG))
			{
				MENU_ITEMS_TARGET[idx] = malloc(strlen(TAGS_PATH) + strlen(pbuf) + 3);
				sprintf(MENU_ITEMS_TARGET[idx], "%s/.%s", TAGS_PATH, pbuf);
			
				//Add the "[ ] " before the name, but first check if the status
				struct stat buf;
 				int fstat = stat(MENU_ITEMS_TARGET[idx], &buf);
 				MENU_ITEMS_TAG[idx] = fstat ? 0x00 : 0x01;
 				char tag = fstat ? ' ' : 'X';	   									
				char* oldItem = MENU_ITEMS[idx];
				MENU_ITEMS[idx] = malloc(strlen(oldItem) + 5);
				sprintf(MENU_ITEMS[idx], "[%c] %s", tag, oldItem);
				free(oldItem);
			}
			else if(!strcmp(MENU_ITEMS_ACTION[idx], ITEM_NAME_MENU_BREAK))
			{
				MENU_ITEMS_SELECTABLE[idx] = 0x00;
				int len = strlen(MENU_ITEMS[idx]);
				char* oldItem = MENU_ITEMS[idx];
				int i = 0;
				int num_cols = ui_get_num_columns();
				MENU_ITEMS[idx] = malloc(num_cols + 1);
				
				if (len == 1 && oldItem[0] == '*')
				{
					//fill it all
					while(i < num_cols)
					{
						MENU_ITEMS[idx][i] = '-';
						i++;
					}
				}
				else
				{					
					if (len > num_cols - 4)
						len = num_cols - 4;
				
					//start with '-'	
					while(i < (num_cols - len - 2) / 2)
					{
						MENU_ITEMS[idx][i] = '-';
						i++;
					}
				
					//now space
					MENU_ITEMS[idx][i] = ' ';
					i++;
				
					//now the string, max 44 characters
					strncpy(&(MENU_ITEMS[idx][i]), oldItem, len);
					i += len;
				
					//now space
					MENU_ITEMS[idx][i] = ' ';
					i++;
				
					//end with '-'
					while(i < num_cols)
					{
						MENU_ITEMS[idx][i] = '-';
						i++;
					}
				
					//null terminator
					MENU_ITEMS[idx][num_cols] = '\0';
					free(oldItem);
				
					MENU_ITEMS_TARGET[idx] = malloc(2);
				 	strcpy(MENU_ITEMS_TARGET[idx], "*");
				} 
			}
			else 
			{
				MENU_ITEMS_TARGET[idx] = malloc(strlen(pbuf) + 1);
			 	strcpy(MENU_ITEMS_TARGET[idx], pbuf);	
			 	
			 	if (!strcmp(MENU_ITEMS_ACTION[idx], ITEM_NAME_MENU_LABEL))
			 		MENU_ITEMS_SELECTABLE[idx] = 0x00;
			}
		}

		fprintf(stderr, "ITEM[%d]: %s - %s - %s\n", idx, MENU_ITEMS[idx], MENU_ITEMS_ACTION[idx], MENU_ITEMS_TARGET[idx]);
		idx++;
	} 

	fclose(fp);
	return 0;
}
Ejemplo n.º 12
0
int save_map(){
	int i = 0, j = 115, tru = 1;
	char Key;
	buffer[0] = '\0';
	int x1 = 100, y1 = 2, x2 = 145, y2 = 17, min = 115, max = 130, mv = 8, ind1 = 4;
	FILE  *saved_maps;

	print_border(y1, x1, y2, x2);
	mvprintw(y1 + 1, x1 + 15, " S A V E  M A P  A S");
	mvprintw(y1 + 6, x1 + 2, " Map Name :  _______________");
	mvprintw(y1 + 13, x1 + 2, "ESC : Return to main menu ");
	attron(COLOR_WHITE | A_REVERSE);
	mvprintw(y1 + 11, x1 + 1, " Max. 15 characters(letters & num allowed!)");
	attroff(COLOR_WHITE | A_REVERSE);
	refresh();
	while (tru)
	{

		switch (Key = getch()){
		case KEY_UP: case KEY_DOWN: case KEY_LEFT: case KEY_RIGHT:  break;
		case ENTER:if (buffer[0] == '\0') name_it(); else  tru = check_if_legit(buffer); break;
		default: if (j < max) 
		{ buffer[i++] = Key; buffer[i] = '\0'; mvaddch(y1 + 6, j++, Key); 
		}; refresh(); break;
		case BACKSPACE: if (j > min) 
		{ 
			buffer[--i] = '\0'; mvaddch(y1 + 6, --j, '_'); 
		}; refresh(); break;
		case ESC: delete_menu(y1, x1, y2, x2); return 1; break;
		}
	}
	buffer[i] = '.'; buffer[i + 1] = buffer[i + 3] = 't'; buffer[i + 2] = 'x'; buffer[i + 4] = '\0';
	save_it();
	if (!(saved_maps = fopen("saved_maps.txt", "r+"))) saved_maps = fopen("saved_maps.txt", "w");
	i = 0;
	while ((Key = fgetc(saved_maps)) != EOF){   // does this map already exist in the file?
		while (Key == buffer[i])
		{
			Key = fgetc(saved_maps);
			i++;
		}
		if (i == strlen(buffer)) break; else i = 0;
	}
	if (i == strlen(buffer)) fclose(saved_maps); else // if it does->do nothing, if it doesn't, then save it in the file;
	{
		fprintf(saved_maps, "%s\n", buffer);
		fclose(saved_maps);
	}

	delete_menu(y1, x1, y2, x2);
	print_border(y1, x1, y2, x2);
	mvprintw(y1 + 4, x1 + 2, " Continue with editting this map?");
	attron(COLOR_PAIR(8));
	mvprintw(y1 + 6, x1 + 18, " Yes ");
	attroff(COLOR_PAIR(8));
	mvprintw(y1 + 8, x1 + 18, " No ");
	refresh();
	while (1){
		switch (getch()){
		case KEY_UP: menu_up(&mv, y1 + 6, &ind1, x1 + 18); break;
		case KEY_DOWN: menu_down(&mv, y1 + 8, &ind1, x1 + 18); break;
		case ENTER: if (mv == 8)
		{
			delete_menu(y1, x1, y2, x2); return 0;
		}
					else
					{
						delete_menu(y1, x1, y2, x2); return 1;
					}
					break;
		}
	}


}