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.
17 * FIXME: put description here
37 #include "pa_enabl.h" //$$POLY_ACC
84 #define MAXDISPLAYABLEITEMS 15
86 #define LHX(x) ((x)*(MenuHires?2:1))
87 #define LHY(y) ((y)*(MenuHires?2.4:1))
89 #define TITLE_FONT HUGE_FONT
90 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
91 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
92 #define SUBTITLE_FONT MEDIUM3_FONT
94 #define NORMAL_CHECK_BOX "
\81"
95 #define CHECKED_CHECK_BOX "
\82"
97 #define NORMAL_RADIO_BOX "
\7f"
98 #define CHECKED_RADIO_BOX "
\80"
99 #define CURSOR_STRING "_"
100 #define SLIDER_LEFT "
\83" // 131
101 #define SLIDER_RIGHT "
\84" // 132
102 #define SLIDER_MIDDLE "
\85" // 133
103 #define SLIDER_MARKER "
\86" // 134
104 #define UP_ARROW_MARKER "
\87" // 135
105 #define DOWN_ARROW_MARKER "
\88" // 136
107 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 );
108 void show_extra_netgame_info(int choice);
111 int Newmenu_first_time = 1;
112 //--unused-- int Newmenu_fade_in = 1;
115 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
116 grs_bitmap * saved; // The background under the menu.
117 grs_bitmap * background;
120 grs_bitmap nm_background,nm_background_save;
122 #define MESSAGEBOX_TEXT_SIZE 300 // How many characters in messagebox
123 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
125 extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
127 ubyte MenuReordering=0;
129 char Pauseable_menu=0;
130 char already_showing_info=0;
133 void newmenu_close() {
134 if ( nm_background.bm_data )
135 d_free(nm_background.bm_data);
137 if ( nm_background_save.bm_data )
138 d_free(nm_background_save.bm_data);
139 Newmenu_first_time = 1;
142 ubyte background_palette[768];
144 //should be called whenever the palette changes
145 void nm_remap_background()
147 if (!Newmenu_first_time) {
148 if (!nm_background.bm_data)
149 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
151 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
153 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
159 extern char last_palette_loaded[];
161 void nm_draw_background1(char * filename)
167 //@@//I think this only gets called to fill the whole screen
168 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
169 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
172 bmp = gr_create_bitmap(320,200); //high res pcx not available
174 bmp = gr_create_bitmap(grd_curcanv->cv_bitmap.bm_w,grd_curcanv->cv_bitmap.bm_h);
177 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
178 Assert(pcx_error == PCX_ERROR_NONE);
180 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
183 { //remap stuff. this code is kindof a hack
185 //now, before we bring up the menu, we need to
186 //do some stuff to make sure the palette is ok. First, we need to
187 //get our current palette into the 2d's array, so the remapping will
188 //work. Second, we need to remap the fonts. Third, we need to fill
189 //in part of the fade tables so the darkening of the menu edges works
191 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
192 remap_fonts_and_menus(1);
196 WIN(DDGRLOCK(dd_grd_curcanv));
197 #if defined(POLY_ACC)
199 pa_update_clut(gr_palette, 0, 256, 0);
202 #if defined(POLY_ACC)
205 WIN(DDGRUNLOCK(dd_grd_curcanv));
209 strcpy(last_palette_loaded,""); //force palette load next time
213 #define MENU_BACKGROUND_BITMAP ((MenuHires && cfexist("scoresb.pcx"))?"scoresb.pcx":"scores.pcx")
215 int Background_hires;
218 void nm_draw_background(int x1, int y1, int x2, int y2 )
222 if (Newmenu_first_time || MenuHires!=Background_hires) {
225 if (Newmenu_first_time) {
226 atexit( newmenu_close );
227 Newmenu_first_time = 0;
228 nm_background_save.bm_data=NULL;
231 if (nm_background_save.bm_data)
232 d_free(nm_background_save.bm_data);
233 if (nm_background.bm_data)
234 d_free(nm_background.bm_data);
237 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
238 Assert(pcx_error == PCX_ERROR_NONE);
240 nm_background = nm_background_save;
241 nm_background.bm_data=NULL;
242 nm_remap_background();
244 Background_hires = MenuHires;
247 if ( x1 < 0 ) x1 = 0;
248 if ( y1 < 0 ) y1 = 0;
253 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
254 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
260 grs_bitmap *tmp = gr_create_bitmap(w, h);
262 gr_bitmap_scale_to(&nm_background, tmp);
264 WIN(DDGRLOCK(dd_grd_curcanv));
266 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
268 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
273 Gr_scanline_darkening_level = 2*7;
275 gr_setcolor( BM_XRGB(0,0,0) );
276 gr_urect( x2-5, y1+5, x2-5, y2-5 );
277 gr_urect( x2-4, y1+4, x2-4, y2-5 );
278 gr_urect( x2-3, y1+3, x2-3, y2-5 );
279 gr_urect( x2-2, y1+2, x2-2, y2-5 );
280 gr_urect( x2-1, y1+1, x2-1, y2-5 );
281 gr_urect( x2+0, y1+0, x2-0, y2-5 );
283 gr_urect( x1+5, y2-5, x2, y2-5 );
284 gr_urect( x1+4, y2-4, x2, y2-4 );
285 gr_urect( x1+3, y2-3, x2, y2-3 );
286 gr_urect( x1+2, y2-2, x2, y2-2 );
287 gr_urect( x1+1, y2-1, x2, y2-1 );
288 gr_urect( x1+0, y2, x2, y2-0 );
290 WIN(DDGRUNLOCK(dd_grd_curcanv));
292 Gr_scanline_darkening_level = GR_FADE_LEVELS;
295 void nm_restore_background( int x, int y, int w, int h )
302 if ( x1 < 0 ) x1 = 0;
303 if ( y1 < 0 ) y1 = 0;
305 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
306 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
311 WIN(DDGRLOCK(dd_grd_curcanv));
312 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
313 WIN(DDGRUNLOCK(dd_grd_curcanv));
316 // Draw a left justfied string
317 void nm_string( bkg * b, int w1,int x, int y, char * s)
319 int w,h,aw,tx=0,t=0,i;
320 char *p,*s1,*s2,measure[2];
321 int XTabs[]={15,87,124,162,228,253};
327 XTabs[i]=(LHX(XTabs[i]));
334 p = strchr( s2, '\t' );
341 gr_get_string_size(s2, &w, &h, &aw );
347 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
348 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
351 for (i=0;i<strlen(s2);i++) {
352 if (s2[i]=='\t' && SurfingNet) {
358 gr_get_string_size(measure,&tx,&h,&aw);
359 gr_string(x,y,measure);
366 if (!SurfingNet && p && (w1>0) ) {
367 gr_get_string_size(s1, &w, &h, &aw );
369 gr_string( x+w1-w, y, s1 );
376 // Draw a slider and it's string
377 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
384 p = strchr( s, '\t' );
390 gr_get_string_size(s, &w, &h, &aw );
393 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
394 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
396 gr_string( x, y, s );
399 gr_get_string_size(s1, &w, &h, &aw );
402 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
404 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
406 gr_string( x+w1-w, y, s1 );
413 // Draw a left justfied string with black background.
414 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
417 gr_get_string_size(s, &w, &h, &aw );
421 WIN(DDGRLOCK(dd_grd_curcanv));
422 gr_setcolor( BM_XRGB(2,2,2) );
423 gr_rect( x-1, y-1, x-1, y+h-1 );
424 gr_rect( x-1, y-1, x+w1-1, y-1 );
427 gr_setcolor( BM_XRGB(5,5,5) );
428 gr_rect( x, y+h, x+w1, y+h);
429 gr_rect( x+w1, y-1, x+w1, y+h );
431 gr_setcolor( BM_XRGB(0,0,0) );
432 gr_rect( x, y, x+w1-1, y+h-1 );
434 gr_string( x+1, y+1, s );
435 WIN(DDGRUNLOCK(dd_grd_curcanv));
439 // Draw a right justfied string
440 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
443 gr_get_string_size(s, &w, &h, &aw );
448 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
451 WIN(DDGRLOCK(dd_grd_curcanv));
452 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
453 gr_string( x-w, y, s );
454 WIN(DDGRUNLOCK(dd_grd_curcanv));
459 //for text items, constantly redraw cursor (to achieve flash)
460 void update_cursor( newmenu_item *item)
463 fix time = timer_get_approx_seconds();
465 char * text = item->text;
467 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
470 gr_get_string_size(text, &w, &h, &aw );
471 if ( w > item->w-10 )
478 x = item->x+w; y = item->y;
480 WIN(DDGRLOCK(dd_grd_curcanv));
482 gr_string( x, y, CURSOR_STRING );
484 gr_setcolor( BM_XRGB(0,0,0) );
485 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
487 WIN(DDGRUNLOCK(dd_grd_curcanv));
490 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
495 gr_get_string_size(text, &w1, &h1, &aw );
504 nm_string_black( b, w, x, y, text );
507 gr_string( x+w1+1, y, CURSOR_STRING );
511 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
516 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
518 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
520 if (item->text[0]=='\t')
521 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
526 grd_curcanv->cv_font = SELECTED_FONT;
528 grd_curcanv->cv_font = NORMAL_FONT;
531 if (is_current && item->type == NM_TYPE_TEXT)
532 grd_curcanv->cv_font = NORMAL_FONT;
536 WIN(DDGRLOCK(dd_grd_curcanv));
537 switch( item->type ) {
539 // grd_curcanv->cv_font=TEXT_FONT;
540 // fall through on purpose
543 nm_string( b, item->w, item->x, item->y, item->text );
545 case NM_TYPE_SLIDER: {
547 if (item->value < item->min_value) item->value=item->min_value;
548 if (item->value > item->max_value) item->value=item->max_value;
549 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
550 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
551 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
553 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
555 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
557 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
560 case NM_TYPE_INPUT_MENU:
561 if ( item->group==0 ) {
562 nm_string( b, item->w, item->x, item->y, item->text );
564 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
568 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
571 nm_string( b, item->w, item->x, item->y, item->text );
573 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
575 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
578 nm_string( b, item->w, item->x, item->y, item->text );
580 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
582 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
584 case NM_TYPE_NUMBER: {
586 if (item->value < item->min_value) item->value=item->min_value;
587 if (item->value > item->max_value) item->value=item->max_value;
588 nm_string( b, item->w, item->x, item->y, item->text );
589 sprintf( text, "%d", item->value );
590 nm_rstring( b,item->right_offset,item->x, item->y, text );
594 WIN(DDGRUNLOCK(dd_grd_curcanv));
598 char *Newmenu_allowed_chars=NULL;
600 //returns true if char is allowed
601 int char_allowed(char c)
603 char *p = Newmenu_allowed_chars;
611 if (c>=p[0] && c<=p[1])
620 void strip_end_whitespace( char * text )
624 for (i=l-1; i>=0; i-- ) {
625 if ( isspace(text[i]) )
632 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
634 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
636 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
638 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
642 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
644 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
648 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 )
650 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
654 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 )
656 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
658 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 )
660 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
663 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){
664 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
665 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
666 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
669 //returns 1 if a control device button has been pressed
670 int check_button_press()
674 switch (Config_control_type) {
675 case CONTROL_JOYSTICK:
676 case CONTROL_FLIGHTSTICK_PRO:
677 case CONTROL_THRUSTMASTER_FCS:
678 case CONTROL_GRAVIS_GAMEPAD:
680 if (joy_get_button_down_cnt(i)>0) return 1;
683 case CONTROL_CYBERMAN:
684 #ifndef MACINTOSH // don't allow mouse to continue from menu
686 if (mouse_button_down_count(i)>0) return 1;
689 case CONTROL_WINJOYSTICK:
692 if (joy_get_button_down_cnt(i)>0) return 1;
695 case CONTROL_NONE: //keyboard only
697 if (key_checkch()) return 1;
702 Error("Bad control type (Config_control_type):%i",Config_control_type);
708 extern int network_request_player_names(int);
709 extern int RestoringMenu;
711 #if defined(WINDOWS) || defined(MACINTOSH)
712 ubyte Hack_DblClick_MenuMode=0;
715 MAC(extern ubyte joydefs_calibrating;)
719 #define CLOSE_SIZE 10
721 void draw_close_box(int x,int y)
723 WIN (DDGRLOCK(dd_grd_curcanv));
724 gr_setcolor( BM_XRGB(0, 0, 0) );
725 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
726 gr_setcolor( BM_XRGB(21, 21, 21) );
727 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
728 WIN (DDGRUNLOCK(dd_grd_curcanv));
731 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 )
733 int old_keyd_repeat, done;
734 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
735 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
736 grs_font * save_font;
737 int string_width, string_height, average_width;
740 int all_text=0; //set true if all text items
741 int sound_stopped=0,time_stopped=0;
742 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
745 int MaxOnMenu=MAXDISPLAYABLEITEMS;
746 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
747 #if defined(MACINTOSH) || defined(WINDOWS)
748 int mouse_state, omouse_state, dblclick_flag=0;
749 int mx=0, my=0, x1, x2, y1, y2;
753 EventRecord event; // looking for disk inserted events for CD mounts
756 PA_DFX (pa_set_frontbuffer_current());
757 PA_DFX (pa_set_front_to_read());
759 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
768 WIN(mouse_set_mode(0)); //disable centering mode
770 MaxDisplayable=nitems;
773 set_screen_mode(SCREEN_MENU);
777 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
778 digi_pause_digi_sounds();
782 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
795 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
797 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
799 save_font = grd_curcanv->cv_font;
804 grd_curcanv->cv_font = TITLE_FONT;
805 gr_get_string_size(title,&string_width,&string_height,&average_width );
810 grd_curcanv->cv_font = SUBTITLE_FONT;
811 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
812 if (string_width > tw )
817 th += LHY(8); //put some space between titles & body
820 grd_curcanv->cv_font = SMALL_FONT;
822 grd_curcanv->cv_font = NORMAL_FONT;
826 nmenus = nothers = 0;
828 // Find menu height & width (store in w,h)
829 for (i=0; i<nitems; i++ ) {
832 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
833 item[i].right_offset = 0;
836 string_height+=LHY(3);
838 item[i].saved_text[0] = '\0';
840 if ( item[i].type == NM_TYPE_SLIDER ) {
843 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
844 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
845 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
847 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
848 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
849 string_width += w1 + aw;
852 if ( item[i].type == NM_TYPE_MENU ) {
856 if ( item[i].type == NM_TYPE_CHECK ) {
859 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
860 item[i].right_offset = w1;
861 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
862 if (w1 > item[i].right_offset)
863 item[i].right_offset = w1;
866 if (item[i].type == NM_TYPE_RADIO ) {
869 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
870 item[i].right_offset = w1;
871 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
872 if (w1 > item[i].right_offset)
873 item[i].right_offset = w1;
876 if (item[i].type==NM_TYPE_NUMBER ) {
880 sprintf( test_text, "%d", item[i].max_value );
881 gr_get_string_size( test_text, &w1, &h1, &aw1 );
882 item[i].right_offset = w1;
883 sprintf( test_text, "%d", item[i].min_value );
884 gr_get_string_size( test_text, &w1, &h1, &aw1 );
885 if ( w1 > item[i].right_offset)
886 item[i].right_offset = w1;
889 if ( item[i].type == NM_TYPE_INPUT ) {
890 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
891 strcpy(item[i].saved_text, item[i].text );
893 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
894 if ( string_width > MAX_TEXT_WIDTH )
895 string_width = MAX_TEXT_WIDTH;
899 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
900 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
901 strcpy(item[i].saved_text, item[i].text );
903 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
908 item[i].w = string_width;
909 item[i].h = string_height;
911 if ( string_width > w )
912 w = string_width; // Save maximum width
913 if ( average_width > aw )
915 h += string_height+1; // Find the height of all strings
918 // Big hack for allowing the netgame options menu to spill over
920 MaxOnMenu=MAXDISPLAYABLEITEMS;
921 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
924 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
927 h=(MaxOnMenu*(string_height+1)+LHY(8));
928 MaxDisplayable=MaxOnMenu;
929 mprintf ((0,"Hey, this is a scroll box!\n"));
942 for (i=0; i<nitems; i++ ) {
944 if (item[i].right_offset > right_offset )
945 right_offset = item[i].right_offset;
947 if (right_offset > 0 )
950 //gr_get_string_size("",&string_width,&string_height,&average_width );
957 twidth = ( tw - w )/2;
962 { right_offset=0; twidth=0;}
964 mprintf(( 0, "Right offset = %d\n", right_offset ));
967 // Find min point of menu border
968 // x = (grd_curscreen->sc_w-w)/2;
969 // y = (grd_curscreen->sc_h-h)/2;
971 w += MenuHires?60:30;
972 h += MenuHires?60:30;
974 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
975 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
977 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
978 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
983 if ( filename != NULL ) {
984 nm_draw_background1( filename );
985 gr_palette_load(gr_palette);
988 // Save the background of the display
989 // Win95 must refer to the screen as a dd_grs_canvas, so...
990 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
991 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
993 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
994 gr_set_current_canvas(bg.menu_canvas) );
996 if ( filename == NULL ) {
997 // Save the background under the menu...
1003 #if defined(POLY_ACC)
1004 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1006 bg.saved = gr_create_bitmap( w, h );
1008 Assert( bg.saved != NULL );
1010 WIN (DDGRLOCK(dd_grd_curcanv));
1011 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1012 WIN (DDGRUNLOCK(dd_grd_curcanv));
1014 WINDOS ( dd_gr_set_current_canvas(NULL),
1015 gr_set_current_canvas( NULL )
1018 nm_draw_background(x,y,x+w-1,y+h-1);
1020 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1021 gr_set_current_canvas( bg.menu_canvas )
1024 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1028 #if defined(POLY_ACC)
1029 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1031 bg.background = gr_create_bitmap( w, h );
1033 Assert( bg.background != NULL );
1035 WIN (DDGRLOCK(dd_grd_curcanv));
1036 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1037 WIN (DDGRUNLOCK(dd_grd_curcanv));
1040 // ty = 15 + (yborder/4);
1042 ty = MenuHires?30:15;
1045 grd_curcanv->cv_font = TITLE_FONT;
1046 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1047 gr_get_string_size(title,&string_width,&string_height,&average_width );
1050 WIN (DDGRLOCK(dd_grd_curcanv));
1051 gr_printf( 0x8000, ty, title );
1052 WIN (DDGRUNLOCK(dd_grd_curcanv));
1057 grd_curcanv->cv_font = SUBTITLE_FONT;
1058 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1059 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1062 WIN (DDGRLOCK(dd_grd_curcanv));
1063 gr_printf( 0x8000, ty, subtitle );
1064 WIN (DDGRUNLOCK(dd_grd_curcanv));
1069 grd_curcanv->cv_font = SMALL_FONT;
1071 grd_curcanv->cv_font = NORMAL_FONT;
1073 // Update all item's x & y values.
1074 for (i=0; i<nitems; i++ ) {
1075 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1076 item[i].y += (MenuHires?30:15);
1077 if ( item[i].type==NM_TYPE_RADIO ) {
1078 fm = -1; // find first marked one
1079 for ( j=0; j<nitems; j++ ) {
1080 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1081 if (fm==-1 && item[j].value)
1093 old_keyd_repeat = keyd_repeat;
1099 if (citem < 0 ) citem = 0;
1100 if (citem > nitems-1 ) citem = nitems-1;
1103 #if defined(WINDOWS) || defined(MACINTOSH)
1107 while ( item[choice].type==NM_TYPE_TEXT ) {
1109 if (choice >= nitems ) {
1112 if (choice == citem ) {
1123 // Clear mouse, joystick to clear button presses.
1124 game_flush_inputs();
1126 #if defined(WINDOWS) || defined(MACINTOSH)
1127 mouse_state = omouse_state = 0;
1128 if (filename == NULL && !MenuReordering) {
1129 draw_close_box(0,0);
1135 if (!MenuReordering) {
1137 SetCursor (LoadCursor(NULL,IDC_ARROW));
1142 if (!joydefs_calibrating)
1146 mprintf ((0,"Set to true!\n"));
1152 DoMessageStuff(&msg);
1154 if (_RedrawScreen) {
1155 _RedrawScreen = FALSE;
1158 gr_free_bitmap(bg.saved);
1159 d_free( bg.background );
1162 gr_free_bitmap(bg.background);
1164 dd_gr_free_sub_canvas( bg.menu_canvas );
1165 grd_curcanv->cv_font = save_font;
1166 dd_grd_curcanv = save_canvas;
1168 goto RePaintNewmenu4;
1177 omouse_state = mouse_state;
1178 mouse_state = mouse_button_state(0);
1179 if (!joydefs_calibrating)
1180 show_cursor(); // possibly hidden
1184 omouse_state = mouse_state;
1185 if (!MenuReordering)
1186 mouse_state = mouse_button_state(0);
1187 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1190 //see if redbook song needs to be restarted
1191 songs_check_redbook_repeat();
1198 (*subfunction)(nitems,item,&k,choice);
1201 if (!time_stopped) {
1202 // Save current menu box
1203 if (multi_menu_poll() == -1)
1209 dont_restore = (k == -3); //-3 means don't restore
1215 if (check_button_press())
1219 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1222 old_choice = choice;
1228 if (SurfingNet && !already_showing_info)
1230 show_extra_netgame_info(choice-2);
1232 if (SurfingNet && already_showing_info)
1239 if (SurfingNet && !already_showing_info)
1241 network_request_player_names(choice-2);
1243 if (SurfingNet && already_showing_info)
1258 case KEY_TAB + KEY_SHIFTED:
1261 if (all_text) break;
1268 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1270 if (choice<TopChoice)
1271 { choice=TopChoice; break; }
1273 if (choice<ScrollOffset)
1275 for (i=0;i<nitems;i++)
1278 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1283 if (choice >= nitems ) choice=0;
1284 if (choice < 0 ) choice=nitems-1;
1286 } while ( item[choice].type==NM_TYPE_TEXT );
1287 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1288 item[choice].value = -1;
1289 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1290 item[old_choice].group=0;
1291 strcpy(item[old_choice].text, item[old_choice].saved_text );
1292 item[old_choice].value = -1;
1295 item[old_choice].redraw = 1;
1296 item[choice].redraw=1;
1301 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1302 if (all_text) break;
1309 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1312 { choice--; break; }
1314 if (choice>=MaxOnMenu+ScrollOffset)
1316 for (i=0;i<nitems;i++)
1319 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1324 if (choice < 0 ) choice=nitems-1;
1325 if (choice >= nitems ) choice=0;
1328 } while ( item[choice].type==NM_TYPE_TEXT );
1330 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1331 item[choice].value = -1;
1332 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1333 item[old_choice].group=0;
1334 strcpy(item[old_choice].text, item[old_choice].saved_text );
1335 item[old_choice].value = -1;
1338 item[old_choice].redraw=1;
1339 item[choice].redraw=1;
1342 if ( choice > -1 ) {
1343 switch( item[choice].type ) {
1346 case NM_TYPE_INPUT_MENU:
1349 if ( item[choice].value )
1350 item[choice].value = 0;
1352 item[choice].value = 1;
1353 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1356 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1358 mprintf ((0,"Special redraw!\n"));
1363 item[choice].redraw=1;
1366 for (i=0; i<nitems; i++ ) {
1367 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1372 item[choice].value = 1;
1373 item[choice].redraw = 1;
1379 case KEY_SHIFTED+KEY_UP:
1380 if (MenuReordering && choice!=TopChoice)
1382 Temp=item[choice].text;
1383 TempVal=item[choice].value;
1384 item[choice].text=item[choice-1].text;
1385 item[choice].value=item[choice-1].value;
1386 item[choice-1].text=Temp;
1387 item[choice-1].value=TempVal;
1388 item[choice].redraw=1;
1389 item[choice-1].redraw=1;
1393 case KEY_SHIFTED+KEY_DOWN:
1394 if (MenuReordering && choice!=(nitems-1))
1396 Temp=item[choice].text;
1397 TempVal=item[choice].value;
1398 item[choice].text=item[choice+1].text;
1399 item[choice].value=item[choice+1].value;
1400 item[choice+1].text=Temp;
1401 item[choice+1].value=TempVal;
1402 item[choice].redraw=1;
1403 item[choice+1].redraw=1;
1410 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1411 item[choice].group = 1;
1412 item[choice].redraw = 1;
1413 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1414 item[choice].text[0] = 0;
1415 item[choice].value = -1;
1417 strip_end_whitespace(item[choice].text);
1424 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1425 item[choice].group=0;
1426 strcpy(item[choice].text, item[choice].saved_text );
1427 item[choice].redraw=1;
1428 item[choice].value = -1;
1435 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1436 case KEY_PRINT_SCREEN:
1438 save_screen_shot(0);
1439 PA_DFX (pa_set_frontbuffer_current());
1440 PA_DFX (pa_set_front_to_read());
1441 for (i=0;i<nitems;i++)
1450 case KEY_COMMAND+KEY_RIGHT:
1451 songs_goto_next_song();
1453 case KEY_COMMAND+KEY_LEFT:
1454 songs_goto_prev_song();
1456 case KEY_COMMAND+KEY_UP:
1457 songs_play_level_song(1);
1459 case KEY_COMMAND+KEY_DOWN:
1460 songs_stop_redbook();
1463 case KEY_COMMAND+KEY_M:
1465 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1466 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1469 key_close(); // no processing of keys with keyboard handler.. jeez
1472 show_boxed_message ("Mounting CD\nESC to quit");
1473 RBAMountDisk(); // OS has totaly control of the CD.
1474 if (Function_mode == FMODE_MENU)
1475 songs_play_song(SONG_TITLE,1);
1476 else if (Function_mode == FMODE_GAME)
1477 songs_play_level_song( Current_level_num );
1478 clear_boxed_message();
1487 case KEY_COMMAND+KEY_E:
1488 songs_stop_redbook();
1490 k = -1; // force key not to register
1493 case KEY_COMMAND+KEY_Q: {
1494 extern void macintosh_quit();
1496 if ( !(Game_mode & GM_MULTI) )
1498 if (!joydefs_calibrating)
1500 k = -1; // force key not to register
1507 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1514 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1516 if ( !done && mouse_state && !omouse_state && !all_text ) {
1517 mouse_get_pos(&mx, &my);
1518 for (i=0; i<nitems; i++ ) {
1519 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1520 x2 = x1 + item[i].w;
1521 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1522 y2 = y1 + item[i].h;
1523 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1524 if (i+ScrollOffset != choice) {
1525 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1528 choice = i + ScrollOffset;
1530 switch( item[choice].type ) {
1532 if ( item[choice].value )
1533 item[choice].value = 0;
1535 item[choice].value = 1;
1536 item[choice].redraw=1;
1543 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1545 mprintf ((0,"Special redraw!\n"));
1552 for (i=0; i<nitems; i++ ) {
1553 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1558 item[choice].value = 1;
1559 item[choice].redraw = 1;
1562 item[old_choice].redraw=1;
1568 if (mouse_state && all_text)
1571 if ( !done && mouse_state && !all_text ) {
1572 mouse_get_pos(&mx, &my);
1574 // check possible scrollbar stuff first
1576 int arrow_width, arrow_height, aw;
1578 if (ScrollOffset != 0) {
1579 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1580 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1581 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1582 x1 = x1 - arrow_width;
1583 y2 = y1 + arrow_height;
1584 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1587 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1589 if (choice<ScrollOffset)
1591 for (i=0;i<nitems;i++)
1594 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1598 if (ScrollOffset+MaxDisplayable<nitems) {
1599 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1600 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1601 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1602 x1 = x1 - arrow_width;
1603 y2 = y1 + arrow_height;
1604 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1607 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1609 if (choice>=MaxOnMenu+ScrollOffset)
1611 for (i=0;i<nitems;i++)
1614 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1620 for (i=0; i<nitems; i++ ) {
1621 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1622 x2 = x1 + item[i].w;
1623 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1624 y2 = y1 + item[i].h;
1625 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1626 if (i+ScrollOffset != choice) {
1627 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1630 choice = i + ScrollOffset;
1632 if ( item[choice].type == NM_TYPE_SLIDER ) {
1633 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1634 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1636 strcpy(slider_text, item[choice].saved_text);
1637 p = strchr(slider_text, '\t');
1643 gr_get_string_size(s1, &slider_width, &height, &aw);
1644 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1645 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1646 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1648 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1649 x2 = x1 + slider_width + sright_width;
1650 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1651 item[choice].value = item[choice].min_value;
1652 item[choice].redraw = 2;
1653 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1654 item[choice].value = item[choice].max_value;
1655 item[choice].redraw = 2;
1656 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1657 int num_values, value_width, new_value;
1659 num_values = item[choice].max_value - item[choice].min_value + 1;
1660 value_width = (slider_width - sleft_width - sright_width) / num_values;
1661 new_value = (mx - x1 - sleft_width) / value_width;
1662 if ( item[choice].value != new_value ) {
1663 item[choice].value = new_value;
1664 item[choice].redraw = 2;
1670 if (choice == old_choice)
1672 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1673 item[choice].value = -1;
1674 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1675 item[old_choice].group=0;
1676 strcpy(item[old_choice].text, item[old_choice].saved_text );
1677 item[old_choice].value = -1;
1680 item[old_choice].redraw = 1;
1681 item[choice].redraw=1;
1687 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1688 mouse_get_pos(&mx, &my);
1689 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1690 x2 = x1 + item[choice].w;
1691 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1692 y2 = y1 + item[choice].h;
1693 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1694 if (Hack_DblClick_MenuMode) {
1695 if (dblclick_flag) done = 1;
1696 else dblclick_flag = 1;
1702 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1703 item[choice].group = 1;
1704 item[choice].redraw = 1;
1705 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1706 item[choice].text[0] = 0;
1707 item[choice].value = -1;
1709 strip_end_whitespace(item[choice].text);
1713 if ( !done && !mouse_state && omouse_state && close_box ) {
1714 mouse_get_pos(&mx, &my);
1715 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1716 x2 = x1 + CLOSE_SIZE;
1717 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1718 y2 = y1 + CLOSE_SIZE;
1719 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1725 // HACK! Don't redraw loadgame preview
1726 if (RestoringMenu) item[0].redraw = 0;
1727 #endif // ifdef MACINTOSH
1729 if ( choice > -1 ) {
1732 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1733 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1734 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1735 if (item[choice].value > 0)
1736 item[choice].value--;
1737 item[choice].text[item[choice].value] = 0;
1738 item[choice].redraw = 1;
1740 ascii = key_to_ascii(k);
1741 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1745 if (item[choice].value==-1) {
1746 item[choice].value = 0;
1749 allowed = char_allowed(ascii);
1751 if (!allowed && ascii==' ' && char_allowed('_')) {
1757 item[choice].text[item[choice].value++] = ascii;
1758 item[choice].text[item[choice].value] = 0;
1759 item[choice].redraw=1;
1763 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1764 ascii = key_to_ascii(k);
1766 int choice1 = choice;
1767 ascii = toupper(ascii);
1771 if (choice1 >= nitems ) choice1=0;
1772 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1773 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1774 (item[choice1].type==NM_TYPE_CHECK) ||
1775 (item[choice1].type==NM_TYPE_RADIO) ||
1776 (item[choice1].type==NM_TYPE_NUMBER) ||
1777 (item[choice1].type==NM_TYPE_SLIDER) )
1778 && (ascii==toupper(ch)) ) {
1782 item[old_choice].redraw=1;
1783 item[choice].redraw=1;
1785 } while (choice1 != choice );
1789 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1790 int ov=item[choice].value;
1795 case KEY_MINUS+KEY_SHIFTED:
1797 item[choice].value -= 1;
1802 case KEY_EQUAL+KEY_SHIFTED:
1804 item[choice].value++;
1809 item[choice].value += 10;
1814 item[choice].value -= 10;
1817 if (ov!=item[choice].value)
1818 item[choice].redraw=1;
1823 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1824 gr_set_current_canvas(bg.menu_canvas));
1826 // Redraw everything...
1827 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1829 if (item[i].redraw) // warning! ugly hack below
1831 item[i].y-=((string_height+1)*ScrollOffset);
1834 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1836 MAC(if (!joydefs_calibrating) show_cursor());
1837 WIN(if (!MenuReordering) ShowCursorW());
1838 item[i].y+=((string_height+1)*ScrollOffset);
1840 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1841 update_cursor( &item[i]);
1847 //grd_curcanv->cv_font = NORMAL_FONT;
1849 if (LastScrollCheck!=ScrollOffset)
1851 LastScrollCheck=ScrollOffset;
1852 grd_curcanv->cv_font = SELECTED_FONT;
1854 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1855 sx=item[ScrollOffset].x-(MenuHires?24:12);
1858 if (ScrollOffset!=0)
1859 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1861 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1863 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1864 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1866 if (ScrollOffset+MaxDisplayable<nitems)
1867 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1869 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1875 if ( !dont_restore && gr_palette_faded_out ) {
1876 gr_palette_fade_in( gr_palette, 32, 0 );
1883 // Restore everything...
1885 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1886 gr_set_current_canvas(bg.menu_canvas));
1888 if ( filename == NULL ) {
1889 // Save the background under the menu...
1890 WIN (DDGRLOCK(dd_grd_curcanv));
1891 gr_bitmap(0, 0, bg.saved);
1892 WIN (DDGRUNLOCK(dd_grd_curcanv));
1893 gr_free_bitmap(bg.saved);
1894 d_free( bg.background );
1896 if (!dont_restore) //info passed back from subfunction
1898 WIN (DDGRLOCK(dd_grd_curcanv));
1899 gr_bitmap(0, 0, bg.background);
1900 WIN (DDGRUNLOCK(dd_grd_curcanv));
1902 gr_free_bitmap(bg.background);
1905 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1906 gr_free_sub_canvas( bg.menu_canvas ) );
1908 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1909 grd_curcanv->cv_font = save_font;
1910 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1911 keyd_repeat = old_keyd_repeat;
1913 game_flush_inputs();
1924 if ( sound_stopped )
1925 digi_resume_digi_sounds();
1927 WIN(mouse_set_mode(1)); //re-enable centering mode
1934 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1940 char nm_text[MESSAGEBOX_TEXT_SIZE];
1941 newmenu_item nm_message_items[5];
1943 va_start(args, nchoices );
1945 Assert( nchoices <= 5 );
1947 for (i=0; i<nchoices; i++ ) {
1948 s = va_arg( args, char * );
1949 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1951 format = va_arg( args, char * );
1952 strcpy( nm_text, "" );
1953 vsprintf(nm_text,format,args);
1956 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1958 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1961 int nm_messagebox( char *title, int nchoices, ... )
1967 char nm_text[MESSAGEBOX_TEXT_SIZE];
1968 newmenu_item nm_message_items[5];
1970 va_start(args, nchoices );
1972 Assert( nchoices <= 5 );
1974 for (i=0; i<nchoices; i++ ) {
1975 s = va_arg( args, char * );
1976 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1978 format = va_arg( args, char * );
1979 strcpy( nm_text, "" );
1980 vsprintf(nm_text,format,args);
1983 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1985 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1991 void newmenu_file_sort( int n, char *list )
1998 for (i=incr; i<n; i++ ) {
2001 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
2002 memcpy( t, &list[j*14], FILENAME_LEN );
2003 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
2004 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2015 void delete_player_saved_games(char * name)
2020 for (i=0;i<10; i++) {
2022 sprintf( filename, "%s.sg%d", name, i );
2024 sprintf( filename, ":Players:%s.sg%d", name, i );
2030 #define MAX_FILES 300
2032 int MakeNewPlayerFile(int allow_abort);
2034 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2037 FILEFINDSTRUCT find;
2038 int NumFiles=0, key,done, citem, ocitem;
2039 char * filenames = NULL;
2040 int NumFiles_displayed = 8;
2041 int first_item = -1, ofirst_item;
2042 int old_keyd_repeat = keyd_repeat;
2045 int demos_deleted=0;
2046 int initialized = 0;
2048 int w_x, w_y, w_w, w_h, title_height;
2049 int box_x, box_y, box_w, box_h;
2050 bkg bg; // background under listbox
2051 #if defined(MACINTOSH) || defined(WINDOWS)
2052 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2053 int mouse2_state, omouse2_state;
2054 int dblclick_flag=0;
2056 int show_up_arrow=0,show_down_arrow=0;
2058 WIN(int win_redraw=0);
2060 w_x=w_y=w_w=w_h=title_height=0;
2061 box_x=box_y=box_w=box_h=0;
2063 filenames = d_malloc( MAX_FILES * 14 );
2064 if (filenames==NULL) return 0;
2069 WIN(mouse_set_mode(0)); //disable centering mode
2071 if (strstr( filespec, "*.plr" ))
2073 else if (strstr( filespec, "*.dem" ))
2080 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2082 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2087 if( !FileFindFirst( filespec, &find ) ) {
2089 if (NumFiles<MAX_FILES) {
2090 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2091 if ( player_mode ) {
2093 p = strchr(&filenames[NumFiles*14],'.');
2100 } while( !FileFindNext( &find ) );
2104 if ( (NumFiles < 1) && demos_deleted ) {
2108 if ( (NumFiles < 1) && demo_mode ) {
2109 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2115 if ( (NumFiles < 2) && player_mode ) {
2117 goto ExitFileMenuEarly;
2124 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2131 // set_screen_mode(SCREEN_MENU);
2137 dd_gr_set_current_canvas(NULL);
2139 gr_set_current_canvas(NULL);
2142 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2144 grd_curcanv->cv_font = SUBTITLE_FONT;
2146 WIN(DDGRUNLOCK(dd_grd_curcanv));
2151 for (i=0; i<NumFiles; i++ ) {
2153 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2159 gr_get_string_size( title, &w, &h, &aw );
2162 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2166 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2168 w_w += (grd_curfont->ft_w * 4);
2169 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2171 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2172 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2174 w_x = (grd_curcanv->cv_w-w_w)/2;
2175 w_y = (grd_curcanv->cv_h-w_h)/2;
2177 if ( w_x < 0 ) w_x = 0;
2178 if ( w_y < 0 ) w_y = 0;
2180 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2181 box_y = w_y + title_height;
2183 // save the screen behind the menu.
2187 #if !defined(WINDOWS)
2188 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2189 bg.background = &VR_offscreen_buffer->cv_bitmap;
2192 #if defined(POLY_ACC)
2193 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2195 bg.background = gr_create_bitmap( w_w, w_h );
2198 Assert( bg.background != NULL );
2201 WIN(DDGRLOCK(dd_grd_curcanv));
2202 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2203 WIN(DDGRUNLOCK(dd_grd_curcanv));
2207 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2208 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2209 dd_VR_offscreen_buffer, 0, 0,
2210 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2211 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2215 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2217 WIN(DDGRLOCK(dd_grd_curcanv))
2219 gr_string( 0x8000, w_y+10, title );
2221 WIN(DDGRUNLOCK(dd_grd_curcanv));
2228 if ( !player_mode ) {
2229 newmenu_file_sort( NumFiles, filenames );
2231 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2232 newmenu_file_sort( NumFiles, filenames );
2234 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2236 for ( i=0; i<NumFiles; i++ ) {
2237 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2238 #if defined(WINDOWS) || defined(MACINTOSH)
2246 #if defined(MACINTOSH) || defined(WINDOWS)
2247 mouse_state = omouse_state = 0;
2248 mouse2_state = omouse2_state = 0;
2249 draw_close_box(w_x,w_y);
2261 DoMessageStuff(&msg);
2263 if (_RedrawScreen) {
2264 _RedrawScreen = FALSE;
2266 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2267 gr_free_bitmap(bg.background);
2270 goto RePaintNewmenuFile;
2277 ofirst_item = first_item;
2280 #if defined(MACINTOSH) || defined(WINDOWS)
2281 omouse_state = mouse_state;
2282 omouse2_state = mouse2_state;
2283 mouse_state = mouse_button_state(0);
2284 mouse2_state = mouse_button_state(1);
2287 //see if redbook song needs to be restarted
2288 songs_check_redbook_repeat();
2291 if (!mouse2_state && omouse2_state)
2292 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2295 //NOTE LINK TO ABOVE ELSE
2301 else if (simukey==1)
2307 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2308 case KEY_PRINT_SCREEN:
2310 save_screen_shot(0);
2311 PA_DFX (pa_set_frontbuffer_current());
2312 PA_DFX (pa_set_front_to_read());
2318 case KEY_CTRLED+KEY_D:
2319 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2323 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2327 mouse_set_mode(1); //re-enable centering mode
2331 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2333 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2336 mouse_set_mode(0); //disenable centering mode
2342 char name[_MAX_PATH],dir[_MAX_DIR];
2344 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2348 _splitpath(filespec,name,dir,NULL,NULL);
2350 strcat(name,&filenames[citem*14]);
2357 if ( !strncmp(name, ".\\", 2) )
2358 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2359 name[i] = name[i+1];
2360 while ( (p = strchr(name, '\\')) )
2365 ret = unlink( name );
2369 if ((!ret) && player_mode) {
2370 delete_player_saved_games( &filenames[citem*14] );
2375 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2377 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2378 } else if (demo_mode)
2403 citem += NumFiles_displayed;
2407 citem -= NumFiles_displayed;
2410 if (allow_abort_flag) {
2421 case KEY_COMMAND+KEY_Q: {
2422 extern void macintosh_quit();
2424 if ( !(Game_mode & GM_MULTI) )
2435 int ascii = key_to_ascii(key);
2436 if ( ascii < 255 ) {
2439 if (cc1 < 0 ) cc1 = 0;
2440 if (cc1 >= NumFiles ) cc1 = 0;
2442 if ( cc < 0 ) cc = 0;
2443 if ( cc >= NumFiles ) cc = 0;
2444 if ( citem == cc ) break;
2446 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2461 if (citem>=NumFiles)
2464 if (citem< first_item)
2467 if (citem>=( first_item+NumFiles_displayed))
2469 first_item = citem-NumFiles_displayed+1;
2473 if (NumFiles>first_item+NumFiles_displayed)
2484 if (NumFiles <= NumFiles_displayed )
2487 if (first_item>NumFiles-NumFiles_displayed)
2489 first_item = NumFiles-NumFiles_displayed;
2492 if (first_item < 0 ) first_item = 0;
2494 #if defined(MACINTOSH) || defined(WINDOWS)
2496 if (mouse_state || mouse2_state) {
2499 mouse_get_pos(&mx, &my);
2500 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2501 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2503 x2 = box_x + box_w - 1;
2504 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2506 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2507 if (i == citem && !mouse2_state) {
2517 if (!mouse_state && omouse_state) {
2520 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2521 mouse_get_pos(&mx, &my);
2523 x2 = box_x + box_w - 1;
2524 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2526 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2527 if (dblclick_flag) done = 1;
2528 else dblclick_flag = 1;
2532 if ( !mouse_state && omouse_state ) {
2533 mouse_get_pos(&mx, &my);
2534 x1 = w_x + CLOSE_X + 2;
2535 x2 = x1 + CLOSE_SIZE - 2;
2536 y1 = w_y + CLOSE_Y + 2;
2537 y2 = y1 + CLOSE_SIZE - 2;
2538 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2547 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2549 y1 = box_y+box_h-LHY(7);
2551 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2558 WIN(DDGRLOCK(dd_grd_curcanv));
2559 gr_setcolor( BM_XRGB(2,2,2));
2560 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2561 gr_setcolor( BM_XRGB( 0,0,0) );
2564 if (ofirst_item != first_item || win_redraw) {
2567 if (ofirst_item != first_item) {
2571 gr_setcolor( BM_XRGB( 0,0,0) );
2572 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2574 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2576 if ( i >= NumFiles ) {
2578 gr_setcolor( BM_XRGB(5,5,5));
2579 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2580 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2582 gr_setcolor( BM_XRGB(2,2,2));
2583 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2585 gr_setcolor( BM_XRGB(0,0,0));
2586 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2590 grd_curcanv->cv_font = SELECTED_FONT;
2592 grd_curcanv->cv_font = NORMAL_FONT;
2593 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2595 gr_setcolor( BM_XRGB(5,5,5));
2596 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2597 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2599 gr_setcolor( BM_XRGB(2,2,2));
2600 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2601 gr_setcolor( BM_XRGB(0,0,0));
2603 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2604 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2609 } else if ( citem != ocitem ) {
2615 if ( (i>=0) && (i<NumFiles) ) {
2616 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2618 grd_curcanv->cv_font = SELECTED_FONT;
2620 grd_curcanv->cv_font = NORMAL_FONT;
2621 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2622 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2623 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2626 if ( (i>=0) && (i<NumFiles) ) {
2627 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2629 grd_curcanv->cv_font = SELECTED_FONT;
2631 grd_curcanv->cv_font = NORMAL_FONT;
2632 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2633 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2634 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2641 grd_curcanv->cv_font = NORMAL_FONT;
2643 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2647 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2651 if (show_down_arrow)
2652 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2656 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2664 WIN(DDGRUNLOCK(dd_grd_curcanv));
2670 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2677 keyd_repeat = old_keyd_repeat;
2679 if ( initialized ) {
2680 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2682 WIN (DDGRLOCK(dd_grd_curcanv));
2683 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2684 WIN (DDGRUNLOCK(dd_grd_curcanv));
2686 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2687 gr_free_bitmap(bg.background);
2690 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2691 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2693 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2694 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2704 WIN(mouse_set_mode(1)); //re-enable centering mode
2712 // Example listbox callback function...
2713 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2717 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2718 // if ( *nitems > 1 ) {
2719 // unlink( items[*citem] ); // Delete the file
2720 // for (i=*citem; i<*nitems-1; i++ ) {
2721 // items[i] = items[i+1];
2723 // *nitems = *nitems - 1;
2724 // d_free( items[*nitems] );
2725 // items[*nitems] = NULL;
2726 // return 1; // redraw;
2733 #define LB_ITEMS_ON_SCREEN 8
2735 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2737 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2740 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 ) )
2743 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2744 int old_keyd_repeat = keyd_repeat;
2745 int width, height, wx, wy, title_height, border_size;
2746 int total_width,total_height;
2748 #if defined(MACINTOSH) || defined(WINDOWS)
2749 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2750 int close_x,close_y;
2751 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2753 WIN(int win_redraw=0);
2757 PA_DFX (pa_set_frontbuffer_current());
2758 PA_DFX (pa_set_front_to_read());
2759 WIN(mouse_set_mode(0)); //disable centering mode
2761 // set_screen_mode(SCREEN_MENU);
2765 RePaintNewmenuListbox:
2767 dd_gr_set_current_canvas(NULL);
2769 gr_set_current_canvas(NULL);
2772 grd_curcanv->cv_font = SUBTITLE_FONT;
2775 for (i=0; i<nitems; i++ ) {
2777 gr_get_string_size( items[i], &w, &h, &aw );
2781 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2785 gr_get_string_size( title, &w, &h, &aw );
2788 title_height = h + 5;
2791 border_size = grd_curfont->ft_w;
2792 WIN (border_size=grd_curfont->ft_w*2);
2794 width += (grd_curfont->ft_w);
2795 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2796 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2798 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2799 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2800 if ( wy < title_height )
2803 total_width = width+2*border_size;
2804 total_height = height+2*border_size+title_height;
2808 #if !defined(WINDOWS)
2809 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2810 bg.background = &VR_offscreen_buffer->cv_bitmap;
2813 //bg.background = gr_create_bitmap( width, (height + title_height) );
2814 #if defined(POLY_ACC)
2815 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2817 bg.background = gr_create_bitmap(total_width,total_height);
2819 Assert( bg.background != NULL );
2821 WIN (DDGRLOCK(dd_grd_curcanv));
2822 //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 );
2823 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2824 WIN (DDGRUNLOCK(dd_grd_curcanv));
2828 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2829 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2830 dd_VR_offscreen_buffer, 0, 0,
2831 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2832 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2836 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2838 WIN(DDGRLOCK(dd_grd_curcanv));
2839 gr_string( 0x8000, wy - title_height, title );
2840 WIN(DDGRUNLOCK(dd_grd_curcanv));
2845 citem = default_item;
2846 if ( citem < 0 ) citem = 0;
2847 if ( citem >= nitems ) citem = 0;
2851 #if defined(MACINTOSH) || defined(WINDOWS)
2852 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2853 close_x = wx-border_size;
2854 close_y = wy-title_height-border_size;
2855 draw_close_box(close_x,close_y);
2867 DoMessageStuff(&msg);
2869 if (_RedrawScreen) {
2870 _RedrawScreen = FALSE;
2872 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2873 gr_free_bitmap(bg.background);
2875 goto RePaintNewmenuListbox;
2882 ofirst_item = first_item;
2883 #if defined(MACINTOSH) || defined(WINDOWS)
2884 omouse_state = mouse_state;
2885 mouse_state = mouse_button_state(0);
2887 //see if redbook song needs to be restarted
2888 songs_check_redbook_repeat();
2892 if ( listbox_callback )
2893 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2914 else if (simukey==1)
2920 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2921 case KEY_PRINT_SCREEN:
2923 save_screen_shot(0);
2924 PA_DFX (pa_set_frontbuffer_current());
2925 PA_DFX (pa_set_front_to_read());
2948 citem += LB_ITEMS_ON_SCREEN;
2952 citem -= LB_ITEMS_ON_SCREEN;
2955 if (allow_abort_flag) {
2966 case KEY_COMMAND+KEY_Q: {
2967 extern void macintosh_quit();
2969 if ( !(Game_mode & GM_MULTI) )
2979 int ascii = key_to_ascii(key);
2980 if ( ascii < 255 ) {
2983 if (cc1 < 0 ) cc1 = 0;
2984 if (cc1 >= nitems ) cc1 = 0;
2986 if ( cc < 0 ) cc = 0;
2987 if ( cc >= nitems ) cc = 0;
2988 if ( citem == cc ) break;
2990 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
3007 if (citem< first_item)
3010 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
3011 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3013 if (nitems <= LB_ITEMS_ON_SCREEN )
3016 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3017 first_item = nitems-LB_ITEMS_ON_SCREEN;
3018 if (first_item < 0 ) first_item = 0;
3021 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3032 #if defined(MACINTOSH) || defined(WINDOWS)
3037 mouse_get_pos(&mx, &my);
3038 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3041 gr_get_string_size(items[i], &w, &h, &aw );
3044 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3046 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3058 //no double-click stuff for listbox
3059 //@@if (!mouse_state && omouse_state) {
3062 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3063 //@@ mouse_get_pos(&mx, &my);
3065 //@@ x2 = wx + width;
3066 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3068 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3069 //@@ if (dblclick_flag) done = 1;
3073 //check for close box clicked
3074 if ( !mouse_state && omouse_state ) {
3075 mouse_get_pos(&mx, &my);
3076 x1 = close_x + CLOSE_X + 2;
3077 x2 = x1 + CLOSE_SIZE - 2;
3078 y1 = close_y + CLOSE_Y + 2;
3079 y2 = y1 + CLOSE_SIZE - 2;
3080 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3090 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3092 y1 = total_height-LHY(7);
3094 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3102 if ( (ofirst_item != first_item) || redraw) {
3105 WIN(DDGRLOCK(dd_grd_curcanv));
3107 gr_setcolor( BM_XRGB( 0,0,0) );
3108 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3110 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3111 if ( i >= nitems ) {
3112 gr_setcolor( BM_XRGB(0,0,0));
3113 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3116 grd_curcanv->cv_font = SELECTED_FONT;
3118 grd_curcanv->cv_font = NORMAL_FONT;
3119 gr_get_string_size(items[i], &w, &h, &aw );
3120 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3121 gr_string( wx+5, y, items[i] );
3126 // If Win95 port, draw up/down arrows on left side of menu
3128 grd_curcanv->cv_font = NORMAL_FONT;
3130 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3134 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3138 if (show_down_arrow)
3139 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3143 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3150 WIN(DDGRUNLOCK(dd_grd_curcanv));
3154 } else if ( citem != ocitem ) {
3160 WIN(DDGRLOCK(dd_grd_curcanv));
3163 if ( (i>=0) && (i<nitems) ) {
3164 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3166 grd_curcanv->cv_font = SELECTED_FONT;
3168 grd_curcanv->cv_font = NORMAL_FONT;
3169 gr_get_string_size(items[i], &w, &h, &aw );
3170 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3171 gr_string( wx+5, y, items[i] );
3175 if ( (i>=0) && (i<nitems) ) {
3176 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3178 grd_curcanv->cv_font = SELECTED_FONT;
3180 grd_curcanv->cv_font = NORMAL_FONT;
3181 gr_get_string_size( items[i], &w, &h, &aw );
3182 gr_rect( wx, y-1, wx+width-1, y+h );
3183 gr_string( wx+5, y, items[i] );
3185 WIN(DDGRUNLOCK(dd_grd_curcanv));
3195 keyd_repeat = old_keyd_repeat;
3197 WIN (DDGRLOCK(dd_grd_curcanv));
3198 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3199 WIN (DDGRUNLOCK(dd_grd_curcanv));
3201 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3202 gr_free_bitmap(bg.background);
3206 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3207 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3209 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3210 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3216 WIN(mouse_set_mode(1)); //re-enable centering mode
3221 int newmenu_filelist( char * title, char * filespec, char * filename )
3224 char * Filenames[MAX_FILES];
3225 char FilenameText[MAX_FILES][14];
3226 FILEFINDSTRUCT find;
3229 if( !FileFindFirst( filespec, &find ) ) {
3231 if (NumFiles<MAX_FILES) {
3232 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3233 Filenames[NumFiles] = FilenameText[NumFiles];
3238 } while( !FileFindNext( &find ) );
3242 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3244 strcpy( filename, Filenames[i] );
3250 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3251 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3257 char nm_text[MESSAGEBOX_TEXT_SIZE];
3258 newmenu_item nm_message_items[5];
3260 va_start(args, nchoices );
3262 Assert( nchoices <= 5 );
3264 for (i=0; i<nchoices; i++ ) {
3265 s = va_arg( args, char * );
3266 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3268 format = va_arg( args, char * );
3269 //sprintf( nm_text, "" ); // adb: ?
3270 vsprintf(nm_text,format,args);
3273 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3275 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3277 //end this section addition - Victor Rachels
3280 extern netgame_info Active_games[];
3281 extern int NumActiveNetgames;
3283 void show_extra_netgame_info(int choice)
3289 if (choice>=NumActiveNetgames)
3294 m[i].text=(char *)&mtext[i];
3295 m[i].type=NM_TYPE_TEXT;
3298 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3299 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3300 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3301 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3303 already_showing_info=1;
3304 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3305 already_showing_info=0;
3310 /* Spiffy word wrap string formatting function */
3312 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3318 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3321 wordptr = strtok(tbuf, " ");
3322 if (!wordptr) return;
3328 col = col+strlen(wordptr)+1;
3329 if (col >=line_length) {
3331 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3334 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3336 wordptr = strtok(NULL, " ");