2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
29 #if !defined(_MSC_VER) && !defined(macintosh)
76 #define MAXDISPLAYABLEITEMS 15
78 #define LHX(x) ((x)*(MenuHires?2:1))
79 #define LHY(y) ((y)*(MenuHires?2.4:1))
81 #define TITLE_FONT HUGE_FONT
82 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
83 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
84 #define SUBTITLE_FONT MEDIUM3_FONT
86 #define NORMAL_CHECK_BOX "\x81" // 129
87 #define CHECKED_CHECK_BOX "\x82" // 130
89 #define NORMAL_RADIO_BOX "\x7f" // 127
90 #define CHECKED_RADIO_BOX "\x80" // 128
91 #define CURSOR_STRING "_"
92 #define SLIDER_LEFT "\x83" // 131
93 #define SLIDER_RIGHT "\x84" // 132
94 #define SLIDER_MIDDLE "\x85" // 133
95 #define SLIDER_MARKER "\x86" // 134
96 #define UP_ARROW_MARKER "\x87" // 135
97 #define DOWN_ARROW_MARKER "\x88" // 136
99 int newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem, char * filename, int width, int height, int TinyMode );
100 void show_extra_netgame_info(int choice);
103 int Newmenu_first_time = 1;
104 //--unused-- int Newmenu_fade_in = 1;
107 grs_canvas * menu_canvas;
108 grs_bitmap * saved; // The background under the menu.
109 grs_bitmap * background;
112 grs_bitmap nm_background,nm_background_save;
114 #define MESSAGEBOX_TEXT_SIZE 2176 // How many characters in messagebox (changed form 300 (fixes crash from show_game_score and friends) - 2000/01/18 Matt Mueller)
115 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
117 ubyte MenuReordering=0;
119 char Pauseable_menu=0;
120 char already_showing_info=0;
123 void newmenu_close() {
124 if ( nm_background.bm_data )
125 d_free(nm_background.bm_data);
127 if ( nm_background_save.bm_data )
128 d_free(nm_background_save.bm_data);
129 Newmenu_first_time = 1;
132 ubyte background_palette[768];
134 //should be called whenever the palette changes
135 void nm_remap_background()
137 if (!Newmenu_first_time) {
138 if (!nm_background.bm_data)
139 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
141 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
143 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
149 extern char last_palette_loaded[];
151 void nm_draw_background1(char * filename)
158 //@@//I think this only gets called to fill the whole screen
159 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
160 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
162 pcx_error = pcx_get_dimensions(filename, &width, &height);
163 if (pcx_error != PCX_ERROR_NONE)
164 Error("Could not open pcx file <%s>\n", filename);
166 bmp = gr_create_bitmap(width, height);
168 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
169 Assert(pcx_error == PCX_ERROR_NONE);
171 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
174 { //remap stuff. this code is kindof a hack
176 //now, before we bring up the menu, we need to
177 //do some stuff to make sure the palette is ok. First, we need to
178 //get our current palette into the 2d's array, so the remapping will
179 //work. Second, we need to remap the fonts. Third, we need to fill
180 //in part of the fade tables so the darkening of the menu edges works
182 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
184 gr_palette_load(gr_palette);
186 remap_fonts_and_menus(1);
194 strcpy(last_palette_loaded,""); //force palette load next time
198 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
199 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
201 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
203 int Background_hires;
206 void nm_draw_background(int x1, int y1, int x2, int y2 )
210 if (Newmenu_first_time || MenuHires!=Background_hires) {
213 if (Newmenu_first_time) {
214 atexit( newmenu_close );
215 Newmenu_first_time = 0;
216 nm_background_save.bm_data=NULL;
219 if (nm_background_save.bm_data)
220 d_free(nm_background_save.bm_data);
221 if (nm_background.bm_data)
222 d_free(nm_background.bm_data);
225 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
226 Assert(pcx_error == PCX_ERROR_NONE);
228 nm_background = nm_background_save;
229 nm_background.bm_data=NULL;
230 nm_remap_background();
232 Background_hires = MenuHires;
235 if ( x1 < 0 ) x1 = 0;
236 if ( y1 < 0 ) y1 = 0;
241 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
242 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
249 grs_bitmap *tmp = gr_create_bitmap(w, h);
251 gr_bitmap_scale_to(&nm_background, tmp);
254 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
256 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
261 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
263 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
267 Gr_scanline_darkening_level = 2*7;
269 gr_setcolor( BM_XRGB(0,0,0) );
270 gr_urect( x2-5, y1+5, x2-5, y2-5 );
271 gr_urect( x2-4, y1+4, x2-4, y2-5 );
272 gr_urect( x2-3, y1+3, x2-3, y2-5 );
273 gr_urect( x2-2, y1+2, x2-2, y2-5 );
274 gr_urect( x2-1, y1+1, x2-1, y2-5 );
275 gr_urect( x2+0, y1+0, x2-0, y2-5 );
277 gr_urect( x1+5, y2-5, x2, y2-5 );
278 gr_urect( x1+4, y2-4, x2, y2-4 );
279 gr_urect( x1+3, y2-3, x2, y2-3 );
280 gr_urect( x1+2, y2-2, x2, y2-2 );
281 gr_urect( x1+1, y2-1, x2, y2-1 );
282 gr_urect( x1+0, y2, x2, y2-0 );
285 Gr_scanline_darkening_level = GR_FADE_LEVELS;
288 void nm_restore_background( int x, int y, int w, int h )
295 if ( x1 < 0 ) x1 = 0;
296 if ( y1 < 0 ) y1 = 0;
298 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
299 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
304 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
307 // Draw a left justfied string
308 void nm_string( bkg * b, int w1,int x, int y, char * s)
310 int w,h,aw,tx=0,t=0,i;
311 char *p,*s1,*s2,measure[2];
312 int XTabs[]={15,87,124,162,228,253};
318 XTabs[i]=(LHX(XTabs[i]));
325 p = strchr( s2, '\t' );
332 gr_get_string_size(s2, &w, &h, &aw );
338 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
339 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
342 for (i=0;i<strlen(s2);i++) {
343 if (s2[i]=='\t' && SurfingNet) {
349 gr_get_string_size(measure,&tx,&h,&aw);
350 gr_string(x,y,measure);
357 if (!SurfingNet && p && (w1>0) ) {
358 gr_get_string_size(s1, &w, &h, &aw );
360 gr_string( x+w1-w, y, s1 );
367 // Draw a slider and it's string
368 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
375 p = strchr( s, '\t' );
381 gr_get_string_size(s, &w, &h, &aw );
384 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
385 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
387 gr_string( x, y, s );
390 gr_get_string_size(s1, &w, &h, &aw );
393 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
395 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
397 gr_string( x+w1-w, y, s1 );
404 // Draw a left justfied string with black background.
405 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
408 gr_get_string_size(s, &w, &h, &aw );
411 gr_setcolor( BM_XRGB(2,2,2) );
412 gr_rect( x-1, y-1, x-1, y+h-1 );
413 gr_rect( x-1, y-1, x+w1-1, y-1 );
416 gr_setcolor( BM_XRGB(5,5,5) );
417 gr_rect( x, y+h, x+w1, y+h);
418 gr_rect( x+w1, y-1, x+w1, y+h );
420 gr_setcolor( BM_XRGB(0,0,0) );
421 gr_rect( x, y, x+w1-1, y+h-1 );
423 gr_string( x+1, y+1, s );
427 // Draw a right justfied string
428 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
431 gr_get_string_size(s, &w, &h, &aw );
436 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
439 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
440 gr_string( x-w, y, s );
445 //for text items, constantly redraw cursor (to achieve flash)
446 void update_cursor( newmenu_item *item)
449 fix time = timer_get_approx_seconds();
451 char * text = item->text;
453 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
456 gr_get_string_size(text, &w, &h, &aw );
457 if ( w > item->w-10 )
464 x = item->x+w; y = item->y;
467 gr_string( x, y, CURSOR_STRING );
469 gr_setcolor( BM_XRGB(0,0,0) );
470 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
474 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
479 gr_get_string_size(text, &w1, &h1, &aw );
488 nm_string_black( b, w, x, y, text );
491 gr_string( x+w1+1, y, CURSOR_STRING );
495 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
500 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
502 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
504 if (item->text[0]=='\t')
505 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
510 grd_curcanv->cv_font = SELECTED_FONT;
512 grd_curcanv->cv_font = NORMAL_FONT;
515 if (is_current && item->type == NM_TYPE_TEXT)
516 grd_curcanv->cv_font = NORMAL_FONT;
520 switch( item->type ) {
522 // grd_curcanv->cv_font=TEXT_FONT;
523 // fall through on purpose
526 nm_string( b, item->w, item->x, item->y, item->text );
528 case NM_TYPE_SLIDER: {
530 if (item->value < item->min_value) item->value=item->min_value;
531 if (item->value > item->max_value) item->value=item->max_value;
532 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
533 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
534 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
536 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
538 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
540 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
543 case NM_TYPE_INPUT_MENU:
544 if ( item->group==0 ) {
545 nm_string( b, item->w, item->x, item->y, item->text );
547 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
551 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
554 nm_string( b, item->w, item->x, item->y, item->text );
556 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
558 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
561 nm_string( b, item->w, item->x, item->y, item->text );
563 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
565 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
567 case NM_TYPE_NUMBER: {
569 if (item->value < item->min_value) item->value=item->min_value;
570 if (item->value > item->max_value) item->value=item->max_value;
571 nm_string( b, item->w, item->x, item->y, item->text );
572 sprintf( text, "%d", item->value );
573 nm_rstring( b,item->right_offset,item->x, item->y, text );
579 char *Newmenu_allowed_chars=NULL;
581 //returns true if char is allowed
582 int char_allowed(char c)
584 char *p = Newmenu_allowed_chars;
592 if (c>=p[0] && c<=p[1])
601 void strip_end_whitespace( char * text )
604 l = (int)strlen( text );
605 for (i=l-1; i>=0; i-- ) {
606 if ( isspace(text[i]) )
613 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
615 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
617 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
619 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
623 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
625 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
629 int newmenu_do1( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem )
631 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
635 int newmenu_do2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem, char * filename )
637 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
639 int newmenu_do3( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem, char * filename, int width, int height )
641 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
644 int newmenu_do_fixedfont( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem, char * filename, int width, int height){
645 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
646 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
647 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
650 //returns 1 if a control device button has been pressed
651 int check_button_press()
653 #ifndef NEWMENU_MOUSE // don't allow mouse to continue from menu
656 if (Config_control_mouse.intval)
658 if (mouse_button_down_count(i)>0) return 1;
665 // use menu with joystick
666 int newmenu_inkey(void)
672 if ( !Config_control_joystick.intval || key < KEY_JB1 || key > 255 ) // not using joystick, not a joystick button, or modifier pressed
675 if ( strlen(key_text[key]) > 5 && key_text[key][0] == 'J' && key_text[key][2] == 'H' ) // joystick hat
676 switch (key_text[key][4]) {
677 case 'U': key = KEY_UP; break;
678 case 'R': key = KEY_RIGHT; break;
679 case 'D': key = KEY_DOWN; break;
680 case 'L': key = KEY_LEFT; break;
682 else if ( strlen(key_text[key]) > 3 && key_text[key][0] == 'J' && key_text[key][2] == 'B' ) // joystick button
683 switch (key_text[key][3]) {
684 case '1': key = KEY_SPACEBAR; break;
685 case '2': key = KEY_ENTER; break;
686 case '3': key = KEY_ESC; break;
692 extern int network_request_player_names(int);
693 extern int RestoringMenu;
696 ubyte Hack_DblClick_MenuMode=0;
700 extern ubyte joydefs_calibrating;
702 # define joydefs_calibrating 0
705 #define CLOSE_X (MenuHires?15:7)
706 #define CLOSE_Y (MenuHires?15:7)
707 #define CLOSE_SIZE (MenuHires?10:5)
709 void draw_close_box(int x,int y)
711 gr_setcolor( BM_XRGB(0, 0, 0) );
712 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
713 gr_setcolor( BM_XRGB(21, 21, 21) );
714 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));
717 extern int Num_bitmap_files;
719 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 )
721 int old_keyd_repeat, done;
722 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
723 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
724 grs_font * save_font;
725 int string_width, string_height = 0, average_width;
728 int all_text=0; //set true if all text items
729 int sound_stopped=0,time_stopped=0;
730 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
733 int MaxOnMenu=MAXDISPLAYABLEITEMS;
734 grs_canvas *save_canvas;
736 int mouse_state, omouse_state, dblclick_flag=0;
737 int mx=0, my=0, x1 = 0, x2, y1, y2;
741 EventRecord event; // looking for disk inserted events for CD mounts
744 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
745 newmenu_hide_cursor();
752 MaxDisplayable=nitems;
754 //set_screen_mode(SCREEN_MENU);
757 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
758 digi_pause_digi_sounds();
762 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
772 save_canvas = grd_curcanv;
774 gr_set_current_canvas(NULL);
776 save_font = grd_curcanv->cv_font;
781 grd_curcanv->cv_font = TITLE_FONT;
782 gr_get_string_size(title,&string_width,&string_height,&average_width );
787 grd_curcanv->cv_font = SUBTITLE_FONT;
788 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
789 if (string_width > tw )
794 th += LHY(8); //put some space between titles & body
797 grd_curcanv->cv_font = SMALL_FONT;
799 grd_curcanv->cv_font = NORMAL_FONT;
803 nmenus = nothers = 0;
805 // Find menu height & width (store in w,h)
806 for (i=0; i<nitems; i++ ) {
809 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
810 item[i].right_offset = 0;
813 string_height+=LHY(3);
815 item[i].saved_text[0] = '\0';
817 if ( item[i].type == NM_TYPE_SLIDER ) {
820 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
821 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
822 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
824 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
825 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
826 string_width += w1 + aw;
829 if ( item[i].type == NM_TYPE_MENU ) {
833 if ( item[i].type == NM_TYPE_CHECK ) {
836 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
837 item[i].right_offset = w1;
838 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
839 if (w1 > item[i].right_offset)
840 item[i].right_offset = w1;
843 if (item[i].type == NM_TYPE_RADIO ) {
846 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
847 item[i].right_offset = w1;
848 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
849 if (w1 > item[i].right_offset)
850 item[i].right_offset = w1;
853 if (item[i].type==NM_TYPE_NUMBER ) {
857 sprintf( test_text, "%d", item[i].max_value );
858 gr_get_string_size( test_text, &w1, &h1, &aw1 );
859 item[i].right_offset = w1;
860 sprintf( test_text, "%d", item[i].min_value );
861 gr_get_string_size( test_text, &w1, &h1, &aw1 );
862 if ( w1 > item[i].right_offset)
863 item[i].right_offset = w1;
866 if ( item[i].type == NM_TYPE_INPUT ) {
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);
871 if ( string_width > MAX_TEXT_WIDTH )
872 string_width = MAX_TEXT_WIDTH;
876 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
877 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
878 strcpy(item[i].saved_text, item[i].text );
880 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
885 item[i].w = string_width;
886 item[i].h = string_height;
888 if ( string_width > w )
889 w = string_width; // Save maximum width
890 if ( average_width > aw )
892 h += string_height+1; // Find the height of all strings
895 // Big hack for allowing the netgame options menu to spill over
897 MaxOnMenu=MAXDISPLAYABLEITEMS;
898 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
901 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
904 h=(MaxOnMenu*(string_height+1)+LHY(8));
905 MaxDisplayable=MaxOnMenu;
906 mprintf ((0,"Hey, this is a scroll box!\n"));
919 for (i=0; i<nitems; i++ ) {
921 if (item[i].right_offset > right_offset )
922 right_offset = item[i].right_offset;
924 if (right_offset > 0 )
927 //gr_get_string_size("",&string_width,&string_height,&average_width );
934 twidth = ( tw - w )/2;
939 { right_offset=0; twidth=0;}
941 mprintf(( 0, "Right offset = %d\n", right_offset ));
944 // Find min point of menu border
945 // x = (grd_curscreen->sc_w-w)/2;
946 // y = (grd_curscreen->sc_h-h)/2;
948 w += MenuHires?60:30;
949 h += MenuHires?60:30;
951 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
952 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
954 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
955 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
960 if ( filename != NULL ) {
961 nm_draw_background1( filename );
962 gr_palette_load(gr_palette);
965 // Save the background of the display
966 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h );
967 gr_set_current_canvas(bg.menu_canvas);
969 if ( filename == NULL ) {
970 // Save the background under the menu...
976 bg.saved = gr_create_bitmap( w, h );
977 Assert( bg.saved != NULL );
979 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
981 gr_set_current_canvas( NULL );
983 nm_draw_background(x,y,x+w-1,y+h-1);
985 gr_set_current_canvas( bg.menu_canvas );
987 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
991 bg.background = gr_create_bitmap( w, h );
992 Assert( bg.background != NULL );
994 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
997 // ty = 15 + (yborder/4);
999 ty = MenuHires?30:15;
1002 grd_curcanv->cv_font = TITLE_FONT;
1003 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1004 gr_get_string_size(title,&string_width,&string_height,&average_width );
1007 gr_printf( 0x8000, ty, title );
1012 grd_curcanv->cv_font = SUBTITLE_FONT;
1013 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1014 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1017 gr_printf( 0x8000, ty, subtitle );
1022 grd_curcanv->cv_font = SMALL_FONT;
1024 grd_curcanv->cv_font = NORMAL_FONT;
1026 // Update all item's x & y values.
1027 for (i=0; i<nitems; i++ ) {
1028 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1029 item[i].y += (MenuHires?30:15);
1030 if ( item[i].type==NM_TYPE_RADIO ) {
1031 fm = -1; // find first marked one
1032 for ( j=0; j<nitems; j++ ) {
1033 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1034 if (fm==-1 && item[j].value)
1046 old_keyd_repeat = keyd_repeat;
1052 if (citem < 0 ) citem = 0;
1053 if (citem > nitems-1 ) citem = nitems-1;
1056 #ifdef NEWMENU_MOUSE
1060 while ( item[choice].type==NM_TYPE_TEXT ) {
1062 if (choice >= nitems ) {
1065 if (choice == citem ) {
1076 // Clear mouse, joystick to clear button presses.
1077 game_flush_inputs();
1079 #ifdef NEWMENU_MOUSE
1080 mouse_state = omouse_state = 0;
1081 if (filename == NULL && !MenuReordering) {
1082 //draw_close_box(0,0);
1086 if (!MenuReordering && !joydefs_calibrating)
1088 newmenu_show_cursor();
1090 SetCursor(LoadCursor(NULL,IDC_ARROW));
1095 mprintf ((0,"Set to true!\n"));
1098 #ifdef NEWMENU_MOUSE
1099 if (!joydefs_calibrating)
1100 newmenu_show_cursor(); // possibly hidden
1101 omouse_state = mouse_state;
1102 if (!MenuReordering)
1103 mouse_state = mouse_button_state(0);
1104 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1107 //see if redbook song needs to be restarted
1108 songs_check_redbook_repeat();
1112 k = newmenu_inkey();
1115 (*subfunction)(nitems,item,&k,choice);
1118 if (!time_stopped) {
1119 // Save current menu box
1120 if (multi_menu_poll() == -1)
1126 dont_restore = (k == -3); //-3 means don't restore
1131 if (check_button_press())
1134 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1137 old_choice = choice;
1143 if (SurfingNet && !already_showing_info)
1145 show_extra_netgame_info(choice-2);
1147 if (SurfingNet && already_showing_info)
1154 if (SurfingNet && !already_showing_info)
1156 network_request_player_names(choice-2);
1158 if (SurfingNet && already_showing_info)
1173 case KEY_TAB + KEY_SHIFTED:
1176 if (all_text) break;
1183 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1185 if (choice<TopChoice)
1186 { choice=TopChoice; break; }
1188 if (choice<ScrollOffset)
1190 for (i=0;i<nitems;i++)
1193 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1198 if (choice >= nitems ) choice=0;
1199 if (choice < 0 ) choice=nitems-1;
1201 } while ( item[choice].type==NM_TYPE_TEXT );
1202 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1203 item[choice].value = -1;
1204 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1205 item[old_choice].group=0;
1206 strcpy(item[old_choice].text, item[old_choice].saved_text );
1207 item[old_choice].value = -1;
1210 item[old_choice].redraw = 1;
1211 item[choice].redraw=1;
1216 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1217 if (all_text) break;
1224 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1227 { choice--; break; }
1229 if (choice>=MaxOnMenu+ScrollOffset)
1231 for (i=0;i<nitems;i++)
1234 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1239 if (choice < 0 ) choice=nitems-1;
1240 if (choice >= nitems ) choice=0;
1243 } while ( item[choice].type==NM_TYPE_TEXT );
1245 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1246 item[choice].value = -1;
1247 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1248 item[old_choice].group=0;
1249 strcpy(item[old_choice].text, item[old_choice].saved_text );
1250 item[old_choice].value = -1;
1253 item[old_choice].redraw=1;
1254 item[choice].redraw=1;
1257 if ( choice > -1 ) {
1258 switch( item[choice].type ) {
1261 case NM_TYPE_INPUT_MENU:
1264 if ( item[choice].value )
1265 item[choice].value = 0;
1267 item[choice].value = 1;
1268 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1271 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1273 mprintf ((0,"Special redraw!\n"));
1278 item[choice].redraw=1;
1281 for (i=0; i<nitems; i++ ) {
1282 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1287 item[choice].value = 1;
1288 item[choice].redraw = 1;
1294 case KEY_SHIFTED+KEY_UP:
1295 if (MenuReordering && choice!=TopChoice)
1297 Temp=item[choice].text;
1298 TempVal=item[choice].value;
1299 item[choice].text=item[choice-1].text;
1300 item[choice].value=item[choice-1].value;
1301 item[choice-1].text=Temp;
1302 item[choice-1].value=TempVal;
1303 item[choice].redraw=1;
1304 item[choice-1].redraw=1;
1308 case KEY_SHIFTED+KEY_DOWN:
1309 if (MenuReordering && choice!=(nitems-1))
1311 Temp=item[choice].text;
1312 TempVal=item[choice].value;
1313 item[choice].text=item[choice+1].text;
1314 item[choice].value=item[choice+1].value;
1315 item[choice+1].text=Temp;
1316 item[choice+1].value=TempVal;
1317 item[choice].redraw=1;
1318 item[choice+1].redraw=1;
1325 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1326 item[choice].group = 1;
1327 item[choice].redraw = 1;
1328 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1329 item[choice].text[0] = 0;
1330 item[choice].value = -1;
1332 strip_end_whitespace(item[choice].text);
1339 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1340 item[choice].group=0;
1341 strcpy(item[choice].text, item[choice].saved_text );
1342 item[choice].redraw=1;
1343 item[choice].value = -1;
1350 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
1351 case KEY_PRINT_SCREEN:
1352 MAC(newmenu_hide_cursor());
1353 save_screen_shot(0);
1354 for (i=0;i<nitems;i++)
1357 MAC(newmenu_show_cursor());
1363 case KEY_COMMAND+KEY_RIGHT:
1364 songs_goto_next_song();
1366 case KEY_COMMAND+KEY_LEFT:
1367 songs_goto_prev_song();
1369 case KEY_COMMAND+KEY_UP:
1370 songs_play_level_song(1);
1372 case KEY_COMMAND+KEY_DOWN:
1373 songs_stop_redbook();
1376 case KEY_COMMAND+KEY_M:
1378 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1381 key_close(); // no processing of keys with keyboard handler.. jeez
1383 newmenu_hide_cursor();
1384 show_boxed_message ("Mounting CD\nESC to quit");
1385 RBAMountDisk(); // OS has totaly control of the CD.
1386 if (Function_mode == FMODE_MENU)
1387 songs_play_song(SONG_TITLE,1);
1388 else if (Function_mode == FMODE_GAME)
1389 songs_play_level_song( Current_level_num );
1390 clear_boxed_message();
1391 newmenu_show_cursor();
1398 case KEY_COMMAND+KEY_E:
1399 songs_stop_redbook();
1401 k = -1; // force key not to register
1405 case KEY_COMMAND+KEY_Q: {
1406 if ( !(Game_mode & GM_MULTI) )
1408 if (!joydefs_calibrating)
1409 newmenu_show_cursor();
1410 k = -1; // force key not to register
1416 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1421 case KEY_SHIFTED + KEY_B:
1424 grs_canvas *canv_save = grd_curcanv;
1425 grs_canvas *temp_canv;
1428 ubyte pal_save[768];
1430 memcpy(pal_save, gr_palette, 768);
1431 gr_use_palette_table(DEFAULT_LEVEL_PALETTE);
1432 memcpy(bm_pal, gr_palette, 768);
1433 gr_copy_palette(gr_palette, pal_save, 768);
1435 if (k & KEY_SHIFTED)
1441 n = Num_bitmap_files - 1;
1442 n %= Num_bitmap_files;
1443 bm = &GameBitmaps[n];
1444 PIGGY_PAGE_IN( *(bitmap_index *)&n );
1445 con_printf(CON_DEBUG, "showing bitmap %d of %d: %s\n", n, Num_bitmap_files, piggy_game_bitmap_name(bm));
1447 temp_canv = gr_create_canvas(bm->bm_w, bm->bm_h);
1448 gr_set_current_canvas(temp_canv);
1449 gr_bitmap(0, 0, bm);
1450 gr_set_current_canvas(&grd_curscreen->sc_canvas);
1451 gr_remap_bitmap_good(&temp_canv->cv_bitmap, bm_pal, -1, -1);
1452 gr_bitmap(0, 0, &temp_canv->cv_bitmap);
1453 gr_free_canvas(temp_canv);
1454 gr_set_current_canvas(canv_save);
1459 case KEY_SHIFTED + KEY_P:
1461 char *palettes[] = {
1471 static unsigned int palnum = 0;
1473 if (k & KEY_SHIFTED)
1478 palnum %= sizeof(palettes)/sizeof(char *);
1479 load_palette(palettes[palnum], 0, 0);
1487 #ifdef NEWMENU_MOUSE // for mouse selection of menu's etc.
1488 if ( !done && mouse_state && !omouse_state && !all_text ) {
1489 mouse_get_pos(&mx, &my);
1490 for (i=0; i<nitems; i++ ) {
1491 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1492 x2 = x1 + item[i].w;
1493 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1494 y2 = y1 + item[i].h;
1495 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1496 if (i+ScrollOffset != choice) {
1497 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1500 choice = i + ScrollOffset;
1502 switch( item[choice].type ) {
1504 if ( item[choice].value )
1505 item[choice].value = 0;
1507 item[choice].value = 1;
1508 item[choice].redraw=1;
1515 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1517 mprintf ((0,"Special redraw!\n"));
1524 for (i=0; i<nitems; i++ ) {
1525 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1530 item[choice].value = 1;
1531 item[choice].redraw = 1;
1534 item[old_choice].redraw=1;
1540 if (mouse_state && all_text)
1543 if ( !done && mouse_state && !all_text ) {
1544 mouse_get_pos(&mx, &my);
1546 // check possible scrollbar stuff first
1548 int arrow_width, arrow_height, aw;
1550 if (ScrollOffset != 0) {
1551 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1552 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1553 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1554 x1 = x1 - arrow_width;
1555 y2 = y1 + arrow_height;
1556 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1559 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1561 if (choice<ScrollOffset)
1563 for (i=0;i<nitems;i++)
1566 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1570 if (ScrollOffset+MaxDisplayable<nitems) {
1571 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1572 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1573 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1574 x1 = x1 - arrow_width;
1575 y2 = y1 + arrow_height;
1576 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1579 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1581 if (choice>=MaxOnMenu+ScrollOffset)
1583 for (i=0;i<nitems;i++)
1586 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1592 for (i=0; i<nitems; i++ ) {
1593 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1594 x2 = x1 + item[i].w;
1595 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1596 y2 = y1 + item[i].h;
1597 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1598 if (i+ScrollOffset != choice) {
1599 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1602 choice = i + ScrollOffset;
1604 if ( item[choice].type == NM_TYPE_SLIDER ) {
1605 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1 = NULL;
1606 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1608 strcpy(slider_text, item[choice].saved_text);
1609 p = strchr(slider_text, '\t');
1615 gr_get_string_size(s1, &slider_width, &height, &aw);
1616 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1617 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1618 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1620 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1621 x2 = x1 + slider_width + sright_width;
1622 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1623 item[choice].value = item[choice].min_value;
1624 item[choice].redraw = 2;
1625 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1626 item[choice].value = item[choice].max_value;
1627 item[choice].redraw = 2;
1628 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1629 int num_values, value_width, new_value;
1631 num_values = item[choice].max_value - item[choice].min_value + 1;
1632 value_width = (slider_width - sleft_width - sright_width) / num_values;
1633 new_value = (mx - x1 - sleft_width) / value_width;
1634 if ( item[choice].value != new_value ) {
1635 item[choice].value = new_value;
1636 item[choice].redraw = 2;
1642 if (choice == old_choice)
1644 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1645 item[choice].value = -1;
1646 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1647 item[old_choice].group=0;
1648 strcpy(item[old_choice].text, item[old_choice].saved_text );
1649 item[old_choice].value = -1;
1652 item[old_choice].redraw = 1;
1653 item[choice].redraw=1;
1659 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1660 mouse_get_pos(&mx, &my);
1661 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1662 x2 = x1 + item[choice].w;
1663 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1664 y2 = y1 + item[choice].h;
1665 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1666 if (Hack_DblClick_MenuMode) {
1667 if (dblclick_flag) done = 1;
1668 else dblclick_flag = 1;
1674 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1675 item[choice].group = 1;
1676 item[choice].redraw = 1;
1677 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1678 item[choice].text[0] = 0;
1679 item[choice].value = -1;
1681 strip_end_whitespace(item[choice].text);
1685 if ( !done && !mouse_state && omouse_state && close_box ) {
1686 mouse_get_pos(&mx, &my);
1687 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1688 x2 = x1 + CLOSE_SIZE;
1689 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1690 y2 = y1 + CLOSE_SIZE;
1691 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1697 // HACK! Don't redraw loadgame preview
1698 if (RestoringMenu) item[0].redraw = 0;
1699 #endif // NEWMENU_MOUSE
1701 if ( choice > -1 ) {
1704 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1705 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1706 if (item[choice].value == -1)
1707 item[choice].value = (int)strlen(item[choice].text);
1708 if (item[choice].value > 0)
1709 item[choice].value--;
1710 item[choice].text[item[choice].value] = 0;
1711 item[choice].redraw = 1;
1713 ascii = key_to_ascii(k);
1714 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1718 if (item[choice].value==-1) {
1719 item[choice].value = 0;
1722 allowed = char_allowed(ascii);
1724 if (!allowed && ascii==' ' && char_allowed('_')) {
1730 item[choice].text[item[choice].value++] = ascii;
1731 item[choice].text[item[choice].value] = 0;
1732 item[choice].redraw=1;
1736 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1737 ascii = key_to_ascii(k);
1739 int choice1 = choice;
1740 ascii = toupper(ascii);
1744 if (choice1 >= nitems ) choice1=0;
1745 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1746 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1747 (item[choice1].type==NM_TYPE_CHECK) ||
1748 (item[choice1].type==NM_TYPE_RADIO) ||
1749 (item[choice1].type==NM_TYPE_NUMBER) ||
1750 (item[choice1].type==NM_TYPE_SLIDER) )
1751 && (ascii==toupper(ch)) ) {
1755 item[old_choice].redraw=1;
1756 item[choice].redraw=1;
1758 } while (choice1 != choice );
1762 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1763 int ov=item[choice].value;
1768 case KEY_MINUS+KEY_SHIFTED:
1770 item[choice].value -= 1;
1775 case KEY_EQUAL+KEY_SHIFTED:
1777 item[choice].value++;
1782 item[choice].value += 10;
1787 item[choice].value -= 10;
1790 if (ov!=item[choice].value)
1791 item[choice].redraw=1;
1796 gr_set_current_canvas(bg.menu_canvas);
1798 // Redraw everything...
1799 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1801 if (item[i].redraw) // warning! ugly hack below
1803 item[i].y-=((string_height+1)*ScrollOffset);
1804 newmenu_hide_cursor();
1805 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1807 #ifdef NEWMENU_MOUSE
1808 if (!MenuReordering && !joydefs_calibrating)
1809 newmenu_show_cursor();
1811 item[i].y+=((string_height+1)*ScrollOffset);
1813 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1814 update_cursor( &item[i]);
1820 //grd_curcanv->cv_font = NORMAL_FONT;
1822 if (LastScrollCheck!=ScrollOffset)
1824 LastScrollCheck=ScrollOffset;
1825 grd_curcanv->cv_font = SELECTED_FONT;
1827 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1828 sx=item[ScrollOffset].x-(MenuHires?24:12);
1831 if (ScrollOffset!=0)
1832 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1834 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1836 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1837 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1839 if (ScrollOffset+MaxDisplayable<nitems)
1840 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1842 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1848 if ( !dont_restore && gr_palette_faded_out ) {
1849 gr_palette_fade_in( gr_palette, 32, 0 );
1853 newmenu_hide_cursor();
1855 // Restore everything...
1857 gr_set_current_canvas(bg.menu_canvas);
1859 if ( filename == NULL ) {
1860 // Save the background under the menu...
1861 gr_bitmap(0, 0, bg.saved);
1862 gr_free_bitmap(bg.saved);
1863 d_free( bg.background );
1865 if (!dont_restore) //info passed back from subfunction
1866 gr_bitmap(0, 0, bg.background);
1867 gr_free_bitmap(bg.background);
1870 gr_free_sub_canvas( bg.menu_canvas );
1872 gr_set_current_canvas(save_canvas);
1873 grd_curcanv->cv_font = save_font;
1874 keyd_repeat = old_keyd_repeat;
1876 game_flush_inputs();
1887 if ( sound_stopped )
1888 digi_resume_digi_sounds();
1895 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1901 char nm_text[MESSAGEBOX_TEXT_SIZE];
1902 newmenu_item nm_message_items[5];
1904 va_start(args, nchoices );
1906 Assert( nchoices <= 5 );
1908 for (i=0; i<nchoices; i++ ) {
1909 s = va_arg( args, char * );
1910 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1912 format = va_arg( args, char * );
1913 strcpy( nm_text, "" );
1914 vsprintf(nm_text,format,args);
1917 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1919 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1922 int nm_messagebox( char *title, int nchoices, ... )
1928 char nm_text[MESSAGEBOX_TEXT_SIZE];
1929 newmenu_item nm_message_items[5];
1931 va_start(args, nchoices );
1933 Assert( nchoices <= 5 );
1935 for (i=0; i<nchoices; i++ ) {
1936 s = va_arg( args, char * );
1937 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1939 format = va_arg( args, char * );
1940 strcpy( nm_text, "" );
1941 vsprintf(nm_text,format,args);
1944 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1946 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1952 void newmenu_file_sort( int n, char *list )
1959 for (i=incr; i<n; i++ ) {
1962 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1963 memcpy( t, &list[j*14], FILENAME_LEN );
1964 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1965 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1976 void delete_player_saved_games(char * name)
1981 for (i=0;i<10; i++) {
1982 sprintf( filename, PLAYER_DIR "%s.sg%d", name, i );
1983 PHYSFS_delete(filename);
1987 #define MAX_FILES 300
1989 //FIXME: should maybe put globbing ability back?
1990 int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
1996 int NumFiles=0, key,done, citem, ocitem;
1997 char * filenames = NULL;
1998 int NumFiles_displayed = 8;
1999 int first_item = -1, ofirst_item;
2000 int old_keyd_repeat = keyd_repeat;
2003 int demos_deleted=0;
2004 int initialized = 0;
2006 int w_x, w_y, w_w, w_h, title_height;
2007 int box_x, box_y, box_w, box_h;
2008 bkg bg; // background under listbox
2009 #ifdef NEWMENU_MOUSE
2010 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2011 int mouse2_state, omouse2_state;
2012 int dblclick_flag=0;
2015 int show_up_arrow=0, show_down_arrow=0;
2019 w_x=w_y=w_w=w_h=title_height=0;
2020 box_x=box_y=box_w=box_h=0;
2022 filenames = d_malloc( MAX_FILES * 14 );
2023 if (filenames==NULL) return 0;
2028 if (!stricmp(type, "plr"))
2030 else if (!stricmp(type, "dem"))
2037 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2039 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2044 find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
2045 for (f = find; *f != NULL; f++)
2049 ext = strrchr(*f, '.');
2050 if (!ext || strnicmp(ext, ".plr", 4))
2053 if (NumFiles < MAX_FILES)
2055 strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
2060 p = strchr(&filenames[NumFiles*14], '.');
2070 PHYSFS_freeList(find);
2072 if ( (NumFiles < 1) && demos_deleted ) {
2076 if ( (NumFiles < 1) && demo_mode ) {
2077 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2083 if ( (NumFiles < 2) && player_mode ) {
2085 goto ExitFileMenuEarly;
2092 nm_messagebox(NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND);
2099 // set_screen_mode(SCREEN_MENU);
2102 gr_set_current_canvas(NULL);
2104 grd_curcanv->cv_font = SUBTITLE_FONT;
2109 for (i=0; i<NumFiles; i++ ) {
2111 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2117 gr_get_string_size( title, &w, &h, &aw );
2120 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2124 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2126 w_w += (grd_curfont->ft_w * 4);
2127 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2129 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2130 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2132 w_x = (grd_curcanv->cv_w-w_w)/2;
2133 w_y = (grd_curcanv->cv_h-w_h)/2;
2135 if ( w_x < 0 ) w_x = 0;
2136 if ( w_y < 0 ) w_y = 0;
2138 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2139 box_y = w_y + title_height;
2141 // save the screen behind the menu.
2145 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2146 bg.background = &VR_offscreen_buffer->cv_bitmap;
2148 bg.background = gr_create_bitmap( w_w, w_h );
2150 Assert( bg.background != NULL );
2153 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2156 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2159 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2161 gr_string( 0x8000, w_y+10, title );
2166 if ( !player_mode ) {
2167 newmenu_file_sort( NumFiles, filenames );
2169 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2170 newmenu_file_sort( NumFiles, filenames );
2172 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2174 for ( i=0; i<NumFiles; i++ ) {
2175 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2176 #ifdef NEWMENU_MOUSE
2184 #ifdef NEWMENU_MOUSE
2185 mouse_state = omouse_state = 0;
2186 mouse2_state = omouse2_state = 0;
2187 //draw_close_box(w_x,w_y);
2188 newmenu_show_cursor();
2193 ofirst_item = first_item;
2196 #ifdef NEWMENU_MOUSE
2197 omouse_state = mouse_state;
2198 omouse2_state = mouse2_state;
2199 mouse_state = mouse_button_state(0);
2200 mouse2_state = mouse_button_state(1);
2203 //see if redbook song needs to be restarted
2204 songs_check_redbook_repeat();
2206 key = newmenu_inkey();
2209 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2210 case KEY_PRINT_SCREEN:
2211 MAC(newmenu_hide_cursor());
2212 save_screen_shot(0);
2214 MAC(newmenu_show_cursor());
2218 case KEY_CTRLED+KEY_D:
2219 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2223 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2225 newmenu_hide_cursor();
2227 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2229 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2230 newmenu_show_cursor();
2234 char name[PATH_MAX];
2236 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2240 strcpy(name, demo_mode?DEMO_DIR:"");
2241 strcat(name,&filenames[citem*14]);
2248 if ( !strncmp(name, ".\\", 2) )
2249 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2250 name[i] = name[i+1];
2251 while ( (p = strchr(name, '\\')) )
2256 ret = !PHYSFS_delete(name);
2260 if ((!ret) && player_mode) {
2261 delete_player_saved_games( &filenames[citem*14] );
2266 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2268 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2269 } else if (demo_mode)
2294 citem += NumFiles_displayed;
2298 citem -= NumFiles_displayed;
2301 if (allow_abort_flag) {
2311 case KEY_COMMAND+KEY_Q: {
2312 if ( !(Game_mode & GM_MULTI) )
2317 newmenu_show_cursor();
2325 int ascii = key_to_ascii(key);
2326 if ( ascii < 255 ) {
2329 if (cc1 < 0 ) cc1 = 0;
2330 if (cc1 >= NumFiles ) cc1 = 0;
2332 if ( cc < 0 ) cc = 0;
2333 if ( cc >= NumFiles ) cc = 0;
2334 if ( citem == cc ) break;
2336 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2351 if (citem>=NumFiles)
2354 if (citem< first_item)
2357 if (citem>=( first_item+NumFiles_displayed))
2359 first_item = citem-NumFiles_displayed+1;
2363 if (NumFiles>first_item+NumFiles_displayed)
2374 if (NumFiles <= NumFiles_displayed )
2377 if (first_item>NumFiles-NumFiles_displayed)
2379 first_item = NumFiles-NumFiles_displayed;
2382 if (first_item < 0 ) first_item = 0;
2384 #ifdef NEWMENU_MOUSE
2385 if (mouse_state || mouse2_state) {
2388 mouse_get_pos(&mx, &my);
2389 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2390 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2392 x2 = box_x + box_w - 1;
2393 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2395 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2396 if (i == citem && !mouse2_state) {
2406 if (!mouse_state && omouse_state) {
2409 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2410 mouse_get_pos(&mx, &my);
2412 x2 = box_x + box_w - 1;
2413 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2415 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2416 if (dblclick_flag) done = 1;
2417 else dblclick_flag = 1;
2421 if ( !mouse_state && omouse_state ) {
2422 mouse_get_pos(&mx, &my);
2423 x1 = w_x + CLOSE_X + 2;
2424 x2 = x1 + CLOSE_SIZE - 2;
2425 y1 = w_y + CLOSE_Y + 2;
2426 y2 = y1 + CLOSE_SIZE - 2;
2427 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2436 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2438 y1 = box_y+box_h-LHY(7);
2440 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2447 gr_setcolor( BM_XRGB(2,2,2));
2448 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2449 gr_setcolor( BM_XRGB( 0,0,0) );
2451 if (ofirst_item != first_item) {
2452 newmenu_hide_cursor();
2453 gr_setcolor( BM_XRGB( 0,0,0) );
2454 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2456 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2458 if ( i >= NumFiles ) {
2460 gr_setcolor( BM_XRGB(5,5,5));
2461 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2462 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2464 gr_setcolor( BM_XRGB(2,2,2));
2465 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2467 gr_setcolor( BM_XRGB(0,0,0));
2468 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2472 grd_curcanv->cv_font = SELECTED_FONT;
2474 grd_curcanv->cv_font = NORMAL_FONT;
2475 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2477 gr_setcolor( BM_XRGB(5,5,5));
2478 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2479 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2481 gr_setcolor( BM_XRGB(2,2,2));
2482 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2483 gr_setcolor( BM_XRGB(0,0,0));
2485 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2486 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2489 newmenu_show_cursor();
2490 } else if ( citem != ocitem ) {
2493 newmenu_hide_cursor();
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_w - 1, y + h + 1 );
2503 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2506 if ( (i>=0) && (i<NumFiles) ) {
2507 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2509 grd_curcanv->cv_font = SELECTED_FONT;
2511 grd_curcanv->cv_font = NORMAL_FONT;
2512 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2513 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2514 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2516 newmenu_show_cursor();
2520 grd_curcanv->cv_font = NORMAL_FONT;
2522 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2526 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2530 if (show_down_arrow)
2531 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2535 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2543 MAC(newmenu_hide_cursor());
2545 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2552 keyd_repeat = old_keyd_repeat;
2554 if ( initialized ) {
2555 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2556 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2557 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2558 gr_free_bitmap(bg.background);
2560 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2572 // Example listbox callback function...
2573 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2577 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2578 // if ( *nitems > 1 ) {
2579 // PHYSFS_delete(items[*citem]); // Delete the file
2580 // for (i=*citem; i<*nitems-1; i++ ) {
2581 // items[i] = items[i+1];
2583 // *nitems = *nitems - 1;
2584 // d_free( items[*nitems] );
2585 // items[*nitems] = NULL;
2586 // return 1; // redraw;
2593 #define LB_ITEMS_ON_SCREEN 8
2595 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2597 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2600 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 ) )
2603 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2604 int old_keyd_repeat = keyd_repeat;
2605 int width, height, wx, wy, title_height, border_size;
2606 int total_width,total_height;
2608 #ifdef NEWMENU_MOUSE
2609 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2610 int close_x,close_y;
2612 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2618 // set_screen_mode(SCREEN_MENU);
2621 gr_set_current_canvas(NULL);
2623 grd_curcanv->cv_font = SUBTITLE_FONT;
2626 for (i=0; i<nitems; i++ ) {
2628 gr_get_string_size( items[i], &w, &h, &aw );
2632 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2636 gr_get_string_size( title, &w, &h, &aw );
2639 title_height = h + 5;
2642 border_size = grd_curfont->ft_w;
2643 WIN (border_size=grd_curfont->ft_w*2);
2645 width += (grd_curfont->ft_w);
2646 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2647 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2649 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2650 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2651 if ( wy < title_height )
2654 total_width = width+2*border_size;
2655 total_height = height+2*border_size+title_height;
2659 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2660 bg.background = &VR_offscreen_buffer->cv_bitmap;
2662 //bg.background = gr_create_bitmap( width, (height + title_height) );
2663 bg.background = gr_create_bitmap(total_width,total_height);
2664 Assert( bg.background != NULL );
2666 //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 );
2667 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2670 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2673 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2675 gr_string( 0x8000, wy - title_height, title );
2678 citem = default_item;
2679 if ( citem < 0 ) citem = 0;
2680 if ( citem >= nitems ) citem = 0;
2684 #ifdef NEWMENU_MOUSE
2685 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2686 close_x = wx-border_size;
2687 close_y = wy-title_height-border_size;
2688 //draw_close_box(close_x,close_y);
2689 newmenu_show_cursor();
2694 ofirst_item = first_item;
2695 #ifdef NEWMENU_MOUSE
2696 omouse_state = mouse_state;
2697 mouse_state = mouse_button_state(0);
2699 //see if redbook song needs to be restarted
2700 songs_check_redbook_repeat();
2702 key = newmenu_inkey();
2704 if ( listbox_callback )
2705 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2719 else if (simukey==1)
2725 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2726 case KEY_PRINT_SCREEN:
2727 MAC(newmenu_hide_cursor());
2728 save_screen_shot(0);
2730 MAC(newmenu_show_cursor());
2751 citem += LB_ITEMS_ON_SCREEN;
2755 citem -= LB_ITEMS_ON_SCREEN;
2758 if (allow_abort_flag) {
2768 case KEY_COMMAND+KEY_Q: {
2769 if ( !(Game_mode & GM_MULTI) )
2771 newmenu_show_cursor();
2778 int ascii = key_to_ascii(key);
2779 if ( ascii < 255 ) {
2782 if (cc1 < 0 ) cc1 = 0;
2783 if (cc1 >= nitems ) cc1 = 0;
2785 if ( cc < 0 ) cc = 0;
2786 if ( cc >= nitems ) cc = 0;
2787 if ( citem == cc ) break;
2789 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2806 if (citem< first_item)
2809 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2810 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2812 if (nitems <= LB_ITEMS_ON_SCREEN )
2815 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
2816 first_item = nitems-LB_ITEMS_ON_SCREEN;
2817 if (first_item < 0 ) first_item = 0;
2820 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
2831 #ifdef NEWMENU_MOUSE
2835 mouse_get_pos(&mx, &my);
2836 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2839 gr_get_string_size(items[i], &w, &h, &aw );
2842 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2844 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2856 //no double-click stuff for listbox
2857 //@@if (!mouse_state && omouse_state) {
2860 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
2861 //@@ mouse_get_pos(&mx, &my);
2863 //@@ x2 = wx + width;
2864 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
2866 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2867 //@@ if (dblclick_flag) done = 1;
2871 //check for close box clicked
2872 if ( !mouse_state && omouse_state ) {
2873 mouse_get_pos(&mx, &my);
2874 x1 = close_x + CLOSE_X + 2;
2875 x2 = x1 + CLOSE_SIZE - 2;
2876 y1 = close_y + CLOSE_Y + 2;
2877 y2 = y1 + CLOSE_SIZE - 2;
2878 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2888 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
2890 y1 = total_height-LHY(7);
2892 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
2900 if ( (ofirst_item != first_item) || redraw) {
2901 newmenu_hide_cursor();
2903 gr_setcolor( BM_XRGB( 0,0,0) );
2904 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2906 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2907 if ( i >= nitems ) {
2908 gr_setcolor( BM_XRGB(0,0,0));
2909 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
2912 grd_curcanv->cv_font = SELECTED_FONT;
2914 grd_curcanv->cv_font = NORMAL_FONT;
2915 gr_get_string_size(items[i], &w, &h, &aw );
2916 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2917 gr_string( wx+5, y, items[i] );
2922 // If Win95 port, draw up/down arrows on left side of menu
2924 grd_curcanv->cv_font = NORMAL_FONT;
2926 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
2930 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
2934 if (show_down_arrow)
2935 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
2939 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
2946 newmenu_show_cursor();
2948 } else if ( citem != ocitem ) {
2951 newmenu_hide_cursor();
2954 if ( (i>=0) && (i<nitems) ) {
2955 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2957 grd_curcanv->cv_font = SELECTED_FONT;
2959 grd_curcanv->cv_font = NORMAL_FONT;
2960 gr_get_string_size(items[i], &w, &h, &aw );
2961 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2962 gr_string( wx+5, y, items[i] );
2966 if ( (i>=0) && (i<nitems) ) {
2967 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2969 grd_curcanv->cv_font = SELECTED_FONT;
2971 grd_curcanv->cv_font = NORMAL_FONT;
2972 gr_get_string_size( items[i], &w, &h, &aw );
2973 gr_rect( wx, y-1, wx+width-1, y+h );
2974 gr_string( wx+5, y, items[i] );
2977 newmenu_show_cursor();
2981 newmenu_hide_cursor();
2983 keyd_repeat = old_keyd_repeat;
2985 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2987 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2988 gr_free_bitmap(bg.background);
2991 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) );
2998 int newmenu_filelist( char * title, char * filespec, char * filename )
3001 char * Filenames[MAX_FILES];
3002 char FilenameText[MAX_FILES][14];
3003 FILEFINDSTRUCT find;
3006 if( !FileFindFirst( filespec, &find ) ) {
3008 if (NumFiles<MAX_FILES) {
3009 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3010 Filenames[NumFiles] = FilenameText[NumFiles];
3015 } while( !FileFindNext( &find ) );
3019 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3021 strcpy( filename, Filenames[i] );
3028 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3029 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3035 char nm_text[MESSAGEBOX_TEXT_SIZE];
3036 newmenu_item nm_message_items[5];
3038 va_start(args, nchoices );
3040 Assert( nchoices <= 5 );
3042 for (i=0; i<nchoices; i++ ) {
3043 s = va_arg( args, char * );
3044 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3046 format = va_arg( args, char * );
3047 //sprintf( nm_text, "" ); // adb: ?
3048 vsprintf(nm_text,format,args);
3051 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3053 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3055 //end this section addition - Victor Rachels
3058 extern netgame_info Active_games[];
3059 extern int NumActiveNetgames;
3061 void show_extra_netgame_info(int choice)
3067 if (choice>=NumActiveNetgames)
3072 m[i].text=(char *)&mtext[i];
3073 m[i].type=NM_TYPE_TEXT;
3076 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3077 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3078 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3079 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3081 already_showing_info=1;
3082 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3083 already_showing_info=0;
3088 /* Spiffy word wrap string formatting function */
3090 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3096 tbuf = (char *)d_malloc((unsigned int)strlen(sbuf) + 1);
3099 wordptr = strtok(tbuf, " ");
3100 if (!wordptr) return;
3106 col = col + (int)strlen(wordptr) + 1;
3107 if (col >=line_length) {
3109 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3112 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3114 wordptr = strtok(NULL, " ");