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