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.
14 #pragma off (unreferenced)
15 static char rcsid[] = "$Id: message.c,v 1.1.1.1 2001-01-19 03:30:14 bradleyb Exp $";
16 #pragma on (unreferenced)
27 // w = width of each item
28 // n = number of items
29 // i = item number (0 based)
30 #define EVEN_DIVIDE(ts,w,n,i) ((((ts)-((w)*(n)))*((i)+1))/((n)+1))+((w)*(i))
32 #define BUTTON_HORZ_SPACING 20
33 #define TEXT_EXTRA_HEIGHT 5
35 int MessageBoxN( short xc, short yc, int NumButtons, char * text, char * Button[] )
39 UI_GADGET_BUTTON * ButtonG[10];
41 int i, width, height, avg, x, y;
42 int button_width, button_height, text_height, text_width;
47 if ((NumButtons < 1) || (NumButtons>10)) return -1;
49 button_width = button_height = 0;
51 gr_set_current_canvas( &grd_curscreen->sc_canvas );
52 w = grd_curscreen->sc_w;
53 h = grd_curscreen->sc_h;
54 temp_font = grd_curscreen->sc_canvas.cv_font;
57 grd_curscreen->sc_canvas.cv_font = ui_small_font;
60 for (i=0; i<NumButtons; i++ )
62 ui_get_button_size( Button[i], &width, &height );
64 if ( width > button_width ) button_width = width;
65 if ( height > button_height ) button_height = height;
68 gr_get_string_size(text, &text_width, &text_height, &avg );
70 width = button_width*NumButtons;
71 width += BUTTON_HORZ_SPACING*(NumButtons+1);
77 if (text_width > width )
81 height += button_height;
82 height += 4*TEXT_EXTRA_HEIGHT;
83 height += 2; // For line in middle
89 yc = Mouse.y - button_height/2;
104 if ( (x+width-1) >= w ) {
112 if ( (y+height-1) >= h ) {
116 wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
118 //ui_draw_line_in( MESSAGEBOX_BORDER, MESSAGEBOX_BORDER, width-MESSAGEBOX_BORDER, height-MESSAGEBOX_BORDER );
120 y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
122 ui_string_centered( width/2, y, text );
124 y = 2*TEXT_EXTRA_HEIGHT + text_height;
126 gr_setcolor( CGREY );
127 Hline(1, width-2, y+1 );
129 gr_setcolor( CBRIGHT );
130 Hline(2, width-2, y+2 );
132 y = height - TEXT_EXTRA_HEIGHT - button_height;
134 for (i=0; i<NumButtons; i++ )
137 x = EVEN_DIVIDE(width,button_width,NumButtons,i);
139 ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
142 ui_gadget_calc_keys(wnd);
146 wnd->keyboard_focus_gadget = (UI_GADGET *)ButtonG[0];
153 ui_window_do_gadgets(wnd);
155 for (i=0; i<NumButtons; i++ )
157 if (ButtonG[i]->pressed) {
165 ui_close_window(wnd);
167 grd_curscreen->sc_canvas.cv_font = temp_font;
174 int MessageBox( short xc, short yc, int NumButtons, char * text, ... )
181 if ((NumButtons < 1) || (NumButtons>10)) return -1;
183 va_start( marker, text );
184 for (i=0; i<NumButtons; i++ )
186 Button[i] = va_arg( marker, char * );
192 return MessageBoxN( xc, yc, NumButtons, text, Button );