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)
57 #define MAXDISPLAYABLEITEMS 15
59 #define LHX(x) ((x)*(MenuHires?2:1))
60 #define LHY(y) ((y)*(MenuHires?2.4:1))
62 #define TITLE_FONT HUGE_FONT
63 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
64 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
65 #define SUBTITLE_FONT MEDIUM3_FONT
67 #define NORMAL_CHECK_BOX "\x81" // 129
68 #define CHECKED_CHECK_BOX "\x82" // 130
70 #define NORMAL_RADIO_BOX "\x7f" // 127
71 #define CHECKED_RADIO_BOX "\x80" // 128
72 #define CURSOR_STRING "_"
73 #define SLIDER_LEFT "\x83" // 131
74 #define SLIDER_RIGHT "\x84" // 132
75 #define SLIDER_MIDDLE "\x85" // 133
76 #define SLIDER_MARKER "\x86" // 134
77 #define UP_ARROW_MARKER "\x87" // 135
78 #define DOWN_ARROW_MARKER "\x88" // 136
80 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 );
81 void show_extra_netgame_info(int choice);
84 int Newmenu_first_time = 1;
85 //--unused-- int Newmenu_fade_in = 1;
88 grs_canvas * menu_canvas;
89 grs_bitmap * saved; // The background under the menu.
90 grs_bitmap * background;
93 grs_bitmap nm_background,nm_background_save;
95 #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)
96 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
98 ubyte MenuReordering=0;
100 char Pauseable_menu=0;
101 char already_showing_info=0;
104 void newmenu_close() {
105 if ( nm_background.bm_data )
106 d_free(nm_background.bm_data);
108 if ( nm_background_save.bm_data )
109 d_free(nm_background_save.bm_data);
110 Newmenu_first_time = 1;
113 ubyte background_palette[768];
115 //should be called whenever the palette changes
116 void nm_remap_background()
118 if (!Newmenu_first_time) {
119 if (!nm_background.bm_data)
120 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
122 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
124 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
130 extern char last_palette_loaded[];
132 void nm_draw_background1(char * filename)
139 //@@//I think this only gets called to fill the whole screen
140 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
141 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
143 pcx_error = pcx_get_dimensions(filename, &width, &height);
144 if (pcx_error != PCX_ERROR_NONE)
145 Error("Could not open pcx file <%s>\n", filename);
147 bmp = gr_create_bitmap(width, height);
149 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
150 Assert(pcx_error == PCX_ERROR_NONE);
152 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
155 { //remap stuff. this code is kindof a hack
157 //now, before we bring up the menu, we need to
158 //do some stuff to make sure the palette is ok. First, we need to
159 //get our current palette into the 2d's array, so the remapping will
160 //work. Second, we need to remap the fonts. Third, we need to fill
161 //in part of the fade tables so the darkening of the menu edges works
163 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
165 gr_palette_load(gr_palette);
167 remap_fonts_and_menus(1);
175 strcpy(last_palette_loaded,""); //force palette load next time
179 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
180 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
182 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
184 int Background_hires;
187 void nm_draw_background(int x1, int y1, int x2, int y2 )
191 if (Newmenu_first_time || MenuHires!=Background_hires) {
194 if (Newmenu_first_time) {
195 atexit( newmenu_close );
196 Newmenu_first_time = 0;
197 nm_background_save.bm_data=NULL;
200 if (nm_background_save.bm_data)
201 d_free(nm_background_save.bm_data);
202 if (nm_background.bm_data)
203 d_free(nm_background.bm_data);
206 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
207 Assert(pcx_error == PCX_ERROR_NONE);
209 nm_background = nm_background_save;
210 nm_background.bm_data=NULL;
211 nm_remap_background();
213 Background_hires = MenuHires;
216 if ( x1 < 0 ) x1 = 0;
217 if ( y1 < 0 ) y1 = 0;
222 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
223 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
230 grs_bitmap *tmp = gr_create_bitmap(w, h);
232 gr_bitmap_scale_to(&nm_background, tmp);
235 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
237 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
242 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
244 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
248 Gr_scanline_darkening_level = 2*7;
250 gr_setcolor( BM_XRGB(0,0,0) );
251 gr_urect( x2-5, y1+5, x2-5, y2-5 );
252 gr_urect( x2-4, y1+4, x2-4, y2-5 );
253 gr_urect( x2-3, y1+3, x2-3, y2-5 );
254 gr_urect( x2-2, y1+2, x2-2, y2-5 );
255 gr_urect( x2-1, y1+1, x2-1, y2-5 );
256 gr_urect( x2+0, y1+0, x2-0, y2-5 );
258 gr_urect( x1+5, y2-5, x2, y2-5 );
259 gr_urect( x1+4, y2-4, x2, y2-4 );
260 gr_urect( x1+3, y2-3, x2, y2-3 );
261 gr_urect( x1+2, y2-2, x2, y2-2 );
262 gr_urect( x1+1, y2-1, x2, y2-1 );
263 gr_urect( x1+0, y2, x2, y2-0 );
266 Gr_scanline_darkening_level = GR_FADE_LEVELS;
269 void nm_restore_background( int x, int y, int w, int h )
276 if ( x1 < 0 ) x1 = 0;
277 if ( y1 < 0 ) y1 = 0;
279 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
280 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
285 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
288 // Draw a left justfied string
289 void nm_string( bkg * b, int w1,int x, int y, char * s)
291 int w,h,aw,tx=0,t=0,i;
292 char *p,*s1,*s2,measure[2];
293 int XTabs[]={15,87,124,162,228,253};
299 XTabs[i]=(LHX(XTabs[i]));
306 p = strchr( s2, '\t' );
313 gr_get_string_size(s2, &w, &h, &aw );
319 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
320 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
323 for (i=0;i<strlen(s2);i++) {
324 if (s2[i]=='\t' && SurfingNet) {
330 gr_get_string_size(measure,&tx,&h,&aw);
331 gr_string(x,y,measure);
338 if (!SurfingNet && p && (w1>0) ) {
339 gr_get_string_size(s1, &w, &h, &aw );
341 gr_string( x+w1-w, y, s1 );
348 // Draw a slider and it's string
349 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
356 p = strchr( s, '\t' );
362 gr_get_string_size(s, &w, &h, &aw );
365 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
366 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
368 gr_string( x, y, s );
371 gr_get_string_size(s1, &w, &h, &aw );
374 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
376 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
378 gr_string( x+w1-w, y, s1 );
385 // Draw a left justfied string with black background.
386 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
389 gr_get_string_size(s, &w, &h, &aw );
392 gr_setcolor( BM_XRGB(2,2,2) );
393 gr_rect( x-1, y-1, x-1, y+h-1 );
394 gr_rect( x-1, y-1, x+w1-1, y-1 );
397 gr_setcolor( BM_XRGB(5,5,5) );
398 gr_rect( x, y+h, x+w1, y+h);
399 gr_rect( x+w1, y-1, x+w1, y+h );
401 gr_setcolor( BM_XRGB(0,0,0) );
402 gr_rect( x, y, x+w1-1, y+h-1 );
404 gr_string( x+1, y+1, s );
408 // Draw a right justfied string
409 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
412 gr_get_string_size(s, &w, &h, &aw );
417 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
420 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
421 gr_string( x-w, y, s );
426 //for text items, constantly redraw cursor (to achieve flash)
427 void update_cursor( newmenu_item *item)
430 fix time = timer_get_approx_seconds();
432 char * text = item->text;
434 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
437 gr_get_string_size(text, &w, &h, &aw );
438 if ( w > item->w-10 )
445 x = item->x+w; y = item->y;
448 gr_string( x, y, CURSOR_STRING );
450 gr_setcolor( BM_XRGB(0,0,0) );
451 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
455 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
460 gr_get_string_size(text, &w1, &h1, &aw );
469 nm_string_black( b, w, x, y, text );
472 gr_string( x+w1+1, y, CURSOR_STRING );
476 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
481 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
483 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
485 if (item->text[0]=='\t')
486 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
491 grd_curcanv->cv_font = SELECTED_FONT;
493 grd_curcanv->cv_font = NORMAL_FONT;
496 if (is_current && item->type == NM_TYPE_TEXT)
497 grd_curcanv->cv_font = NORMAL_FONT;
501 switch( item->type ) {
503 // grd_curcanv->cv_font=TEXT_FONT;
504 // fall through on purpose
507 nm_string( b, item->w, item->x, item->y, item->text );
509 case NM_TYPE_SLIDER: {
511 if (item->value < item->min_value) item->value=item->min_value;
512 if (item->value > item->max_value) item->value=item->max_value;
513 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
514 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
515 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
517 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
519 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
521 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
524 case NM_TYPE_INPUT_MENU:
525 if ( item->group==0 ) {
526 nm_string( b, item->w, item->x, item->y, item->text );
528 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
532 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
535 nm_string( b, item->w, item->x, item->y, item->text );
537 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
539 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
542 nm_string( b, item->w, item->x, item->y, item->text );
544 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
546 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
548 case NM_TYPE_NUMBER: {
550 if (item->value < item->min_value) item->value=item->min_value;
551 if (item->value > item->max_value) item->value=item->max_value;
552 nm_string( b, item->w, item->x, item->y, item->text );
553 sprintf( text, "%d", item->value );
554 nm_rstring( b,item->right_offset,item->x, item->y, text );
560 char *Newmenu_allowed_chars=NULL;
562 //returns true if char is allowed
563 int char_allowed(char c)
565 char *p = Newmenu_allowed_chars;
573 if (c>=p[0] && c<=p[1])
582 void strip_end_whitespace( char * text )
585 l = (int)strlen( text );
586 for (i=l-1; i>=0; i-- ) {
587 if ( isspace(text[i]) )
594 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
596 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
598 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
600 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
604 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
606 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
610 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 )
612 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
616 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 )
618 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
620 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 )
622 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
625 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){
626 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
627 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
628 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
632 // use menu with joystick
633 int newmenu_inkey(void)
639 if ( !Config_control_joystick.intval || key < KEY_JB1 || key > 255 ) // not using joystick, not a joystick button, or modifier pressed
642 if ( strlen(key_text[key]) > 5 && key_text[key][0] == 'J' && key_text[key][2] == 'H' ) // joystick hat
643 switch (key_text[key][4]) {
644 case 'U': key = KEY_UP; break;
645 case 'R': key = KEY_RIGHT; break;
646 case 'D': key = KEY_DOWN; break;
647 case 'L': key = KEY_LEFT; break;
649 else if ( strlen(key_text[key]) > 3 && key_text[key][0] == 'J' && key_text[key][2] == 'B' ) // joystick button
650 switch (key_text[key][3]) {
651 case '1': key = KEY_SPACEBAR; break;
652 case '2': key = KEY_ENTER; break;
653 case '3': key = KEY_ESC; break;
661 while (!key_checkch())
664 return newmenu_inkey();
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();
1088 k = newmenu_inkey();
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
1108 #ifndef NEWMENU_MOUSE // don't allow mouse to continue from menu
1109 if (Config_control_mouse.intval)
1110 for ( i = 0; i < 3; i++ )
1111 if (mouse_button_down_count(i) > 0)
1115 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1118 old_choice = choice;
1120 // More versatile menu navigation
1123 switch (item[choice].type) {
1125 case NM_TYPE_INPUT_MENU:
1135 switch (item[choice].type) {
1139 case NM_TYPE_INPUT_MENU:
1150 if (SurfingNet && !already_showing_info)
1152 show_extra_netgame_info(choice-2);
1154 if (SurfingNet && already_showing_info)
1161 if (SurfingNet && !already_showing_info)
1163 network_request_player_names(choice-2);
1165 if (SurfingNet && already_showing_info)
1180 case KEY_TAB + KEY_SHIFTED:
1183 if (all_text) break;
1190 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1192 if (choice<TopChoice)
1193 { choice=TopChoice; break; }
1195 if (choice<ScrollOffset)
1197 for (i=0;i<nitems;i++)
1200 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1205 if (choice >= nitems ) choice=0;
1206 if (choice < 0 ) choice=nitems-1;
1208 } while ( item[choice].type==NM_TYPE_TEXT );
1209 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1210 item[choice].value = -1;
1211 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1212 item[old_choice].group=0;
1213 strcpy(item[old_choice].text, item[old_choice].saved_text );
1214 item[old_choice].value = -1;
1217 item[old_choice].redraw = 1;
1218 item[choice].redraw=1;
1223 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1224 if (all_text) break;
1231 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1234 { choice--; break; }
1236 if (choice>=MaxOnMenu+ScrollOffset)
1238 for (i=0;i<nitems;i++)
1241 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1246 if (choice < 0 ) choice=nitems-1;
1247 if (choice >= nitems ) choice=0;
1250 } while ( item[choice].type==NM_TYPE_TEXT );
1252 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1253 item[choice].value = -1;
1254 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1255 item[old_choice].group=0;
1256 strcpy(item[old_choice].text, item[old_choice].saved_text );
1257 item[old_choice].value = -1;
1260 item[old_choice].redraw=1;
1261 item[choice].redraw=1;
1264 if ( choice > -1 ) {
1265 switch( item[choice].type ) {
1268 case NM_TYPE_INPUT_MENU:
1271 if ( item[choice].value )
1272 item[choice].value = 0;
1274 item[choice].value = 1;
1275 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1278 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1280 mprintf ((0,"Special redraw!\n"));
1285 item[choice].redraw=1;
1288 for (i=0; i<nitems; i++ ) {
1289 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1294 item[choice].value = 1;
1295 item[choice].redraw = 1;
1301 case KEY_SHIFTED+KEY_UP:
1302 if (MenuReordering && choice!=TopChoice)
1304 Temp=item[choice].text;
1305 TempVal=item[choice].value;
1306 item[choice].text=item[choice-1].text;
1307 item[choice].value=item[choice-1].value;
1308 item[choice-1].text=Temp;
1309 item[choice-1].value=TempVal;
1310 item[choice].redraw=1;
1311 item[choice-1].redraw=1;
1315 case KEY_SHIFTED+KEY_DOWN:
1316 if (MenuReordering && choice!=(nitems-1))
1318 Temp=item[choice].text;
1319 TempVal=item[choice].value;
1320 item[choice].text=item[choice+1].text;
1321 item[choice].value=item[choice+1].value;
1322 item[choice+1].text=Temp;
1323 item[choice+1].value=TempVal;
1324 item[choice].redraw=1;
1325 item[choice+1].redraw=1;
1332 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1333 item[choice].group = 1;
1334 item[choice].redraw = 1;
1335 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1336 item[choice].text[0] = 0;
1337 item[choice].value = -1;
1339 strip_end_whitespace(item[choice].text);
1346 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1347 item[choice].group=0;
1348 strcpy(item[choice].text, item[choice].saved_text );
1349 item[choice].redraw=1;
1350 item[choice].value = -1;
1357 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
1358 case KEY_PRINT_SCREEN:
1359 MAC(newmenu_hide_cursor());
1360 save_screen_shot(0);
1361 for (i=0;i<nitems;i++)
1364 MAC(newmenu_show_cursor());
1370 case KEY_COMMAND+KEY_RIGHT:
1371 songs_goto_next_song();
1373 case KEY_COMMAND+KEY_LEFT:
1374 songs_goto_prev_song();
1376 case KEY_COMMAND+KEY_UP:
1377 songs_play_level_song(1);
1379 case KEY_COMMAND+KEY_DOWN:
1380 songs_stop_redbook();
1383 case KEY_COMMAND+KEY_M:
1385 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1388 key_close(); // no processing of keys with keyboard handler.. jeez
1390 newmenu_hide_cursor();
1391 show_boxed_message ("Mounting CD\nESC to quit");
1392 RBAMountDisk(); // OS has totaly control of the CD.
1393 if (Function_mode == FMODE_MENU)
1394 songs_play_song(SONG_TITLE,1);
1395 else if (Function_mode == FMODE_GAME)
1396 songs_play_level_song( Current_level_num );
1397 clear_boxed_message();
1398 newmenu_show_cursor();
1405 case KEY_COMMAND+KEY_E:
1406 songs_stop_redbook();
1408 k = -1; // force key not to register
1412 case KEY_COMMAND+KEY_Q: {
1413 if ( !(Game_mode & GM_MULTI) )
1415 if (!joydefs_calibrating)
1416 newmenu_show_cursor();
1417 k = -1; // force key not to register
1423 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1428 case KEY_SHIFTED + KEY_B:
1431 grs_canvas *canv_save = grd_curcanv;
1432 grs_canvas *temp_canv;
1435 ubyte pal_save[768];
1437 memcpy(pal_save, gr_palette, 768);
1438 gr_use_palette_table(DEFAULT_LEVEL_PALETTE);
1439 memcpy(bm_pal, gr_palette, 768);
1440 gr_copy_palette(gr_palette, pal_save, 768);
1442 if (k & KEY_SHIFTED)
1448 n = Num_bitmap_files - 1;
1449 n %= Num_bitmap_files;
1450 bm = &GameBitmaps[n];
1451 PIGGY_PAGE_IN( *(bitmap_index *)&n );
1452 con_printf(CON_DEBUG, "showing bitmap %d of %d: %s\n", n, Num_bitmap_files, piggy_game_bitmap_name(bm));
1454 temp_canv = gr_create_canvas(bm->bm_w, bm->bm_h);
1455 gr_set_current_canvas(temp_canv);
1456 gr_bitmap(0, 0, bm);
1457 gr_set_current_canvas(&grd_curscreen->sc_canvas);
1458 gr_remap_bitmap_good(&temp_canv->cv_bitmap, bm_pal, -1, -1);
1459 gr_bitmap(0, 0, &temp_canv->cv_bitmap);
1460 gr_free_canvas(temp_canv);
1461 gr_set_current_canvas(canv_save);
1466 case KEY_SHIFTED + KEY_P:
1468 char *palettes[] = {
1478 static unsigned int palnum = 0;
1480 if (k & KEY_SHIFTED)
1485 palnum %= sizeof(palettes)/sizeof(char *);
1486 load_palette(palettes[palnum], 0, 0);
1494 #ifdef NEWMENU_MOUSE // for mouse selection of menu's etc.
1495 if ( !done && mouse_state && !omouse_state && !all_text ) {
1496 mouse_get_pos(&mx, &my);
1497 for (i=0; i<nitems; i++ ) {
1498 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1499 x2 = x1 + item[i].w;
1500 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1501 y2 = y1 + item[i].h;
1502 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1503 if (i+ScrollOffset != choice) {
1504 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1507 choice = i + ScrollOffset;
1509 switch( item[choice].type ) {
1511 if ( item[choice].value )
1512 item[choice].value = 0;
1514 item[choice].value = 1;
1515 item[choice].redraw=1;
1522 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1524 mprintf ((0,"Special redraw!\n"));
1531 for (i=0; i<nitems; i++ ) {
1532 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1537 item[choice].value = 1;
1538 item[choice].redraw = 1;
1541 item[old_choice].redraw=1;
1547 if (mouse_state && all_text)
1550 if ( !done && mouse_state && !all_text ) {
1551 mouse_get_pos(&mx, &my);
1553 // check possible scrollbar stuff first
1555 int arrow_width, arrow_height, aw;
1557 if (ScrollOffset != 0) {
1558 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1559 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1560 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1561 x1 = x1 - arrow_width;
1562 y2 = y1 + arrow_height;
1563 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1566 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1568 if (choice<ScrollOffset)
1570 for (i=0;i<nitems;i++)
1573 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1577 if (ScrollOffset+MaxDisplayable<nitems) {
1578 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1579 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1580 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1581 x1 = x1 - arrow_width;
1582 y2 = y1 + arrow_height;
1583 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1586 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1588 if (choice>=MaxOnMenu+ScrollOffset)
1590 for (i=0;i<nitems;i++)
1593 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1599 for (i=0; i<nitems; i++ ) {
1600 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1601 x2 = x1 + item[i].w;
1602 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1603 y2 = y1 + item[i].h;
1604 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1605 if (i+ScrollOffset != choice) {
1606 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1609 choice = i + ScrollOffset;
1611 if ( item[choice].type == NM_TYPE_SLIDER ) {
1612 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1 = NULL;
1613 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1615 strcpy(slider_text, item[choice].saved_text);
1616 p = strchr(slider_text, '\t');
1622 gr_get_string_size(s1, &slider_width, &height, &aw);
1623 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1624 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1625 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1627 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1628 x2 = x1 + slider_width + sright_width;
1629 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1630 item[choice].value = item[choice].min_value;
1631 item[choice].redraw = 2;
1632 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1633 item[choice].value = item[choice].max_value;
1634 item[choice].redraw = 2;
1635 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1636 int num_values, value_width, new_value;
1638 num_values = item[choice].max_value - item[choice].min_value + 1;
1639 value_width = (slider_width - sleft_width - sright_width) / num_values;
1640 new_value = (mx - x1 - sleft_width) / value_width;
1641 if ( item[choice].value != new_value ) {
1642 item[choice].value = new_value;
1643 item[choice].redraw = 2;
1649 if (choice == old_choice)
1651 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1652 item[choice].value = -1;
1653 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1654 item[old_choice].group=0;
1655 strcpy(item[old_choice].text, item[old_choice].saved_text );
1656 item[old_choice].value = -1;
1659 item[old_choice].redraw = 1;
1660 item[choice].redraw=1;
1666 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1667 mouse_get_pos(&mx, &my);
1668 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1669 x2 = x1 + item[choice].w;
1670 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1671 y2 = y1 + item[choice].h;
1672 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1673 if (Hack_DblClick_MenuMode) {
1674 if (dblclick_flag) done = 1;
1675 else dblclick_flag = 1;
1681 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1682 item[choice].group = 1;
1683 item[choice].redraw = 1;
1684 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1685 item[choice].text[0] = 0;
1686 item[choice].value = -1;
1688 strip_end_whitespace(item[choice].text);
1692 if ( !done && !mouse_state && omouse_state && close_box ) {
1693 mouse_get_pos(&mx, &my);
1694 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1695 x2 = x1 + CLOSE_SIZE;
1696 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1697 y2 = y1 + CLOSE_SIZE;
1698 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1704 // HACK! Don't redraw loadgame preview
1705 if (RestoringMenu) item[0].redraw = 0;
1706 #endif // NEWMENU_MOUSE
1708 if ( choice > -1 ) {
1711 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1712 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1713 if (item[choice].value == -1)
1714 item[choice].value = (int)strlen(item[choice].text);
1715 if (item[choice].value > 0)
1716 item[choice].value--;
1717 item[choice].text[item[choice].value] = 0;
1718 item[choice].redraw = 1;
1720 ascii = key_to_ascii(k);
1721 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1725 if (item[choice].value==-1) {
1726 item[choice].value = 0;
1729 allowed = char_allowed(ascii);
1731 if (!allowed && ascii==' ' && char_allowed('_')) {
1737 item[choice].text[item[choice].value++] = ascii;
1738 item[choice].text[item[choice].value] = 0;
1739 item[choice].redraw=1;
1743 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1744 ascii = key_to_ascii(k);
1746 int choice1 = choice;
1747 ascii = toupper(ascii);
1751 if (choice1 >= nitems ) choice1=0;
1752 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1753 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1754 (item[choice1].type==NM_TYPE_CHECK) ||
1755 (item[choice1].type==NM_TYPE_RADIO) ||
1756 (item[choice1].type==NM_TYPE_NUMBER) ||
1757 (item[choice1].type==NM_TYPE_SLIDER) )
1758 && (ascii==toupper(ch)) ) {
1762 item[old_choice].redraw=1;
1763 item[choice].redraw=1;
1765 } while (choice1 != choice );
1769 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1770 int ov=item[choice].value;
1775 case KEY_MINUS+KEY_SHIFTED:
1777 item[choice].value -= 1;
1782 case KEY_EQUAL+KEY_SHIFTED:
1784 item[choice].value++;
1789 item[choice].value += 10;
1794 item[choice].value -= 10;
1797 if (ov!=item[choice].value)
1798 item[choice].redraw=1;
1803 gr_set_current_canvas(bg.menu_canvas);
1805 // Redraw everything...
1806 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1808 if (item[i].redraw) // warning! ugly hack below
1810 item[i].y-=((string_height+1)*ScrollOffset);
1811 newmenu_hide_cursor();
1812 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1814 #ifdef NEWMENU_MOUSE
1815 if (!MenuReordering && !joydefs_calibrating)
1816 newmenu_show_cursor();
1818 item[i].y+=((string_height+1)*ScrollOffset);
1820 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1821 update_cursor( &item[i]);
1827 //grd_curcanv->cv_font = NORMAL_FONT;
1829 if (LastScrollCheck!=ScrollOffset)
1831 LastScrollCheck=ScrollOffset;
1832 grd_curcanv->cv_font = SELECTED_FONT;
1834 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1835 sx=item[ScrollOffset].x-(MenuHires?24:12);
1838 if (ScrollOffset!=0)
1839 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1841 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1843 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1844 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1846 if (ScrollOffset+MaxDisplayable<nitems)
1847 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1849 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1855 if ( !dont_restore && gr_palette_faded_out ) {
1856 gr_palette_fade_in( gr_palette, 32, 0 );
1860 newmenu_hide_cursor();
1862 // Restore everything...
1864 gr_set_current_canvas(bg.menu_canvas);
1866 if ( filename == NULL ) {
1867 // Save the background under the menu...
1868 gr_bitmap(0, 0, bg.saved);
1869 gr_free_bitmap(bg.saved);
1870 d_free( bg.background );
1872 if (!dont_restore) //info passed back from subfunction
1873 gr_bitmap(0, 0, bg.background);
1874 gr_free_bitmap(bg.background);
1877 gr_free_sub_canvas( bg.menu_canvas );
1879 gr_set_current_canvas(save_canvas);
1880 grd_curcanv->cv_font = save_font;
1881 keyd_repeat = old_keyd_repeat;
1883 game_flush_inputs();
1894 if ( sound_stopped )
1895 digi_resume_digi_sounds();
1902 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1908 char nm_text[MESSAGEBOX_TEXT_SIZE];
1909 newmenu_item nm_message_items[5];
1911 va_start(args, nchoices );
1913 Assert( nchoices <= 5 );
1915 for (i=0; i<nchoices; i++ ) {
1916 s = va_arg( args, char * );
1917 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1919 format = va_arg( args, char * );
1920 strcpy( nm_text, "" );
1921 vsprintf(nm_text,format,args);
1924 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1926 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1929 int nm_messagebox( char *title, int nchoices, ... )
1935 char nm_text[MESSAGEBOX_TEXT_SIZE];
1936 newmenu_item nm_message_items[5];
1938 va_start(args, nchoices );
1940 Assert( nchoices <= 5 );
1942 for (i=0; i<nchoices; i++ ) {
1943 s = va_arg( args, char * );
1944 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1946 format = va_arg( args, char * );
1947 strcpy( nm_text, "" );
1948 vsprintf(nm_text,format,args);
1951 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1953 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1959 void newmenu_file_sort( int n, char *list )
1966 for (i=incr; i<n; i++ ) {
1969 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1970 memcpy( t, &list[j*14], FILENAME_LEN );
1971 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1972 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1983 void delete_player_saved_games(char * name)
1988 for (i=0;i<10; i++) {
1989 sprintf( filename, PLAYER_DIR "%s.sg%d", name, i );
1990 PHYSFS_delete(filename);
1994 #define MAX_FILES 300
1996 //FIXME: should maybe put globbing ability back?
1997 int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
2003 int NumFiles=0, key,done, citem, ocitem;
2004 char * filenames = NULL;
2005 int NumFiles_displayed = 8;
2006 int first_item = -1, ofirst_item;
2007 int old_keyd_repeat = keyd_repeat;
2010 int demos_deleted=0;
2011 int initialized = 0;
2013 int w_x, w_y, w_w, w_h, title_height;
2014 int box_x, box_y, box_w, box_h;
2015 bkg bg; // background under listbox
2016 #ifdef NEWMENU_MOUSE
2017 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2018 int mouse2_state, omouse2_state;
2019 int dblclick_flag=0;
2022 int show_up_arrow=0, show_down_arrow=0;
2026 w_x=w_y=w_w=w_h=title_height=0;
2027 box_x=box_y=box_w=box_h=0;
2029 filenames = d_malloc( MAX_FILES * 14 );
2030 if (filenames==NULL) return 0;
2035 if (!stricmp(type, "plr"))
2037 else if (!stricmp(type, "dem"))
2044 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2046 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2051 find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
2052 for (f = find; *f != NULL; f++)
2056 ext = strrchr(*f, '.');
2057 if (!ext || strnicmp(ext, ".plr", 4))
2060 if (NumFiles < MAX_FILES)
2062 strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
2067 p = strchr(&filenames[NumFiles*14], '.');
2077 PHYSFS_freeList(find);
2079 if ( (NumFiles < 1) && demos_deleted ) {
2083 if ( (NumFiles < 1) && demo_mode ) {
2084 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2090 if ( (NumFiles < 2) && player_mode ) {
2092 goto ExitFileMenuEarly;
2099 nm_messagebox(NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND);
2106 // set_screen_mode(SCREEN_MENU);
2109 gr_set_current_canvas(NULL);
2111 grd_curcanv->cv_font = SUBTITLE_FONT;
2116 for (i=0; i<NumFiles; i++ ) {
2118 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2124 gr_get_string_size( title, &w, &h, &aw );
2127 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2131 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2133 w_w += (grd_curfont->ft_w * 4);
2134 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2136 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2137 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2139 w_x = (grd_curcanv->cv_w-w_w)/2;
2140 w_y = (grd_curcanv->cv_h-w_h)/2;
2142 if ( w_x < 0 ) w_x = 0;
2143 if ( w_y < 0 ) w_y = 0;
2145 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2146 box_y = w_y + title_height;
2148 // save the screen behind the menu.
2152 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2153 bg.background = &VR_offscreen_buffer->cv_bitmap;
2155 bg.background = gr_create_bitmap( w_w, w_h );
2157 Assert( bg.background != NULL );
2160 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2163 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2166 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2168 gr_string( 0x8000, w_y+10, title );
2173 if ( !player_mode ) {
2174 newmenu_file_sort( NumFiles, filenames );
2176 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2177 newmenu_file_sort( NumFiles, filenames );
2179 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2181 for ( i=0; i<NumFiles; i++ ) {
2182 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2183 #ifdef NEWMENU_MOUSE
2191 #ifdef NEWMENU_MOUSE
2192 mouse_state = omouse_state = 0;
2193 mouse2_state = omouse2_state = 0;
2194 //draw_close_box(w_x,w_y);
2195 newmenu_show_cursor();
2200 ofirst_item = first_item;
2203 #ifdef NEWMENU_MOUSE
2204 omouse_state = mouse_state;
2205 omouse2_state = mouse2_state;
2206 mouse_state = mouse_button_state(0);
2207 mouse2_state = mouse_button_state(1);
2210 //see if redbook song needs to be restarted
2211 songs_check_redbook_repeat();
2213 key = newmenu_inkey();
2216 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2217 case KEY_PRINT_SCREEN:
2218 MAC(newmenu_hide_cursor());
2219 save_screen_shot(0);
2221 MAC(newmenu_show_cursor());
2225 case KEY_CTRLED+KEY_D:
2226 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2230 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2232 newmenu_hide_cursor();
2234 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2236 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2237 newmenu_show_cursor();
2241 char name[PATH_MAX];
2243 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2247 strcpy(name, demo_mode?DEMO_DIR:"");
2248 strcat(name,&filenames[citem*14]);
2255 if ( !strncmp(name, ".\\", 2) )
2256 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2257 name[i] = name[i+1];
2258 while ( (p = strchr(name, '\\')) )
2263 ret = !PHYSFS_delete(name);
2267 if ((!ret) && player_mode) {
2268 delete_player_saved_games( &filenames[citem*14] );
2273 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2275 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2276 } else if (demo_mode)
2301 citem += NumFiles_displayed;
2305 citem -= NumFiles_displayed;
2309 if (allow_abort_flag) {
2320 case KEY_COMMAND+KEY_Q: {
2321 if ( !(Game_mode & GM_MULTI) )
2326 newmenu_show_cursor();
2334 int ascii = key_to_ascii(key);
2335 if ( ascii < 255 ) {
2338 if (cc1 < 0 ) cc1 = 0;
2339 if (cc1 >= NumFiles ) cc1 = 0;
2341 if ( cc < 0 ) cc = 0;
2342 if ( cc >= NumFiles ) cc = 0;
2343 if ( citem == cc ) break;
2345 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2360 if (citem>=NumFiles)
2363 if (citem< first_item)
2366 if (citem>=( first_item+NumFiles_displayed))
2368 first_item = citem-NumFiles_displayed+1;
2372 if (NumFiles>first_item+NumFiles_displayed)
2383 if (NumFiles <= NumFiles_displayed )
2386 if (first_item>NumFiles-NumFiles_displayed)
2388 first_item = NumFiles-NumFiles_displayed;
2391 if (first_item < 0 ) first_item = 0;
2393 #ifdef NEWMENU_MOUSE
2394 if (mouse_state || mouse2_state) {
2397 mouse_get_pos(&mx, &my);
2398 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2399 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2401 x2 = box_x + box_w - 1;
2402 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2404 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2405 if (i == citem && !mouse2_state) {
2415 if (!mouse_state && omouse_state) {
2418 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2419 mouse_get_pos(&mx, &my);
2421 x2 = box_x + box_w - 1;
2422 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2424 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2425 if (dblclick_flag) done = 1;
2426 else dblclick_flag = 1;
2430 if ( !mouse_state && omouse_state ) {
2431 mouse_get_pos(&mx, &my);
2432 x1 = w_x + CLOSE_X + 2;
2433 x2 = x1 + CLOSE_SIZE - 2;
2434 y1 = w_y + CLOSE_Y + 2;
2435 y2 = y1 + CLOSE_SIZE - 2;
2436 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2445 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2447 y1 = box_y+box_h-LHY(7);
2449 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2456 gr_setcolor( BM_XRGB(2,2,2));
2457 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2458 gr_setcolor( BM_XRGB( 0,0,0) );
2460 if (ofirst_item != first_item) {
2461 newmenu_hide_cursor();
2462 gr_setcolor( BM_XRGB( 0,0,0) );
2463 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2465 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2467 if ( i >= NumFiles ) {
2469 gr_setcolor( BM_XRGB(5,5,5));
2470 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2471 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2473 gr_setcolor( BM_XRGB(2,2,2));
2474 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2476 gr_setcolor( BM_XRGB(0,0,0));
2477 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2481 grd_curcanv->cv_font = SELECTED_FONT;
2483 grd_curcanv->cv_font = NORMAL_FONT;
2484 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2486 gr_setcolor( BM_XRGB(5,5,5));
2487 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2488 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2490 gr_setcolor( BM_XRGB(2,2,2));
2491 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2492 gr_setcolor( BM_XRGB(0,0,0));
2494 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2495 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2498 newmenu_show_cursor();
2499 } else if ( citem != ocitem ) {
2502 newmenu_hide_cursor();
2504 if ( (i>=0) && (i<NumFiles) ) {
2505 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2507 grd_curcanv->cv_font = SELECTED_FONT;
2509 grd_curcanv->cv_font = NORMAL_FONT;
2510 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2511 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2512 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2515 if ( (i>=0) && (i<NumFiles) ) {
2516 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2518 grd_curcanv->cv_font = SELECTED_FONT;
2520 grd_curcanv->cv_font = NORMAL_FONT;
2521 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2522 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2523 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2525 newmenu_show_cursor();
2529 grd_curcanv->cv_font = NORMAL_FONT;
2531 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2535 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2539 if (show_down_arrow)
2540 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2544 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2552 MAC(newmenu_hide_cursor());
2554 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2561 keyd_repeat = old_keyd_repeat;
2563 if ( initialized ) {
2564 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2565 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2566 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2567 gr_free_bitmap(bg.background);
2569 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2581 // Example listbox callback function...
2582 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2586 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2587 // if ( *nitems > 1 ) {
2588 // PHYSFS_delete(items[*citem]); // Delete the file
2589 // for (i=*citem; i<*nitems-1; i++ ) {
2590 // items[i] = items[i+1];
2592 // *nitems = *nitems - 1;
2593 // d_free( items[*nitems] );
2594 // items[*nitems] = NULL;
2595 // return 1; // redraw;
2602 #define LB_ITEMS_ON_SCREEN 8
2604 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2606 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2609 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 ) )
2612 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2613 int old_keyd_repeat = keyd_repeat;
2614 int width, height, wx, wy, title_height, border_size;
2615 int total_width,total_height;
2617 #ifdef NEWMENU_MOUSE
2618 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2619 int close_x,close_y;
2621 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2627 // set_screen_mode(SCREEN_MENU);
2630 gr_set_current_canvas(NULL);
2632 grd_curcanv->cv_font = SUBTITLE_FONT;
2635 for (i=0; i<nitems; i++ ) {
2637 gr_get_string_size( items[i], &w, &h, &aw );
2641 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2645 gr_get_string_size( title, &w, &h, &aw );
2648 title_height = h + 5;
2651 border_size = grd_curfont->ft_w;
2652 WIN (border_size=grd_curfont->ft_w*2);
2654 width += (grd_curfont->ft_w);
2655 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2656 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2658 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2659 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2660 if ( wy < title_height )
2663 total_width = width+2*border_size;
2664 total_height = height+2*border_size+title_height;
2668 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2669 bg.background = &VR_offscreen_buffer->cv_bitmap;
2671 //bg.background = gr_create_bitmap( width, (height + title_height) );
2672 bg.background = gr_create_bitmap(total_width,total_height);
2673 Assert( bg.background != NULL );
2675 //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 );
2676 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2679 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2682 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2684 gr_string( 0x8000, wy - title_height, title );
2687 citem = default_item;
2688 if ( citem < 0 ) citem = 0;
2689 if ( citem >= nitems ) citem = 0;
2693 #ifdef NEWMENU_MOUSE
2694 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2695 close_x = wx-border_size;
2696 close_y = wy-title_height-border_size;
2697 //draw_close_box(close_x,close_y);
2698 newmenu_show_cursor();
2703 ofirst_item = first_item;
2704 #ifdef NEWMENU_MOUSE
2705 omouse_state = mouse_state;
2706 mouse_state = mouse_button_state(0);
2708 //see if redbook song needs to be restarted
2709 songs_check_redbook_repeat();
2711 key = newmenu_inkey();
2713 if ( listbox_callback )
2714 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2728 else if (simukey==1)
2734 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2735 case KEY_PRINT_SCREEN:
2736 MAC(newmenu_hide_cursor());
2737 save_screen_shot(0);
2739 MAC(newmenu_show_cursor());
2760 citem += LB_ITEMS_ON_SCREEN;
2764 citem -= LB_ITEMS_ON_SCREEN;
2768 if (allow_abort_flag) {
2779 case KEY_COMMAND+KEY_Q: {
2780 if ( !(Game_mode & GM_MULTI) )
2782 newmenu_show_cursor();
2789 int ascii = key_to_ascii(key);
2790 if ( ascii < 255 ) {
2793 if (cc1 < 0 ) cc1 = 0;
2794 if (cc1 >= nitems ) cc1 = 0;
2796 if ( cc < 0 ) cc = 0;
2797 if ( cc >= nitems ) cc = 0;
2798 if ( citem == cc ) break;
2800 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2817 if (citem< first_item)
2820 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2821 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2823 if (nitems <= LB_ITEMS_ON_SCREEN )
2826 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
2827 first_item = nitems-LB_ITEMS_ON_SCREEN;
2828 if (first_item < 0 ) first_item = 0;
2831 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
2842 #ifdef NEWMENU_MOUSE
2846 mouse_get_pos(&mx, &my);
2847 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2850 gr_get_string_size(items[i], &w, &h, &aw );
2853 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2855 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2867 //no double-click stuff for listbox
2868 //@@if (!mouse_state && omouse_state) {
2871 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
2872 //@@ mouse_get_pos(&mx, &my);
2874 //@@ x2 = wx + width;
2875 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
2877 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2878 //@@ if (dblclick_flag) done = 1;
2882 //check for close box clicked
2883 if ( !mouse_state && omouse_state ) {
2884 mouse_get_pos(&mx, &my);
2885 x1 = close_x + CLOSE_X + 2;
2886 x2 = x1 + CLOSE_SIZE - 2;
2887 y1 = close_y + CLOSE_Y + 2;
2888 y2 = y1 + CLOSE_SIZE - 2;
2889 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2899 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
2901 y1 = total_height-LHY(7);
2903 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
2911 if ( (ofirst_item != first_item) || redraw) {
2912 newmenu_hide_cursor();
2914 gr_setcolor( BM_XRGB( 0,0,0) );
2915 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2917 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2918 if ( i >= nitems ) {
2919 gr_setcolor( BM_XRGB(0,0,0));
2920 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
2923 grd_curcanv->cv_font = SELECTED_FONT;
2925 grd_curcanv->cv_font = NORMAL_FONT;
2926 gr_get_string_size(items[i], &w, &h, &aw );
2927 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2928 gr_string( wx+5, y, items[i] );
2933 // If Win95 port, draw up/down arrows on left side of menu
2935 grd_curcanv->cv_font = NORMAL_FONT;
2937 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
2941 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
2945 if (show_down_arrow)
2946 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
2950 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
2957 newmenu_show_cursor();
2959 } else if ( citem != ocitem ) {
2962 newmenu_hide_cursor();
2965 if ( (i>=0) && (i<nitems) ) {
2966 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2968 grd_curcanv->cv_font = SELECTED_FONT;
2970 grd_curcanv->cv_font = NORMAL_FONT;
2971 gr_get_string_size(items[i], &w, &h, &aw );
2972 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2973 gr_string( wx+5, y, items[i] );
2977 if ( (i>=0) && (i<nitems) ) {
2978 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2980 grd_curcanv->cv_font = SELECTED_FONT;
2982 grd_curcanv->cv_font = NORMAL_FONT;
2983 gr_get_string_size( items[i], &w, &h, &aw );
2984 gr_rect( wx, y-1, wx+width-1, y+h );
2985 gr_string( wx+5, y, items[i] );
2988 newmenu_show_cursor();
2992 newmenu_hide_cursor();
2994 keyd_repeat = old_keyd_repeat;
2996 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2998 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2999 gr_free_bitmap(bg.background);
3002 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) );
3009 int newmenu_filelist( char * title, char * filespec, char * filename )
3012 char * Filenames[MAX_FILES];
3013 char FilenameText[MAX_FILES][14];
3014 FILEFINDSTRUCT find;
3017 if( !FileFindFirst( filespec, &find ) ) {
3019 if (NumFiles<MAX_FILES) {
3020 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3021 Filenames[NumFiles] = FilenameText[NumFiles];
3026 } while( !FileFindNext( &find ) );
3030 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3032 strcpy( filename, Filenames[i] );
3039 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3040 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3046 char nm_text[MESSAGEBOX_TEXT_SIZE];
3047 newmenu_item nm_message_items[5];
3049 va_start(args, nchoices );
3051 Assert( nchoices <= 5 );
3053 for (i=0; i<nchoices; i++ ) {
3054 s = va_arg( args, char * );
3055 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3057 format = va_arg( args, char * );
3058 //sprintf( nm_text, "" ); // adb: ?
3059 vsprintf(nm_text,format,args);
3062 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3064 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3066 //end this section addition - Victor Rachels
3069 extern netgame_info Active_games[];
3070 extern int NumActiveNetgames;
3072 void show_extra_netgame_info(int choice)
3078 if (choice>=NumActiveNetgames)
3083 m[i].text=(char *)&mtext[i];
3084 m[i].type=NM_TYPE_TEXT;
3087 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3088 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3089 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3090 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3092 already_showing_info=1;
3093 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3094 already_showing_info=0;
3099 /* Spiffy word wrap string formatting function */
3101 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3107 tbuf = (char *)d_malloc((unsigned int)strlen(sbuf) + 1);
3110 wordptr = strtok(tbuf, " ");
3111 if (!wordptr) return;
3117 col = col + (int)strlen(wordptr) + 1;
3118 if (col >=line_length) {
3120 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3123 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3125 wordptr = strtok(NULL, " ");