Simplify setup for ui_messagebox_n

This commit is contained in:
Kp 2013-12-04 23:31:29 +00:00
parent 92e8cb7a31
commit d1fa9ff7a6
2 changed files with 15 additions and 38 deletions

View file

@ -24,6 +24,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "event.h"
#ifdef __cplusplus
#include "varutil.h"
struct grs_bitmap;
struct grs_canvas;
@ -233,7 +234,10 @@ extern void ui_draw_shad( short x1, short y1, short x2, short y2, short c1, shor
void ui_init();
void ui_close();
int ui_messagebox( short x, short y, int NumButtons, const char * text, ... );
typedef cstring_tie<10> ui_messagebox_tie;
int ui_messagebox( short xc, short yc, const char * text, const ui_messagebox_tie &Button );
#define ui_messagebox(X,Y,N,T,...) ((ui_messagebox)((X),(Y),(T), ui_messagebox_tie(__VA_ARGS__)))
extern UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_flags flags, int (*callback)(UI_DIALOG *, struct d_event *, void *), void *userdata );
extern struct window *ui_dialog_get_window(UI_DIALOG *dlg);

View file

@ -39,11 +39,10 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
typedef struct messagebox
{
const array<const char *, 10> *button;
const ui_messagebox_tie *button;
UI_GADGET_BUTTON *button_g[10];
const char *text;
int *choice;
int num_buttons;
int width;
int text_y;
int line_y;
@ -78,7 +77,7 @@ static int messagebox_handler(UI_DIALOG *dlg, d_event *event, messagebox *m)
return 1;
}
for (i=0; i<m->num_buttons; i++ )
for (i=0; i < m->button->count(); i++ )
{
if (GADGET_PRESSED(m->button_g[i]))
{
@ -90,7 +89,7 @@ static int messagebox_handler(UI_DIALOG *dlg, d_event *event, messagebox *m)
return 0;
}
static int ui_messagebox_n( short xc, short yc, int NumButtons, const char * text, const array<const char *, 10> &Button )
int (ui_messagebox)( short xc, short yc, const char * text, const ui_messagebox_tie &Button )
{
UI_DIALOG * dlg;
messagebox *m;
@ -101,13 +100,10 @@ static int ui_messagebox_n( short xc, short yc, int NumButtons, const char * tex
int choice;
if ((NumButtons < 1) || (NumButtons>10)) return -1;
MALLOC(m, messagebox, 1);
m->button = &Button;
m->text = text;
m->choice = &choice;
m->num_buttons = NumButtons;
button_width = button_height = 0;
@ -115,9 +111,9 @@ static int ui_messagebox_n( short xc, short yc, int NumButtons, const char * tex
w = grd_curscreen->sc_w;
h = grd_curscreen->sc_h;
for (i=0; i<NumButtons; i++ )
for (i=0; i < Button.count(); i++ )
{
ui_get_button_size( Button[i], &width, &height );
ui_get_button_size( Button.string(i), &width, &height );
if ( width > button_width ) button_width = width;
if ( height > button_height ) button_height = height;
@ -125,8 +121,8 @@ static int ui_messagebox_n( short xc, short yc, int NumButtons, const char * tex
gr_get_string_size(text, &text_width, &text_height, &avg );
width = button_width*NumButtons;
width += BUTTON_HORZ_SPACING*(NumButtons+1);
width = button_width*Button.count();
width += BUTTON_HORZ_SPACING*(Button.count()+1);
width ++;
text_width += avg*6;
@ -192,12 +188,12 @@ static int ui_messagebox_n( short xc, short yc, int NumButtons, const char * tex
y = height - TEXT_EXTRA_HEIGHT - button_height;
for (i=0; i<NumButtons; i++ )
for (i=0; i < Button.count(); i++ )
{
x = EVEN_DIVIDE(width,button_width,NumButtons,i);
x = EVEN_DIVIDE(width,button_width,Button.count(),i);
m->button_g[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, Button.string(i), NULL );
}
ui_gadget_calc_keys(dlg);
@ -215,26 +211,3 @@ static int ui_messagebox_n( short xc, short yc, int NumButtons, const char * tex
return choice;
}
int ui_messagebox( short xc, short yc, int NumButtons, const char * text, ... )
{
va_list marker;
array<const char *, 10> Button;
short i;
if ((NumButtons < 1) || (NumButtons>10)) return -1;
va_start( marker, text );
for (i=0; i<NumButtons; i++ )
{
Button[i] = va_arg( marker, char * );
}
va_end( marker );
return ui_messagebox_n( xc, yc, NumButtons, text, Button );
}