1 /* $Id: popup.c,v 1.3 2004-12-19 15:21:11 btb 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: popup.c,v 1.3 2004-12-19 15:21:11 btb Exp $";
31 #define MENU_VERT_SPACING 2
33 extern void ui_mouse_flip_buttons();
35 int PopupMenu( int NumButtons, char * text[] )
38 UI_GADGET_BUTTON * ButtonG[10];
40 short SavedMouseX, SavedMouseY;
43 int button_width, button_height, width, height;
50 ui_mouse_flip_buttons();
56 ui_mouse_flip_buttons();
60 if ((NumButtons < 1) || (NumButtons>10))
62 ui_mouse_flip_buttons();
66 SavedMouseX = Mouse.x; SavedMouseY = Mouse.y;
68 button_width = button_height = 0;
70 gr_set_current_canvas( &grd_curscreen->sc_canvas );
72 for (i=0; i<NumButtons; i++ )
76 ui_get_button_size( Button[i], &width, &height );
78 if ( width > button_width ) button_width = width;
79 if ( height > button_height ) button_height = height;
82 width = button_width + 2*(MENU_BORDER+3);
84 height = (button_height*NumButtons) + (MENU_VERT_SPACING*(NumButtons-1)) ;
85 height += (MENU_BORDER+3) * 2;
87 x = Mouse.x - width/2;
88 y = Mouse.y - (MENU_BORDER+3) - button_height/2;
90 w = grd_curscreen->sc_w;
91 h = grd_curscreen->sc_h;
95 Mouse.x = x + width / 2;
98 if ( (x+width-1) >= w ) {
100 Mouse.x = x + width / 2;
105 Mouse.y = y + (MENU_BORDER+3) + button_height/2;
108 if ( (y+height-1) >= h ) {
110 Mouse.y = y + (MENU_BORDER+3) + button_height/2;
113 wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
115 mouse_set_pos( Mouse.x, Mouse.y );
120 for (i=0; i<NumButtons; i++ )
122 ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
123 y += button_height+MENU_VERT_SPACING;
131 ui_window_do_gadgets(wnd);
133 for (i=0; i<NumButtons; i++ )
135 if (ButtonG[i]->pressed) {
141 if ( (choice==0) && B1_JUST_RELEASED ) {
148 ui_close_window(wnd);
150 ui_mouse_flip_buttons();