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.
28 // w = width of each item
29 // n = number of items
30 // i = item number (0 based)
31 #define EVEN_DIVIDE(ts,w,n,i) ((((ts)-((w)*(n)))*((i)+1))/((n)+1))+((w)*(i))
33 #define BUTTON_HORZ_SPACING 20
34 #define TEXT_EXTRA_HEIGHT 5
36 int MessageBoxN( short xc, short yc, int NumButtons, char * text, char * Button[] )
40 UI_GADGET_BUTTON * ButtonG[10];
42 int i, width, height, avg, x, y;
43 int button_width, button_height, text_height, text_width;
48 if ((NumButtons < 1) || (NumButtons>10)) return -1;
50 button_width = button_height = 0;
52 gr_set_current_canvas( &grd_curscreen->sc_canvas );
53 w = grd_curscreen->sc_w;
54 h = grd_curscreen->sc_h;
55 temp_font = grd_curscreen->sc_canvas.cv_font;
58 grd_curscreen->sc_canvas.cv_font = ui_small_font;
61 for (i=0; i<NumButtons; i++ )
63 ui_get_button_size( Button[i], &width, &height );
65 if ( width > button_width ) button_width = width;
66 if ( height > button_height ) button_height = height;
69 gr_get_string_size(text, &text_width, &text_height, &avg );
71 width = button_width*NumButtons;
72 width += BUTTON_HORZ_SPACING*(NumButtons+1);
78 if (text_width > width )
82 height += button_height;
83 height += 4*TEXT_EXTRA_HEIGHT;
84 height += 2; // For line in middle
90 yc = Mouse.y - button_height/2;
105 if ( (x+width-1) >= w ) {
113 if ( (y+height-1) >= h ) {
117 wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
119 //ui_draw_line_in( MESSAGEBOX_BORDER, MESSAGEBOX_BORDER, width-MESSAGEBOX_BORDER, height-MESSAGEBOX_BORDER );
121 y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
123 ui_string_centered( width/2, y, text );
125 y = 2*TEXT_EXTRA_HEIGHT + text_height;
127 gr_setcolor( CGREY );
128 Hline(1, width-2, y+1 );
130 gr_setcolor( CBRIGHT );
131 Hline(2, width-2, y+2 );
133 y = height - TEXT_EXTRA_HEIGHT - button_height;
135 for (i=0; i<NumButtons; i++ )
138 x = EVEN_DIVIDE(width,button_width,NumButtons,i);
140 ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
143 ui_gadget_calc_keys(wnd);
147 wnd->keyboard_focus_gadget = (UI_GADGET *)ButtonG[0];
154 ui_window_do_gadgets(wnd);
156 for (i=0; i<NumButtons; i++ )
158 if (ButtonG[i]->pressed) {
167 ui_close_window(wnd);
169 grd_curscreen->sc_canvas.cv_font = temp_font;
176 int MessageBox( short xc, short yc, int NumButtons, char * text, ... )
183 if ((NumButtons < 1) || (NumButtons>10)) return -1;
185 va_start( marker, text );
186 for (i=0; i<NumButtons; i++ )
188 Button[i] = va_arg( marker, char * );
194 return MessageBoxN( xc, yc, NumButtons, text, Button );