Exemplo n.º 1
0
int MenuX( int x, int y, int NumButtons, char * text[] )
{
	UI_DIALOG * dlg;
	menu *m;
	int button_width, button_height, width, height;
	int i;
	int w, h;
	int choice;

	MALLOC(m, menu, 1);
	m->num_buttons = NumButtons;
	m->button_g = (UI_GADGET_BUTTON **) d_malloc(sizeof(UI_GADGET_BUTTON *)*NumButtons);
	MALLOC(m->button, char *, NumButtons);
	m->choice = &choice;

	button_width = button_height = 0;

	for (i=0; i<NumButtons; i++ )
	{
		m->button[i] = text[i];

		ui_get_button_size( m->button[i], &width, &height );

		if ( width > button_width ) button_width = width;
		if ( height > button_height ) button_height = height;
	}

	width = button_width + 2*(MENU_BORDER+3);

	height = (button_height*NumButtons) + (MENU_VERT_SPACING*(NumButtons-1)) ;
	height += (MENU_BORDER+3) * 2;

	w = grd_curscreen->sc_w;
	h = grd_curscreen->sc_h;

	{
		int mx, my, mz;
		
		mouse_get_pos(&mx, &my, &mz);
		if ( x == -1 ) x = mx - width/2;
		if ( y == -1 ) y = my;
	}

	if (x < 0 ) {
		x = 0;
	}

	if ( (x+width-1) >= w ) {
		x = w - width;
	}

	if (y < 0 ) {
		y = 0;
	}

	if ( (y+height-1) >= h ) {
		y = h - height;
	}

	dlg = ui_create_dialog( x, y, width, height, DF_FILLED | DF_SAVE_BG | DF_MODAL, (int (*)(UI_DIALOG *, d_event *, void *))menu_handler, m );

	x = MENU_BORDER+3;
	y = MENU_BORDER+3;

	for (i=0; i<NumButtons; i++ )
	{
		m->button_g[i] = ui_add_gadget_button( dlg, x, y, button_width, button_height, m->button[i], NULL );
		y += button_height+MENU_VERT_SPACING;
	}

	choice = 0;

	while(choice==0)
		event_process();

	ui_close_dialog(dlg);
	d_free(m->button);
	d_free(m->button_g);
	d_free(m);

	return choice;
}
Exemplo n.º 2
0
int PopupMenu( int NumButtons, char * text[] )
{
	UI_WINDOW * wnd;
	UI_GADGET_BUTTON * ButtonG[10];

	short SavedMouseX, SavedMouseY;
	char * Button[10];

	int button_width, button_height, width, height;

	short i, x, y;
	short w, h;

	int choice;

	ui_mouse_flip_buttons();

	//ui_mouse_process();

	if ( B1_RELEASED )
	{
		ui_mouse_flip_buttons();
		return -1;
	}

	if ((NumButtons < 1) || (NumButtons>10))
	{
		ui_mouse_flip_buttons();
		return -1;
	}

	SavedMouseX = Mouse.x; SavedMouseY = Mouse.y;

	button_width = button_height = 0;

	gr_set_current_canvas( &grd_curscreen->sc_canvas );

	for (i=0; i<NumButtons; i++ )
	{
		Button[i] = text[i];

		ui_get_button_size( Button[i], &width, &height );

		if ( width > button_width ) button_width = width;
		if ( height > button_height ) button_height = height;
	}

	width = button_width + 2*(MENU_BORDER+3);

	height = (button_height*NumButtons) + (MENU_VERT_SPACING*(NumButtons-1)) ;
	height += (MENU_BORDER+3) * 2;

	x = Mouse.x - width/2;
	y = Mouse.y - (MENU_BORDER+3) - button_height/2;

	w = grd_curscreen->sc_w;
	h = grd_curscreen->sc_h;

	if (x < 0 ) {
		x = 0;
		Mouse.x = x + width / 2;
	}

	if ( (x+width-1) >= w ) {
		x = w - width;
		Mouse.x = x + width / 2;
	}

	if (y < 0 ) {
		y = 0;
		Mouse.y = y + (MENU_BORDER+3) + button_height/2;
	}

	if ( (y+height-1) >= h ) {
		y = h - height;
		Mouse.y = y + (MENU_BORDER+3) + button_height/2;
	}

	wnd = ui_open_window( x, y, width, height, WIN_DIALOG );

	mouse_set_pos( Mouse.x, Mouse.y );

	x = MENU_BORDER+3;
	y = MENU_BORDER+3;

	for (i=0; i<NumButtons; i++ )
	{
		ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
		y += button_height+MENU_VERT_SPACING;
	}

	choice = 0;

	while(choice==0)
	{
		ui_mega_process();
		ui_window_do_gadgets(wnd);

		for (i=0; i<NumButtons; i++ )
		{
			if (ButtonG[i]->pressed)   {
				choice = i+1;
				break;
			}
		}

		if ( (choice==0) && B1_JUST_RELEASED )  {
			choice = -1;
			break;
		}

	}

	ui_close_window(wnd);

	ui_mouse_flip_buttons();

	return choice;

}
Exemplo n.º 3
0
Arquivo: menu.c Projeto: btb/d1x
int MenuX( int x, int y, int NumButtons, char * text[] )
{
	UI_WINDOW * wnd;
	UI_GADGET_BUTTON ** ButtonG;
	char ** Button;

	int button_width, button_height, width, height;

	int i;
	int w, h;

	int choice;

	ButtonG = (UI_GADGET_BUTTON **)malloc( sizeof(UI_GADGET_BUTTON *)*NumButtons );
	Button = (char **)malloc( sizeof(char *)*NumButtons );

	button_width = button_height = 0;

	for (i=0; i<NumButtons; i++ )
	{
		Button[i] = text[i];

		ui_get_button_size( Button[i], &width, &height );

		if ( width > button_width ) button_width = width;
		if ( height > button_height ) button_height = height;
	}

	width = button_width + 2*(MENU_BORDER+3);

	height = (button_height*NumButtons) + (MENU_VERT_SPACING*(NumButtons-1)) ;
	height += (MENU_BORDER+3) * 2;

	w = grd_curscreen->sc_w;
	h = grd_curscreen->sc_h;

	if ( x == -1 ) x = Mouse.x - width/2;
	if ( y == -1 ) y = Mouse.y;

	if (x < 0 ) {
		x = 0;
	}

	if ( (x+width-1) >= w ) {
		x = w - width;
	}

	if (y < 0 ) {
		y = 0;
	}

	if ( (y+height-1) >= h ) {
		y = h - height;
	}

	wnd = ui_open_window( x, y, width, height, WIN_FILLED | WIN_SAVE_BG );

	x = MENU_BORDER+3;
	y = MENU_BORDER+3;

	for (i=0; i<NumButtons; i++ )
	{
		ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
		y += button_height+MENU_VERT_SPACING;
	}

	choice = 0;

	while(choice==0)
	{
		ui_mega_process();
		ui_window_do_gadgets(wnd);

		for (i=0; i<NumButtons; i++ )
		{
			if (ButtonG[i]->pressed)   {
				choice = i+1;
				break;
			}
		}

		if ( (choice==0) && B1_JUST_RELEASED )  {
			choice = -1;
			break;
		}

	}

	ui_close_window(wnd);
	free(Button);
	free(ButtonG);

	return choice;

}
Exemplo n.º 4
0
Arquivo: popup.c Projeto: jihnsius/d2r
// Use: Left button (button 0) goes down, then up, then this is called
// as opposed to straight after the button goes down, holding down
// until an option is chosen.
// This is like the 'modern' behaviour of popup menus and also happens
// to be easier to implement because of the button code.
// Recommended for use in conjunction with a button gadget,
// i.e. when that button is pressed, call PopupMenu,
// update the button's text then the value in question.
int PopupMenu( int NumButtons, char * text[] )
{
	UI_DIALOG * dlg;
	popup	*p;

	char * Button[10];

	int button_width, button_height, width, height;

	short i, x, y;
	short w, h;

	int choice;

	MALLOC(p, popup, 1);
	
	p->num_buttons = NumButtons;
	p->choice = &choice;

	if ((NumButtons < 1) || (NumButtons>10))
	{
		d_free(p);
		return -1;
	}

	button_width = button_height = 0;

	gr_set_current_canvas( &grd_curscreen->sc_canvas );

	for (i=0; i<NumButtons; i++ )
	{
		Button[i] = text[i];

		ui_get_button_size( Button[i], &width, &height );

		if ( width > button_width ) button_width = width;
		if ( height > button_height ) button_height = height;
	}

	width = button_width + 2*(MENU_BORDER+3);

	height = (button_height*NumButtons) + (MENU_VERT_SPACING*(NumButtons-1)) ;
	height += (MENU_BORDER+3) * 2;

	{
		int mx, my, mz;
		
		mouse_get_pos(&mx, &my, &mz);
		x = mx - width/2;
		y = my - (MENU_BORDER+3) - button_height/2;
	}

	w = grd_curscreen->sc_w;
	h = grd_curscreen->sc_h;

	if (x < 0 ) {
		x = 0;
		//Mouse.x = x + width / 2;
	}

	if ( (x+width-1) >= w ) {
		x = w - width;
		//Mouse.x = x + width / 2;
	}

	if (y < 0 ) {
		y = 0;
		//Mouse.y = y + (MENU_BORDER+3) + button_height/2;
	}

	if ( (y+height-1) >= h ) {
		y = h - height;
		//Mouse.y = y + (MENU_BORDER+3) + button_height/2;
	}

	dlg = ui_create_dialog( x, y, width, height, DF_DIALOG | DF_MODAL, (int (*)(UI_DIALOG *, d_event *, void *))popup_handler, p );

	//mouse_set_pos(Mouse.x, Mouse.y);

	x = MENU_BORDER+3;
	y = MENU_BORDER+3;

	for (i=0; i<NumButtons; i++ )
	{
		p->button_g[i] = ui_add_gadget_button( dlg, x, y, button_width, button_height, Button[i], NULL );
		y += button_height+MENU_VERT_SPACING;
	}

	choice = 0;

	while(choice==0)
		event_process();

	ui_close_dialog(dlg);
	d_free(p);

	return choice;
}
Exemplo n.º 5
0
int MenuX( int x, int y, int NumButtons, const char *const text[] )
{
	UI_DIALOG * dlg;
	int button_width, button_height;
	int w, h;
	int choice;

	auto m = make_unique<menu>();
	m->num_buttons = NumButtons;
	m->button_g = make_unique<std::unique_ptr<UI_GADGET_BUTTON>[]>(NumButtons);
	m->button = make_unique<const char *[]>(NumButtons);
	m->choice = &choice;

	button_width = button_height = 0;

	for (int i=0; i<NumButtons; i++ )
	{
		m->button[i] = text[i];

		int width, height;
		ui_get_button_size(*grd_curcanv->cv_font, m->button[i], width, height);

		if ( width > button_width ) button_width = width;
		if ( height > button_height ) button_height = height;
	}

	unsigned width, height;
	width = button_width + 2*(MENU_BORDER+3);

	height = (button_height*NumButtons) + (MENU_VERT_SPACING*(NumButtons-1)) ;
	height += (MENU_BORDER+3) * 2;

	w = grd_curscreen->get_screen_width();
	h = grd_curscreen->get_screen_height();

	{
		int mx, my, mz;
		
		mouse_get_pos(&mx, &my, &mz);
		if ( x == -1 ) x = mx - width/2;
		if ( y == -1 ) y = my;
	}

	if (x < 0 ) {
		x = 0;
	}

	if ( (x+width-1) >= w ) {
		x = w - width;
	}

	if (y < 0 ) {
		y = 0;
	}

	if ( (y+height-1) >= h ) {
		y = h - height;
	}

	dlg = ui_create_dialog(x, y, width, height, static_cast<dialog_flags>(DF_FILLED | DF_SAVE_BG | DF_MODAL), menu_handler, m.get());

	x = MENU_BORDER+3;
	y = MENU_BORDER+3;

	for (int i=0; i<NumButtons; i++ )
	{
		m->button_g[i] = ui_add_gadget_button( dlg, x, y, button_width, button_height, m->button[i], NULL );
		y += button_height+MENU_VERT_SPACING;
	}

	choice = 0;

	while(choice==0)
		event_process();

	ui_close_dialog(dlg);
	return choice;
}