]> icculus.org git repositories - btb/d2x.git/blob - ui/popup.c
avoid assignments between sbyte * and char *, ubyte * and char * to fix warnings...
[btb/d2x.git] / ui / popup.c
1 /* $Id: popup.c,v 1.6 2005-02-27 03:55:46 chris Exp $ */
2 /*
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.
13 */
14
15 #ifdef RCS
16 static char rcsid[] = "$Id: popup.c,v 1.6 2005-02-27 03:55:46 chris Exp $";
17 #endif
18
19 #ifdef HAVE_CONFIG_H
20 #include "conf.h"
21 #endif
22
23 #include "fix.h"
24 #include "pstypes.h"
25 #include "gr.h"
26 #include "ui.h"
27 #include "mouse.h"
28
29
30 #define MENU_BORDER 2
31 #define MENU_VERT_SPACING 2
32
33 extern void ui_mouse_flip_buttons();
34
35 int PopupMenu( int NumButtons, char * text[] )
36 {
37         UI_WINDOW * wnd;
38         UI_GADGET_BUTTON * ButtonG[10];
39
40         short SavedMouseX, SavedMouseY;
41         char * Button[10];
42
43         int button_width, button_height, width, height;
44
45         short i, x, y;
46         short w, h;
47
48         int choice;
49
50         ui_mouse_flip_buttons();
51
52         //ui_mouse_process();
53
54         if ( B1_RELEASED )
55         {
56                 ui_mouse_flip_buttons();
57                 return -1;
58         }
59
60         if ((NumButtons < 1) || (NumButtons>10))
61         {
62                 ui_mouse_flip_buttons();
63                 return -1;
64         }
65
66         SavedMouseX = Mouse.x; SavedMouseY = Mouse.y;
67
68         button_width = button_height = 0;
69
70         gr_set_current_canvas( &grd_curscreen->sc_canvas );
71
72         for (i=0; i<NumButtons; i++ )
73         {
74                 Button[i] = text[i];
75
76                 ui_get_button_size( Button[i], &width, &height );
77
78                 if ( width > button_width ) button_width = width;
79                 if ( height > button_height ) button_height = height;
80         }
81
82         width = button_width + 2*(MENU_BORDER+3);
83
84         height = (button_height*NumButtons) + (MENU_VERT_SPACING*(NumButtons-1)) ;
85         height += (MENU_BORDER+3) * 2;
86
87         x = Mouse.x - width/2;
88         y = Mouse.y - (MENU_BORDER+3) - button_height/2;
89
90         w = grd_curscreen->sc_w;
91         h = grd_curscreen->sc_h;
92
93         if (x < 0 ) {
94                 x = 0;
95                 Mouse.x = x + width / 2;
96         }
97
98         if ( (x+width-1) >= w ) {
99                 x = w - width;
100                 Mouse.x = x + width / 2;
101         }
102
103         if (y < 0 ) {
104                 y = 0;
105                 Mouse.y = y + (MENU_BORDER+3) + button_height/2;
106         }
107
108         if ( (y+height-1) >= h ) {
109                 y = h - height;
110                 Mouse.y = y + (MENU_BORDER+3) + button_height/2;
111         }
112
113         wnd = ui_open_window( x, y, width, height, WIN_DIALOG );
114
115         //mouse_set_pos(Mouse.x, Mouse.y);
116
117         x = MENU_BORDER+3;
118         y = MENU_BORDER+3;
119
120         for (i=0; i<NumButtons; i++ )
121         {
122                 ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
123                 y += button_height+MENU_VERT_SPACING;
124         }
125
126         choice = 0;
127
128         while(choice==0)
129         {
130                 ui_mega_process();
131                 ui_window_do_gadgets(wnd);
132
133                 for (i=0; i<NumButtons; i++ )
134                 {
135                         if (ButtonG[i]->pressed)   {
136                                 choice = i+1;
137                                 break;
138                         }
139                 }
140
141                 if ( (choice==0) && B1_JUST_RELEASED )  {
142                         choice = -1;
143                         break;
144                 }
145
146                 gr_update();
147         }
148
149         ui_close_window(wnd);
150
151         ui_mouse_flip_buttons();
152
153         return choice;
154
155 }
156