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)
54 #define MAXDISPLAYABLEITEMS 15
56 #define LHX(x) ((x)*(MenuHires?2:1))
57 #define LHY(y) ((y)*(MenuHires?2.4:1))
59 #define TITLE_FONT HUGE_FONT
60 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
61 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
62 #define SUBTITLE_FONT MEDIUM3_FONT
64 #define NORMAL_CHECK_BOX "\x81" // 129
65 #define CHECKED_CHECK_BOX "\x82" // 130
67 #define NORMAL_RADIO_BOX "\x7f" // 127
68 #define CHECKED_RADIO_BOX "\x80" // 128
69 #define CURSOR_STRING "_"
70 #define SLIDER_LEFT "\x83" // 131
71 #define SLIDER_RIGHT "\x84" // 132
72 #define SLIDER_MIDDLE "\x85" // 133
73 #define SLIDER_MARKER "\x86" // 134
74 #define UP_ARROW_MARKER "\x87" // 135
75 #define DOWN_ARROW_MARKER "\x88" // 136
77 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 );
78 void show_extra_netgame_info(int choice);
81 int Newmenu_first_time = 1;
82 //--unused-- int Newmenu_fade_in = 1;
85 grs_canvas * menu_canvas;
86 grs_bitmap * saved; // The background under the menu.
87 grs_bitmap * background;
90 grs_bitmap nm_background,nm_background_save;
92 #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)
93 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
95 ubyte MenuReordering=0;
97 char Pauseable_menu=0;
98 char already_showing_info=0;
101 void newmenu_close() {
102 if ( nm_background.bm_data )
103 d_free(nm_background.bm_data);
105 if ( nm_background_save.bm_data )
106 d_free(nm_background_save.bm_data);
107 Newmenu_first_time = 1;
110 ubyte background_palette[768];
112 //should be called whenever the palette changes
113 void nm_remap_background()
115 if (!Newmenu_first_time) {
116 if (!nm_background.bm_data)
117 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
119 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
121 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
127 extern char last_palette_loaded[];
129 void nm_draw_background1(char * filename)
136 //@@//I think this only gets called to fill the whole screen
137 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
138 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
140 pcx_error = pcx_get_dimensions(filename, &width, &height);
141 if (pcx_error != PCX_ERROR_NONE)
142 Error("Could not open pcx file <%s>\n", filename);
144 bmp = gr_create_bitmap(width, height);
146 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
147 Assert(pcx_error == PCX_ERROR_NONE);
149 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
152 { //remap stuff. this code is kindof a hack
154 //now, before we bring up the menu, we need to
155 //do some stuff to make sure the palette is ok. First, we need to
156 //get our current palette into the 2d's array, so the remapping will
157 //work. Second, we need to remap the fonts. Third, we need to fill
158 //in part of the fade tables so the darkening of the menu edges works
160 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
162 gr_palette_load(gr_palette);
164 remap_fonts_and_menus(1);
172 strcpy(last_palette_loaded,""); //force palette load next time
176 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
177 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
179 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
181 int Background_hires;
184 void nm_draw_background(int x1, int y1, int x2, int y2 )
188 if (Newmenu_first_time || MenuHires!=Background_hires) {
191 if (Newmenu_first_time) {
192 atexit( newmenu_close );
193 Newmenu_first_time = 0;
194 nm_background_save.bm_data=NULL;
197 if (nm_background_save.bm_data)
198 d_free(nm_background_save.bm_data);
199 if (nm_background.bm_data)
200 d_free(nm_background.bm_data);
203 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
204 Assert(pcx_error == PCX_ERROR_NONE);
206 nm_background = nm_background_save;
207 nm_background.bm_data=NULL;
208 nm_remap_background();
210 Background_hires = MenuHires;
213 if ( x1 < 0 ) x1 = 0;
214 if ( y1 < 0 ) y1 = 0;
219 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
220 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
227 grs_bitmap *tmp = gr_create_bitmap(w, h);
229 gr_bitmap_scale_to(&nm_background, tmp);
232 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
234 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
239 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
241 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
245 Gr_scanline_darkening_level = 2*7;
247 gr_setcolor( BM_XRGB(0,0,0) );
248 gr_urect( x2-5, y1+5, x2-5, y2-5 );
249 gr_urect( x2-4, y1+4, x2-4, y2-5 );
250 gr_urect( x2-3, y1+3, x2-3, y2-5 );
251 gr_urect( x2-2, y1+2, x2-2, y2-5 );
252 gr_urect( x2-1, y1+1, x2-1, y2-5 );
253 gr_urect( x2+0, y1+0, x2-0, y2-5 );
255 gr_urect( x1+5, y2-5, x2, y2-5 );
256 gr_urect( x1+4, y2-4, x2, y2-4 );
257 gr_urect( x1+3, y2-3, x2, y2-3 );
258 gr_urect( x1+2, y2-2, x2, y2-2 );
259 gr_urect( x1+1, y2-1, x2, y2-1 );
260 gr_urect( x1+0, y2, x2, y2-0 );
263 Gr_scanline_darkening_level = GR_FADE_LEVELS;
266 void nm_restore_background( int x, int y, int w, int h )
273 if ( x1 < 0 ) x1 = 0;
274 if ( y1 < 0 ) y1 = 0;
276 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
277 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
282 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
285 // Draw a left justfied string
286 void nm_string( bkg * b, int w1,int x, int y, char * s)
288 int w,h,aw,tx=0,t=0,i;
289 char *p,*s1,*s2,measure[2];
290 int XTabs[]={15,87,124,162,228,253};
296 XTabs[i]=(LHX(XTabs[i]));
303 p = strchr( s2, '\t' );
310 gr_get_string_size(s2, &w, &h, &aw );
316 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
317 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
320 for (i=0;i<strlen(s2);i++) {
321 if (s2[i]=='\t' && SurfingNet) {
327 gr_get_string_size(measure,&tx,&h,&aw);
328 gr_string(x,y,measure);
335 if (!SurfingNet && p && (w1>0) ) {
336 gr_get_string_size(s1, &w, &h, &aw );
338 gr_string( x+w1-w, y, s1 );
345 // Draw a slider and it's string
346 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
353 p = strchr( s, '\t' );
359 gr_get_string_size(s, &w, &h, &aw );
362 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
363 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
365 gr_string( x, y, s );
368 gr_get_string_size(s1, &w, &h, &aw );
371 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
373 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
375 gr_string( x+w1-w, y, s1 );
382 // Draw a left justfied string with black background.
383 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
386 gr_get_string_size(s, &w, &h, &aw );
389 gr_setcolor( BM_XRGB(2,2,2) );
390 gr_rect( x-1, y-1, x-1, y+h-1 );
391 gr_rect( x-1, y-1, x+w1-1, y-1 );
394 gr_setcolor( BM_XRGB(5,5,5) );
395 gr_rect( x, y+h, x+w1, y+h);
396 gr_rect( x+w1, y-1, x+w1, y+h );
398 gr_setcolor( BM_XRGB(0,0,0) );
399 gr_rect( x, y, x+w1-1, y+h-1 );
401 gr_string( x+1, y+1, s );
405 // Draw a right justfied string
406 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
409 gr_get_string_size(s, &w, &h, &aw );
414 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
417 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
418 gr_string( x-w, y, s );
423 //for text items, constantly redraw cursor (to achieve flash)
424 void update_cursor( newmenu_item *item)
427 fix time = timer_get_approx_seconds();
429 char * text = item->text;
431 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
434 gr_get_string_size(text, &w, &h, &aw );
435 if ( w > item->w-10 )
442 x = item->x+w; y = item->y;
445 gr_string( x, y, CURSOR_STRING );
447 gr_setcolor( BM_XRGB(0,0,0) );
448 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
452 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
457 gr_get_string_size(text, &w1, &h1, &aw );
466 nm_string_black( b, w, x, y, text );
469 gr_string( x+w1+1, y, CURSOR_STRING );
473 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
478 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
480 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
482 if (item->text[0]=='\t')
483 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
488 grd_curcanv->cv_font = SELECTED_FONT;
490 grd_curcanv->cv_font = NORMAL_FONT;
493 if (is_current && item->type == NM_TYPE_TEXT)
494 grd_curcanv->cv_font = NORMAL_FONT;
498 switch( item->type ) {
500 // grd_curcanv->cv_font=TEXT_FONT;
501 // fall through on purpose
504 nm_string( b, item->w, item->x, item->y, item->text );
506 case NM_TYPE_SLIDER: {
508 if (item->value < item->min_value) item->value=item->min_value;
509 if (item->value > item->max_value) item->value=item->max_value;
510 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
511 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
512 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
514 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
516 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
518 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
521 case NM_TYPE_INPUT_MENU:
522 if ( item->group==0 ) {
523 nm_string( b, item->w, item->x, item->y, item->text );
525 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
529 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
532 nm_string( b, item->w, item->x, item->y, item->text );
534 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
536 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
539 nm_string( b, item->w, item->x, item->y, item->text );
541 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
543 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
545 case NM_TYPE_NUMBER: {
547 if (item->value < item->min_value) item->value=item->min_value;
548 if (item->value > item->max_value) item->value=item->max_value;
549 nm_string( b, item->w, item->x, item->y, item->text );
550 sprintf( text, "%d", item->value );
551 nm_rstring( b,item->right_offset,item->x, item->y, text );
557 char *Newmenu_allowed_chars=NULL;
559 //returns true if char is allowed
560 int char_allowed(char c)
562 char *p = Newmenu_allowed_chars;
570 if (c>=p[0] && c<=p[1])
579 void strip_end_whitespace( char * text )
582 l = (int)strlen( text );
583 for (i=l-1; i>=0; i-- ) {
584 if ( isspace(text[i]) )
591 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
593 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
595 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
597 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
601 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
603 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
607 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 )
609 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
613 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 )
615 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
617 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 )
619 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
622 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){
623 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
624 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
625 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
629 // use menu with joystick
630 int newmenu_inkey(void)
636 if ( !Config_control_joystick.intval || key < KEY_JB1 || key > 255 ) // not using joystick, not a joystick button, or modifier pressed
639 if ( strlen(key_text[key]) > 5 && key_text[key][0] == 'J' && key_text[key][2] == 'H' ) // joystick hat
640 switch (key_text[key][4]) {
641 case 'U': key = KEY_UP; break;
642 case 'R': key = KEY_RIGHT; break;
643 case 'D': key = KEY_DOWN; break;
644 case 'L': key = KEY_LEFT; break;
646 else if ( strlen(key_text[key]) > 3 && key_text[key][0] == 'J' && key_text[key][2] == 'B' ) // joystick button
647 switch (key_text[key][3]) {
648 case '1': key = KEY_SPACEBAR; break;
649 case '2': key = KEY_ENTER; break;
650 case '3': key = KEY_ESC; break;
658 while (!key_checkch())
661 return newmenu_inkey();
665 extern int network_request_player_names(int);
666 extern int RestoringMenu;
669 ubyte Hack_DblClick_MenuMode=0;
673 extern ubyte joydefs_calibrating;
675 # define joydefs_calibrating 0
678 #define CLOSE_X (MenuHires?15:7)
679 #define CLOSE_Y (MenuHires?15:7)
680 #define CLOSE_SIZE (MenuHires?10:5)
682 void draw_close_box(int x,int y)
684 gr_setcolor( BM_XRGB(0, 0, 0) );
685 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
686 gr_setcolor( BM_XRGB(21, 21, 21) );
687 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));
690 extern int Num_bitmap_files;
692 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 )
694 int old_keyd_repeat, done;
695 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
696 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
697 grs_font * save_font;
698 int string_width, string_height = 0, average_width;
701 int all_text=0; //set true if all text items
702 int sound_stopped=0,time_stopped=0;
703 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
706 int MaxOnMenu=MAXDISPLAYABLEITEMS;
707 grs_canvas *save_canvas;
709 int mouse_state, omouse_state, dblclick_flag=0;
710 int mx=0, my=0, x1 = 0, x2, y1, y2;
714 EventRecord event; // looking for disk inserted events for CD mounts
717 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
718 newmenu_hide_cursor();
725 MaxDisplayable=nitems;
727 //set_screen_mode(SCREEN_MENU);
730 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
731 digi_pause_digi_sounds();
735 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
745 save_canvas = grd_curcanv;
747 gr_set_current_canvas(NULL);
749 save_font = grd_curcanv->cv_font;
754 grd_curcanv->cv_font = TITLE_FONT;
755 gr_get_string_size(title,&string_width,&string_height,&average_width );
760 grd_curcanv->cv_font = SUBTITLE_FONT;
761 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
762 if (string_width > tw )
767 th += LHY(8); //put some space between titles & body
770 grd_curcanv->cv_font = SMALL_FONT;
772 grd_curcanv->cv_font = NORMAL_FONT;
776 nmenus = nothers = 0;
778 // Find menu height & width (store in w,h)
779 for (i=0; i<nitems; i++ ) {
782 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
783 item[i].right_offset = 0;
786 string_height+=LHY(3);
788 item[i].saved_text[0] = '\0';
790 if ( item[i].type == NM_TYPE_SLIDER ) {
793 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
794 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
795 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
797 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
798 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
799 string_width += w1 + aw;
802 if ( item[i].type == NM_TYPE_MENU ) {
806 if ( item[i].type == NM_TYPE_CHECK ) {
809 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
810 item[i].right_offset = w1;
811 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
812 if (w1 > item[i].right_offset)
813 item[i].right_offset = w1;
816 if (item[i].type == NM_TYPE_RADIO ) {
819 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
820 item[i].right_offset = w1;
821 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
822 if (w1 > item[i].right_offset)
823 item[i].right_offset = w1;
826 if (item[i].type==NM_TYPE_NUMBER ) {
830 sprintf( test_text, "%d", item[i].max_value );
831 gr_get_string_size( test_text, &w1, &h1, &aw1 );
832 item[i].right_offset = w1;
833 sprintf( test_text, "%d", item[i].min_value );
834 gr_get_string_size( test_text, &w1, &h1, &aw1 );
835 if ( w1 > item[i].right_offset)
836 item[i].right_offset = w1;
839 if ( item[i].type == NM_TYPE_INPUT ) {
840 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
841 strcpy(item[i].saved_text, item[i].text );
843 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
844 if ( string_width > MAX_TEXT_WIDTH )
845 string_width = MAX_TEXT_WIDTH;
849 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
850 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
851 strcpy(item[i].saved_text, item[i].text );
853 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
858 item[i].w = string_width;
859 item[i].h = string_height;
861 if ( string_width > w )
862 w = string_width; // Save maximum width
863 if ( average_width > aw )
865 h += string_height+1; // Find the height of all strings
868 // Big hack for allowing the netgame options menu to spill over
870 MaxOnMenu=MAXDISPLAYABLEITEMS;
871 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
874 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
877 h=(MaxOnMenu*(string_height+1)+LHY(8));
878 MaxDisplayable=MaxOnMenu;
879 mprintf ((0,"Hey, this is a scroll box!\n"));
892 for (i=0; i<nitems; i++ ) {
894 if (item[i].right_offset > right_offset )
895 right_offset = item[i].right_offset;
897 if (right_offset > 0 )
900 //gr_get_string_size("",&string_width,&string_height,&average_width );
907 twidth = ( tw - w )/2;
912 { right_offset=0; twidth=0;}
914 mprintf(( 0, "Right offset = %d\n", right_offset ));
917 // Find min point of menu border
918 // x = (grd_curscreen->sc_w-w)/2;
919 // y = (grd_curscreen->sc_h-h)/2;
921 w += MenuHires?60:30;
922 h += MenuHires?60:30;
924 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
925 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
927 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
928 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
933 if ( filename != NULL ) {
934 nm_draw_background1( filename );
935 gr_palette_load(gr_palette);
938 // Save the background of the display
939 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h );
940 gr_set_current_canvas(bg.menu_canvas);
942 if ( filename == NULL ) {
943 // Save the background under the menu...
949 bg.saved = gr_create_bitmap( w, h );
950 Assert( bg.saved != NULL );
952 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
954 gr_set_current_canvas( NULL );
956 nm_draw_background(x,y,x+w-1,y+h-1);
958 gr_set_current_canvas( bg.menu_canvas );
960 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
964 bg.background = gr_create_bitmap( w, h );
965 Assert( bg.background != NULL );
967 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
970 // ty = 15 + (yborder/4);
972 ty = MenuHires?30:15;
975 grd_curcanv->cv_font = TITLE_FONT;
976 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
977 gr_get_string_size(title,&string_width,&string_height,&average_width );
980 gr_printf( 0x8000, ty, title );
985 grd_curcanv->cv_font = SUBTITLE_FONT;
986 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
987 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
990 gr_printf( 0x8000, ty, subtitle );
995 grd_curcanv->cv_font = SMALL_FONT;
997 grd_curcanv->cv_font = NORMAL_FONT;
999 // Update all item's x & y values.
1000 for (i=0; i<nitems; i++ ) {
1001 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1002 item[i].y += (MenuHires?30:15);
1003 if ( item[i].type==NM_TYPE_RADIO ) {
1004 fm = -1; // find first marked one
1005 for ( j=0; j<nitems; j++ ) {
1006 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1007 if (fm==-1 && item[j].value)
1019 old_keyd_repeat = keyd_repeat;
1025 if (citem < 0 ) citem = 0;
1026 if (citem > nitems-1 ) citem = nitems-1;
1029 #ifdef NEWMENU_MOUSE
1033 while ( item[choice].type==NM_TYPE_TEXT ) {
1035 if (choice >= nitems ) {
1038 if (choice == citem ) {
1049 // Clear mouse, joystick to clear button presses.
1050 game_flush_inputs();
1052 #ifdef NEWMENU_MOUSE
1053 mouse_state = omouse_state = 0;
1054 if (filename == NULL && !MenuReordering) {
1055 //draw_close_box(0,0);
1059 if (!MenuReordering && !joydefs_calibrating)
1061 newmenu_show_cursor();
1063 SetCursor(LoadCursor(NULL,IDC_ARROW));
1068 mprintf ((0,"Set to true!\n"));
1071 #ifdef NEWMENU_MOUSE
1072 if (!joydefs_calibrating)
1073 newmenu_show_cursor(); // possibly hidden
1074 omouse_state = mouse_state;
1075 if (!MenuReordering)
1076 mouse_state = mouse_button_state(0);
1077 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1080 //see if redbook song needs to be restarted
1081 songs_check_redbook_repeat();
1085 k = newmenu_inkey();
1088 (*subfunction)(nitems,item,&k,choice);
1091 if (!time_stopped) {
1092 // Save current menu box
1093 if (multi_menu_poll() == -1)
1099 dont_restore = (k == -3); //-3 means don't restore
1105 #ifndef NEWMENU_MOUSE // don't allow mouse to continue from menu
1106 if (Config_control_mouse.intval)
1107 for ( i = 0; i < 3; i++ )
1108 if (mouse_button_down_count(i) > 0)
1112 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1115 old_choice = choice;
1117 // More versatile menu navigation
1120 switch (item[choice].type) {
1122 case NM_TYPE_INPUT_MENU:
1132 switch (item[choice].type) {
1136 case NM_TYPE_INPUT_MENU:
1147 if (SurfingNet && !already_showing_info)
1149 show_extra_netgame_info(choice-2);
1151 if (SurfingNet && already_showing_info)
1158 if (SurfingNet && !already_showing_info)
1160 network_request_player_names(choice-2);
1162 if (SurfingNet && already_showing_info)
1177 case KEY_TAB + KEY_SHIFTED:
1180 if (all_text) break;
1187 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1189 if (choice<TopChoice)
1190 { choice=TopChoice; break; }
1192 if (choice<ScrollOffset)
1194 for (i=0;i<nitems;i++)
1197 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1202 if (choice >= nitems ) choice=0;
1203 if (choice < 0 ) choice=nitems-1;
1205 } while ( item[choice].type==NM_TYPE_TEXT );
1206 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1207 item[choice].value = -1;
1208 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1209 item[old_choice].group=0;
1210 strcpy(item[old_choice].text, item[old_choice].saved_text );
1211 item[old_choice].value = -1;
1214 item[old_choice].redraw = 1;
1215 item[choice].redraw=1;
1220 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1221 if (all_text) break;
1228 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1231 { choice--; break; }
1233 if (choice>=MaxOnMenu+ScrollOffset)
1235 for (i=0;i<nitems;i++)
1238 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1243 if (choice < 0 ) choice=nitems-1;
1244 if (choice >= nitems ) choice=0;
1247 } while ( item[choice].type==NM_TYPE_TEXT );
1249 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1250 item[choice].value = -1;
1251 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1252 item[old_choice].group=0;
1253 strcpy(item[old_choice].text, item[old_choice].saved_text );
1254 item[old_choice].value = -1;
1257 item[old_choice].redraw=1;
1258 item[choice].redraw=1;
1261 if ( choice > -1 ) {
1262 switch( item[choice].type ) {
1265 case NM_TYPE_INPUT_MENU:
1268 if ( item[choice].value )
1269 item[choice].value = 0;
1271 item[choice].value = 1;
1272 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1275 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1277 mprintf ((0,"Special redraw!\n"));
1282 item[choice].redraw=1;
1285 for (i=0; i<nitems; i++ ) {
1286 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1291 item[choice].value = 1;
1292 item[choice].redraw = 1;
1298 case KEY_SHIFTED+KEY_UP:
1299 if (MenuReordering && choice!=TopChoice)
1301 Temp=item[choice].text;
1302 TempVal=item[choice].value;
1303 item[choice].text=item[choice-1].text;
1304 item[choice].value=item[choice-1].value;
1305 item[choice-1].text=Temp;
1306 item[choice-1].value=TempVal;
1307 item[choice].redraw=1;
1308 item[choice-1].redraw=1;
1312 case KEY_SHIFTED+KEY_DOWN:
1313 if (MenuReordering && choice!=(nitems-1))
1315 Temp=item[choice].text;
1316 TempVal=item[choice].value;
1317 item[choice].text=item[choice+1].text;
1318 item[choice].value=item[choice+1].value;
1319 item[choice+1].text=Temp;
1320 item[choice+1].value=TempVal;
1321 item[choice].redraw=1;
1322 item[choice+1].redraw=1;
1329 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1330 item[choice].group = 1;
1331 item[choice].redraw = 1;
1332 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1333 item[choice].text[0] = 0;
1334 item[choice].value = -1;
1336 strip_end_whitespace(item[choice].text);
1343 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1344 item[choice].group=0;
1345 strcpy(item[choice].text, item[choice].saved_text );
1346 item[choice].redraw=1;
1347 item[choice].value = -1;
1354 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
1355 case KEY_PRINT_SCREEN:
1356 MAC(newmenu_hide_cursor());
1357 save_screen_shot(0);
1358 for (i=0;i<nitems;i++)
1361 MAC(newmenu_show_cursor());
1367 case KEY_COMMAND+KEY_RIGHT:
1368 songs_goto_next_song();
1370 case KEY_COMMAND+KEY_LEFT:
1371 songs_goto_prev_song();
1373 case KEY_COMMAND+KEY_UP:
1374 songs_play_level_song(1);
1376 case KEY_COMMAND+KEY_DOWN:
1377 songs_stop_redbook();
1380 case KEY_COMMAND+KEY_M:
1382 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1385 key_close(); // no processing of keys with keyboard handler.. jeez
1387 newmenu_hide_cursor();
1388 show_boxed_message ("Mounting CD\nESC to quit");
1389 RBAMountDisk(); // OS has totaly control of the CD.
1390 if (Function_mode == FMODE_MENU)
1391 songs_play_song(SONG_TITLE,1);
1392 else if (Function_mode == FMODE_GAME)
1393 songs_play_level_song( Current_level_num );
1394 clear_boxed_message();
1395 newmenu_show_cursor();
1402 case KEY_COMMAND+KEY_E:
1403 songs_stop_redbook();
1405 k = -1; // force key not to register
1409 case KEY_COMMAND+KEY_Q: {
1410 if ( !(Game_mode & GM_MULTI) )
1412 if (!joydefs_calibrating)
1413 newmenu_show_cursor();
1414 k = -1; // force key not to register
1420 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1425 case KEY_SHIFTED + KEY_B:
1428 grs_canvas *canv_save = grd_curcanv;
1429 grs_canvas *temp_canv;
1432 ubyte pal_save[768];
1434 memcpy(pal_save, gr_palette, 768);
1435 gr_use_palette_table(DEFAULT_LEVEL_PALETTE);
1436 memcpy(bm_pal, gr_palette, 768);
1437 gr_copy_palette(gr_palette, pal_save, 768);
1439 if (k & KEY_SHIFTED)
1445 n = Num_bitmap_files - 1;
1446 n %= Num_bitmap_files;
1447 bm = &GameBitmaps[n];
1448 PIGGY_PAGE_IN( *(bitmap_index *)&n );
1449 con_printf(CON_DEBUG, "showing bitmap %d of %d: %s\n", n, Num_bitmap_files, piggy_game_bitmap_name(bm));
1451 temp_canv = gr_create_canvas(bm->bm_w, bm->bm_h);
1452 gr_set_current_canvas(temp_canv);
1453 gr_bitmap(0, 0, bm);
1454 gr_set_current_canvas(&grd_curscreen->sc_canvas);
1455 gr_remap_bitmap_good(&temp_canv->cv_bitmap, bm_pal, -1, -1);
1456 gr_bitmap(0, 0, &temp_canv->cv_bitmap);
1457 gr_free_canvas(temp_canv);
1458 gr_set_current_canvas(canv_save);
1463 case KEY_SHIFTED + KEY_P:
1465 char *palettes[] = {
1475 static unsigned int palnum = 0;
1477 if (k & KEY_SHIFTED)
1482 palnum %= sizeof(palettes)/sizeof(char *);
1483 load_palette(palettes[palnum], 0, 0);
1491 #ifdef NEWMENU_MOUSE // for mouse selection of menu's etc.
1492 if ( !done && mouse_state && !omouse_state && !all_text ) {
1493 mouse_get_pos(&mx, &my);
1494 for (i=0; i<nitems; i++ ) {
1495 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1496 x2 = x1 + item[i].w;
1497 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1498 y2 = y1 + item[i].h;
1499 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1500 if (i+ScrollOffset != choice) {
1501 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1504 choice = i + ScrollOffset;
1506 switch( item[choice].type ) {
1508 if ( item[choice].value )
1509 item[choice].value = 0;
1511 item[choice].value = 1;
1512 item[choice].redraw=1;
1519 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1521 mprintf ((0,"Special redraw!\n"));
1528 for (i=0; i<nitems; i++ ) {
1529 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1534 item[choice].value = 1;
1535 item[choice].redraw = 1;
1538 item[old_choice].redraw=1;
1544 if (mouse_state && all_text)
1547 if ( !done && mouse_state && !all_text ) {
1548 mouse_get_pos(&mx, &my);
1550 // check possible scrollbar stuff first
1552 int arrow_width, arrow_height, aw;
1554 if (ScrollOffset != 0) {
1555 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1556 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1557 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1558 x1 = x1 - arrow_width;
1559 y2 = y1 + arrow_height;
1560 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1563 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1565 if (choice<ScrollOffset)
1567 for (i=0;i<nitems;i++)
1570 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1574 if (ScrollOffset+MaxDisplayable<nitems) {
1575 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1576 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1577 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1578 x1 = x1 - arrow_width;
1579 y2 = y1 + arrow_height;
1580 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1583 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1585 if (choice>=MaxOnMenu+ScrollOffset)
1587 for (i=0;i<nitems;i++)
1590 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1596 for (i=0; i<nitems; i++ ) {
1597 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1598 x2 = x1 + item[i].w;
1599 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1600 y2 = y1 + item[i].h;
1601 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1602 if (i+ScrollOffset != choice) {
1603 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1606 choice = i + ScrollOffset;
1608 if ( item[choice].type == NM_TYPE_SLIDER ) {
1609 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1 = NULL;
1610 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1612 strcpy(slider_text, item[choice].saved_text);
1613 p = strchr(slider_text, '\t');
1619 gr_get_string_size(s1, &slider_width, &height, &aw);
1620 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1621 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1622 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1624 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1625 x2 = x1 + slider_width + sright_width;
1626 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1627 item[choice].value = item[choice].min_value;
1628 item[choice].redraw = 2;
1629 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1630 item[choice].value = item[choice].max_value;
1631 item[choice].redraw = 2;
1632 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1633 int num_values, value_width, new_value;
1635 num_values = item[choice].max_value - item[choice].min_value + 1;
1636 value_width = (slider_width - sleft_width - sright_width) / num_values;
1637 new_value = (mx - x1 - sleft_width) / value_width;
1638 if ( item[choice].value != new_value ) {
1639 item[choice].value = new_value;
1640 item[choice].redraw = 2;
1646 if (choice == old_choice)
1648 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1649 item[choice].value = -1;
1650 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1651 item[old_choice].group=0;
1652 strcpy(item[old_choice].text, item[old_choice].saved_text );
1653 item[old_choice].value = -1;
1656 item[old_choice].redraw = 1;
1657 item[choice].redraw=1;
1663 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1664 mouse_get_pos(&mx, &my);
1665 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1666 x2 = x1 + item[choice].w;
1667 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1668 y2 = y1 + item[choice].h;
1669 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1670 if (Hack_DblClick_MenuMode) {
1671 if (dblclick_flag) done = 1;
1672 else dblclick_flag = 1;
1678 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1679 item[choice].group = 1;
1680 item[choice].redraw = 1;
1681 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1682 item[choice].text[0] = 0;
1683 item[choice].value = -1;
1685 strip_end_whitespace(item[choice].text);
1689 if ( !done && !mouse_state && omouse_state && close_box ) {
1690 mouse_get_pos(&mx, &my);
1691 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1692 x2 = x1 + CLOSE_SIZE;
1693 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1694 y2 = y1 + CLOSE_SIZE;
1695 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1701 // HACK! Don't redraw loadgame preview
1702 if (RestoringMenu) item[0].redraw = 0;
1703 #endif // NEWMENU_MOUSE
1705 if ( choice > -1 ) {
1708 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1709 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1710 if (item[choice].value == -1)
1711 item[choice].value = (int)strlen(item[choice].text);
1712 if (item[choice].value > 0)
1713 item[choice].value--;
1714 item[choice].text[item[choice].value] = 0;
1715 item[choice].redraw = 1;
1717 ascii = key_to_ascii(k);
1718 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1722 if (item[choice].value==-1) {
1723 item[choice].value = 0;
1726 allowed = char_allowed(ascii);
1728 if (!allowed && ascii==' ' && char_allowed('_')) {
1734 item[choice].text[item[choice].value++] = ascii;
1735 item[choice].text[item[choice].value] = 0;
1736 item[choice].redraw=1;
1740 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1741 ascii = key_to_ascii(k);
1743 int choice1 = choice;
1744 ascii = toupper(ascii);
1748 if (choice1 >= nitems ) choice1=0;
1749 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1750 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1751 (item[choice1].type==NM_TYPE_CHECK) ||
1752 (item[choice1].type==NM_TYPE_RADIO) ||
1753 (item[choice1].type==NM_TYPE_NUMBER) ||
1754 (item[choice1].type==NM_TYPE_SLIDER) )
1755 && (ascii==toupper(ch)) ) {
1759 item[old_choice].redraw=1;
1760 item[choice].redraw=1;
1762 } while (choice1 != choice );
1766 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1767 int ov=item[choice].value;
1772 case KEY_MINUS+KEY_SHIFTED:
1774 item[choice].value -= 1;
1779 case KEY_EQUAL+KEY_SHIFTED:
1781 item[choice].value++;
1786 item[choice].value += 10;
1791 item[choice].value -= 10;
1794 if (ov!=item[choice].value)
1795 item[choice].redraw=1;
1800 gr_set_current_canvas(bg.menu_canvas);
1802 // Redraw everything...
1803 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1805 if (item[i].redraw) // warning! ugly hack below
1807 item[i].y-=((string_height+1)*ScrollOffset);
1808 newmenu_hide_cursor();
1809 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1811 #ifdef NEWMENU_MOUSE
1812 if (!MenuReordering && !joydefs_calibrating)
1813 newmenu_show_cursor();
1815 item[i].y+=((string_height+1)*ScrollOffset);
1817 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1818 update_cursor( &item[i]);
1824 //grd_curcanv->cv_font = NORMAL_FONT;
1826 if (LastScrollCheck!=ScrollOffset)
1828 LastScrollCheck=ScrollOffset;
1829 grd_curcanv->cv_font = SELECTED_FONT;
1831 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1832 sx=item[ScrollOffset].x-(MenuHires?24:12);
1835 if (ScrollOffset!=0)
1836 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1838 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1840 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1841 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1843 if (ScrollOffset+MaxDisplayable<nitems)
1844 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1846 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1852 if ( !dont_restore && gr_palette_faded_out ) {
1853 gr_palette_fade_in( gr_palette, 32, 0 );
1857 newmenu_hide_cursor();
1859 // Restore everything...
1861 gr_set_current_canvas(bg.menu_canvas);
1863 if ( filename == NULL ) {
1864 // Save the background under the menu...
1865 gr_bitmap(0, 0, bg.saved);
1866 gr_free_bitmap(bg.saved);
1867 d_free( bg.background );
1869 if (!dont_restore) //info passed back from subfunction
1870 gr_bitmap(0, 0, bg.background);
1871 gr_free_bitmap(bg.background);
1874 gr_free_sub_canvas( bg.menu_canvas );
1876 gr_set_current_canvas(save_canvas);
1877 grd_curcanv->cv_font = save_font;
1878 keyd_repeat = old_keyd_repeat;
1880 game_flush_inputs();
1891 if ( sound_stopped )
1892 digi_resume_digi_sounds();
1899 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1905 char nm_text[MESSAGEBOX_TEXT_SIZE];
1906 newmenu_item nm_message_items[5];
1908 va_start(args, nchoices );
1910 Assert( nchoices <= 5 );
1912 for (i=0; i<nchoices; i++ ) {
1913 s = va_arg( args, char * );
1914 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1916 format = va_arg( args, char * );
1917 strcpy( nm_text, "" );
1918 vsprintf(nm_text,format,args);
1921 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1923 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1926 int nm_messagebox( char *title, int nchoices, ... )
1932 char nm_text[MESSAGEBOX_TEXT_SIZE];
1933 newmenu_item nm_message_items[5];
1935 va_start(args, nchoices );
1937 Assert( nchoices <= 5 );
1939 for (i=0; i<nchoices; i++ ) {
1940 s = va_arg( args, char * );
1941 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1943 format = va_arg( args, char * );
1944 strcpy( nm_text, "" );
1945 vsprintf(nm_text,format,args);
1948 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1950 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1956 void newmenu_file_sort( int n, char *list )
1963 for (i=incr; i<n; i++ ) {
1966 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1967 memcpy( t, &list[j*14], FILENAME_LEN );
1968 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1969 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1980 void delete_player_saved_games(char * name)
1985 for (i=0;i<10; i++) {
1986 sprintf( filename, PLAYER_DIR "%s.sg%d", name, i );
1987 PHYSFS_delete(filename);
1991 #define MAX_FILES 300
1993 //FIXME: should maybe put globbing ability back?
1994 int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
2000 int NumFiles=0, key,done, citem, ocitem;
2001 char * filenames = NULL;
2002 int NumFiles_displayed = 8;
2003 int first_item = -1, ofirst_item;
2004 int old_keyd_repeat = keyd_repeat;
2007 int demos_deleted=0;
2008 int initialized = 0;
2010 int w_x, w_y, w_w, w_h, title_height;
2011 int box_x, box_y, box_w, box_h;
2012 bkg bg; // background under listbox
2013 #ifdef NEWMENU_MOUSE
2014 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2015 int mouse2_state, omouse2_state;
2016 int dblclick_flag=0;
2019 int show_up_arrow=0, show_down_arrow=0;
2023 w_x=w_y=w_w=w_h=title_height=0;
2024 box_x=box_y=box_w=box_h=0;
2026 filenames = d_malloc( MAX_FILES * 14 );
2027 if (filenames==NULL) return 0;
2032 if (!stricmp(type, "plr"))
2034 else if (!stricmp(type, "dem"))
2041 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2043 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2048 find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
2049 for (f = find; *f != NULL; f++)
2053 ext = strrchr(*f, '.');
2054 if (!ext || strnicmp(ext, ".plr", 4))
2057 if (NumFiles < MAX_FILES)
2059 strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
2064 p = strchr(&filenames[NumFiles*14], '.');
2074 PHYSFS_freeList(find);
2076 if ( (NumFiles < 1) && demos_deleted ) {
2080 if ( (NumFiles < 1) && demo_mode ) {
2081 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2087 if ( (NumFiles < 2) && player_mode ) {
2089 goto ExitFileMenuEarly;
2096 nm_messagebox(NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND);
2103 // set_screen_mode(SCREEN_MENU);
2106 gr_set_current_canvas(NULL);
2108 grd_curcanv->cv_font = SUBTITLE_FONT;
2113 for (i=0; i<NumFiles; i++ ) {
2115 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2121 gr_get_string_size( title, &w, &h, &aw );
2124 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2128 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2130 w_w += (grd_curfont->ft_w * 4);
2131 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2133 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2134 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2136 w_x = (grd_curcanv->cv_w-w_w)/2;
2137 w_y = (grd_curcanv->cv_h-w_h)/2;
2139 if ( w_x < 0 ) w_x = 0;
2140 if ( w_y < 0 ) w_y = 0;
2142 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2143 box_y = w_y + title_height;
2145 // save the screen behind the menu.
2149 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2150 bg.background = &VR_offscreen_buffer->cv_bitmap;
2152 bg.background = gr_create_bitmap( w_w, w_h );
2154 Assert( bg.background != NULL );
2157 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2160 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2163 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2165 gr_string( 0x8000, w_y+10, title );
2170 if ( !player_mode ) {
2171 newmenu_file_sort( NumFiles, filenames );
2173 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2174 newmenu_file_sort( NumFiles, filenames );
2176 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2178 for ( i=0; i<NumFiles; i++ ) {
2179 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2180 #ifdef NEWMENU_MOUSE
2188 #ifdef NEWMENU_MOUSE
2189 mouse_state = omouse_state = 0;
2190 mouse2_state = omouse2_state = 0;
2191 //draw_close_box(w_x,w_y);
2192 newmenu_show_cursor();
2197 ofirst_item = first_item;
2200 #ifdef NEWMENU_MOUSE
2201 omouse_state = mouse_state;
2202 omouse2_state = mouse2_state;
2203 mouse_state = mouse_button_state(0);
2204 mouse2_state = mouse_button_state(1);
2207 //see if redbook song needs to be restarted
2208 songs_check_redbook_repeat();
2210 key = newmenu_inkey();
2213 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2214 case KEY_PRINT_SCREEN:
2215 MAC(newmenu_hide_cursor());
2216 save_screen_shot(0);
2218 MAC(newmenu_show_cursor());
2222 case KEY_CTRLED+KEY_D:
2223 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2227 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2229 newmenu_hide_cursor();
2231 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2233 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2234 newmenu_show_cursor();
2238 char name[PATH_MAX];
2240 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2244 strcpy(name, demo_mode?DEMO_DIR:"");
2245 strcat(name,&filenames[citem*14]);
2252 if ( !strncmp(name, ".\\", 2) )
2253 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2254 name[i] = name[i+1];
2255 while ( (p = strchr(name, '\\')) )
2260 ret = !PHYSFS_delete(name);
2264 if ((!ret) && player_mode) {
2265 delete_player_saved_games( &filenames[citem*14] );
2270 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2272 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2273 } else if (demo_mode)
2298 citem += NumFiles_displayed;
2302 citem -= NumFiles_displayed;
2306 if (allow_abort_flag) {
2317 case KEY_COMMAND+KEY_Q: {
2318 if ( !(Game_mode & GM_MULTI) )
2323 newmenu_show_cursor();
2331 int ascii = key_to_ascii(key);
2332 if ( ascii < 255 ) {
2335 if (cc1 < 0 ) cc1 = 0;
2336 if (cc1 >= NumFiles ) cc1 = 0;
2338 if ( cc < 0 ) cc = 0;
2339 if ( cc >= NumFiles ) cc = 0;
2340 if ( citem == cc ) break;
2342 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2357 if (citem>=NumFiles)
2360 if (citem< first_item)
2363 if (citem>=( first_item+NumFiles_displayed))
2365 first_item = citem-NumFiles_displayed+1;
2369 if (NumFiles>first_item+NumFiles_displayed)
2380 if (NumFiles <= NumFiles_displayed )
2383 if (first_item>NumFiles-NumFiles_displayed)
2385 first_item = NumFiles-NumFiles_displayed;
2388 if (first_item < 0 ) first_item = 0;
2390 #ifdef NEWMENU_MOUSE
2391 if (mouse_state || mouse2_state) {
2394 mouse_get_pos(&mx, &my);
2395 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2396 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2398 x2 = box_x + box_w - 1;
2399 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2401 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2402 if (i == citem && !mouse2_state) {
2412 if (!mouse_state && omouse_state) {
2415 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2416 mouse_get_pos(&mx, &my);
2418 x2 = box_x + box_w - 1;
2419 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2421 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2422 if (dblclick_flag) done = 1;
2423 else dblclick_flag = 1;
2427 if ( !mouse_state && omouse_state ) {
2428 mouse_get_pos(&mx, &my);
2429 x1 = w_x + CLOSE_X + 2;
2430 x2 = x1 + CLOSE_SIZE - 2;
2431 y1 = w_y + CLOSE_Y + 2;
2432 y2 = y1 + CLOSE_SIZE - 2;
2433 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2442 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2444 y1 = box_y+box_h-LHY(7);
2446 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2453 gr_setcolor( BM_XRGB(2,2,2));
2454 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2455 gr_setcolor( BM_XRGB( 0,0,0) );
2457 if (ofirst_item != first_item) {
2458 newmenu_hide_cursor();
2459 gr_setcolor( BM_XRGB( 0,0,0) );
2460 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2462 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2464 if ( i >= NumFiles ) {
2466 gr_setcolor( BM_XRGB(5,5,5));
2467 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2468 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2470 gr_setcolor( BM_XRGB(2,2,2));
2471 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2473 gr_setcolor( BM_XRGB(0,0,0));
2474 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2478 grd_curcanv->cv_font = SELECTED_FONT;
2480 grd_curcanv->cv_font = NORMAL_FONT;
2481 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2483 gr_setcolor( BM_XRGB(5,5,5));
2484 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2485 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2487 gr_setcolor( BM_XRGB(2,2,2));
2488 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2489 gr_setcolor( BM_XRGB(0,0,0));
2491 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2492 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2495 newmenu_show_cursor();
2496 } else if ( citem != ocitem ) {
2499 newmenu_hide_cursor();
2501 if ( (i>=0) && (i<NumFiles) ) {
2502 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2504 grd_curcanv->cv_font = SELECTED_FONT;
2506 grd_curcanv->cv_font = NORMAL_FONT;
2507 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2508 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2509 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2512 if ( (i>=0) && (i<NumFiles) ) {
2513 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2515 grd_curcanv->cv_font = SELECTED_FONT;
2517 grd_curcanv->cv_font = NORMAL_FONT;
2518 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2519 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2520 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2522 newmenu_show_cursor();
2526 grd_curcanv->cv_font = NORMAL_FONT;
2528 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2532 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2536 if (show_down_arrow)
2537 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2541 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2549 MAC(newmenu_hide_cursor());
2551 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2558 keyd_repeat = old_keyd_repeat;
2560 if ( initialized ) {
2561 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2562 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2563 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2564 gr_free_bitmap(bg.background);
2566 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2578 // Example listbox callback function...
2579 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2583 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2584 // if ( *nitems > 1 ) {
2585 // PHYSFS_delete(items[*citem]); // Delete the file
2586 // for (i=*citem; i<*nitems-1; i++ ) {
2587 // items[i] = items[i+1];
2589 // *nitems = *nitems - 1;
2590 // d_free( items[*nitems] );
2591 // items[*nitems] = NULL;
2592 // return 1; // redraw;
2599 #define LB_ITEMS_ON_SCREEN 8
2601 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2603 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2606 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 ) )
2609 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2610 int old_keyd_repeat = keyd_repeat;
2611 int width, height, wx, wy, title_height, border_size;
2612 int total_width,total_height;
2614 #ifdef NEWMENU_MOUSE
2615 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2616 int close_x,close_y;
2618 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2624 // set_screen_mode(SCREEN_MENU);
2627 gr_set_current_canvas(NULL);
2629 grd_curcanv->cv_font = SUBTITLE_FONT;
2632 for (i=0; i<nitems; i++ ) {
2634 gr_get_string_size( items[i], &w, &h, &aw );
2638 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2642 gr_get_string_size( title, &w, &h, &aw );
2645 title_height = h + 5;
2648 border_size = grd_curfont->ft_w;
2649 WIN (border_size=grd_curfont->ft_w*2);
2651 width += (grd_curfont->ft_w);
2652 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2653 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2655 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2656 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2657 if ( wy < title_height )
2660 total_width = width+2*border_size;
2661 total_height = height+2*border_size+title_height;
2665 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2666 bg.background = &VR_offscreen_buffer->cv_bitmap;
2668 //bg.background = gr_create_bitmap( width, (height + title_height) );
2669 bg.background = gr_create_bitmap(total_width,total_height);
2670 Assert( bg.background != NULL );
2672 //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 );
2673 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2676 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2679 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2681 gr_string( 0x8000, wy - title_height, title );
2684 citem = default_item;
2685 if ( citem < 0 ) citem = 0;
2686 if ( citem >= nitems ) citem = 0;
2690 #ifdef NEWMENU_MOUSE
2691 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2692 close_x = wx-border_size;
2693 close_y = wy-title_height-border_size;
2694 //draw_close_box(close_x,close_y);
2695 newmenu_show_cursor();
2700 ofirst_item = first_item;
2701 #ifdef NEWMENU_MOUSE
2702 omouse_state = mouse_state;
2703 mouse_state = mouse_button_state(0);
2705 //see if redbook song needs to be restarted
2706 songs_check_redbook_repeat();
2708 key = newmenu_inkey();
2710 if ( listbox_callback )
2711 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2725 else if (simukey==1)
2731 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2732 case KEY_PRINT_SCREEN:
2733 MAC(newmenu_hide_cursor());
2734 save_screen_shot(0);
2736 MAC(newmenu_show_cursor());
2757 citem += LB_ITEMS_ON_SCREEN;
2761 citem -= LB_ITEMS_ON_SCREEN;
2765 if (allow_abort_flag) {
2776 case KEY_COMMAND+KEY_Q: {
2777 if ( !(Game_mode & GM_MULTI) )
2779 newmenu_show_cursor();
2786 int ascii = key_to_ascii(key);
2787 if ( ascii < 255 ) {
2790 if (cc1 < 0 ) cc1 = 0;
2791 if (cc1 >= nitems ) cc1 = 0;
2793 if ( cc < 0 ) cc = 0;
2794 if ( cc >= nitems ) cc = 0;
2795 if ( citem == cc ) break;
2797 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2814 if (citem< first_item)
2817 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2818 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2820 if (nitems <= LB_ITEMS_ON_SCREEN )
2823 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
2824 first_item = nitems-LB_ITEMS_ON_SCREEN;
2825 if (first_item < 0 ) first_item = 0;
2828 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
2839 #ifdef NEWMENU_MOUSE
2843 mouse_get_pos(&mx, &my);
2844 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2847 gr_get_string_size(items[i], &w, &h, &aw );
2850 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2852 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2864 //no double-click stuff for listbox
2865 //@@if (!mouse_state && omouse_state) {
2868 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
2869 //@@ mouse_get_pos(&mx, &my);
2871 //@@ x2 = wx + width;
2872 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
2874 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2875 //@@ if (dblclick_flag) done = 1;
2879 //check for close box clicked
2880 if ( !mouse_state && omouse_state ) {
2881 mouse_get_pos(&mx, &my);
2882 x1 = close_x + CLOSE_X + 2;
2883 x2 = x1 + CLOSE_SIZE - 2;
2884 y1 = close_y + CLOSE_Y + 2;
2885 y2 = y1 + CLOSE_SIZE - 2;
2886 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2896 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
2898 y1 = total_height-LHY(7);
2900 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
2908 if ( (ofirst_item != first_item) || redraw) {
2909 newmenu_hide_cursor();
2911 gr_setcolor( BM_XRGB( 0,0,0) );
2912 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2914 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2915 if ( i >= nitems ) {
2916 gr_setcolor( BM_XRGB(0,0,0));
2917 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
2920 grd_curcanv->cv_font = SELECTED_FONT;
2922 grd_curcanv->cv_font = NORMAL_FONT;
2923 gr_get_string_size(items[i], &w, &h, &aw );
2924 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2925 gr_string( wx+5, y, items[i] );
2930 // If Win95 port, draw up/down arrows on left side of menu
2932 grd_curcanv->cv_font = NORMAL_FONT;
2934 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
2938 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
2942 if (show_down_arrow)
2943 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
2947 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
2954 newmenu_show_cursor();
2956 } else if ( citem != ocitem ) {
2959 newmenu_hide_cursor();
2962 if ( (i>=0) && (i<nitems) ) {
2963 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2965 grd_curcanv->cv_font = SELECTED_FONT;
2967 grd_curcanv->cv_font = NORMAL_FONT;
2968 gr_get_string_size(items[i], &w, &h, &aw );
2969 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2970 gr_string( wx+5, y, items[i] );
2974 if ( (i>=0) && (i<nitems) ) {
2975 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2977 grd_curcanv->cv_font = SELECTED_FONT;
2979 grd_curcanv->cv_font = NORMAL_FONT;
2980 gr_get_string_size( items[i], &w, &h, &aw );
2981 gr_rect( wx, y-1, wx+width-1, y+h );
2982 gr_string( wx+5, y, items[i] );
2985 newmenu_show_cursor();
2989 newmenu_hide_cursor();
2991 keyd_repeat = old_keyd_repeat;
2993 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2995 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2996 gr_free_bitmap(bg.background);
2999 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) );
3006 int newmenu_filelist( char * title, char * filespec, char * filename )
3009 char * Filenames[MAX_FILES];
3010 char FilenameText[MAX_FILES][14];
3011 FILEFINDSTRUCT find;
3014 if( !FileFindFirst( filespec, &find ) ) {
3016 if (NumFiles<MAX_FILES) {
3017 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3018 Filenames[NumFiles] = FilenameText[NumFiles];
3023 } while( !FileFindNext( &find ) );
3027 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3029 strcpy( filename, Filenames[i] );
3036 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3037 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3043 char nm_text[MESSAGEBOX_TEXT_SIZE];
3044 newmenu_item nm_message_items[5];
3046 va_start(args, nchoices );
3048 Assert( nchoices <= 5 );
3050 for (i=0; i<nchoices; i++ ) {
3051 s = va_arg( args, char * );
3052 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3054 format = va_arg( args, char * );
3055 //sprintf( nm_text, "" ); // adb: ?
3056 vsprintf(nm_text,format,args);
3059 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3061 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3063 //end this section addition - Victor Rachels
3066 extern netgame_info Active_games[];
3067 extern int NumActiveNetgames;
3069 void show_extra_netgame_info(int choice)
3075 if (choice>=NumActiveNetgames)
3080 m[i].text=(char *)&mtext[i];
3081 m[i].type=NM_TYPE_TEXT;
3084 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3085 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3086 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3087 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3089 already_showing_info=1;
3090 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3091 already_showing_info=0;
3096 /* Spiffy word wrap string formatting function */
3098 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3104 tbuf = (char *)d_malloc((unsigned int)strlen(sbuf) + 1);
3107 wordptr = strtok(tbuf, " ");
3108 if (!wordptr) return;
3114 col = col + (int)strlen(wordptr) + 1;
3115 if (col >=line_length) {
3117 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3120 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3122 wordptr = strtok(NULL, " ");