Give the dialog in (also presently unused) MenuX a callback
This commit is contained in:
parent
11daae4a2d
commit
5336ee198d
|
@ -3,6 +3,7 @@ D2X-Rebirth Changelog
|
||||||
20120103
|
20120103
|
||||||
--------
|
--------
|
||||||
ui/keypress.c: Give the dialog in (presently unused) GetKeyCode a callback
|
ui/keypress.c: Give the dialog in (presently unused) GetKeyCode a callback
|
||||||
|
ui/menu.c: Give the dialog in (also presently unused) MenuX a callback
|
||||||
|
|
||||||
20120102
|
20120102
|
||||||
--------
|
--------
|
||||||
|
|
84
ui/menu.c
84
ui/menu.c
|
@ -23,35 +23,65 @@ static char rcsid[] = "$Id: menu.c,v 1.1.1.1 2006/03/17 19:52:19 zicodxx Exp $";
|
||||||
#include "pstypes.h"
|
#include "pstypes.h"
|
||||||
#include "gr.h"
|
#include "gr.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
#include "mouse.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
|
|
||||||
#define MENU_BORDER 2
|
#define MENU_BORDER 2
|
||||||
#define MENU_VERT_SPACING 2
|
#define MENU_VERT_SPACING 2
|
||||||
|
|
||||||
|
typedef struct menu
|
||||||
|
{
|
||||||
|
UI_GADGET_BUTTON ** button_g;
|
||||||
|
char ** button;
|
||||||
|
int *choice;
|
||||||
|
int num_buttons;
|
||||||
|
} menu;
|
||||||
|
|
||||||
|
static int menu_handler(UI_DIALOG *dlg, d_event *event, menu *m)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<m->num_buttons; i++ )
|
||||||
|
{
|
||||||
|
if (m->button_g[i]->pressed)
|
||||||
|
{
|
||||||
|
*(m->choice) = i+1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( (*(m->choice)==0) && B1_JUST_RELEASED )
|
||||||
|
{
|
||||||
|
*(m->choice) = -1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int MenuX( int x, int y, int NumButtons, char * text[] )
|
int MenuX( int x, int y, int NumButtons, char * text[] )
|
||||||
{
|
{
|
||||||
UI_DIALOG * dlg;
|
UI_DIALOG * dlg;
|
||||||
UI_GADGET_BUTTON ** ButtonG;
|
menu *m;
|
||||||
char ** Button;
|
|
||||||
|
|
||||||
int button_width, button_height, width, height;
|
int button_width, button_height, width, height;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int w, h;
|
int w, h;
|
||||||
|
|
||||||
int choice;
|
int choice;
|
||||||
|
|
||||||
ButtonG = (UI_GADGET_BUTTON **) d_malloc(sizeof(UI_GADGET_BUTTON *)*NumButtons);
|
MALLOC(m, menu, 1);
|
||||||
Button = (char **) d_malloc(sizeof(char *)*NumButtons);
|
m->num_buttons = NumButtons;
|
||||||
|
m->button_g = (UI_GADGET_BUTTON **) d_malloc(sizeof(UI_GADGET_BUTTON *)*NumButtons);
|
||||||
|
m->button = (char **) d_malloc(sizeof(char *)*NumButtons);
|
||||||
|
m->choice = &choice;
|
||||||
|
|
||||||
button_width = button_height = 0;
|
button_width = button_height = 0;
|
||||||
|
|
||||||
for (i=0; i<NumButtons; i++ )
|
for (i=0; i<NumButtons; i++ )
|
||||||
{
|
{
|
||||||
Button[i] = text[i];
|
m->button[i] = text[i];
|
||||||
|
|
||||||
ui_get_button_size( Button[i], &width, &height );
|
ui_get_button_size( m->button[i], &width, &height );
|
||||||
|
|
||||||
if ( width > button_width ) button_width = width;
|
if ( width > button_width ) button_width = width;
|
||||||
if ( height > button_height ) button_height = height;
|
if ( height > button_height ) button_height = height;
|
||||||
|
@ -65,8 +95,13 @@ int MenuX( int x, int y, int NumButtons, char * text[] )
|
||||||
w = grd_curscreen->sc_w;
|
w = grd_curscreen->sc_w;
|
||||||
h = grd_curscreen->sc_h;
|
h = grd_curscreen->sc_h;
|
||||||
|
|
||||||
if ( x == -1 ) x = Mouse.x - width/2;
|
{
|
||||||
if ( y == -1 ) y = Mouse.y;
|
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 ) {
|
if (x < 0 ) {
|
||||||
x = 0;
|
x = 0;
|
||||||
|
@ -84,44 +119,27 @@ int MenuX( int x, int y, int NumButtons, char * text[] )
|
||||||
y = h - height;
|
y = h - height;
|
||||||
}
|
}
|
||||||
|
|
||||||
dlg = ui_create_dialog( x, y, width, height, DF_FILLED | DF_SAVE_BG | DF_MODAL, NULL, NULL );
|
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;
|
x = MENU_BORDER+3;
|
||||||
y = MENU_BORDER+3;
|
y = MENU_BORDER+3;
|
||||||
|
|
||||||
for (i=0; i<NumButtons; i++ )
|
for (i=0; i<NumButtons; i++ )
|
||||||
{
|
{
|
||||||
ButtonG[i] = ui_add_gadget_button( dlg, x, y, button_width, button_height, Button[i], NULL );
|
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;
|
y += button_height+MENU_VERT_SPACING;
|
||||||
}
|
}
|
||||||
|
|
||||||
choice = 0;
|
choice = 0;
|
||||||
|
|
||||||
while(choice==0)
|
while(choice==0)
|
||||||
{
|
|
||||||
event_process();
|
event_process();
|
||||||
|
|
||||||
for (i=0; i<NumButtons; i++ )
|
|
||||||
{
|
|
||||||
if (ButtonG[i]->pressed) {
|
|
||||||
choice = i+1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0 // FIXME: Put this code in the handler when it uses one
|
|
||||||
if ( (choice==0) && B1_JUST_RELEASED ) {
|
|
||||||
choice = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_close_dialog(dlg);
|
ui_close_dialog(dlg);
|
||||||
d_free(Button);
|
d_free(m->button);
|
||||||
d_free(ButtonG);
|
d_free(m->button_g);
|
||||||
|
d_free(m);
|
||||||
|
|
||||||
return choice;
|
return choice;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue