Example #1
0
int main()
{       
	int c, choice = 0;
	WINDOW *menu_win;
	MEVENT event;

	/* 初始化 curses */
	initscr();
	clear();
	noecho();
	cbreak();                                       /* 禁用行缓冲,直接传递所有的信号 */

	/* 将窗口放在屏幕中央 */
	startx = (80 - WIDTH) / 2;
	starty = (24 - HEIGHT) / 2;

	attron(A_REVERSE);
	mvprintw(23, 1, "Click on Exit to quit (Works best in a virtual console)");
	refresh();
	attroff(A_REVERSE);

	/* 首先显示菜单 */
	menu_win = newwin(HEIGHT, WIDTH, starty, startx);
	print_menu(menu_win, 1);
	/* 监听所有的鼠标事件 */
	mousemask(ALL_MOUSE_EVENTS, NULL);

	while(1)
	{       
		c = wgetch(menu_win);
		switch(c)
		{       
			case KEY_MOUSE:
			if(getmouse(&event) == OK)
			{                               /* 用户按下鼠标左键 */
				if(event.bstate & BUTTON1_PRESSED)
				{       
					report_choice(event.x + 1, event.y + 1, &choice);
					if(choice == -1) /* 退出选项 */
						goto end;
					mvprintw(22, 1, "Choice made is : %d String Chosen is \"%10s\"", choice, choices[choice - 1]);
					refresh(); 
				}
			}
			print_menu(menu_win, choice);
			break;
		}
	}               
end:
	endwin();
	return 0;
}
Example #2
0
int main()
{	int c, choice = 0;
	WINDOW *menu_win;
	MEVENT event;

	/* Initialize curses */
	initscr();
	clear();
	noecho();
	cbreak();	//Line buffering disabled. pass on everything

	/* Try to put the window in the middle of screen */
	startx = (80 - WIDTH) / 2;
	starty = (24 - HEIGHT) / 2;
	
	attron(A_REVERSE);
	mvprintw(23, 1, "Click on Exit to quit (Works best in a virtual console)");
	refresh();
	attroff(A_REVERSE);

	/* Print the menu for the first time */
	menu_win = newwin(HEIGHT, WIDTH, starty, startx);
	print_menu(menu_win, 1);
	/* Get all the mouse events */
	mousemask(ALL_MOUSE_EVENTS, NULL);
	
	while(1)
	{	c = wgetch(menu_win);
		switch(c)
		{	case KEY_MOUSE:
			if(getmouse(&event) == OK)
			{	/* When the user clicks left mouse button */
				if(event.bstate & BUTTON1_PRESSED)
				{	report_choice(event.x + 1, event.y + 1, &choice);
					if(choice == -1) //Exit chosen
						goto end;
					mvprintw(22, 1, "Choice made is : %d String Chosen is \"%10s\"", choice, choices[choice - 1]);
					refresh(); 
				}
			}
			print_menu(menu_win, choice);
			break;
		}
	}		
end:
	endwin();
	return 0;
}
int main(int argc, char const *argv[]) {
    int c, choice = 0;
    WINDOW *menu_win;
    MEVENT event;

    initscr();
    clear();
    noecho();
    cbreak();

    startx = (80 - WIDTH) / 2;
    starty = (24 - HEIGHT) / 2;

    attron(A_REVERSE);
    mvprintw(23, 1, "Click on Exit to quit (Works best in a virtual console)");
    refresh();
    attroff(A_REVERSE);

    menu_win = newwin(HEIGHT, WIDTH, starty, startx);
    print_menu(menu_win, 1);
    mousemask(ALL_MOUSE_EVENTS, NULL);

    while (1) {
        c = wgetch(menu_win);
        switch (c) {
        case KEY_MOUSE:
            if (getmouse(&event) == OK) {
                if (event.bstate & BUTTON1_PRESSED) {
                    report_choice(event.x + 1, event.y + 1, &choice);
                    if (choice == -1)
                        goto end;
                    mvprintw(22, 1, "Choice made is : %d String Choice is \"%s\"", choice, choices[choice]);
                    refresh();
                }
            }
            print_menu(menu_win, choice);
            break;
        }
    }
end:
    endwin();
    return 0;
}
Example #4
0
int _tmain(int argc, _TCHAR* argv[])
{
	setlocale(LC_ALL, "en_US.UTF-8");
	//Start SDL
	SDL_Init(SDL_INIT_EVERYTHING);

	int c, choice = 0;
	WINDOW *menu_win = NULL;
	MEVENT event;


	/* Initialize curses */
	initscr();
	clear();
	noecho();
	cbreak();	//Line buffering disabled. pass on everything

	/* Try to put the window in the middle of screen */
	startx = (80 - WIDTH) / 2;
	starty = (24 - HEIGHT) / 2;

	attron(A_REVERSE);
	mvprintw(23, 1, "Click on Exit to quit (Works best in a virtual console)");
	refresh();
	attroff(A_REVERSE);

	/* Print the menu for the first time */
//	menu_win = newwin(HEIGHT, WIDTH, 0, 0);

	// Initialize game resources.
	Game game(&menu_win);
	PhysicalPlayer player;


//	print_menu(menu_win, 1);
	game.DrawGame(menu_win);
	/* Get all the mouse events */
	mousemask(ALL_MOUSE_EVENTS, NULL);

	while (1)
	{
		c = wgetch(menu_win);
		switch (c)
		{
		case KEY_MOUSE:
			if (nc_getmouse(&event) == OK)
//			if (getmouse() == OK)
			{	
				if (event.bstate & BUTTON1_CLICKED)
				{
					game.OnMouseEvent(event);
					report_choice(event.x + 1, event.y + 1, &choice);
					if (choice == -1) //Exit chosen
						goto end;
					mvprintw(22, 1, "Choice made is : %d String Chosen is \"%10s\"", choice, choices[choice - 1]);
					refresh();
				}
			}
			print_menu(menu_win, choice);
			break;
		}
	}
end:
	endwin();
	return 0;

	//Quit SDL
//	SDL_Quit();

	return 0;
}