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.
29 #if !defined(_MSC_VER) && !defined(macintosh)
76 #define MAXDISPLAYABLEITEMS 15
78 #define LHX(x) ((x)*(MenuHires?2:1))
79 #define LHY(y) ((y)*(MenuHires?2.4:1))
81 #define TITLE_FONT HUGE_FONT
82 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
83 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
84 #define SUBTITLE_FONT MEDIUM3_FONT
86 #define NORMAL_CHECK_BOX "\x81" // 129
87 #define CHECKED_CHECK_BOX "\x82" // 130
89 #define NORMAL_RADIO_BOX "\x7f" // 127
90 #define CHECKED_RADIO_BOX "\x80" // 128
91 #define CURSOR_STRING "_"
92 #define SLIDER_LEFT "\x83" // 131
93 #define SLIDER_RIGHT "\x84" // 132
94 #define SLIDER_MIDDLE "\x85" // 133
95 #define SLIDER_MARKER "\x86" // 134
96 #define UP_ARROW_MARKER "\x87" // 135
97 #define DOWN_ARROW_MARKER "\x88" // 136
99 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 );
100 void show_extra_netgame_info(int choice);
103 int Newmenu_first_time = 1;
104 //--unused-- int Newmenu_fade_in = 1;
107 grs_canvas * menu_canvas;
108 grs_bitmap * saved; // The background under the menu.
109 grs_bitmap * background;
112 grs_bitmap nm_background,nm_background_save;
114 #define MESSAGEBOX_TEXT_SIZE 2176 // How many characters in messagebox (changed form 300 (fixes crash from show_game_score and friends) - 2000/01/18 Matt Mueller)
115 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
117 ubyte MenuReordering=0;
119 char Pauseable_menu=0;
120 char already_showing_info=0;
123 void newmenu_close() {
124 if ( nm_background.bm_data )
125 d_free(nm_background.bm_data);
127 if ( nm_background_save.bm_data )
128 d_free(nm_background_save.bm_data);
129 Newmenu_first_time = 1;
132 ubyte background_palette[768];
134 //should be called whenever the palette changes
135 void nm_remap_background()
137 if (!Newmenu_first_time) {
138 if (!nm_background.bm_data)
139 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
141 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
143 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
149 extern char last_palette_loaded[];
151 void nm_draw_background1(char * filename)
158 //@@//I think this only gets called to fill the whole screen
159 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
160 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
162 pcx_error = pcx_get_dimensions(filename, &width, &height);
163 if (pcx_error != PCX_ERROR_NONE)
164 Error("Could not open pcx file <%s>\n", filename);
166 bmp = gr_create_bitmap(width, height);
168 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
169 Assert(pcx_error == PCX_ERROR_NONE);
171 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
174 { //remap stuff. this code is kindof a hack
176 //now, before we bring up the menu, we need to
177 //do some stuff to make sure the palette is ok. First, we need to
178 //get our current palette into the 2d's array, so the remapping will
179 //work. Second, we need to remap the fonts. Third, we need to fill
180 //in part of the fade tables so the darkening of the menu edges works
182 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
184 gr_palette_load(gr_palette);
186 remap_fonts_and_menus(1);
194 strcpy(last_palette_loaded,""); //force palette load next time
198 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
199 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
201 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
203 int Background_hires;
206 void nm_draw_background(int x1, int y1, int x2, int y2 )
210 if (Newmenu_first_time || MenuHires!=Background_hires) {
213 if (Newmenu_first_time) {
214 atexit( newmenu_close );
215 Newmenu_first_time = 0;
216 nm_background_save.bm_data=NULL;
219 if (nm_background_save.bm_data)
220 d_free(nm_background_save.bm_data);
221 if (nm_background.bm_data)
222 d_free(nm_background.bm_data);
225 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
226 Assert(pcx_error == PCX_ERROR_NONE);
228 nm_background = nm_background_save;
229 nm_background.bm_data=NULL;
230 nm_remap_background();
232 Background_hires = MenuHires;
235 if ( x1 < 0 ) x1 = 0;
236 if ( y1 < 0 ) y1 = 0;
241 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
242 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
249 grs_bitmap *tmp = gr_create_bitmap(w, h);
251 gr_bitmap_scale_to(&nm_background, tmp);
254 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
256 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
261 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
263 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
267 Gr_scanline_darkening_level = 2*7;
269 gr_setcolor( BM_XRGB(0,0,0) );
270 gr_urect( x2-5, y1+5, x2-5, y2-5 );
271 gr_urect( x2-4, y1+4, x2-4, y2-5 );
272 gr_urect( x2-3, y1+3, x2-3, y2-5 );
273 gr_urect( x2-2, y1+2, x2-2, y2-5 );
274 gr_urect( x2-1, y1+1, x2-1, y2-5 );
275 gr_urect( x2+0, y1+0, x2-0, y2-5 );
277 gr_urect( x1+5, y2-5, x2, y2-5 );
278 gr_urect( x1+4, y2-4, x2, y2-4 );
279 gr_urect( x1+3, y2-3, x2, y2-3 );
280 gr_urect( x1+2, y2-2, x2, y2-2 );
281 gr_urect( x1+1, y2-1, x2, y2-1 );
282 gr_urect( x1+0, y2, x2, y2-0 );
285 Gr_scanline_darkening_level = GR_FADE_LEVELS;
288 void nm_restore_background( int x, int y, int w, int h )
295 if ( x1 < 0 ) x1 = 0;
296 if ( y1 < 0 ) y1 = 0;
298 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
299 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
304 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
307 // Draw a left justfied string
308 void nm_string( bkg * b, int w1,int x, int y, char * s)
310 int w,h,aw,tx=0,t=0,i;
311 char *p,*s1,*s2,measure[2];
312 int XTabs[]={15,87,124,162,228,253};
318 XTabs[i]=(LHX(XTabs[i]));
325 p = strchr( s2, '\t' );
332 gr_get_string_size(s2, &w, &h, &aw );
338 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
339 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
342 for (i=0;i<strlen(s2);i++) {
343 if (s2[i]=='\t' && SurfingNet) {
349 gr_get_string_size(measure,&tx,&h,&aw);
350 gr_string(x,y,measure);
357 if (!SurfingNet && p && (w1>0) ) {
358 gr_get_string_size(s1, &w, &h, &aw );
360 gr_string( x+w1-w, y, s1 );
367 // Draw a slider and it's string
368 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
375 p = strchr( s, '\t' );
381 gr_get_string_size(s, &w, &h, &aw );
384 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
385 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
387 gr_string( x, y, s );
390 gr_get_string_size(s1, &w, &h, &aw );
393 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
395 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
397 gr_string( x+w1-w, y, s1 );
404 // Draw a left justfied string with black background.
405 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
408 gr_get_string_size(s, &w, &h, &aw );
411 gr_setcolor( BM_XRGB(2,2,2) );
412 gr_rect( x-1, y-1, x-1, y+h-1 );
413 gr_rect( x-1, y-1, x+w1-1, y-1 );
416 gr_setcolor( BM_XRGB(5,5,5) );
417 gr_rect( x, y+h, x+w1, y+h);
418 gr_rect( x+w1, y-1, x+w1, y+h );
420 gr_setcolor( BM_XRGB(0,0,0) );
421 gr_rect( x, y, x+w1-1, y+h-1 );
423 gr_string( x+1, y+1, s );
427 // Draw a right justfied string
428 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
431 gr_get_string_size(s, &w, &h, &aw );
436 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
439 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
440 gr_string( x-w, y, s );
445 //for text items, constantly redraw cursor (to achieve flash)
446 void update_cursor( newmenu_item *item)
449 fix time = timer_get_approx_seconds();
451 char * text = item->text;
453 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
456 gr_get_string_size(text, &w, &h, &aw );
457 if ( w > item->w-10 )
464 x = item->x+w; y = item->y;
467 gr_string( x, y, CURSOR_STRING );
469 gr_setcolor( BM_XRGB(0,0,0) );
470 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
474 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
479 gr_get_string_size(text, &w1, &h1, &aw );
488 nm_string_black( b, w, x, y, text );
491 gr_string( x+w1+1, y, CURSOR_STRING );
495 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
500 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
502 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
504 if (item->text[0]=='\t')
505 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
510 grd_curcanv->cv_font = SELECTED_FONT;
512 grd_curcanv->cv_font = NORMAL_FONT;
515 if (is_current && item->type == NM_TYPE_TEXT)
516 grd_curcanv->cv_font = NORMAL_FONT;
520 switch( item->type ) {
522 // grd_curcanv->cv_font=TEXT_FONT;
523 // fall through on purpose
526 nm_string( b, item->w, item->x, item->y, item->text );
528 case NM_TYPE_SLIDER: {
530 if (item->value < item->min_value) item->value=item->min_value;
531 if (item->value > item->max_value) item->value=item->max_value;
532 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
533 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
534 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
536 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
538 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
540 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
543 case NM_TYPE_INPUT_MENU:
544 if ( item->group==0 ) {
545 nm_string( b, item->w, item->x, item->y, item->text );
547 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
551 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
554 nm_string( b, item->w, item->x, item->y, item->text );
556 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
558 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
561 nm_string( b, item->w, item->x, item->y, item->text );
563 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
565 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
567 case NM_TYPE_NUMBER: {
569 if (item->value < item->min_value) item->value=item->min_value;
570 if (item->value > item->max_value) item->value=item->max_value;
571 nm_string( b, item->w, item->x, item->y, item->text );
572 sprintf( text, "%d", item->value );
573 nm_rstring( b,item->right_offset,item->x, item->y, text );
579 char *Newmenu_allowed_chars=NULL;
581 //returns true if char is allowed
582 int char_allowed(char c)
584 char *p = Newmenu_allowed_chars;
592 if (c>=p[0] && c<=p[1])
601 void strip_end_whitespace( char * text )
604 l = (int)strlen( text );
605 for (i=l-1; i>=0; i-- ) {
606 if ( isspace(text[i]) )
613 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
615 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
617 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
619 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
623 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
625 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
629 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 )
631 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
635 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 )
637 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
639 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 )
641 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
644 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){
645 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
646 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
647 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
650 //returns 1 if a control device button has been pressed
651 int check_button_press()
655 if (Config_control_joystick.intval)
657 if (joy_get_button_down_cnt(i)>0) return 1;
659 #ifndef NEWMENU_MOUSE // don't allow mouse to continue from menu
660 if (Config_control_mouse.intval)
662 if (mouse_button_down_count(i)>0) return 1;
668 extern int network_request_player_names(int);
669 extern int RestoringMenu;
672 ubyte Hack_DblClick_MenuMode=0;
676 extern ubyte joydefs_calibrating;
678 # define joydefs_calibrating 0
681 #define CLOSE_X (MenuHires?15:7)
682 #define CLOSE_Y (MenuHires?15:7)
683 #define CLOSE_SIZE (MenuHires?10:5)
685 void draw_close_box(int x,int y)
687 gr_setcolor( BM_XRGB(0, 0, 0) );
688 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
689 gr_setcolor( BM_XRGB(21, 21, 21) );
690 gr_rect(x + CLOSE_X + LHX(1), y + CLOSE_Y + LHX(1), x + CLOSE_X + CLOSE_SIZE - LHX(1), y + CLOSE_Y + CLOSE_SIZE - LHX(1));
693 extern int Num_bitmap_files;
695 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 )
697 int old_keyd_repeat, done;
698 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
699 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
700 grs_font * save_font;
701 int string_width, string_height = 0, average_width;
704 int all_text=0; //set true if all text items
705 int sound_stopped=0,time_stopped=0;
706 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
709 int MaxOnMenu=MAXDISPLAYABLEITEMS;
710 grs_canvas *save_canvas;
712 int mouse_state, omouse_state, dblclick_flag=0;
713 int mx=0, my=0, x1 = 0, x2, y1, y2;
717 EventRecord event; // looking for disk inserted events for CD mounts
720 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
721 newmenu_hide_cursor();
728 MaxDisplayable=nitems;
730 //set_screen_mode(SCREEN_MENU);
733 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
734 digi_pause_digi_sounds();
738 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
748 save_canvas = grd_curcanv;
750 gr_set_current_canvas(NULL);
752 save_font = grd_curcanv->cv_font;
757 grd_curcanv->cv_font = TITLE_FONT;
758 gr_get_string_size(title,&string_width,&string_height,&average_width );
763 grd_curcanv->cv_font = SUBTITLE_FONT;
764 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
765 if (string_width > tw )
770 th += LHY(8); //put some space between titles & body
773 grd_curcanv->cv_font = SMALL_FONT;
775 grd_curcanv->cv_font = NORMAL_FONT;
779 nmenus = nothers = 0;
781 // Find menu height & width (store in w,h)
782 for (i=0; i<nitems; i++ ) {
785 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
786 item[i].right_offset = 0;
789 string_height+=LHY(3);
791 item[i].saved_text[0] = '\0';
793 if ( item[i].type == NM_TYPE_SLIDER ) {
796 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
797 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
798 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
800 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
801 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
802 string_width += w1 + aw;
805 if ( item[i].type == NM_TYPE_MENU ) {
809 if ( item[i].type == NM_TYPE_CHECK ) {
812 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
813 item[i].right_offset = w1;
814 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
815 if (w1 > item[i].right_offset)
816 item[i].right_offset = w1;
819 if (item[i].type == NM_TYPE_RADIO ) {
822 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
823 item[i].right_offset = w1;
824 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
825 if (w1 > item[i].right_offset)
826 item[i].right_offset = w1;
829 if (item[i].type==NM_TYPE_NUMBER ) {
833 sprintf( test_text, "%d", item[i].max_value );
834 gr_get_string_size( test_text, &w1, &h1, &aw1 );
835 item[i].right_offset = w1;
836 sprintf( test_text, "%d", item[i].min_value );
837 gr_get_string_size( test_text, &w1, &h1, &aw1 );
838 if ( w1 > item[i].right_offset)
839 item[i].right_offset = w1;
842 if ( item[i].type == NM_TYPE_INPUT ) {
843 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
844 strcpy(item[i].saved_text, item[i].text );
846 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
847 if ( string_width > MAX_TEXT_WIDTH )
848 string_width = MAX_TEXT_WIDTH;
852 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
853 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
854 strcpy(item[i].saved_text, item[i].text );
856 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
861 item[i].w = string_width;
862 item[i].h = string_height;
864 if ( string_width > w )
865 w = string_width; // Save maximum width
866 if ( average_width > aw )
868 h += string_height+1; // Find the height of all strings
871 // Big hack for allowing the netgame options menu to spill over
873 MaxOnMenu=MAXDISPLAYABLEITEMS;
874 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
877 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
880 h=(MaxOnMenu*(string_height+1)+LHY(8));
881 MaxDisplayable=MaxOnMenu;
882 mprintf ((0,"Hey, this is a scroll box!\n"));
895 for (i=0; i<nitems; i++ ) {
897 if (item[i].right_offset > right_offset )
898 right_offset = item[i].right_offset;
900 if (right_offset > 0 )
903 //gr_get_string_size("",&string_width,&string_height,&average_width );
910 twidth = ( tw - w )/2;
915 { right_offset=0; twidth=0;}
917 mprintf(( 0, "Right offset = %d\n", right_offset ));
920 // Find min point of menu border
921 // x = (grd_curscreen->sc_w-w)/2;
922 // y = (grd_curscreen->sc_h-h)/2;
924 w += MenuHires?60:30;
925 h += MenuHires?60:30;
927 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
928 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
930 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
931 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
936 if ( filename != NULL ) {
937 nm_draw_background1( filename );
938 gr_palette_load(gr_palette);
941 // Save the background of the display
942 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h );
943 gr_set_current_canvas(bg.menu_canvas);
945 if ( filename == NULL ) {
946 // Save the background under the menu...
952 bg.saved = gr_create_bitmap( w, h );
953 Assert( bg.saved != NULL );
955 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
957 gr_set_current_canvas( NULL );
959 nm_draw_background(x,y,x+w-1,y+h-1);
961 gr_set_current_canvas( bg.menu_canvas );
963 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
967 bg.background = gr_create_bitmap( w, h );
968 Assert( bg.background != NULL );
970 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
973 // ty = 15 + (yborder/4);
975 ty = MenuHires?30:15;
978 grd_curcanv->cv_font = TITLE_FONT;
979 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
980 gr_get_string_size(title,&string_width,&string_height,&average_width );
983 gr_printf( 0x8000, ty, title );
988 grd_curcanv->cv_font = SUBTITLE_FONT;
989 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
990 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
993 gr_printf( 0x8000, ty, subtitle );
998 grd_curcanv->cv_font = SMALL_FONT;
1000 grd_curcanv->cv_font = NORMAL_FONT;
1002 // Update all item's x & y values.
1003 for (i=0; i<nitems; i++ ) {
1004 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1005 item[i].y += (MenuHires?30:15);
1006 if ( item[i].type==NM_TYPE_RADIO ) {
1007 fm = -1; // find first marked one
1008 for ( j=0; j<nitems; j++ ) {
1009 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1010 if (fm==-1 && item[j].value)
1022 old_keyd_repeat = keyd_repeat;
1028 if (citem < 0 ) citem = 0;
1029 if (citem > nitems-1 ) citem = nitems-1;
1032 #ifdef NEWMENU_MOUSE
1036 while ( item[choice].type==NM_TYPE_TEXT ) {
1038 if (choice >= nitems ) {
1041 if (choice == citem ) {
1052 // Clear mouse, joystick to clear button presses.
1053 game_flush_inputs();
1055 #ifdef NEWMENU_MOUSE
1056 mouse_state = omouse_state = 0;
1057 if (filename == NULL && !MenuReordering) {
1058 //draw_close_box(0,0);
1062 if (!MenuReordering && !joydefs_calibrating)
1064 newmenu_show_cursor();
1066 SetCursor(LoadCursor(NULL,IDC_ARROW));
1071 mprintf ((0,"Set to true!\n"));
1074 #ifdef NEWMENU_MOUSE
1075 if (!joydefs_calibrating)
1076 newmenu_show_cursor(); // possibly hidden
1077 omouse_state = mouse_state;
1078 if (!MenuReordering)
1079 mouse_state = mouse_button_state(0);
1080 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1083 //see if redbook song needs to be restarted
1084 songs_check_redbook_repeat();
1091 (*subfunction)(nitems,item,&k,choice);
1094 if (!time_stopped) {
1095 // Save current menu box
1096 if (multi_menu_poll() == -1)
1102 dont_restore = (k == -3); //-3 means don't restore
1107 if (check_button_press())
1110 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1113 old_choice = choice;
1119 if (SurfingNet && !already_showing_info)
1121 show_extra_netgame_info(choice-2);
1123 if (SurfingNet && already_showing_info)
1130 if (SurfingNet && !already_showing_info)
1132 network_request_player_names(choice-2);
1134 if (SurfingNet && already_showing_info)
1149 case KEY_TAB + KEY_SHIFTED:
1152 if (all_text) break;
1159 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1161 if (choice<TopChoice)
1162 { choice=TopChoice; break; }
1164 if (choice<ScrollOffset)
1166 for (i=0;i<nitems;i++)
1169 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1174 if (choice >= nitems ) choice=0;
1175 if (choice < 0 ) choice=nitems-1;
1177 } while ( item[choice].type==NM_TYPE_TEXT );
1178 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1179 item[choice].value = -1;
1180 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1181 item[old_choice].group=0;
1182 strcpy(item[old_choice].text, item[old_choice].saved_text );
1183 item[old_choice].value = -1;
1186 item[old_choice].redraw = 1;
1187 item[choice].redraw=1;
1192 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1193 if (all_text) break;
1200 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1203 { choice--; break; }
1205 if (choice>=MaxOnMenu+ScrollOffset)
1207 for (i=0;i<nitems;i++)
1210 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1215 if (choice < 0 ) choice=nitems-1;
1216 if (choice >= nitems ) choice=0;
1219 } while ( item[choice].type==NM_TYPE_TEXT );
1221 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1222 item[choice].value = -1;
1223 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1224 item[old_choice].group=0;
1225 strcpy(item[old_choice].text, item[old_choice].saved_text );
1226 item[old_choice].value = -1;
1229 item[old_choice].redraw=1;
1230 item[choice].redraw=1;
1233 if ( choice > -1 ) {
1234 switch( item[choice].type ) {
1237 case NM_TYPE_INPUT_MENU:
1240 if ( item[choice].value )
1241 item[choice].value = 0;
1243 item[choice].value = 1;
1244 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1247 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1249 mprintf ((0,"Special redraw!\n"));
1254 item[choice].redraw=1;
1257 for (i=0; i<nitems; i++ ) {
1258 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1263 item[choice].value = 1;
1264 item[choice].redraw = 1;
1270 case KEY_SHIFTED+KEY_UP:
1271 if (MenuReordering && choice!=TopChoice)
1273 Temp=item[choice].text;
1274 TempVal=item[choice].value;
1275 item[choice].text=item[choice-1].text;
1276 item[choice].value=item[choice-1].value;
1277 item[choice-1].text=Temp;
1278 item[choice-1].value=TempVal;
1279 item[choice].redraw=1;
1280 item[choice-1].redraw=1;
1284 case KEY_SHIFTED+KEY_DOWN:
1285 if (MenuReordering && choice!=(nitems-1))
1287 Temp=item[choice].text;
1288 TempVal=item[choice].value;
1289 item[choice].text=item[choice+1].text;
1290 item[choice].value=item[choice+1].value;
1291 item[choice+1].text=Temp;
1292 item[choice+1].value=TempVal;
1293 item[choice].redraw=1;
1294 item[choice+1].redraw=1;
1301 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1302 item[choice].group = 1;
1303 item[choice].redraw = 1;
1304 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1305 item[choice].text[0] = 0;
1306 item[choice].value = -1;
1308 strip_end_whitespace(item[choice].text);
1315 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1316 item[choice].group=0;
1317 strcpy(item[choice].text, item[choice].saved_text );
1318 item[choice].redraw=1;
1319 item[choice].value = -1;
1326 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
1327 case KEY_PRINT_SCREEN:
1328 MAC(newmenu_hide_cursor());
1329 save_screen_shot(0);
1330 for (i=0;i<nitems;i++)
1333 MAC(newmenu_show_cursor());
1339 case KEY_COMMAND+KEY_RIGHT:
1340 songs_goto_next_song();
1342 case KEY_COMMAND+KEY_LEFT:
1343 songs_goto_prev_song();
1345 case KEY_COMMAND+KEY_UP:
1346 songs_play_level_song(1);
1348 case KEY_COMMAND+KEY_DOWN:
1349 songs_stop_redbook();
1352 case KEY_COMMAND+KEY_M:
1354 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1357 key_close(); // no processing of keys with keyboard handler.. jeez
1359 newmenu_hide_cursor();
1360 show_boxed_message ("Mounting CD\nESC to quit");
1361 RBAMountDisk(); // OS has totaly control of the CD.
1362 if (Function_mode == FMODE_MENU)
1363 songs_play_song(SONG_TITLE,1);
1364 else if (Function_mode == FMODE_GAME)
1365 songs_play_level_song( Current_level_num );
1366 clear_boxed_message();
1367 newmenu_show_cursor();
1374 case KEY_COMMAND+KEY_E:
1375 songs_stop_redbook();
1377 k = -1; // force key not to register
1381 case KEY_COMMAND+KEY_Q: {
1382 if ( !(Game_mode & GM_MULTI) )
1384 if (!joydefs_calibrating)
1385 newmenu_show_cursor();
1386 k = -1; // force key not to register
1392 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1397 case KEY_SHIFTED + KEY_B:
1400 grs_canvas *canv_save = grd_curcanv;
1401 grs_canvas *temp_canv;
1404 ubyte pal_save[768];
1406 memcpy(pal_save, gr_palette, 768);
1407 gr_use_palette_table(DEFAULT_LEVEL_PALETTE);
1408 memcpy(bm_pal, gr_palette, 768);
1409 gr_copy_palette(gr_palette, pal_save, 768);
1411 if (k & KEY_SHIFTED)
1417 n = Num_bitmap_files - 1;
1418 n %= Num_bitmap_files;
1419 bm = &GameBitmaps[n];
1420 PIGGY_PAGE_IN( *(bitmap_index *)&n );
1421 con_printf(CON_DEBUG, "showing bitmap %d of %d: %s\n", n, Num_bitmap_files, piggy_game_bitmap_name(bm));
1423 temp_canv = gr_create_canvas(bm->bm_w, bm->bm_h);
1424 gr_set_current_canvas(temp_canv);
1425 gr_bitmap(0, 0, bm);
1426 gr_set_current_canvas(&grd_curscreen->sc_canvas);
1427 gr_remap_bitmap_good(&temp_canv->cv_bitmap, bm_pal, -1, -1);
1428 gr_bitmap(0, 0, &temp_canv->cv_bitmap);
1429 gr_free_canvas(temp_canv);
1430 gr_set_current_canvas(canv_save);
1435 case KEY_SHIFTED + KEY_P:
1437 char *palettes[] = {
1447 static unsigned int palnum = 0;
1449 if (k & KEY_SHIFTED)
1454 palnum %= sizeof(palettes)/sizeof(char *);
1455 load_palette(palettes[palnum], 0, 0);
1463 #ifdef NEWMENU_MOUSE // for mouse selection of menu's etc.
1464 if ( !done && mouse_state && !omouse_state && !all_text ) {
1465 mouse_get_pos(&mx, &my);
1466 for (i=0; i<nitems; i++ ) {
1467 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1468 x2 = x1 + item[i].w;
1469 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1470 y2 = y1 + item[i].h;
1471 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1472 if (i+ScrollOffset != choice) {
1473 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1476 choice = i + ScrollOffset;
1478 switch( item[choice].type ) {
1480 if ( item[choice].value )
1481 item[choice].value = 0;
1483 item[choice].value = 1;
1484 item[choice].redraw=1;
1491 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1493 mprintf ((0,"Special redraw!\n"));
1500 for (i=0; i<nitems; i++ ) {
1501 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1506 item[choice].value = 1;
1507 item[choice].redraw = 1;
1510 item[old_choice].redraw=1;
1516 if (mouse_state && all_text)
1519 if ( !done && mouse_state && !all_text ) {
1520 mouse_get_pos(&mx, &my);
1522 // check possible scrollbar stuff first
1524 int arrow_width, arrow_height, aw;
1526 if (ScrollOffset != 0) {
1527 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1528 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1529 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1530 x1 = x1 - arrow_width;
1531 y2 = y1 + arrow_height;
1532 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1535 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1537 if (choice<ScrollOffset)
1539 for (i=0;i<nitems;i++)
1542 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1546 if (ScrollOffset+MaxDisplayable<nitems) {
1547 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1548 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1549 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1550 x1 = x1 - arrow_width;
1551 y2 = y1 + arrow_height;
1552 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1555 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1557 if (choice>=MaxOnMenu+ScrollOffset)
1559 for (i=0;i<nitems;i++)
1562 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1568 for (i=0; i<nitems; i++ ) {
1569 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1570 x2 = x1 + item[i].w;
1571 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1572 y2 = y1 + item[i].h;
1573 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1574 if (i+ScrollOffset != choice) {
1575 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1578 choice = i + ScrollOffset;
1580 if ( item[choice].type == NM_TYPE_SLIDER ) {
1581 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1 = NULL;
1582 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1584 strcpy(slider_text, item[choice].saved_text);
1585 p = strchr(slider_text, '\t');
1591 gr_get_string_size(s1, &slider_width, &height, &aw);
1592 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1593 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1594 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1596 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1597 x2 = x1 + slider_width + sright_width;
1598 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1599 item[choice].value = item[choice].min_value;
1600 item[choice].redraw = 2;
1601 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1602 item[choice].value = item[choice].max_value;
1603 item[choice].redraw = 2;
1604 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1605 int num_values, value_width, new_value;
1607 num_values = item[choice].max_value - item[choice].min_value + 1;
1608 value_width = (slider_width - sleft_width - sright_width) / num_values;
1609 new_value = (mx - x1 - sleft_width) / value_width;
1610 if ( item[choice].value != new_value ) {
1611 item[choice].value = new_value;
1612 item[choice].redraw = 2;
1618 if (choice == old_choice)
1620 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1621 item[choice].value = -1;
1622 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1623 item[old_choice].group=0;
1624 strcpy(item[old_choice].text, item[old_choice].saved_text );
1625 item[old_choice].value = -1;
1628 item[old_choice].redraw = 1;
1629 item[choice].redraw=1;
1635 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1636 mouse_get_pos(&mx, &my);
1637 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1638 x2 = x1 + item[choice].w;
1639 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1640 y2 = y1 + item[choice].h;
1641 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1642 if (Hack_DblClick_MenuMode) {
1643 if (dblclick_flag) done = 1;
1644 else dblclick_flag = 1;
1650 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1651 item[choice].group = 1;
1652 item[choice].redraw = 1;
1653 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1654 item[choice].text[0] = 0;
1655 item[choice].value = -1;
1657 strip_end_whitespace(item[choice].text);
1661 if ( !done && !mouse_state && omouse_state && close_box ) {
1662 mouse_get_pos(&mx, &my);
1663 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1664 x2 = x1 + CLOSE_SIZE;
1665 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1666 y2 = y1 + CLOSE_SIZE;
1667 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1673 // HACK! Don't redraw loadgame preview
1674 if (RestoringMenu) item[0].redraw = 0;
1675 #endif // NEWMENU_MOUSE
1677 if ( choice > -1 ) {
1680 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1681 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1682 if (item[choice].value == -1)
1683 item[choice].value = (int)strlen(item[choice].text);
1684 if (item[choice].value > 0)
1685 item[choice].value--;
1686 item[choice].text[item[choice].value] = 0;
1687 item[choice].redraw = 1;
1689 ascii = key_to_ascii(k);
1690 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1694 if (item[choice].value==-1) {
1695 item[choice].value = 0;
1698 allowed = char_allowed(ascii);
1700 if (!allowed && ascii==' ' && char_allowed('_')) {
1706 item[choice].text[item[choice].value++] = ascii;
1707 item[choice].text[item[choice].value] = 0;
1708 item[choice].redraw=1;
1712 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1713 ascii = key_to_ascii(k);
1715 int choice1 = choice;
1716 ascii = toupper(ascii);
1720 if (choice1 >= nitems ) choice1=0;
1721 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1722 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1723 (item[choice1].type==NM_TYPE_CHECK) ||
1724 (item[choice1].type==NM_TYPE_RADIO) ||
1725 (item[choice1].type==NM_TYPE_NUMBER) ||
1726 (item[choice1].type==NM_TYPE_SLIDER) )
1727 && (ascii==toupper(ch)) ) {
1731 item[old_choice].redraw=1;
1732 item[choice].redraw=1;
1734 } while (choice1 != choice );
1738 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1739 int ov=item[choice].value;
1744 case KEY_MINUS+KEY_SHIFTED:
1746 item[choice].value -= 1;
1751 case KEY_EQUAL+KEY_SHIFTED:
1753 item[choice].value++;
1758 item[choice].value += 10;
1763 item[choice].value -= 10;
1766 if (ov!=item[choice].value)
1767 item[choice].redraw=1;
1772 gr_set_current_canvas(bg.menu_canvas);
1774 // Redraw everything...
1775 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1777 if (item[i].redraw) // warning! ugly hack below
1779 item[i].y-=((string_height+1)*ScrollOffset);
1780 newmenu_hide_cursor();
1781 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1783 #ifdef NEWMENU_MOUSE
1784 if (!MenuReordering && !joydefs_calibrating)
1785 newmenu_show_cursor();
1787 item[i].y+=((string_height+1)*ScrollOffset);
1789 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1790 update_cursor( &item[i]);
1796 //grd_curcanv->cv_font = NORMAL_FONT;
1798 if (LastScrollCheck!=ScrollOffset)
1800 LastScrollCheck=ScrollOffset;
1801 grd_curcanv->cv_font = SELECTED_FONT;
1803 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1804 sx=item[ScrollOffset].x-(MenuHires?24:12);
1807 if (ScrollOffset!=0)
1808 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1810 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1812 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1813 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1815 if (ScrollOffset+MaxDisplayable<nitems)
1816 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1818 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1824 if ( !dont_restore && gr_palette_faded_out ) {
1825 gr_palette_fade_in( gr_palette, 32, 0 );
1829 newmenu_hide_cursor();
1831 // Restore everything...
1833 gr_set_current_canvas(bg.menu_canvas);
1835 if ( filename == NULL ) {
1836 // Save the background under the menu...
1837 gr_bitmap(0, 0, bg.saved);
1838 gr_free_bitmap(bg.saved);
1839 d_free( bg.background );
1841 if (!dont_restore) //info passed back from subfunction
1842 gr_bitmap(0, 0, bg.background);
1843 gr_free_bitmap(bg.background);
1846 gr_free_sub_canvas( bg.menu_canvas );
1848 gr_set_current_canvas(save_canvas);
1849 grd_curcanv->cv_font = save_font;
1850 keyd_repeat = old_keyd_repeat;
1852 game_flush_inputs();
1863 if ( sound_stopped )
1864 digi_resume_digi_sounds();
1871 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1877 char nm_text[MESSAGEBOX_TEXT_SIZE];
1878 newmenu_item nm_message_items[5];
1880 va_start(args, nchoices );
1882 Assert( nchoices <= 5 );
1884 for (i=0; i<nchoices; i++ ) {
1885 s = va_arg( args, char * );
1886 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1888 format = va_arg( args, char * );
1889 strcpy( nm_text, "" );
1890 vsprintf(nm_text,format,args);
1893 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1895 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1898 int nm_messagebox( char *title, int nchoices, ... )
1904 char nm_text[MESSAGEBOX_TEXT_SIZE];
1905 newmenu_item nm_message_items[5];
1907 va_start(args, nchoices );
1909 Assert( nchoices <= 5 );
1911 for (i=0; i<nchoices; i++ ) {
1912 s = va_arg( args, char * );
1913 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1915 format = va_arg( args, char * );
1916 strcpy( nm_text, "" );
1917 vsprintf(nm_text,format,args);
1920 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1922 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1928 void newmenu_file_sort( int n, char *list )
1935 for (i=incr; i<n; i++ ) {
1938 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1939 memcpy( t, &list[j*14], FILENAME_LEN );
1940 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1941 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1952 void delete_player_saved_games(char * name)
1957 for (i=0;i<10; i++) {
1958 sprintf( filename, PLAYER_DIR "%s.sg%d", name, i );
1959 PHYSFS_delete(filename);
1963 #define MAX_FILES 300
1965 //FIXME: should maybe put globbing ability back?
1966 int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
1972 int NumFiles=0, key,done, citem, ocitem;
1973 char * filenames = NULL;
1974 int NumFiles_displayed = 8;
1975 int first_item = -1, ofirst_item;
1976 int old_keyd_repeat = keyd_repeat;
1979 int demos_deleted=0;
1980 int initialized = 0;
1982 int w_x, w_y, w_w, w_h, title_height;
1983 int box_x, box_y, box_w, box_h;
1984 bkg bg; // background under listbox
1985 #ifdef NEWMENU_MOUSE
1986 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
1987 int mouse2_state, omouse2_state;
1988 int dblclick_flag=0;
1991 int show_up_arrow=0, show_down_arrow=0;
1995 w_x=w_y=w_w=w_h=title_height=0;
1996 box_x=box_y=box_w=box_h=0;
1998 filenames = d_malloc( MAX_FILES * 14 );
1999 if (filenames==NULL) return 0;
2004 if (!stricmp(type, "plr"))
2006 else if (!stricmp(type, "dem"))
2013 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2015 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2020 find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
2021 for (f = find; *f != NULL; f++)
2025 ext = strrchr(*f, '.');
2026 if (!ext || strnicmp(ext, ".plr", 4))
2029 if (NumFiles < MAX_FILES)
2031 strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
2036 p = strchr(&filenames[NumFiles*14], '.');
2046 PHYSFS_freeList(find);
2048 if ( (NumFiles < 1) && demos_deleted ) {
2052 if ( (NumFiles < 1) && demo_mode ) {
2053 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2059 if ( (NumFiles < 2) && player_mode ) {
2061 goto ExitFileMenuEarly;
2068 nm_messagebox(NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND);
2075 // set_screen_mode(SCREEN_MENU);
2078 gr_set_current_canvas(NULL);
2080 grd_curcanv->cv_font = SUBTITLE_FONT;
2085 for (i=0; i<NumFiles; i++ ) {
2087 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2093 gr_get_string_size( title, &w, &h, &aw );
2096 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2100 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2102 w_w += (grd_curfont->ft_w * 4);
2103 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2105 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2106 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2108 w_x = (grd_curcanv->cv_w-w_w)/2;
2109 w_y = (grd_curcanv->cv_h-w_h)/2;
2111 if ( w_x < 0 ) w_x = 0;
2112 if ( w_y < 0 ) w_y = 0;
2114 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2115 box_y = w_y + title_height;
2117 // save the screen behind the menu.
2121 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2122 bg.background = &VR_offscreen_buffer->cv_bitmap;
2124 bg.background = gr_create_bitmap( w_w, w_h );
2126 Assert( bg.background != NULL );
2129 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2132 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2135 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2137 gr_string( 0x8000, w_y+10, title );
2142 if ( !player_mode ) {
2143 newmenu_file_sort( NumFiles, filenames );
2145 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2146 newmenu_file_sort( NumFiles, filenames );
2148 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2150 for ( i=0; i<NumFiles; i++ ) {
2151 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2152 #ifdef NEWMENU_MOUSE
2160 #ifdef NEWMENU_MOUSE
2161 mouse_state = omouse_state = 0;
2162 mouse2_state = omouse2_state = 0;
2163 //draw_close_box(w_x,w_y);
2164 newmenu_show_cursor();
2169 ofirst_item = first_item;
2172 #ifdef NEWMENU_MOUSE
2173 omouse_state = mouse_state;
2174 omouse2_state = mouse2_state;
2175 mouse_state = mouse_button_state(0);
2176 mouse2_state = mouse_button_state(1);
2179 //see if redbook song needs to be restarted
2180 songs_check_redbook_repeat();
2185 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2186 case KEY_PRINT_SCREEN:
2187 MAC(newmenu_hide_cursor());
2188 save_screen_shot(0);
2190 MAC(newmenu_show_cursor());
2194 case KEY_CTRLED+KEY_D:
2195 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2199 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2201 newmenu_hide_cursor();
2203 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2205 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2206 newmenu_show_cursor();
2210 char name[PATH_MAX];
2212 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2216 strcpy(name, demo_mode?DEMO_DIR:"");
2217 strcat(name,&filenames[citem*14]);
2224 if ( !strncmp(name, ".\\", 2) )
2225 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2226 name[i] = name[i+1];
2227 while ( (p = strchr(name, '\\')) )
2232 ret = !PHYSFS_delete(name);
2236 if ((!ret) && player_mode) {
2237 delete_player_saved_games( &filenames[citem*14] );
2242 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2244 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2245 } else if (demo_mode)
2270 citem += NumFiles_displayed;
2274 citem -= NumFiles_displayed;
2277 if (allow_abort_flag) {
2287 case KEY_COMMAND+KEY_Q: {
2288 if ( !(Game_mode & GM_MULTI) )
2293 newmenu_show_cursor();
2301 int ascii = key_to_ascii(key);
2302 if ( ascii < 255 ) {
2305 if (cc1 < 0 ) cc1 = 0;
2306 if (cc1 >= NumFiles ) cc1 = 0;
2308 if ( cc < 0 ) cc = 0;
2309 if ( cc >= NumFiles ) cc = 0;
2310 if ( citem == cc ) break;
2312 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2327 if (citem>=NumFiles)
2330 if (citem< first_item)
2333 if (citem>=( first_item+NumFiles_displayed))
2335 first_item = citem-NumFiles_displayed+1;
2339 if (NumFiles>first_item+NumFiles_displayed)
2350 if (NumFiles <= NumFiles_displayed )
2353 if (first_item>NumFiles-NumFiles_displayed)
2355 first_item = NumFiles-NumFiles_displayed;
2358 if (first_item < 0 ) first_item = 0;
2360 #ifdef NEWMENU_MOUSE
2361 if (mouse_state || mouse2_state) {
2364 mouse_get_pos(&mx, &my);
2365 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2366 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2368 x2 = box_x + box_w - 1;
2369 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2371 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2372 if (i == citem && !mouse2_state) {
2382 if (!mouse_state && omouse_state) {
2385 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2386 mouse_get_pos(&mx, &my);
2388 x2 = box_x + box_w - 1;
2389 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2391 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2392 if (dblclick_flag) done = 1;
2393 else dblclick_flag = 1;
2397 if ( !mouse_state && omouse_state ) {
2398 mouse_get_pos(&mx, &my);
2399 x1 = w_x + CLOSE_X + 2;
2400 x2 = x1 + CLOSE_SIZE - 2;
2401 y1 = w_y + CLOSE_Y + 2;
2402 y2 = y1 + CLOSE_SIZE - 2;
2403 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2412 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2414 y1 = box_y+box_h-LHY(7);
2416 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2423 gr_setcolor( BM_XRGB(2,2,2));
2424 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2425 gr_setcolor( BM_XRGB( 0,0,0) );
2427 if (ofirst_item != first_item) {
2428 newmenu_hide_cursor();
2429 gr_setcolor( BM_XRGB( 0,0,0) );
2430 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2432 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2434 if ( i >= NumFiles ) {
2436 gr_setcolor( BM_XRGB(5,5,5));
2437 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2438 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2440 gr_setcolor( BM_XRGB(2,2,2));
2441 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2443 gr_setcolor( BM_XRGB(0,0,0));
2444 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2448 grd_curcanv->cv_font = SELECTED_FONT;
2450 grd_curcanv->cv_font = NORMAL_FONT;
2451 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2453 gr_setcolor( BM_XRGB(5,5,5));
2454 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2455 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2457 gr_setcolor( BM_XRGB(2,2,2));
2458 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2459 gr_setcolor( BM_XRGB(0,0,0));
2461 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2462 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2465 newmenu_show_cursor();
2466 } else if ( citem != ocitem ) {
2469 newmenu_hide_cursor();
2471 if ( (i>=0) && (i<NumFiles) ) {
2472 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2474 grd_curcanv->cv_font = SELECTED_FONT;
2476 grd_curcanv->cv_font = NORMAL_FONT;
2477 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2478 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2479 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2482 if ( (i>=0) && (i<NumFiles) ) {
2483 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2485 grd_curcanv->cv_font = SELECTED_FONT;
2487 grd_curcanv->cv_font = NORMAL_FONT;
2488 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2489 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2490 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2492 newmenu_show_cursor();
2496 grd_curcanv->cv_font = NORMAL_FONT;
2498 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2502 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2506 if (show_down_arrow)
2507 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2511 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2519 MAC(newmenu_hide_cursor());
2521 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2528 keyd_repeat = old_keyd_repeat;
2530 if ( initialized ) {
2531 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2532 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2533 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2534 gr_free_bitmap(bg.background);
2536 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2548 // Example listbox callback function...
2549 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2553 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2554 // if ( *nitems > 1 ) {
2555 // PHYSFS_delete(items[*citem]); // Delete the file
2556 // for (i=*citem; i<*nitems-1; i++ ) {
2557 // items[i] = items[i+1];
2559 // *nitems = *nitems - 1;
2560 // d_free( items[*nitems] );
2561 // items[*nitems] = NULL;
2562 // return 1; // redraw;
2569 #define LB_ITEMS_ON_SCREEN 8
2571 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2573 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2576 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 ) )
2579 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2580 int old_keyd_repeat = keyd_repeat;
2581 int width, height, wx, wy, title_height, border_size;
2582 int total_width,total_height;
2584 #ifdef NEWMENU_MOUSE
2585 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2586 int close_x,close_y;
2588 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2594 // set_screen_mode(SCREEN_MENU);
2597 gr_set_current_canvas(NULL);
2599 grd_curcanv->cv_font = SUBTITLE_FONT;
2602 for (i=0; i<nitems; i++ ) {
2604 gr_get_string_size( items[i], &w, &h, &aw );
2608 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2612 gr_get_string_size( title, &w, &h, &aw );
2615 title_height = h + 5;
2618 border_size = grd_curfont->ft_w;
2619 WIN (border_size=grd_curfont->ft_w*2);
2621 width += (grd_curfont->ft_w);
2622 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2623 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2625 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2626 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2627 if ( wy < title_height )
2630 total_width = width+2*border_size;
2631 total_height = height+2*border_size+title_height;
2635 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2636 bg.background = &VR_offscreen_buffer->cv_bitmap;
2638 //bg.background = gr_create_bitmap( width, (height + title_height) );
2639 bg.background = gr_create_bitmap(total_width,total_height);
2640 Assert( bg.background != NULL );
2642 //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 );
2643 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2646 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2649 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2651 gr_string( 0x8000, wy - title_height, title );
2654 citem = default_item;
2655 if ( citem < 0 ) citem = 0;
2656 if ( citem >= nitems ) citem = 0;
2660 #ifdef NEWMENU_MOUSE
2661 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2662 close_x = wx-border_size;
2663 close_y = wy-title_height-border_size;
2664 //draw_close_box(close_x,close_y);
2665 newmenu_show_cursor();
2670 ofirst_item = first_item;
2671 #ifdef NEWMENU_MOUSE
2672 omouse_state = mouse_state;
2673 mouse_state = mouse_button_state(0);
2675 //see if redbook song needs to be restarted
2676 songs_check_redbook_repeat();
2680 if ( listbox_callback )
2681 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2695 else if (simukey==1)
2701 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2702 case KEY_PRINT_SCREEN:
2703 MAC(newmenu_hide_cursor());
2704 save_screen_shot(0);
2706 MAC(newmenu_show_cursor());
2727 citem += LB_ITEMS_ON_SCREEN;
2731 citem -= LB_ITEMS_ON_SCREEN;
2734 if (allow_abort_flag) {
2744 case KEY_COMMAND+KEY_Q: {
2745 if ( !(Game_mode & GM_MULTI) )
2747 newmenu_show_cursor();
2754 int ascii = key_to_ascii(key);
2755 if ( ascii < 255 ) {
2758 if (cc1 < 0 ) cc1 = 0;
2759 if (cc1 >= nitems ) cc1 = 0;
2761 if ( cc < 0 ) cc = 0;
2762 if ( cc >= nitems ) cc = 0;
2763 if ( citem == cc ) break;
2765 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2782 if (citem< first_item)
2785 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2786 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2788 if (nitems <= LB_ITEMS_ON_SCREEN )
2791 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
2792 first_item = nitems-LB_ITEMS_ON_SCREEN;
2793 if (first_item < 0 ) first_item = 0;
2796 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
2807 #ifdef NEWMENU_MOUSE
2811 mouse_get_pos(&mx, &my);
2812 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2815 gr_get_string_size(items[i], &w, &h, &aw );
2818 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2820 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2832 //no double-click stuff for listbox
2833 //@@if (!mouse_state && omouse_state) {
2836 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
2837 //@@ mouse_get_pos(&mx, &my);
2839 //@@ x2 = wx + width;
2840 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
2842 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2843 //@@ if (dblclick_flag) done = 1;
2847 //check for close box clicked
2848 if ( !mouse_state && omouse_state ) {
2849 mouse_get_pos(&mx, &my);
2850 x1 = close_x + CLOSE_X + 2;
2851 x2 = x1 + CLOSE_SIZE - 2;
2852 y1 = close_y + CLOSE_Y + 2;
2853 y2 = y1 + CLOSE_SIZE - 2;
2854 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2864 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
2866 y1 = total_height-LHY(7);
2868 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
2876 if ( (ofirst_item != first_item) || redraw) {
2877 newmenu_hide_cursor();
2879 gr_setcolor( BM_XRGB( 0,0,0) );
2880 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2882 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2883 if ( i >= nitems ) {
2884 gr_setcolor( BM_XRGB(0,0,0));
2885 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
2888 grd_curcanv->cv_font = SELECTED_FONT;
2890 grd_curcanv->cv_font = NORMAL_FONT;
2891 gr_get_string_size(items[i], &w, &h, &aw );
2892 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2893 gr_string( wx+5, y, items[i] );
2898 // If Win95 port, draw up/down arrows on left side of menu
2900 grd_curcanv->cv_font = NORMAL_FONT;
2902 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
2906 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
2910 if (show_down_arrow)
2911 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
2915 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
2922 newmenu_show_cursor();
2924 } else if ( citem != ocitem ) {
2927 newmenu_hide_cursor();
2930 if ( (i>=0) && (i<nitems) ) {
2931 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2933 grd_curcanv->cv_font = SELECTED_FONT;
2935 grd_curcanv->cv_font = NORMAL_FONT;
2936 gr_get_string_size(items[i], &w, &h, &aw );
2937 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2938 gr_string( wx+5, y, items[i] );
2942 if ( (i>=0) && (i<nitems) ) {
2943 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2945 grd_curcanv->cv_font = SELECTED_FONT;
2947 grd_curcanv->cv_font = NORMAL_FONT;
2948 gr_get_string_size( items[i], &w, &h, &aw );
2949 gr_rect( wx, y-1, wx+width-1, y+h );
2950 gr_string( wx+5, y, items[i] );
2953 newmenu_show_cursor();
2957 newmenu_hide_cursor();
2959 keyd_repeat = old_keyd_repeat;
2961 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2963 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2964 gr_free_bitmap(bg.background);
2967 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) );
2974 int newmenu_filelist( char * title, char * filespec, char * filename )
2977 char * Filenames[MAX_FILES];
2978 char FilenameText[MAX_FILES][14];
2979 FILEFINDSTRUCT find;
2982 if( !FileFindFirst( filespec, &find ) ) {
2984 if (NumFiles<MAX_FILES) {
2985 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
2986 Filenames[NumFiles] = FilenameText[NumFiles];
2991 } while( !FileFindNext( &find ) );
2995 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
2997 strcpy( filename, Filenames[i] );
3004 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3005 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3011 char nm_text[MESSAGEBOX_TEXT_SIZE];
3012 newmenu_item nm_message_items[5];
3014 va_start(args, nchoices );
3016 Assert( nchoices <= 5 );
3018 for (i=0; i<nchoices; i++ ) {
3019 s = va_arg( args, char * );
3020 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3022 format = va_arg( args, char * );
3023 //sprintf( nm_text, "" ); // adb: ?
3024 vsprintf(nm_text,format,args);
3027 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3029 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3031 //end this section addition - Victor Rachels
3034 extern netgame_info Active_games[];
3035 extern int NumActiveNetgames;
3037 void show_extra_netgame_info(int choice)
3043 if (choice>=NumActiveNetgames)
3048 m[i].text=(char *)&mtext[i];
3049 m[i].type=NM_TYPE_TEXT;
3052 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3053 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3054 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3055 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3057 already_showing_info=1;
3058 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3059 already_showing_info=0;
3064 /* Spiffy word wrap string formatting function */
3066 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3072 tbuf = (char *)d_malloc((unsigned int)strlen(sbuf) + 1);
3075 wordptr = strtok(tbuf, " ");
3076 if (!wordptr) return;
3082 col = col + (int)strlen(wordptr) + 1;
3083 if (col >=line_length) {
3085 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3088 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3090 wordptr = strtok(NULL, " ");