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 )
603 l = (int)strlen( 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 if (Config_control_joystick.intval)
656 if (joy_get_button_down_cnt(i)>0) return 1;
658 #ifndef NEWMENU_MOUSE // don't allow mouse to continue from menu
659 if (Config_control_mouse.intval)
661 if (mouse_button_down_count(i)>0) return 1;
667 extern int network_request_player_names(int);
668 extern int RestoringMenu;
671 ubyte Hack_DblClick_MenuMode=0;
675 extern ubyte joydefs_calibrating;
677 # define joydefs_calibrating 0
680 #define CLOSE_X (MenuHires?15:7)
681 #define CLOSE_Y (MenuHires?15:7)
682 #define CLOSE_SIZE (MenuHires?10:5)
684 void draw_close_box(int x,int y)
686 gr_setcolor( BM_XRGB(0, 0, 0) );
687 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
688 gr_setcolor( BM_XRGB(21, 21, 21) );
689 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));
692 extern int Num_bitmap_files;
694 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 )
696 int old_keyd_repeat, done;
697 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
698 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
699 grs_font * save_font;
700 int string_width, string_height = 0, average_width;
703 int all_text=0; //set true if all text items
704 int sound_stopped=0,time_stopped=0;
705 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
708 int MaxOnMenu=MAXDISPLAYABLEITEMS;
709 grs_canvas *save_canvas;
711 int mouse_state, omouse_state, dblclick_flag=0;
712 int mx=0, my=0, x1 = 0, x2, y1, y2;
716 EventRecord event; // looking for disk inserted events for CD mounts
719 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
720 newmenu_hide_cursor();
727 MaxDisplayable=nitems;
729 //set_screen_mode(SCREEN_MENU);
732 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
733 digi_pause_digi_sounds();
737 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
747 save_canvas = grd_curcanv;
749 gr_set_current_canvas(NULL);
751 save_font = grd_curcanv->cv_font;
756 grd_curcanv->cv_font = TITLE_FONT;
757 gr_get_string_size(title,&string_width,&string_height,&average_width );
762 grd_curcanv->cv_font = SUBTITLE_FONT;
763 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
764 if (string_width > tw )
769 th += LHY(8); //put some space between titles & body
772 grd_curcanv->cv_font = SMALL_FONT;
774 grd_curcanv->cv_font = NORMAL_FONT;
778 nmenus = nothers = 0;
780 // Find menu height & width (store in w,h)
781 for (i=0; i<nitems; i++ ) {
784 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
785 item[i].right_offset = 0;
788 string_height+=LHY(3);
790 item[i].saved_text[0] = '\0';
792 if ( item[i].type == NM_TYPE_SLIDER ) {
795 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
796 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
797 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
799 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
800 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
801 string_width += w1 + aw;
804 if ( item[i].type == NM_TYPE_MENU ) {
808 if ( item[i].type == NM_TYPE_CHECK ) {
811 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
812 item[i].right_offset = w1;
813 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
814 if (w1 > item[i].right_offset)
815 item[i].right_offset = w1;
818 if (item[i].type == NM_TYPE_RADIO ) {
821 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
822 item[i].right_offset = w1;
823 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
824 if (w1 > item[i].right_offset)
825 item[i].right_offset = w1;
828 if (item[i].type==NM_TYPE_NUMBER ) {
832 sprintf( test_text, "%d", item[i].max_value );
833 gr_get_string_size( test_text, &w1, &h1, &aw1 );
834 item[i].right_offset = w1;
835 sprintf( test_text, "%d", item[i].min_value );
836 gr_get_string_size( test_text, &w1, &h1, &aw1 );
837 if ( w1 > item[i].right_offset)
838 item[i].right_offset = w1;
841 if ( item[i].type == NM_TYPE_INPUT ) {
842 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
843 strcpy(item[i].saved_text, item[i].text );
845 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
846 if ( string_width > MAX_TEXT_WIDTH )
847 string_width = MAX_TEXT_WIDTH;
851 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
852 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
853 strcpy(item[i].saved_text, item[i].text );
855 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
860 item[i].w = string_width;
861 item[i].h = string_height;
863 if ( string_width > w )
864 w = string_width; // Save maximum width
865 if ( average_width > aw )
867 h += string_height+1; // Find the height of all strings
870 // Big hack for allowing the netgame options menu to spill over
872 MaxOnMenu=MAXDISPLAYABLEITEMS;
873 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
876 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
879 h=(MaxOnMenu*(string_height+1)+LHY(8));
880 MaxDisplayable=MaxOnMenu;
881 mprintf ((0,"Hey, this is a scroll box!\n"));
894 for (i=0; i<nitems; i++ ) {
896 if (item[i].right_offset > right_offset )
897 right_offset = item[i].right_offset;
899 if (right_offset > 0 )
902 //gr_get_string_size("",&string_width,&string_height,&average_width );
909 twidth = ( tw - w )/2;
914 { right_offset=0; twidth=0;}
916 mprintf(( 0, "Right offset = %d\n", right_offset ));
919 // Find min point of menu border
920 // x = (grd_curscreen->sc_w-w)/2;
921 // y = (grd_curscreen->sc_h-h)/2;
923 w += MenuHires?60:30;
924 h += MenuHires?60:30;
926 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
927 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
929 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
930 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
935 if ( filename != NULL ) {
936 nm_draw_background1( filename );
937 gr_palette_load(gr_palette);
940 // Save the background of the display
941 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h );
942 gr_set_current_canvas(bg.menu_canvas);
944 if ( filename == NULL ) {
945 // Save the background under the menu...
951 bg.saved = gr_create_bitmap( w, h );
952 Assert( bg.saved != NULL );
954 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
956 gr_set_current_canvas( NULL );
958 nm_draw_background(x,y,x+w-1,y+h-1);
960 gr_set_current_canvas( bg.menu_canvas );
962 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
966 bg.background = gr_create_bitmap( w, h );
967 Assert( bg.background != NULL );
969 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
972 // ty = 15 + (yborder/4);
974 ty = MenuHires?30:15;
977 grd_curcanv->cv_font = TITLE_FONT;
978 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
979 gr_get_string_size(title,&string_width,&string_height,&average_width );
982 gr_printf( 0x8000, ty, title );
987 grd_curcanv->cv_font = SUBTITLE_FONT;
988 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
989 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
992 gr_printf( 0x8000, ty, subtitle );
997 grd_curcanv->cv_font = SMALL_FONT;
999 grd_curcanv->cv_font = NORMAL_FONT;
1001 // Update all item's x & y values.
1002 for (i=0; i<nitems; i++ ) {
1003 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1004 item[i].y += (MenuHires?30:15);
1005 if ( item[i].type==NM_TYPE_RADIO ) {
1006 fm = -1; // find first marked one
1007 for ( j=0; j<nitems; j++ ) {
1008 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1009 if (fm==-1 && item[j].value)
1021 old_keyd_repeat = keyd_repeat;
1027 if (citem < 0 ) citem = 0;
1028 if (citem > nitems-1 ) citem = nitems-1;
1031 #ifdef NEWMENU_MOUSE
1035 while ( item[choice].type==NM_TYPE_TEXT ) {
1037 if (choice >= nitems ) {
1040 if (choice == citem ) {
1051 // Clear mouse, joystick to clear button presses.
1052 game_flush_inputs();
1054 #ifdef NEWMENU_MOUSE
1055 mouse_state = omouse_state = 0;
1056 if (filename == NULL && !MenuReordering) {
1057 //draw_close_box(0,0);
1061 if (!MenuReordering && !joydefs_calibrating)
1063 newmenu_show_cursor();
1065 SetCursor(LoadCursor(NULL,IDC_ARROW));
1070 mprintf ((0,"Set to true!\n"));
1073 #ifdef NEWMENU_MOUSE
1074 if (!joydefs_calibrating)
1075 newmenu_show_cursor(); // possibly hidden
1076 omouse_state = mouse_state;
1077 if (!MenuReordering)
1078 mouse_state = mouse_button_state(0);
1079 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1082 //see if redbook song needs to be restarted
1083 songs_check_redbook_repeat();
1090 (*subfunction)(nitems,item,&k,choice);
1093 if (!time_stopped) {
1094 // Save current menu box
1095 if (multi_menu_poll() == -1)
1101 dont_restore = (k == -3); //-3 means don't restore
1106 if (check_button_press())
1109 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1112 old_choice = choice;
1118 if (SurfingNet && !already_showing_info)
1120 show_extra_netgame_info(choice-2);
1122 if (SurfingNet && already_showing_info)
1129 if (SurfingNet && !already_showing_info)
1131 network_request_player_names(choice-2);
1133 if (SurfingNet && already_showing_info)
1148 case KEY_TAB + KEY_SHIFTED:
1151 if (all_text) break;
1158 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1160 if (choice<TopChoice)
1161 { choice=TopChoice; break; }
1163 if (choice<ScrollOffset)
1165 for (i=0;i<nitems;i++)
1168 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1173 if (choice >= nitems ) choice=0;
1174 if (choice < 0 ) choice=nitems-1;
1176 } while ( item[choice].type==NM_TYPE_TEXT );
1177 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1178 item[choice].value = -1;
1179 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1180 item[old_choice].group=0;
1181 strcpy(item[old_choice].text, item[old_choice].saved_text );
1182 item[old_choice].value = -1;
1185 item[old_choice].redraw = 1;
1186 item[choice].redraw=1;
1191 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1192 if (all_text) break;
1199 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1202 { choice--; break; }
1204 if (choice>=MaxOnMenu+ScrollOffset)
1206 for (i=0;i<nitems;i++)
1209 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1214 if (choice < 0 ) choice=nitems-1;
1215 if (choice >= nitems ) choice=0;
1218 } while ( item[choice].type==NM_TYPE_TEXT );
1220 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1221 item[choice].value = -1;
1222 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1223 item[old_choice].group=0;
1224 strcpy(item[old_choice].text, item[old_choice].saved_text );
1225 item[old_choice].value = -1;
1228 item[old_choice].redraw=1;
1229 item[choice].redraw=1;
1232 if ( choice > -1 ) {
1233 switch( item[choice].type ) {
1236 case NM_TYPE_INPUT_MENU:
1239 if ( item[choice].value )
1240 item[choice].value = 0;
1242 item[choice].value = 1;
1243 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1246 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1248 mprintf ((0,"Special redraw!\n"));
1253 item[choice].redraw=1;
1256 for (i=0; i<nitems; i++ ) {
1257 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1262 item[choice].value = 1;
1263 item[choice].redraw = 1;
1269 case KEY_SHIFTED+KEY_UP:
1270 if (MenuReordering && choice!=TopChoice)
1272 Temp=item[choice].text;
1273 TempVal=item[choice].value;
1274 item[choice].text=item[choice-1].text;
1275 item[choice].value=item[choice-1].value;
1276 item[choice-1].text=Temp;
1277 item[choice-1].value=TempVal;
1278 item[choice].redraw=1;
1279 item[choice-1].redraw=1;
1283 case KEY_SHIFTED+KEY_DOWN:
1284 if (MenuReordering && choice!=(nitems-1))
1286 Temp=item[choice].text;
1287 TempVal=item[choice].value;
1288 item[choice].text=item[choice+1].text;
1289 item[choice].value=item[choice+1].value;
1290 item[choice+1].text=Temp;
1291 item[choice+1].value=TempVal;
1292 item[choice].redraw=1;
1293 item[choice+1].redraw=1;
1300 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1301 item[choice].group = 1;
1302 item[choice].redraw = 1;
1303 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1304 item[choice].text[0] = 0;
1305 item[choice].value = -1;
1307 strip_end_whitespace(item[choice].text);
1314 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1315 item[choice].group=0;
1316 strcpy(item[choice].text, item[choice].saved_text );
1317 item[choice].redraw=1;
1318 item[choice].value = -1;
1325 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
1326 case KEY_PRINT_SCREEN:
1327 MAC(newmenu_hide_cursor());
1328 save_screen_shot(0);
1329 for (i=0;i<nitems;i++)
1332 MAC(newmenu_show_cursor());
1338 case KEY_COMMAND+KEY_RIGHT:
1339 songs_goto_next_song();
1341 case KEY_COMMAND+KEY_LEFT:
1342 songs_goto_prev_song();
1344 case KEY_COMMAND+KEY_UP:
1345 songs_play_level_song(1);
1347 case KEY_COMMAND+KEY_DOWN:
1348 songs_stop_redbook();
1351 case KEY_COMMAND+KEY_M:
1353 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1356 key_close(); // no processing of keys with keyboard handler.. jeez
1358 newmenu_hide_cursor();
1359 show_boxed_message ("Mounting CD\nESC to quit");
1360 RBAMountDisk(); // OS has totaly control of the CD.
1361 if (Function_mode == FMODE_MENU)
1362 songs_play_song(SONG_TITLE,1);
1363 else if (Function_mode == FMODE_GAME)
1364 songs_play_level_song( Current_level_num );
1365 clear_boxed_message();
1366 newmenu_show_cursor();
1373 case KEY_COMMAND+KEY_E:
1374 songs_stop_redbook();
1376 k = -1; // force key not to register
1380 case KEY_COMMAND+KEY_Q: {
1381 if ( !(Game_mode & GM_MULTI) )
1383 if (!joydefs_calibrating)
1384 newmenu_show_cursor();
1385 k = -1; // force key not to register
1391 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1396 case KEY_SHIFTED + KEY_B:
1399 grs_canvas *canv_save = grd_curcanv;
1400 grs_canvas *temp_canv;
1403 ubyte pal_save[768];
1405 memcpy(pal_save, gr_palette, 768);
1406 gr_use_palette_table(DEFAULT_LEVEL_PALETTE);
1407 memcpy(bm_pal, gr_palette, 768);
1408 gr_copy_palette(gr_palette, pal_save, 768);
1410 if (k & KEY_SHIFTED)
1416 n = Num_bitmap_files - 1;
1417 n %= Num_bitmap_files;
1418 bm = &GameBitmaps[n];
1419 PIGGY_PAGE_IN( *(bitmap_index *)&n );
1420 con_printf(CON_DEBUG, "showing bitmap %d of %d: %s\n", n, Num_bitmap_files, piggy_game_bitmap_name(bm));
1422 temp_canv = gr_create_canvas(bm->bm_w, bm->bm_h);
1423 gr_set_current_canvas(temp_canv);
1424 gr_bitmap(0, 0, bm);
1425 gr_set_current_canvas(&grd_curscreen->sc_canvas);
1426 gr_remap_bitmap_good(&temp_canv->cv_bitmap, bm_pal, -1, -1);
1427 gr_bitmap(0, 0, &temp_canv->cv_bitmap);
1428 gr_free_canvas(temp_canv);
1429 gr_set_current_canvas(canv_save);
1434 case KEY_SHIFTED + KEY_P:
1436 char *palettes[] = {
1446 static unsigned int palnum = 0;
1448 if (k & KEY_SHIFTED)
1453 palnum %= sizeof(palettes)/sizeof(char *);
1454 load_palette(palettes[palnum], 0, 0);
1462 #ifdef NEWMENU_MOUSE // for mouse selection of menu's etc.
1463 if ( !done && mouse_state && !omouse_state && !all_text ) {
1464 mouse_get_pos(&mx, &my);
1465 for (i=0; i<nitems; i++ ) {
1466 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1467 x2 = x1 + item[i].w;
1468 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1469 y2 = y1 + item[i].h;
1470 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1471 if (i+ScrollOffset != choice) {
1472 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1475 choice = i + ScrollOffset;
1477 switch( item[choice].type ) {
1479 if ( item[choice].value )
1480 item[choice].value = 0;
1482 item[choice].value = 1;
1483 item[choice].redraw=1;
1490 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1492 mprintf ((0,"Special redraw!\n"));
1499 for (i=0; i<nitems; i++ ) {
1500 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1505 item[choice].value = 1;
1506 item[choice].redraw = 1;
1509 item[old_choice].redraw=1;
1515 if (mouse_state && all_text)
1518 if ( !done && mouse_state && !all_text ) {
1519 mouse_get_pos(&mx, &my);
1521 // check possible scrollbar stuff first
1523 int arrow_width, arrow_height, aw;
1525 if (ScrollOffset != 0) {
1526 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1527 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1528 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1529 x1 = x1 - arrow_width;
1530 y2 = y1 + arrow_height;
1531 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1534 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1536 if (choice<ScrollOffset)
1538 for (i=0;i<nitems;i++)
1541 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1545 if (ScrollOffset+MaxDisplayable<nitems) {
1546 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1547 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1548 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1549 x1 = x1 - arrow_width;
1550 y2 = y1 + arrow_height;
1551 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1554 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1556 if (choice>=MaxOnMenu+ScrollOffset)
1558 for (i=0;i<nitems;i++)
1561 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1567 for (i=0; i<nitems; i++ ) {
1568 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1569 x2 = x1 + item[i].w;
1570 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1571 y2 = y1 + item[i].h;
1572 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1573 if (i+ScrollOffset != choice) {
1574 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1577 choice = i + ScrollOffset;
1579 if ( item[choice].type == NM_TYPE_SLIDER ) {
1580 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1 = NULL;
1581 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1583 strcpy(slider_text, item[choice].saved_text);
1584 p = strchr(slider_text, '\t');
1590 gr_get_string_size(s1, &slider_width, &height, &aw);
1591 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1592 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1593 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1595 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1596 x2 = x1 + slider_width + sright_width;
1597 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1598 item[choice].value = item[choice].min_value;
1599 item[choice].redraw = 2;
1600 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1601 item[choice].value = item[choice].max_value;
1602 item[choice].redraw = 2;
1603 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1604 int num_values, value_width, new_value;
1606 num_values = item[choice].max_value - item[choice].min_value + 1;
1607 value_width = (slider_width - sleft_width - sright_width) / num_values;
1608 new_value = (mx - x1 - sleft_width) / value_width;
1609 if ( item[choice].value != new_value ) {
1610 item[choice].value = new_value;
1611 item[choice].redraw = 2;
1617 if (choice == old_choice)
1619 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1620 item[choice].value = -1;
1621 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1622 item[old_choice].group=0;
1623 strcpy(item[old_choice].text, item[old_choice].saved_text );
1624 item[old_choice].value = -1;
1627 item[old_choice].redraw = 1;
1628 item[choice].redraw=1;
1634 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1635 mouse_get_pos(&mx, &my);
1636 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1637 x2 = x1 + item[choice].w;
1638 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1639 y2 = y1 + item[choice].h;
1640 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1641 if (Hack_DblClick_MenuMode) {
1642 if (dblclick_flag) done = 1;
1643 else dblclick_flag = 1;
1649 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1650 item[choice].group = 1;
1651 item[choice].redraw = 1;
1652 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1653 item[choice].text[0] = 0;
1654 item[choice].value = -1;
1656 strip_end_whitespace(item[choice].text);
1660 if ( !done && !mouse_state && omouse_state && close_box ) {
1661 mouse_get_pos(&mx, &my);
1662 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1663 x2 = x1 + CLOSE_SIZE;
1664 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1665 y2 = y1 + CLOSE_SIZE;
1666 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1672 // HACK! Don't redraw loadgame preview
1673 if (RestoringMenu) item[0].redraw = 0;
1674 #endif // NEWMENU_MOUSE
1676 if ( choice > -1 ) {
1679 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1680 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1681 if (item[choice].value == -1)
1682 item[choice].value = (int)strlen(item[choice].text);
1683 if (item[choice].value > 0)
1684 item[choice].value--;
1685 item[choice].text[item[choice].value] = 0;
1686 item[choice].redraw = 1;
1688 ascii = key_to_ascii(k);
1689 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1693 if (item[choice].value==-1) {
1694 item[choice].value = 0;
1697 allowed = char_allowed(ascii);
1699 if (!allowed && ascii==' ' && char_allowed('_')) {
1705 item[choice].text[item[choice].value++] = ascii;
1706 item[choice].text[item[choice].value] = 0;
1707 item[choice].redraw=1;
1711 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1712 ascii = key_to_ascii(k);
1714 int choice1 = choice;
1715 ascii = toupper(ascii);
1719 if (choice1 >= nitems ) choice1=0;
1720 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1721 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1722 (item[choice1].type==NM_TYPE_CHECK) ||
1723 (item[choice1].type==NM_TYPE_RADIO) ||
1724 (item[choice1].type==NM_TYPE_NUMBER) ||
1725 (item[choice1].type==NM_TYPE_SLIDER) )
1726 && (ascii==toupper(ch)) ) {
1730 item[old_choice].redraw=1;
1731 item[choice].redraw=1;
1733 } while (choice1 != choice );
1737 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1738 int ov=item[choice].value;
1743 case KEY_MINUS+KEY_SHIFTED:
1745 item[choice].value -= 1;
1750 case KEY_EQUAL+KEY_SHIFTED:
1752 item[choice].value++;
1757 item[choice].value += 10;
1762 item[choice].value -= 10;
1765 if (ov!=item[choice].value)
1766 item[choice].redraw=1;
1771 gr_set_current_canvas(bg.menu_canvas);
1773 // Redraw everything...
1774 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1776 if (item[i].redraw) // warning! ugly hack below
1778 item[i].y-=((string_height+1)*ScrollOffset);
1779 newmenu_hide_cursor();
1780 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1782 #ifdef NEWMENU_MOUSE
1783 if (!MenuReordering && !joydefs_calibrating)
1784 newmenu_show_cursor();
1786 item[i].y+=((string_height+1)*ScrollOffset);
1788 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1789 update_cursor( &item[i]);
1795 //grd_curcanv->cv_font = NORMAL_FONT;
1797 if (LastScrollCheck!=ScrollOffset)
1799 LastScrollCheck=ScrollOffset;
1800 grd_curcanv->cv_font = SELECTED_FONT;
1802 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1803 sx=item[ScrollOffset].x-(MenuHires?24:12);
1806 if (ScrollOffset!=0)
1807 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1809 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1811 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1812 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1814 if (ScrollOffset+MaxDisplayable<nitems)
1815 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1817 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1823 if ( !dont_restore && gr_palette_faded_out ) {
1824 gr_palette_fade_in( gr_palette, 32, 0 );
1828 newmenu_hide_cursor();
1830 // Restore everything...
1832 gr_set_current_canvas(bg.menu_canvas);
1834 if ( filename == NULL ) {
1835 // Save the background under the menu...
1836 gr_bitmap(0, 0, bg.saved);
1837 gr_free_bitmap(bg.saved);
1838 d_free( bg.background );
1840 if (!dont_restore) //info passed back from subfunction
1841 gr_bitmap(0, 0, bg.background);
1842 gr_free_bitmap(bg.background);
1845 gr_free_sub_canvas( bg.menu_canvas );
1847 gr_set_current_canvas(save_canvas);
1848 grd_curcanv->cv_font = save_font;
1849 keyd_repeat = old_keyd_repeat;
1851 game_flush_inputs();
1862 if ( sound_stopped )
1863 digi_resume_digi_sounds();
1870 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1876 char nm_text[MESSAGEBOX_TEXT_SIZE];
1877 newmenu_item nm_message_items[5];
1879 va_start(args, nchoices );
1881 Assert( nchoices <= 5 );
1883 for (i=0; i<nchoices; i++ ) {
1884 s = va_arg( args, char * );
1885 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1887 format = va_arg( args, char * );
1888 strcpy( nm_text, "" );
1889 vsprintf(nm_text,format,args);
1892 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1894 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1897 int nm_messagebox( char *title, int nchoices, ... )
1903 char nm_text[MESSAGEBOX_TEXT_SIZE];
1904 newmenu_item nm_message_items[5];
1906 va_start(args, nchoices );
1908 Assert( nchoices <= 5 );
1910 for (i=0; i<nchoices; i++ ) {
1911 s = va_arg( args, char * );
1912 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1914 format = va_arg( args, char * );
1915 strcpy( nm_text, "" );
1916 vsprintf(nm_text,format,args);
1919 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1921 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1927 void newmenu_file_sort( int n, char *list )
1934 for (i=incr; i<n; i++ ) {
1937 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1938 memcpy( t, &list[j*14], FILENAME_LEN );
1939 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1940 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1951 void delete_player_saved_games(char * name)
1956 for (i=0;i<10; i++) {
1957 sprintf( filename, PLAYER_DIR "%s.sg%d", name, i );
1958 PHYSFS_delete(filename);
1962 #define MAX_FILES 300
1964 //FIXME: should maybe put globbing ability back?
1965 int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
1971 int NumFiles=0, key,done, citem, ocitem;
1972 char * filenames = NULL;
1973 int NumFiles_displayed = 8;
1974 int first_item = -1, ofirst_item;
1975 int old_keyd_repeat = keyd_repeat;
1978 int demos_deleted=0;
1979 int initialized = 0;
1981 int w_x, w_y, w_w, w_h, title_height;
1982 int box_x, box_y, box_w, box_h;
1983 bkg bg; // background under listbox
1984 #ifdef NEWMENU_MOUSE
1985 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
1986 int mouse2_state, omouse2_state;
1987 int dblclick_flag=0;
1990 int show_up_arrow=0, show_down_arrow=0;
1994 w_x=w_y=w_w=w_h=title_height=0;
1995 box_x=box_y=box_w=box_h=0;
1997 filenames = d_malloc( MAX_FILES * 14 );
1998 if (filenames==NULL) return 0;
2003 if (!stricmp(type, "plr"))
2005 else if (!stricmp(type, "dem"))
2012 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2014 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2019 find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
2020 for (f = find; *f != NULL; f++)
2024 ext = strrchr(*f, '.');
2025 if (!ext || strnicmp(ext, ".plr", 4))
2028 if (NumFiles < MAX_FILES)
2030 strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
2035 p = strchr(&filenames[NumFiles*14], '.');
2045 PHYSFS_freeList(find);
2047 if ( (NumFiles < 1) && demos_deleted ) {
2051 if ( (NumFiles < 1) && demo_mode ) {
2052 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2058 if ( (NumFiles < 2) && player_mode ) {
2060 goto ExitFileMenuEarly;
2067 nm_messagebox(NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND);
2074 // set_screen_mode(SCREEN_MENU);
2077 gr_set_current_canvas(NULL);
2079 grd_curcanv->cv_font = SUBTITLE_FONT;
2084 for (i=0; i<NumFiles; i++ ) {
2086 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2092 gr_get_string_size( title, &w, &h, &aw );
2095 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2099 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2101 w_w += (grd_curfont->ft_w * 4);
2102 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2104 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2105 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2107 w_x = (grd_curcanv->cv_w-w_w)/2;
2108 w_y = (grd_curcanv->cv_h-w_h)/2;
2110 if ( w_x < 0 ) w_x = 0;
2111 if ( w_y < 0 ) w_y = 0;
2113 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2114 box_y = w_y + title_height;
2116 // save the screen behind the menu.
2120 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2121 bg.background = &VR_offscreen_buffer->cv_bitmap;
2123 bg.background = gr_create_bitmap( w_w, w_h );
2125 Assert( bg.background != NULL );
2128 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2131 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2134 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2136 gr_string( 0x8000, w_y+10, title );
2141 if ( !player_mode ) {
2142 newmenu_file_sort( NumFiles, filenames );
2144 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2145 newmenu_file_sort( NumFiles, filenames );
2147 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2149 for ( i=0; i<NumFiles; i++ ) {
2150 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2151 #ifdef NEWMENU_MOUSE
2159 #ifdef NEWMENU_MOUSE
2160 mouse_state = omouse_state = 0;
2161 mouse2_state = omouse2_state = 0;
2162 //draw_close_box(w_x,w_y);
2163 newmenu_show_cursor();
2168 ofirst_item = first_item;
2171 #ifdef NEWMENU_MOUSE
2172 omouse_state = mouse_state;
2173 omouse2_state = mouse2_state;
2174 mouse_state = mouse_button_state(0);
2175 mouse2_state = mouse_button_state(1);
2178 //see if redbook song needs to be restarted
2179 songs_check_redbook_repeat();
2184 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2185 case KEY_PRINT_SCREEN:
2186 MAC(newmenu_hide_cursor());
2187 save_screen_shot(0);
2189 MAC(newmenu_show_cursor());
2193 case KEY_CTRLED+KEY_D:
2194 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2198 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2200 newmenu_hide_cursor();
2202 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2204 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2205 newmenu_show_cursor();
2209 char name[PATH_MAX];
2211 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2215 strcpy(name, demo_mode?DEMO_DIR:"");
2216 strcat(name,&filenames[citem*14]);
2223 if ( !strncmp(name, ".\\", 2) )
2224 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2225 name[i] = name[i+1];
2226 while ( (p = strchr(name, '\\')) )
2231 ret = !PHYSFS_delete(name);
2235 if ((!ret) && player_mode) {
2236 delete_player_saved_games( &filenames[citem*14] );
2241 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2243 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2244 } else if (demo_mode)
2269 citem += NumFiles_displayed;
2273 citem -= NumFiles_displayed;
2276 if (allow_abort_flag) {
2286 case KEY_COMMAND+KEY_Q: {
2287 if ( !(Game_mode & GM_MULTI) )
2292 newmenu_show_cursor();
2300 int ascii = key_to_ascii(key);
2301 if ( ascii < 255 ) {
2304 if (cc1 < 0 ) cc1 = 0;
2305 if (cc1 >= NumFiles ) cc1 = 0;
2307 if ( cc < 0 ) cc = 0;
2308 if ( cc >= NumFiles ) cc = 0;
2309 if ( citem == cc ) break;
2311 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2326 if (citem>=NumFiles)
2329 if (citem< first_item)
2332 if (citem>=( first_item+NumFiles_displayed))
2334 first_item = citem-NumFiles_displayed+1;
2338 if (NumFiles>first_item+NumFiles_displayed)
2349 if (NumFiles <= NumFiles_displayed )
2352 if (first_item>NumFiles-NumFiles_displayed)
2354 first_item = NumFiles-NumFiles_displayed;
2357 if (first_item < 0 ) first_item = 0;
2359 #ifdef NEWMENU_MOUSE
2360 if (mouse_state || mouse2_state) {
2363 mouse_get_pos(&mx, &my);
2364 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2365 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2367 x2 = box_x + box_w - 1;
2368 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2370 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2371 if (i == citem && !mouse2_state) {
2381 if (!mouse_state && omouse_state) {
2384 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2385 mouse_get_pos(&mx, &my);
2387 x2 = box_x + box_w - 1;
2388 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2390 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2391 if (dblclick_flag) done = 1;
2392 else dblclick_flag = 1;
2396 if ( !mouse_state && omouse_state ) {
2397 mouse_get_pos(&mx, &my);
2398 x1 = w_x + CLOSE_X + 2;
2399 x2 = x1 + CLOSE_SIZE - 2;
2400 y1 = w_y + CLOSE_Y + 2;
2401 y2 = y1 + CLOSE_SIZE - 2;
2402 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2411 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2413 y1 = box_y+box_h-LHY(7);
2415 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2422 gr_setcolor( BM_XRGB(2,2,2));
2423 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2424 gr_setcolor( BM_XRGB( 0,0,0) );
2426 if (ofirst_item != first_item) {
2427 newmenu_hide_cursor();
2428 gr_setcolor( BM_XRGB( 0,0,0) );
2429 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2431 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2433 if ( i >= NumFiles ) {
2435 gr_setcolor( BM_XRGB(5,5,5));
2436 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2437 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2439 gr_setcolor( BM_XRGB(2,2,2));
2440 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2442 gr_setcolor( BM_XRGB(0,0,0));
2443 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2447 grd_curcanv->cv_font = SELECTED_FONT;
2449 grd_curcanv->cv_font = NORMAL_FONT;
2450 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2452 gr_setcolor( BM_XRGB(5,5,5));
2453 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2454 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2456 gr_setcolor( BM_XRGB(2,2,2));
2457 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2458 gr_setcolor( BM_XRGB(0,0,0));
2460 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2461 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2464 newmenu_show_cursor();
2465 } else if ( citem != ocitem ) {
2468 newmenu_hide_cursor();
2470 if ( (i>=0) && (i<NumFiles) ) {
2471 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2473 grd_curcanv->cv_font = SELECTED_FONT;
2475 grd_curcanv->cv_font = NORMAL_FONT;
2476 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2477 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2478 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2481 if ( (i>=0) && (i<NumFiles) ) {
2482 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2484 grd_curcanv->cv_font = SELECTED_FONT;
2486 grd_curcanv->cv_font = NORMAL_FONT;
2487 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2488 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2489 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2491 newmenu_show_cursor();
2495 grd_curcanv->cv_font = NORMAL_FONT;
2497 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2501 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2505 if (show_down_arrow)
2506 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2510 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2518 MAC(newmenu_hide_cursor());
2520 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2527 keyd_repeat = old_keyd_repeat;
2529 if ( initialized ) {
2530 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2531 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2532 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2533 gr_free_bitmap(bg.background);
2535 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2547 // Example listbox callback function...
2548 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2552 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2553 // if ( *nitems > 1 ) {
2554 // PHYSFS_delete(items[*citem]); // Delete the file
2555 // for (i=*citem; i<*nitems-1; i++ ) {
2556 // items[i] = items[i+1];
2558 // *nitems = *nitems - 1;
2559 // d_free( items[*nitems] );
2560 // items[*nitems] = NULL;
2561 // return 1; // redraw;
2568 #define LB_ITEMS_ON_SCREEN 8
2570 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2572 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2575 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 ) )
2578 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2579 int old_keyd_repeat = keyd_repeat;
2580 int width, height, wx, wy, title_height, border_size;
2581 int total_width,total_height;
2583 #ifdef NEWMENU_MOUSE
2584 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2585 int close_x,close_y;
2587 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2593 // set_screen_mode(SCREEN_MENU);
2596 gr_set_current_canvas(NULL);
2598 grd_curcanv->cv_font = SUBTITLE_FONT;
2601 for (i=0; i<nitems; i++ ) {
2603 gr_get_string_size( items[i], &w, &h, &aw );
2607 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2611 gr_get_string_size( title, &w, &h, &aw );
2614 title_height = h + 5;
2617 border_size = grd_curfont->ft_w;
2618 WIN (border_size=grd_curfont->ft_w*2);
2620 width += (grd_curfont->ft_w);
2621 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2622 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2624 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2625 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2626 if ( wy < title_height )
2629 total_width = width+2*border_size;
2630 total_height = height+2*border_size+title_height;
2634 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2635 bg.background = &VR_offscreen_buffer->cv_bitmap;
2637 //bg.background = gr_create_bitmap( width, (height + title_height) );
2638 bg.background = gr_create_bitmap(total_width,total_height);
2639 Assert( bg.background != NULL );
2641 //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 );
2642 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2645 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2648 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2650 gr_string( 0x8000, wy - title_height, title );
2653 citem = default_item;
2654 if ( citem < 0 ) citem = 0;
2655 if ( citem >= nitems ) citem = 0;
2659 #ifdef NEWMENU_MOUSE
2660 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2661 close_x = wx-border_size;
2662 close_y = wy-title_height-border_size;
2663 //draw_close_box(close_x,close_y);
2664 newmenu_show_cursor();
2669 ofirst_item = first_item;
2670 #ifdef NEWMENU_MOUSE
2671 omouse_state = mouse_state;
2672 mouse_state = mouse_button_state(0);
2674 //see if redbook song needs to be restarted
2675 songs_check_redbook_repeat();
2679 if ( listbox_callback )
2680 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2694 else if (simukey==1)
2700 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2701 case KEY_PRINT_SCREEN:
2702 MAC(newmenu_hide_cursor());
2703 save_screen_shot(0);
2705 MAC(newmenu_show_cursor());
2726 citem += LB_ITEMS_ON_SCREEN;
2730 citem -= LB_ITEMS_ON_SCREEN;
2733 if (allow_abort_flag) {
2743 case KEY_COMMAND+KEY_Q: {
2744 if ( !(Game_mode & GM_MULTI) )
2746 newmenu_show_cursor();
2753 int ascii = key_to_ascii(key);
2754 if ( ascii < 255 ) {
2757 if (cc1 < 0 ) cc1 = 0;
2758 if (cc1 >= nitems ) cc1 = 0;
2760 if ( cc < 0 ) cc = 0;
2761 if ( cc >= nitems ) cc = 0;
2762 if ( citem == cc ) break;
2764 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2781 if (citem< first_item)
2784 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2785 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2787 if (nitems <= LB_ITEMS_ON_SCREEN )
2790 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
2791 first_item = nitems-LB_ITEMS_ON_SCREEN;
2792 if (first_item < 0 ) first_item = 0;
2795 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
2806 #ifdef NEWMENU_MOUSE
2810 mouse_get_pos(&mx, &my);
2811 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2814 gr_get_string_size(items[i], &w, &h, &aw );
2817 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2819 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2831 //no double-click stuff for listbox
2832 //@@if (!mouse_state && omouse_state) {
2835 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
2836 //@@ mouse_get_pos(&mx, &my);
2838 //@@ x2 = wx + width;
2839 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
2841 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2842 //@@ if (dblclick_flag) done = 1;
2846 //check for close box clicked
2847 if ( !mouse_state && omouse_state ) {
2848 mouse_get_pos(&mx, &my);
2849 x1 = close_x + CLOSE_X + 2;
2850 x2 = x1 + CLOSE_SIZE - 2;
2851 y1 = close_y + CLOSE_Y + 2;
2852 y2 = y1 + CLOSE_SIZE - 2;
2853 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2863 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
2865 y1 = total_height-LHY(7);
2867 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
2875 if ( (ofirst_item != first_item) || redraw) {
2876 newmenu_hide_cursor();
2878 gr_setcolor( BM_XRGB( 0,0,0) );
2879 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2881 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2882 if ( i >= nitems ) {
2883 gr_setcolor( BM_XRGB(0,0,0));
2884 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
2887 grd_curcanv->cv_font = SELECTED_FONT;
2889 grd_curcanv->cv_font = NORMAL_FONT;
2890 gr_get_string_size(items[i], &w, &h, &aw );
2891 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2892 gr_string( wx+5, y, items[i] );
2897 // If Win95 port, draw up/down arrows on left side of menu
2899 grd_curcanv->cv_font = NORMAL_FONT;
2901 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
2905 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
2909 if (show_down_arrow)
2910 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
2914 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
2921 newmenu_show_cursor();
2923 } else if ( citem != ocitem ) {
2926 newmenu_hide_cursor();
2929 if ( (i>=0) && (i<nitems) ) {
2930 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2932 grd_curcanv->cv_font = SELECTED_FONT;
2934 grd_curcanv->cv_font = NORMAL_FONT;
2935 gr_get_string_size(items[i], &w, &h, &aw );
2936 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2937 gr_string( wx+5, y, items[i] );
2941 if ( (i>=0) && (i<nitems) ) {
2942 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2944 grd_curcanv->cv_font = SELECTED_FONT;
2946 grd_curcanv->cv_font = NORMAL_FONT;
2947 gr_get_string_size( items[i], &w, &h, &aw );
2948 gr_rect( wx, y-1, wx+width-1, y+h );
2949 gr_string( wx+5, y, items[i] );
2952 newmenu_show_cursor();
2956 newmenu_hide_cursor();
2958 keyd_repeat = old_keyd_repeat;
2960 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2962 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2963 gr_free_bitmap(bg.background);
2966 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) );
2973 int newmenu_filelist( char * title, char * filespec, char * filename )
2976 char * Filenames[MAX_FILES];
2977 char FilenameText[MAX_FILES][14];
2978 FILEFINDSTRUCT find;
2981 if( !FileFindFirst( filespec, &find ) ) {
2983 if (NumFiles<MAX_FILES) {
2984 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
2985 Filenames[NumFiles] = FilenameText[NumFiles];
2990 } while( !FileFindNext( &find ) );
2994 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
2996 strcpy( filename, Filenames[i] );
3003 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3004 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3010 char nm_text[MESSAGEBOX_TEXT_SIZE];
3011 newmenu_item nm_message_items[5];
3013 va_start(args, nchoices );
3015 Assert( nchoices <= 5 );
3017 for (i=0; i<nchoices; i++ ) {
3018 s = va_arg( args, char * );
3019 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3021 format = va_arg( args, char * );
3022 //sprintf( nm_text, "" ); // adb: ?
3023 vsprintf(nm_text,format,args);
3026 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3028 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3030 //end this section addition - Victor Rachels
3033 extern netgame_info Active_games[];
3034 extern int NumActiveNetgames;
3036 void show_extra_netgame_info(int choice)
3042 if (choice>=NumActiveNetgames)
3047 m[i].text=(char *)&mtext[i];
3048 m[i].type=NM_TYPE_TEXT;
3051 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3052 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3053 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3054 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3056 already_showing_info=1;
3057 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3058 already_showing_info=0;
3063 /* Spiffy word wrap string formatting function */
3065 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3071 tbuf = (char *)d_malloc((unsigned int)strlen(sbuf) + 1);
3074 wordptr = strtok(tbuf, " ");
3075 if (!wordptr) return;
3081 col = col + (int)strlen(wordptr) + 1;
3082 if (col >=line_length) {
3084 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3087 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3089 wordptr = strtok(NULL, " ");