1 /* $Id: newmenu.c,v 1.22 2003-11-18 00:29:53 btb Exp $ */
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.
20 * Revision 1.26 1996/04/14 21:07:35 allender
21 * some change for update
23 * Revision 1.25 1995/10/31 10:19:25 allender
26 * Revision 1.24 1995/10/27 11:09:04 allender
27 * always cd to descent dir before any menu processing --
28 * sanity check because of way mac does volume mounting and
31 * Revision 1.23 1995/10/24 18:11:19 allender
32 * do_appl_quit saves and restores background -- don't
33 * do any special processing. fixed newmenu_do3 to pass width
34 * and height to ...do_4
36 * Revision 1.22 1995/10/21 23:26:25 allender
37 * can't do cmd-q in multiplayer games
39 * Revision 1.21 1995/10/21 22:53:25 allender
40 * menus need to be 8 byte multiple wide -- printscreen stuff
42 * Revision 1.20 1995/10/20 00:50:15 allender
43 * redbook stuff and make esc leave menu always
45 * Revision 1.19 1995/10/17 13:14:52 allender
46 * mouse support for other menus now operational -- dragging
47 * mouse will also move sliders
49 * Revision 1.18 1995/10/12 17:35:19 allender
50 * mouse support for pilot and demos
52 * Revision 1.17 1995/10/11 12:17:47 allender
53 * removed event loop processing
55 * Revision 1.16 1995/10/10 11:51:29 allender
56 * align menus to 8 byte boundry
58 * Revision 1.15 1995/10/05 14:09:36 allender
59 * lowered starting x location on menus to fixup network
60 * status screen chopping off characters
62 * Revision 1.14 1995/09/24 10:52:27 allender
63 * made close boxes work
64 * maybe some other minor stuff?
66 * Revision 1.13 1995/09/15 09:02:04 allender
67 * started putting mouse support in listboxes
69 * Revision 1.12 1995/09/13 08:50:14 allender
70 * close box in this rev? Worked on getting list box better
73 * Revision 1.11 1995/09/01 10:52:37 allender
76 * Revision 1.10 1995/08/24 16:23:08 allender
77 * mouse support for most menus
79 * Revision 1.9 1995/08/08 13:46:56 allender
80 * added macsys header file
82 * Revision 1.8 1995/08/01 16:03:54 allender
83 * added file list with Desalvo's directory stuff
85 * Revision 1.7 1995/07/26 17:03:37 allender
86 * show then hide cursor during newmenu operations -- not quite
89 * Revision 1.6 1995/07/17 08:56:26 allender
90 * fixed up menus to look better with new high res fonts
92 * Revision 1.5 1995/07/12 10:35:52 allender
93 * removed old debug thing
95 * Revision 1.4 1995/06/23 10:23:21 allender
96 * menus should work in any resolution now
98 * Revision 1.3 1995/06/20 09:11:19 allender
99 * changed menu system to support 640x480 instead of 320x200
101 * Revision 1.2 1995/06/13 13:07:30 allender
102 * added special key to move 320x200 window to upper left corner of screen
104 * Revision 1.1 1995/05/16 15:29:13 allender
107 * Revision 2.8 1995/05/26 16:16:28 john
108 * Split SATURN into define's for requiring cd, using cd, etc.
109 * Also started adding all the Rockwell stuff.
111 * Revision 2.7 1995/04/23 14:54:17 john
112 * Fixed bug with background breaking in first menu.
114 * Revision 2.6 1995/03/21 14:38:46 john
115 * Ifdef'd out the NETWORK code.
117 * Revision 2.5 1995/03/15 14:33:29 john
118 * Added code to force the Descent CD-rom in the drive.
120 * Revision 2.4 1995/03/14 18:24:28 john
121 * Force Destination Saturn to use CD-ROM drive.
123 * Revision 2.3 1995/03/14 16:22:23 john
124 * Added cdrom alternate directory stuff.
126 * Revision 2.2 1995/03/06 18:30:51 john
127 * Fixed bug with newmenu trashing editor font.
129 * Revision 2.1 1995/03/06 15:23:17 john
130 * New screen techniques.
132 * Revision 2.0 1995/02/27 11:27:55 john
133 * New version 2.0, which has no anonymous unions, builds with
134 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
136 * Revision 1.129 1995/02/11 16:19:56 john
137 * Added code to make the default mission be the one last played.
139 * Revision 1.128 1995/02/02 19:41:33 john
140 * Added 10 save game slots.
142 * Revision 1.127 1995/02/01 18:13:52 john
143 * Fixed some constants.
145 * Revision 1.126 1995/02/01 18:04:01 yuan
146 * Added 50 characters to list.
148 * Revision 1.125 1995/02/01 13:39:35 john
149 * Made menu text that changes not overwrite.
151 * Revision 1.124 1995/01/31 10:47:57 john
152 * Added menu that you can specify the width of the menu.
154 * Revision 1.123 1995/01/28 17:18:12 john
155 * Added file list box.
157 * Revision 1.122 1995/01/27 17:15:55 john
158 * Made prev comment actually work.
160 * Revision 1.121 1995/01/27 16:49:03 john
161 * *** empty log message ***
163 * Revision 1.120 1995/01/27 16:46:40 john
164 * Made so that input_menu only clears text if -empty-.
166 * Revision 1.119 1995/01/27 15:25:04 john
167 * Delete saved game when deleteing a pilot file.
169 * Revision 1.118 1995/01/25 16:36:09 john
170 * Made so that when you hit enter during
171 * game save, -empty- goes away.
173 * Revision 1.117 1995/01/24 16:59:30 john
174 * took out mono debugging text.
176 * Revision 1.116 1995/01/24 16:23:16 john
177 * Fixed some bugs with listboxes.
179 * Revision 1.115 1995/01/23 23:47:36 matt
180 * Made keypad enter work in menus
182 * Revision 1.114 1995/01/23 19:29:59 john
183 * Added scrolling listbox menus.
185 * Revision 1.113 1995/01/19 12:33:34 john
186 * Made keys jump to sliders, etc in menus.
188 * Revision 1.112 1995/01/15 14:33:08 rob
189 * Fixed problem with nested nm_messageboxes.
191 * Revision 1.111 1995/01/03 17:33:40 john
192 * Made scrolling textbox. Used it for scores cool saying.
194 * Revision 1.110 1994/12/28 10:42:58 john
197 * Revision 1.109 1994/12/28 10:26:39 john
198 * Fixed some VFX problems.
200 * Revision 1.108 1994/12/15 23:18:10 john
201 * Added fix so that VFX mode doesn't hang.
203 * Revision 1.107 1994/12/15 12:19:55 john
204 * Made menu use clipped bitblt functions.
206 * Revision 1.106 1994/12/09 00:41:30 mike
207 * fix hang in automap print screen
209 * Revision 1.105 1994/12/08 10:01:34 john
210 * Changed the way the player callsign stuff works.
212 * Revision 1.104 1994/12/04 15:34:30 john
213 * Fixed bug with newmenu not restoring font properly.
215 * Revision 1.103 1994/12/03 17:47:09 john
216 * Fixed bug that didn't free filename mem when not .plr files found.
218 * Revision 1.102 1994/12/03 15:06:15 john
219 * If no pilot exists, bring up box asking for name.
221 * Revision 1.101 1994/12/03 11:04:02 john
222 * Changed newmenu code a bit to fix bug with bogus
223 * backgrounds occcasionally.
225 * Revision 1.100 1994/12/01 20:15:48 yuan
228 * Revision 1.99 1994/12/01 10:33:28 john
229 * Fixed bug with large menu backgrounds not drawing correctly.
231 * Revision 1.98 1994/12/01 02:41:56 john
234 * Revision 1.97 1994/11/30 22:52:43 john
235 * Fixed bug in code that made the backgrounds behind menus.
237 * Revision 1.96 1994/11/30 19:47:42 john
238 * Added a check for out o' memory when mallocing background.
240 * Revision 1.95 1994/11/30 19:39:10 john
243 * Revision 1.94 1994/11/30 19:38:27 john
244 * fixed bug with previous.
246 * Revision 1.93 1994/11/30 19:36:47 john
247 * Made Gravis Ultrasound work again. Made the scores blink
248 * at a constant rate. Revamped the newmenu background storage,
249 * which hopefully fixed some bugs. Made menus in ame not pause
250 * sound, except for the pause key. ^== Game!
252 * Revision 1.92 1994/11/30 18:06:05 matt
253 * When player types space in callsign, comes up as underscore
255 * Revision 1.91 1994/11/30 12:28:22 adam
258 * Revision 1.90 1994/11/30 12:10:59 adam
259 * added support for PCX titles/brief screens
261 * Revision 1.89 1994/11/29 00:59:12 allender
262 * change newmenu_get_filename so demo files can be deleted too
264 * Revision 1.88 1994/11/27 21:16:18 allender
265 * made some return values in newmenu_get_filename 0 instead of -1
267 * Revision 1.87 1994/11/27 16:58:17 matt
268 * Made printscreen work all the time (not just when no ndebug) and made it
269 * work when getting a filename.
271 * Revision 1.86 1994/11/27 16:47:51 john
272 * Made the call to fade in palette only happen if it needs to be, just
273 * because I thought it might reduce code paging with vm in menus.
275 * Revision 1.85 1994/11/26 15:30:16 matt
276 * Allow escape out of change pilot menu
278 * Revision 1.84 1994/11/26 14:17:26 matt
279 * Player can now only enter valid chars for his name
281 * Revision 1.83 1994/11/23 14:13:17 allender
282 * if no demo files, displays less "techy" message
284 * Revision 1.82 1994/11/21 11:55:52 john
285 * Fixed some sound pausing in menus bugs.
287 * Revision 1.81 1994/11/19 15:14:58 mike
288 * remove unused code and data
290 * Revision 1.80 1994/11/18 23:37:54 john
291 * Changed some shorts to ints.
293 * Revision 1.79 1994/11/15 09:29:21 john
294 * Made it so that pressing a letter when selecting players moves to
297 * Revision 1.78 1994/11/14 17:12:28 adam
298 * *** empty log message ***
300 * Revision 1.77 1994/11/14 16:58:31 rob
301 * Tried to fix a problem with save demo dialog.
303 * Revision 1.76 1994/11/14 16:13:46 matt
304 * Fixed handling of players with DOS device names
306 * Revision 1.75 1994/11/13 18:12:53 matt
307 * Fixed handling of filenames that are the same as DOS devices
309 * Revision 1.74 1994/11/13 17:20:44 john
312 * Revision 1.73 1994/11/13 17:18:22 john
313 * Changed wording of new pilot.
315 * Revision 1.72 1994/11/13 17:14:21 john
316 * Fixed bug with player list box.
318 * Revision 1.71 1994/11/13 17:12:48 john
319 * Fixed broken demo file list.
321 * Revision 1.70 1994/11/13 17:04:49 john
322 * Made the callsign entry be a list box and gave the ability
325 * Revision 1.69 1994/11/13 15:38:03 john
326 * Added critical error handler to game. Took out -editor command line
327 * option because it didn't work anymore and wasn't worth fixing. Made scores
328 * not use MINER enviroment variable on release version, and made scores
329 * not print an error if there is no descent.hi.
331 * Revision 1.68 1994/11/11 18:17:03 rob
332 * Made multi_menu_poll return a value to exit menus.
334 * Revision 1.67 1994/11/11 11:07:06 rob
335 * Added include of multi.h
337 * Revision 1.66 1994/11/10 20:25:16 rob
338 * John's stuff to make network menus work.
340 * Revision 1.65 1994/11/08 14:51:39 john
341 * Added nm_messagebox1, (like the original, only you can pass a function).
343 * Revision 1.64 1994/11/08 08:30:39 john
344 * Fixed bug with centering titles.
346 * Revision 1.63 1994/11/08 08:27:00 john
347 * Made titles and subtitles center.
349 * Revision 1.62 1994/11/07 09:40:48 john
350 * Neatend file list box some.
352 * Revision 1.61 1994/11/05 17:22:41 john
353 * Fixed lots of sequencing problems with newdemo stuff.
355 * Revision 1.60 1994/11/05 15:04:08 john
356 * Added non-popup menu for the main menu, so that scores and credits don't have to save
359 * Revision 1.59 1994/11/05 14:03:52 john
360 * Fixed fade transitions between all screens by making gr_palette_fade_in and out keep
361 * track of whether the palette is faded in or not. Then, wherever the code needs to fade out,
362 * it just calls gr_palette_fade_out and it will fade out if it isn't already. The same with fade_in.
363 * This eliminates the need for all the flags like Menu_fade_out, game_fade_in palette, etc.
365 * Revision 1.58 1994/11/04 20:11:50 john
366 * Neatening up palette stuff with demos.
368 * Revision 1.57 1994/11/04 13:49:24 allender
369 * fixed newmenu_get_filename to work with less than 10 files
371 * Revision 1.56 1994/11/03 19:37:44 john
372 * Added scrolling file list box
374 * Revision 1.55 1994/10/31 18:16:42 john
375 * Made Pad arrows work with menus.
377 * Revision 1.54 1994/10/28 14:54:25 john
378 * Added forward dec. for newmenu_close.
381 * Revision 1.53 1994/10/28 14:53:00 john
382 * Fixed hideous bug that would bomb if you called newmenu_draw_background
383 * before any menus were ever displayed.
385 * Revision 1.52 1994/10/24 19:56:53 john
386 * Made the new user setup prompt for config options.
388 * Revision 1.51 1994/10/24 15:15:49 john
389 * Made Esc exit nm_messagebox's,
392 * Revision 1.50 1994/10/21 15:20:20 john
393 * Made PrtScr do screen dump, not F2.
395 * Revision 1.49 1994/10/18 12:33:38 john
396 * Only used copy the item text into the saved_text field
397 * if it is an inputbox or inputbox_menu.
399 * Revision 1.48 1994/10/17 11:04:01 john
400 * Made backtab work also.
402 * Revision 1.47 1994/10/17 10:47:49 john
403 * MAde Tab work like down arrow.
405 * Revision 1.46 1994/10/17 10:45:10 john
406 * Made the player able to abort death by pressing any button or key.
408 * Revision 1.45 1994/10/13 21:52:02 john
409 * Made it so that if a messagebox has 1 choice, then
410 * Esc will return -1.
412 * Revision 1.44 1994/10/13 11:35:38 john
413 * Made Thrustmaster FCS Hat work. Put a background behind the
414 * keyboard configure. Took out turn_sensitivity. Changed sound/config
415 * menu to new menu. Made F6 be calibrate joystick.
417 * Revision 1.43 1994/10/11 17:18:52 john
418 * Fixed bug with sliders always starting at -1.
420 * Revision 1.42 1994/10/11 17:08:29 john
421 * Added sliders for volume controls.
423 * Revision 1.41 1994/10/06 16:04:40 john
424 * Made text items color differently than others. Adam
425 * is gonna make a diff colored font for these.
427 * Revision 1.40 1994/10/06 15:08:23 rob
428 * Allowed any negative key value to abort the menu and return.
430 * Revision 1.39 1994/10/04 10:26:06 matt
431 * Changed fade in to happen every time a global var is set
433 * Revision 1.38 1994/10/04 09:16:08 john
434 * If you pass -1 as choice in newmenu_do1, then
435 * no item is highlighted until you press up or
438 * Revision 1.37 1994/10/03 23:44:37 matt
439 * Save & restore palette effect around menus & pause message
441 * Revision 1.36 1994/10/03 22:59:40 matt
442 * Re-enabled backspace to generate Int3()
444 * Revision 1.35 1994/10/03 19:11:21 matt
445 * Changed string input cursor to blinking underscore
447 * Revision 1.34 1994/10/03 14:44:15 john
448 * Added newmenu_do1, which allows you to pass the starting
449 * item to the menu system
451 * Revision 1.33 1994/09/30 11:51:21 john
452 * Added Matt's NM_TYPE_INPUT_MENU
454 * Revision 1.32 1994/09/28 17:22:56 matt
455 * Added extra space between subtitle and menu items
456 * Made shortcut key check ignore leading spaces in text
458 * Revision 1.31 1994/09/15 16:11:22 john
459 * Added support for VFX1 head tracking. Fixed bug with memory over-
460 * write when using stereo mode.
462 * Revision 1.30 1994/09/12 09:52:59 john
463 * Made global flush function that flushes keyboard,mouse, and joystick.
465 * Revision 1.29 1994/09/10 19:10:54 matt
466 * Fixed a few things (like arrow key handling) for menus with all
467 * text items, such as the key help message.
469 * Revision 1.28 1994/09/01 18:55:38 john
472 * Revision 1.27 1994/09/01 18:03:50 john
473 * Neatened up scores a bit.
475 * Revision 1.26 1994/08/30 20:38:13 john
476 * Passed citem in newmenu sub.
478 * Revision 1.25 1994/08/30 11:13:01 john
479 * Added beveled edges to menus.
481 * Revision 1.24 1994/08/26 13:01:58 john
482 * Put high score system in.
484 * Revision 1.23 1994/08/16 00:18:44 john
485 * Made pressing the first letter of a menu
488 * Revision 1.22 1994/08/15 23:17:43 john
489 * *** empty log message ***
491 * Revision 1.21 1994/08/15 23:15:28 john
492 * Made 1 menu/checkbox return with any keypress.
494 * Revision 1.20 1994/08/12 10:18:23 john
495 * *** empty log message ***
497 * Revision 1.19 1994/08/12 10:09:11 john
498 * Made borders better.
500 * Revision 1.18 1994/08/12 03:11:16 john
501 * Made network be default off; Moved network options into
502 * main menu. Made starting net game check that mines are the
505 * Revision 1.17 1994/08/11 22:14:43 john
506 * Free'd up some memory that I forgot to free.
508 * Revision 1.16 1994/08/11 19:27:35 john
509 * Made the Backspace drop into the debugger only
510 * if you're not in an inputbox.
512 * Revision 1.15 1994/08/11 18:01:49 matt
513 * Added F2 and BACKSPACE keys to new menu system
515 * Revision 1.14 1994/08/11 14:25:58 john
516 * *** empty log message ***
518 * Revision 1.13 1994/08/11 14:25:40 john
519 * *** empty log message ***
521 * Revision 1.12 1994/08/11 13:47:02 john
522 * Made newmenu have subtitles, passed key through to
523 * the newmenu subfunctions.
525 * Revision 1.11 1994/08/11 12:45:08 john
526 * *** empty log message ***
528 * Revision 1.10 1994/08/11 12:25:45 john
529 * Made right_offset spacing different
531 * Revision 1.9 1994/08/11 12:09:49 john
532 * Made work with bitmapped fonts.
534 * Revision 1.8 1994/08/10 19:56:16 john
535 * Changed font stuff; Took out old menu; messed up lots of
536 * other stuff like game sequencing messages, etc.
538 * Revision 1.7 1994/07/27 16:12:23 john
539 * Changed newmenu system to have a callback function.
542 * Revision 1.6 1994/07/25 15:10:23 john
543 * *** empty log message ***
545 * Revision 1.5 1994/07/25 12:33:35 john
546 * Network "pinging" in.
548 * Revision 1.4 1994/07/24 18:21:27 john
549 * Took out first time stuff.
551 * Revision 1.3 1994/07/24 17:32:47 john
552 * Added percent item. Also neatend up a bit.
554 * Revision 1.2 1994/07/22 17:48:13 john
555 * Added new menuing system.
557 * Revision 1.1 1994/07/22 13:55:38 john
579 #include "pa_enabl.h" //$$POLY_ACC
589 #include "findfile.h"
593 #include "gamefont.h"
606 #include "endlevel.h"
618 #if defined (TACTILE)
622 #if defined(POLY_ACC)
623 #include "poly_acc.h"
626 #define MAXDISPLAYABLEITEMS 15
628 #define LHX(x) ((x)*(MenuHires?2:1))
629 #define LHY(y) ((y)*(MenuHires?2.4:1))
631 #define TITLE_FONT HUGE_FONT
632 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
633 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
634 #define SUBTITLE_FONT MEDIUM3_FONT
636 #define NORMAL_CHECK_BOX "
\81"
637 #define CHECKED_CHECK_BOX "
\82"
639 #define NORMAL_RADIO_BOX "
\7f"
640 #define CHECKED_RADIO_BOX "
\80"
641 #define CURSOR_STRING "_"
642 #define SLIDER_LEFT "
\83" // 131
643 #define SLIDER_RIGHT "
\84" // 132
644 #define SLIDER_MIDDLE "
\85" // 133
645 #define SLIDER_MARKER "
\86" // 134
646 #define UP_ARROW_MARKER "
\87" // 135
647 #define DOWN_ARROW_MARKER "
\88" // 136
649 int newmenu_do4( 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, int TinyMode );
650 void show_extra_netgame_info(int choice);
653 int Newmenu_first_time = 1;
654 //--unused-- int Newmenu_fade_in = 1;
657 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
658 grs_bitmap * saved; // The background under the menu.
659 grs_bitmap * background;
662 grs_bitmap nm_background,nm_background_save;
664 #define MESSAGEBOX_TEXT_SIZE 300 // How many characters in messagebox
665 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
667 ubyte MenuReordering=0;
669 char Pauseable_menu=0;
670 char already_showing_info=0;
673 void newmenu_close() {
674 if ( nm_background.bm_data )
675 d_free(nm_background.bm_data);
677 if ( nm_background_save.bm_data )
678 d_free(nm_background_save.bm_data);
679 Newmenu_first_time = 1;
682 ubyte background_palette[768];
684 //should be called whenever the palette changes
685 void nm_remap_background()
687 if (!Newmenu_first_time) {
688 if (!nm_background.bm_data)
689 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
691 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
693 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
699 extern char last_palette_loaded[];
701 void nm_draw_background1(char * filename)
708 //@@//I think this only gets called to fill the whole screen
709 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
710 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
712 pcx_error = pcx_get_dimensions(filename, &width, &height);
713 if (pcx_error != PCX_ERROR_NONE)
714 Error("Could not open pcx file <%s>\n", filename);
716 bmp = gr_create_bitmap(width, height);
718 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
719 Assert(pcx_error == PCX_ERROR_NONE);
721 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
724 { //remap stuff. this code is kindof a hack
726 //now, before we bring up the menu, we need to
727 //do some stuff to make sure the palette is ok. First, we need to
728 //get our current palette into the 2d's array, so the remapping will
729 //work. Second, we need to remap the fonts. Third, we need to fill
730 //in part of the fade tables so the darkening of the menu edges works
732 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
734 gr_palette_load(gr_palette);
736 remap_fonts_and_menus(1);
740 WIN(DDGRLOCK(dd_grd_curcanv));
741 #if defined(POLY_ACC)
743 pa_update_clut(gr_palette, 0, 256, 0);
746 #if defined(POLY_ACC)
749 WIN(DDGRUNLOCK(dd_grd_curcanv));
753 strcpy(last_palette_loaded,""); //force palette load next time
757 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
758 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
760 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
762 int Background_hires;
765 void nm_draw_background(int x1, int y1, int x2, int y2 )
769 if (Newmenu_first_time || MenuHires!=Background_hires) {
772 if (Newmenu_first_time) {
773 atexit( newmenu_close );
774 Newmenu_first_time = 0;
775 nm_background_save.bm_data=NULL;
778 if (nm_background_save.bm_data)
779 d_free(nm_background_save.bm_data);
780 if (nm_background.bm_data)
781 d_free(nm_background.bm_data);
784 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
785 Assert(pcx_error == PCX_ERROR_NONE);
787 nm_background = nm_background_save;
788 nm_background.bm_data=NULL;
789 nm_remap_background();
791 Background_hires = MenuHires;
794 if ( x1 < 0 ) x1 = 0;
795 if ( y1 < 0 ) y1 = 0;
800 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
801 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
808 grs_bitmap *tmp = gr_create_bitmap(w, h);
810 gr_bitmap_scale_to(&nm_background, tmp);
812 WIN(DDGRLOCK(dd_grd_curcanv));
814 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
816 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
820 WIN(DDGRLOCK(dd_grd_curcanv));
822 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
824 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
828 Gr_scanline_darkening_level = 2*7;
830 gr_setcolor( BM_XRGB(0,0,0) );
831 gr_urect( x2-5, y1+5, x2-5, y2-5 );
832 gr_urect( x2-4, y1+4, x2-4, y2-5 );
833 gr_urect( x2-3, y1+3, x2-3, y2-5 );
834 gr_urect( x2-2, y1+2, x2-2, y2-5 );
835 gr_urect( x2-1, y1+1, x2-1, y2-5 );
836 gr_urect( x2+0, y1+0, x2-0, y2-5 );
838 gr_urect( x1+5, y2-5, x2, y2-5 );
839 gr_urect( x1+4, y2-4, x2, y2-4 );
840 gr_urect( x1+3, y2-3, x2, y2-3 );
841 gr_urect( x1+2, y2-2, x2, y2-2 );
842 gr_urect( x1+1, y2-1, x2, y2-1 );
843 gr_urect( x1+0, y2, x2, y2-0 );
845 WIN(DDGRUNLOCK(dd_grd_curcanv));
847 Gr_scanline_darkening_level = GR_FADE_LEVELS;
850 void nm_restore_background( int x, int y, int w, int h )
857 if ( x1 < 0 ) x1 = 0;
858 if ( y1 < 0 ) y1 = 0;
860 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
861 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
866 WIN(DDGRLOCK(dd_grd_curcanv));
867 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
868 WIN(DDGRUNLOCK(dd_grd_curcanv));
871 // Draw a left justfied string
872 void nm_string( bkg * b, int w1,int x, int y, char * s)
874 int w,h,aw,tx=0,t=0,i;
875 char *p,*s1,*s2,measure[2];
876 int XTabs[]={15,87,124,162,228,253};
882 XTabs[i]=(LHX(XTabs[i]));
889 p = strchr( s2, '\t' );
896 gr_get_string_size(s2, &w, &h, &aw );
902 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
903 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
906 for (i=0;i<strlen(s2);i++) {
907 if (s2[i]=='\t' && SurfingNet) {
913 gr_get_string_size(measure,&tx,&h,&aw);
914 gr_string(x,y,measure);
921 if (!SurfingNet && p && (w1>0) ) {
922 gr_get_string_size(s1, &w, &h, &aw );
924 gr_string( x+w1-w, y, s1 );
931 // Draw a slider and it's string
932 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
939 p = strchr( s, '\t' );
945 gr_get_string_size(s, &w, &h, &aw );
948 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
949 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
951 gr_string( x, y, s );
954 gr_get_string_size(s1, &w, &h, &aw );
957 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
959 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
961 gr_string( x+w1-w, y, s1 );
968 // Draw a left justfied string with black background.
969 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
972 gr_get_string_size(s, &w, &h, &aw );
976 WIN(DDGRLOCK(dd_grd_curcanv));
977 gr_setcolor( BM_XRGB(2,2,2) );
978 gr_rect( x-1, y-1, x-1, y+h-1 );
979 gr_rect( x-1, y-1, x+w1-1, y-1 );
982 gr_setcolor( BM_XRGB(5,5,5) );
983 gr_rect( x, y+h, x+w1, y+h);
984 gr_rect( x+w1, y-1, x+w1, y+h );
986 gr_setcolor( BM_XRGB(0,0,0) );
987 gr_rect( x, y, x+w1-1, y+h-1 );
989 gr_string( x+1, y+1, s );
990 WIN(DDGRUNLOCK(dd_grd_curcanv));
994 // Draw a right justfied string
995 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
998 gr_get_string_size(s, &w, &h, &aw );
1001 if (w1 == 0) w1 = w;
1003 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
1006 WIN(DDGRLOCK(dd_grd_curcanv));
1007 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
1008 gr_string( x-w, y, s );
1009 WIN(DDGRUNLOCK(dd_grd_curcanv));
1014 //for text items, constantly redraw cursor (to achieve flash)
1015 void update_cursor( newmenu_item *item)
1018 fix time = timer_get_approx_seconds();
1020 char * text = item->text;
1022 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
1025 gr_get_string_size(text, &w, &h, &aw );
1026 if ( w > item->w-10 )
1033 x = item->x+w; y = item->y;
1035 WIN(DDGRLOCK(dd_grd_curcanv));
1037 gr_string( x, y, CURSOR_STRING );
1039 gr_setcolor( BM_XRGB(0,0,0) );
1040 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
1042 WIN(DDGRUNLOCK(dd_grd_curcanv));
1045 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
1050 gr_get_string_size(text, &w1, &h1, &aw );
1059 nm_string_black( b, w, x, y, text );
1062 gr_string( x+w1+1, y, CURSOR_STRING );
1066 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
1071 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
1073 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
1075 if (item->text[0]=='\t')
1076 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
1081 grd_curcanv->cv_font = SELECTED_FONT;
1083 grd_curcanv->cv_font = NORMAL_FONT;
1086 if (is_current && item->type == NM_TYPE_TEXT)
1087 grd_curcanv->cv_font = NORMAL_FONT;
1091 WIN(DDGRLOCK(dd_grd_curcanv));
1092 switch( item->type ) {
1094 // grd_curcanv->cv_font=TEXT_FONT;
1095 // fall through on purpose
1098 nm_string( b, item->w, item->x, item->y, item->text );
1100 case NM_TYPE_SLIDER: {
1102 if (item->value < item->min_value) item->value=item->min_value;
1103 if (item->value > item->max_value) item->value=item->max_value;
1104 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
1105 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
1106 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
1108 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
1110 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
1112 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
1115 case NM_TYPE_INPUT_MENU:
1116 if ( item->group==0 ) {
1117 nm_string( b, item->w, item->x, item->y, item->text );
1119 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
1123 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
1126 nm_string( b, item->w, item->x, item->y, item->text );
1128 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
1130 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
1133 nm_string( b, item->w, item->x, item->y, item->text );
1135 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
1137 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
1139 case NM_TYPE_NUMBER: {
1141 if (item->value < item->min_value) item->value=item->min_value;
1142 if (item->value > item->max_value) item->value=item->max_value;
1143 nm_string( b, item->w, item->x, item->y, item->text );
1144 sprintf( text, "%d", item->value );
1145 nm_rstring( b,item->right_offset,item->x, item->y, text );
1149 WIN(DDGRUNLOCK(dd_grd_curcanv));
1153 char *Newmenu_allowed_chars=NULL;
1155 //returns true if char is allowed
1156 int char_allowed(char c)
1158 char *p = Newmenu_allowed_chars;
1166 if (c>=p[0] && c<=p[1])
1175 void strip_end_whitespace( char * text )
1179 for (i=l-1; i>=0; i-- ) {
1180 if ( isspace(text[i]) )
1187 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
1189 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
1191 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
1193 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
1197 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
1199 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
1203 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 )
1205 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
1209 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 )
1211 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
1213 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 )
1215 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
1218 int newmenu_do_fixedfont( 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){
1219 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
1220 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
1221 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
1224 //returns 1 if a control device button has been pressed
1225 int check_button_press()
1229 switch (Config_control_type) {
1230 case CONTROL_JOYSTICK:
1231 case CONTROL_FLIGHTSTICK_PRO:
1232 case CONTROL_THRUSTMASTER_FCS:
1233 case CONTROL_GRAVIS_GAMEPAD:
1234 for (i=0; i<4; i++ )
1235 if (joy_get_button_down_cnt(i)>0) return 1;
1238 case CONTROL_CYBERMAN:
1239 #ifndef MACINTOSH // don't allow mouse to continue from menu
1240 for (i=0; i<3; i++ )
1241 if (mouse_button_down_count(i)>0) return 1;
1244 case CONTROL_WINJOYSTICK:
1246 for (i=0; i<4; i++ )
1247 if (joy_get_button_down_cnt(i)>0) return 1;
1250 case CONTROL_NONE: //keyboard only
1252 if (key_checkch()) return 1;
1257 Error("Bad control type (Config_control_type):%i",Config_control_type);
1263 extern int network_request_player_names(int);
1264 extern int RestoringMenu;
1266 #if defined(WINDOWS) || defined(MACINTOSH)
1267 ubyte Hack_DblClick_MenuMode=0;
1270 MAC(extern ubyte joydefs_calibrating;)
1274 #define CLOSE_SIZE 10
1276 void draw_close_box(int x,int y)
1278 WIN (DDGRLOCK(dd_grd_curcanv));
1279 gr_setcolor( BM_XRGB(0, 0, 0) );
1280 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
1281 gr_setcolor( BM_XRGB(21, 21, 21) );
1282 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
1283 WIN (DDGRUNLOCK(dd_grd_curcanv));
1286 int newmenu_do4( 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, int TinyMode )
1288 int old_keyd_repeat, done;
1289 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
1290 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
1291 grs_font * save_font;
1292 int string_width, string_height, average_width;
1295 int all_text=0; //set true if all text items
1296 int sound_stopped=0,time_stopped=0;
1297 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
1300 int MaxOnMenu=MAXDISPLAYABLEITEMS;
1301 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
1302 #if defined(MACINTOSH) || defined(WINDOWS)
1303 int mouse_state, omouse_state, dblclick_flag=0;
1304 int mx=0, my=0, x1, x2, y1, y2;
1308 EventRecord event; // looking for disk inserted events for CD mounts
1311 PA_DFX (pa_set_frontbuffer_current());
1312 PA_DFX (pa_set_front_to_read());
1314 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
1323 WIN(mouse_set_mode(0)); //disable centering mode
1325 MaxDisplayable=nitems;
1327 //set_screen_mode(SCREEN_MENU);
1330 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
1331 digi_pause_digi_sounds();
1335 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
1348 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
1350 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
1352 save_font = grd_curcanv->cv_font;
1357 grd_curcanv->cv_font = TITLE_FONT;
1358 gr_get_string_size(title,&string_width,&string_height,&average_width );
1363 grd_curcanv->cv_font = SUBTITLE_FONT;
1364 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1365 if (string_width > tw )
1367 th += string_height;
1370 th += LHY(8); //put some space between titles & body
1373 grd_curcanv->cv_font = SMALL_FONT;
1375 grd_curcanv->cv_font = NORMAL_FONT;
1379 nmenus = nothers = 0;
1381 // Find menu height & width (store in w,h)
1382 for (i=0; i<nitems; i++ ) {
1385 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
1386 item[i].right_offset = 0;
1389 string_height+=LHY(3);
1391 item[i].saved_text[0] = '\0';
1393 if ( item[i].type == NM_TYPE_SLIDER ) {
1396 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
1397 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
1398 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
1400 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
1401 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
1402 string_width += w1 + aw;
1405 if ( item[i].type == NM_TYPE_MENU ) {
1409 if ( item[i].type == NM_TYPE_CHECK ) {
1412 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
1413 item[i].right_offset = w1;
1414 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
1415 if (w1 > item[i].right_offset)
1416 item[i].right_offset = w1;
1419 if (item[i].type == NM_TYPE_RADIO ) {
1422 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
1423 item[i].right_offset = w1;
1424 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
1425 if (w1 > item[i].right_offset)
1426 item[i].right_offset = w1;
1429 if (item[i].type==NM_TYPE_NUMBER ) {
1433 sprintf( test_text, "%d", item[i].max_value );
1434 gr_get_string_size( test_text, &w1, &h1, &aw1 );
1435 item[i].right_offset = w1;
1436 sprintf( test_text, "%d", item[i].min_value );
1437 gr_get_string_size( test_text, &w1, &h1, &aw1 );
1438 if ( w1 > item[i].right_offset)
1439 item[i].right_offset = w1;
1442 if ( item[i].type == NM_TYPE_INPUT ) {
1443 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
1444 strcpy(item[i].saved_text, item[i].text );
1446 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
1447 if ( string_width > MAX_TEXT_WIDTH )
1448 string_width = MAX_TEXT_WIDTH;
1452 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
1453 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
1454 strcpy(item[i].saved_text, item[i].text );
1456 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
1461 item[i].w = string_width;
1462 item[i].h = string_height;
1464 if ( string_width > w )
1465 w = string_width; // Save maximum width
1466 if ( average_width > aw )
1468 h += string_height+1; // Find the height of all strings
1471 // Big hack for allowing the netgame options menu to spill over
1473 MaxOnMenu=MAXDISPLAYABLEITEMS;
1474 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
1477 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
1480 h=(MaxOnMenu*(string_height+1)+LHY(8));
1481 MaxDisplayable=MaxOnMenu;
1482 mprintf ((0,"Hey, this is a scroll box!\n"));
1495 for (i=0; i<nitems; i++ ) {
1497 if (item[i].right_offset > right_offset )
1498 right_offset = item[i].right_offset;
1500 if (right_offset > 0 )
1503 //gr_get_string_size("",&string_width,&string_height,&average_width );
1510 twidth = ( tw - w )/2;
1515 { right_offset=0; twidth=0;}
1517 mprintf(( 0, "Right offset = %d\n", right_offset ));
1520 // Find min point of menu border
1521 // x = (grd_curscreen->sc_w-w)/2;
1522 // y = (grd_curscreen->sc_h-h)/2;
1524 w += MenuHires?60:30;
1525 h += MenuHires?60:30;
1527 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
1528 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
1530 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
1531 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
1536 if ( filename != NULL ) {
1537 nm_draw_background1( filename );
1538 gr_palette_load(gr_palette);
1541 // Save the background of the display
1542 // Win95 must refer to the screen as a dd_grs_canvas, so...
1543 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
1544 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
1546 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
1547 gr_set_current_canvas(bg.menu_canvas) );
1549 if ( filename == NULL ) {
1550 // Save the background under the menu...
1556 #if defined(POLY_ACC)
1557 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1559 bg.saved = gr_create_bitmap( w, h );
1561 Assert( bg.saved != NULL );
1563 WIN (DDGRLOCK(dd_grd_curcanv));
1564 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1565 WIN (DDGRUNLOCK(dd_grd_curcanv));
1567 WINDOS ( dd_gr_set_current_canvas(NULL),
1568 gr_set_current_canvas( NULL )
1571 nm_draw_background(x,y,x+w-1,y+h-1);
1573 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1574 gr_set_current_canvas( bg.menu_canvas )
1577 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1581 #if defined(POLY_ACC)
1582 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1584 bg.background = gr_create_bitmap( w, h );
1586 Assert( bg.background != NULL );
1588 WIN (DDGRLOCK(dd_grd_curcanv));
1589 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1590 WIN (DDGRUNLOCK(dd_grd_curcanv));
1593 // ty = 15 + (yborder/4);
1595 ty = MenuHires?30:15;
1598 grd_curcanv->cv_font = TITLE_FONT;
1599 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1600 gr_get_string_size(title,&string_width,&string_height,&average_width );
1603 WIN (DDGRLOCK(dd_grd_curcanv));
1604 gr_printf( 0x8000, ty, title );
1605 WIN (DDGRUNLOCK(dd_grd_curcanv));
1610 grd_curcanv->cv_font = SUBTITLE_FONT;
1611 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1612 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1615 WIN (DDGRLOCK(dd_grd_curcanv));
1616 gr_printf( 0x8000, ty, subtitle );
1617 WIN (DDGRUNLOCK(dd_grd_curcanv));
1622 grd_curcanv->cv_font = SMALL_FONT;
1624 grd_curcanv->cv_font = NORMAL_FONT;
1626 // Update all item's x & y values.
1627 for (i=0; i<nitems; i++ ) {
1628 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1629 item[i].y += (MenuHires?30:15);
1630 if ( item[i].type==NM_TYPE_RADIO ) {
1631 fm = -1; // find first marked one
1632 for ( j=0; j<nitems; j++ ) {
1633 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1634 if (fm==-1 && item[j].value)
1646 old_keyd_repeat = keyd_repeat;
1652 if (citem < 0 ) citem = 0;
1653 if (citem > nitems-1 ) citem = nitems-1;
1656 #if defined(WINDOWS) || defined(MACINTOSH)
1660 while ( item[choice].type==NM_TYPE_TEXT ) {
1662 if (choice >= nitems ) {
1665 if (choice == citem ) {
1676 // Clear mouse, joystick to clear button presses.
1677 game_flush_inputs();
1679 #if defined(WINDOWS) || defined(MACINTOSH)
1680 mouse_state = omouse_state = 0;
1681 if (filename == NULL && !MenuReordering) {
1682 draw_close_box(0,0);
1688 if (!MenuReordering) {
1690 SetCursor (LoadCursor(NULL,IDC_ARROW));
1695 if (!joydefs_calibrating)
1699 mprintf ((0,"Set to true!\n"));
1705 DoMessageStuff(&msg);
1707 if (_RedrawScreen) {
1708 _RedrawScreen = FALSE;
1711 gr_free_bitmap(bg.saved);
1712 d_free( bg.background );
1715 gr_free_bitmap(bg.background);
1717 dd_gr_free_sub_canvas( bg.menu_canvas );
1718 grd_curcanv->cv_font = save_font;
1719 dd_grd_curcanv = save_canvas;
1721 goto RePaintNewmenu4;
1730 omouse_state = mouse_state;
1731 mouse_state = mouse_button_state(0);
1732 if (!joydefs_calibrating)
1733 show_cursor(); // possibly hidden
1737 omouse_state = mouse_state;
1738 if (!MenuReordering)
1739 mouse_state = mouse_button_state(0);
1740 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1743 //see if redbook song needs to be restarted
1744 songs_check_redbook_repeat();
1751 (*subfunction)(nitems,item,&k,choice);
1754 if (!time_stopped) {
1755 // Save current menu box
1756 if (multi_menu_poll() == -1)
1762 dont_restore = (k == -3); //-3 means don't restore
1768 if (check_button_press())
1772 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1775 old_choice = choice;
1781 if (SurfingNet && !already_showing_info)
1783 show_extra_netgame_info(choice-2);
1785 if (SurfingNet && already_showing_info)
1792 if (SurfingNet && !already_showing_info)
1794 network_request_player_names(choice-2);
1796 if (SurfingNet && already_showing_info)
1811 case KEY_TAB + KEY_SHIFTED:
1814 if (all_text) break;
1821 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1823 if (choice<TopChoice)
1824 { choice=TopChoice; break; }
1826 if (choice<ScrollOffset)
1828 for (i=0;i<nitems;i++)
1831 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1836 if (choice >= nitems ) choice=0;
1837 if (choice < 0 ) choice=nitems-1;
1839 } while ( item[choice].type==NM_TYPE_TEXT );
1840 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1841 item[choice].value = -1;
1842 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1843 item[old_choice].group=0;
1844 strcpy(item[old_choice].text, item[old_choice].saved_text );
1845 item[old_choice].value = -1;
1848 item[old_choice].redraw = 1;
1849 item[choice].redraw=1;
1854 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1855 if (all_text) break;
1862 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1865 { choice--; break; }
1867 if (choice>=MaxOnMenu+ScrollOffset)
1869 for (i=0;i<nitems;i++)
1872 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1877 if (choice < 0 ) choice=nitems-1;
1878 if (choice >= nitems ) choice=0;
1881 } while ( item[choice].type==NM_TYPE_TEXT );
1883 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1884 item[choice].value = -1;
1885 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1886 item[old_choice].group=0;
1887 strcpy(item[old_choice].text, item[old_choice].saved_text );
1888 item[old_choice].value = -1;
1891 item[old_choice].redraw=1;
1892 item[choice].redraw=1;
1895 if ( choice > -1 ) {
1896 switch( item[choice].type ) {
1899 case NM_TYPE_INPUT_MENU:
1902 if ( item[choice].value )
1903 item[choice].value = 0;
1905 item[choice].value = 1;
1906 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1909 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1911 mprintf ((0,"Special redraw!\n"));
1916 item[choice].redraw=1;
1919 for (i=0; i<nitems; i++ ) {
1920 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1925 item[choice].value = 1;
1926 item[choice].redraw = 1;
1932 case KEY_SHIFTED+KEY_UP:
1933 if (MenuReordering && choice!=TopChoice)
1935 Temp=item[choice].text;
1936 TempVal=item[choice].value;
1937 item[choice].text=item[choice-1].text;
1938 item[choice].value=item[choice-1].value;
1939 item[choice-1].text=Temp;
1940 item[choice-1].value=TempVal;
1941 item[choice].redraw=1;
1942 item[choice-1].redraw=1;
1946 case KEY_SHIFTED+KEY_DOWN:
1947 if (MenuReordering && choice!=(nitems-1))
1949 Temp=item[choice].text;
1950 TempVal=item[choice].value;
1951 item[choice].text=item[choice+1].text;
1952 item[choice].value=item[choice+1].value;
1953 item[choice+1].text=Temp;
1954 item[choice+1].value=TempVal;
1955 item[choice].redraw=1;
1956 item[choice+1].redraw=1;
1963 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1964 item[choice].group = 1;
1965 item[choice].redraw = 1;
1966 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1967 item[choice].text[0] = 0;
1968 item[choice].value = -1;
1970 strip_end_whitespace(item[choice].text);
1977 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1978 item[choice].group=0;
1979 strcpy(item[choice].text, item[choice].saved_text );
1980 item[choice].redraw=1;
1981 item[choice].value = -1;
1988 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1989 case KEY_PRINT_SCREEN:
1991 save_screen_shot(0);
1992 PA_DFX (pa_set_frontbuffer_current());
1993 PA_DFX (pa_set_front_to_read());
1994 for (i=0;i<nitems;i++)
2003 case KEY_COMMAND+KEY_RIGHT:
2004 songs_goto_next_song();
2006 case KEY_COMMAND+KEY_LEFT:
2007 songs_goto_prev_song();
2009 case KEY_COMMAND+KEY_UP:
2010 songs_play_level_song(1);
2012 case KEY_COMMAND+KEY_DOWN:
2013 songs_stop_redbook();
2016 case KEY_COMMAND+KEY_M:
2018 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
2019 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
2022 key_close(); // no processing of keys with keyboard handler.. jeez
2025 show_boxed_message ("Mounting CD\nESC to quit");
2026 RBAMountDisk(); // OS has totaly control of the CD.
2027 if (Function_mode == FMODE_MENU)
2028 songs_play_song(SONG_TITLE,1);
2029 else if (Function_mode == FMODE_GAME)
2030 songs_play_level_song( Current_level_num );
2031 clear_boxed_message();
2040 case KEY_COMMAND+KEY_E:
2041 songs_stop_redbook();
2043 k = -1; // force key not to register
2046 case KEY_COMMAND+KEY_Q: {
2047 extern void macintosh_quit();
2049 if ( !(Game_mode & GM_MULTI) )
2051 if (!joydefs_calibrating)
2053 k = -1; // force key not to register
2060 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
2067 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
2069 if ( !done && mouse_state && !omouse_state && !all_text ) {
2070 mouse_get_pos(&mx, &my);
2071 for (i=0; i<nitems; i++ ) {
2072 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
2073 x2 = x1 + item[i].w;
2074 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
2075 y2 = y1 + item[i].h;
2076 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
2077 if (i+ScrollOffset != choice) {
2078 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
2081 choice = i + ScrollOffset;
2083 switch( item[choice].type ) {
2085 if ( item[choice].value )
2086 item[choice].value = 0;
2088 item[choice].value = 1;
2089 item[choice].redraw=1;
2096 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
2098 mprintf ((0,"Special redraw!\n"));
2105 for (i=0; i<nitems; i++ ) {
2106 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
2111 item[choice].value = 1;
2112 item[choice].redraw = 1;
2115 item[old_choice].redraw=1;
2121 if (mouse_state && all_text)
2124 if ( !done && mouse_state && !all_text ) {
2125 mouse_get_pos(&mx, &my);
2127 // check possible scrollbar stuff first
2129 int arrow_width, arrow_height, aw;
2131 if (ScrollOffset != 0) {
2132 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
2133 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
2134 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
2135 x1 = x1 - arrow_width;
2136 y2 = y1 + arrow_height;
2137 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2140 mprintf ((0,"Scrolling! Choice=%d\n",choice));
2142 if (choice<ScrollOffset)
2144 for (i=0;i<nitems;i++)
2147 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
2151 if (ScrollOffset+MaxDisplayable<nitems) {
2152 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
2153 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
2154 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
2155 x1 = x1 - arrow_width;
2156 y2 = y1 + arrow_height;
2157 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2160 mprintf ((0,"Scrolling! Choice=%d\n",choice));
2162 if (choice>=MaxOnMenu+ScrollOffset)
2164 for (i=0;i<nitems;i++)
2167 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
2173 for (i=0; i<nitems; i++ ) {
2174 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
2175 x2 = x1 + item[i].w;
2176 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
2177 y2 = y1 + item[i].h;
2178 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
2179 if (i+ScrollOffset != choice) {
2180 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
2183 choice = i + ScrollOffset;
2185 if ( item[choice].type == NM_TYPE_SLIDER ) {
2186 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
2187 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
2189 strcpy(slider_text, item[choice].saved_text);
2190 p = strchr(slider_text, '\t');
2196 gr_get_string_size(s1, &slider_width, &height, &aw);
2197 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
2198 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
2199 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
2201 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
2202 x2 = x1 + slider_width + sright_width;
2203 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
2204 item[choice].value = item[choice].min_value;
2205 item[choice].redraw = 2;
2206 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
2207 item[choice].value = item[choice].max_value;
2208 item[choice].redraw = 2;
2209 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
2210 int num_values, value_width, new_value;
2212 num_values = item[choice].max_value - item[choice].min_value + 1;
2213 value_width = (slider_width - sleft_width - sright_width) / num_values;
2214 new_value = (mx - x1 - sleft_width) / value_width;
2215 if ( item[choice].value != new_value ) {
2216 item[choice].value = new_value;
2217 item[choice].redraw = 2;
2223 if (choice == old_choice)
2225 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
2226 item[choice].value = -1;
2227 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
2228 item[old_choice].group=0;
2229 strcpy(item[old_choice].text, item[old_choice].saved_text );
2230 item[old_choice].value = -1;
2233 item[old_choice].redraw = 1;
2234 item[choice].redraw=1;
2240 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
2241 mouse_get_pos(&mx, &my);
2242 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
2243 x2 = x1 + item[choice].w;
2244 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
2245 y2 = y1 + item[choice].h;
2246 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
2247 if (Hack_DblClick_MenuMode) {
2248 if (dblclick_flag) done = 1;
2249 else dblclick_flag = 1;
2255 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
2256 item[choice].group = 1;
2257 item[choice].redraw = 1;
2258 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
2259 item[choice].text[0] = 0;
2260 item[choice].value = -1;
2262 strip_end_whitespace(item[choice].text);
2266 if ( !done && !mouse_state && omouse_state && close_box ) {
2267 mouse_get_pos(&mx, &my);
2268 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
2269 x2 = x1 + CLOSE_SIZE;
2270 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
2271 y2 = y1 + CLOSE_SIZE;
2272 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2278 // HACK! Don't redraw loadgame preview
2279 if (RestoringMenu) item[0].redraw = 0;
2280 #endif // ifdef MACINTOSH
2282 if ( choice > -1 ) {
2285 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
2286 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
2287 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
2288 if (item[choice].value > 0)
2289 item[choice].value--;
2290 item[choice].text[item[choice].value] = 0;
2291 item[choice].redraw = 1;
2293 ascii = key_to_ascii(k);
2294 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
2298 if (item[choice].value==-1) {
2299 item[choice].value = 0;
2302 allowed = char_allowed(ascii);
2304 if (!allowed && ascii==' ' && char_allowed('_')) {
2310 item[choice].text[item[choice].value++] = ascii;
2311 item[choice].text[item[choice].value] = 0;
2312 item[choice].redraw=1;
2316 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
2317 ascii = key_to_ascii(k);
2319 int choice1 = choice;
2320 ascii = toupper(ascii);
2324 if (choice1 >= nitems ) choice1=0;
2325 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
2326 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
2327 (item[choice1].type==NM_TYPE_CHECK) ||
2328 (item[choice1].type==NM_TYPE_RADIO) ||
2329 (item[choice1].type==NM_TYPE_NUMBER) ||
2330 (item[choice1].type==NM_TYPE_SLIDER) )
2331 && (ascii==toupper(ch)) ) {
2335 item[old_choice].redraw=1;
2336 item[choice].redraw=1;
2338 } while (choice1 != choice );
2342 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
2343 int ov=item[choice].value;
2348 case KEY_MINUS+KEY_SHIFTED:
2350 item[choice].value -= 1;
2355 case KEY_EQUAL+KEY_SHIFTED:
2357 item[choice].value++;
2362 item[choice].value += 10;
2367 item[choice].value -= 10;
2370 if (ov!=item[choice].value)
2371 item[choice].redraw=1;
2376 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
2377 gr_set_current_canvas(bg.menu_canvas));
2379 // Redraw everything...
2380 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
2382 if (item[i].redraw) // warning! ugly hack below
2384 item[i].y-=((string_height+1)*ScrollOffset);
2387 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
2389 MAC(if (!joydefs_calibrating) show_cursor());
2390 WIN(if (!MenuReordering) ShowCursorW());
2391 item[i].y+=((string_height+1)*ScrollOffset);
2393 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
2394 update_cursor( &item[i]);
2400 //grd_curcanv->cv_font = NORMAL_FONT;
2402 if (LastScrollCheck!=ScrollOffset)
2404 LastScrollCheck=ScrollOffset;
2405 grd_curcanv->cv_font = SELECTED_FONT;
2407 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
2408 sx=item[ScrollOffset].x-(MenuHires?24:12);
2411 if (ScrollOffset!=0)
2412 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
2414 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
2416 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
2417 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
2419 if (ScrollOffset+MaxDisplayable<nitems)
2420 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
2422 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
2428 if ( !dont_restore && gr_palette_faded_out ) {
2429 gr_palette_fade_in( gr_palette, 32, 0 );
2436 // Restore everything...
2438 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
2439 gr_set_current_canvas(bg.menu_canvas));
2441 if ( filename == NULL ) {
2442 // Save the background under the menu...
2443 WIN (DDGRLOCK(dd_grd_curcanv));
2444 gr_bitmap(0, 0, bg.saved);
2445 WIN (DDGRUNLOCK(dd_grd_curcanv));
2446 gr_free_bitmap(bg.saved);
2447 d_free( bg.background );
2449 if (!dont_restore) //info passed back from subfunction
2451 WIN (DDGRLOCK(dd_grd_curcanv));
2452 gr_bitmap(0, 0, bg.background);
2453 WIN (DDGRUNLOCK(dd_grd_curcanv));
2455 gr_free_bitmap(bg.background);
2458 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
2459 gr_free_sub_canvas( bg.menu_canvas ) );
2461 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
2462 grd_curcanv->cv_font = save_font;
2463 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
2464 keyd_repeat = old_keyd_repeat;
2466 game_flush_inputs();
2477 if ( sound_stopped )
2478 digi_resume_digi_sounds();
2480 WIN(mouse_set_mode(1)); //re-enable centering mode
2487 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
2493 char nm_text[MESSAGEBOX_TEXT_SIZE];
2494 newmenu_item nm_message_items[5];
2496 va_start(args, nchoices );
2498 Assert( nchoices <= 5 );
2500 for (i=0; i<nchoices; i++ ) {
2501 s = va_arg( args, char * );
2502 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
2504 format = va_arg( args, char * );
2505 strcpy( nm_text, "" );
2506 vsprintf(nm_text,format,args);
2509 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
2511 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
2514 int nm_messagebox( char *title, int nchoices, ... )
2520 char nm_text[MESSAGEBOX_TEXT_SIZE];
2521 newmenu_item nm_message_items[5];
2523 va_start(args, nchoices );
2525 Assert( nchoices <= 5 );
2527 for (i=0; i<nchoices; i++ ) {
2528 s = va_arg( args, char * );
2529 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
2531 format = va_arg( args, char * );
2532 strcpy( nm_text, "" );
2533 vsprintf(nm_text,format,args);
2536 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
2538 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
2544 void newmenu_file_sort( int n, char *list )
2551 for (i=incr; i<n; i++ ) {
2554 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
2555 memcpy( t, &list[j*14], FILENAME_LEN );
2556 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
2557 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2568 void delete_player_saved_games(char * name)
2573 for (i=0;i<10; i++) {
2575 sprintf( filename, "%s.sg%d", name, i );
2577 sprintf( filename, ":Players:%s.sg%d", name, i );
2579 cfile_delete(filename);
2583 #define MAX_FILES 300
2585 int MakeNewPlayerFile(int allow_abort);
2587 extern char AltHogDir[64];
2588 extern char AltHogdir_initialized;
2590 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2593 FILEFINDSTRUCT find;
2594 int NumFiles=0, key,done, citem, ocitem;
2595 char * filenames = NULL;
2596 int NumFiles_displayed = 8;
2597 int first_item = -1, ofirst_item;
2598 int old_keyd_repeat = keyd_repeat;
2601 int demos_deleted=0;
2602 int initialized = 0;
2604 int w_x, w_y, w_w, w_h, title_height;
2605 int box_x, box_y, box_w, box_h;
2606 bkg bg; // background under listbox
2607 #if defined(MACINTOSH) || defined(WINDOWS)
2608 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2609 int mouse2_state, omouse2_state;
2610 int dblclick_flag=0;
2612 int show_up_arrow=0,show_down_arrow=0;
2614 WIN(int win_redraw=0);
2616 w_x=w_y=w_w=w_h=title_height=0;
2617 box_x=box_y=box_w=box_h=0;
2619 filenames = d_malloc( MAX_FILES * 14 );
2620 if (filenames==NULL) return 0;
2625 WIN(mouse_set_mode(0)); //disable centering mode
2627 if (strstr( filespec, "*.plr" ))
2629 else if (strstr( filespec, "*.dem" ))
2636 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2638 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2643 if( !FileFindFirst( filespec, &find ) ) {
2645 if (NumFiles<MAX_FILES) {
2646 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2647 if ( player_mode ) {
2649 p = strchr(&filenames[NumFiles*14],'.');
2656 } while( !FileFindNext( &find ) );
2660 if (demo_mode && AltHogdir_initialized) {
2661 char filespec2[PATH_MAX + FILENAME_LEN];
2662 strcpy(filespec2, AltHogDir);
2663 strcat(filespec2, "/");
2664 strcat(filespec2, filespec);
2665 if ( !FileFindFirst( filespec2, &find ) ) {
2667 if (NumFiles<MAX_FILES) {
2668 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2673 } while( !FileFindNext( &find ) );
2678 if ( (NumFiles < 1) && demos_deleted ) {
2682 if ( (NumFiles < 1) && demo_mode ) {
2683 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2689 if ( (NumFiles < 2) && player_mode ) {
2691 goto ExitFileMenuEarly;
2698 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2705 // set_screen_mode(SCREEN_MENU);
2711 dd_gr_set_current_canvas(NULL);
2713 gr_set_current_canvas(NULL);
2716 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2718 grd_curcanv->cv_font = SUBTITLE_FONT;
2720 WIN(DDGRUNLOCK(dd_grd_curcanv));
2725 for (i=0; i<NumFiles; i++ ) {
2727 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2733 gr_get_string_size( title, &w, &h, &aw );
2736 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2740 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2742 w_w += (grd_curfont->ft_w * 4);
2743 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2745 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2746 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2748 w_x = (grd_curcanv->cv_w-w_w)/2;
2749 w_y = (grd_curcanv->cv_h-w_h)/2;
2751 if ( w_x < 0 ) w_x = 0;
2752 if ( w_y < 0 ) w_y = 0;
2754 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2755 box_y = w_y + title_height;
2757 // save the screen behind the menu.
2761 #if !defined(WINDOWS)
2762 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2763 bg.background = &VR_offscreen_buffer->cv_bitmap;
2766 #if defined(POLY_ACC)
2767 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2769 bg.background = gr_create_bitmap( w_w, w_h );
2772 Assert( bg.background != NULL );
2775 WIN(DDGRLOCK(dd_grd_curcanv));
2776 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2777 WIN(DDGRUNLOCK(dd_grd_curcanv));
2781 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2782 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2783 dd_VR_offscreen_buffer, 0, 0,
2784 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2785 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2789 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2791 WIN(DDGRLOCK(dd_grd_curcanv))
2793 gr_string( 0x8000, w_y+10, title );
2795 WIN(DDGRUNLOCK(dd_grd_curcanv));
2802 if ( !player_mode ) {
2803 newmenu_file_sort( NumFiles, filenames );
2805 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2806 newmenu_file_sort( NumFiles, filenames );
2808 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2810 for ( i=0; i<NumFiles; i++ ) {
2811 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2812 #if defined(WINDOWS) || defined(MACINTOSH)
2820 #if defined(MACINTOSH) || defined(WINDOWS)
2821 mouse_state = omouse_state = 0;
2822 mouse2_state = omouse2_state = 0;
2823 draw_close_box(w_x,w_y);
2835 DoMessageStuff(&msg);
2837 if (_RedrawScreen) {
2838 _RedrawScreen = FALSE;
2840 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2841 gr_free_bitmap(bg.background);
2844 goto RePaintNewmenuFile;
2851 ofirst_item = first_item;
2854 #if defined(MACINTOSH) || defined(WINDOWS)
2855 omouse_state = mouse_state;
2856 omouse2_state = mouse2_state;
2857 mouse_state = mouse_button_state(0);
2858 mouse2_state = mouse_button_state(1);
2861 //see if redbook song needs to be restarted
2862 songs_check_redbook_repeat();
2865 if (!mouse2_state && omouse2_state)
2866 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2869 //NOTE LINK TO ABOVE ELSE
2875 else if (simukey==1)
2881 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2882 case KEY_PRINT_SCREEN:
2884 save_screen_shot(0);
2885 PA_DFX (pa_set_frontbuffer_current());
2886 PA_DFX (pa_set_front_to_read());
2892 case KEY_CTRLED+KEY_D:
2893 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2897 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2901 mouse_set_mode(1); //re-enable centering mode
2905 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2907 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2910 mouse_set_mode(0); //disenable centering mode
2916 char name[_MAX_PATH],dir[_MAX_DIR];
2918 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2922 _splitpath(filespec,name,dir,NULL,NULL);
2924 strcat(name,&filenames[citem*14]);
2931 if ( !strncmp(name, ".\\", 2) )
2932 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2933 name[i] = name[i+1];
2934 while ( (p = strchr(name, '\\')) )
2939 ret = cfile_delete(name);
2943 if ((!ret) && player_mode) {
2944 delete_player_saved_games( &filenames[citem*14] );
2949 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2951 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2952 } else if (demo_mode)
2977 citem += NumFiles_displayed;
2981 citem -= NumFiles_displayed;
2984 if (allow_abort_flag) {
2995 case KEY_COMMAND+KEY_Q: {
2996 extern void macintosh_quit();
2998 if ( !(Game_mode & GM_MULTI) )
3009 int ascii = key_to_ascii(key);
3010 if ( ascii < 255 ) {
3013 if (cc1 < 0 ) cc1 = 0;
3014 if (cc1 >= NumFiles ) cc1 = 0;
3016 if ( cc < 0 ) cc = 0;
3017 if ( cc >= NumFiles ) cc = 0;
3018 if ( citem == cc ) break;
3020 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
3035 if (citem>=NumFiles)
3038 if (citem< first_item)
3041 if (citem>=( first_item+NumFiles_displayed))
3043 first_item = citem-NumFiles_displayed+1;
3047 if (NumFiles>first_item+NumFiles_displayed)
3058 if (NumFiles <= NumFiles_displayed )
3061 if (first_item>NumFiles-NumFiles_displayed)
3063 first_item = NumFiles-NumFiles_displayed;
3066 if (first_item < 0 ) first_item = 0;
3068 #if defined(MACINTOSH) || defined(WINDOWS)
3070 if (mouse_state || mouse2_state) {
3073 mouse_get_pos(&mx, &my);
3074 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
3075 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
3077 x2 = box_x + box_w - 1;
3078 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
3080 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3081 if (i == citem && !mouse2_state) {
3091 if (!mouse_state && omouse_state) {
3094 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
3095 mouse_get_pos(&mx, &my);
3097 x2 = box_x + box_w - 1;
3098 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
3100 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3101 if (dblclick_flag) done = 1;
3102 else dblclick_flag = 1;
3106 if ( !mouse_state && omouse_state ) {
3107 mouse_get_pos(&mx, &my);
3108 x1 = w_x + CLOSE_X + 2;
3109 x2 = x1 + CLOSE_SIZE - 2;
3110 y1 = w_y + CLOSE_Y + 2;
3111 y2 = y1 + CLOSE_SIZE - 2;
3112 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3121 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
3123 y1 = box_y+box_h-LHY(7);
3125 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
3132 WIN(DDGRLOCK(dd_grd_curcanv));
3133 gr_setcolor( BM_XRGB(2,2,2));
3134 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
3135 gr_setcolor( BM_XRGB( 0,0,0) );
3138 if (ofirst_item != first_item || win_redraw) {
3141 if (ofirst_item != first_item) {
3145 gr_setcolor( BM_XRGB( 0,0,0) );
3146 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
3148 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
3150 if ( i >= NumFiles ) {
3152 gr_setcolor( BM_XRGB(5,5,5));
3153 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
3154 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
3156 gr_setcolor( BM_XRGB(2,2,2));
3157 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
3159 gr_setcolor( BM_XRGB(0,0,0));
3160 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
3164 grd_curcanv->cv_font = SELECTED_FONT;
3166 grd_curcanv->cv_font = NORMAL_FONT;
3167 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
3169 gr_setcolor( BM_XRGB(5,5,5));
3170 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
3171 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
3173 gr_setcolor( BM_XRGB(2,2,2));
3174 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
3175 gr_setcolor( BM_XRGB(0,0,0));
3177 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
3178 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
3183 } else if ( citem != ocitem ) {
3189 if ( (i>=0) && (i<NumFiles) ) {
3190 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
3192 grd_curcanv->cv_font = SELECTED_FONT;
3194 grd_curcanv->cv_font = NORMAL_FONT;
3195 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
3196 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
3197 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
3200 if ( (i>=0) && (i<NumFiles) ) {
3201 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
3203 grd_curcanv->cv_font = SELECTED_FONT;
3205 grd_curcanv->cv_font = NORMAL_FONT;
3206 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
3207 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
3208 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
3215 grd_curcanv->cv_font = NORMAL_FONT;
3217 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
3221 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
3225 if (show_down_arrow)
3226 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
3230 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
3238 WIN(DDGRUNLOCK(dd_grd_curcanv));
3244 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
3251 keyd_repeat = old_keyd_repeat;
3253 if ( initialized ) {
3254 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
3256 WIN (DDGRLOCK(dd_grd_curcanv));
3257 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3258 WIN (DDGRUNLOCK(dd_grd_curcanv));
3260 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3261 gr_free_bitmap(bg.background);
3264 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3265 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3267 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3268 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3278 WIN(mouse_set_mode(1)); //re-enable centering mode
3286 // Example listbox callback function...
3287 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
3291 // if ( *keypress = KEY_CTRLED+KEY_D ) {
3292 // if ( *nitems > 1 ) {
3293 // cfile_delete(items[*citem]); // Delete the file
3294 // for (i=*citem; i<*nitems-1; i++ ) {
3295 // items[i] = items[i+1];
3297 // *nitems = *nitems - 1;
3298 // d_free( items[*nitems] );
3299 // items[*nitems] = NULL;
3300 // return 1; // redraw;
3307 #define LB_ITEMS_ON_SCREEN 8
3309 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
3311 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
3314 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 ) )
3317 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
3318 int old_keyd_repeat = keyd_repeat;
3319 int width, height, wx, wy, title_height, border_size;
3320 int total_width,total_height;
3322 #if defined(MACINTOSH) || defined(WINDOWS)
3323 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
3324 int close_x,close_y;
3325 int simukey=0,show_up_arrow=0,show_down_arrow=0;
3327 WIN(int win_redraw=0);
3331 PA_DFX (pa_set_frontbuffer_current());
3332 PA_DFX (pa_set_front_to_read());
3333 WIN(mouse_set_mode(0)); //disable centering mode
3335 // set_screen_mode(SCREEN_MENU);
3339 RePaintNewmenuListbox:
3341 dd_gr_set_current_canvas(NULL);
3343 gr_set_current_canvas(NULL);
3346 grd_curcanv->cv_font = SUBTITLE_FONT;
3349 for (i=0; i<nitems; i++ ) {
3351 gr_get_string_size( items[i], &w, &h, &aw );
3355 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
3359 gr_get_string_size( title, &w, &h, &aw );
3362 title_height = h + 5;
3365 border_size = grd_curfont->ft_w;
3366 WIN (border_size=grd_curfont->ft_w*2);
3368 width += (grd_curfont->ft_w);
3369 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
3370 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
3372 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
3373 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
3374 if ( wy < title_height )
3377 total_width = width+2*border_size;
3378 total_height = height+2*border_size+title_height;
3382 #if !defined(WINDOWS)
3383 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
3384 bg.background = &VR_offscreen_buffer->cv_bitmap;
3387 //bg.background = gr_create_bitmap( width, (height + title_height) );
3388 #if defined(POLY_ACC)
3389 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
3391 bg.background = gr_create_bitmap(total_width,total_height);
3393 Assert( bg.background != NULL );
3395 WIN (DDGRLOCK(dd_grd_curcanv));
3396 //gr_bm_bitblt(wx+width+border_size, wy+height+border_size, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
3397 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
3398 WIN (DDGRUNLOCK(dd_grd_curcanv));
3402 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
3403 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3404 dd_VR_offscreen_buffer, 0, 0,
3405 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3406 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
3410 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
3412 WIN(DDGRLOCK(dd_grd_curcanv));
3413 gr_string( 0x8000, wy - title_height, title );
3414 WIN(DDGRUNLOCK(dd_grd_curcanv));
3419 citem = default_item;
3420 if ( citem < 0 ) citem = 0;
3421 if ( citem >= nitems ) citem = 0;
3425 #if defined(MACINTOSH) || defined(WINDOWS)
3426 mouse_state = omouse_state = 0; //dblclick_flag = 0;
3427 close_x = wx-border_size;
3428 close_y = wy-title_height-border_size;
3429 draw_close_box(close_x,close_y);
3441 DoMessageStuff(&msg);
3443 if (_RedrawScreen) {
3444 _RedrawScreen = FALSE;
3446 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3447 gr_free_bitmap(bg.background);
3449 goto RePaintNewmenuListbox;
3456 ofirst_item = first_item;
3457 #if defined(MACINTOSH) || defined(WINDOWS)
3458 omouse_state = mouse_state;
3459 mouse_state = mouse_button_state(0);
3461 //see if redbook song needs to be restarted
3462 songs_check_redbook_repeat();
3466 if ( listbox_callback )
3467 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
3488 else if (simukey==1)
3494 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
3495 case KEY_PRINT_SCREEN:
3497 save_screen_shot(0);
3498 PA_DFX (pa_set_frontbuffer_current());
3499 PA_DFX (pa_set_front_to_read());
3522 citem += LB_ITEMS_ON_SCREEN;
3526 citem -= LB_ITEMS_ON_SCREEN;
3529 if (allow_abort_flag) {
3540 case KEY_COMMAND+KEY_Q: {
3541 extern void macintosh_quit();
3543 if ( !(Game_mode & GM_MULTI) )
3553 int ascii = key_to_ascii(key);
3554 if ( ascii < 255 ) {
3557 if (cc1 < 0 ) cc1 = 0;
3558 if (cc1 >= nitems ) cc1 = 0;
3560 if ( cc < 0 ) cc = 0;
3561 if ( cc >= nitems ) cc = 0;
3562 if ( citem == cc ) break;
3564 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
3581 if (citem< first_item)
3584 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
3585 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3587 if (nitems <= LB_ITEMS_ON_SCREEN )
3590 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3591 first_item = nitems-LB_ITEMS_ON_SCREEN;
3592 if (first_item < 0 ) first_item = 0;
3595 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3606 #if defined(MACINTOSH) || defined(WINDOWS)
3611 mouse_get_pos(&mx, &my);
3612 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3615 gr_get_string_size(items[i], &w, &h, &aw );
3618 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3620 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3632 //no double-click stuff for listbox
3633 //@@if (!mouse_state && omouse_state) {
3636 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3637 //@@ mouse_get_pos(&mx, &my);
3639 //@@ x2 = wx + width;
3640 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3642 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3643 //@@ if (dblclick_flag) done = 1;
3647 //check for close box clicked
3648 if ( !mouse_state && omouse_state ) {
3649 mouse_get_pos(&mx, &my);
3650 x1 = close_x + CLOSE_X + 2;
3651 x2 = x1 + CLOSE_SIZE - 2;
3652 y1 = close_y + CLOSE_Y + 2;
3653 y2 = y1 + CLOSE_SIZE - 2;
3654 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3664 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3666 y1 = total_height-LHY(7);
3668 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3676 if ( (ofirst_item != first_item) || redraw) {
3679 WIN(DDGRLOCK(dd_grd_curcanv));
3681 gr_setcolor( BM_XRGB( 0,0,0) );
3682 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3684 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3685 if ( i >= nitems ) {
3686 gr_setcolor( BM_XRGB(0,0,0));
3687 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3690 grd_curcanv->cv_font = SELECTED_FONT;
3692 grd_curcanv->cv_font = NORMAL_FONT;
3693 gr_get_string_size(items[i], &w, &h, &aw );
3694 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3695 gr_string( wx+5, y, items[i] );
3700 // If Win95 port, draw up/down arrows on left side of menu
3702 grd_curcanv->cv_font = NORMAL_FONT;
3704 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3708 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3712 if (show_down_arrow)
3713 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3717 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3724 WIN(DDGRUNLOCK(dd_grd_curcanv));
3728 } else if ( citem != ocitem ) {
3734 WIN(DDGRLOCK(dd_grd_curcanv));
3737 if ( (i>=0) && (i<nitems) ) {
3738 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3740 grd_curcanv->cv_font = SELECTED_FONT;
3742 grd_curcanv->cv_font = NORMAL_FONT;
3743 gr_get_string_size(items[i], &w, &h, &aw );
3744 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3745 gr_string( wx+5, y, items[i] );
3749 if ( (i>=0) && (i<nitems) ) {
3750 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3752 grd_curcanv->cv_font = SELECTED_FONT;
3754 grd_curcanv->cv_font = NORMAL_FONT;
3755 gr_get_string_size( items[i], &w, &h, &aw );
3756 gr_rect( wx, y-1, wx+width-1, y+h );
3757 gr_string( wx+5, y, items[i] );
3759 WIN(DDGRUNLOCK(dd_grd_curcanv));
3769 keyd_repeat = old_keyd_repeat;
3771 WIN (DDGRLOCK(dd_grd_curcanv));
3772 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3773 WIN (DDGRUNLOCK(dd_grd_curcanv));
3775 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3776 gr_free_bitmap(bg.background);
3780 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3781 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3783 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3784 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3790 WIN(mouse_set_mode(1)); //re-enable centering mode
3795 int newmenu_filelist( char * title, char * filespec, char * filename )
3798 char * Filenames[MAX_FILES];
3799 char FilenameText[MAX_FILES][14];
3800 FILEFINDSTRUCT find;
3803 if( !FileFindFirst( filespec, &find ) ) {
3805 if (NumFiles<MAX_FILES) {
3806 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3807 Filenames[NumFiles] = FilenameText[NumFiles];
3812 } while( !FileFindNext( &find ) );
3816 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3818 strcpy( filename, Filenames[i] );
3824 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3825 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3831 char nm_text[MESSAGEBOX_TEXT_SIZE];
3832 newmenu_item nm_message_items[5];
3834 va_start(args, nchoices );
3836 Assert( nchoices <= 5 );
3838 for (i=0; i<nchoices; i++ ) {
3839 s = va_arg( args, char * );
3840 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3842 format = va_arg( args, char * );
3843 //sprintf( nm_text, "" ); // adb: ?
3844 vsprintf(nm_text,format,args);
3847 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3849 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3851 //end this section addition - Victor Rachels
3854 extern netgame_info Active_games[];
3855 extern int NumActiveNetgames;
3857 void show_extra_netgame_info(int choice)
3863 if (choice>=NumActiveNetgames)
3868 m[i].text=(char *)&mtext[i];
3869 m[i].type=NM_TYPE_TEXT;
3872 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3873 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3874 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3875 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3877 already_showing_info=1;
3878 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3879 already_showing_info=0;
3884 /* Spiffy word wrap string formatting function */
3886 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3892 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3895 wordptr = strtok(tbuf, " ");
3896 if (!wordptr) return;
3902 col = col+strlen(wordptr)+1;
3903 if (col >=line_length) {
3905 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3908 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3910 wordptr = strtok(NULL, " ");