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)
75 #define MAXDISPLAYABLEITEMS 15
77 #define LHX(x) ((x)*(MenuHires?2:1))
78 #define LHY(y) ((y)*(MenuHires?2.4:1))
80 #define TITLE_FONT HUGE_FONT
81 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
82 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
83 #define SUBTITLE_FONT MEDIUM3_FONT
85 #define NORMAL_CHECK_BOX "\x81" // 129
86 #define CHECKED_CHECK_BOX "\x82" // 130
88 #define NORMAL_RADIO_BOX "\x7f" // 127
89 #define CHECKED_RADIO_BOX "\x80" // 128
90 #define CURSOR_STRING "_"
91 #define SLIDER_LEFT "\x83" // 131
92 #define SLIDER_RIGHT "\x84" // 132
93 #define SLIDER_MIDDLE "\x85" // 133
94 #define SLIDER_MARKER "\x86" // 134
95 #define UP_ARROW_MARKER "\x87" // 135
96 #define DOWN_ARROW_MARKER "\x88" // 136
98 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 );
99 void show_extra_netgame_info(int choice);
102 int Newmenu_first_time = 1;
103 //--unused-- int Newmenu_fade_in = 1;
106 grs_canvas * menu_canvas;
107 grs_bitmap * saved; // The background under the menu.
108 grs_bitmap * background;
111 grs_bitmap nm_background,nm_background_save;
113 #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)
114 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
116 ubyte MenuReordering=0;
118 char Pauseable_menu=0;
119 char already_showing_info=0;
122 void newmenu_close() {
123 if ( nm_background.bm_data )
124 d_free(nm_background.bm_data);
126 if ( nm_background_save.bm_data )
127 d_free(nm_background_save.bm_data);
128 Newmenu_first_time = 1;
131 ubyte background_palette[768];
133 //should be called whenever the palette changes
134 void nm_remap_background()
136 if (!Newmenu_first_time) {
137 if (!nm_background.bm_data)
138 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
140 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
142 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
148 extern char last_palette_loaded[];
150 void nm_draw_background1(char * filename)
157 //@@//I think this only gets called to fill the whole screen
158 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
159 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
161 pcx_error = pcx_get_dimensions(filename, &width, &height);
162 if (pcx_error != PCX_ERROR_NONE)
163 Error("Could not open pcx file <%s>\n", filename);
165 bmp = gr_create_bitmap(width, height);
167 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
168 Assert(pcx_error == PCX_ERROR_NONE);
170 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
173 { //remap stuff. this code is kindof a hack
175 //now, before we bring up the menu, we need to
176 //do some stuff to make sure the palette is ok. First, we need to
177 //get our current palette into the 2d's array, so the remapping will
178 //work. Second, we need to remap the fonts. Third, we need to fill
179 //in part of the fade tables so the darkening of the menu edges works
181 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
183 gr_palette_load(gr_palette);
185 remap_fonts_and_menus(1);
193 strcpy(last_palette_loaded,""); //force palette load next time
197 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
198 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
200 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
202 int Background_hires;
205 void nm_draw_background(int x1, int y1, int x2, int y2 )
209 if (Newmenu_first_time || MenuHires!=Background_hires) {
212 if (Newmenu_first_time) {
213 atexit( newmenu_close );
214 Newmenu_first_time = 0;
215 nm_background_save.bm_data=NULL;
218 if (nm_background_save.bm_data)
219 d_free(nm_background_save.bm_data);
220 if (nm_background.bm_data)
221 d_free(nm_background.bm_data);
224 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
225 Assert(pcx_error == PCX_ERROR_NONE);
227 nm_background = nm_background_save;
228 nm_background.bm_data=NULL;
229 nm_remap_background();
231 Background_hires = MenuHires;
234 if ( x1 < 0 ) x1 = 0;
235 if ( y1 < 0 ) y1 = 0;
240 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
241 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
248 grs_bitmap *tmp = gr_create_bitmap(w, h);
250 gr_bitmap_scale_to(&nm_background, tmp);
253 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
255 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
260 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
262 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
266 Gr_scanline_darkening_level = 2*7;
268 gr_setcolor( BM_XRGB(0,0,0) );
269 gr_urect( x2-5, y1+5, x2-5, y2-5 );
270 gr_urect( x2-4, y1+4, x2-4, y2-5 );
271 gr_urect( x2-3, y1+3, x2-3, y2-5 );
272 gr_urect( x2-2, y1+2, x2-2, y2-5 );
273 gr_urect( x2-1, y1+1, x2-1, y2-5 );
274 gr_urect( x2+0, y1+0, x2-0, y2-5 );
276 gr_urect( x1+5, y2-5, x2, y2-5 );
277 gr_urect( x1+4, y2-4, x2, y2-4 );
278 gr_urect( x1+3, y2-3, x2, y2-3 );
279 gr_urect( x1+2, y2-2, x2, y2-2 );
280 gr_urect( x1+1, y2-1, x2, y2-1 );
281 gr_urect( x1+0, y2, x2, y2-0 );
284 Gr_scanline_darkening_level = GR_FADE_LEVELS;
287 void nm_restore_background( int x, int y, int w, int h )
294 if ( x1 < 0 ) x1 = 0;
295 if ( y1 < 0 ) y1 = 0;
297 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
298 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
303 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
306 // Draw a left justfied string
307 void nm_string( bkg * b, int w1,int x, int y, char * s)
309 int w,h,aw,tx=0,t=0,i;
310 char *p,*s1,*s2,measure[2];
311 int XTabs[]={15,87,124,162,228,253};
317 XTabs[i]=(LHX(XTabs[i]));
324 p = strchr( s2, '\t' );
331 gr_get_string_size(s2, &w, &h, &aw );
337 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
338 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
341 for (i=0;i<strlen(s2);i++) {
342 if (s2[i]=='\t' && SurfingNet) {
348 gr_get_string_size(measure,&tx,&h,&aw);
349 gr_string(x,y,measure);
356 if (!SurfingNet && p && (w1>0) ) {
357 gr_get_string_size(s1, &w, &h, &aw );
359 gr_string( x+w1-w, y, s1 );
366 // Draw a slider and it's string
367 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
374 p = strchr( s, '\t' );
380 gr_get_string_size(s, &w, &h, &aw );
383 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
384 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
386 gr_string( x, y, s );
389 gr_get_string_size(s1, &w, &h, &aw );
392 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
394 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
396 gr_string( x+w1-w, y, s1 );
403 // Draw a left justfied string with black background.
404 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
407 gr_get_string_size(s, &w, &h, &aw );
410 gr_setcolor( BM_XRGB(2,2,2) );
411 gr_rect( x-1, y-1, x-1, y+h-1 );
412 gr_rect( x-1, y-1, x+w1-1, y-1 );
415 gr_setcolor( BM_XRGB(5,5,5) );
416 gr_rect( x, y+h, x+w1, y+h);
417 gr_rect( x+w1, y-1, x+w1, y+h );
419 gr_setcolor( BM_XRGB(0,0,0) );
420 gr_rect( x, y, x+w1-1, y+h-1 );
422 gr_string( x+1, y+1, s );
426 // Draw a right justfied string
427 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
430 gr_get_string_size(s, &w, &h, &aw );
435 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
438 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
439 gr_string( x-w, y, s );
444 //for text items, constantly redraw cursor (to achieve flash)
445 void update_cursor( newmenu_item *item)
448 fix time = timer_get_approx_seconds();
450 char * text = item->text;
452 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
455 gr_get_string_size(text, &w, &h, &aw );
456 if ( w > item->w-10 )
463 x = item->x+w; y = item->y;
466 gr_string( x, y, CURSOR_STRING );
468 gr_setcolor( BM_XRGB(0,0,0) );
469 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
473 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
478 gr_get_string_size(text, &w1, &h1, &aw );
487 nm_string_black( b, w, x, y, text );
490 gr_string( x+w1+1, y, CURSOR_STRING );
494 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
499 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
501 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
503 if (item->text[0]=='\t')
504 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
509 grd_curcanv->cv_font = SELECTED_FONT;
511 grd_curcanv->cv_font = NORMAL_FONT;
514 if (is_current && item->type == NM_TYPE_TEXT)
515 grd_curcanv->cv_font = NORMAL_FONT;
519 switch( item->type ) {
521 // grd_curcanv->cv_font=TEXT_FONT;
522 // fall through on purpose
525 nm_string( b, item->w, item->x, item->y, item->text );
527 case NM_TYPE_SLIDER: {
529 if (item->value < item->min_value) item->value=item->min_value;
530 if (item->value > item->max_value) item->value=item->max_value;
531 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
532 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
533 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
535 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
537 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
539 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
542 case NM_TYPE_INPUT_MENU:
543 if ( item->group==0 ) {
544 nm_string( b, item->w, item->x, item->y, item->text );
546 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
550 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
553 nm_string( b, item->w, item->x, item->y, item->text );
555 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
557 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
560 nm_string( b, item->w, item->x, item->y, item->text );
562 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
564 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
566 case NM_TYPE_NUMBER: {
568 if (item->value < item->min_value) item->value=item->min_value;
569 if (item->value > item->max_value) item->value=item->max_value;
570 nm_string( b, item->w, item->x, item->y, item->text );
571 sprintf( text, "%d", item->value );
572 nm_rstring( b,item->right_offset,item->x, item->y, text );
578 char *Newmenu_allowed_chars=NULL;
580 //returns true if char is allowed
581 int char_allowed(char c)
583 char *p = Newmenu_allowed_chars;
591 if (c>=p[0] && c<=p[1])
600 void strip_end_whitespace( char * text )
604 for (i=l-1; i>=0; i-- ) {
605 if ( isspace(text[i]) )
612 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
614 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
616 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
618 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
622 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
624 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
628 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 )
630 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
634 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 )
636 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
638 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 )
640 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
643 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){
644 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
645 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
646 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
649 //returns 1 if a control device button has been pressed
650 int check_button_press()
654 switch (Config_control_type.intval) {
655 case CONTROL_JOYSTICK:
656 case CONTROL_FLIGHTSTICK_PRO:
657 case CONTROL_THRUSTMASTER_FCS:
658 case CONTROL_GRAVIS_GAMEPAD:
660 if (joy_get_button_down_cnt(i)>0) return 1;
663 case CONTROL_CYBERMAN:
664 #ifndef NEWMENU_MOUSE // don't allow mouse to continue from menu
666 if (mouse_button_down_count(i)>0) return 1;
669 case CONTROL_NONE: //keyboard only
671 if (key_checkch()) return 1;
676 Error("Bad ControlType: %i", Config_control_type.intval);
682 extern int network_request_player_names(int);
683 extern int RestoringMenu;
686 ubyte Hack_DblClick_MenuMode=0;
690 extern ubyte joydefs_calibrating;
692 # define joydefs_calibrating 0
695 #define CLOSE_X (MenuHires?15:7)
696 #define CLOSE_Y (MenuHires?15:7)
697 #define CLOSE_SIZE (MenuHires?10:5)
699 void draw_close_box(int x,int y)
701 gr_setcolor( BM_XRGB(0, 0, 0) );
702 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
703 gr_setcolor( BM_XRGB(21, 21, 21) );
704 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));
707 extern int Num_bitmap_files;
709 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 )
711 int old_keyd_repeat, done;
712 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
713 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
714 grs_font * save_font;
715 int string_width, string_height, average_width;
718 int all_text=0; //set true if all text items
719 int sound_stopped=0,time_stopped=0;
720 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
723 int MaxOnMenu=MAXDISPLAYABLEITEMS;
724 grs_canvas *save_canvas;
726 int mouse_state, omouse_state, dblclick_flag=0;
727 int mx=0, my=0, x1 = 0, x2, y1, y2;
731 EventRecord event; // looking for disk inserted events for CD mounts
734 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
735 newmenu_hide_cursor();
742 MaxDisplayable=nitems;
744 //set_screen_mode(SCREEN_MENU);
747 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
748 digi_pause_digi_sounds();
752 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
762 save_canvas = grd_curcanv;
764 gr_set_current_canvas(NULL);
766 save_font = grd_curcanv->cv_font;
771 grd_curcanv->cv_font = TITLE_FONT;
772 gr_get_string_size(title,&string_width,&string_height,&average_width );
777 grd_curcanv->cv_font = SUBTITLE_FONT;
778 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
779 if (string_width > tw )
784 th += LHY(8); //put some space between titles & body
787 grd_curcanv->cv_font = SMALL_FONT;
789 grd_curcanv->cv_font = NORMAL_FONT;
793 nmenus = nothers = 0;
795 // Find menu height & width (store in w,h)
796 for (i=0; i<nitems; i++ ) {
799 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
800 item[i].right_offset = 0;
803 string_height+=LHY(3);
805 item[i].saved_text[0] = '\0';
807 if ( item[i].type == NM_TYPE_SLIDER ) {
810 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
811 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
812 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
814 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
815 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
816 string_width += w1 + aw;
819 if ( item[i].type == NM_TYPE_MENU ) {
823 if ( item[i].type == NM_TYPE_CHECK ) {
826 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
827 item[i].right_offset = w1;
828 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
829 if (w1 > item[i].right_offset)
830 item[i].right_offset = w1;
833 if (item[i].type == NM_TYPE_RADIO ) {
836 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
837 item[i].right_offset = w1;
838 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
839 if (w1 > item[i].right_offset)
840 item[i].right_offset = w1;
843 if (item[i].type==NM_TYPE_NUMBER ) {
847 sprintf( test_text, "%d", item[i].max_value );
848 gr_get_string_size( test_text, &w1, &h1, &aw1 );
849 item[i].right_offset = w1;
850 sprintf( test_text, "%d", item[i].min_value );
851 gr_get_string_size( test_text, &w1, &h1, &aw1 );
852 if ( w1 > item[i].right_offset)
853 item[i].right_offset = w1;
856 if ( item[i].type == NM_TYPE_INPUT ) {
857 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
858 strcpy(item[i].saved_text, item[i].text );
860 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
861 if ( string_width > MAX_TEXT_WIDTH )
862 string_width = MAX_TEXT_WIDTH;
866 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
867 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
868 strcpy(item[i].saved_text, item[i].text );
870 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
875 item[i].w = string_width;
876 item[i].h = string_height;
878 if ( string_width > w )
879 w = string_width; // Save maximum width
880 if ( average_width > aw )
882 h += string_height+1; // Find the height of all strings
885 // Big hack for allowing the netgame options menu to spill over
887 MaxOnMenu=MAXDISPLAYABLEITEMS;
888 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
891 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
894 h=(MaxOnMenu*(string_height+1)+LHY(8));
895 MaxDisplayable=MaxOnMenu;
896 mprintf ((0,"Hey, this is a scroll box!\n"));
909 for (i=0; i<nitems; i++ ) {
911 if (item[i].right_offset > right_offset )
912 right_offset = item[i].right_offset;
914 if (right_offset > 0 )
917 //gr_get_string_size("",&string_width,&string_height,&average_width );
924 twidth = ( tw - w )/2;
929 { right_offset=0; twidth=0;}
931 mprintf(( 0, "Right offset = %d\n", right_offset ));
934 // Find min point of menu border
935 // x = (grd_curscreen->sc_w-w)/2;
936 // y = (grd_curscreen->sc_h-h)/2;
938 w += MenuHires?60:30;
939 h += MenuHires?60:30;
941 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
942 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
944 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
945 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
950 if ( filename != NULL ) {
951 nm_draw_background1( filename );
952 gr_palette_load(gr_palette);
955 // Save the background of the display
956 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h );
957 gr_set_current_canvas(bg.menu_canvas);
959 if ( filename == NULL ) {
960 // Save the background under the menu...
966 bg.saved = gr_create_bitmap( w, h );
967 Assert( bg.saved != NULL );
969 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
971 gr_set_current_canvas( NULL );
973 nm_draw_background(x,y,x+w-1,y+h-1);
975 gr_set_current_canvas( bg.menu_canvas );
977 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
981 bg.background = gr_create_bitmap( w, h );
982 Assert( bg.background != NULL );
984 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
987 // ty = 15 + (yborder/4);
989 ty = MenuHires?30:15;
992 grd_curcanv->cv_font = TITLE_FONT;
993 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
994 gr_get_string_size(title,&string_width,&string_height,&average_width );
997 gr_printf( 0x8000, ty, title );
1002 grd_curcanv->cv_font = SUBTITLE_FONT;
1003 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1004 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1007 gr_printf( 0x8000, ty, subtitle );
1012 grd_curcanv->cv_font = SMALL_FONT;
1014 grd_curcanv->cv_font = NORMAL_FONT;
1016 // Update all item's x & y values.
1017 for (i=0; i<nitems; i++ ) {
1018 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1019 item[i].y += (MenuHires?30:15);
1020 if ( item[i].type==NM_TYPE_RADIO ) {
1021 fm = -1; // find first marked one
1022 for ( j=0; j<nitems; j++ ) {
1023 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1024 if (fm==-1 && item[j].value)
1036 old_keyd_repeat = keyd_repeat;
1042 if (citem < 0 ) citem = 0;
1043 if (citem > nitems-1 ) citem = nitems-1;
1046 #ifdef NEWMENU_MOUSE
1050 while ( item[choice].type==NM_TYPE_TEXT ) {
1052 if (choice >= nitems ) {
1055 if (choice == citem ) {
1066 // Clear mouse, joystick to clear button presses.
1067 game_flush_inputs();
1069 #ifdef NEWMENU_MOUSE
1070 mouse_state = omouse_state = 0;
1071 if (filename == NULL && !MenuReordering) {
1072 //draw_close_box(0,0);
1076 if (!MenuReordering && !joydefs_calibrating)
1078 newmenu_show_cursor();
1080 SetCursor(LoadCursor(NULL,IDC_ARROW));
1085 mprintf ((0,"Set to true!\n"));
1088 #ifdef NEWMENU_MOUSE
1089 if (!joydefs_calibrating)
1090 newmenu_show_cursor(); // possibly hidden
1091 omouse_state = mouse_state;
1092 if (!MenuReordering)
1093 mouse_state = mouse_button_state(0);
1094 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1097 //see if redbook song needs to be restarted
1098 songs_check_redbook_repeat();
1105 (*subfunction)(nitems,item,&k,choice);
1108 if (!time_stopped) {
1109 // Save current menu box
1110 if (multi_menu_poll() == -1)
1116 dont_restore = (k == -3); //-3 means don't restore
1121 if (check_button_press())
1124 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1127 old_choice = choice;
1133 if (SurfingNet && !already_showing_info)
1135 show_extra_netgame_info(choice-2);
1137 if (SurfingNet && already_showing_info)
1144 if (SurfingNet && !already_showing_info)
1146 network_request_player_names(choice-2);
1148 if (SurfingNet && already_showing_info)
1163 case KEY_TAB + KEY_SHIFTED:
1166 if (all_text) break;
1173 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1175 if (choice<TopChoice)
1176 { choice=TopChoice; break; }
1178 if (choice<ScrollOffset)
1180 for (i=0;i<nitems;i++)
1183 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1188 if (choice >= nitems ) choice=0;
1189 if (choice < 0 ) choice=nitems-1;
1191 } while ( item[choice].type==NM_TYPE_TEXT );
1192 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1193 item[choice].value = -1;
1194 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1195 item[old_choice].group=0;
1196 strcpy(item[old_choice].text, item[old_choice].saved_text );
1197 item[old_choice].value = -1;
1200 item[old_choice].redraw = 1;
1201 item[choice].redraw=1;
1206 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1207 if (all_text) break;
1214 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1217 { choice--; break; }
1219 if (choice>=MaxOnMenu+ScrollOffset)
1221 for (i=0;i<nitems;i++)
1224 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1229 if (choice < 0 ) choice=nitems-1;
1230 if (choice >= nitems ) choice=0;
1233 } while ( item[choice].type==NM_TYPE_TEXT );
1235 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1236 item[choice].value = -1;
1237 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1238 item[old_choice].group=0;
1239 strcpy(item[old_choice].text, item[old_choice].saved_text );
1240 item[old_choice].value = -1;
1243 item[old_choice].redraw=1;
1244 item[choice].redraw=1;
1247 if ( choice > -1 ) {
1248 switch( item[choice].type ) {
1251 case NM_TYPE_INPUT_MENU:
1254 if ( item[choice].value )
1255 item[choice].value = 0;
1257 item[choice].value = 1;
1258 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1261 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1263 mprintf ((0,"Special redraw!\n"));
1268 item[choice].redraw=1;
1271 for (i=0; i<nitems; i++ ) {
1272 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1277 item[choice].value = 1;
1278 item[choice].redraw = 1;
1284 case KEY_SHIFTED+KEY_UP:
1285 if (MenuReordering && choice!=TopChoice)
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;
1298 case KEY_SHIFTED+KEY_DOWN:
1299 if (MenuReordering && choice!=(nitems-1))
1301 Temp=item[choice].text;
1302 TempVal=item[choice].value;
1303 item[choice].text=item[choice+1].text;
1304 item[choice].value=item[choice+1].value;
1305 item[choice+1].text=Temp;
1306 item[choice+1].value=TempVal;
1307 item[choice].redraw=1;
1308 item[choice+1].redraw=1;
1315 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1316 item[choice].group = 1;
1317 item[choice].redraw = 1;
1318 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1319 item[choice].text[0] = 0;
1320 item[choice].value = -1;
1322 strip_end_whitespace(item[choice].text);
1329 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1330 item[choice].group=0;
1331 strcpy(item[choice].text, item[choice].saved_text );
1332 item[choice].redraw=1;
1333 item[choice].value = -1;
1340 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
1341 case KEY_PRINT_SCREEN:
1342 MAC(newmenu_hide_cursor());
1343 save_screen_shot(0);
1344 for (i=0;i<nitems;i++)
1347 MAC(newmenu_show_cursor());
1353 case KEY_COMMAND+KEY_RIGHT:
1354 songs_goto_next_song();
1356 case KEY_COMMAND+KEY_LEFT:
1357 songs_goto_prev_song();
1359 case KEY_COMMAND+KEY_UP:
1360 songs_play_level_song(1);
1362 case KEY_COMMAND+KEY_DOWN:
1363 songs_stop_redbook();
1366 case KEY_COMMAND+KEY_M:
1368 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1371 key_close(); // no processing of keys with keyboard handler.. jeez
1373 newmenu_hide_cursor();
1374 show_boxed_message ("Mounting CD\nESC to quit");
1375 RBAMountDisk(); // OS has totaly control of the CD.
1376 if (Function_mode == FMODE_MENU)
1377 songs_play_song(SONG_TITLE,1);
1378 else if (Function_mode == FMODE_GAME)
1379 songs_play_level_song( Current_level_num );
1380 clear_boxed_message();
1381 newmenu_show_cursor();
1388 case KEY_COMMAND+KEY_E:
1389 songs_stop_redbook();
1391 k = -1; // force key not to register
1395 case KEY_COMMAND+KEY_Q: {
1396 if ( !(Game_mode & GM_MULTI) )
1398 if (!joydefs_calibrating)
1399 newmenu_show_cursor();
1400 k = -1; // force key not to register
1406 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1411 case KEY_SHIFTED + KEY_B:
1414 grs_canvas *canv_save = grd_curcanv;
1415 grs_canvas *temp_canv;
1418 ubyte pal_save[768];
1420 memcpy(pal_save, gr_palette, 768);
1421 gr_use_palette_table(DEFAULT_LEVEL_PALETTE);
1422 memcpy(bm_pal, gr_palette, 768);
1423 gr_copy_palette(gr_palette, pal_save, 768);
1425 if (k & KEY_SHIFTED)
1431 n = Num_bitmap_files - 1;
1432 n %= Num_bitmap_files;
1433 bm = &GameBitmaps[n];
1434 PIGGY_PAGE_IN( *(bitmap_index *)&n );
1435 con_printf(CON_DEBUG, "showing bitmap %d of %d: %s\n", n, Num_bitmap_files, piggy_game_bitmap_name(bm));
1437 temp_canv = gr_create_canvas(bm->bm_w, bm->bm_h);
1438 gr_set_current_canvas(temp_canv);
1439 gr_bitmap(0, 0, bm);
1440 gr_set_current_canvas(&grd_curscreen->sc_canvas);
1441 gr_remap_bitmap_good(&temp_canv->cv_bitmap, bm_pal, -1, -1);
1442 gr_bitmap(0, 0, &temp_canv->cv_bitmap);
1443 gr_free_canvas(temp_canv);
1444 gr_set_current_canvas(canv_save);
1449 case KEY_SHIFTED + KEY_P:
1451 char *palettes[] = {
1461 static unsigned int palnum = 0;
1463 if (k & KEY_SHIFTED)
1468 palnum %= sizeof(palettes)/sizeof(char *);
1469 load_palette(palettes[palnum], 0, 0);
1477 #ifdef NEWMENU_MOUSE // for mouse selection of menu's etc.
1478 if ( !done && mouse_state && !omouse_state && !all_text ) {
1479 mouse_get_pos(&mx, &my);
1480 for (i=0; i<nitems; i++ ) {
1481 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1482 x2 = x1 + item[i].w;
1483 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1484 y2 = y1 + item[i].h;
1485 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1486 if (i+ScrollOffset != choice) {
1487 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1490 choice = i + ScrollOffset;
1492 switch( item[choice].type ) {
1494 if ( item[choice].value )
1495 item[choice].value = 0;
1497 item[choice].value = 1;
1498 item[choice].redraw=1;
1505 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1507 mprintf ((0,"Special redraw!\n"));
1514 for (i=0; i<nitems; i++ ) {
1515 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1520 item[choice].value = 1;
1521 item[choice].redraw = 1;
1524 item[old_choice].redraw=1;
1530 if (mouse_state && all_text)
1533 if ( !done && mouse_state && !all_text ) {
1534 mouse_get_pos(&mx, &my);
1536 // check possible scrollbar stuff first
1538 int arrow_width, arrow_height, aw;
1540 if (ScrollOffset != 0) {
1541 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1542 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1543 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1544 x1 = x1 - arrow_width;
1545 y2 = y1 + arrow_height;
1546 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1549 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1551 if (choice<ScrollOffset)
1553 for (i=0;i<nitems;i++)
1556 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1560 if (ScrollOffset+MaxDisplayable<nitems) {
1561 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1562 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1563 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1564 x1 = x1 - arrow_width;
1565 y2 = y1 + arrow_height;
1566 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1569 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1571 if (choice>=MaxOnMenu+ScrollOffset)
1573 for (i=0;i<nitems;i++)
1576 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1582 for (i=0; i<nitems; i++ ) {
1583 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1584 x2 = x1 + item[i].w;
1585 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1586 y2 = y1 + item[i].h;
1587 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1588 if (i+ScrollOffset != choice) {
1589 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1592 choice = i + ScrollOffset;
1594 if ( item[choice].type == NM_TYPE_SLIDER ) {
1595 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1596 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1598 strcpy(slider_text, item[choice].saved_text);
1599 p = strchr(slider_text, '\t');
1605 gr_get_string_size(s1, &slider_width, &height, &aw);
1606 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1607 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1608 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1610 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1611 x2 = x1 + slider_width + sright_width;
1612 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1613 item[choice].value = item[choice].min_value;
1614 item[choice].redraw = 2;
1615 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1616 item[choice].value = item[choice].max_value;
1617 item[choice].redraw = 2;
1618 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1619 int num_values, value_width, new_value;
1621 num_values = item[choice].max_value - item[choice].min_value + 1;
1622 value_width = (slider_width - sleft_width - sright_width) / num_values;
1623 new_value = (mx - x1 - sleft_width) / value_width;
1624 if ( item[choice].value != new_value ) {
1625 item[choice].value = new_value;
1626 item[choice].redraw = 2;
1632 if (choice == old_choice)
1634 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1635 item[choice].value = -1;
1636 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1637 item[old_choice].group=0;
1638 strcpy(item[old_choice].text, item[old_choice].saved_text );
1639 item[old_choice].value = -1;
1642 item[old_choice].redraw = 1;
1643 item[choice].redraw=1;
1649 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1650 mouse_get_pos(&mx, &my);
1651 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1652 x2 = x1 + item[choice].w;
1653 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1654 y2 = y1 + item[choice].h;
1655 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1656 if (Hack_DblClick_MenuMode) {
1657 if (dblclick_flag) done = 1;
1658 else dblclick_flag = 1;
1664 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1665 item[choice].group = 1;
1666 item[choice].redraw = 1;
1667 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1668 item[choice].text[0] = 0;
1669 item[choice].value = -1;
1671 strip_end_whitespace(item[choice].text);
1675 if ( !done && !mouse_state && omouse_state && close_box ) {
1676 mouse_get_pos(&mx, &my);
1677 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1678 x2 = x1 + CLOSE_SIZE;
1679 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1680 y2 = y1 + CLOSE_SIZE;
1681 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1687 // HACK! Don't redraw loadgame preview
1688 if (RestoringMenu) item[0].redraw = 0;
1689 #endif // NEWMENU_MOUSE
1691 if ( choice > -1 ) {
1694 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1695 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1696 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1697 if (item[choice].value > 0)
1698 item[choice].value--;
1699 item[choice].text[item[choice].value] = 0;
1700 item[choice].redraw = 1;
1702 ascii = key_to_ascii(k);
1703 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1707 if (item[choice].value==-1) {
1708 item[choice].value = 0;
1711 allowed = char_allowed(ascii);
1713 if (!allowed && ascii==' ' && char_allowed('_')) {
1719 item[choice].text[item[choice].value++] = ascii;
1720 item[choice].text[item[choice].value] = 0;
1721 item[choice].redraw=1;
1725 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1726 ascii = key_to_ascii(k);
1728 int choice1 = choice;
1729 ascii = toupper(ascii);
1733 if (choice1 >= nitems ) choice1=0;
1734 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1735 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1736 (item[choice1].type==NM_TYPE_CHECK) ||
1737 (item[choice1].type==NM_TYPE_RADIO) ||
1738 (item[choice1].type==NM_TYPE_NUMBER) ||
1739 (item[choice1].type==NM_TYPE_SLIDER) )
1740 && (ascii==toupper(ch)) ) {
1744 item[old_choice].redraw=1;
1745 item[choice].redraw=1;
1747 } while (choice1 != choice );
1751 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1752 int ov=item[choice].value;
1757 case KEY_MINUS+KEY_SHIFTED:
1759 item[choice].value -= 1;
1764 case KEY_EQUAL+KEY_SHIFTED:
1766 item[choice].value++;
1771 item[choice].value += 10;
1776 item[choice].value -= 10;
1779 if (ov!=item[choice].value)
1780 item[choice].redraw=1;
1785 gr_set_current_canvas(bg.menu_canvas);
1787 // Redraw everything...
1788 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1790 if (item[i].redraw) // warning! ugly hack below
1792 item[i].y-=((string_height+1)*ScrollOffset);
1793 newmenu_hide_cursor();
1794 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1796 #ifdef NEWMENU_MOUSE
1797 if (!MenuReordering && !joydefs_calibrating)
1798 newmenu_show_cursor();
1800 item[i].y+=((string_height+1)*ScrollOffset);
1802 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1803 update_cursor( &item[i]);
1809 //grd_curcanv->cv_font = NORMAL_FONT;
1811 if (LastScrollCheck!=ScrollOffset)
1813 LastScrollCheck=ScrollOffset;
1814 grd_curcanv->cv_font = SELECTED_FONT;
1816 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1817 sx=item[ScrollOffset].x-(MenuHires?24:12);
1820 if (ScrollOffset!=0)
1821 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1823 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1825 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1826 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1828 if (ScrollOffset+MaxDisplayable<nitems)
1829 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1831 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1837 if ( !dont_restore && gr_palette_faded_out ) {
1838 gr_palette_fade_in( gr_palette, 32, 0 );
1842 newmenu_hide_cursor();
1844 // Restore everything...
1846 gr_set_current_canvas(bg.menu_canvas);
1848 if ( filename == NULL ) {
1849 // Save the background under the menu...
1850 gr_bitmap(0, 0, bg.saved);
1851 gr_free_bitmap(bg.saved);
1852 d_free( bg.background );
1854 if (!dont_restore) //info passed back from subfunction
1855 gr_bitmap(0, 0, bg.background);
1856 gr_free_bitmap(bg.background);
1859 gr_free_sub_canvas( bg.menu_canvas );
1861 gr_set_current_canvas(save_canvas);
1862 grd_curcanv->cv_font = save_font;
1863 keyd_repeat = old_keyd_repeat;
1865 game_flush_inputs();
1876 if ( sound_stopped )
1877 digi_resume_digi_sounds();
1884 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1890 char nm_text[MESSAGEBOX_TEXT_SIZE];
1891 newmenu_item nm_message_items[5];
1893 va_start(args, nchoices );
1895 Assert( nchoices <= 5 );
1897 for (i=0; i<nchoices; i++ ) {
1898 s = va_arg( args, char * );
1899 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1901 format = va_arg( args, char * );
1902 strcpy( nm_text, "" );
1903 vsprintf(nm_text,format,args);
1906 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1908 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1911 int nm_messagebox( char *title, int nchoices, ... )
1917 char nm_text[MESSAGEBOX_TEXT_SIZE];
1918 newmenu_item nm_message_items[5];
1920 va_start(args, nchoices );
1922 Assert( nchoices <= 5 );
1924 for (i=0; i<nchoices; i++ ) {
1925 s = va_arg( args, char * );
1926 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1928 format = va_arg( args, char * );
1929 strcpy( nm_text, "" );
1930 vsprintf(nm_text,format,args);
1933 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1935 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1941 void newmenu_file_sort( int n, char *list )
1948 for (i=incr; i<n; i++ ) {
1951 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1952 memcpy( t, &list[j*14], FILENAME_LEN );
1953 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1954 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1965 void delete_player_saved_games(char * name)
1970 for (i=0;i<10; i++) {
1971 sprintf( filename, PLAYER_DIR "%s.sg%d", name, i );
1972 PHYSFS_delete(filename);
1976 #define MAX_FILES 300
1978 //FIXME: should maybe put globbing ability back?
1979 int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
1985 int NumFiles=0, key,done, citem, ocitem;
1986 char * filenames = NULL;
1987 int NumFiles_displayed = 8;
1988 int first_item = -1, ofirst_item;
1989 int old_keyd_repeat = keyd_repeat;
1992 int demos_deleted=0;
1993 int initialized = 0;
1995 int w_x, w_y, w_w, w_h, title_height;
1996 int box_x, box_y, box_w, box_h;
1997 bkg bg; // background under listbox
1998 #ifdef NEWMENU_MOUSE
1999 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2000 int mouse2_state, omouse2_state;
2001 int dblclick_flag=0;
2004 int show_up_arrow=0, show_down_arrow=0;
2008 w_x=w_y=w_w=w_h=title_height=0;
2009 box_x=box_y=box_w=box_h=0;
2011 filenames = d_malloc( MAX_FILES * 14 );
2012 if (filenames==NULL) return 0;
2017 if (!stricmp(type, "plr"))
2019 else if (!stricmp(type, "dem"))
2026 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2028 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2033 find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
2034 for (f = find; *f != NULL; f++)
2038 ext = strrchr(*f, '.');
2039 if (!ext || strnicmp(ext, ".plr", 4))
2042 if (NumFiles < MAX_FILES)
2044 strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
2049 p = strchr(&filenames[NumFiles*14], '.');
2059 PHYSFS_freeList(find);
2061 if ( (NumFiles < 1) && demos_deleted ) {
2065 if ( (NumFiles < 1) && demo_mode ) {
2066 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2072 if ( (NumFiles < 2) && player_mode ) {
2074 goto ExitFileMenuEarly;
2081 nm_messagebox(NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND);
2088 // set_screen_mode(SCREEN_MENU);
2091 gr_set_current_canvas(NULL);
2093 grd_curcanv->cv_font = SUBTITLE_FONT;
2098 for (i=0; i<NumFiles; i++ ) {
2100 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2106 gr_get_string_size( title, &w, &h, &aw );
2109 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2113 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2115 w_w += (grd_curfont->ft_w * 4);
2116 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2118 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2119 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2121 w_x = (grd_curcanv->cv_w-w_w)/2;
2122 w_y = (grd_curcanv->cv_h-w_h)/2;
2124 if ( w_x < 0 ) w_x = 0;
2125 if ( w_y < 0 ) w_y = 0;
2127 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2128 box_y = w_y + title_height;
2130 // save the screen behind the menu.
2134 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2135 bg.background = &VR_offscreen_buffer->cv_bitmap;
2137 bg.background = gr_create_bitmap( w_w, w_h );
2139 Assert( bg.background != NULL );
2142 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2145 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2148 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2150 gr_string( 0x8000, w_y+10, title );
2155 if ( !player_mode ) {
2156 newmenu_file_sort( NumFiles, filenames );
2158 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2159 newmenu_file_sort( NumFiles, filenames );
2161 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2163 for ( i=0; i<NumFiles; i++ ) {
2164 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2165 #ifdef NEWMENU_MOUSE
2173 #ifdef NEWMENU_MOUSE
2174 mouse_state = omouse_state = 0;
2175 mouse2_state = omouse2_state = 0;
2176 //draw_close_box(w_x,w_y);
2177 newmenu_show_cursor();
2182 ofirst_item = first_item;
2185 #ifdef NEWMENU_MOUSE
2186 omouse_state = mouse_state;
2187 omouse2_state = mouse2_state;
2188 mouse_state = mouse_button_state(0);
2189 mouse2_state = mouse_button_state(1);
2192 //see if redbook song needs to be restarted
2193 songs_check_redbook_repeat();
2198 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2199 case KEY_PRINT_SCREEN:
2200 MAC(newmenu_hide_cursor());
2201 save_screen_shot(0);
2203 MAC(newmenu_show_cursor());
2207 case KEY_CTRLED+KEY_D:
2208 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2212 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2214 newmenu_hide_cursor();
2216 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2218 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2219 newmenu_show_cursor();
2223 char name[PATH_MAX];
2225 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2229 strcpy(name, demo_mode?DEMO_DIR:"");
2230 strcat(name,&filenames[citem*14]);
2237 if ( !strncmp(name, ".\\", 2) )
2238 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2239 name[i] = name[i+1];
2240 while ( (p = strchr(name, '\\')) )
2245 ret = !PHYSFS_delete(name);
2249 if ((!ret) && player_mode) {
2250 delete_player_saved_games( &filenames[citem*14] );
2255 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2257 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2258 } else if (demo_mode)
2283 citem += NumFiles_displayed;
2287 citem -= NumFiles_displayed;
2290 if (allow_abort_flag) {
2300 case KEY_COMMAND+KEY_Q: {
2301 if ( !(Game_mode & GM_MULTI) )
2306 newmenu_show_cursor();
2314 int ascii = key_to_ascii(key);
2315 if ( ascii < 255 ) {
2318 if (cc1 < 0 ) cc1 = 0;
2319 if (cc1 >= NumFiles ) cc1 = 0;
2321 if ( cc < 0 ) cc = 0;
2322 if ( cc >= NumFiles ) cc = 0;
2323 if ( citem == cc ) break;
2325 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2340 if (citem>=NumFiles)
2343 if (citem< first_item)
2346 if (citem>=( first_item+NumFiles_displayed))
2348 first_item = citem-NumFiles_displayed+1;
2352 if (NumFiles>first_item+NumFiles_displayed)
2363 if (NumFiles <= NumFiles_displayed )
2366 if (first_item>NumFiles-NumFiles_displayed)
2368 first_item = NumFiles-NumFiles_displayed;
2371 if (first_item < 0 ) first_item = 0;
2373 #ifdef NEWMENU_MOUSE
2374 if (mouse_state || mouse2_state) {
2377 mouse_get_pos(&mx, &my);
2378 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2379 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2381 x2 = box_x + box_w - 1;
2382 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2384 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2385 if (i == citem && !mouse2_state) {
2395 if (!mouse_state && omouse_state) {
2398 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2399 mouse_get_pos(&mx, &my);
2401 x2 = box_x + box_w - 1;
2402 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2404 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2405 if (dblclick_flag) done = 1;
2406 else dblclick_flag = 1;
2410 if ( !mouse_state && omouse_state ) {
2411 mouse_get_pos(&mx, &my);
2412 x1 = w_x + CLOSE_X + 2;
2413 x2 = x1 + CLOSE_SIZE - 2;
2414 y1 = w_y + CLOSE_Y + 2;
2415 y2 = y1 + CLOSE_SIZE - 2;
2416 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2425 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2427 y1 = box_y+box_h-LHY(7);
2429 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2436 gr_setcolor( BM_XRGB(2,2,2));
2437 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2438 gr_setcolor( BM_XRGB( 0,0,0) );
2440 if (ofirst_item != first_item) {
2441 newmenu_hide_cursor();
2442 gr_setcolor( BM_XRGB( 0,0,0) );
2443 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2445 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2447 if ( i >= NumFiles ) {
2449 gr_setcolor( BM_XRGB(5,5,5));
2450 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2451 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2453 gr_setcolor( BM_XRGB(2,2,2));
2454 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2456 gr_setcolor( BM_XRGB(0,0,0));
2457 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2461 grd_curcanv->cv_font = SELECTED_FONT;
2463 grd_curcanv->cv_font = NORMAL_FONT;
2464 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2466 gr_setcolor( BM_XRGB(5,5,5));
2467 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2468 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2470 gr_setcolor( BM_XRGB(2,2,2));
2471 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2472 gr_setcolor( BM_XRGB(0,0,0));
2474 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2475 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2478 newmenu_show_cursor();
2479 } else if ( citem != ocitem ) {
2482 newmenu_hide_cursor();
2484 if ( (i>=0) && (i<NumFiles) ) {
2485 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2487 grd_curcanv->cv_font = SELECTED_FONT;
2489 grd_curcanv->cv_font = NORMAL_FONT;
2490 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2491 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2492 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2495 if ( (i>=0) && (i<NumFiles) ) {
2496 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2498 grd_curcanv->cv_font = SELECTED_FONT;
2500 grd_curcanv->cv_font = NORMAL_FONT;
2501 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2502 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2503 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2505 newmenu_show_cursor();
2509 grd_curcanv->cv_font = NORMAL_FONT;
2511 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2515 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2519 if (show_down_arrow)
2520 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2524 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2532 MAC(newmenu_hide_cursor());
2534 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2541 keyd_repeat = old_keyd_repeat;
2543 if ( initialized ) {
2544 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2545 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2546 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2547 gr_free_bitmap(bg.background);
2549 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2561 // Example listbox callback function...
2562 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2566 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2567 // if ( *nitems > 1 ) {
2568 // PHYSFS_delete(items[*citem]); // Delete the file
2569 // for (i=*citem; i<*nitems-1; i++ ) {
2570 // items[i] = items[i+1];
2572 // *nitems = *nitems - 1;
2573 // d_free( items[*nitems] );
2574 // items[*nitems] = NULL;
2575 // return 1; // redraw;
2582 #define LB_ITEMS_ON_SCREEN 8
2584 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2586 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2589 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 ) )
2592 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2593 int old_keyd_repeat = keyd_repeat;
2594 int width, height, wx, wy, title_height, border_size;
2595 int total_width,total_height;
2597 #ifdef NEWMENU_MOUSE
2598 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2599 int close_x,close_y;
2601 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2607 // set_screen_mode(SCREEN_MENU);
2610 gr_set_current_canvas(NULL);
2612 grd_curcanv->cv_font = SUBTITLE_FONT;
2615 for (i=0; i<nitems; i++ ) {
2617 gr_get_string_size( items[i], &w, &h, &aw );
2621 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2625 gr_get_string_size( title, &w, &h, &aw );
2628 title_height = h + 5;
2631 border_size = grd_curfont->ft_w;
2632 WIN (border_size=grd_curfont->ft_w*2);
2634 width += (grd_curfont->ft_w);
2635 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2636 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2638 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2639 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2640 if ( wy < title_height )
2643 total_width = width+2*border_size;
2644 total_height = height+2*border_size+title_height;
2648 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2649 bg.background = &VR_offscreen_buffer->cv_bitmap;
2651 //bg.background = gr_create_bitmap( width, (height + title_height) );
2652 bg.background = gr_create_bitmap(total_width,total_height);
2653 Assert( bg.background != NULL );
2655 //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 );
2656 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2659 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2662 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2664 gr_string( 0x8000, wy - title_height, title );
2667 citem = default_item;
2668 if ( citem < 0 ) citem = 0;
2669 if ( citem >= nitems ) citem = 0;
2673 #ifdef NEWMENU_MOUSE
2674 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2675 close_x = wx-border_size;
2676 close_y = wy-title_height-border_size;
2677 //draw_close_box(close_x,close_y);
2678 newmenu_show_cursor();
2683 ofirst_item = first_item;
2684 #ifdef NEWMENU_MOUSE
2685 omouse_state = mouse_state;
2686 mouse_state = mouse_button_state(0);
2688 //see if redbook song needs to be restarted
2689 songs_check_redbook_repeat();
2693 if ( listbox_callback )
2694 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2708 else if (simukey==1)
2714 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2715 case KEY_PRINT_SCREEN:
2716 MAC(newmenu_hide_cursor());
2717 save_screen_shot(0);
2719 MAC(newmenu_show_cursor());
2740 citem += LB_ITEMS_ON_SCREEN;
2744 citem -= LB_ITEMS_ON_SCREEN;
2747 if (allow_abort_flag) {
2757 case KEY_COMMAND+KEY_Q: {
2758 if ( !(Game_mode & GM_MULTI) )
2760 newmenu_show_cursor();
2767 int ascii = key_to_ascii(key);
2768 if ( ascii < 255 ) {
2771 if (cc1 < 0 ) cc1 = 0;
2772 if (cc1 >= nitems ) cc1 = 0;
2774 if ( cc < 0 ) cc = 0;
2775 if ( cc >= nitems ) cc = 0;
2776 if ( citem == cc ) break;
2778 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2795 if (citem< first_item)
2798 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2799 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2801 if (nitems <= LB_ITEMS_ON_SCREEN )
2804 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
2805 first_item = nitems-LB_ITEMS_ON_SCREEN;
2806 if (first_item < 0 ) first_item = 0;
2809 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
2820 #ifdef NEWMENU_MOUSE
2824 mouse_get_pos(&mx, &my);
2825 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2828 gr_get_string_size(items[i], &w, &h, &aw );
2831 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2833 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2845 //no double-click stuff for listbox
2846 //@@if (!mouse_state && omouse_state) {
2849 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
2850 //@@ mouse_get_pos(&mx, &my);
2852 //@@ x2 = wx + width;
2853 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
2855 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2856 //@@ if (dblclick_flag) done = 1;
2860 //check for close box clicked
2861 if ( !mouse_state && omouse_state ) {
2862 mouse_get_pos(&mx, &my);
2863 x1 = close_x + CLOSE_X + 2;
2864 x2 = x1 + CLOSE_SIZE - 2;
2865 y1 = close_y + CLOSE_Y + 2;
2866 y2 = y1 + CLOSE_SIZE - 2;
2867 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2877 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
2879 y1 = total_height-LHY(7);
2881 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
2889 if ( (ofirst_item != first_item) || redraw) {
2890 newmenu_hide_cursor();
2892 gr_setcolor( BM_XRGB( 0,0,0) );
2893 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2895 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2896 if ( i >= nitems ) {
2897 gr_setcolor( BM_XRGB(0,0,0));
2898 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
2901 grd_curcanv->cv_font = SELECTED_FONT;
2903 grd_curcanv->cv_font = NORMAL_FONT;
2904 gr_get_string_size(items[i], &w, &h, &aw );
2905 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2906 gr_string( wx+5, y, items[i] );
2911 // If Win95 port, draw up/down arrows on left side of menu
2913 grd_curcanv->cv_font = NORMAL_FONT;
2915 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
2919 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
2923 if (show_down_arrow)
2924 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
2928 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
2935 newmenu_show_cursor();
2937 } else if ( citem != ocitem ) {
2940 newmenu_hide_cursor();
2943 if ( (i>=0) && (i<nitems) ) {
2944 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2946 grd_curcanv->cv_font = SELECTED_FONT;
2948 grd_curcanv->cv_font = NORMAL_FONT;
2949 gr_get_string_size(items[i], &w, &h, &aw );
2950 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2951 gr_string( wx+5, y, items[i] );
2955 if ( (i>=0) && (i<nitems) ) {
2956 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2958 grd_curcanv->cv_font = SELECTED_FONT;
2960 grd_curcanv->cv_font = NORMAL_FONT;
2961 gr_get_string_size( items[i], &w, &h, &aw );
2962 gr_rect( wx, y-1, wx+width-1, y+h );
2963 gr_string( wx+5, y, items[i] );
2966 newmenu_show_cursor();
2970 newmenu_hide_cursor();
2972 keyd_repeat = old_keyd_repeat;
2974 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2976 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2977 gr_free_bitmap(bg.background);
2980 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) );
2987 int newmenu_filelist( char * title, char * filespec, char * filename )
2990 char * Filenames[MAX_FILES];
2991 char FilenameText[MAX_FILES][14];
2992 FILEFINDSTRUCT find;
2995 if( !FileFindFirst( filespec, &find ) ) {
2997 if (NumFiles<MAX_FILES) {
2998 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
2999 Filenames[NumFiles] = FilenameText[NumFiles];
3004 } while( !FileFindNext( &find ) );
3008 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3010 strcpy( filename, Filenames[i] );
3017 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3018 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3024 char nm_text[MESSAGEBOX_TEXT_SIZE];
3025 newmenu_item nm_message_items[5];
3027 va_start(args, nchoices );
3029 Assert( nchoices <= 5 );
3031 for (i=0; i<nchoices; i++ ) {
3032 s = va_arg( args, char * );
3033 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3035 format = va_arg( args, char * );
3036 //sprintf( nm_text, "" ); // adb: ?
3037 vsprintf(nm_text,format,args);
3040 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3042 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3044 //end this section addition - Victor Rachels
3047 extern netgame_info Active_games[];
3048 extern int NumActiveNetgames;
3050 void show_extra_netgame_info(int choice)
3056 if (choice>=NumActiveNetgames)
3061 m[i].text=(char *)&mtext[i];
3062 m[i].type=NM_TYPE_TEXT;
3065 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3066 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3067 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3068 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3070 already_showing_info=1;
3071 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3072 already_showing_info=0;
3077 /* Spiffy word wrap string formatting function */
3079 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3085 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3088 wordptr = strtok(tbuf, " ");
3089 if (!wordptr) return;
3095 col = col+strlen(wordptr)+1;
3096 if (col >=line_length) {
3098 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3101 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3103 wordptr = strtok(NULL, " ");