]> icculus.org git repositories - btb/d2x.git/blob - ui/menu.c
remove rcs tags
[btb/d2x.git] / ui / menu.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 <stdlib.h>
19
20 #include "u_mem.h"
21 #include "fix.h"
22 #include "pstypes.h"
23 #include "gr.h"
24 #include "ui.h"
25
26
27 #define MENU_BORDER 2
28 #define MENU_VERT_SPACING 2
29
30 int MenuX( int x, int y, int NumButtons, char * text[] )
31 {
32         UI_WINDOW * wnd;
33         UI_GADGET_BUTTON ** ButtonG;
34         char ** Button;
35
36         int button_width, button_height, width, height;
37
38         int i;
39         int w, h;
40
41         int choice;
42
43         ButtonG = (UI_GADGET_BUTTON **) d_malloc(sizeof(UI_GADGET_BUTTON *)*NumButtons);
44         Button = (char **) d_malloc(sizeof(char *)*NumButtons);
45
46         button_width = button_height = 0;
47
48         for (i=0; i<NumButtons; i++ )
49         {
50                 Button[i] = text[i];
51
52                 ui_get_button_size( Button[i], &width, &height );
53
54                 if ( width > button_width ) button_width = width;
55                 if ( height > button_height ) button_height = height;
56         }
57
58         width = button_width + 2*(MENU_BORDER+3);
59
60         height = (button_height*NumButtons) + (MENU_VERT_SPACING*(NumButtons-1)) ;
61         height += (MENU_BORDER+3) * 2;
62
63         w = grd_curscreen->sc_w;
64         h = grd_curscreen->sc_h;
65
66         if ( x == -1 ) x = Mouse.x - width/2;
67         if ( y == -1 ) y = Mouse.y;
68
69         if (x < 0 ) {
70                 x = 0;
71         }
72
73         if ( (x+width-1) >= w ) {
74                 x = w - width;
75         }
76
77         if (y < 0 ) {
78                 y = 0;
79         }
80
81         if ( (y+height-1) >= h ) {
82                 y = h - height;
83         }
84
85         wnd = ui_open_window( x, y, width, height, WIN_FILLED | WIN_SAVE_BG );
86
87         x = MENU_BORDER+3;
88         y = MENU_BORDER+3;
89
90         for (i=0; i<NumButtons; i++ )
91         {
92                 ButtonG[i] = ui_add_gadget_button( wnd, x, y, button_width, button_height, Button[i], NULL );
93                 y += button_height+MENU_VERT_SPACING;
94         }
95
96         choice = 0;
97
98         while(choice==0)
99         {
100                 ui_mega_process();
101                 ui_window_do_gadgets(wnd);
102
103                 for (i=0; i<NumButtons; i++ )
104                 {
105                         if (ButtonG[i]->pressed)   {
106                                 choice = i+1;
107                                 break;
108                         }
109                 }
110
111                 if ( (choice==0) && B1_JUST_RELEASED )  {
112                         choice = -1;
113                         break;
114                 }
115
116                 gr_update();
117         }
118
119         ui_close_window(wnd);
120         d_free(Button);
121         d_free(ButtonG);
122
123         return choice;
124
125 }
126