]> icculus.org git repositories - btb/d2x.git/blob - main/newmenu.h
add ui_checkbox_check
[btb/d2x.git] / main / newmenu.h
1 /* $Id: newmenu.h,v 1.8 2004-08-28 23:17:45 schaffner 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 /*
16  *
17  * Routines for menus.
18  *
19  */
20
21
22 #ifndef _NEWMENU_H
23 #define _NEWMENU_H
24
25 #define NM_TYPE_MENU        0   // A menu item... when enter is hit on this, newmenu_do returns this item number
26 #define NM_TYPE_INPUT       1   // An input box... fills the text field in, and you need to fill in text_len field.
27 #define NM_TYPE_CHECK       2   // A check box. Set and get its status by looking at flags field (1=on, 0=off)
28 #define NM_TYPE_RADIO       3   // Same as check box, but only 1 in a group can be set at a time. Set group fields.
29 #define NM_TYPE_TEXT        4   // A line of text that does nothing.
30 #define NM_TYPE_NUMBER      5   // A numeric entry counter.  Changes value from min_value to max_value;
31 #define NM_TYPE_INPUT_MENU  6   // A inputbox that you hit Enter to edit, when done, hit enter and menu leaves.
32 #define NM_TYPE_SLIDER      7   // A slider from min_value to max_value. Draws with text_len chars.
33
34 #define NM_MAX_TEXT_LEN     50
35
36 typedef struct newmenu_item {
37         int     type;           // What kind of item this is, see NM_TYPE_????? defines
38         int     value;          // For checkboxes and radio buttons, this is 1 if marked initially, else 0
39         int     min_value, max_value;   // For sliders and number bars.
40         int     group;          // What group this belongs to for radio buttons.
41         int     text_len;       // The maximum length of characters that can be entered by this inputboxes
42         char    *text;          // The text associated with this item.
43         // The rest of these are used internally by by the menu system, so don't set 'em!!
44         short   x, y;
45         short   w, h;
46         short   right_offset;
47         ubyte   redraw;
48         char    saved_text[NM_MAX_TEXT_LEN+1];
49 } newmenu_item;
50
51 // Pass an array of newmenu_items and it processes the menu. It will
52 // return a -1 if Esc is pressed, otherwise, it returns the index of
53 // the item that was current when Enter was was selected.
54 // The subfunction function gets called constantly, so you can dynamically
55 // change the text of an item.  Just pass NULL if you don't want this.
56 // Title draws big, Subtitle draw medium sized.  You can pass NULL for
57 // either/both of these if you don't want them.
58 extern int newmenu_do(char * title, char * subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem));
59
60 // Same as above, only you can pass through what item is initially selected.
61 extern int newmenu_do1(char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int citem);
62
63 // Same as above, only you can pass through what background bitmap to use.
64 extern int newmenu_do2(char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int citem, char *filename);
65
66 // Same as above, only you can pass through the width & height
67 extern int newmenu_do3(char *title, char *subtitle, int nitems, newmenu_item *item, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int citem, char *filename, int width, int height);
68
69
70 // Sample Code:
71 /*
72 {
73         int mmn;
74         newmenu_item mm[8];
75         char xtext[21];
76
77         strcpy( xtext, "John" );
78
79         mm[0].type=NM_TYPE_MENU; mm[0].text="Play game";
80         mm[1].type=NM_TYPE_INPUT; mm[1].text=xtext; mm[1].text_len=20;
81         mm[2].type=NM_TYPE_CHECK; mm[2].value=0; mm[2].text="check box";
82         mm[3].type=NM_TYPE_TEXT; mm[3].text="-pickone-";
83         mm[4].type=NM_TYPE_RADIO; mm[4].value=1; mm[4].group=0; mm[4].text="Radio #1";
84         mm[5].type=NM_TYPE_RADIO; mm[5].value=1; mm[5].group=0; mm[5].text="Radio #2";
85         mm[6].type=NM_TYPE_RADIO; mm[6].value=1; mm[6].group=0; mm[6].text="Radio #3";
86         mm[7].type=NM_TYPE_PERCENT; mm[7].value=50; mm[7].text="Volume";
87
88         mmn = newmenu_do("Descent", "Sample Menu", 8, mm, NULL );
89         mprintf( 0, "Menu returned: %d\n", mmn );
90 }
91
92 */
93
94 // This function pops up a messagebox and returns which choice was selected...
95 // Example:
96 // nm_messagebox( "Title", "Subtitle", 2, "Ok", "Cancel", "There are %d objects", nobjects );
97 // Returns 0 through nchoices-1.
98 int nm_messagebox(char *title, int nchoices, ...);
99 // Same as above, but you can pass a function
100 int nm_messagebox1(char *title, void (*subfunction)(int nitems, newmenu_item *items, int *last_key, int citem), int nchoices, ...);
101
102 void nm_draw_background(int x1, int y1, int x2, int y2);
103 void nm_restore_background(int x, int y, int w, int h);
104
105 // Returns 0 if no file selected, else filename is filled with selected file.
106 int newmenu_get_filename(char *title, char *filespec, char *filename, int allow_abort_flag);
107
108 // in menu.c
109 extern int Max_linear_depth_objects;
110
111 extern char *Newmenu_allowed_chars;
112
113 // Example listbox callback function...
114 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
115 // {
116 //      int i;
117 //
118 //      if ( *keypress = KEY_CTRLED+KEY_D )     {
119 //              if ( *nitems > 1 )      {
120 //                      unlink( items[*citem] );                // Delete the file
121 //                      for (i=*citem; i<*nitems-1; i++ )       {
122 //                              items[i] = items[i+1];
123 //                      }
124 //                      *nitems = *nitems - 1;
125 //                      free( items[*nitems] );
126 //                      items[*nitems] = NULL;
127 //                      return 1;       // redraw;
128 //              }
129 //                      *keypress = 0;
130 //      }
131 //      return 0;
132 // }
133
134 extern int newmenu_listbox(char *title, int nitems, char *items[], int allow_abort_flag, int (*listbox_callback)(int *citem, int *nitems, char *items[], int *keypress));
135 extern int newmenu_listbox1(char *title, int nitems, char *items[], int allow_abort_flag, int default_item, int (*listbox_callback)(int *citem, int *nitems, char *items[], int *keypress));
136
137 extern int newmenu_filelist(char *title, char *filespace, char *filename);
138
139 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
140 int nm_messagebox_fixedfont(char *title, int nchoices, ...);
141 //end this section addition
142
143 //should be called whenever the palette changes
144 extern void nm_remap_background(void);
145
146 #if defined(MACINTOSH) || defined(WINDOWS) || defined(SDL_INPUT)
147 # define NEWMENU_MOUSE
148 #endif
149
150 #ifdef NEWMENU_MOUSE
151 # if defined(MACINTOSH)
152 #  define newmenu_show_cursor() show_cursor()
153 #  define newmenu_hide_cursor() hide_cursor()
154 # elif defined(WINDOWS)
155 #  define newmenu_show_cursor() ShowCursorW()
156 #  define newmenu_hide_cursor() HideCursorW()
157 # elif defined(SDL_INPUT)
158 #  include <SDL.h>
159 #  define newmenu_show_cursor() SDL_ShowCursor(SDL_ENABLE)
160 #  define newmenu_hide_cursor() SDL_ShowCursor(SDL_DISABLE)
161 # else
162 #  define newmenu_show_cursor()
163 #  define newmenu_hide_cursor()
164 # endif
165 #endif
166
167 #endif /* _NEWMENU_H */