2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
30 // w = width of each item
31 // n = number of items
32 // i = item number (0 based)
33 #define EVEN_DIVIDE(ts,w,n,i) ((((ts)-((w)*(n)))*((i)+1))/((n)+1))+((w)*(i))
35 #define BUTTON_HORZ_SPACING 20
36 #define TEXT_EXTRA_HEIGHT 5
38 int MessageBoxN( short xc, short yc, int NumButtons, char * text, char * Button[] )
42 UI_GADGET_BUTTON * ButtonG[10];
44 int i, width, height, avg, x, y;
45 int button_width, button_height, text_height, text_width;
50 if ((NumButtons < 1) || (NumButtons>10)) return -1;
52 button_width = button_height = 0;
54 gr_set_current_canvas( &grd_curscreen->sc_canvas );
55 w = grd_curscreen->sc_w;
56 h = grd_curscreen->sc_h;
57 temp_font = grd_curscreen->sc_canvas.cv_font;
60 grd_curscreen->sc_canvas.cv_font = ui_small_font;
63 for (i=0; i<NumButtons; i++ )
65 ui_get_button_size( Button[i], &width, &height );
67 if ( width > button_width ) button_width = width;
68 if ( height > button_height ) button_height = height;
71 gr_get_string_size(text, &text_width, &text_height, &avg );
73 width = button_width*NumButtons;
74 width += BUTTON_HORZ_SPACING*(NumButtons+1);
80 if (text_width > width )
84 height += button_height;
85 height += 4*TEXT_EXTRA_HEIGHT;
86 height += 2; // For line in middle
92 yc = Mouse.y - button_height/2;
107 if ( (x+width-1) >= w ) {
115 if ( (y+height-1) >= h ) {
119 wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
121 //ui_draw_line_in( MESSAGEBOX_BORDER, MESSAGEBOX_BORDER, width-MESSAGEBOX_BORDER, height-MESSAGEBOX_BORDER );
123 y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
125 ui_string_centered( width/2, y, text );
127 y = 2*TEXT_EXTRA_HEIGHT + text_height;
129 gr_setcolor( CGREY );
130 Hline(1, width-2, y+1 );
132 gr_setcolor( CBRIGHT );
133 Hline(2, width-2, y+2 );
135 y = height - TEXT_EXTRA_HEIGHT - button_height;
137 for (i=0; i<NumButtons; i++ )
140 x = EVEN_DIVIDE(width,button_width,NumButtons,i);
142 ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
145 ui_gadget_calc_keys(wnd);
149 wnd->keyboard_focus_gadget = (UI_GADGET *)ButtonG[0];
156 ui_window_do_gadgets(wnd);
158 for (i=0; i<NumButtons; i++ )
160 if (ButtonG[i]->pressed) {
169 ui_close_window(wnd);
171 grd_curscreen->sc_canvas.cv_font = temp_font;
178 int ui_messagebox( short xc, short yc, int NumButtons, char * text, ... )
185 if ((NumButtons < 1) || (NumButtons>10)) return -1;
187 va_start( marker, text );
188 for (i=0; i<NumButtons; i++ )
190 Button[i] = va_arg( marker, char * );
196 return MessageBoxN( xc, yc, NumButtons, text, Button );