2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 * $Source: /cvs/cvsroot/d2x/main/newmenu.c,v $
18 * $Date: 2002-02-11 07:39:11 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
41 #include "pa_enabl.h" //$$POLY_ACC
88 #define MAXDISPLAYABLEITEMS 15
90 #define LHX(x) ((x)*(MenuHires?2:1))
91 #define LHY(y) ((y)*(MenuHires?2.4:1))
93 #define TITLE_FONT HUGE_FONT
94 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
95 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
96 #define SUBTITLE_FONT MEDIUM3_FONT
98 #define NORMAL_CHECK_BOX "
\81"
99 #define CHECKED_CHECK_BOX "
\82"
101 #define NORMAL_RADIO_BOX "
\7f"
102 #define CHECKED_RADIO_BOX "
\80"
103 #define CURSOR_STRING "_"
104 #define SLIDER_LEFT "
\83" // 131
105 #define SLIDER_RIGHT "
\84" // 132
106 #define SLIDER_MIDDLE "
\85" // 133
107 #define SLIDER_MARKER "
\86" // 134
108 #define UP_ARROW_MARKER "
\87" // 135
109 #define DOWN_ARROW_MARKER "
\88" // 136
111 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 );
112 void show_extra_netgame_info(int choice);
115 int Newmenu_first_time = 1;
116 //--unused-- int Newmenu_fade_in = 1;
119 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
120 grs_bitmap * saved; // The background under the menu.
121 grs_bitmap * background;
124 grs_bitmap nm_background,nm_background_save;
126 #define MESSAGEBOX_TEXT_SIZE 300 // How many characters in messagebox
127 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
129 extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
131 ubyte MenuReordering=0;
133 char Pauseable_menu=0;
134 char already_showing_info=0;
137 void newmenu_close() {
138 if ( nm_background.bm_data )
139 d_free(nm_background.bm_data);
141 if ( nm_background_save.bm_data )
142 d_free(nm_background_save.bm_data);
143 Newmenu_first_time = 1;
146 ubyte background_palette[768];
148 //should be called whenever the palette changes
149 void nm_remap_background()
151 if (!Newmenu_first_time) {
152 if (!nm_background.bm_data)
153 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
155 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
157 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
163 extern char last_palette_loaded[];
165 void nm_draw_background1(char * filename)
171 //@@//I think this only gets called to fill the whole screen
172 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
173 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
175 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
214 #define MENU_BACKGROUND_BITMAP "scores.pcx"
217 #define MENU_BACKGROUND_BITMAP (MenuHires?"\x01scoresb.pcx":"\x01scores.pcx") //read only from hog file
219 #define MENU_BACKGROUND_BITMAP (MenuHires?"scoresb.pcx":"scores.pcx")
223 int Background_hires;
226 void nm_draw_background(int x1, int y1, int x2, int y2 )
230 if (Newmenu_first_time || MenuHires!=Background_hires) {
233 if (Newmenu_first_time) {
234 atexit( newmenu_close );
235 Newmenu_first_time = 0;
236 nm_background_save.bm_data=NULL;
239 if (nm_background_save.bm_data)
240 d_free(nm_background_save.bm_data);
241 if (nm_background.bm_data)
242 d_free(nm_background.bm_data);
245 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
246 Assert(pcx_error == PCX_ERROR_NONE);
248 nm_background = nm_background_save;
249 nm_background.bm_data=NULL;
250 nm_remap_background();
252 Background_hires = MenuHires;
255 if ( x1 < 0 ) x1 = 0;
256 if ( y1 < 0 ) y1 = 0;
261 if ( w > nm_background.bm_w ) w = nm_background.bm_w;
262 if ( h > nm_background.bm_h ) h = nm_background.bm_h;
267 WIN(DDGRLOCK(dd_grd_curcanv));
269 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
271 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
276 Gr_scanline_darkening_level = 2*7;
279 gr_setcolor( BM_XRGB(0,0,0) );
280 gr_urect( x2-5, y1+5, x2-5, y2-5 );
281 gr_urect( x2-4, y1+4, x2-4, y2-5 );
282 gr_urect( x2-3, y1+3, x2-3, y2-5 );
283 gr_urect( x2-2, y1+2, x2-2, y2-5 );
284 gr_urect( x2-1, y1+1, x2-1, y2-5 );
285 gr_urect( x2+0, y1+0, x2-0, y2-5 );
287 gr_urect( x1+5, y2-5, x2, y2-5 );
288 gr_urect( x1+4, y2-4, x2, y2-4 );
289 gr_urect( x1+3, y2-3, x2, y2-3 );
290 gr_urect( x1+2, y2-2, x2, y2-2 );
291 gr_urect( x1+1, y2-1, x2, y2-1 );
292 gr_urect( x1+0, y2, x2, y2-0 );
294 WIN(DDGRUNLOCK(dd_grd_curcanv));
296 Gr_scanline_darkening_level = GR_FADE_LEVELS;
299 void nm_restore_background( int x, int y, int w, int h )
306 if ( x1 < 0 ) x1 = 0;
307 if ( y1 < 0 ) y1 = 0;
309 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
310 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
315 WIN(DDGRLOCK(dd_grd_curcanv));
316 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
317 WIN(DDGRUNLOCK(dd_grd_curcanv));
320 // Draw a left justfied string
321 void nm_string( bkg * b, int w1,int x, int y, char * s)
323 int w,h,aw,tx=0,t=0,i;
324 char *p,*s1,measure[2];
325 int XTabs[]={15,87,124,162,228,253};
331 XTabs[i]=(LHX(XTabs[i]));
339 p = strchr( s, '\t' );
346 gr_get_string_size(s, &w, &h, &aw );
352 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
353 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
357 for (i=0;i<strlen(s);i++)
359 if (s[i]=='\t' && SurfingNet)
366 gr_get_string_size(measure,&tx,&h,&aw);
367 gr_string(x,y,measure);
371 else gr_string (x,y,s);
373 if (!SurfingNet && p && (w1>0) ) {
374 gr_get_string_size(s1, &w, &h, &aw );
376 gr_string( x+w1-w, y, s1 );
382 // Draw a slider and it's string
383 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
390 p = strchr( s, '\t' );
396 gr_get_string_size(s, &w, &h, &aw );
399 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
400 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
402 gr_string( x, y, s );
405 gr_get_string_size(s1, &w, &h, &aw );
408 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
410 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
412 gr_string( x+w1-w, y, s1 );
419 // Draw a left justfied string with black background.
420 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
423 gr_get_string_size(s, &w, &h, &aw );
427 WIN(DDGRLOCK(dd_grd_curcanv));
428 gr_setcolor( BM_XRGB(2,2,2) );
429 gr_rect( x-1, y-1, x-1, y+h-1 );
430 gr_rect( x-1, y-1, x+w1-1, y-1 );
433 gr_setcolor( BM_XRGB(5,5,5) );
434 gr_rect( x, y+h, x+w1, y+h);
435 gr_rect( x+w1, y-1, x+w1, y+h );
437 gr_setcolor( BM_XRGB(0,0,0) );
438 gr_rect( x, y, x+w1-1, y+h-1 );
440 gr_string( x+1, y+1, s );
441 WIN(DDGRUNLOCK(dd_grd_curcanv));
445 // Draw a right justfied string
446 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
449 gr_get_string_size(s, &w, &h, &aw );
454 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
457 WIN(DDGRLOCK(dd_grd_curcanv));
458 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
459 gr_string( x-w, y, s );
460 WIN(DDGRUNLOCK(dd_grd_curcanv));
465 //for text items, constantly redraw cursor (to achieve flash)
466 void update_cursor( newmenu_item *item)
469 fix time = timer_get_approx_seconds();
471 char * text = item->text;
473 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
476 gr_get_string_size(text, &w, &h, &aw );
477 if ( w > item->w-10 )
484 x = item->x+w; y = item->y;
486 WIN(DDGRLOCK(dd_grd_curcanv));
488 gr_string( x, y, CURSOR_STRING );
490 gr_setcolor( BM_XRGB(0,0,0) );
491 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
493 WIN(DDGRUNLOCK(dd_grd_curcanv));
496 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
501 gr_get_string_size(text, &w1, &h1, &aw );
510 nm_string_black( b, w, x, y, text );
513 gr_string( x+w1+1, y, CURSOR_STRING );
517 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
522 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
524 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
526 if (item->text[0]=='\t')
527 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
532 grd_curcanv->cv_font = SELECTED_FONT;
534 grd_curcanv->cv_font = NORMAL_FONT;
537 if (is_current && item->type == NM_TYPE_TEXT)
538 grd_curcanv->cv_font = NORMAL_FONT;
542 WIN(DDGRLOCK(dd_grd_curcanv));
543 switch( item->type ) {
545 // grd_curcanv->cv_font=TEXT_FONT;
546 // fall through on purpose
549 nm_string( b, item->w, item->x, item->y, item->text );
551 case NM_TYPE_SLIDER: {
553 if (item->value < item->min_value) item->value=item->min_value;
554 if (item->value > item->max_value) item->value=item->max_value;
555 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
556 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
557 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
559 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
561 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
563 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
566 case NM_TYPE_INPUT_MENU:
567 if ( item->group==0 ) {
568 nm_string( b, item->w, item->x, item->y, item->text );
570 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
574 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
577 nm_string( b, item->w, item->x, item->y, item->text );
579 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
581 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
584 nm_string( b, item->w, item->x, item->y, item->text );
586 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
588 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
590 case NM_TYPE_NUMBER: {
592 if (item->value < item->min_value) item->value=item->min_value;
593 if (item->value > item->max_value) item->value=item->max_value;
594 nm_string( b, item->w, item->x, item->y, item->text );
595 sprintf( text, "%d", item->value );
596 nm_rstring( b,item->right_offset,item->x, item->y, text );
600 WIN(DDGRUNLOCK(dd_grd_curcanv));
604 char *Newmenu_allowed_chars=NULL;
606 //returns true if char is allowed
607 int char_allowed(char c)
609 char *p = Newmenu_allowed_chars;
617 if (c>=p[0] && c<=p[1])
626 void strip_end_whitespace( char * text )
630 for (i=l-1; i>=0; i-- ) {
631 if ( isspace(text[i]) )
638 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
640 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
642 int newmenu_dotiny( 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, LHX(310), -1, 1 );
648 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
650 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
654 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 )
656 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
660 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 )
662 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
664 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 )
666 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
669 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){
670 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
671 return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
674 //returns 1 if a control device button has been pressed
675 int check_button_press()
679 switch (Config_control_type) {
680 case CONTROL_JOYSTICK:
681 case CONTROL_FLIGHTSTICK_PRO:
682 case CONTROL_THRUSTMASTER_FCS:
683 case CONTROL_GRAVIS_GAMEPAD:
685 if (joy_get_button_down_cnt(i)>0) return 1;
688 case CONTROL_CYBERMAN:
689 #ifndef MACINTOSH // don't allow mouse to continue from menu
691 if (mouse_button_down_count(i)>0) return 1;
694 case CONTROL_WINJOYSTICK:
697 if (joy_get_button_down_cnt(i)>0) return 1;
700 case CONTROL_NONE: //keyboard only
702 if (key_checkch()) return 1;
707 Error("Bad control type (Config_control_type):%i",Config_control_type);
713 extern int network_request_player_names(int);
714 extern int RestoringMenu;
716 #if defined(WINDOWS) || defined(MACINTOSH)
717 ubyte Hack_DblClick_MenuMode=0;
720 MAC(extern ubyte joydefs_calibrating;)
724 #define CLOSE_SIZE 10
726 void draw_close_box(int x,int y)
728 WIN (DDGRLOCK(dd_grd_curcanv));
729 gr_setcolor( BM_XRGB(0, 0, 0) );
730 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
731 gr_setcolor( BM_XRGB(21, 21, 21) );
732 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
733 WIN (DDGRUNLOCK(dd_grd_curcanv));
736 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 )
738 int old_keyd_repeat, done;
739 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
740 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
741 grs_font * save_font;
742 int string_width, string_height, average_width;
745 int all_text=0; //set true if all text items
746 int sound_stopped=0,time_stopped=0;
747 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
750 int MaxOnMenu=MAXDISPLAYABLEITEMS;
751 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
752 #if defined(MACINTOSH) || defined(WINDOWS)
753 int mouse_state, omouse_state, dblclick_flag=0;
754 int mx=0, my=0, x1, x2, y1, y2;
758 EventRecord event; // looking for disk inserted events for CD mounts
761 PA_DFX (pa_set_frontbuffer_current());
762 PA_DFX (pa_set_front_to_read());
764 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
773 WIN(mouse_set_mode(0)); //disable centering mode
775 MaxDisplayable=nitems;
778 set_screen_mode(SCREEN_MENU);
782 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
783 digi_pause_digi_sounds();
787 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
800 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
802 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
804 save_font = grd_curcanv->cv_font;
809 grd_curcanv->cv_font = TITLE_FONT;
810 gr_get_string_size(title,&string_width,&string_height,&average_width );
815 grd_curcanv->cv_font = SUBTITLE_FONT;
816 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
817 if (string_width > tw )
822 th += LHY(8); //put some space between titles & body
825 grd_curcanv->cv_font = SMALL_FONT;
827 grd_curcanv->cv_font = NORMAL_FONT;
831 nmenus = nothers = 0;
833 // Find menu height & width (store in w,h)
834 for (i=0; i<nitems; i++ ) {
837 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
838 item[i].right_offset = 0;
841 string_height+=LHY(3);
843 item[i].saved_text[0] = '\0';
845 if ( item[i].type == NM_TYPE_SLIDER ) {
848 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
849 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
850 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
852 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
853 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
854 string_width += w1 + aw;
857 if ( item[i].type == NM_TYPE_MENU ) {
861 if ( item[i].type == NM_TYPE_CHECK ) {
864 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
865 item[i].right_offset = w1;
866 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
867 if (w1 > item[i].right_offset)
868 item[i].right_offset = w1;
871 if (item[i].type == NM_TYPE_RADIO ) {
874 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
875 item[i].right_offset = w1;
876 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
877 if (w1 > item[i].right_offset)
878 item[i].right_offset = w1;
881 if (item[i].type==NM_TYPE_NUMBER ) {
885 sprintf( test_text, "%d", item[i].max_value );
886 gr_get_string_size( test_text, &w1, &h1, &aw1 );
887 item[i].right_offset = w1;
888 sprintf( test_text, "%d", item[i].min_value );
889 gr_get_string_size( test_text, &w1, &h1, &aw1 );
890 if ( w1 > item[i].right_offset)
891 item[i].right_offset = w1;
894 if ( item[i].type == NM_TYPE_INPUT ) {
895 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
896 strcpy(item[i].saved_text, item[i].text );
898 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
899 if ( string_width > MAX_TEXT_WIDTH )
900 string_width = MAX_TEXT_WIDTH;
904 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
905 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
906 strcpy(item[i].saved_text, item[i].text );
908 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
913 item[i].w = string_width;
914 item[i].h = string_height;
916 if ( string_width > w )
917 w = string_width; // Save maximum width
918 if ( average_width > aw )
920 h += string_height+1; // Find the height of all strings
923 // Big hack for allowing the netgame options menu to spill over
925 MaxOnMenu=MAXDISPLAYABLEITEMS;
926 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
929 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
932 h=(MaxOnMenu*(string_height+1)+LHY(8));
933 MaxDisplayable=MaxOnMenu;
934 mprintf ((0,"Hey, this is a scroll box!\n"));
947 for (i=0; i<nitems; i++ ) {
949 if (item[i].right_offset > right_offset )
950 right_offset = item[i].right_offset;
952 if (right_offset > 0 )
955 //gr_get_string_size("",&string_width,&string_height,&average_width );
962 twidth = ( tw - w )/2;
967 { right_offset=0; twidth=0;}
969 mprintf(( 0, "Right offset = %d\n", right_offset ));
972 // Find min point of menu border
973 // x = (grd_curscreen->sc_w-w)/2;
974 // y = (grd_curscreen->sc_h-h)/2;
976 w += MenuHires?60:30;
977 h += MenuHires?60:30;
979 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
980 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
982 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
983 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
988 if ( filename != NULL ) {
989 nm_draw_background1( filename );
990 gr_palette_load(gr_palette);
993 // Save the background of the display
994 // Win95 must refer to the screen as a dd_grs_canvas, so...
995 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
996 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
998 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
999 gr_set_current_canvas(bg.menu_canvas) );
1001 if ( filename == NULL ) {
1002 // Save the background under the menu...
1008 #if defined(POLY_ACC)
1009 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1011 bg.saved = gr_create_bitmap( w, h );
1013 Assert( bg.saved != NULL );
1015 WIN (DDGRLOCK(dd_grd_curcanv));
1016 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1017 WIN (DDGRUNLOCK(dd_grd_curcanv));
1019 WINDOS ( dd_gr_set_current_canvas(NULL),
1020 gr_set_current_canvas( NULL )
1023 nm_draw_background(x,y,x+w-1,y+h-1);
1025 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1026 gr_set_current_canvas( bg.menu_canvas )
1029 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1033 #if defined(POLY_ACC)
1034 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1036 bg.background = gr_create_bitmap( w, h );
1038 Assert( bg.background != NULL );
1040 WIN (DDGRLOCK(dd_grd_curcanv));
1041 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1042 WIN (DDGRUNLOCK(dd_grd_curcanv));
1045 // ty = 15 + (yborder/4);
1047 ty = MenuHires?30:15;
1050 grd_curcanv->cv_font = TITLE_FONT;
1051 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1052 gr_get_string_size(title,&string_width,&string_height,&average_width );
1055 WIN (DDGRLOCK(dd_grd_curcanv));
1056 gr_printf( 0x8000, ty, title );
1057 WIN (DDGRUNLOCK(dd_grd_curcanv));
1062 grd_curcanv->cv_font = SUBTITLE_FONT;
1063 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1064 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1067 WIN (DDGRLOCK(dd_grd_curcanv));
1068 gr_printf( 0x8000, ty, subtitle );
1069 WIN (DDGRUNLOCK(dd_grd_curcanv));
1074 grd_curcanv->cv_font = SMALL_FONT;
1076 grd_curcanv->cv_font = NORMAL_FONT;
1078 // Update all item's x & y values.
1079 for (i=0; i<nitems; i++ ) {
1080 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1081 item[i].y += (MenuHires?30:15);
1082 if ( item[i].type==NM_TYPE_RADIO ) {
1083 fm = -1; // find first marked one
1084 for ( j=0; j<nitems; j++ ) {
1085 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1086 if (fm==-1 && item[j].value)
1098 old_keyd_repeat = keyd_repeat;
1104 if (citem < 0 ) citem = 0;
1105 if (citem > nitems-1 ) citem = nitems-1;
1108 #if defined(WINDOWS) || defined(MACINTOSH)
1112 while ( item[choice].type==NM_TYPE_TEXT ) {
1114 if (choice >= nitems ) {
1117 if (choice == citem ) {
1128 // Clear mouse, joystick to clear button presses.
1129 game_flush_inputs();
1131 #if defined(WINDOWS) || defined(MACINTOSH)
1132 mouse_state = omouse_state = 0;
1133 if (filename == NULL && !MenuReordering) {
1134 draw_close_box(0,0);
1140 if (!MenuReordering) {
1142 SetCursor (LoadCursor(NULL,IDC_ARROW));
1147 if (!joydefs_calibrating)
1151 mprintf ((0,"Set to true!\n"));
1157 DoMessageStuff(&msg);
1159 if (_RedrawScreen) {
1160 _RedrawScreen = FALSE;
1163 gr_free_bitmap(bg.saved);
1164 d_free( bg.background );
1167 gr_free_bitmap(bg.background);
1169 dd_gr_free_sub_canvas( bg.menu_canvas );
1170 grd_curcanv->cv_font = save_font;
1171 dd_grd_curcanv = save_canvas;
1173 goto RePaintNewmenu4;
1182 omouse_state = mouse_state;
1183 mouse_state = mouse_button_state(0);
1184 if (!joydefs_calibrating)
1185 show_cursor(); // possibly hidden
1189 omouse_state = mouse_state;
1190 if (!MenuReordering)
1191 mouse_state = mouse_button_state(0);
1192 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1195 //see if redbook song needs to be restarted
1196 songs_check_redbook_repeat();
1203 (*subfunction)(nitems,item,&k,choice);
1206 if (!time_stopped) {
1207 // Save current menu box
1208 if (multi_menu_poll() == -1)
1214 dont_restore = (k == -3); //-3 means don't restore
1220 if (check_button_press())
1224 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1227 old_choice = choice;
1233 if (SurfingNet && !already_showing_info)
1235 show_extra_netgame_info(choice-2);
1237 if (SurfingNet && already_showing_info)
1244 if (SurfingNet && !already_showing_info)
1246 network_request_player_names(choice-2);
1248 if (SurfingNet && already_showing_info)
1263 case KEY_TAB + KEY_SHIFTED:
1266 if (all_text) break;
1273 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1275 if (choice<TopChoice)
1276 { choice=TopChoice; break; }
1278 if (choice<ScrollOffset)
1280 for (i=0;i<nitems;i++)
1283 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1288 if (choice >= nitems ) choice=0;
1289 if (choice < 0 ) choice=nitems-1;
1291 } while ( item[choice].type==NM_TYPE_TEXT );
1292 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1293 item[choice].value = -1;
1294 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1295 item[old_choice].group=0;
1296 strcpy(item[old_choice].text, item[old_choice].saved_text );
1297 item[old_choice].value = -1;
1300 item[old_choice].redraw = 1;
1301 item[choice].redraw=1;
1306 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1307 if (all_text) break;
1314 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1317 { choice--; break; }
1319 if (choice>=MaxOnMenu+ScrollOffset)
1321 for (i=0;i<nitems;i++)
1324 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1329 if (choice < 0 ) choice=nitems-1;
1330 if (choice >= nitems ) choice=0;
1333 } while ( item[choice].type==NM_TYPE_TEXT );
1335 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1336 item[choice].value = -1;
1337 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1338 item[old_choice].group=0;
1339 strcpy(item[old_choice].text, item[old_choice].saved_text );
1340 item[old_choice].value = -1;
1343 item[old_choice].redraw=1;
1344 item[choice].redraw=1;
1347 if ( choice > -1 ) {
1348 switch( item[choice].type ) {
1351 case NM_TYPE_INPUT_MENU:
1354 if ( item[choice].value )
1355 item[choice].value = 0;
1357 item[choice].value = 1;
1358 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1361 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1363 mprintf ((0,"Special redraw!\n"));
1368 item[choice].redraw=1;
1371 for (i=0; i<nitems; i++ ) {
1372 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1377 item[choice].value = 1;
1378 item[choice].redraw = 1;
1384 case KEY_SHIFTED+KEY_UP:
1385 if (MenuReordering && choice!=TopChoice)
1387 Temp=item[choice].text;
1388 TempVal=item[choice].value;
1389 item[choice].text=item[choice-1].text;
1390 item[choice].value=item[choice-1].value;
1391 item[choice-1].text=Temp;
1392 item[choice-1].value=TempVal;
1393 item[choice].redraw=1;
1394 item[choice-1].redraw=1;
1398 case KEY_SHIFTED+KEY_DOWN:
1399 if (MenuReordering && choice!=(nitems-1))
1401 Temp=item[choice].text;
1402 TempVal=item[choice].value;
1403 item[choice].text=item[choice+1].text;
1404 item[choice].value=item[choice+1].value;
1405 item[choice+1].text=Temp;
1406 item[choice+1].value=TempVal;
1407 item[choice].redraw=1;
1408 item[choice+1].redraw=1;
1415 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1416 item[choice].group = 1;
1417 item[choice].redraw = 1;
1418 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1419 item[choice].text[0] = 0;
1420 item[choice].value = -1;
1422 strip_end_whitespace(item[choice].text);
1429 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1430 item[choice].group=0;
1431 strcpy(item[choice].text, item[choice].saved_text );
1432 item[choice].redraw=1;
1433 item[choice].value = -1;
1440 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1441 case KEY_PRINT_SCREEN:
1443 save_screen_shot(0);
1444 PA_DFX (pa_set_frontbuffer_current());
1445 PA_DFX (pa_set_front_to_read());
1446 for (i=0;i<nitems;i++)
1455 case KEY_COMMAND+KEY_RIGHT:
1456 songs_goto_next_song();
1458 case KEY_COMMAND+KEY_LEFT:
1459 songs_goto_prev_song();
1461 case KEY_COMMAND+KEY_UP:
1462 songs_play_level_song(1);
1464 case KEY_COMMAND+KEY_DOWN:
1465 songs_stop_redbook();
1468 case KEY_COMMAND+KEY_M:
1470 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1471 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1474 key_close(); // no processing of keys with keyboard handler.. jeez
1477 show_boxed_message ("Mounting CD\nESC to quit");
1478 RBAMountDisk(); // OS has totaly control of the CD.
1479 if (Function_mode == FMODE_MENU)
1480 songs_play_song(SONG_TITLE,1);
1481 else if (Function_mode == FMODE_GAME)
1482 songs_play_level_song( Current_level_num );
1483 clear_boxed_message();
1492 case KEY_COMMAND+KEY_E:
1493 songs_stop_redbook();
1495 k = -1; // force key not to register
1498 case KEY_COMMAND+KEY_Q: {
1499 extern void macintosh_quit();
1501 if ( !(Game_mode & GM_MULTI) )
1503 if (!joydefs_calibrating)
1505 k = -1; // force key not to register
1512 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1519 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1521 if ( !done && mouse_state && !omouse_state && !all_text ) {
1522 mouse_get_pos(&mx, &my);
1523 for (i=0; i<nitems; i++ ) {
1524 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1525 x2 = x1 + item[i].w;
1526 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1527 y2 = y1 + item[i].h;
1528 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1529 if (i+ScrollOffset != choice) {
1530 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1533 choice = i + ScrollOffset;
1535 switch( item[choice].type ) {
1537 if ( item[choice].value )
1538 item[choice].value = 0;
1540 item[choice].value = 1;
1541 item[choice].redraw=1;
1548 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1550 mprintf ((0,"Special redraw!\n"));
1557 for (i=0; i<nitems; i++ ) {
1558 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1563 item[choice].value = 1;
1564 item[choice].redraw = 1;
1567 item[old_choice].redraw=1;
1573 if (mouse_state && all_text)
1576 if ( !done && mouse_state && !all_text ) {
1577 mouse_get_pos(&mx, &my);
1579 // check possible scrollbar stuff first
1581 int arrow_width, arrow_height, aw;
1583 if (ScrollOffset != 0) {
1584 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1585 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1586 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1587 x1 = x1 - arrow_width;
1588 y2 = y1 + arrow_height;
1589 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1592 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1594 if (choice<ScrollOffset)
1596 for (i=0;i<nitems;i++)
1599 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1603 if (ScrollOffset+MaxDisplayable<nitems) {
1604 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1605 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1606 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1607 x1 = x1 - arrow_width;
1608 y2 = y1 + arrow_height;
1609 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1612 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1614 if (choice>=MaxOnMenu+ScrollOffset)
1616 for (i=0;i<nitems;i++)
1619 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1625 for (i=0; i<nitems; i++ ) {
1626 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1627 x2 = x1 + item[i].w;
1628 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1629 y2 = y1 + item[i].h;
1630 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1631 if (i+ScrollOffset != choice) {
1632 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1635 choice = i + ScrollOffset;
1637 if ( item[choice].type == NM_TYPE_SLIDER ) {
1638 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1639 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1641 strcpy(slider_text, item[choice].saved_text);
1642 p = strchr(slider_text, '\t');
1648 gr_get_string_size(s1, &slider_width, &height, &aw);
1649 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1650 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1651 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1653 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1654 x2 = x1 + slider_width + sright_width;
1655 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1656 item[choice].value = item[choice].min_value;
1657 item[choice].redraw = 2;
1658 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1659 item[choice].value = item[choice].max_value;
1660 item[choice].redraw = 2;
1661 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1662 int num_values, value_width, new_value;
1664 num_values = item[choice].max_value - item[choice].min_value + 1;
1665 value_width = (slider_width - sleft_width - sright_width) / num_values;
1666 new_value = (mx - x1 - sleft_width) / value_width;
1667 if ( item[choice].value != new_value ) {
1668 item[choice].value = new_value;
1669 item[choice].redraw = 2;
1675 if (choice == old_choice)
1677 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1678 item[choice].value = -1;
1679 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1680 item[old_choice].group=0;
1681 strcpy(item[old_choice].text, item[old_choice].saved_text );
1682 item[old_choice].value = -1;
1685 item[old_choice].redraw = 1;
1686 item[choice].redraw=1;
1692 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1693 mouse_get_pos(&mx, &my);
1694 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1695 x2 = x1 + item[choice].w;
1696 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1697 y2 = y1 + item[choice].h;
1698 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1699 if (Hack_DblClick_MenuMode) {
1700 if (dblclick_flag) done = 1;
1701 else dblclick_flag = 1;
1707 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1708 item[choice].group = 1;
1709 item[choice].redraw = 1;
1710 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1711 item[choice].text[0] = 0;
1712 item[choice].value = -1;
1714 strip_end_whitespace(item[choice].text);
1718 if ( !done && !mouse_state && omouse_state && close_box ) {
1719 mouse_get_pos(&mx, &my);
1720 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1721 x2 = x1 + CLOSE_SIZE;
1722 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1723 y2 = y1 + CLOSE_SIZE;
1724 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1730 // HACK! Don't redraw loadgame preview
1731 if (RestoringMenu) item[0].redraw = 0;
1732 #endif // ifdef MACINTOSH
1734 if ( choice > -1 ) {
1737 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1738 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1739 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1740 if (item[choice].value > 0)
1741 item[choice].value--;
1742 item[choice].text[item[choice].value] = 0;
1743 item[choice].redraw = 1;
1745 ascii = key_to_ascii(k);
1746 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1750 if (item[choice].value==-1) {
1751 item[choice].value = 0;
1754 allowed = char_allowed(ascii);
1756 if (!allowed && ascii==' ' && char_allowed('_')) {
1762 item[choice].text[item[choice].value++] = ascii;
1763 item[choice].text[item[choice].value] = 0;
1764 item[choice].redraw=1;
1768 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1769 ascii = key_to_ascii(k);
1771 int choice1 = choice;
1772 ascii = toupper(ascii);
1776 if (choice1 >= nitems ) choice1=0;
1777 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1778 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1779 (item[choice1].type==NM_TYPE_CHECK) ||
1780 (item[choice1].type==NM_TYPE_RADIO) ||
1781 (item[choice1].type==NM_TYPE_NUMBER) ||
1782 (item[choice1].type==NM_TYPE_SLIDER) )
1783 && (ascii==toupper(ch)) ) {
1787 item[old_choice].redraw=1;
1788 item[choice].redraw=1;
1790 } while (choice1 != choice );
1794 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1795 int ov=item[choice].value;
1800 case KEY_MINUS+KEY_SHIFTED:
1802 item[choice].value -= 1;
1807 case KEY_EQUAL+KEY_SHIFTED:
1809 item[choice].value++;
1814 item[choice].value += 10;
1819 item[choice].value -= 10;
1822 if (ov!=item[choice].value)
1823 item[choice].redraw=1;
1828 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1829 gr_set_current_canvas(bg.menu_canvas));
1831 // Redraw everything...
1832 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1834 if (item[i].redraw) // warning! ugly hack below
1836 item[i].y-=((string_height+1)*ScrollOffset);
1839 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1841 MAC(if (!joydefs_calibrating) show_cursor());
1842 WIN(if (!MenuReordering) ShowCursorW());
1843 item[i].y+=((string_height+1)*ScrollOffset);
1845 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1846 update_cursor( &item[i]);
1852 //grd_curcanv->cv_font = NORMAL_FONT;
1854 if (LastScrollCheck!=ScrollOffset)
1856 LastScrollCheck=ScrollOffset;
1857 grd_curcanv->cv_font = SELECTED_FONT;
1859 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1860 sx=item[ScrollOffset].x-(MenuHires?24:12);
1863 if (ScrollOffset!=0)
1864 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1866 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1868 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1869 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1871 if (ScrollOffset+MaxDisplayable<nitems)
1872 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1874 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1880 if ( !dont_restore && gr_palette_faded_out ) {
1881 gr_palette_fade_in( gr_palette, 32, 0 );
1888 // Restore everything...
1890 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1891 gr_set_current_canvas(bg.menu_canvas));
1893 if ( filename == NULL ) {
1894 // Save the background under the menu...
1895 WIN (DDGRLOCK(dd_grd_curcanv));
1896 gr_bitmap(0, 0, bg.saved);
1897 WIN (DDGRUNLOCK(dd_grd_curcanv));
1898 gr_free_bitmap(bg.saved);
1899 d_free( bg.background );
1901 if (!dont_restore) //info passed back from subfunction
1903 WIN (DDGRLOCK(dd_grd_curcanv));
1904 gr_bitmap(0, 0, bg.background);
1905 WIN (DDGRUNLOCK(dd_grd_curcanv));
1907 gr_free_bitmap(bg.background);
1910 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1911 gr_free_sub_canvas( bg.menu_canvas ) );
1913 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1914 grd_curcanv->cv_font = save_font;
1915 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1916 keyd_repeat = old_keyd_repeat;
1918 game_flush_inputs();
1929 if ( sound_stopped )
1930 digi_resume_digi_sounds();
1932 WIN(mouse_set_mode(1)); //re-enable centering mode
1939 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1945 char nm_text[MESSAGEBOX_TEXT_SIZE];
1946 newmenu_item nm_message_items[5];
1948 va_start(args, nchoices );
1950 Assert( nchoices <= 5 );
1952 for (i=0; i<nchoices; i++ ) {
1953 s = va_arg( args, char * );
1954 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1956 format = va_arg( args, char * );
1957 strcpy( nm_text, "" );
1958 vsprintf(nm_text,format,args);
1961 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1963 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1966 int nm_messagebox( char *title, int nchoices, ... )
1972 char nm_text[MESSAGEBOX_TEXT_SIZE];
1973 newmenu_item nm_message_items[5];
1975 va_start(args, nchoices );
1977 Assert( nchoices <= 5 );
1979 for (i=0; i<nchoices; i++ ) {
1980 s = va_arg( args, char * );
1981 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1983 format = va_arg( args, char * );
1984 strcpy( nm_text, "" );
1985 vsprintf(nm_text,format,args);
1988 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1990 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1996 void newmenu_file_sort( int n, char *list )
2003 for (i=incr; i<n; i++ ) {
2006 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
2007 memcpy( t, &list[j*14], FILENAME_LEN );
2008 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
2009 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2020 void delete_player_saved_games(char * name)
2025 for (i=0;i<10; i++) {
2027 sprintf( filename, "%s.sg%d", name, i );
2029 sprintf( filename, ":Players:%s.sg%d", name, i );
2035 #define MAX_FILES 300
2037 int MakeNewPlayerFile(int allow_abort);
2039 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2042 FILEFINDSTRUCT find;
2043 int NumFiles=0, key,done, citem, ocitem;
2044 char * filenames = NULL;
2045 int NumFiles_displayed = 8;
2046 int first_item = -1, ofirst_item;
2047 int old_keyd_repeat = keyd_repeat;
2050 int demos_deleted=0;
2051 int initialized = 0;
2053 int w_x, w_y, w_w, w_h, title_height;
2054 int box_x, box_y, box_w, box_h;
2055 bkg bg; // background under listbox
2056 #if defined(MACINTOSH) || defined(WINDOWS)
2057 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2058 int mouse2_state, omouse2_state;
2059 int dblclick_flag=0;
2061 int show_up_arrow=0,show_down_arrow=0;
2063 WIN(int win_redraw=0);
2065 w_x=w_y=w_w=w_h=title_height=0;
2066 box_x=box_y=box_w=box_h=0;
2068 filenames = d_malloc( MAX_FILES * 14 );
2069 if (filenames==NULL) return 0;
2074 WIN(mouse_set_mode(0)); //disable centering mode
2076 if (strstr( filespec, "*.plr" ))
2078 else if (strstr( filespec, "*.dem" ))
2085 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2087 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2092 if( !FileFindFirst( filespec, &find ) ) {
2094 if (NumFiles<MAX_FILES) {
2095 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2096 if ( player_mode ) {
2098 p = strchr(&filenames[NumFiles*14],'.');
2105 } while( !FileFindNext( &find ) );
2109 if ( (NumFiles < 1) && demos_deleted ) {
2113 if ( (NumFiles < 1) && demo_mode ) {
2114 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2120 if ( (NumFiles < 2) && player_mode ) {
2122 goto ExitFileMenuEarly;
2129 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2136 // set_screen_mode(SCREEN_MENU);
2142 dd_gr_set_current_canvas(NULL);
2144 gr_set_current_canvas(NULL);
2147 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2149 grd_curcanv->cv_font = SUBTITLE_FONT;
2151 WIN(DDGRUNLOCK(dd_grd_curcanv));
2156 for (i=0; i<NumFiles; i++ ) {
2158 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2164 gr_get_string_size( title, &w, &h, &aw );
2167 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2171 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2173 w_w += (grd_curfont->ft_w * 4);
2174 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2176 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2177 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2179 w_x = (grd_curcanv->cv_w-w_w)/2;
2180 w_y = (grd_curcanv->cv_h-w_h)/2;
2182 if ( w_x < 0 ) w_x = 0;
2183 if ( w_y < 0 ) w_y = 0;
2185 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2186 box_y = w_y + title_height;
2188 // save the screen behind the menu.
2192 #if !defined(WINDOWS)
2193 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2194 bg.background = &VR_offscreen_buffer->cv_bitmap;
2197 #if defined(POLY_ACC)
2198 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2200 bg.background = gr_create_bitmap( w_w, w_h );
2203 Assert( bg.background != NULL );
2206 WIN(DDGRLOCK(dd_grd_curcanv));
2207 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2208 WIN(DDGRUNLOCK(dd_grd_curcanv));
2212 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2213 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2214 dd_VR_offscreen_buffer, 0, 0,
2215 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2216 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2220 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2222 WIN(DDGRLOCK(dd_grd_curcanv))
2224 gr_string( 0x8000, w_y+10, title );
2226 WIN(DDGRUNLOCK(dd_grd_curcanv));
2233 if ( !player_mode ) {
2234 newmenu_file_sort( NumFiles, filenames );
2236 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2237 newmenu_file_sort( NumFiles, filenames );
2239 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2241 for ( i=0; i<NumFiles; i++ ) {
2242 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2243 #if defined(WINDOWS) || defined(MACINTOSH)
2251 #if defined(MACINTOSH) || defined(WINDOWS)
2252 mouse_state = omouse_state = 0;
2253 mouse2_state = omouse2_state = 0;
2254 draw_close_box(w_x,w_y);
2266 DoMessageStuff(&msg);
2268 if (_RedrawScreen) {
2269 _RedrawScreen = FALSE;
2271 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2272 gr_free_bitmap(bg.background);
2275 goto RePaintNewmenuFile;
2282 ofirst_item = first_item;
2285 #if defined(MACINTOSH) || defined(WINDOWS)
2286 omouse_state = mouse_state;
2287 omouse2_state = mouse2_state;
2288 mouse_state = mouse_button_state(0);
2289 mouse2_state = mouse_button_state(1);
2292 //see if redbook song needs to be restarted
2293 songs_check_redbook_repeat();
2296 if (!mouse2_state && omouse2_state)
2297 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2300 //NOTE LINK TO ABOVE ELSE
2306 else if (simukey==1)
2312 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2313 case KEY_PRINT_SCREEN:
2315 save_screen_shot(0);
2316 PA_DFX (pa_set_frontbuffer_current());
2317 PA_DFX (pa_set_front_to_read());
2323 case KEY_CTRLED+KEY_D:
2324 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2328 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2332 mouse_set_mode(1); //re-enable centering mode
2336 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2338 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2341 mouse_set_mode(0); //disenable centering mode
2347 char name[_MAX_PATH],dir[_MAX_DIR];
2349 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2353 _splitpath(filespec,name,dir,NULL,NULL);
2355 strcat(name,&filenames[citem*14]);
2362 if ( !strncmp(name, ".\\", 2) )
2363 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2364 name[i] = name[i+1];
2365 while ( (p = strchr(name, '\\')) )
2370 ret = unlink( name );
2374 if ((!ret) && player_mode) {
2375 delete_player_saved_games( &filenames[citem*14] );
2380 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2382 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2383 } else if (demo_mode)
2408 citem += NumFiles_displayed;
2412 citem -= NumFiles_displayed;
2415 if (allow_abort_flag) {
2426 case KEY_COMMAND+KEY_Q: {
2427 extern void macintosh_quit();
2429 if ( !(Game_mode & GM_MULTI) )
2440 int ascii = key_to_ascii(key);
2441 if ( ascii < 255 ) {
2444 if (cc1 < 0 ) cc1 = 0;
2445 if (cc1 >= NumFiles ) cc1 = 0;
2447 if ( cc < 0 ) cc = 0;
2448 if ( cc >= NumFiles ) cc = 0;
2449 if ( citem == cc ) break;
2451 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2466 if (citem>=NumFiles)
2469 if (citem< first_item)
2472 if (citem>=( first_item+NumFiles_displayed))
2474 first_item = citem-NumFiles_displayed+1;
2478 if (NumFiles>first_item+NumFiles_displayed)
2489 if (NumFiles <= NumFiles_displayed )
2492 if (first_item>NumFiles-NumFiles_displayed)
2494 first_item = NumFiles-NumFiles_displayed;
2497 if (first_item < 0 ) first_item = 0;
2499 #if defined(MACINTOSH) || defined(WINDOWS)
2501 if (mouse_state || mouse2_state) {
2504 mouse_get_pos(&mx, &my);
2505 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2506 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2508 x2 = box_x + box_w - 1;
2509 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2511 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2512 if (i == citem && !mouse2_state) {
2522 if (!mouse_state && omouse_state) {
2525 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2526 mouse_get_pos(&mx, &my);
2528 x2 = box_x + box_w - 1;
2529 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2531 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2532 if (dblclick_flag) done = 1;
2533 else dblclick_flag = 1;
2537 if ( !mouse_state && omouse_state ) {
2538 mouse_get_pos(&mx, &my);
2539 x1 = w_x + CLOSE_X + 2;
2540 x2 = x1 + CLOSE_SIZE - 2;
2541 y1 = w_y + CLOSE_Y + 2;
2542 y2 = y1 + CLOSE_SIZE - 2;
2543 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2552 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2554 y1 = box_y+box_h-LHY(7);
2556 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2563 WIN(DDGRLOCK(dd_grd_curcanv));
2564 gr_setcolor( BM_XRGB(2,2,2));
2565 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2566 gr_setcolor( BM_XRGB( 0,0,0) );
2569 if (ofirst_item != first_item || win_redraw) {
2572 if (ofirst_item != first_item) {
2576 gr_setcolor( BM_XRGB( 0,0,0) );
2577 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2579 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2581 if ( i >= NumFiles ) {
2583 gr_setcolor( BM_XRGB(5,5,5));
2584 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2585 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2587 gr_setcolor( BM_XRGB(2,2,2));
2588 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2590 gr_setcolor( BM_XRGB(0,0,0));
2591 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2595 grd_curcanv->cv_font = SELECTED_FONT;
2597 grd_curcanv->cv_font = NORMAL_FONT;
2598 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2600 gr_setcolor( BM_XRGB(5,5,5));
2601 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2602 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2604 gr_setcolor( BM_XRGB(2,2,2));
2605 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2606 gr_setcolor( BM_XRGB(0,0,0));
2608 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2609 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2614 } else if ( citem != ocitem ) {
2620 if ( (i>=0) && (i<NumFiles) ) {
2621 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2623 grd_curcanv->cv_font = SELECTED_FONT;
2625 grd_curcanv->cv_font = NORMAL_FONT;
2626 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2627 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2628 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2631 if ( (i>=0) && (i<NumFiles) ) {
2632 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2634 grd_curcanv->cv_font = SELECTED_FONT;
2636 grd_curcanv->cv_font = NORMAL_FONT;
2637 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2638 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2639 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2646 grd_curcanv->cv_font = NORMAL_FONT;
2648 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2652 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2656 if (show_down_arrow)
2657 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2661 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2669 WIN(DDGRUNLOCK(dd_grd_curcanv));
2675 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2682 keyd_repeat = old_keyd_repeat;
2684 if ( initialized ) {
2685 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2687 WIN (DDGRLOCK(dd_grd_curcanv));
2688 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2689 WIN (DDGRUNLOCK(dd_grd_curcanv));
2691 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2692 gr_free_bitmap(bg.background);
2695 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2696 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2698 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2699 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2709 WIN(mouse_set_mode(1)); //re-enable centering mode
2717 // Example listbox callback function...
2718 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2722 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2723 // if ( *nitems > 1 ) {
2724 // unlink( items[*citem] ); // Delete the file
2725 // for (i=*citem; i<*nitems-1; i++ ) {
2726 // items[i] = items[i+1];
2728 // *nitems = *nitems - 1;
2729 // d_free( items[*nitems] );
2730 // items[*nitems] = NULL;
2731 // return 1; // redraw;
2738 #define LB_ITEMS_ON_SCREEN 8
2740 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2742 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2745 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 ) )
2748 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2749 int old_keyd_repeat = keyd_repeat;
2750 int width, height, wx, wy, title_height, border_size;
2751 int total_width,total_height;
2753 #if defined(MACINTOSH) || defined(WINDOWS)
2754 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2755 int close_x,close_y;
2756 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2758 WIN(int win_redraw=0);
2762 PA_DFX (pa_set_frontbuffer_current());
2763 PA_DFX (pa_set_front_to_read());
2764 WIN(mouse_set_mode(0)); //disable centering mode
2766 // set_screen_mode(SCREEN_MENU);
2770 RePaintNewmenuListbox:
2772 dd_gr_set_current_canvas(NULL);
2774 gr_set_current_canvas(NULL);
2777 grd_curcanv->cv_font = SUBTITLE_FONT;
2780 for (i=0; i<nitems; i++ ) {
2782 gr_get_string_size( items[i], &w, &h, &aw );
2786 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2790 gr_get_string_size( title, &w, &h, &aw );
2793 title_height = h + 5;
2796 border_size = grd_curfont->ft_w;
2797 WIN (border_size=grd_curfont->ft_w*2);
2799 width += (grd_curfont->ft_w);
2800 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2801 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2803 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2804 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2805 if ( wy < title_height )
2808 total_width = width+2*border_size;
2809 total_height = height+2*border_size+title_height;
2813 #if !defined(WINDOWS)
2814 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2815 bg.background = &VR_offscreen_buffer->cv_bitmap;
2818 //bg.background = gr_create_bitmap( width, (height + title_height) );
2819 #if defined(POLY_ACC)
2820 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2822 bg.background = gr_create_bitmap(total_width,total_height);
2824 Assert( bg.background != NULL );
2826 WIN (DDGRLOCK(dd_grd_curcanv));
2827 //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 );
2828 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2829 WIN (DDGRUNLOCK(dd_grd_curcanv));
2833 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2834 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2835 dd_VR_offscreen_buffer, 0, 0,
2836 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2837 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2841 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2843 WIN(DDGRLOCK(dd_grd_curcanv));
2844 gr_string( 0x8000, wy - title_height, title );
2845 WIN(DDGRUNLOCK(dd_grd_curcanv));
2850 citem = default_item;
2851 if ( citem < 0 ) citem = 0;
2852 if ( citem >= nitems ) citem = 0;
2856 #if defined(MACINTOSH) || defined(WINDOWS)
2857 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2858 close_x = wx-border_size;
2859 close_y = wy-title_height-border_size;
2860 draw_close_box(close_x,close_y);
2872 DoMessageStuff(&msg);
2874 if (_RedrawScreen) {
2875 _RedrawScreen = FALSE;
2877 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2878 gr_free_bitmap(bg.background);
2880 goto RePaintNewmenuListbox;
2887 ofirst_item = first_item;
2888 #if defined(MACINTOSH) || defined(WINDOWS)
2889 omouse_state = mouse_state;
2890 mouse_state = mouse_button_state(0);
2892 //see if redbook song needs to be restarted
2893 songs_check_redbook_repeat();
2897 if ( listbox_callback )
2898 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2919 else if (simukey==1)
2925 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2926 case KEY_PRINT_SCREEN:
2928 save_screen_shot(0);
2929 PA_DFX (pa_set_frontbuffer_current());
2930 PA_DFX (pa_set_front_to_read());
2953 citem += LB_ITEMS_ON_SCREEN;
2957 citem -= LB_ITEMS_ON_SCREEN;
2960 if (allow_abort_flag) {
2971 case KEY_COMMAND+KEY_Q: {
2972 extern void macintosh_quit();
2974 if ( !(Game_mode & GM_MULTI) )
2984 int ascii = key_to_ascii(key);
2985 if ( ascii < 255 ) {
2988 if (cc1 < 0 ) cc1 = 0;
2989 if (cc1 >= nitems ) cc1 = 0;
2991 if ( cc < 0 ) cc = 0;
2992 if ( cc >= nitems ) cc = 0;
2993 if ( citem == cc ) break;
2995 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
3012 if (citem< first_item)
3015 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
3016 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3018 if (nitems <= LB_ITEMS_ON_SCREEN )
3021 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3022 first_item = nitems-LB_ITEMS_ON_SCREEN;
3023 if (first_item < 0 ) first_item = 0;
3026 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3037 #if defined(MACINTOSH) || defined(WINDOWS)
3042 mouse_get_pos(&mx, &my);
3043 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3046 gr_get_string_size(items[i], &w, &h, &aw );
3049 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3051 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3063 //no double-click stuff for listbox
3064 //@@if (!mouse_state && omouse_state) {
3067 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3068 //@@ mouse_get_pos(&mx, &my);
3070 //@@ x2 = wx + width;
3071 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3073 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3074 //@@ if (dblclick_flag) done = 1;
3078 //check for close box clicked
3079 if ( !mouse_state && omouse_state ) {
3080 mouse_get_pos(&mx, &my);
3081 x1 = close_x + CLOSE_X + 2;
3082 x2 = x1 + CLOSE_SIZE - 2;
3083 y1 = close_y + CLOSE_Y + 2;
3084 y2 = y1 + CLOSE_SIZE - 2;
3085 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3095 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3097 y1 = total_height-LHY(7);
3099 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3107 if ( (ofirst_item != first_item) || redraw) {
3110 WIN(DDGRLOCK(dd_grd_curcanv));
3112 gr_setcolor( BM_XRGB( 0,0,0) );
3113 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3115 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3116 if ( i >= nitems ) {
3117 gr_setcolor( BM_XRGB(0,0,0));
3118 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3121 grd_curcanv->cv_font = SELECTED_FONT;
3123 grd_curcanv->cv_font = NORMAL_FONT;
3124 gr_get_string_size(items[i], &w, &h, &aw );
3125 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3126 gr_string( wx+5, y, items[i] );
3131 // If Win95 port, draw up/down arrows on left side of menu
3133 grd_curcanv->cv_font = NORMAL_FONT;
3135 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3139 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3143 if (show_down_arrow)
3144 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3148 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3155 WIN(DDGRUNLOCK(dd_grd_curcanv));
3159 } else if ( citem != ocitem ) {
3165 WIN(DDGRLOCK(dd_grd_curcanv));
3168 if ( (i>=0) && (i<nitems) ) {
3169 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3171 grd_curcanv->cv_font = SELECTED_FONT;
3173 grd_curcanv->cv_font = NORMAL_FONT;
3174 gr_get_string_size(items[i], &w, &h, &aw );
3175 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3176 gr_string( wx+5, y, items[i] );
3180 if ( (i>=0) && (i<nitems) ) {
3181 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3183 grd_curcanv->cv_font = SELECTED_FONT;
3185 grd_curcanv->cv_font = NORMAL_FONT;
3186 gr_get_string_size( items[i], &w, &h, &aw );
3187 gr_rect( wx, y-1, wx+width-1, y+h );
3188 gr_string( wx+5, y, items[i] );
3190 WIN(DDGRUNLOCK(dd_grd_curcanv));
3200 keyd_repeat = old_keyd_repeat;
3202 WIN (DDGRLOCK(dd_grd_curcanv));
3203 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3204 WIN (DDGRUNLOCK(dd_grd_curcanv));
3206 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3207 gr_free_bitmap(bg.background);
3211 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3212 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3214 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3215 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3221 WIN(mouse_set_mode(1)); //re-enable centering mode
3226 int newmenu_filelist( char * title, char * filespec, char * filename )
3229 char * Filenames[MAX_FILES];
3230 char FilenameText[MAX_FILES][14];
3231 FILEFINDSTRUCT find;
3234 if( !FileFindFirst( filespec, &find ) ) {
3236 if (NumFiles<MAX_FILES) {
3237 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3238 Filenames[NumFiles] = FilenameText[NumFiles];
3243 } while( !FileFindNext( &find ) );
3247 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3249 strcpy( filename, Filenames[i] );
3255 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3256 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3262 char nm_text[MESSAGEBOX_TEXT_SIZE];
3263 newmenu_item nm_message_items[5];
3265 va_start(args, nchoices );
3267 Assert( nchoices <= 5 );
3269 for (i=0; i<nchoices; i++ ) {
3270 s = va_arg( args, char * );
3271 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3273 format = va_arg( args, char * );
3274 //sprintf( nm_text, "" ); // adb: ?
3275 vsprintf(nm_text,format,args);
3278 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3280 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3282 //end this section addition - Victor Rachels
3285 extern netgame_info Active_games[];
3286 extern int NumActiveNetgames;
3288 void show_extra_netgame_info(int choice)
3294 if (choice>=NumActiveNetgames)
3299 m[i].text=(char *)&mtext[i];
3300 m[i].type=NM_TYPE_TEXT;
3303 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3304 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3305 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3306 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3308 already_showing_info=1;
3309 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3310 already_showing_info=0;
3315 /* Spiffy word wrap string formatting function */
3317 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3323 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3326 wordptr = strtok(tbuf, " ");
3327 if (!wordptr) return;
3333 col = col+strlen(wordptr)+1;
3334 if (col >=line_length) {
3336 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3339 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3341 wordptr = strtok(NULL, " ");