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