diff --git a/common/include/ui.h b/common/include/ui.h index b802d4fb9..44138b932 100644 --- a/common/include/ui.h +++ b/common/include/ui.h @@ -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); diff --git a/common/ui/message.cpp b/common/ui/message.cpp index 80da75a7c..9be455221 100644 --- a/common/ui/message.cpp +++ b/common/ui/message.cpp @@ -39,11 +39,10 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. typedef struct messagebox { - const array *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; inum_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 &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 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; ibutton_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 Button; - - short i; - - if ((NumButtons < 1) || (NumButtons>10)) return -1; - - va_start( marker, text ); - for (i=0; i