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