1 /* $Id: message.c,v 1.4 2005-01-24 22:19:10 schaffner Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 static char rcsid[] = "$Id: message.c,v 1.4 2005-01-24 22:19:10 schaffner Exp $";
33 // w = width of each item
34 // n = number of items
35 // i = item number (0 based)
36 #define EVEN_DIVIDE(ts,w,n,i) ((((ts)-((w)*(n)))*((i)+1))/((n)+1))+((w)*(i))
38 #define BUTTON_HORZ_SPACING 20
39 #define TEXT_EXTRA_HEIGHT 5
41 int MessageBoxN( short xc, short yc, int NumButtons, char * text, char * Button[] )
45 UI_GADGET_BUTTON * ButtonG[10];
47 int i, width, height, avg, x, y;
48 int button_width, button_height, text_height, text_width;
53 if ((NumButtons < 1) || (NumButtons>10)) return -1;
55 button_width = button_height = 0;
57 gr_set_current_canvas( &grd_curscreen->sc_canvas );
58 w = grd_curscreen->sc_w;
59 h = grd_curscreen->sc_h;
60 temp_font = grd_curscreen->sc_canvas.cv_font;
63 grd_curscreen->sc_canvas.cv_font = ui_small_font;
66 for (i=0; i<NumButtons; i++ )
68 ui_get_button_size( Button[i], &width, &height );
70 if ( width > button_width ) button_width = width;
71 if ( height > button_height ) button_height = height;
74 gr_get_string_size(text, &text_width, &text_height, &avg );
76 width = button_width*NumButtons;
77 width += BUTTON_HORZ_SPACING*(NumButtons+1);
83 if (text_width > width )
87 height += button_height;
88 height += 4*TEXT_EXTRA_HEIGHT;
89 height += 2; // For line in middle
95 yc = Mouse.y - button_height/2;
110 if ( (x+width-1) >= w ) {
118 if ( (y+height-1) >= h ) {
122 wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
124 //ui_draw_line_in( MESSAGEBOX_BORDER, MESSAGEBOX_BORDER, width-MESSAGEBOX_BORDER, height-MESSAGEBOX_BORDER );
126 y = TEXT_EXTRA_HEIGHT + text_height/2 - 1;
128 ui_string_centered( width/2, y, text );
130 y = 2*TEXT_EXTRA_HEIGHT + text_height;
132 gr_setcolor( CGREY );
133 Hline(1, width-2, y+1 );
135 gr_setcolor( CBRIGHT );
136 Hline(2, width-2, y+2 );
138 y = height - TEXT_EXTRA_HEIGHT - button_height;
140 for (i=0; i<NumButtons; i++ )
143 x = EVEN_DIVIDE(width,button_width,NumButtons,i);
145 ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
148 ui_gadget_calc_keys(wnd);
152 wnd->keyboard_focus_gadget = (UI_GADGET *)ButtonG[0];
159 ui_window_do_gadgets(wnd);
161 for (i=0; i<NumButtons; i++ )
163 if (ButtonG[i]->pressed) {
171 ui_close_window(wnd);
173 grd_curscreen->sc_canvas.cv_font = temp_font;
180 int MessageBox( short xc, short yc, int NumButtons, char * text, ... )
187 if ((NumButtons < 1) || (NumButtons>10)) return -1;
189 va_start( marker, text );
190 for (i=0; i<NumButtons; i++ )
192 Button[i] = va_arg( marker, char * );
198 return MessageBoxN( xc, yc, NumButtons, text, Button );