Esempio n. 1
0
menu_t *get_grub2() {
    return new_menu(install_grub2, uninstall_grub2,
            fix_grub2, check_fix_grub2,
            gen_grub2, append_grub2, remove_grub2);
}
Esempio n. 2
0
int main()
{	ITEM **my_items;
	int c;
	MENU *my_menu;
        WINDOW *my_menu_win;
        int n_choices, i;
	/* Initialize curses */
	initscr();
	start_color();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	clear();	
	refresh();
	init_pair(1, COLOR_RED, COLOR_BLACK);
	getmaxyx(stdscr,y,x);
	/* Create items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
        for(i=0;i<n_choices;++i)
	{
                my_items[i] = new_item(choices[i],"");
		set_item_userptr(my_items[i], func);
	}
	my_items[n_choices] = (ITEM *)NULL;
	/* Crate menu */
	my_menu = new_menu((ITEM **)my_items);
	/* Create the window to be associated with the menu */
        my_menu_win = newwin(10, 45, (y/2)-6,(x/2)-22 );
        keypad(my_menu_win, TRUE);
     
	/* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win);
        set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
	/* Set menu mark to the string " * " */
        set_menu_mark(my_menu, " * ");
	/* Print a border around the main window and print a title */
        box(my_menu_win, 0, 0);
	print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Ncurses Phone Book (NPB)", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
	mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
	mvprintw(LINES - 2, 0, "Press ESC to exit");
	refresh();
	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);
//upon();
	while((c = wgetch(my_menu_win)) != 27)
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10: /* Enter */
			{	ITEM *cur;
				void (*p)(char *);
				cur = current_item(my_menu);
				p = item_userptr(cur);
				p((char *)item_name(cur));
				refresh();
				//printw("%s",item_name(cur));
				if(!strcmp("[6] Exit",item_name(cur)))
				{
					unpost_menu(my_menu);
				        free_menu(my_menu);
					endwin();
					return 0;
				}
				else if(!strcmp("[3] Searching for a contact by name",item_name(cur)))
				{
					upon("Search by name");
					//if(strlen(str)>1)
					
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[4] Searching for a contact by number",item_name(cur)))
				{
					upon("Search by number");
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[2] Removing a contact",item_name(cur)))
				{
					upon("Enter contact name to remove");
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[5] Displaying contact list",item_name(cur)))
				{
					show();
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
				}
				else if(!strcmp("[1] Adding a contact",item_name(cur)))
				{
					int ret=uponadd();			
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
					if(ret==1)
					{
					int trash=outprint();
					clear();
					set_menu_sub(my_menu, derwin(my_menu_win, 6, 40, 3, 1));
					/* Set menu mark to the string " * " */
				        set_menu_mark(my_menu, " * ");
					/* Print a border around the main window and print a title */
				        box(my_menu_win, 0, 0);
					print_in_middle(my_menu_win, 1, 0, 45, "Welcome to Simple Phone Book Application", COLOR_PAIR(1));
					mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
					mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43);
					mvwaddch(my_menu_win, 2, 44, ACS_RTEE);
					mvprintw(LINES - 2, 0, "Press ESC to exit");
					refresh();
					/* Post the menu */
					post_menu(my_menu);
					wrefresh(my_menu_win);
					}
				}
				pos_menu_cursor(my_menu);
				break;
			}
		}
                wrefresh(my_menu_win);
	}	
	/* Unpost and free all the memory taken up */
        unpost_menu(my_menu);
        free_menu(my_menu);
//        for(i = 0; i < n_choices; ++i)
  //              free_item(my_items[i]);
	endwin();
}
Esempio n. 3
0
	tab_compl_n(dlg_data, item, strlen((const char *)item));
}

/* Complete to last unambiguous character, and display menu for all possible
 * further completions. */
void
do_tab_compl(struct dialog_data *dlg_data,
	     LIST_OF(struct input_history_entry) *history)
{
	struct terminal *term = dlg_data->win->term;
	struct widget_data *widget_data = selected_widget(dlg_data);
	int cpos = widget_data->info.field.cpos;
	int n = 0;
	struct input_history_entry *entry;
	struct menu_item *items = new_menu(FREE_LIST | NO_INTL);

	if (!items) return;

	foreach (entry, *history) {
		if (strncmp((char *)widget_data->cdata, (char *)entry->data, cpos))
			continue;

		add_to_menu(&items, entry->data, NULL, ACT_MAIN_NONE,
			    menu_tab_compl, entry->data, 0);
		n++;
	}

	if (n > 1) {
		do_menu_selected(term, items, dlg_data, n - 1, 0);
	} else {
Esempio n. 4
0
int main()
{
    ITEM **my_items;
	int c;				
	MENU *my_menu;
    WINDOW *my_menu_win;
    int n_choices, i;
	
	/* Initialize curses */
	initscr();
	start_color();
    cbreak();
    noecho();
	keypad(stdscr, TRUE);
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_CYAN, COLOR_BLACK);
    
	/* Create items */
    n_choices = ARRAY_SIZE(choices);
    my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
    for(i = 0; i < n_choices; ++i)
        my_items[i] = new_item(choices[i], choices[i]);
    
	/* Crate menu */
	my_menu = new_menu((ITEM **)my_items);
    
	/* Set menu option not to show the description */
	menu_opts_off(my_menu, O_SHOWDESC);
    
	/* Create the window to be associated with the menu */
    my_menu_win = newwin(10, 70, 4, 4);
    keypad(my_menu_win, TRUE);
    
	/* Set main window and sub window */
    set_menu_win(my_menu, my_menu_win);
    set_menu_sub(my_menu, derwin(my_menu_win, 6, 68, 3, 1));
	set_menu_format(my_menu, 5, 3);
	set_menu_mark(my_menu, " * ");
    
	/* Print a border around the main window and print a title */
    box(my_menu_win, 0, 0);
	
	attron(COLOR_PAIR(2));
	mvprintw(LINES - 3, 0, "Use PageUp and PageDown to scroll");
	mvprintw(LINES - 2, 0, "Use Arrow Keys to navigate (F1 to Exit)");
	attroff(COLOR_PAIR(2));
	refresh();
    
	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);
	
	while((c = wgetch(my_menu_win)) != KEY_F(1))
	{
        switch(c)
	    {
        case KEY_DOWN:
            menu_driver(my_menu, REQ_DOWN_ITEM);
            break;
        case KEY_UP:
            menu_driver(my_menu, REQ_UP_ITEM);
            break;
        case KEY_LEFT:
            menu_driver(my_menu, REQ_LEFT_ITEM);
            break;
        case KEY_RIGHT:
            menu_driver(my_menu, REQ_RIGHT_ITEM);
            break;
        case KEY_NPAGE:
            menu_driver(my_menu, REQ_SCR_DPAGE);
            break;
        case KEY_PPAGE:
            menu_driver(my_menu, REQ_SCR_UPAGE);
            break;
		}
        wrefresh(my_menu_win);
	}	

	/* Unpost and free all the memory taken up */
    unpost_menu(my_menu);
    free_menu(my_menu);
    for(i = 0; i < n_choices; ++i)
        free_item(my_items[i]);
	endwin();
}
Esempio n. 5
0
enum state game_update(enum state state, struct game* game, int key, key_event_t key_event) {
	struct player* players[game->nb_player];
	for(int i=0; i<game->nb_player; i++) {
		players[i] = game->players[i];
	}
	struct map* map = level_get_curr_map(game_get_curr_level(game));

	if(game->nb_player == 1 && player_get_key(players[0]) == -1)
		return(W);

	if(game->nb_player == 1 && player_get_key(players[0]) == -2)
		return(GO);

	if(key_event == DOWN) {
		switch (key) {
		case SDLK_p:
			if(game->game_state == CHOOSE_MAP)
				break;
		/* no break */
		case SDLK_ESCAPE:
		 // Pause
			if(game->game_state == PLAYING) {
				if(game->nb_player == 1)
					new_menu(PAUSE_SINGLE);
				else
					new_menu(PAUSE_MULTI);
				game->game_state = PAUSED;
			}
			else if(game->game_state == PAUSED){
				menu_free(NULL);
				game->game_state = PLAYING;
			}
			else if(game->game_state == CHOOSE_MAP) {
				return ENDGAME;
			}
			return GAME;
			break;
		case SDLK_RETURN:
		case SDLK_KP_ENTER:
			switch(game->game_state) {
			case PAUSED:

				switch(menu_update(state, key, key_event)) {
				case KEEP:
					menu_free(NULL);
					game->game_state = PLAYING;
					break;
				case MAINMENU:
					return ENDGAME;
					break;
				case QUIT:
					return(QUIT);
					break;
				case SAVEGAME_MAINMENU:
					file_savegame(game);
					return ENDGAME;
					break;
				case SAVEGAME_QUIT:
					file_savegame(game);
					return(QUIT);
					break;
				case CHANGEMAP:
					multi_change_state(game, CHOOSE_MAP);
					break;
				default:
					break;
				}

			break;
			case CHOOSE_MAP:
				multi_change_state(game, PLAYING);

				break;
			case SCORE:
				if(game_get_score_max(game, 0) < game->score_obj)
					multi_change_state(game, PLAYING);
				else
					multi_change_state(game, CHOOSE_MAP);

				break;
			default:
				break;
			}
			break;
		case SDLK_UP:
			if(game->game_state == PLAYING){
				player_set_way(players[0], NORTH);
				player_inc_moving(players[0]);
			}
			else if (game->game_state == PAUSED)
				return(menu_update(state, key, key_event));
			else if(game->game_state == CHOOSE_MAP) {
				if(game->pos > 0) {
					game->pos--;
					level_set_cur_map(game_get_curr_level(game), game->pos);
				}
			}
			break;
		case SDLK_DOWN:
			if(game->game_state == PLAYING){
				player_set_way(players[0], SOUTH);
				player_inc_moving(players[0]);
			}
			else if (game->game_state == PAUSED) {
				return(menu_update(state, key, key_event));
			}
			else if(game->game_state == CHOOSE_MAP) {
				if(game->pos < sprite_get_nb_map_multi() - 1) {
					game->pos++;
					level_set_cur_map(game_get_curr_level(game), game->pos);
				}
			}
			break;
		case SDLK_RIGHT:
			if(game->game_state == PLAYING){
				player_set_way(players[0], EAST);
				player_inc_moving(players[0]);
			}
			break;
		case SDLK_LEFT:
			if(game->game_state == PLAYING){
				player_set_way(players[0], WEST);
				player_inc_moving(players[0]);
			}
			break;
		case SDLK_SPACE:
			if(game->game_state == PLAYING)
				bomb_plant(game, map, players[0]); // the bomb is planted if it is possible
			break;
		case SDLK_z:
			if(game->nb_player >= 2)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[1], NORTH);
					player_inc_moving(players[1]);
				}
				else if (game->game_state == PAUSED) {
					return(menu_update(state, key, key_event));
				}
			}
			break;
		case SDLK_s:
			if(game->nb_player >= 2)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[1], SOUTH);
					player_inc_moving(players[1]);
				}
				else if (game->game_state == PAUSED) {
					return(menu_update(state, key, key_event));
				}
			}
			break;
		case SDLK_d:
			if(game->nb_player >= 2)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[1], EAST);
					player_inc_moving(players[1]);
				}
			}
			break;
		case SDLK_q:
			if(game->nb_player >= 2)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[1], WEST);
					player_inc_moving(players[1]);
				}
			}
			break;
		case SDLK_a:
			if(game->nb_player >= 2)
			{
				if(game->game_state == PLAYING)
					bomb_plant(game, map, players[1]); // the bomb is planted if it is possible
			}
			break;
		case SDLK_t:
			if(game->nb_player >= 3)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[2], NORTH);
					player_inc_moving(players[2]);
				}
				else if (game->game_state == PAUSED) {
					return(menu_update(state, key, key_event));
				}
			}
			break;
		case SDLK_g:
			if(game->nb_player >= 3)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[2], SOUTH);
					player_inc_moving(players[2]);
				}
				else if (game->game_state == PAUSED) {
					return(menu_update(state, key, key_event));
				}
			}
			break;
		case SDLK_h:
			if(game->nb_player >= 3)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[2], EAST);
					player_inc_moving(players[2]);
				}
			}
			break;
		case SDLK_f:
			if(game->nb_player >= 3)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[2], WEST);
					player_inc_moving(players[2]);
				}
			}
			break;
		case SDLK_r:
			if(game->nb_player >= 3)
			{
				if(game->game_state == PLAYING)
					bomb_plant(game, map, players[2]); // the bomb is planted if it is possible
			}
			break;
		case SDLK_i:
			if(game->nb_player >= 4)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[3], NORTH);
					player_inc_moving(players[3]);
				}
				else if (game->game_state == PAUSED) {
					return(menu_update(state, key, key_event));
				}
			}
			break;
		case SDLK_k:
			if(game->nb_player >= 4)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[3], SOUTH);
					player_inc_moving(players[3]);
				}
				else if (game->game_state == PAUSED) {
					return(menu_update(state, key, key_event));
				}
			}
			break;
		case SDLK_l:
			if(game->nb_player >= 4)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[3], EAST);
					player_inc_moving(players[3]);
				}
			}
			break;
		case SDLK_j:
			if(game->nb_player >= 4)
			{
				if(game->game_state == PLAYING){
					player_set_way(players[3], WEST);
					player_inc_moving(players[3]);
				}
			}
			break;
		case SDLK_u:
			if(game->nb_player >= 4)
			{
				if(game->game_state == PLAYING)
					bomb_plant(game, map, players[3]); // the bomb is planted if it is possible
			}
			break;
		default:
			break;
		}
	}
	else if(key_event == UP) {
		switch (key) {
		case SDLK_UP:
				player_dec_moving(players[0]);
				player_unset_way(players[0], NORTH);
			break;
		case SDLK_DOWN:
				player_dec_moving(players[0]);
				player_unset_way(players[0], SOUTH);
			break;
		case SDLK_RIGHT:
				player_dec_moving(players[0]);
				player_unset_way(players[0], EAST);
			break;
		case SDLK_LEFT:
				player_dec_moving(players[0]);
				player_unset_way(players[0], WEST);
			break;
		case SDLK_z:
			if(game->nb_player >= 2)
			{
				player_dec_moving(players[1]);
				player_unset_way(players[1], NORTH);
			}
			break;
		case SDLK_s:
			if(game->nb_player >= 2)
			{
				player_dec_moving(players[1]);
				player_unset_way(players[1], SOUTH);
			}
			break;
		case SDLK_d:
			if(game->nb_player >= 2)
			{
				player_dec_moving(players[1]);
				player_unset_way(players[1], EAST);
			}
			break;
		case SDLK_q:
			if(game->nb_player >= 2)
			{
				player_dec_moving(players[1]);
				player_unset_way(players[1], WEST);
			}
			break;
		case SDLK_t:
			if(game->nb_player >= 3)
			{
				player_dec_moving(players[2]);
				player_unset_way(players[2], NORTH);
			}
			break;
		case SDLK_g:
			if(game->nb_player >= 3)
			{
				player_dec_moving(players[2]);
				player_unset_way(players[2], SOUTH);
			}
			break;
		case SDLK_h:
			if(game->nb_player >= 3)
			{
				player_dec_moving(players[2]);
				player_unset_way(players[2], EAST);
			}
			break;
		case SDLK_f:
			if(game->nb_player >= 3)
			{
				player_dec_moving(players[2]);
				player_unset_way(players[2], WEST);
			}
			break;
		case SDLK_i:
			if(game->nb_player >= 4)
			{
				player_dec_moving(players[3]);
				player_unset_way(players[3], NORTH);
			}
			break;
		case SDLK_k:
			if(game->nb_player >= 4)
			{
				player_dec_moving(players[3]);
				player_unset_way(players[3], SOUTH);
			}
			break;
		case SDLK_l:
			if(game->nb_player >= 4)
			{
				player_dec_moving(players[3]);
				player_unset_way(players[3], EAST);
			}
			break;
		case SDLK_j:
			if(game->nb_player >= 4)
			{
				player_dec_moving(players[3]);
				player_unset_way(players[3], WEST);
			}
			break;
		case SDLK_F1:
			player_reset_way_mov(game->players[0]);
			break;
		case SDLK_F2:
			player_reset_way_mov(game->players[1]);
			break;
		case SDLK_F3:
			player_reset_way_mov(game->players[2]);
			break;
		case SDLK_F4:
			player_reset_way_mov(game->players[3]);
			break;
		}
	}
	return GAME;
}
Esempio n. 6
0
char*  seleccionar_menu( Partida* par, int linea, int col ){

    ITEM ** items;
    MENU*   menu;
    WINDOW* menuwin;
    int cant = qg_partida_movidas_count( par );
    int i;
    char* ret;
    int  srow, scol;

    items = malloc( sizeof( ITEM ) * ( cant + 1 ) );
    for( i = 0; i < cant; i ++ ){
        Movdata  movd;
        assert( qg_partida_movidas_data( par, i, &movd ) );
        items[i] = new_item( strdup( movd.notacion ), NULL );
    }
    items[i] = NULL;
    menu = new_menu( items );
    set_menu_format( menu, 13, 3 );

    scale_menu( menu, &srow, &scol );

    menuwin = newwin( srow + 2, scol + 2, linea, col );
    set_menu_win( menu, menuwin );
    set_menu_sub( menu, derwin( menuwin, srow, scol, 1, 1 ) );
    menu_opts_off( menu, O_SHOWDESC );
    box( menuwin, 0, 0 );
    keypad(menuwin, TRUE);

    post_menu( menu );

    ITEM* selected = NULL;

    while(!selected){
        wrefresh( menuwin );
        switch( getch() ){
            case  27:
                selected = (ITEM*)-1;
                break;
            case KEY_DOWN:
                menu_driver(menu, REQ_DOWN_ITEM);
                break;
            case KEY_UP:
                menu_driver(menu, REQ_UP_ITEM);
                break;
            case KEY_LEFT:
                menu_driver(menu, REQ_LEFT_ITEM);
                break;
            case KEY_RIGHT:
                menu_driver(menu, REQ_RIGHT_ITEM);
                break;
            case KEY_NPAGE:
                menu_driver(menu, REQ_SCR_DPAGE);
                break;
            case KEY_PPAGE:
                menu_driver(menu, REQ_SCR_UPAGE);
                break;
            case 10:
                selected = current_item(menu);
                break;
        }
    }

    if( selected != (ITEM*)-1 ){
        ret = strdup( item_name(selected ) );
    } else {
        ret = NULL;
    }

    for( i = 0; i < cant; i ++ ){
        free( (void*)item_name(items[i]) );
        free( items[i] );
    }
    unpost_menu( menu );
    free_menu( menu );
    borrar_win( menuwin );

    return ret;
}
Esempio n. 7
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
        int n_choices, i;
	ITEM *cur_item;
	
	/* Initialize curses */	
	initscr();
	start_color();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_GREEN, COLOR_BLACK);
	init_pair(3, COLOR_MAGENTA, COLOR_BLACK);

	/* Initialize items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
        for(i = 0; i < n_choices; ++i)
                my_items[i] = new_item(choices[i], choices[i]);
	my_items[n_choices] = (ITEM *)NULL;
	item_opts_off(my_items[3], O_SELECTABLE);
	item_opts_off(my_items[6], O_SELECTABLE);

	/* Create menu */
	my_menu = new_menu((ITEM **)my_items);

	/* Set fore ground and back ground of the menu */
	set_menu_fore(my_menu, COLOR_PAIR(1) | A_REVERSE);
	set_menu_back(my_menu, COLOR_PAIR(2));
	set_menu_grey(my_menu, COLOR_PAIR(3));

	/* Post the menu */
	mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected");
	mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)");
	post_menu(my_menu);
	refresh();

	while((c = getch()) != KEY_F(1))
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10: /* Enter */
				move(20, 0);
				clrtoeol();
				mvprintw(20, 0, "Item selected is : %s", 
						item_name(current_item(my_menu)));
				pos_menu_cursor(my_menu);
				break;
		}
	}	
	unpost_menu(my_menu);
	for(i = 0; i < n_choices; ++i)
		free_item(my_items[i]);
	free_menu(my_menu);
	endwin();
}
Esempio n. 8
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
        int n_choices, i;
	ITEM *cur_item;
	
	/* Initialize curses */	
	initscr();
	start_color();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_GREEN, COLOR_BLACK);
	init_pair(3, COLOR_MAGENTA, COLOR_BLACK);

	/* Initialize items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
        for(i = 0; i < n_choices; ++i)
	{       my_items[i] = new_item(choices[i], choices[i]);
		/* Set the user pointer */
		set_item_userptr(my_items[i], func);
	}
	my_items[n_choices] = (ITEM *)NULL;

	/* Create menu */
	my_menu = new_menu((ITEM **)my_items);

	/* Post the menu */
	mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected");
	mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)");
	post_menu(my_menu);
	refresh();

	while((c = getch()) != KEY_F(1))
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
			case 10: /* Enter */
			{	ITEM *cur;
				void (*p)(char *);

				cur = current_item(my_menu);
				p = item_userptr(cur);
				p((char *)item_name(cur));
				pos_menu_cursor(my_menu);
				break;
			}
			break;
		}
	}	
	unpost_menu(my_menu);
	for(i = 0; i < n_choices; ++i)
		free_item(my_items[i]);
	free_menu(my_menu);
	endwin();
}
Esempio n. 9
0
/*主程序入口*/
void main(){
	//初始化GPIO按钮
	gpiosetup();
	//构建菜单
	ITEM **my_items;
	int c;
	MENU *my_menu;
	int n_choices, i;
	ITEM *cur_item;
	initscr();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	n_choices = ARRAY_SIZE(choices);
	my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
	for(i = 0; i < n_choices; ++i)
		my_items[i] = new_item(choices[i],choice_descp[i]);
	my_items[n_choices] = (ITEM *)NULL;
	my_menu = new_menu((ITEM **)my_items);
	post_menu(my_menu);
	refresh();
	//开始检测按键
	int ret = 0;
	while(ret==0){
		refresh();
		if (digitalRead (BTN_UP) == LOW){
			menu_driver(my_menu, REQ_UP_ITEM);
			delay(200);
			continue;
		}
		if (digitalRead (BTN_DOWN) == LOW){
			menu_driver(my_menu, REQ_DOWN_ITEM);
			delay(200);
			continue;
		}
		if (digitalRead (BTN_OK) == LOW){
			switch(item_index(current_item(my_menu)))
				{	
					case 0://执行第一个程序
						def_prog_mode();
						endwin();
						system ("cd //home//pi//xpi// && sudo python tools.py");
						reset_prog_mode();
						refresh();
						break;
					case 1://执行第二个程序
						def_prog_mode();
						endwin();
						system ("cd //home//pi//ada// && sudo python cam.py");
						reset_prog_mode();
						refresh();
						break;
					case 2://MPC
						def_prog_mode();
						endwin();
						system ("cd //home//pi//impc// && sudo python radioplayer.py");
						reset_prog_mode();
						refresh();
						break;
					case 3://HD Music Player
						def_prog_mode();
						endwin();
						system ("cd //home//pi//pplayer && sudo python player.py");
						reset_prog_mode();
						refresh();
						break;
					case 4://back to console
						ret = 1;
						break;
					case 5://关机
						free_item(my_items[0]);
						free_item(my_items[1]);
						free_menu(my_menu);
						endwin();
						refresh();
						system ("sudo shutdown -h now");
						break;
				}
			delay(200);
			continue;
		}
		mvprintw(LINES-1,0,"[%s]                 ", item_name(current_item(my_menu)));
	}
	free_item(my_items[0]);
	free_item(my_items[1]);
	free_menu(my_menu);
	endwin();
	fflush (stdout) ;
}
Esempio n. 10
0
File: nchgdc.c Progetto: Eeketh/hgd
int
hgd_update_console_win(struct ui *u)
{
	char		  buf[HGD_LOG_BACKBUFFER + 1], *start = buf, *end, *copy;
	long		  pos, endpos, read;
	long		  toread = HGD_LOG_BACKBUFFER;
	ITEM		**items = NULL;
	int		  cur_index = 0;

	DPRINTF(HGD_D_INFO, "Update console window");

	wclear(u->content_wins[HGD_WIN_CONSOLE]);
	hgd_unpost_and_free_content_menu(u, HGD_WIN_CONSOLE);

	memset(buf, 0, HGD_LOG_BACKBUFFER + 1);

	/* find how long the log is */
	if ((fseek(logs.rd, 0, SEEK_END)) != 0)
		DPRINTF(HGD_D_WARN, "fseek: %s", SERROR);

	endpos = ftell(logs.rd);
	if (endpos < HGD_LOG_BACKBUFFER)
		toread = endpos;

	/* rewind at most HGD_LOG_BACKBUFFER and read into buffer */
	if ((fseek(logs.rd, -toread, SEEK_END)) != 0)
		DPRINTF(HGD_D_WARN, "fseek: %s", SERROR);

	pos = ftell(logs.rd);
	if ((read = fread(buf, toread, 1, logs.rd)) == 0) {
		if (ferror(logs.rd)) {
		    DPRINTF(HGD_D_WARN,
			"Failed to read console log: %s", SERROR);
		}
	}

	/* ensure we dont start printing the middle of a line */
	if (pos < 0)
		DPRINTF(HGD_D_WARN, "ftell failed: %s", SERROR);
	else if (pos != 0) {
		/* if not at the start of file, find a \n */
		while ((*start != '\n') && (*start != '\0'))
			start++;
	}

	/* this SHOULD happen, but not guaraunteed */
	if (*start == '\n')
		start++;

	items = xcalloc(sizeof(ITEM *), 1);

	/* scan for lines and add them as menu items */
	end = start;
	while (*start != 0) {
		while ((*end != 0) && (*end != '\n'))
			end++;

		if (*end == 0) {
			DPRINTF(HGD_D_WARN, "Unexpected end of log");
			break;
		}
		*end = 0;

		/* could be more efficient */
		items = xrealloc(items, sizeof(ITEM *) * (cur_index + 2));
		items[cur_index + 1] = NULL;

		hgd_prepare_item_string(&copy, start);
		items[cur_index] = new_item(copy, NULL);

		if (items[cur_index] == NULL) {
			DPRINTF(HGD_D_WARN,
			    "Could not make new menu item '%s'", start);
			free(copy);
		}

		end++;
		start = end;

		if (items[cur_index] == NULL)
			continue;

		cur_index++;
	}

	/* now we have our items, make the menu */
	if (u->content_menus[HGD_WIN_CONSOLE] != NULL) {
		/* XXX clean up old menu */
	}

	u->content_menus[HGD_WIN_CONSOLE] = new_menu(items);

	keypad(u->content_wins[HGD_WIN_CONSOLE], TRUE);
	set_menu_win(u->content_menus[HGD_WIN_CONSOLE],
	    u->content_wins[HGD_WIN_CONSOLE]);
	set_menu_mark(u->content_menus[HGD_WIN_CONSOLE], "");
	set_menu_format(u->content_menus[HGD_WIN_CONSOLE],
	    LINES - 2, 1);
	set_menu_fore(u->content_menus[HGD_WIN_CONSOLE],
	    COLOR_PAIR(HGD_CPAIR_SELECTED));

	if ((post_menu(u->content_menus[HGD_WIN_CONSOLE])) != E_OK)
		DPRINTF(HGD_D_WARN, "Could not post menu");

	menu_driver(u->content_menus[HGD_WIN_CONSOLE], REQ_LAST_ITEM);

	return (HGD_OK);
}
Esempio n. 11
0
// Scan MAME ROMs folder, cross-reference against XML (if present) for
// verbose descriptions, generate ncurses menu.
static void find_roms(void) {
	FILE           *fp;
	struct dirent **dirList;
	int             i, nFiles;
	Game           *g;       // For traversing Game linked list
	WINDOW         *scanWin; // Modal 'Scanning...' window

	if(noRomWin) { // Delete 'No ROMS' window if present
		delwin(noRomWin);
		noRomWin = NULL;
		werase(mainWin);
		box(mainWin, 0, 0);
	}

	if(items) { // Delete old ROM menu and contents, if any
		if(menu) {
			unpost_menu(menu);
			free_menu(menu);
			menu = NULL;
		}
		for(i=0; items[i]; i++) free_item(items[i]);
		free(items);
		items = NULL;
	}

	const char scanMsg[] = "Scanning ROM folder...";
	scanWin = newwin(3, strlen(scanMsg) + 4,
	  (LINES - 4) / 2 - 1, (COLS - strlen(scanMsg)) / 2 - 2);
	box(scanWin, 0, 0);
	mvwprintw(scanWin, 1, 2, scanMsg);

	wnoutrefresh(mainWin);
	wnoutrefresh(scanWin);
	doupdate();

	delwin(scanWin);
	werase(mainWin);
	box(mainWin, 0, 0);

	while(gameList) { // Delete existing gameList, if any
		g = gameList->next;
		if(gameList->name) free(gameList->name);
		if(gameList->desc) free(gameList->desc);
		free(gameList);
		gameList = g;
	}

	i = 0; // Count number of games found & successfully alloc'd
	if((nFiles = scandir(rom, &dirList, sel, alphasort)) > 0) {
		// Copy dirent array to a Game linked list
		while(nFiles--) { // List is assembled in reverse
			if((g = (Game *)malloc(sizeof(Game)))) {
				g->name  = strdup(dirList[nFiles]->d_name);
				g->desc  = NULL;
				g->next  = gameList;
				gameList = g;
				i++; // A winner is you
			}
			// dirList contents are freed as we go
			free(dirList[nFiles]);
		}
		free(dirList);
	}

	// Alloc, load, cross-reference XML file against ROM filenames
	if((fp = fopen(xml, "r"))) {
		fseek(fp, 0, SEEK_END);
		char *buf;
		int   len = ftell(fp);
		if((buf = (char *)malloc(len))) {
			int depth = 0;
			fseek(fp, 0, SEEK_SET);
			fread(buf, 1, len, fp);
			XML_Parser parser = XML_ParserCreate(NULL);
			XML_SetUserData(parser, &depth);
			XML_SetElementHandler(parser,
			  startElement, endElement);
			XML_SetCharacterDataHandler(parser, elementData);
			XML_Parse(parser, buf, len, 1);
			XML_ParserFree(parser);
			free(buf);
		}
		fclose(fp);
	}

	if((items = (ITEM**)malloc((i + 1) * sizeof(ITEM *)))) {
		for(i=0, g=gameList; g; g=g->next, i++) {
			items[i] = new_item(g->name, g->desc);
			set_item_userptr(items[i], g);
		}
		items[i] = NULL;
		menu = new_menu(items);
		set_menu_win(menu, mainWin);
		set_menu_sub(menu, derwin(mainWin, LINES-6, COLS-2, 1, 1));
		set_menu_format(menu, LINES-6, 1);
		set_menu_mark(menu, " ");
		post_menu(menu);
	}

	wrefresh(mainWin);

	if(!menu) { // If no ROMs, throw up a message to that effect
		const char noRomMsg[] = "No ROMs found";
		noRomWin = newwin(3, strlen(noRomMsg) + 4,
		  (LINES - 4) / 2 - 1, (COLS - strlen(noRomMsg)) / 2 - 2);
		box(noRomWin, 0, 0);
		mvwprintw(noRomWin, 1, 2, noRomMsg);
		wrefresh(noRomWin);
	}
}
Esempio n. 12
0
File: nchgdc.c Progetto: Eeketh/hgd
int
hgd_update_files_win(struct ui *u)
{
	ITEM			**items = NULL;
	char			 *slash_append, *prep_item_str;
	struct dirent		**dirents_dirs = 0, **dirents_files = 0, *d, *d_copy;
	int			  n_dirs = 0, n_files = 0;
	int			  i, cur_item = 0, ret = HGD_FAIL;

	DPRINTF(HGD_D_INFO, "Update files window");

	wclear(u->content_wins[HGD_WIN_FILES]);
	hgd_unpost_and_free_content_menu(u, HGD_WIN_FILES);

	if ((n_dirs = scandir(
	    u->cwd, &dirents_dirs, hgd_filter_dirs, alphasort)) < 0) {
		 DPRINTF(HGD_D_WARN, "Failed to scan directory: '%s'", u->cwd);
		 goto clean;
	}

	if ((n_files = scandir(
	    u->cwd, &dirents_files, hgd_filter_files, alphasort)) < 0) {
		 DPRINTF(HGD_D_WARN, "Failed to scan directory: '%s'", u->cwd);
		 goto clean;
	}

	/* make our menu items */
	DPRINTF(HGD_D_INFO, "allocating %d menu items", n_files + n_dirs);
	items = xcalloc(n_files + n_dirs + 1, sizeof(ITEM *));

	/* add dirs */
	for (i = 0; i < n_dirs; i++) {
		d = dirents_dirs[i];

		xasprintf(&slash_append, "%s/", d->d_name);
		hgd_prepare_item_string(&prep_item_str, slash_append);
		free(slash_append);

		items[cur_item] = new_item(prep_item_str, NULL);

		if (items[cur_item] == NULL) {
			DPRINTF(HGD_D_WARN,
			    "Could not make new menu item: %s", SERROR);
			free(prep_item_str);
			continue;
		}

		/*
		 * jam away the dirent for later use
		 * Note! scandir does notallocate a full struct dirent
		 */
#if !defined(__linux__)
		d_copy = xcalloc(1, sizeof(struct dirent));
		d_copy->d_fileno = d->d_fileno;2
		d_copy->d_reclen = d->d_reclen;
		d_copy->d_type = d->d_type;
		d_copy->d_namlen = d->d_namlen;
		strlcpy(d_copy->d_name, d->d_name, d->d_namlen + 1);
#else
		d_copy = xcalloc(1, d->d_reclen);
		memcpy(d_copy, d, d->d_reclen);
#endif

		set_item_userptr(items[cur_item], d_copy);

		cur_item++;
	}

	/* add files */
	for (i = 0; i < n_files; i++) {
		d = dirents_files[i];

		hgd_prepare_item_string(&prep_item_str, d->d_name);

		items[cur_item] = new_item(prep_item_str, NULL);

		if (items[cur_item] == NULL) {
			DPRINTF(HGD_D_WARN,
			    "Could not make new menu item: %s", SERROR);
			free(prep_item_str);
			continue;
		}

		/*
		 * copy manually, do not use memcpy, as scandir does not
		 * allocate a full struct dirent
		 */
#if !defined(__linux__)
		d_copy = xcalloc(1, sizeof(struct dirent));
		d_copy->d_fileno = d->d_fileno;2
		d_copy->d_reclen = d->d_reclen;
		d_copy->d_type = d->d_type;
		d_copy->d_namlen = d->d_namlen;
		strlcpy(d_copy->d_name, d->d_name, d->d_namlen + 1);
#else
		d_copy = xcalloc(1, d->d_reclen);
		memcpy(d_copy, d, d->d_reclen);
#endif

		set_item_userptr(items[cur_item], d_copy);

		cur_item++;
	}

	DPRINTF(HGD_D_INFO, "Actually allocated %d menu items", cur_item);
	items[cur_item] = NULL;

	u->content_menus[HGD_WIN_FILES] = new_menu(items);

	keypad(u->content_wins[HGD_WIN_FILES], TRUE);
	set_menu_win(u->content_menus[HGD_WIN_FILES],
	    u->content_wins[HGD_WIN_FILES]);
	set_menu_mark(u->content_menus[HGD_WIN_FILES], "");
	set_menu_format(u->content_menus[HGD_WIN_FILES],
	    LINES - 2, 1);
	set_menu_fore(u->content_menus[HGD_WIN_FILES],
	    COLOR_PAIR(HGD_CPAIR_SELECTED));

	if ((post_menu(u->content_menus[HGD_WIN_FILES])) != E_OK)
		DPRINTF(HGD_D_WARN, "Could not post menu");

	ret = HGD_OK;

clean:
	if (dirents_files) {
		for (i = 0; i < n_files; i ++)
			free(dirents_files[i]);
		free(dirents_files);
	}

	if (dirents_dirs) {
		for (i = 0; i < n_dirs; i ++)
			free(dirents_dirs[i]);
		free(dirents_dirs);
	}

#if 0
	if (items)
		free(items);
#endif

	return (ret);

}
Esempio n. 13
0
File: nchgdc.c Progetto: Eeketh/hgd
int
hgd_update_playlist_win(struct ui *u)
{
	ITEM			**items = NULL;
	int			  i, ret = HGD_FAIL;
	char			 *item_str;
	struct hgd_playlist	 *playlist = NULL;
	char			 *track_str;

	DPRINTF(HGD_D_INFO, "Update playlist window");

	hgd_set_statusbar_text(u, "Connected >>> Fetching playlist");

	if (sock_fd == -1) {
		ret = HGD_OK;
		goto clean;
	}

	wclear(u->content_wins[HGD_WIN_PLAYLIST]);
	hgd_unpost_and_free_content_menu(u, HGD_WIN_PLAYLIST);

	/* and now populate the menu */
	if (hgd_cli_get_playlist(&playlist) != HGD_OK) {
		goto clean;
	}

	if (playlist->n_items == 0) {
		ret = HGD_OK;
		mvwprintw(u->content_wins[HGD_WIN_PLAYLIST], 0, 0, "Playlist Empty - Saddest of times!");
		goto clean;
	}

	items = xcalloc(playlist->n_items + 1, sizeof(ITEM *));
	for (i = 0; i < playlist->n_items; i++) {

		DPRINTF(HGD_D_DEBUG, "Adding item \"%s\"",
		    playlist->items[i]->tags.title);

		if ((strcmp(playlist->items[i]->tags.artist, "")) ||
		    (strcmp(playlist->items[i]->tags.title, ""))) {

			xasprintf(&track_str, "#%03d from %-8s: '%s' by '%s'",
			    playlist->items[i]->id,
			    playlist->items[i]->user,
			    playlist->items[i]->tags.title,
			    playlist->items[i]->tags.artist);
		} else  {
			xasprintf(&track_str, "#%03d from %-8s: '%s'",
			    playlist->items[i]->id,
			    playlist->items[i]->user,
			    playlist->items[i]->filename);
		}

		hgd_prepare_item_string(&item_str, track_str);
		free(track_str);

		items[i] = new_item(item_str, NULL);
		if (items[i] == NULL)
			DPRINTF(HGD_D_WARN, "Could not make new item: %s", SERROR);
	}

	u->content_menus[HGD_WIN_PLAYLIST] = new_menu(items);
	if (u->content_menus[HGD_WIN_PLAYLIST] == NULL) {
			DPRINTF(HGD_D_ERROR, "Could not make menu");
			goto clean;
	}

	set_menu_win(u->content_menus[HGD_WIN_PLAYLIST],
	    u->content_wins[HGD_WIN_PLAYLIST]);
	set_menu_mark(u->content_menus[HGD_WIN_PLAYLIST], "");
	set_menu_format(u->content_menus[HGD_WIN_PLAYLIST], LINES - 2, 1);
	set_menu_fore(u->content_menus[HGD_WIN_PLAYLIST],
	    COLOR_PAIR(HGD_CPAIR_SELECTED));

	if ((post_menu(u->content_menus[HGD_WIN_PLAYLIST])) != E_OK) {
		DPRINTF(HGD_D_ERROR, "Could not post menu");
		goto clean;
	}

	hgd_set_standard_statusbar_text(u);

	ret = HGD_OK;
clean:
	if (playlist)
		hgd_free_playlist(playlist);
#if 0
	if (items)
		free(items);
#endif
	if (playlist)
		free(playlist);

	return (ret);
}
Esempio n. 14
0
/**
 * main_menu - Main menu processing
 *
 * Processes the main menu.
 */
int main_menu(void)
{
	int o, f;
	struct filp_val *v;
	int n, m, i;
	unsigned char *ptr;
	unsigned char *ptr2;
	unsigned char c;
	int ret = 0;

	filp_exec("\"$data_dir/e0/episode.filp\" load");

	filp_exec("MSG_MENU_MAIN");
	v = filp_pop();
	filp_ref_value(v);

	o = f = 0;
	i = (_qdgdfv_screen_x_size / 2) - (LOGO_WIDTH / 2);

	qdgdfa_play_sound(_soundtrack, 1);

	qdgdfv_timer(1);

	for (;;) {
		_ticks_elapsed = qdgdfv_timer(1);

		render(_player_x, _player_y, _player_a);

		/* transfer the logo */
		for (ptr = _qdgdfv_virtual_screen + i, n = 0; n < LOGO_HEIGHT; n++) {
			ptr2 = ptr;

			for (m = 0; m < LOGO_WIDTH; m++, ptr2++) {
				c = _logo[(n * LOGO_WIDTH) + m];

				if (c != 255)
					*ptr2 = c;
			}

			ptr += _qdgdfv_screen_x_size;
		}

		qdgdfv_input_poll();

		if (f) {
			show_info("$info_text");

			if (_qdgdfv_key_enter) {
				while (_qdgdfv_key_enter)
					qdgdfv_input_poll();
				f = 0;
			}
			else if (_qdgdfv_key_escape) {
				while (_qdgdfv_key_escape)
					qdgdfv_input_poll();
				f = 0;
			}
		}
		else {
			if (menu(v->value, &o)) {
				if (o == -1)
					o = 0;
				else if (o == 0) {
					if (new_menu())
						break;
				}
				else if (o == 1) {
					if (save_load_game_menu(0))
						break;
				}
				else if (o == 3) {
					while (_qdgdfv_key_enter)
						qdgdfv_input_poll();

					f = 1;
				}
				else if (o == 4) {
					ret = 1;
					break;
				}
			}
		}

		qdgdfv_dump_virtual_screen();
	}

	filp_unref_value(v);

	return ret;
}
Esempio n. 15
0
/*
 * Return codes:
 *  0 - action performed
 * -1 - quit was pressed (only for main menu)
 * +1 - backspace or escape was pressed, back to previous menu
 */
static int
do_menu(struct menuoption *runmenu, int num, int upper, const char *title, ...)
{
	int ch, i, y, x;
//	char buf[BUFSIZ];
	char *buf;
	struct menuoption *curmenu;
	ITEM **mitems, *mitem;
	MENU *mmenu;
	WINDOW *msubwin;
	va_list ap;

	/* Clear screen and print title */
	if (upper)
		show_mainwin(0);
	else
		show_mainwin(1);
	va_start(ap, title);
	head_mainwin(title, ap);
	va_end(ap);

	x = 0;
	y = 0;
	if (upper)
		msubwin = create_uppersubwin();
	else
		msubwin = create_lowersubwin(&y, &x);

	mitems = (ITEM **)calloc(num + 1, sizeof(ITEM*));
	for (curmenu = runmenu, i = 0; i < num; i++) {
		ch = sizeof buf > x ? x - 1 : sizeof buf - 1;
//		if (snprintf(buf, ch, "%s", curmenu->m_name) <= 0) {
		if (asprintf(&buf, "%s", curmenu->m_name) <= 0) {
			ask_ok("Error creating the menu.");
			for (i--; i >= 0; i--)
				free(mitems[i]);
			return 0;
		}
		mitems[i] = new_item(buf, NULL);
		set_item_userptr(mitems[i], (void *)curmenu);
//		warnx("%ld %s", (long)curmenu, curmenu->m_name);
		curmenu++;
	}
	mitems[num] = NULL;

	mmenu = new_menu(mitems);
	set_menu_win(mmenu, mainwin);
	set_menu_sub(mmenu, msubwin);
	set_menu_format(mmenu, upper ? 1 : y, 1);
	if (colouring) {
		set_menu_fore(mmenu, COLOR_PAIR(1));
		set_menu_back(mmenu, COLOR_PAIR(1));
		set_menu_grey(mmenu, COLOR_PAIR(1));
	}
	set_menu_mark(mmenu, ">");
	if (post_menu(mmenu)) {
		ask_ok("Error posting the menu.");
		return 1;
	}
	show_mainwin(0);
	show_lowersubwin(0, msubwin);

	while ((ch = getch()) != '\n' && ch != '\b') {
		switch (ch) {
			case KEY_DOWN:
				menu_driver(mmenu, REQ_NEXT_ITEM);
				break;
			case KEY_UP:
				menu_driver(mmenu, REQ_PREV_ITEM);
				break;
			case KEY_NPAGE:
				menu_driver(mmenu, REQ_SCR_DPAGE);
				break;
			case KEY_PPAGE:
				menu_driver(mmenu, REQ_SCR_UPAGE);
				break;
			case KEY_END:
				menu_driver(mmenu, REQ_LAST_ITEM);
				break;
			case KEY_HOME:
				menu_driver(mmenu, REQ_FIRST_ITEM);
				break;
		}
		show_mainwin(0);
		show_lowersubwin(0, msubwin);
	}

	mitem = current_item(mmenu);
	curmenu = (struct menuoption *)item_userptr(mitem);

	unpost_menu(mmenu);
	delwin(msubwin);
	free_menu(mmenu);
	for (i = 0; i < num; i++)
		free_item(mitems[i]);
	free(mitems);

	if (ch != '\b' && curmenu->m_action != NULL) {
		curmenu->m_action(curmenu->m_argv);
		return 0;
	} else {
		return 1;
	}
}
Esempio n. 16
0
struct result
selection_show(struct selection *selection, WINDOW *parent)
{
    if (!selection) return result_set_system_error(EINVAL);
    
    selection->menu = new_menu(selection->items);
    if (!selection->menu) return result_ncurses_errno();
    
    int menu_height;
    int menu_width;
    int code = scale_menu(selection->menu, &menu_height, &menu_width);
    if (E_OK != code) return result_ncurses_error(code);
    
    int title_width = (int)strlen(selection->title) + 1;
    if (title_width > menu_width) menu_width = title_width;
    
    int main_window_height;
    int main_window_width;
    getmaxyx(parent, main_window_height, main_window_width);
    
    int menu_window_height = menu_height + 4;
    int menu_window_width = menu_width + 5;
    int menu_window_y = (main_window_height - menu_window_height) / 2;
    int menu_window_x = (main_window_width - menu_window_width) / 2;
    
    selection->window = newwin(menu_window_height, menu_window_width,
                               menu_window_y, menu_window_x);
    if (!selection->window) return result_ncurses_err();
    
    code = keypad(selection->window, TRUE);
    if (ERR == code) return result_ncurses_err();
        
    struct result result = draw_window(selection);
    if (!result_is_success(result)) return result;
    
    code = set_menu_win(selection->menu, selection->window);
    if (E_OK != code) return result_ncurses_error(code);
    
    int menu_sub_height = menu_height;
    int menu_sub_width = menu_width;
    int menu_sub_y = 2;
    int menu_sub_x = 2;
    
    selection->sub_window = derwin(selection->window,
                                   menu_sub_height, menu_sub_width,
                                   menu_sub_y, menu_sub_x);
    if (!selection->sub_window) return result_ncurses_err();
    
    code = set_menu_sub(selection->menu, selection->sub_window);
    if (E_OK != code) return result_ncurses_error(code);
    
    selection->index = 0;
    code = post_menu(selection->menu);
    if (E_OK != code) return result_ncurses_error(code);
    
    code = wrefresh(selection->window);
    if (ERR == code) return result_ncurses_err();
        
    result = get_selection(selection);
    if (!result_is_success(result)) return result;
    
    ITEM *selected_item = current_item(selection->menu);
    if (selected_item) selection->index = item_index(selected_item);
    
    code = unpost_menu(selection->menu);
    if (E_OK != code) return result_ncurses_error(code);
    
    code = wclear(selection->window);
    if (ERR == code) return result_ncurses_err();
        
    code = wrefresh(selection->window);
    if (ERR == code) return result_ncurses_err();
    
    code = free_menu(selection->menu);
    if (E_OK != code) return result_ncurses_error(code);
    selection->menu = NULL;
    
    code = delwin(selection->sub_window);
    if (E_OK != code) return result_ncurses_error(code);
    selection->sub_window = NULL;
        
    code = delwin(selection->window);
    if (E_OK != code) return result_ncurses_error(code);
    selection->window = NULL;
    
    return result_success();
}
Esempio n. 17
0
void theme::add_object(const config& cfg)
{
	if (const config &c = cfg.child("main_map")) {
		main_map_ = object(c);
	}

	if (const config &c = cfg.child("mini_map")) {
		mini_map_ = object(c);
	}

	if (const config &c = cfg.child("palette")) {
		palette_ = object(c);
	}

	if (const config &status_cfg = cfg.child("status"))
	{
		for(const config::any_child &i : status_cfg.all_children_range()) {
			status_.insert(std::pair<std::string, status_item>(i.key, status_item(i.cfg)));
		}
		if (const config &unit_image_cfg = status_cfg.child("unit_image")) {
			unit_image_ = object(unit_image_cfg);
		} else {
			unit_image_ = object();
		}
	}

	for(const config &p : cfg.child_range("panel")) {
		panel new_panel(p);
		set_object_location(new_panel, p["rect"], p["ref"]);
		panels_.push_back(new_panel);
	}

	for(const config &lb : cfg.child_range("label")) {
		label new_label(lb);
		set_object_location(new_label, lb["rect"], lb["ref"]);
		labels_.push_back(new_label);
	}

	for(const config &m : cfg.child_range("menu"))
	{
		menu new_menu(m);
		DBG_DP << "adding menu: " << (new_menu.is_context() ? "is context" : "not context") << "\n";
		if(new_menu.is_context())
			context_ = new_menu;
		else{
			set_object_location(new_menu, m["rect"], m["ref"]);
			menus_.push_back(new_menu);
		}

		DBG_DP << "done adding menu...\n";
	}

	for(const config &a : cfg.child_range("action"))
	{
			action new_action(a);
			DBG_DP << "adding action: " << (new_action.is_context() ? "is context" : "not context") << "\n";
			if(new_action.is_context())
				action_context_ = new_action;
			else{
				set_object_location(new_action, a["rect"], a["ref"]);
				actions_.push_back(new_action);
			}

			DBG_DP << "done adding action...\n";
	}

	for(const config &s : cfg.child_range("slider"))
	{
			slider new_slider(s);
			DBG_DP << "adding slider\n";
			set_object_location(new_slider, s["rect"], s["ref"]);
			sliders_.push_back(new_slider);

			DBG_DP << "done adding slider...\n";
	}

	if (const config &c = cfg.child("main_map_border")) {
		border_ = tborder(c);
	} else {
		border_ = tborder();
	}
}
Esempio n. 18
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
	int n_choices, i;
	ITEM *cur_item;	
	
	WINDOW *local_win;
	
	initscr();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	
	start_color();
	init_pair(1, COLOR_BLUE, COLOR_BLACK);
	
	attron(COLOR_PAIR(1));
	mvprintw((LINES/2)-10,(COLS/3)-25,"%s",title1);
	mvprintw((LINES/2)-9,(COLS/3)-25,"%s",title2);
	mvprintw((LINES/2)-8,(COLS/3)-25,"%s",title3);
	mvprintw((LINES/2)-7,(COLS/3)-25,"%s",title4);
	mvprintw((LINES/2)-6,(COLS/3)-25,"%s",title5);
	attroff(COLOR_PAIR(1));

	//getch();
	mvprintw(((LINES/2)+5), ((COLS/2)-7), "q to Exit");
	refresh();
	
	local_win = newwin(5, 15, ((LINES/2)-2), ((COLS/3)+8));
	
	//box(local_win, 0 , 0);
	wrefresh(local_win);	
	
	n_choices = ARRAY_SIZE(choices);
	my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));

	for(i = 0; i < n_choices; ++i)
	        my_items[i] = new_item(choices[i],"");//, choices[i]);
	my_items[n_choices] = (ITEM *)NULL;

	my_menu = new_menu((ITEM **)my_items);
	set_menu_win(my_menu, local_win);
	keypad(local_win, TRUE);
	
	post_menu(my_menu);
	wrefresh(local_win);
	while(true)
	{
		c = wgetch(local_win);
 		switch(c)
	    {	case KEY_DOWN:
		        menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;	
			case 'a':
				//mvprintw(LINES-3, 0, "Item selected is : %s", item_name(current_item(my_menu)));
				const char *blargh=item_name(current_item(my_menu));
				//mvprintw(LINES-3,0,"Item selected is : %s",blargh);
				switch(blargh[0])
				{
					case 'S'://tart New Game":
						mvprintw(LINES-3,0,"Started New Game");
						break;
					case 'L'://oad Game":
						mvprintw(LINES-3,0,"Loaded Game");
						break;
					case 'O'://ptions":
						mvprintw(LINES-3,0,"Selected Options");
						break;
					case 'H'://elp":
						mvprintw(LINES-3,0,"Selected Help");
						break;
					case 'E'://xit":
						mvprintw(LINES-3,0,"Exiting");
						c='q';
				}
				break;			
		}
		if (c=='q'){
			break;
		}
	}	
	free_item(my_items[0]);
	free_item(my_items[1]);
	free_menu(my_menu);
	endwin();
}
Esempio n. 19
0
/**
 * Documentation here
 */
void main_menu()
{


  MENU *my_menu;
  /* Order here doesn't matter. Name (the first item in each of these
     "pairs") does. If you change the name, change the selection
     handling code towards the end of this function. */
  char *my_choices[] = {
    "Create","(Create new termship game)",
    "Join", "(Join existing termship game on network)",
    "Exit", "",
    (char *)NULL, (char *)NULL
  };
  ITEM **my_items;
  int n_choices = ARRAY_SIZE(my_choices)/2;

  /* some testing modes: */
#ifdef TEST_SHIPS
  initShips();
  return;
#endif

  keypad(stdscr, TRUE);
  curs_set(0); // make cursor invisible
  noecho();
  title_screen();

  clear();

  my_items = (ITEM **)calloc(n_choices,sizeof(ITEM *));
  for (int i=0; my_choices[i*2]!=NULL; ++i) {
    /* i*2 since we're iterating in pairs */
    my_items[i] = new_item(my_choices[(i*2)], my_choices[(i*2)+1]);
  }

  my_menu = new_menu(my_items);
  set_menu_mark(my_menu, "   * ");
  post_menu(my_menu);
  refresh();

  int c;
  while ((c = getch()) != 10) {
    switch (c) {
    case KEY_DOWN:
      menu_driver(my_menu, REQ_DOWN_ITEM);
      break;
    case KEY_UP:
      menu_driver(my_menu, REQ_UP_ITEM);
      break;
    }
  }
  ITEM *cur = current_item(my_menu);
  const char *selected_name = item_name(cur);
  
  /* delete the menu, free resources */
  for (int i=0; i<n_choices-1; ++i) {
    free_item(my_items[i]);
  }
  /* free(my_items); */
  unpost_menu(my_menu);
  free_menu(my_menu);

  if (0==strcmp(selected_name, "Create")) {
    user_mode = SERVER_MODE;
    get_text_string_from_centered_panel("Enter your name",
                    global_user_name,
                    MAX_NAME);
    init_game(user_mode);
  } else if (0==strcmp(selected_name, "Join")) {
    user_mode = CLIENT_MODE;
    get_text_string_from_centered_panel("Enter your name",
                    global_user_name,
                    MAX_NAME);
    init_game();
  }

  return;
}
Esempio n. 20
0
static void main_menu(){
    MENU *my_menu;
    WINDOW *left_win, *right_win, *bottom_win_box, *bottom_win;
    int n_options;
    
    clear();

    //initialize color schemes used by update window
    init_pair(1, COLOR_BLUE, 0);
    init_pair(2, COLOR_YELLOW, 0); 
    init_pair(3, COLOR_RED, 0);


    
    //Initialize an array of items to put in menu
    n_options = sizeof(left_main_menu_options)/sizeof(ITEM *);
    ITEM ** my_items = (ITEM **)calloc(n_options+1, sizeof(ITEM *)); 
    for(int i = 0; i < n_options; i++){
            my_items[i] = new_item(left_main_menu_options[i], "");
    }
    
    //initialize menu
    my_menu = new_menu(my_items);
    
    //create the left, right, and bottom windows for main menu.
    left_win = newwin(terminal_y/2, (terminal_x/2), 0, 0);
    right_win = newwin(terminal_y/2, (terminal_x/2), 0, terminal_x/2);
    bottom_win = newwin(terminal_y/2-2, terminal_x-2, terminal_y/2+1,1);
    bottom_win_box = newwin(terminal_y/2, terminal_x, terminal_y/2, 0);
    
    keypad(left_win, TRUE);
    nodelay(left_win, TRUE);
 
    // main/sub window
    set_menu_win(my_menu, left_win);
    set_menu_sub(my_menu, derwin(left_win, 6, (terminal_x/2)-2, 3, 1));
    
    //Set title of left menu and selection character
    char program_title[] = "Welcome to AFLDFF!";
    mvwprintw(left_win, 1, (terminal_x/4)-(strlen(program_title)/2), program_title);
    set_menu_mark(my_menu, " * ");
    
    //box seperator for left menu
    box(left_win, 0, 0);
    mvwaddch(left_win, 2, 0, ACS_LTEE);
    mvwhline(left_win, 2, 1, ACS_HLINE, (terminal_x/2)-2);
    mvwaddch(left_win, 2, (terminal_x/2)-1, ACS_RTEE);

    //menu post
    post_menu(my_menu);
    wrefresh(left_win);
    
    box(bottom_win_box, 0, 0);
    wrefresh(bottom_win_box);

    while(1){
        main_menu_right(right_win);
        main_menu_bottom(bottom_win);
        ITEM * choice = main_menu_left(left_win, my_menu); 

        /************************************************
         *Switch used to control Main menu options      *
         ************************************************/
                
        if(choice != NULL){
            char * menu_selection = (char *) item_name(choice);
            //VIEW JOBS
            if(strcmp(menu_selection, left_main_menu_options[0]) == 0){ 
                global_state = WOOPS;
                return;
            }
            //COLLECT CRASHES
            else if(strcmp(menu_selection, left_main_menu_options[1]) == 0){
                global_state = WOOPS;
                return;
            }
            //APPLY PATCH
            else if(strcmp(menu_selection, left_main_menu_options[2]) == 0){
                global_state = APPLY_PATCH;
                break;
            }
            //EXIT
            else if(strcmp(menu_selection, left_main_menu_options[3]) == 0){
                endwin();
                exit(0);
            }
            else{
                global_state = WOOPS;
                return;
            }
        
        }
                
        usleep(10000);
    }


    /* Unpost and free all the memory taken up */
    unpost_menu(my_menu);
    free_menu(my_menu);
    for(int i = 0; i < n_options; ++i){
            free_item(my_items[i]);
    }
    delwin(left_win);
    delwin(right_win);
    delwin(bottom_win);
    delwin(bottom_win_box);
}
Esempio n. 21
0
static void
prepare_for_new_results(Boolean clear)
{
    results_not_found = False;
    const config_t *conf = config();

    clear_menu(clear);

    choices_cnt = g_list_length(results);

    if (choices_cnt == 0) {
        no_results();
    }

    list_items = (ITEM**) calloc(choices_cnt + 1, sizeof(ITEM*));

    for (int i = 0; i < choices_cnt; i++) {
        if (results_not_found) {
            if (query_len == 0) {
                list_items[i] = new_item("Start typing to search", "");
            } else {
                list_items[i] = new_item("No results, sorry", "");
            }
        } else {
            GList *l = g_list_nth(results, i);
            char *path = l->data;

            char *name = g_path_get_basename(path);
            names = g_list_prepend(names, name);

            if (conf->section_main->numeric_shortcuts) {
                if (i < 10) {
                    list_items[i] = new_item(digits[i], name);
                }
                else
                    list_items[i] = new_item(" ", name);
            } else {
                list_items[i] = new_item(name, (char*) NULL);
            }
        }
    }

    list_items[choices_cnt] = new_item((char*) NULL, (char*) NULL);

    menu_list = new_menu((ITEM**) list_items);

    window = newwin(
        30, // rows
        30, // cols
        2,
        0
    );

    keypad(window, TRUE);
    /* nodelay(window, TRUE); */

    set_menu_win(menu_list, window);
    set_menu_mark(menu_list, "");
    set_menu_fore(menu_list, COLOR_PAIR(XS_COLOR_PAIR_1));
    set_menu_format(menu_list, 10, 1);

    post_menu(menu_list);

    update_info_bar();

    refresh();
}
Esempio n. 22
0
/*setup_windows{{{*/
void setup_windows(int flags) {
 obj_param_t tmp_parm;

 globl_drop_depth =25;
 globl_flags = DROP_SHADOW;
 init_gui(WIDTH, HEIGHT, flags);

 SET_COLOR(globl_fg, 		0   ,0   ,0);
 SET_COLOR(globl_bg, 		224 ,224 ,204);
 SET_COLOR(globl_move_color, 	0x1f,0x8f,0x1f);
 SET_COLOR(hscroll_color, 	0   ,0x7f,0xff);
 SET_COLOR(sprite_color, 	0xff,0x7f,0);
 SET_COLOR(window_color, 	0   ,0   ,0xff);
 SET_COLOR(scroll_b_color, 	0xff,0   ,0xff);
 SET_COLOR(scroll_a_color, 	0xff,0   ,0);

 change_message_grp = new_group(40,40, 202, 77, globl_flags, globl_drop_depth);
 simple_window(change_message_grp, 200, 75);
 PARM(50, 45,100,20, &globl_fg, &globl_bg, SHOW_FOCUS | QUIT_BUTTON, proc_button_box);
 tmp_parm.dp1 = (void *)"Okay";
 new_obj(change_message_grp, &tmp_parm);
 PARM(12,16,172,20,&globl_fg, &globl_bg, MAX_CHARS|SHOW_FOCUS, proc_edit_line);
 tmp_parm.d3 = 80;
 text_edit_object = new_obj(change_message_grp, &tmp_parm);

 select_grp = new_group(0,0,WIDTH, HEIGHT,0,0);
 PARM(305,126,320,240,&globl_fg,&globl_bg,0,select_special);
 select_special_object = new_obj(select_grp, &tmp_parm);


 PARM(0,0, 304, 126, 0,0, 0, select_quit_on_click);
 tmp_parm.user_flags = 0;
 new_obj(select_grp, &tmp_parm);

 PARM(0,126,304,240, 0,0, 0, select_quit_on_click);
 tmp_parm.user_flags = HORIZONTAL;
 new_obj(select_grp, &tmp_parm);

 PARM(0, 366, 305, 112, 0,0, 0, select_quit_on_click);
 tmp_parm.user_flags = 0;
 new_obj(select_grp, &tmp_parm);

 PARM(305, 0, 320, 126, 0,0, 0, select_quit_on_click);
 new_obj(select_grp, &tmp_parm);

 PARM(305, 366, 320, 114, 0,0, 0, select_quit_on_click);
 tmp_parm.user_flags = VERTICAL;
 new_obj(select_grp, &tmp_parm);

 PARM(625, 0, 15, 480, 0,0,0, select_quit_on_click);
 tmp_parm.user_flags = 0;
 new_obj(select_grp, &tmp_parm);

 main_grp = new_group(0,0, WIDTH, HEIGHT, 0, 0);

 PARM(0,0,WIDTH,HEIGHT,&globl_fg,&globl_bg,DROP_ACCUM|LOAD_XPM_FROM_ARRAY,proc_bitmap);
 tmp_parm.dp1 = back_xpm;
 background_object = new_obj(main_grp, &tmp_parm);

 PARM(82,22,0,0,&globl_fg,&globl_bg,
   TOGGLE|CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.callback = undo_button;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 1;
 tmp_parm.dp1 = undo_xpm;
 new_obj(main_grp, &tmp_parm);


 /* tools */

 PARM(124, 22, 0, 0, &globl_fg, &globl_bg,
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY, proc_icon_button);
 tmp_parm.callback = tool_change;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = select_xpm;
 select_object = new_obj(main_grp, &tmp_parm);

 PARM(82, 53, 0, 0, &globl_fg, &globl_bg,
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY, proc_icon_button);
 tmp_parm.callback = tool_change;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = pal_hi_low_xpm;
 pal_hi_low_object = new_obj(main_grp, &tmp_parm);

 PARM(124, 53, 0, 0, &globl_fg, &globl_bg, 
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.callback = tool_change;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = flip_xpm;
 flip_object = new_obj(main_grp, &tmp_parm);
 

 PARM(82,88,0,0,&globl_fg,&globl_bg,
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.callback = tool_change;
 tmp_parm.d1 = TRUE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = line_xpm;
 line_object = new_obj(main_grp, &tmp_parm);
 last_tool = line_object;

 PARM(124,88,0,0,&globl_fg,&globl_bg,
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.callback = tool_change;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = put_pat_xpm;
 put_pat_object = new_obj(main_grp, &tmp_parm);

 PARM(82,123,0,0,&globl_fg,&globl_bg,
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY,proc_icon_button); 
 tmp_parm.callback = tool_change;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = fill_xpm;
 fill_object = new_obj(main_grp, &tmp_parm);

 PARM(124,123,0,0,&globl_fg,&globl_bg,
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.callback = tool_change;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = clear_to_color_xpm;
 clear_to_color_object = new_obj(main_grp, &tmp_parm);


 PARM(82,158,0,0,&globl_fg,&globl_bg,
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY,proc_icon_button); 
 tmp_parm.callback = tool_change;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = pic_xpm;
 pic_object = new_obj(main_grp, &tmp_parm);

 PARM(124,158,0,0,&globl_fg,&globl_bg,
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY,proc_icon_button); 
 tmp_parm.callback = tool_change;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = pic_pat_xpm;
 pic_pat_object = new_obj(main_grp, &tmp_parm);



 /* not tools */

#ifndef WINDOWS
 PARM(580,450,50,17,&globl_fg,&globl_bg,SHOW_FOCUS|CALL_BUTTON|DROP_SHADOW,proc_button_box);
 tmp_parm.dp1 = (void *)"F/W";
 tmp_parm.callback = fw_bottom;
 new_obj(main_grp, &tmp_parm);
#endif

 
 PARM(580,1,50,17,&globl_fg,&globl_bg,SHOW_FOCUS|CALL_BUTTON|DROP_SHADOW,proc_button_box);
 tmp_parm.dp1 = (void *)"Quit";
 tmp_parm.callback = really_quit;
 new_obj(main_grp, &tmp_parm);

 
 PARM(500,1,50,17,&globl_fg,&globl_bg,SHOW_FOCUS|CALL_BUTTON|DROP_SHADOW,proc_button_box);
 tmp_parm.dp1 = (void *)"About";
 tmp_parm.callback = about;
 new_obj(main_grp, &tmp_parm);

 PARM(20,1, 50,17,&globl_fg,&globl_bg,SHOW_FOCUS|CALL_BUTTON|DROP_SHADOW,proc_button_box);
 tmp_parm.dp1 = (void *)"Load";
 tmp_parm.user_flags = LOAD;
 tmp_parm.callback=load_save_top;
 new_obj(main_grp, &tmp_parm);

 load_grp = new_menu(20,5, load_menu, &globl_fg, &globl_bg);

 PARM(75,1, 50,17,&globl_fg,&globl_bg,SHOW_FOCUS|CALL_BUTTON|DROP_SHADOW,proc_button_box);
 tmp_parm.dp1 = (void *)"Save";
 tmp_parm.user_flags = SAVE;
 tmp_parm.callback=load_save_top;
 new_obj(main_grp, &tmp_parm);

 save_grp = new_menu(75,5, save_menu, &globl_fg, &globl_bg);
 high_low_grp = new_menu(124,88, high_low_menu, &globl_fg, &sprite_color);
 hor_ver_grp = new_menu(124,88,horizontal_vertical_menu, &globl_fg, &sprite_color);
 pal_hi_low_grp = new_menu(124,88, pal_hi_low_menu, &globl_fg, &sprite_color);
 copy_move_grp = new_menu(124,88,copy_move_menu, &globl_fg, &sprite_color);

 PARM(380,1,90,17,&globl_fg,&globl_bg,SHOW_FOCUS|CALL_BUTTON|DROP_SHADOW,proc_button_box);
 tmp_parm.dp1 = (void *)"Background";
 tmp_parm.callback = change_background;
 new_obj(main_grp, &tmp_parm);

 PARM(425,81,0,0,&globl_fg,&globl_bg,
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.callback = preview_zoom_change;
 tmp_parm.d1 = FALSE;
 tmp_parm	.d2 = 4;
 tmp_parm.dp1 = zoom_out_xpm;
 preview_zoom_out = new_obj(main_grp,&tmp_parm);

 PARM(461,81,0,0,&globl_fg,&globl_bg,
   CALL_BUTTON|SHOW_FOCUS|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.callback = preview_zoom_change;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 5;
 tmp_parm.dp1 = zoom_in_xpm;
 preview_zoom_in = new_obj(main_grp,&tmp_parm);

 PARM(499,83, 31,27, &globl_fg,&globl_bg,CALL_BUTTON,proc_button_box);
 tmp_parm.callback = change_bg_color;
 tmp_parm.dp1 = (char *)" ";
 bg_color_box = new_obj(main_grp, &tmp_parm);
 UPDATE_BG_COLOR;

 PARM(305,114,320,11,&globl_move_color, &globl_bg,SHOW_FOCUS|CALL_BUTTON,proc_scroll_bar);
 tmp_parm.d2 = 256;
 tmp_parm.d1 = 0;
 tmp_parm.callback = preview_scroll_change;
 preview_scroll_bar = new_obj(main_grp, &tmp_parm);

 PARM(292,126,11,240,&globl_move_color,&globl_bg,SHOW_FOCUS|CALL_BUTTON,proc_scroll_bar);
 tmp_parm.d2 = 0;
 tmp_parm.d1 = 0;
 preview_y_scroll = new_obj(main_grp,&tmp_parm);

 PARM(305,367,320,11,&globl_move_color,&globl_bg,SHOW_FOCUS|CALL_BUTTON,proc_scroll_bar);
 tmp_parm.d2 = 0;
 tmp_parm.d1 = 0;
 preview_x_scroll = new_obj(main_grp,&tmp_parm);


 tmp_parm.callback = preview_size_change;
 PARM(293,82,0,0,&globl_fg, &globl_bg, SHOW_FOCUS|CALL_BUTTON, proc_radio_button);
 tmp_parm.d1 = TRUE;
 tmp_parm.d2 = 1;
 tmp_parm.dp1 = (void *)"NTSC";
 preview_ntsc = new_obj(main_grp, &tmp_parm);

 PARM(293,96,0,0,&globl_fg, &globl_bg, SHOW_FOCUS|CALL_BUTTON, proc_radio_button);
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 1;
 tmp_parm.dp1 = (void *)"PAL";
 preview_pal = new_obj(main_grp, &tmp_parm);

 PARM(348,82,0,0,&globl_fg, &globl_bg, SHOW_FOCUS|CALL_BUTTON, proc_radio_button);
 tmp_parm.d1 = TRUE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = (void *)"40 cell";
 preview_40c = new_obj(main_grp, &tmp_parm);

 PARM(348,96,0,0,&globl_fg, &globl_bg, SHOW_FOCUS|CALL_BUTTON, proc_radio_button);
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 2;
 tmp_parm.dp1 = (void *)"32 cell";
 preview_32c = new_obj(main_grp, &tmp_parm);




 PARM(190,297,11,176,&globl_move_color,&globl_bg,CALL_BUTTON|SHOW_FOCUS,proc_scroll_bar);
 tmp_parm.d2 = 0xf6;
 tmp_parm.d1 = 0;
 tmp_parm.callback = pattern_select_bot;
 pattern_select_scroll_bar = new_obj(main_grp, &tmp_parm);

 
 PARM(10,301,179,0xa*16,&globl_fg,&globl_bg,0,proc_pattern_select);
 pattern_select_object = new_obj(main_grp, &tmp_parm);

 PARM(10,22,70,260,&globl_fg,&globl_bg,0,proc_palette_change_object);
 palette_change_object = new_obj(main_grp, &tmp_parm);

 /* Pattern edit */
 PARM(88,200,67,83,&globl_fg,&globl_bg,0,proc_pattern_edit);
 pattern_edit_object = new_obj(main_grp, &tmp_parm);

 PARM(305,126,320,240,&globl_fg,&globl_bg,0,proc_preview_object);
 preview_object = new_obj(main_grp,&tmp_parm);

 PARM(540,88,65,17,&globl_fg,&globl_bg,SHOW_FOCUS|CALL_BUTTON,proc_button_box);
 tmp_parm.dp1 = (void *)"overlay";
 tmp_parm.callback = load_ovr_window;
 preview_overlay = new_obj(main_grp, &tmp_parm);


/* View and edit what? */

 tmp_parm.callback = edit_change;
 PARM(254,96,0,0,&globl_fg,&globl_bg, 
   SHOW_FOCUS|CALL_BUTTON|LOAD_XPM_FROM_ARRAY, proc_icon_button);
 tmp_parm.d1 = TRUE;
 tmp_parm.d2 = 3;
 tmp_parm.user_flags = EDIT_SCROLL_A;
 tmp_parm.dp1 = scroll_a_edit_xpm;
 new_obj(main_grp, &tmp_parm);
 currently_editing = EDIT_SCROLL_A;

 PARM(254,120,0,0,&globl_fg,&globl_bg, 
   SHOW_FOCUS|CALL_BUTTON|LOAD_XPM_FROM_ARRAY, proc_icon_button);
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 3;
 tmp_parm.user_flags = EDIT_SCROLL_B;
 tmp_parm.dp1 = scroll_b_edit_xpm;
 new_obj(main_grp, &tmp_parm);

 PARM(254,144,0,0,&globl_fg,&globl_bg, 
   SHOW_FOCUS|CALL_BUTTON|LOAD_XPM_FROM_ARRAY, proc_icon_button);
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 3;
 tmp_parm.user_flags = EDIT_SPRITE;
 tmp_parm.dp1 = sprite_edit_xpm;
 new_obj(main_grp, &tmp_parm);


 tmp_parm.callback = edit_change;
 PARM(230,96,0,0,&globl_fg,&globl_bg, 
   SHOW_FOCUS|CALL_BUTTON|LOAD_XPM_FROM_ARRAY|SINGLE_RADIO, proc_icon_button);
 tmp_parm.d1 = TRUE;
 tmp_parm.d2 = 4;
 tmp_parm.user_flags = VIEW_SCROLL_B;
 tmp_parm.dp1 = scroll_b_xpm;
 new_obj(main_grp, &tmp_parm);

 PARM(230,120,0,0,&globl_fg,&globl_bg, 
   SHOW_FOCUS|CALL_BUTTON|LOAD_XPM_FROM_ARRAY|SINGLE_RADIO, proc_icon_button);
 tmp_parm.d1 = TRUE;
 tmp_parm.d2 = 4;
 tmp_parm.user_flags = VIEW_SCROLL_A;
 tmp_parm.dp1 = scroll_a_xpm;
 new_obj(main_grp, &tmp_parm);


 PARM(230,120+24,0,0,&globl_fg,&globl_bg, 
   SHOW_FOCUS|CALL_BUTTON|LOAD_XPM_FROM_ARRAY|SINGLE_RADIO, proc_icon_button);
 tmp_parm.d1 = TRUE;
 tmp_parm.d2 = 4;
 tmp_parm.user_flags = VIEW_SCROLL_B_HIGH;
 tmp_parm.dp1 = scroll_b_high_xpm;
 new_obj(main_grp, &tmp_parm);

 PARM(230,120+24+24,0,0,&globl_fg,&globl_bg, 
   SHOW_FOCUS|CALL_BUTTON|LOAD_XPM_FROM_ARRAY|SINGLE_RADIO, proc_icon_button);
 tmp_parm.d1 = TRUE;
 tmp_parm.d2 = 4;
 tmp_parm.user_flags = VIEW_SCROLL_A_HIGH;
 tmp_parm.dp1 = scroll_a_high_xpm;
 new_obj(main_grp, &tmp_parm);





 PARM(353,25,31,31, &hscroll_color, &globl_bg, 0, proc_scroll_size);
 new_obj(main_grp, &tmp_parm); 

 PARM(415,25,41,41, &globl_fg, &globl_bg, 0, proc_sprite_size);
 new_obj(main_grp, &tmp_parm); 

 PARM(369, 64,0,0,&globl_fg, &globl_bg, 0, proc_ctext);
 tmp_parm.dp1 = (void *)malloc( 8 );
 snprintf(tmp_parm.dp1, 8, "64x64");
 scroll_width = 1;
 scroll_height = 1;

 scroll_size2 =new_obj(main_grp, &tmp_parm);

 sprite_width = 0;
 sprite_height = 0;

 PARM(410, 393,41,51, &globl_fg, &globl_bg, CALL_BUTTON|MODULAR|HEX|INACTIVE, proc_knob);
 tmp_parm.d1 = 40;
 tmp_parm.d2 = 0x400;
 tmp_parm.user_flags = KNOB;
 tmp_parm.callback = knob_tick;
 knob = new_obj(main_grp, &tmp_parm);


 PARM(244,410, 23,24,&globl_fg, &globl_bg,
   LOAD_XPM_FROM_ARRAY|SHOW_FOCUS|CALL_BUTTON|SINGLE_RADIO,proc_icon_button);
 tmp_parm.dp1 = small_knob_xpm;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 200;
 tmp_parm.callback = knob_select;
 knob_icon = new_obj(main_grp,&tmp_parm);

 PARM(315, 422, 0,0, &globl_fg, &globl_bg, 0, proc_ctext);
 tmp_parm.dp1 = (void *)malloc(64);
 snprintf( tmp_parm.dp1, 64, ":<");
 knob_text = new_obj(main_grp,&tmp_parm);


 PARM(272, 256, 11, 82, &globl_fg, &globl_bg, 0, proc_scroll_bar_special)
 tmp_parm.d1 = 2;
 tmp_parm.d2 = 2;
 tmp_parm.user_flags = HORIZONTAL;
 horizontal_scroll_bar = new_obj(main_grp, &tmp_parm);

 PARM(493,385, 82,11, &globl_fg, &globl_bg, 0, proc_scroll_bar_special);
 tmp_parm.d1 = 0;
 tmp_parm.d2 = 1;
 tmp_parm.user_flags = VERTICAL;
 vertical_scroll_bar = new_obj(main_grp, &tmp_parm);

 PARM(462, 401, 0,0, &globl_fg, &globl_bg, SHOW_FOCUS|CALL_BUTTON|LOAD_XPM_FROM_ARRAY,
   proc_icon_button);
 tmp_parm.d1 = TRUE;
 tmp_parm.d2 = 5;
 tmp_parm.dp1 = (void *)scroll_a_edit_xpm;
 tmp_parm.callback = knob_tick;
 tmp_parm.user_flags = SELECT_A;
 select_a_object = new_obj(main_grp, &tmp_parm);

 PARM(462, 423, 0,0, &globl_fg, &globl_bg, SHOW_FOCUS|CALL_BUTTON|LOAD_XPM_FROM_ARRAY,
   proc_icon_button);
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 5;
 tmp_parm.dp1 = (void *)scroll_b_edit_xpm;
 tmp_parm.callback = knob_tick;
 tmp_parm.user_flags = SELECT_B;
 new_obj(main_grp, &tmp_parm);

 tmp_parm.proc = load_default_mega;
 select_b_object = new_obj(main_grp, &tmp_parm);

 PARM(172, 177, 0,0, &globl_fg, &globl_bg, SHOW_FOCUS|SINGLE_RADIO|LOAD_XPM_FROM_ARRAY,
   proc_icon_button);
// tmp_parm.callback = stop_bot;
 tmp_parm.dp1 = (void *)clob_xpm;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 401;
 clob_object = new_obj(main_grp, &tmp_parm);

 PARM(172, 202, 0,0, &globl_fg, &globl_bg, CALL_BUTTON|SHOW_FOCUS|SINGLE_RADIO|LOAD_XPM_FROM_ARRAY,
   proc_icon_button);
 tmp_parm.callback = stop_bot;
 tmp_parm.dp1 = (void *)stop_xpm;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 401;
 stop_object = new_obj(main_grp, &tmp_parm);

 PARM(172, 227, 0,0, &globl_fg, &globl_bg, CALL_BUTTON|SHOW_FOCUS|SINGLE_RADIO|LOAD_XPM_FROM_ARRAY,
   proc_icon_button);
 tmp_parm.callback = go_bot;
 tmp_parm.dp1 = (void *)clear_xpm;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 401;
 new_obj(main_grp, &tmp_parm);

 PARM(172, 252, 0,0, &globl_fg, &globl_bg, CALL_BUTTON|SHOW_FOCUS|SINGLE_RADIO|LOAD_XPM_FROM_ARRAY,
   proc_icon_button);
 tmp_parm.callback = new_bot;
 tmp_parm.dp1 = (void *)new_xpm;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 401;
 new_obj(main_grp, &tmp_parm);

 PARM(490, 400, 140, 45, &globl_fg, &globl_bg, DROP_SHADOW, proc_info);
 info_object = new_obj(main_grp, &tmp_parm);

/* SHADOW BOX */

 PARM(170, 175, 25, 100, &globl_fg, &globl_bg, DROP_SHADOW, proc_shadow_box);
 new_obj(main_grp, &tmp_parm);

 PARM(460, 400, 25, 45, &globl_fg, &globl_bg, DROP_SHADOW, proc_shadow_box);
 new_obj(main_grp, &tmp_parm);


 PARM(270, 254, 14, 86, &globl_fg, &globl_bg, DROP_SHADOW, proc_shadow_box);
 new_obj(main_grp, &tmp_parm);

 PARM(491,383, 86, 14, &globl_fg, &globl_bg, DROP_SHADOW, proc_shadow_box);
 new_obj(main_grp, &tmp_parm);

 PARM(240, 407, 150, 30, &globl_fg, &globl_bg, DROP_SHADOW, proc_shadow_box);
 knob_message_box = new_obj(main_grp, &tmp_parm);

 PARM(405, 400, 50, 45, &globl_fg, &globl_bg, DROP_SHADOW, proc_shadow_box);
 new_obj(main_grp, &tmp_parm);

 PARM(340, 21, 58, 50, &globl_fg,&globl_bg, DROP_SHADOW, proc_shadow_box);
 scroll_size1 = new_obj(main_grp, &tmp_parm);

 PARM(340+67, 21, 58, 50, &globl_fg,&globl_bg, DROP_SHADOW, proc_shadow_box);
 sprite_size1 = new_obj(main_grp, &tmp_parm);


 PARM(340+67+67+((58/4)-6), 20+((50/4)-6)-1, 20, 20, &globl_fg, &globl_bg, 
   CALL_BUTTON|SHOW_FOCUS|SINGLE_RADIO|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.callback = sprite_overlay;
 tmp_parm.dp1 = (void *)minus_xpm;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 401;
 minus_object = new_obj(main_grp, &tmp_parm);

 PARM(340+67+67+((58/4)-6), 20+((50/2)+2)-1, 20, 20, &globl_fg, &globl_bg, 
   CALL_BUTTON|SHOW_FOCUS|SINGLE_RADIO|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.dp1 = (void *)plus_xpm;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 401;
 plus_object =  new_obj(main_grp, &tmp_parm);


 PARM(340+67+67+((58/4)+15), 20+((50/4)-6)-1, 20, 20, &globl_fg, &globl_bg, 
   CALL_BUTTON|SHOW_FOCUS|SINGLE_RADIO|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.dp1 = (void *)a_xpm;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 401;
 a_object = new_obj(main_grp, &tmp_parm);

 PARM(340+67+67+((58/4)+15), 20+((50/2)+2)-1, 20, 20, &globl_fg, &globl_bg, 
   CALL_BUTTON|SHOW_FOCUS|SINGLE_RADIO|LOAD_XPM_FROM_ARRAY,proc_icon_button);
 tmp_parm.dp1 = (void *)b_xpm;
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 401;
 b_object = new_obj(main_grp, &tmp_parm);





 PARM(340+67+67,21,58,50, &globl_fg, &globl_bg, DROP_SHADOW, proc_shadow_box);
 new_obj(main_grp,&tmp_parm);
 
 
 PARM(228, 94, 50, 148-24-24, &globl_fg,&globl_bg, DROP_SHADOW, proc_shadow_box);
 new_obj(main_grp, &tmp_parm);

 PARM(8,19,152,266,&globl_fg,&globl_bg,DROP_SHADOW,proc_shadow_box);
 new_obj(main_grp, &tmp_parm);

 PARM(8,295,198,179,&globl_fg,&globl_bg,DROP_SHADOW,proc_shadow_box);
 new_obj(main_grp, &tmp_parm);

 

 PARM(288,80,340,300,&globl_fg,&globl_bg,DROP_SHADOW,proc_shadow_box);
 preview_box_object =  new_obj(main_grp, &tmp_parm);

 red.r = 0x7f;
 red.g = 0;
 red.b = 0;

 green.r = 0;
 green.g = 0x7f;
 green.b = 0;
  
 blue.r = 0;
 blue.g = 0;
 blue.b = 0x7f;

 PARM(168,22,100,11,&red,&globl_bg,SHOW_FOCUS|CALL_BUTTON,proc_scroll_bar);
 tmp_parm.d2 = 7;
 tmp_parm.d1 = 
  current_vdp->palette[current_palette][current_palette_index].r / (0xff/7);
 tmp_parm.callback = color_change_bot;
 rgb_red_object = new_obj(main_grp, &tmp_parm);

 tmp_parm.d1 = 
  current_vdp->palette[current_palette][current_palette_index].g / (0xff/7);
 tmp_parm.y+=18;
 tmp_parm.fg = &green;
 rgb_green_object = new_obj(main_grp, &tmp_parm);


 tmp_parm.d1 = 
  current_vdp->palette[current_palette][current_palette_index].b / (0xff/7);
 tmp_parm.y+=18;
 tmp_parm.fg = &blue;
 rgb_blue_object = new_obj(main_grp, &tmp_parm);

 PARM(301,38,24,8,&current_color_text_color,&globl_bg,0,proc_ctext);
 tmp_parm.dp1 = (void *)malloc(4);
 current_color_text_object = new_obj(main_grp,&tmp_parm);

 PARM(301,52,24,8, &current_color_text_color, &globl_bg, 0,proc_ctext);
 tmp_parm.dp1 = (void *)malloc(4);
 current_color_text2_object = new_obj(main_grp, &tmp_parm);
  
 update_color_text();

 PARM(276,30,50,30,&globl_fg,&current_vdp->palette[0][0],0,proc_shadow_box);
 current_color_object = new_obj(main_grp, &tmp_parm);

 PARM(165,19,170,55,&globl_fg,&globl_bg,DROP_SHADOW,proc_shadow_box);
 rgb_box_object = new_obj(main_grp, &tmp_parm);



 overlay_sel = setup_overlay_window(400,300, LOAD, "an image", load_ovr_callback);
 background_sel = setup_overlay_window(400,300, LOAD, "an image", load_background_callback);


 pointers = new_group(200, 300, 151,151,globl_flags,globl_drop_depth);
 simple_window(pointers, 150, 150);

 PARM( 25, 100, 100, 30, &globl_fg, &globl_bg, QUIT_BUTTON|SHOW_FOCUS, proc_button_box);
 tmp_parm.dp1 = (char *)"OK";
 new_obj(pointers, &tmp_parm);

 PARM(30, 20, 0,0, &hscroll_color, &globl_bg, SHOW_FOCUS|SINGLE_RADIO, proc_radio_button);
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 50;
 tmp_parm.dp1 = (char *)"hscroll";
 hscroll_radio = new_obj(pointers, &tmp_parm);

 PARM(30, 31, 0,0, &sprite_color, &globl_bg, SHOW_FOCUS|SINGLE_RADIO, proc_radio_button);
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 50;
 tmp_parm.dp1 = (char *)"sprite";
 sprite_radio = new_obj(pointers, &tmp_parm);

 PARM(30, 42, 0,0, &scroll_a_color, &globl_bg, SHOW_FOCUS|SINGLE_RADIO, proc_radio_button);
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 50;
 tmp_parm.dp1 = (char *)"scroll_a";
 scroll_a_radio = new_obj(pointers, &tmp_parm);

 PARM(30, 53, 0,0, &scroll_b_color, &globl_bg, SHOW_FOCUS|SINGLE_RADIO, proc_radio_button);
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 50;
 tmp_parm.dp1 = (char *)"scroll_b";
 scroll_b_radio = new_obj(pointers, &tmp_parm);

 PARM(30, 64, 0,0, &window_color, &globl_bg, SHOW_FOCUS|SINGLE_RADIO, proc_radio_button);
 tmp_parm.d1 = FALSE;
 tmp_parm.d2 = 50;
 tmp_parm.dp1 = (char *)"window";
 window_radio = new_obj(pointers, &tmp_parm);

 load_sel = setup_overlay_window(400,300, LOAD, "123456", load_save_bottom);
 save_sel = setup_overlay_window(400,300, SAVE, "123456", load_save_bottom);
}
Esempio n. 23
0
int main (int argc, char **argv)
{

    logfilepath = getenv ("HOME");
    logfilepath = strcat (logfilepath, "/.ooview.log");

    load_config();


    initscr();
    raw();
    noecho();
    start_color();
    keypad(stdscr,TRUE);

    init_pair(1, COLOR_WHITE, COLOR_BLACK);
    init_pair(2, COLOR_RED, COLOR_WHITE);
    init_pair(3, COLOR_BLUE, COLOR_WHITE);
    init_pair(4, COLOR_BLACK, COLOR_WHITE);
    bkgd(COLOR_PAIR(1));
    curs_set(0);

    menu_bar = subwin(stdscr,1,COLS,0,0);
    wbkgd(menu_bar,COLOR_PAIR(2));
    waddstr(menu_bar,"File");
    wattron(menu_bar, COLOR_PAIR(3));
    waddstr(menu_bar,"<F1>");
    wattroff(menu_bar, COLOR_PAIR(3));
    wmove(menu_bar, 0, 19);
    waddstr(menu_bar,"View");
    wattron(menu_bar, COLOR_PAIR(3));
    waddstr(menu_bar,"<F2>");
    wattroff(menu_bar, COLOR_PAIR(3));
    wmove(menu_bar, 0, 34);
    waddstr(menu_bar,"Options");
    wattron(menu_bar, COLOR_PAIR(3));
    waddstr(menu_bar,"<F3>");
    wattroff(menu_bar, COLOR_PAIR(3));
    wmove(menu_bar, 0, 53);
    waddstr(menu_bar,"Help");
    wattron(menu_bar, COLOR_PAIR(3));
    waddstr(menu_bar,"<F4>");
    wattroff(menu_bar, COLOR_PAIR(3));

    status_bar = subwin(stdscr,1,COLS,LINES-1,0);
    wbkgd(status_bar,COLOR_PAIR(4));

    n_choices[0] = ARRAY_SIZE(file_choices);
    n_choices[1] = ARRAY_SIZE(view_choices);
    n_choices[2] = ARRAY_SIZE(opts_choices);
    n_choices[3] = ARRAY_SIZE(help_choices);
    file_items = (ITEM **)calloc(n_choices[0] + 1, sizeof(ITEM *));
    view_items = (ITEM **)calloc(n_choices[1] + 1, sizeof(ITEM *));
    opts_items = (ITEM **)calloc(n_choices[2] + 1, sizeof(ITEM *));
    help_items = (ITEM **)calloc(n_choices[3] + 1, sizeof(ITEM *));

    for (i=0; i<n_choices[0]; ++i)
        file_items[i] = new_item(file_choices[i], NULL);

    for (i=0; i<n_choices[1]; ++i)
        view_items[i] = new_item(view_choices[i], NULL);

    for (i=0; i<n_choices[2]; ++i)
        opts_items[i] = new_item(opts_choices[i], NULL);

    for (i=0; i<n_choices[3]; ++i)
        help_items[i] = new_item(help_choices[i], NULL);

    file_items[n_choices[0]] = (ITEM *)NULL;
    view_items[n_choices[1]] = (ITEM *)NULL;
    opts_items[n_choices[2]] = (ITEM *)NULL;
    help_items[n_choices[3]] = (ITEM *)NULL;

    file_menu = new_menu((ITEM **)file_items);
    view_menu = new_menu((ITEM **)view_items);
    opts_menu = new_menu((ITEM **)opts_items);
    help_menu = new_menu((ITEM **)help_items);

    set_menu_mark(file_menu, "");
    set_menu_mark(view_menu, "");
    set_menu_mark(opts_menu, "");
    set_menu_mark(help_menu, "");

    init_screen();
    if (argc == 2)
        open_file(argv[1]);

    while ((c = getch()) != EXIT_KEY)
    {
        action_performed = false;

        switch (c)
        {
        case KEY_F(1):
            cur_menu=1;
            break;
        case KEY_F(2):
            cur_menu=2;
            break;
        case KEY_F(3):
            cur_menu=3;
            break;
        case KEY_F(4):
            cur_menu=4;
            break;
        case KEY_UP:
            if ((file_printed) && (buffer->cur_line > 1))
            {
                int backsteps = 0;
                int steps;
                char *tmp;

                if ((*--cur_char)==NEWLINE)
                    backsteps++;

                tmp = cur_char - 1;

                if ((*--cur_char) == NEWLINE)
                {
                    cur_char = tmp;
                    print_status_bar("yeah");
                }
                else
                {
                    do {
                        cur_char--;
                        backsteps++;
                    } while (((*cur_char)!=NEWLINE) && (cur_char != buffer->content));

                    if (backsteps > COLS)
                    {
                        int test;
                        test = backsteps/COLS;
                        steps = (backsteps%COLS);
                        if (test>1)
                            steps += COLS;

                        mvwprintw(status_bar,0,0,"%d",steps);
                        touchwin(status_bar);
                        wrefresh(status_bar);
                        cur_char += backsteps;
                        cur_char -= steps;
                    }
                }
                buffer->cur_line--;
                print_site(buffer->cur_line, buffer->lines);

                if (cur_char!=buffer->content)
                    print_file(buffer,++cur_char);
                else
                    print_file(buffer,cur_char);
            }
            break;
        case KEY_DOWN:
            if ((file_printed) && (buffer->cur_line < buffer->lines))
            {
                int cols=0;


                while (((*cur_char)!=NEWLINE) && (cols < COLS-1))
                {
                    cols++;
                    cur_char++;
                }


                buffer->cur_line++;
                print_site(buffer->cur_line, buffer->lines);
                print_file(buffer,++cur_char);
            }
            break;
        default:
            if (meta_win!=NULL)
            {
                delwin(meta_win);
                touchwin(stdscr);
                refresh();
            }

        }

        if (cur_menu == 1)
        {
            file_win = newwin(8,19,1,0);
            keypad(file_win,TRUE);
            box(file_win,0,0);
            set_menu_win(file_menu, file_win);
            set_menu_sub(file_menu, derwin(file_win,6,17,1,1));
            post_menu(file_menu);
            while (c = wgetch(file_win))
            {
                if (c == KEY_DOWN)
                    menu_driver(file_menu, REQ_DOWN_ITEM);
                else if (c == KEY_UP)
                    menu_driver(file_menu, REQ_UP_ITEM);
                else if (c == KEY_RIGHT)
                {
                    cur_menu = 2;
                    break;
                }
                else if (c == KEY_LEFT)
                {
                    cur_menu = 4;
                    break;
                }
                else if (c == RETURN)
                {
                    cur_menu = 0;
                    cmd = (char *)item_name(current_item(file_menu));
                    action_performed = true;
                    break;
                }
                else
                {
                    cur_menu = 0;
                    break;
                }

            }

            unpost_menu(file_menu);
            touchwin(stdscr);
            wrefresh(stdscr);
        }
        if (cur_menu == 2)
        {
            view_win = newwin(6,15,1,19);
            keypad(view_win,TRUE);
            box(view_win,0,0);
            set_menu_win(view_menu, view_win);
            set_menu_sub(view_menu, derwin(view_win,4,13,1,1));
            post_menu(view_menu);
            while (c = wgetch(view_win))
            {
                if (c == KEY_DOWN)
                    menu_driver(view_menu, REQ_DOWN_ITEM);
                else if (c == KEY_UP)
                    menu_driver(view_menu, REQ_UP_ITEM);
                else if (c == KEY_RIGHT)
                {
                    cur_menu = 3;
                    break;
                }
                else if (c == KEY_LEFT)
                {
                    cur_menu = 1;
                    break;
                }
                else if (c == RETURN)
                {
                    cur_menu = 0;
                    cmd = (char *)item_name(current_item(view_menu));
                    action_performed = true;
                    break;
                }
                else
                {
                    cur_menu = 0;
                    break;
                }
            }

            unpost_menu(view_menu);
            touchwin(stdscr);
            refresh();
        }
        if (cur_menu == 3)
        {
            opts_win = newwin(5,19,1,34);
            keypad(opts_win,TRUE);
            box(opts_win,0,0);
            set_menu_win(opts_menu, opts_win);
            set_menu_sub(opts_menu, derwin(opts_win,3,17,1,1));
            post_menu(opts_menu);
            while (c = wgetch(opts_win))
            {
                if (c == KEY_DOWN)
                    menu_driver(opts_menu, REQ_DOWN_ITEM);
                else if (c == KEY_UP)
                    menu_driver(opts_menu, REQ_UP_ITEM);
                else if (c == KEY_RIGHT)
                {
                    cur_menu = 4;
                    break;
                }
                else if (c == KEY_LEFT)
                {
                    cur_menu = 2;
                    break;
                }
                else if (c == RETURN)
                {
                    cur_menu = 0;
                    cmd = (char *)item_name(current_item(opts_menu));
                    action_performed = true;
                    break;
                }
                else
                {
                    cur_menu = 0;
                    break;
                }
            }

            unpost_menu(opts_menu);
            touchwin(stdscr);
            refresh();
        }
        if (cur_menu == 4)
        {
            help_win = newwin(6,17,1,53);
            keypad(help_win,TRUE);
            box(help_win,0,0);
            set_menu_win(help_menu, help_win);
            set_menu_sub(help_menu, derwin(help_win,4,15,1,1));
            post_menu(help_menu);
            while (c = wgetch(help_win))
            {
                if (c == KEY_DOWN)
                    menu_driver(help_menu, REQ_DOWN_ITEM);
                else if (c == KEY_UP)
                    menu_driver(help_menu, REQ_UP_ITEM);
                else if (c == KEY_RIGHT)
                {
                    cur_menu = 1;
                    break;
                }
                else if (c == KEY_LEFT)
                {
                    cur_menu = 3;
                    break;
                }
                else if (c == RETURN)
                {
                    cur_menu = 0;
                    cmd = (char *)item_name(current_item(help_menu));
                    action_performed = true;
                    break;
                }
                else
                {
                    cur_menu = 0;
                    break;
                }
            }

            unpost_menu(help_menu);
            touchwin(stdscr);
            refresh();
        }




        if (action_performed)
        {
            char file[80];
            clear_status_bar();

            if (!strcmp(cmd,"Open"))
            {
                if (file_printed==false)
                {
                    print_status_bar("Enter a file: ");
                    curs_set(1);
                    echo();
                    wscanw(status_bar,"%s",file);			/* get filename from user */
                    curs_set(0);
                    noecho();
                    open_file(file);


                }
                else
                {
                    print_status_bar("Please close current file.");
                }

            }
            if (!strcmp(cmd,"Close"))
            {
                if (file_printed)
                {
                    free(buffer);


                    werase(main_win);
                    init_screen();
                    wrefresh(main_win);
                    file_printed = false;
                    system("rm -rf /tmp/ooview");


                }
                else
                {
                    print_status_bar("No open file!");
                }
            }
            if (!strcmp(cmd,"Reload"))
            {
                if (file_printed)
                {
                    if (strstr(file,".ovd")!=NULL)			/* ovd*/
                    {
                        ovd_file = fopen(file,"r");

                        if (ovd_file != NULL)
                        {
                            free(buffer);
                            buffer = (struct fileinfo *)malloc(sizeof(struct fileinfo));
                            main_win = subwin(stdscr,LINES-2,COLS,1,0);
                            get_file_content(ovd_file, file, buffer);
                            fclose(ovd_file);
                            cur_char = buffer->content;
                            print_site(buffer->cur_line, buffer->lines);
                            print_file(buffer,cur_char);
                            file_printed = true;
                        }
                        else
                        {
                            print_status_bar("File does not exist!");
                        }
                    }
                    else								/* else if odt */
                    {
                        free(buffer);
                        buffer = (struct fileinfo *)malloc(sizeof(struct fileinfo));
                        main_win= subwin(stdscr,LINES-2,COLS,1,0);
                        open_odt(file,buffer);
                        get_file_meta("/tmp/ooview/meta.xml",buffer);
                        cur_char = buffer->content;
                        print_site(buffer->cur_line, buffer->lines);
                        print_file(buffer,cur_char);
                        file_printed = true;
                    }


                }
                else
                {
                    print_status_bar("No open file!");
                }
            }

            if (!strcmp(cmd,"Document info"))
            {
                if (file_printed)
                {
                    if (file_type==1)
                    {

                        meta_win = newwin(9,COLS-2,(LINES/2)-5,1);
                        wbkgd(meta_win,COLOR_PAIR(4));


                        mvwprintw(meta_win,1,1,"Genarator:  %s", buffer->generator);
                        mvwprintw(meta_win,2,1,"Initial creator:\t%s", buffer->initial_creator);
                        mvwprintw(meta_win,3,1,"Creation date:\t\t%s", buffer->creation_date);
                        mvwprintw(meta_win,4,1,"Creator:\t\t%s", buffer->creator);
                        mvwprintw(meta_win,5,1,"Date:\t\t\t%s", buffer->date);
                        mvwprintw(meta_win,6,1,"Editing cycles:\t%s", buffer->editing_cycles);
                        mvwprintw(meta_win,7,1,"Editing duration:\t%s", buffer->editing_duration);

                        box(meta_win,0,0);
                        wrefresh(meta_win);
                        touchwin(meta_win);

                    }
                }
                else
                {
                    print_status_bar("No open file!");
                }
            }

            if (!strcmp(cmd,"OOView homepage"))
            {
                char *syscall;
                syscall=(char *)malloc(strlen(BROWSER)+strlen(HOMEPAGE_URL)+1);


                sprintf(syscall, "%s %s", BROWSER, HOMEPAGE_URL);
                system(syscall);
                free(syscall);
                if (file_printed)
                    free(buffer);
                end_curses();
                return(0);

            }

            if (!strcmp(cmd,"Documentation"))
            {
                char *syscall;
                syscall=(char *)malloc(strlen(BROWSER)+strlen(HOMEPAGE_URL)+1);


                sprintf(syscall, "%s %s", BROWSER, HOMEPAGE_URL);
                system(syscall);
                free(syscall);
                if (file_printed)
                    free(buffer);
                end_curses();
                return(0);

            }

            if (!strcmp(cmd, "About OOView"))
                print_status_bar("OOView. Visit Homepage for details");

            if (!strcmp(cmd, "Copying"))
                print_status_bar("OOView is under GPL/2 Visit Homepage for details");

            if (!strcmp(cmd, "Find")) {

                if (file_printed) {

                    print_status_bar("Enter string to find: ");
                    char *findit;

                    curs_set(1);
                    echo();

                    wscanw(status_bar,"%s",findit);

                    /*

                    how to find a string in a string?
                    find it -> set cursor to position

                    */

                    print_status_bar("Not implemented yet :(");
                    curs_set(0);
                    noecho();
                } else {
                    print_status_bar("No open file!");
                }
            }

            if (!strcmp(cmd, "External Programs")) {
                char *prompt;

                /*getting printer command*/
                prompt = (char *)malloc((strlen("Enter Printing Command []: ")+strlen(PRINTER)));
                sprintf(prompt,"Enter Printing Command [%s]: ",PRINTER);
                print_status_bar(prompt);
                free(prompt);

                curs_set(1);
                echo();
                char *newcmd;
                wscanw(status_bar,"%s",newcmd);
                curs_set(0);
                noecho();
                print_status_bar(newcmd);
                /* / getting printer command*/

            }

            if (!strcmp(cmd,"Exit"))
            {
                if (file_printed)
                    free(buffer);
                end_curses();
                return 0;
            }
        }

    }
    if (file_printed)
        free(buffer);

    end_curses();
    return 0;
}
Esempio n. 24
0
/*
 * create the internal menu for the files 
 */
static void wdg_file_menu_create(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_file_handle, ww);
   int mrows, mcols;
   int i;
   size_t c = wdg_get_ncols(wo);
   size_t x = wdg_get_begin_x(wo);
   size_t y = wdg_get_begin_y(wo);
   struct stat buf;

   /* the menu is already posted */
   if (ww->nitems)
      return;
 
   WDG_DEBUG_MSG("wdg_file_menu_create");
   
   /* get the working directory */
   getcwd(ww->curpath, PATH_MAX);
         
   /* scan the directory */
   ww->nlist = scandir(".", &ww->namelist, 0, alphasort);

   /* on error display the message in the box */
   if (ww->nlist <= 0) {
      ww->nitems = 2;
      WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
      ww->items[ww->nitems - 2] = new_item("/", "root");
      ww->items[ww->nitems - 1] = new_item("Cannot open the directory", "");
      item_opts_off(ww->items[ww->nitems - 1], O_SELECTABLE);
   } else {

      /* for each directory in the directory */
      for (i = 0; i < ww->nlist; i++) {
        
         /* 
          * transform the current dir into the root.
          * useful to exit from a path whose parent is not readable 
          */
         if (!strcmp(ww->namelist[i]->d_name, ".")) {
            strncpy(ww->namelist[i]->d_name, "/", 1);
            ww->nitems++;
            WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
            ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "root");
            continue;
         }
         
         /* get the file properties */
         stat(ww->namelist[i]->d_name, &buf);
         
         if (S_ISDIR(buf.st_mode)) {
            ww->nitems++;
            WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
            ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "[...]");
         }
         // if not readable
         //item_opts_off(ww->items[ww->nitems - 1], O_SELECTABLE);
      }
      
      /* and now add the files */
      for (i = 0; i < ww->nlist; i++) {
         
         /* get the file properties */
         stat(ww->namelist[i]->d_name, &buf);
         
         if (!S_ISDIR(buf.st_mode)) {
            ww->nitems++;
            WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
            ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "");
         }
      }
   }

   /* null terminate the array */
   WDG_SAFE_REALLOC(ww->items, (ww->nitems + 1) * sizeof(ITEM *));
   ww->items[ww->nitems] = NULL;
     
   /* create the menu */
   ww->m = new_menu(ww->items);

   /* set the dimensions */
   set_menu_format(ww->m, ww->y - 2, 1);
   set_menu_spacing(ww->m, 2, 0, 0);

   /* get the geometry to make a window */
   scale_menu(ww->m, &mrows, &mcols);

   /* 
    * if the menu is larger than the main window
    * adapt to the new dimensions
    */
   if (mcols > (int)c - 4) {
      ww->x = mcols + 4;
      wdg_file_redraw(wo);
      return;
   }
   /* create the window for the menu */
   ww->mwin = newwin(mrows, MAX(mcols, (int)c - 4), y + 1, x + 2);
   /* set the color */
   wbkgd(ww->mwin, COLOR_PAIR(wo->window_color));
   keypad(ww->mwin, TRUE);
  
   /* associate with the menu */
   set_menu_win(ww->m, ww->mwin);
   
   /* the subwin for the menu */
   set_menu_sub(ww->m, derwin(ww->mwin, mrows + 1, mcols, 1, 1));

   /* menu attributes */
   set_menu_mark(ww->m, "");
   set_menu_grey(ww->m, COLOR_PAIR(wo->window_color));
   set_menu_back(ww->m, COLOR_PAIR(wo->window_color));
   set_menu_fore(ww->m, COLOR_PAIR(wo->window_color) | A_REVERSE | A_BOLD);
   
   /* display the menu */
   post_menu(ww->m);

   wnoutrefresh(ww->mwin);
   
}
Esempio n. 25
0
void textris(){
	int score = 0;

	srand(time(NULL));

	setlocale(LC_ALL, "");

	initscr();			
	cbreak();
	noecho();
	halfdelay(1);
	keypad(stdscr, TRUE);

	start_color();
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_YELLOW, COLOR_BLACK);
	init_pair(3, COLOR_BLUE, COLOR_BLACK);
	init_pair(4, COLOR_GREEN, COLOR_BLACK);
	init_pair(5, COLOR_WHITE, COLOR_BLACK);
	init_pair(6, COLOR_CYAN, COLOR_BLACK);
	init_pair(7, COLOR_MAGENTA, COLOR_BLACK);

	//menu

	int MENU_WIDTH = 20;
	int SCREEN_WIDTH = 100;

	char *choices[] = {
                        "20 Lines",
                        "40 Lines",
                        "Classic",
                        "Read Me",
                        "Exit",
                  };

	ITEM **menu_items;
	int c;				
	MENU *menu;
	int n_choices, i;
	ITEM *cur_item;
	WINDOW *menu_win;

	n_choices = ARRAY_SIZE(choices);
	menu_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));

	for(i = 0; i < n_choices; ++i)
	        menu_items[i] = new_item(choices[i], "");
	menu_items[n_choices] = (ITEM *)NULL;

	menu = new_menu((ITEM **)menu_items);

	/* Create the window to be associated with the menu */
	menu_win = newwin(10, MENU_WIDTH + 2, 5, (SCREEN_WIDTH/2) - (MENU_WIDTH/2));
	keypad(menu_win, TRUE);

	/* Set main window and sub window */
	set_menu_win(menu, menu_win);
	set_menu_sub(menu, derwin(menu_win, 6, MENU_WIDTH, 3, 1)); //must be less than window

	/* Set menu mark to the string " * " */
	set_menu_mark(menu, " * ");
	post_menu(menu);
	wrefresh(menu_win);

	draw_menu(menu_win, menu);

	refresh();

	while((c = wgetch(menu_win)) != KEY_F(1))
	{   switch(c)
	    {	case KEY_DOWN:
		        menu_driver(menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(menu, REQ_UP_ITEM);
				break;
			case KEY_LEFT:
				twenty_lines();
				draw_menu(menu_win, menu);
				break;
		}
	}	

	for(i = 0; i < n_choices; ++i)
		free_item(menu_items[i]);
	free_menu(menu);
	endwin();

	//double res = twenty_lines();

	/*while(1){
		mvprintw(0, 0, "20 lines cleared in %f seconds", res);
		refresh();
	}

	endwin();*/
}
Esempio n. 26
0
int teacher_menu(char *database){
	int i, c, n, choice = 0;
	teacher *xteacher;
	WINDOW *win;
	ITEM **items;
	MENU *menu;
	n = teacher_number(database);
	start_color();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	xteacher = (teacher *)malloc(sizeof(teacher) * (n + 1));
	items = (ITEM **)calloc(n + 3, sizeof(ITEM *));
	for(i = 0; i < n; ++i) {
		xteacher[i] = get_teacher(database,i);
		items[i] = new_item(xteacher[i].name, NULL);
	}
	menu = new_menu((ITEM **)items);
	win = newwin(0, 0, 0, 0);
	int y,x;
	getmaxyx(win,y,x);
	keypad(win, TRUE);
	set_menu_win(menu, win);
	set_menu_sub(menu, derwin(win, y - 5, 38, 5, 0.4*x));
	set_menu_format(menu,x - 4, 1);
	set_menu_mark(menu, " * ");
	set_menu_spacing(menu, 0, 2, 0);
	box(win, 0, 0);
	print_in_middle(win, 1, 0, x, "Teachers" , COLOR_PAIR(1));
	mvwaddch(win, 2, 0, ACS_LTEE);
	mvwhline(win, 2, 1, ACS_HLINE, x - 2);
	mvwaddch(win, 2, x - 1, ACS_RTEE);
	mvwaddch(win, y - 3, 0, ACS_LTEE);
	mvwhline(win, y - 3, 1, ACS_HLINE, x - 2);
	mvwaddch(win, y - 3, x - 1, ACS_RTEE);
	refresh();
	if(n) {
		if(n > 1)
			mvwprintw(win,y - 2, 2,"N:New Teacher\t\tR:Remove Teacher\tS:Sort\t\tB:Back\tQ:Quit");
		else
			mvwprintw(win,y - 2, 2,"N:New Teacher\t\tR:Remove Teacher\tB:Back\tQ:Quit");
		for(i = 0; i < choice; i++)
			menu_driver(menu, REQ_DOWN_ITEM);
		post_menu(menu);
		wrefresh(win);
		while((c = wgetch(win))){
			switch(c) {
				case KEY_DOWN:
					menu_driver(menu, REQ_DOWN_ITEM);
					if(choice != n -1)
						choice++;
					break;
				case KEY_UP:
					menu_driver(menu, REQ_UP_ITEM);
					if(choice != 0)
						choice--;
					break;
				case 10: /* Enter */
					remove_menu(menu,items,n);
					return choice;
				case 'R':
				case 'r':
					remove_teacher(database, choice);
					remove_menu(menu,items,n);
					return -1;
				case 'B':
				case 'b':
					remove_menu(menu,items,n);
					return n + 1;
				case 'N':
				case 'n':
					remove_menu(menu,items,n);
					return n + 2;
				case 'Q':
				case 'q':
					remove_menu(menu,items,n);
					return INT_MIN;
				default:
					break;
			}
			wrefresh(win);
		}
	}
	else {
		mvwprintw(win,y - 2, 2,"N:New Teacher\t\tB:Back\t\tQ:Quit");
		mvwprintw(win,5,3*x/7,"No Teachers found :(\n");
		wrefresh(win);
		curs_set(0);
		while((c = wgetch(win)))
		{
			switch(c) {
				case 'n':
				case 'N':
					remove_menu(menu,items,n);
					curs_set(1);
					return n+2;
				case 'b':
				case 'B':
					remove_menu(menu,items,n);
					curs_set(1);
					return n+1;
				case 'Q':
				case 'q':
					remove_menu(menu,items,n);
					curs_set(1);
					return INT_MIN;
				default:
					break;
			}
			wrefresh(win);
		}
	}
	free(xteacher);
	return -1;
}
Esempio n. 27
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
        WINDOW *my_menu_win;
        int n_choices, i;
	
	/* Initialize curses */
	initscr();
	start_color();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);
	init_pair(1, COLOR_RED, COLOR_BLACK);

	/* Create items */
        n_choices = ARRAY_SIZE(choices);
        my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
        for(i = 0; i < n_choices; ++i)
                my_items[i] = new_item(choices[i], choices[i]);

	/* Crate menu */
	my_menu = new_menu((ITEM **)my_items);

	/* Create the window to be associated with the menu */
        my_menu_win = newwin(10, 40, 4, 4);
        keypad(my_menu_win, TRUE);
     
	/* Set main window and sub window */
        set_menu_win(my_menu, my_menu_win);
        set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1));

	/* Set menu mark to the string " * " */
        set_menu_mark(my_menu, " * ");

	/* Print a border around the main window and print a title */
        box(my_menu_win, 0, 0);
	print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1));
	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
	mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
	mvprintw(LINES - 2, 0, "F1 to exit");
	refresh();
        
	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);

	while((c = wgetch(my_menu_win)) != KEY_F(1))
	{       switch(c)
	        {	case KEY_DOWN:
				menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;
		}
                wrefresh(my_menu_win);
	}	

	/* Unpost and free all the memory taken up */
        unpost_menu(my_menu);
        free_menu(my_menu);
        for(i = 0; i < n_choices; ++i)
                free_item(my_items[i]);
	endwin();
}
Esempio n. 28
0
PANEL *
column_select_create()
{
    int attr_id, column;
    PANEL *panel;
    WINDOW *win;
    MENU *menu;
    int height, width;
    column_select_info_t *info;

    // Calculate window dimensions
    height = 20;
    width = 60;

    // Cerate a new indow for the panel and form
    win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);

    // Create a new panel
    panel = new_panel(win);

    // Initialize Filter panel specific data
    info = sng_malloc(sizeof(column_select_info_t));

    // Store it into panel userptr
    set_panel_userptr(panel, (void*) info);

    // Initialize the fields
    info->fields[FLD_COLUMNS_ACCEPT] = new_field(1, 10, height - 2, 13, 0, 0);
    info->fields[FLD_COLUMNS_SAVE]   = new_field(1, 10, height - 2, 25, 0, 0);
    info->fields[FLD_COLUMNS_CANCEL] = new_field(1, 10, height - 2, 37, 0, 0);
    info->fields[FLD_COLUMNS_COUNT] = NULL;

    // Field Labels
    set_field_buffer(info->fields[FLD_COLUMNS_ACCEPT], 0, "[ Accept ]");
    set_field_buffer(info->fields[FLD_COLUMNS_SAVE],   0, "[  Save  ]");
    set_field_buffer(info->fields[FLD_COLUMNS_CANCEL], 0, "[ Cancel ]");

    // Create the form and post it
    info->form = new_form(info->fields);
    set_form_sub(info->form, win);
    post_form(info->form);

    // Create a subwin for the menu area
    info->menu_win = derwin(win, 10, width - 2, 7, 0);

    // Initialize one field for each attribute
    for (attr_id = 0; attr_id < SIP_ATTR_COUNT; attr_id++) {
        // Create a new field for this column
        info->items[attr_id] = new_item("[ ]", sip_attr_get_description(attr_id));
        set_item_userptr(info->items[attr_id], (void*) sip_attr_get_name(attr_id));
    }
    info->items[SIP_ATTR_COUNT] = NULL;

    // Create the columns menu and post it
    info->menu = menu = new_menu(info->items);

    // Set current enabled fields
    // FIXME Stealing Call list columns :/
    call_list_info_t *list_info = call_list_info(ui_get_panel(ui_find_by_type(PANEL_CALL_LIST)));

    // Enable current enabled fields and move them to the top
    for (column = 0; column < list_info->columncnt; column++) {
        const char *attr = list_info->columns[column].attr;
        for (attr_id = 0; attr_id < item_count(menu); attr_id++) {
            if (!strcmp(item_userptr(info->items[attr_id]), attr)) {
                column_select_toggle_item(panel, info->items[attr_id]);
                column_select_move_item(panel, info->items[attr_id], column);
                break;
            }
        }
    }

    // Set main window and sub window
    set_menu_win(menu, win);
    set_menu_sub(menu, derwin(win, 10, width - 5, 7, 2));
    set_menu_format(menu, 10, 1);
    set_menu_mark(menu, "");
    set_menu_fore(menu, COLOR_PAIR(CP_DEF_ON_BLUE));
    menu_opts_off(menu, O_ONEVALUE);
    post_menu(menu);

    // Draw a scrollbar to the right
    draw_vscrollbar(info->menu_win, top_row(menu), item_count(menu) - 1, 0);

    // Set the window title and boxes
    mvwprintw(win, 1, width / 2 - 14, "Call List columns selection");
    wattron(win, COLOR_PAIR(CP_BLUE_ON_DEF));
    title_foot_box(panel);
    mvwhline(win, 6, 1, ACS_HLINE, width - 1);
    mvwaddch(win, 6, 0, ACS_LTEE);
    mvwaddch(win, 6, width - 1, ACS_RTEE);
    wattroff(win, COLOR_PAIR(CP_BLUE_ON_DEF));

    // Some brief explanation abotu what window shows
    wattron(win, COLOR_PAIR(CP_CYAN_ON_DEF));
    mvwprintw(win, 3, 2, "This windows show the list of columns displayed on Call");
    mvwprintw(win, 4, 2, "List. You can enable/disable using Space Bar and reorder");
    mvwprintw(win, 5, 2, "them using + and - keys.");
    wattroff(win, COLOR_PAIR(CP_CYAN_ON_DEF));

    info->form_active = 0;

    return panel;
}
Esempio n. 29
0
int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
{
	va_list ap;
	char *btn;
	int btns_width = 0;
	int msg_lines = 0;
	int msg_width = 0;
	int total_width;
	int win_rows = 0;
	WINDOW *win;
	WINDOW *msg_win;
	WINDOW *menu_win;
	MENU *menu;
	ITEM *btns[btn_num+1];
	int i, x, y;
	int res = -1;


	va_start(ap, btn_num);
	for (i = 0; i < btn_num; i++) {
		btn = va_arg(ap, char *);
		btns[i] = new_item(btn, "");
		btns_width += strlen(btn)+1;
	}
	va_end(ap);
	btns[btn_num] = NULL;

	
	msg_lines = get_line_no(msg);
	for (i = 0; i < msg_lines; i++) {
		const char *line = get_line(msg, i);
		int len = get_line_length(line);
		if (msg_width < len)
			msg_width = len;
	}

	total_width = max(msg_width, btns_width);
	
	y = (LINES-(msg_lines+4))/2;
	x = (COLS-(total_width+4))/2;


	
	if (btn_num > 0)
		win_rows = msg_lines+4;
	else
		win_rows = msg_lines+2;

	win = newwin(win_rows, total_width+4, y, x);
	keypad(win, TRUE);
	menu_win = derwin(win, 1, btns_width, win_rows-2,
			1+(total_width+2-btns_width)/2);
	menu = new_menu(btns);
	msg_win = derwin(win, win_rows-2, msg_width, 1,
			1+(total_width+2-msg_width)/2);

	set_menu_fore(menu, attributes[DIALOG_MENU_FORE]);
	set_menu_back(menu, attributes[DIALOG_MENU_BACK]);

	(void) wattrset(win, attributes[DIALOG_BOX]);
	box(win, 0, 0);

	
	(void) wattrset(msg_win, attributes[DIALOG_TEXT]);
	fill_window(msg_win, msg);

	set_menu_win(menu, win);
	set_menu_sub(menu, menu_win);
	set_menu_format(menu, 1, btn_num);
	menu_opts_off(menu, O_SHOWDESC);
	menu_opts_off(menu, O_SHOWMATCH);
	menu_opts_on(menu, O_ONEVALUE);
	menu_opts_on(menu, O_NONCYCLIC);
	set_menu_mark(menu, "");
	post_menu(menu);


	touchwin(win);
	refresh_all_windows(main_window);
	while ((res = wgetch(win))) {
		switch (res) {
		case KEY_LEFT:
			menu_driver(menu, REQ_LEFT_ITEM);
			break;
		case KEY_RIGHT:
			menu_driver(menu, REQ_RIGHT_ITEM);
			break;
		case 10: 
		case 27: 
		case ' ':
		case KEY_F(F_BACK):
		case KEY_F(F_EXIT):
			break;
		}
		touchwin(win);
		refresh_all_windows(main_window);

		if (res == 10 || res == ' ') {
			res = item_index(current_item(menu));
			break;
		} else if (res == 27 || res == KEY_F(F_BACK) ||
				res == KEY_F(F_EXIT)) {
			res = KEY_EXIT;
			break;
		}
	}

	unpost_menu(menu);
	free_menu(menu);
	for (i = 0; i < btn_num; i++)
		free_item(btns[i]);

	delwin(win);
	return res;
}
Esempio n. 30
0
int
edit_pos (SwitchPos * sp, AppData * a)
{
  MENU *my_menu;
  uint32_t i, maxx;
  int state = 0;
  ITEM **my_items;
//      WINDOW * menu_win,*menu_sub;
  uint32_t num_strings;
  int lbl_x, idx;

  message (a,
           "Here you can set the initial tuning file or edit the frequency bands.\n");
  while (state >= 0)
  {
    num_strings = 2;
    state = 0;
    debugMsg ("allocating items\n");
    my_items = (ITEM **) utlCalloc (num_strings + 1, sizeof (ITEM *));
    my_items[0] = new_item ("Bands", "Bands");
    my_items[1] = new_item ("ITF", "ITF");
    my_items[num_strings] = (ITEM *) NULL;
    my_menu = new_menu ((ITEM **) my_items);
    set_menu_opts (my_menu, O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR);
    maxx = getmaxx (stdscr);
    appDataMakeMenuWnd (my_menu);
    post_menu (my_menu);
    lbl_x = 3 + (maxx - 6) / 2 - strlen ("Position") / 2;
    mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Position");
    wrefresh (menu_win (my_menu));
    debugMsg ("starting menu loop\n");
    while (state == 0)
    {
      int c;
      ITEM *selection;
      c = getch ();
      switch (c)
      {
      case 263:                //ESC
      case K_BACK:             //Backspace
        state = -1;
        break;
      case KEY_DOWN:
        menu_driver (my_menu, REQ_DOWN_ITEM);
        break;
      case KEY_UP:
        menu_driver (my_menu, REQ_UP_ITEM);
        break;
      case KEY_RESIZE:
        //windows need to be resized.. ignore
        break;
      case 13:                 //enter
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 5;
        break;
      default:
        break;
      }
      wrefresh (menu_win (my_menu));
    }
    unpost_menu (my_menu);
    appDataDestroyMenuWnd (my_menu);
    free_menu (my_menu);
    for (i = 0; i < num_strings; ++i)
    {
      free_item (my_items[i]);
    }
    utlFAN (my_items);
    if (state == 5)
    {
      switch (idx)
      {
      case 0:
        edit_bands (sp, a);
        break;
      case 1:
        set_itf (sp, a);
        break;
      default:
        break;
      }
    }
  }
  return 0;
}