NEWMENU.H 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/main/rcs/newmenu.h $
  15. * $Revision: 2.0 $
  16. * $Author: john $
  17. * $Date: 1995/02/27 11:32:28 $
  18. *
  19. * Routines for menus.
  20. *
  21. * $Log: newmenu.h $
  22. * Revision 2.0 1995/02/27 11:32:28 john
  23. * New version 2.0, which has no anonymous unions, builds with
  24. * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  25. *
  26. * Revision 1.24 1995/02/11 16:20:05 john
  27. * Added code to make the default mission be the one last played.
  28. *
  29. * Revision 1.23 1995/01/31 10:21:41 john
  30. * Added code to specify width, height.
  31. *
  32. * Revision 1.22 1995/01/28 17:09:21 john
  33. * *** empty log message ***
  34. *
  35. * Revision 1.21 1995/01/23 18:38:43 john
  36. * Added listbox function.
  37. *
  38. * Revision 1.20 1994/11/26 15:29:55 matt
  39. * Allow escape out of change pilot menu
  40. *
  41. * Revision 1.19 1994/11/26 14:17:05 matt
  42. * Player can now only enter valid chars for his name
  43. *
  44. * Revision 1.18 1994/11/18 16:17:13 mike
  45. * prototype Max_linear_depth_objects.
  46. *
  47. * Revision 1.17 1994/11/08 14:51:17 john
  48. * Added nm_messagebox1, (like the original, only you can pass a function).
  49. *
  50. * Revision 1.16 1994/11/05 14:31:45 john
  51. * Added a new menu function for the background.
  52. *
  53. * Revision 1.15 1994/11/05 14:05:46 john
  54. * Fixed fade transitions between all screens by making gr_palette_fade_in and out keep
  55. * track of whether the palette is faded in or not. Then, wherever the code needs to fade out,
  56. * it just calls gr_palette_fade_out and it will fade out if it isn't already. The same with fade_in.
  57. * This eliminates the need for all the flags like Menu_fade_out, game_fade_in palette, etc.
  58. *
  59. * Revision 1.14 1994/11/03 19:37:35 john
  60. * Added scrolling file list box
  61. *
  62. * Revision 1.13 1994/10/13 11:34:03 john
  63. * Made Thrustmaster FCS Hat work. Put a background behind the
  64. * keyboard configure. Took out turn_sensitivity. Changed sound/config
  65. * menu to new menu. Made F6 be calibrate joystick.
  66. *
  67. * Revision 1.12 1994/10/11 17:08:32 john
  68. * Added sliders for volume controls.
  69. *
  70. * Revision 1.11 1994/10/04 10:26:23 matt
  71. * Changed fade in to happen every time a global var is set
  72. *
  73. * Revision 1.10 1994/10/03 14:43:56 john
  74. * Added newmenu_do1, which allows you to pass the starting
  75. * item to the menu system
  76. *
  77. * Revision 1.9 1994/09/30 11:51:33 john
  78. * Added Matt's NM_TYPE_INPUT_MENU
  79. *
  80. * Revision 1.8 1994/08/30 20:38:28 john
  81. * Passed citem in newmenu sub.
  82. *
  83. * Revision 1.7 1994/08/12 03:11:00 john
  84. * Made network be default off; Moved network options into
  85. * main menu. Made starting net game check that mines are the
  86. * same.
  87. *
  88. * Revision 1.6 1994/08/11 13:47:05 john
  89. * Made newmenu have subtitles, passed key through to
  90. * the newmenu subfunctions.
  91. *
  92. * Revision 1.5 1994/07/27 16:12:24 john
  93. * Changed newmenu system to have a callback function.
  94. * /.
  95. *
  96. * Revision 1.4 1994/07/24 17:41:38 john
  97. * *** empty log message ***
  98. *
  99. * Revision 1.3 1994/07/24 17:33:01 john
  100. * Added percent item. Also neatend up a bit.
  101. *
  102. * Revision 1.2 1994/07/22 17:48:12 john
  103. * Added new menuing system.
  104. *
  105. * Revision 1.1 1994/07/22 13:55:51 john
  106. * Initial revision
  107. *
  108. *
  109. */
  110. #ifndef _NEWMENU_H
  111. #define _NEWMENU_H
  112. #define NM_TYPE_MENU 0 // A menu item... when enter is hit on this, newmenu_do returns this item number
  113. #define NM_TYPE_INPUT 1 // An input box... fills the text field in, and you need to fill in text_len field.
  114. #define NM_TYPE_CHECK 2 // A check box. Set and get its status by looking at flags field (1=on, 0=off)
  115. #define NM_TYPE_RADIO 3 // Same as check box, but only 1 in a group can be set at a time. Set group fields.
  116. #define NM_TYPE_TEXT 4 // A line of text that does nothing.
  117. #define NM_TYPE_NUMBER 5 // A numeric entry counter. Changes value from min_value to max_value;
  118. #define NM_TYPE_INPUT_MENU 6 // A inputbox that you hit Enter to edit, when done, hit enter and menu leaves.
  119. #define NM_TYPE_SLIDER 7 // A slider from min_value to max_value. Draws with text_len chars.
  120. #define NM_MAX_TEXT_LEN 50
  121. typedef struct newmenu_item {
  122. int type; // What kind of item this is, see NM_TYPE_????? defines
  123. int value; // For checkboxes and radio buttons, this is 1 if marked initially, else 0
  124. int min_value, max_value; // For sliders and number bars.
  125. int group; // What group this belongs to for radio buttons.
  126. int text_len; // The maximum length of characters that can be entered by this inputboxes
  127. char *text; // The text associated with this item.
  128. // The rest of these are used internally by by the menu system, so don't set 'em!!
  129. short x, y;
  130. short w, h;
  131. short right_offset;
  132. ubyte redraw;
  133. char saved_text[NM_MAX_TEXT_LEN+1];
  134. } newmenu_item;
  135. // Pass an array of newmenu_items and it processes the menu. It will
  136. // return a -1 if Esc is pressed, otherwise, it returns the index of
  137. // the item that was current when Enter was was selected.
  138. // The subfunction function gets called constantly, so you can dynamically
  139. // change the text of an item. Just pass NULL if you don't want this.
  140. // Title draws big, Subtitle draw medium sized. You can pass NULL for
  141. // either/both of these if you don't want them.
  142. 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 ) );
  143. // Same as above, only you can pass through what item is initially selected.
  144. 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 );
  145. // Same as above, only you can pass through what background bitmap to use.
  146. 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 );
  147. // Same as above, only you can pass through the width & height
  148. 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 );
  149. // Sample Code:
  150. /*
  151. {
  152. int mmn;
  153. newmenu_item mm[8];
  154. char xtext[21];
  155. strcpy( xtext, "John" );
  156. mm[0].type=NM_TYPE_MENU; mm[0].text="Play game";
  157. mm[1].type=NM_TYPE_INPUT; mm[1].text=xtext; mm[1].text_len=20;
  158. mm[2].type=NM_TYPE_CHECK; mm[2].value=0; mm[2].text="check box";
  159. mm[3].type=NM_TYPE_TEXT; mm[3].text="-pickone-";
  160. mm[4].type=NM_TYPE_RADIO; mm[4].value=1; mm[4].group=0; mm[4].text="Radio #1";
  161. mm[5].type=NM_TYPE_RADIO; mm[5].value=1; mm[5].group=0; mm[5].text="Radio #2";
  162. mm[6].type=NM_TYPE_RADIO; mm[6].value=1; mm[6].group=0; mm[6].text="Radio #3";
  163. mm[7].type=NM_TYPE_PERCENT; mm[7].value=50; mm[7].text="Volume";
  164. mmn = newmenu_do("Descent", "Sample Menu", 8, mm, NULL );
  165. mprintf( 0, "Menu returned: %d\n", mmn );
  166. }
  167. */
  168. // This function pops up a messagebox and returns which choice was selected...
  169. // Example:
  170. // nm_messagebox( "Title", "Subtitle", 2, "Ok", "Cancel", "There are %d objects", nobjects );
  171. // Returns 0 through nchoices-1.
  172. int nm_messagebox( char *title, int nchoices, ... );
  173. // Same as above, but you can pass a function
  174. int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... );
  175. void nm_draw_background(int x1, int y1, int x2, int y2);
  176. void nm_restore_background( int x, int y, int w, int h );
  177. // Returns 0 if no file selected, else filename is filled with selected file.
  178. int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag );
  179. // in menu.c
  180. extern int Max_linear_depth_objects;
  181. extern char *Newmenu_allowed_chars;
  182. // Example listbox callback function...
  183. // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
  184. // {
  185. // int i;
  186. //
  187. // if ( *keypress = KEY_CTRLED+KEY_D ) {
  188. // if ( *nitems > 1 ) {
  189. // unlink( items[*citem] ); // Delete the file
  190. // for (i=*citem; i<*nitems-1; i++ ) {
  191. // items[i] = items[i+1];
  192. // }
  193. // *nitems = *nitems - 1;
  194. // free( items[*nitems] );
  195. // items[*nitems] = NULL;
  196. // return 1; // redraw;
  197. // }
  198. // *keypress = 0;
  199. // }
  200. // return 0;
  201. // }
  202. 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 ) );
  203. 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 ) );
  204. extern int newmenu_filelist( char * title, char * filespace, char * filename );
  205. #endif
  206.