1 /* $Id: newmenu.c,v 1.33 2006-02-24 06:19:20 chris Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
30 #if !defined(_MSC_VER) && !defined(macintosh)
77 #define MAXDISPLAYABLEITEMS 15
79 #define LHX(x) ((x)*(MenuHires?2:1))
80 #define LHY(y) ((y)*(MenuHires?2.4:1))
82 #define TITLE_FONT HUGE_FONT
83 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
84 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
85 #define SUBTITLE_FONT MEDIUM3_FONT
87 #define NORMAL_CHECK_BOX "\x81" // 129
88 #define CHECKED_CHECK_BOX "\x82" // 130
90 #define NORMAL_RADIO_BOX "\x7f" // 127
91 #define CHECKED_RADIO_BOX "\x80" // 128
92 #define CURSOR_STRING "_"
93 #define SLIDER_LEFT "\x83" // 131
94 #define SLIDER_RIGHT "\x84" // 132
95 #define SLIDER_MIDDLE "\x85" // 133
96 #define SLIDER_MARKER "\x86" // 134
97 #define UP_ARROW_MARKER "\x87" // 135
98 #define DOWN_ARROW_MARKER "\x88" // 136
100 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 );
101 void show_extra_netgame_info(int choice);
104 int Newmenu_first_time = 1;
105 //--unused-- int Newmenu_fade_in = 1;
108 grs_canvas * menu_canvas;
109 grs_bitmap * saved; // The background under the menu.
110 grs_bitmap * background;
113 grs_bitmap nm_background,nm_background_save;
115 #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)
116 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
118 ubyte MenuReordering=0;
120 char Pauseable_menu=0;
121 char already_showing_info=0;
124 void newmenu_close() {
125 if ( nm_background.bm_data )
126 d_free(nm_background.bm_data);
128 if ( nm_background_save.bm_data )
129 d_free(nm_background_save.bm_data);
130 Newmenu_first_time = 1;
133 ubyte background_palette[768];
135 //should be called whenever the palette changes
136 void nm_remap_background()
138 if (!Newmenu_first_time) {
139 if (!nm_background.bm_data)
140 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
142 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
144 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
150 extern char last_palette_loaded[];
152 void nm_draw_background1(char * filename)
159 //@@//I think this only gets called to fill the whole screen
160 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
161 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
163 pcx_error = pcx_get_dimensions(filename, &width, &height);
164 if (pcx_error != PCX_ERROR_NONE)
165 Error("Could not open pcx file <%s>\n", filename);
167 bmp = gr_create_bitmap(width, height);
169 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
170 Assert(pcx_error == PCX_ERROR_NONE);
172 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
175 { //remap stuff. this code is kindof a hack
177 //now, before we bring up the menu, we need to
178 //do some stuff to make sure the palette is ok. First, we need to
179 //get our current palette into the 2d's array, so the remapping will
180 //work. Second, we need to remap the fonts. Third, we need to fill
181 //in part of the fade tables so the darkening of the menu edges works
183 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
185 gr_palette_load(gr_palette);
187 remap_fonts_and_menus(1);
195 strcpy(last_palette_loaded,""); //force palette load next time
199 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
200 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
202 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
204 int Background_hires;
207 void nm_draw_background(int x1, int y1, int x2, int y2 )
211 if (Newmenu_first_time || MenuHires!=Background_hires) {
214 if (Newmenu_first_time) {
215 atexit( newmenu_close );
216 Newmenu_first_time = 0;
217 nm_background_save.bm_data=NULL;
220 if (nm_background_save.bm_data)
221 d_free(nm_background_save.bm_data);
222 if (nm_background.bm_data)
223 d_free(nm_background.bm_data);
226 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
227 Assert(pcx_error == PCX_ERROR_NONE);
229 nm_background = nm_background_save;
230 nm_background.bm_data=NULL;
231 nm_remap_background();
233 Background_hires = MenuHires;
236 if ( x1 < 0 ) x1 = 0;
237 if ( y1 < 0 ) y1 = 0;
242 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
243 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
250 grs_bitmap *tmp = gr_create_bitmap(w, h);
252 gr_bitmap_scale_to(&nm_background, tmp);
255 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
257 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
262 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
264 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
268 Gr_scanline_darkening_level = 2*7;
270 gr_setcolor( BM_XRGB(0,0,0) );
271 gr_urect( x2-5, y1+5, x2-5, y2-5 );
272 gr_urect( x2-4, y1+4, x2-4, y2-5 );
273 gr_urect( x2-3, y1+3, x2-3, y2-5 );
274 gr_urect( x2-2, y1+2, x2-2, y2-5 );
275 gr_urect( x2-1, y1+1, x2-1, y2-5 );
276 gr_urect( x2+0, y1+0, x2-0, y2-5 );
278 gr_urect( x1+5, y2-5, x2, y2-5 );
279 gr_urect( x1+4, y2-4, x2, y2-4 );
280 gr_urect( x1+3, y2-3, x2, y2-3 );
281 gr_urect( x1+2, y2-2, x2, y2-2 );
282 gr_urect( x1+1, y2-1, x2, y2-1 );
283 gr_urect( x1+0, y2, x2, y2-0 );
286 Gr_scanline_darkening_level = GR_FADE_LEVELS;
289 void nm_restore_background( int x, int y, int w, int h )
296 if ( x1 < 0 ) x1 = 0;
297 if ( y1 < 0 ) y1 = 0;
299 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
300 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
305 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
308 // Draw a left justfied string
309 void nm_string( bkg * b, int w1,int x, int y, char * s)
311 int w,h,aw,tx=0,t=0,i;
312 char *p,*s1,*s2,measure[2];
313 int XTabs[]={15,87,124,162,228,253};
319 XTabs[i]=(LHX(XTabs[i]));
326 p = strchr( s2, '\t' );
333 gr_get_string_size(s2, &w, &h, &aw );
339 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
340 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
343 for (i=0;i<strlen(s2);i++) {
344 if (s2[i]=='\t' && SurfingNet) {
350 gr_get_string_size(measure,&tx,&h,&aw);
351 gr_string(x,y,measure);
358 if (!SurfingNet && p && (w1>0) ) {
359 gr_get_string_size(s1, &w, &h, &aw );
361 gr_string( x+w1-w, y, s1 );
368 // Draw a slider and it's string
369 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
376 p = strchr( s, '\t' );
382 gr_get_string_size(s, &w, &h, &aw );
385 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
386 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
388 gr_string( x, y, s );
391 gr_get_string_size(s1, &w, &h, &aw );
394 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
396 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
398 gr_string( x+w1-w, y, s1 );
405 // Draw a left justfied string with black background.
406 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
409 gr_get_string_size(s, &w, &h, &aw );
412 gr_setcolor( BM_XRGB(2,2,2) );
413 gr_rect( x-1, y-1, x-1, y+h-1 );
414 gr_rect( x-1, y-1, x+w1-1, y-1 );
417 gr_setcolor( BM_XRGB(5,5,5) );
418 gr_rect( x, y+h, x+w1, y+h);
419 gr_rect( x+w1, y-1, x+w1, y+h );
421 gr_setcolor( BM_XRGB(0,0,0) );
422 gr_rect( x, y, x+w1-1, y+h-1 );
424 gr_string( x+1, y+1, s );
428 // Draw a right justfied string
429 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
432 gr_get_string_size(s, &w, &h, &aw );
437 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
440 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
441 gr_string( x-w, y, s );
446 //for text items, constantly redraw cursor (to achieve flash)
447 void update_cursor( newmenu_item *item)
450 fix time = timer_get_approx_seconds();
452 char * text = item->text;
454 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
457 gr_get_string_size(text, &w, &h, &aw );
458 if ( w > item->w-10 )
465 x = item->x+w; y = item->y;
468 gr_string( x, y, CURSOR_STRING );
470 gr_setcolor( BM_XRGB(0,0,0) );
471 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
475 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
480 gr_get_string_size(text, &w1, &h1, &aw );
489 nm_string_black( b, w, x, y, text );
492 gr_string( x+w1+1, y, CURSOR_STRING );
496 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
501 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
503 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
505 if (item->text[0]=='\t')
506 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
511 grd_curcanv->cv_font = SELECTED_FONT;
513 grd_curcanv->cv_font = NORMAL_FONT;
516 if (is_current && item->type == NM_TYPE_TEXT)
517 grd_curcanv->cv_font = NORMAL_FONT;
521 switch( item->type ) {
523 // grd_curcanv->cv_font=TEXT_FONT;
524 // fall through on purpose
527 nm_string( b, item->w, item->x, item->y, item->text );
529 case NM_TYPE_SLIDER: {
531 if (item->value < item->min_value) item->value=item->min_value;
532 if (item->value > item->max_value) item->value=item->max_value;
533 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
534 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
535 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
537 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
539 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
541 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
544 case NM_TYPE_INPUT_MENU:
545 if ( item->group==0 ) {
546 nm_string( b, item->w, item->x, item->y, item->text );
548 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
552 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
555 nm_string( b, item->w, item->x, item->y, item->text );
557 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
559 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
562 nm_string( b, item->w, item->x, item->y, item->text );
564 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
566 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
568 case NM_TYPE_NUMBER: {
570 if (item->value < item->min_value) item->value=item->min_value;
571 if (item->value > item->max_value) item->value=item->max_value;
572 nm_string( b, item->w, item->x, item->y, item->text );
573 sprintf( text, "%d", item->value );
574 nm_rstring( b,item->right_offset,item->x, item->y, text );
580 char *Newmenu_allowed_chars=NULL;
582 //returns true if char is allowed
583 int char_allowed(char c)
585 char *p = Newmenu_allowed_chars;
593 if (c>=p[0] && c<=p[1])
602 void strip_end_whitespace( char * text )
606 for (i=l-1; i>=0; i-- ) {
607 if ( isspace(text[i]) )
614 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
616 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
618 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
620 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
624 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
626 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
630 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 )
632 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
636 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 )
638 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
640 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 )
642 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
645 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){
646 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
647 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
648 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
651 //returns 1 if a control device button has been pressed
652 int check_button_press()
656 switch (Config_control_type) {
657 case CONTROL_JOYSTICK:
658 case CONTROL_FLIGHTSTICK_PRO:
659 case CONTROL_THRUSTMASTER_FCS:
660 case CONTROL_GRAVIS_GAMEPAD:
662 if (joy_get_button_down_cnt(i)>0) return 1;
665 case CONTROL_CYBERMAN:
666 #ifndef NEWMENU_MOUSE // don't allow mouse to continue from menu
668 if (mouse_button_down_count(i)>0) return 1;
671 case CONTROL_WINJOYSTICK:
674 if (joy_get_button_down_cnt(i)>0) return 1;
677 case CONTROL_NONE: //keyboard only
679 if (key_checkch()) return 1;
684 Error("Bad control type (Config_control_type):%i",Config_control_type);
690 extern int network_request_player_names(int);
691 extern int RestoringMenu;
694 ubyte Hack_DblClick_MenuMode=0;
698 extern ubyte joydefs_calibrating;
700 # define joydefs_calibrating 0
703 #define CLOSE_X (MenuHires?15:7)
704 #define CLOSE_Y (MenuHires?15:7)
705 #define CLOSE_SIZE (MenuHires?10:5)
707 void draw_close_box(int x,int y)
709 gr_setcolor( BM_XRGB(0, 0, 0) );
710 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
711 gr_setcolor( BM_XRGB(21, 21, 21) );
712 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));
715 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 )
717 int old_keyd_repeat, done;
718 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
719 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
720 grs_font * save_font;
721 int string_width, string_height, average_width;
724 int all_text=0; //set true if all text items
725 int sound_stopped=0,time_stopped=0;
726 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
729 int MaxOnMenu=MAXDISPLAYABLEITEMS;
730 grs_canvas *save_canvas;
732 int mouse_state, omouse_state, dblclick_flag=0;
733 int mx=0, my=0, x1 = 0, x2, y1, y2;
737 EventRecord event; // looking for disk inserted events for CD mounts
740 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
741 newmenu_hide_cursor();
748 MaxDisplayable=nitems;
750 //set_screen_mode(SCREEN_MENU);
753 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
754 digi_pause_digi_sounds();
758 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
768 save_canvas = grd_curcanv;
770 gr_set_current_canvas(NULL);
772 save_font = grd_curcanv->cv_font;
777 grd_curcanv->cv_font = TITLE_FONT;
778 gr_get_string_size(title,&string_width,&string_height,&average_width );
783 grd_curcanv->cv_font = SUBTITLE_FONT;
784 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
785 if (string_width > tw )
790 th += LHY(8); //put some space between titles & body
793 grd_curcanv->cv_font = SMALL_FONT;
795 grd_curcanv->cv_font = NORMAL_FONT;
799 nmenus = nothers = 0;
801 // Find menu height & width (store in w,h)
802 for (i=0; i<nitems; i++ ) {
805 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
806 item[i].right_offset = 0;
809 string_height+=LHY(3);
811 item[i].saved_text[0] = '\0';
813 if ( item[i].type == NM_TYPE_SLIDER ) {
816 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
817 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
818 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
820 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
821 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
822 string_width += w1 + aw;
825 if ( item[i].type == NM_TYPE_MENU ) {
829 if ( item[i].type == NM_TYPE_CHECK ) {
832 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
833 item[i].right_offset = w1;
834 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
835 if (w1 > item[i].right_offset)
836 item[i].right_offset = w1;
839 if (item[i].type == NM_TYPE_RADIO ) {
842 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
843 item[i].right_offset = w1;
844 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
845 if (w1 > item[i].right_offset)
846 item[i].right_offset = w1;
849 if (item[i].type==NM_TYPE_NUMBER ) {
853 sprintf( test_text, "%d", item[i].max_value );
854 gr_get_string_size( test_text, &w1, &h1, &aw1 );
855 item[i].right_offset = w1;
856 sprintf( test_text, "%d", item[i].min_value );
857 gr_get_string_size( test_text, &w1, &h1, &aw1 );
858 if ( w1 > item[i].right_offset)
859 item[i].right_offset = w1;
862 if ( item[i].type == NM_TYPE_INPUT ) {
863 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
864 strcpy(item[i].saved_text, item[i].text );
866 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
867 if ( string_width > MAX_TEXT_WIDTH )
868 string_width = MAX_TEXT_WIDTH;
872 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
873 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
874 strcpy(item[i].saved_text, item[i].text );
876 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
881 item[i].w = string_width;
882 item[i].h = string_height;
884 if ( string_width > w )
885 w = string_width; // Save maximum width
886 if ( average_width > aw )
888 h += string_height+1; // Find the height of all strings
891 // Big hack for allowing the netgame options menu to spill over
893 MaxOnMenu=MAXDISPLAYABLEITEMS;
894 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
897 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
900 h=(MaxOnMenu*(string_height+1)+LHY(8));
901 MaxDisplayable=MaxOnMenu;
902 mprintf ((0,"Hey, this is a scroll box!\n"));
915 for (i=0; i<nitems; i++ ) {
917 if (item[i].right_offset > right_offset )
918 right_offset = item[i].right_offset;
920 if (right_offset > 0 )
923 //gr_get_string_size("",&string_width,&string_height,&average_width );
930 twidth = ( tw - w )/2;
935 { right_offset=0; twidth=0;}
937 mprintf(( 0, "Right offset = %d\n", right_offset ));
940 // Find min point of menu border
941 // x = (grd_curscreen->sc_w-w)/2;
942 // y = (grd_curscreen->sc_h-h)/2;
944 w += MenuHires?60:30;
945 h += MenuHires?60:30;
947 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
948 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
950 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
951 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
956 if ( filename != NULL ) {
957 nm_draw_background1( filename );
958 gr_palette_load(gr_palette);
961 // Save the background of the display
962 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h );
963 gr_set_current_canvas(bg.menu_canvas);
965 if ( filename == NULL ) {
966 // Save the background under the menu...
972 bg.saved = gr_create_bitmap( w, h );
973 Assert( bg.saved != NULL );
975 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
977 gr_set_current_canvas( NULL );
979 nm_draw_background(x,y,x+w-1,y+h-1);
981 gr_set_current_canvas( bg.menu_canvas );
983 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
987 bg.background = gr_create_bitmap( w, h );
988 Assert( bg.background != NULL );
990 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
993 // ty = 15 + (yborder/4);
995 ty = MenuHires?30:15;
998 grd_curcanv->cv_font = TITLE_FONT;
999 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1000 gr_get_string_size(title,&string_width,&string_height,&average_width );
1003 gr_printf( 0x8000, ty, title );
1008 grd_curcanv->cv_font = SUBTITLE_FONT;
1009 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1010 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1013 gr_printf( 0x8000, ty, subtitle );
1018 grd_curcanv->cv_font = SMALL_FONT;
1020 grd_curcanv->cv_font = NORMAL_FONT;
1022 // Update all item's x & y values.
1023 for (i=0; i<nitems; i++ ) {
1024 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1025 item[i].y += (MenuHires?30:15);
1026 if ( item[i].type==NM_TYPE_RADIO ) {
1027 fm = -1; // find first marked one
1028 for ( j=0; j<nitems; j++ ) {
1029 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1030 if (fm==-1 && item[j].value)
1042 old_keyd_repeat = keyd_repeat;
1048 if (citem < 0 ) citem = 0;
1049 if (citem > nitems-1 ) citem = nitems-1;
1052 #ifdef NEWMENU_MOUSE
1056 while ( item[choice].type==NM_TYPE_TEXT ) {
1058 if (choice >= nitems ) {
1061 if (choice == citem ) {
1072 // Clear mouse, joystick to clear button presses.
1073 game_flush_inputs();
1075 #ifdef NEWMENU_MOUSE
1076 mouse_state = omouse_state = 0;
1077 if (filename == NULL && !MenuReordering) {
1078 //draw_close_box(0,0);
1082 if (!MenuReordering && !joydefs_calibrating)
1084 newmenu_show_cursor();
1086 SetCursor(LoadCursor(NULL,IDC_ARROW));
1091 mprintf ((0,"Set to true!\n"));
1094 #ifdef NEWMENU_MOUSE
1095 if (!joydefs_calibrating)
1096 newmenu_show_cursor(); // possibly hidden
1097 omouse_state = mouse_state;
1098 if (!MenuReordering)
1099 mouse_state = mouse_button_state(0);
1100 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1103 //see if redbook song needs to be restarted
1104 songs_check_redbook_repeat();
1111 (*subfunction)(nitems,item,&k,choice);
1114 if (!time_stopped) {
1115 // Save current menu box
1116 if (multi_menu_poll() == -1)
1122 dont_restore = (k == -3); //-3 means don't restore
1127 if (check_button_press())
1130 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1133 old_choice = choice;
1139 if (SurfingNet && !already_showing_info)
1141 show_extra_netgame_info(choice-2);
1143 if (SurfingNet && already_showing_info)
1150 if (SurfingNet && !already_showing_info)
1152 network_request_player_names(choice-2);
1154 if (SurfingNet && already_showing_info)
1169 case KEY_TAB + KEY_SHIFTED:
1172 if (all_text) break;
1179 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1181 if (choice<TopChoice)
1182 { choice=TopChoice; break; }
1184 if (choice<ScrollOffset)
1186 for (i=0;i<nitems;i++)
1189 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1194 if (choice >= nitems ) choice=0;
1195 if (choice < 0 ) choice=nitems-1;
1197 } while ( item[choice].type==NM_TYPE_TEXT );
1198 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1199 item[choice].value = -1;
1200 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1201 item[old_choice].group=0;
1202 strcpy(item[old_choice].text, item[old_choice].saved_text );
1203 item[old_choice].value = -1;
1206 item[old_choice].redraw = 1;
1207 item[choice].redraw=1;
1212 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1213 if (all_text) break;
1220 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1223 { choice--; break; }
1225 if (choice>=MaxOnMenu+ScrollOffset)
1227 for (i=0;i<nitems;i++)
1230 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1235 if (choice < 0 ) choice=nitems-1;
1236 if (choice >= nitems ) choice=0;
1239 } while ( item[choice].type==NM_TYPE_TEXT );
1241 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1242 item[choice].value = -1;
1243 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1244 item[old_choice].group=0;
1245 strcpy(item[old_choice].text, item[old_choice].saved_text );
1246 item[old_choice].value = -1;
1249 item[old_choice].redraw=1;
1250 item[choice].redraw=1;
1253 if ( choice > -1 ) {
1254 switch( item[choice].type ) {
1257 case NM_TYPE_INPUT_MENU:
1260 if ( item[choice].value )
1261 item[choice].value = 0;
1263 item[choice].value = 1;
1264 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1267 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1269 mprintf ((0,"Special redraw!\n"));
1274 item[choice].redraw=1;
1277 for (i=0; i<nitems; i++ ) {
1278 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1283 item[choice].value = 1;
1284 item[choice].redraw = 1;
1290 case KEY_SHIFTED+KEY_UP:
1291 if (MenuReordering && choice!=TopChoice)
1293 Temp=item[choice].text;
1294 TempVal=item[choice].value;
1295 item[choice].text=item[choice-1].text;
1296 item[choice].value=item[choice-1].value;
1297 item[choice-1].text=Temp;
1298 item[choice-1].value=TempVal;
1299 item[choice].redraw=1;
1300 item[choice-1].redraw=1;
1304 case KEY_SHIFTED+KEY_DOWN:
1305 if (MenuReordering && choice!=(nitems-1))
1307 Temp=item[choice].text;
1308 TempVal=item[choice].value;
1309 item[choice].text=item[choice+1].text;
1310 item[choice].value=item[choice+1].value;
1311 item[choice+1].text=Temp;
1312 item[choice+1].value=TempVal;
1313 item[choice].redraw=1;
1314 item[choice+1].redraw=1;
1321 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1322 item[choice].group = 1;
1323 item[choice].redraw = 1;
1324 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1325 item[choice].text[0] = 0;
1326 item[choice].value = -1;
1328 strip_end_whitespace(item[choice].text);
1335 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1336 item[choice].group=0;
1337 strcpy(item[choice].text, item[choice].saved_text );
1338 item[choice].redraw=1;
1339 item[choice].value = -1;
1346 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
1347 case KEY_PRINT_SCREEN:
1348 MAC(newmenu_hide_cursor());
1349 save_screen_shot(0);
1350 for (i=0;i<nitems;i++)
1353 MAC(newmenu_show_cursor());
1359 case KEY_COMMAND+KEY_RIGHT:
1360 songs_goto_next_song();
1362 case KEY_COMMAND+KEY_LEFT:
1363 songs_goto_prev_song();
1365 case KEY_COMMAND+KEY_UP:
1366 songs_play_level_song(1);
1368 case KEY_COMMAND+KEY_DOWN:
1369 songs_stop_redbook();
1372 case KEY_COMMAND+KEY_M:
1374 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1377 key_close(); // no processing of keys with keyboard handler.. jeez
1379 newmenu_hide_cursor();
1380 show_boxed_message ("Mounting CD\nESC to quit");
1381 RBAMountDisk(); // OS has totaly control of the CD.
1382 if (Function_mode == FMODE_MENU)
1383 songs_play_song(SONG_TITLE,1);
1384 else if (Function_mode == FMODE_GAME)
1385 songs_play_level_song( Current_level_num );
1386 clear_boxed_message();
1387 newmenu_show_cursor();
1394 case KEY_COMMAND+KEY_E:
1395 songs_stop_redbook();
1397 k = -1; // force key not to register
1401 case KEY_COMMAND+KEY_Q: {
1402 if ( !(Game_mode & GM_MULTI) )
1404 if (!joydefs_calibrating)
1405 newmenu_show_cursor();
1406 k = -1; // force key not to register
1412 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1419 #ifdef NEWMENU_MOUSE // for mouse selection of menu's etc.
1420 if ( !done && mouse_state && !omouse_state && !all_text ) {
1421 mouse_get_pos(&mx, &my);
1422 for (i=0; i<nitems; i++ ) {
1423 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1424 x2 = x1 + item[i].w;
1425 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1426 y2 = y1 + item[i].h;
1427 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1428 if (i+ScrollOffset != choice) {
1429 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1432 choice = i + ScrollOffset;
1434 switch( item[choice].type ) {
1436 if ( item[choice].value )
1437 item[choice].value = 0;
1439 item[choice].value = 1;
1440 item[choice].redraw=1;
1447 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1449 mprintf ((0,"Special redraw!\n"));
1456 for (i=0; i<nitems; i++ ) {
1457 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1462 item[choice].value = 1;
1463 item[choice].redraw = 1;
1466 item[old_choice].redraw=1;
1472 if (mouse_state && all_text)
1475 if ( !done && mouse_state && !all_text ) {
1476 mouse_get_pos(&mx, &my);
1478 // check possible scrollbar stuff first
1480 int arrow_width, arrow_height, aw;
1482 if (ScrollOffset != 0) {
1483 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1484 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1485 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1486 x1 = x1 - arrow_width;
1487 y2 = y1 + arrow_height;
1488 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1491 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1493 if (choice<ScrollOffset)
1495 for (i=0;i<nitems;i++)
1498 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1502 if (ScrollOffset+MaxDisplayable<nitems) {
1503 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1504 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1505 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1506 x1 = x1 - arrow_width;
1507 y2 = y1 + arrow_height;
1508 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1511 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1513 if (choice>=MaxOnMenu+ScrollOffset)
1515 for (i=0;i<nitems;i++)
1518 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1524 for (i=0; i<nitems; i++ ) {
1525 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1526 x2 = x1 + item[i].w;
1527 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1528 y2 = y1 + item[i].h;
1529 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1530 if (i+ScrollOffset != choice) {
1531 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1534 choice = i + ScrollOffset;
1536 if ( item[choice].type == NM_TYPE_SLIDER ) {
1537 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1538 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1540 strcpy(slider_text, item[choice].saved_text);
1541 p = strchr(slider_text, '\t');
1547 gr_get_string_size(s1, &slider_width, &height, &aw);
1548 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1549 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1550 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1552 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1553 x2 = x1 + slider_width + sright_width;
1554 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1555 item[choice].value = item[choice].min_value;
1556 item[choice].redraw = 2;
1557 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1558 item[choice].value = item[choice].max_value;
1559 item[choice].redraw = 2;
1560 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1561 int num_values, value_width, new_value;
1563 num_values = item[choice].max_value - item[choice].min_value + 1;
1564 value_width = (slider_width - sleft_width - sright_width) / num_values;
1565 new_value = (mx - x1 - sleft_width) / value_width;
1566 if ( item[choice].value != new_value ) {
1567 item[choice].value = new_value;
1568 item[choice].redraw = 2;
1574 if (choice == old_choice)
1576 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1577 item[choice].value = -1;
1578 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1579 item[old_choice].group=0;
1580 strcpy(item[old_choice].text, item[old_choice].saved_text );
1581 item[old_choice].value = -1;
1584 item[old_choice].redraw = 1;
1585 item[choice].redraw=1;
1591 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1592 mouse_get_pos(&mx, &my);
1593 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1594 x2 = x1 + item[choice].w;
1595 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1596 y2 = y1 + item[choice].h;
1597 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1598 if (Hack_DblClick_MenuMode) {
1599 if (dblclick_flag) done = 1;
1600 else dblclick_flag = 1;
1606 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1607 item[choice].group = 1;
1608 item[choice].redraw = 1;
1609 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1610 item[choice].text[0] = 0;
1611 item[choice].value = -1;
1613 strip_end_whitespace(item[choice].text);
1617 if ( !done && !mouse_state && omouse_state && close_box ) {
1618 mouse_get_pos(&mx, &my);
1619 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1620 x2 = x1 + CLOSE_SIZE;
1621 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1622 y2 = y1 + CLOSE_SIZE;
1623 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1629 // HACK! Don't redraw loadgame preview
1630 if (RestoringMenu) item[0].redraw = 0;
1631 #endif // NEWMENU_MOUSE
1633 if ( choice > -1 ) {
1636 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1637 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1638 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1639 if (item[choice].value > 0)
1640 item[choice].value--;
1641 item[choice].text[item[choice].value] = 0;
1642 item[choice].redraw = 1;
1644 ascii = key_to_ascii(k);
1645 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1649 if (item[choice].value==-1) {
1650 item[choice].value = 0;
1653 allowed = char_allowed(ascii);
1655 if (!allowed && ascii==' ' && char_allowed('_')) {
1661 item[choice].text[item[choice].value++] = ascii;
1662 item[choice].text[item[choice].value] = 0;
1663 item[choice].redraw=1;
1667 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1668 ascii = key_to_ascii(k);
1670 int choice1 = choice;
1671 ascii = toupper(ascii);
1675 if (choice1 >= nitems ) choice1=0;
1676 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1677 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1678 (item[choice1].type==NM_TYPE_CHECK) ||
1679 (item[choice1].type==NM_TYPE_RADIO) ||
1680 (item[choice1].type==NM_TYPE_NUMBER) ||
1681 (item[choice1].type==NM_TYPE_SLIDER) )
1682 && (ascii==toupper(ch)) ) {
1686 item[old_choice].redraw=1;
1687 item[choice].redraw=1;
1689 } while (choice1 != choice );
1693 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1694 int ov=item[choice].value;
1699 case KEY_MINUS+KEY_SHIFTED:
1701 item[choice].value -= 1;
1706 case KEY_EQUAL+KEY_SHIFTED:
1708 item[choice].value++;
1713 item[choice].value += 10;
1718 item[choice].value -= 10;
1721 if (ov!=item[choice].value)
1722 item[choice].redraw=1;
1727 gr_set_current_canvas(bg.menu_canvas);
1729 // Redraw everything...
1730 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1732 if (item[i].redraw) // warning! ugly hack below
1734 item[i].y-=((string_height+1)*ScrollOffset);
1735 newmenu_hide_cursor();
1736 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1738 #ifdef NEWMENU_MOUSE
1739 if (!MenuReordering && !joydefs_calibrating)
1740 newmenu_show_cursor();
1742 item[i].y+=((string_height+1)*ScrollOffset);
1744 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1745 update_cursor( &item[i]);
1751 //grd_curcanv->cv_font = NORMAL_FONT;
1753 if (LastScrollCheck!=ScrollOffset)
1755 LastScrollCheck=ScrollOffset;
1756 grd_curcanv->cv_font = SELECTED_FONT;
1758 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1759 sx=item[ScrollOffset].x-(MenuHires?24:12);
1762 if (ScrollOffset!=0)
1763 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1765 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1767 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1768 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1770 if (ScrollOffset+MaxDisplayable<nitems)
1771 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1773 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1779 if ( !dont_restore && gr_palette_faded_out ) {
1780 gr_palette_fade_in( gr_palette, 32, 0 );
1784 newmenu_hide_cursor();
1786 // Restore everything...
1788 gr_set_current_canvas(bg.menu_canvas);
1790 if ( filename == NULL ) {
1791 // Save the background under the menu...
1792 gr_bitmap(0, 0, bg.saved);
1793 gr_free_bitmap(bg.saved);
1794 d_free( bg.background );
1796 if (!dont_restore) //info passed back from subfunction
1797 gr_bitmap(0, 0, bg.background);
1798 gr_free_bitmap(bg.background);
1801 gr_free_sub_canvas( bg.menu_canvas );
1803 gr_set_current_canvas(save_canvas);
1804 grd_curcanv->cv_font = save_font;
1805 keyd_repeat = old_keyd_repeat;
1807 game_flush_inputs();
1818 if ( sound_stopped )
1819 digi_resume_digi_sounds();
1826 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1832 char nm_text[MESSAGEBOX_TEXT_SIZE];
1833 newmenu_item nm_message_items[5];
1835 va_start(args, nchoices );
1837 Assert( nchoices <= 5 );
1839 for (i=0; i<nchoices; i++ ) {
1840 s = va_arg( args, char * );
1841 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1843 format = va_arg( args, char * );
1844 strcpy( nm_text, "" );
1845 vsprintf(nm_text,format,args);
1848 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1850 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1853 int nm_messagebox( char *title, int nchoices, ... )
1859 char nm_text[MESSAGEBOX_TEXT_SIZE];
1860 newmenu_item nm_message_items[5];
1862 va_start(args, nchoices );
1864 Assert( nchoices <= 5 );
1866 for (i=0; i<nchoices; i++ ) {
1867 s = va_arg( args, char * );
1868 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1870 format = va_arg( args, char * );
1871 strcpy( nm_text, "" );
1872 vsprintf(nm_text,format,args);
1875 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1877 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1883 void newmenu_file_sort( int n, char *list )
1890 for (i=incr; i<n; i++ ) {
1893 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1894 memcpy( t, &list[j*14], FILENAME_LEN );
1895 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1896 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1907 void delete_player_saved_games(char * name)
1912 for (i=0;i<10; i++) {
1913 sprintf( filename, PLAYER_DIR "%s.sg%d", name, i );
1914 PHYSFS_delete(filename);
1918 #define MAX_FILES 300
1920 //FIXME: should maybe put globbing ability back?
1921 int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
1927 int NumFiles=0, key,done, citem, ocitem;
1928 char * filenames = NULL;
1929 int NumFiles_displayed = 8;
1930 int first_item = -1, ofirst_item;
1931 int old_keyd_repeat = keyd_repeat;
1934 int demos_deleted=0;
1935 int initialized = 0;
1937 int w_x, w_y, w_w, w_h, title_height;
1938 int box_x, box_y, box_w, box_h;
1939 bkg bg; // background under listbox
1940 #ifdef NEWMENU_MOUSE
1941 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
1942 int mouse2_state, omouse2_state;
1943 int dblclick_flag=0;
1946 int show_up_arrow=0, show_down_arrow=0;
1950 w_x=w_y=w_w=w_h=title_height=0;
1951 box_x=box_y=box_w=box_h=0;
1953 filenames = d_malloc( MAX_FILES * 14 );
1954 if (filenames==NULL) return 0;
1959 if (!stricmp(type, "plr"))
1961 else if (!stricmp(type, "dem"))
1968 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
1970 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
1975 find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
1976 for (f = find; *f != NULL; f++)
1980 ext = strrchr(*f, '.');
1981 if (!ext || strnicmp(ext, ".plr", 4))
1984 if (NumFiles < MAX_FILES)
1986 strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
1991 p = strchr(&filenames[NumFiles*14], '.');
2001 PHYSFS_freeList(find);
2003 if ( (NumFiles < 1) && demos_deleted ) {
2007 if ( (NumFiles < 1) && demo_mode ) {
2008 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2014 if ( (NumFiles < 2) && player_mode ) {
2016 goto ExitFileMenuEarly;
2023 nm_messagebox(NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND);
2030 // set_screen_mode(SCREEN_MENU);
2033 gr_set_current_canvas(NULL);
2035 grd_curcanv->cv_font = SUBTITLE_FONT;
2040 for (i=0; i<NumFiles; i++ ) {
2042 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2048 gr_get_string_size( title, &w, &h, &aw );
2051 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2055 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2057 w_w += (grd_curfont->ft_w * 4);
2058 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2060 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2061 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2063 w_x = (grd_curcanv->cv_w-w_w)/2;
2064 w_y = (grd_curcanv->cv_h-w_h)/2;
2066 if ( w_x < 0 ) w_x = 0;
2067 if ( w_y < 0 ) w_y = 0;
2069 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2070 box_y = w_y + title_height;
2072 // save the screen behind the menu.
2076 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2077 bg.background = &VR_offscreen_buffer->cv_bitmap;
2079 bg.background = gr_create_bitmap( w_w, w_h );
2081 Assert( bg.background != NULL );
2084 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2087 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2090 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2092 gr_string( 0x8000, w_y+10, title );
2097 if ( !player_mode ) {
2098 newmenu_file_sort( NumFiles, filenames );
2100 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2101 newmenu_file_sort( NumFiles, filenames );
2103 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2105 for ( i=0; i<NumFiles; i++ ) {
2106 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2107 #ifdef NEWMENU_MOUSE
2115 #ifdef NEWMENU_MOUSE
2116 mouse_state = omouse_state = 0;
2117 mouse2_state = omouse2_state = 0;
2118 //draw_close_box(w_x,w_y);
2119 newmenu_show_cursor();
2124 ofirst_item = first_item;
2127 #ifdef NEWMENU_MOUSE
2128 omouse_state = mouse_state;
2129 omouse2_state = mouse2_state;
2130 mouse_state = mouse_button_state(0);
2131 mouse2_state = mouse_button_state(1);
2134 //see if redbook song needs to be restarted
2135 songs_check_redbook_repeat();
2140 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2141 case KEY_PRINT_SCREEN:
2142 MAC(newmenu_hide_cursor());
2143 save_screen_shot(0);
2145 MAC(newmenu_show_cursor());
2149 case KEY_CTRLED+KEY_D:
2150 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2154 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2156 newmenu_hide_cursor();
2158 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2160 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2161 newmenu_show_cursor();
2165 char name[PATH_MAX];
2167 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2171 strcpy(name, demo_mode?DEMO_DIR:"");
2172 strcat(name,&filenames[citem*14]);
2179 if ( !strncmp(name, ".\\", 2) )
2180 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2181 name[i] = name[i+1];
2182 while ( (p = strchr(name, '\\')) )
2187 ret = !PHYSFS_delete(name);
2191 if ((!ret) && player_mode) {
2192 delete_player_saved_games( &filenames[citem*14] );
2197 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2199 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2200 } else if (demo_mode)
2225 citem += NumFiles_displayed;
2229 citem -= NumFiles_displayed;
2232 if (allow_abort_flag) {
2242 case KEY_COMMAND+KEY_Q: {
2243 if ( !(Game_mode & GM_MULTI) )
2248 newmenu_show_cursor();
2256 int ascii = key_to_ascii(key);
2257 if ( ascii < 255 ) {
2260 if (cc1 < 0 ) cc1 = 0;
2261 if (cc1 >= NumFiles ) cc1 = 0;
2263 if ( cc < 0 ) cc = 0;
2264 if ( cc >= NumFiles ) cc = 0;
2265 if ( citem == cc ) break;
2267 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2282 if (citem>=NumFiles)
2285 if (citem< first_item)
2288 if (citem>=( first_item+NumFiles_displayed))
2290 first_item = citem-NumFiles_displayed+1;
2294 if (NumFiles>first_item+NumFiles_displayed)
2305 if (NumFiles <= NumFiles_displayed )
2308 if (first_item>NumFiles-NumFiles_displayed)
2310 first_item = NumFiles-NumFiles_displayed;
2313 if (first_item < 0 ) first_item = 0;
2315 #ifdef NEWMENU_MOUSE
2316 if (mouse_state || mouse2_state) {
2319 mouse_get_pos(&mx, &my);
2320 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2321 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2323 x2 = box_x + box_w - 1;
2324 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2326 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2327 if (i == citem && !mouse2_state) {
2337 if (!mouse_state && omouse_state) {
2340 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2341 mouse_get_pos(&mx, &my);
2343 x2 = box_x + box_w - 1;
2344 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2346 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2347 if (dblclick_flag) done = 1;
2348 else dblclick_flag = 1;
2352 if ( !mouse_state && omouse_state ) {
2353 mouse_get_pos(&mx, &my);
2354 x1 = w_x + CLOSE_X + 2;
2355 x2 = x1 + CLOSE_SIZE - 2;
2356 y1 = w_y + CLOSE_Y + 2;
2357 y2 = y1 + CLOSE_SIZE - 2;
2358 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2367 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2369 y1 = box_y+box_h-LHY(7);
2371 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2378 gr_setcolor( BM_XRGB(2,2,2));
2379 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2380 gr_setcolor( BM_XRGB( 0,0,0) );
2382 if (ofirst_item != first_item) {
2383 newmenu_hide_cursor();
2384 gr_setcolor( BM_XRGB( 0,0,0) );
2385 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2387 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2389 if ( i >= NumFiles ) {
2391 gr_setcolor( BM_XRGB(5,5,5));
2392 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2393 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2395 gr_setcolor( BM_XRGB(2,2,2));
2396 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2398 gr_setcolor( BM_XRGB(0,0,0));
2399 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2403 grd_curcanv->cv_font = SELECTED_FONT;
2405 grd_curcanv->cv_font = NORMAL_FONT;
2406 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2408 gr_setcolor( BM_XRGB(5,5,5));
2409 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2410 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2412 gr_setcolor( BM_XRGB(2,2,2));
2413 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2414 gr_setcolor( BM_XRGB(0,0,0));
2416 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2417 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2420 newmenu_show_cursor();
2421 } else if ( citem != ocitem ) {
2424 newmenu_hide_cursor();
2426 if ( (i>=0) && (i<NumFiles) ) {
2427 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2429 grd_curcanv->cv_font = SELECTED_FONT;
2431 grd_curcanv->cv_font = NORMAL_FONT;
2432 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2433 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2434 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2437 if ( (i>=0) && (i<NumFiles) ) {
2438 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2440 grd_curcanv->cv_font = SELECTED_FONT;
2442 grd_curcanv->cv_font = NORMAL_FONT;
2443 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2444 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2445 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2447 newmenu_show_cursor();
2451 grd_curcanv->cv_font = NORMAL_FONT;
2453 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2457 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2461 if (show_down_arrow)
2462 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2466 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2474 MAC(newmenu_hide_cursor());
2476 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2483 keyd_repeat = old_keyd_repeat;
2485 if ( initialized ) {
2486 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2487 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2488 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2489 gr_free_bitmap(bg.background);
2491 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2503 // Example listbox callback function...
2504 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2508 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2509 // if ( *nitems > 1 ) {
2510 // PHYSFS_delete(items[*citem]); // Delete the file
2511 // for (i=*citem; i<*nitems-1; i++ ) {
2512 // items[i] = items[i+1];
2514 // *nitems = *nitems - 1;
2515 // d_free( items[*nitems] );
2516 // items[*nitems] = NULL;
2517 // return 1; // redraw;
2524 #define LB_ITEMS_ON_SCREEN 8
2526 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2528 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2531 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 ) )
2534 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2535 int old_keyd_repeat = keyd_repeat;
2536 int width, height, wx, wy, title_height, border_size;
2537 int total_width,total_height;
2539 #ifdef NEWMENU_MOUSE
2540 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2541 int close_x,close_y;
2543 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2549 // set_screen_mode(SCREEN_MENU);
2552 gr_set_current_canvas(NULL);
2554 grd_curcanv->cv_font = SUBTITLE_FONT;
2557 for (i=0; i<nitems; i++ ) {
2559 gr_get_string_size( items[i], &w, &h, &aw );
2563 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2567 gr_get_string_size( title, &w, &h, &aw );
2570 title_height = h + 5;
2573 border_size = grd_curfont->ft_w;
2574 WIN (border_size=grd_curfont->ft_w*2);
2576 width += (grd_curfont->ft_w);
2577 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2578 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2580 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2581 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2582 if ( wy < title_height )
2585 total_width = width+2*border_size;
2586 total_height = height+2*border_size+title_height;
2590 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2591 bg.background = &VR_offscreen_buffer->cv_bitmap;
2593 //bg.background = gr_create_bitmap( width, (height + title_height) );
2594 bg.background = gr_create_bitmap(total_width,total_height);
2595 Assert( bg.background != NULL );
2597 //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 );
2598 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2601 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) );
2604 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2606 gr_string( 0x8000, wy - title_height, title );
2609 citem = default_item;
2610 if ( citem < 0 ) citem = 0;
2611 if ( citem >= nitems ) citem = 0;
2615 #ifdef NEWMENU_MOUSE
2616 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2617 close_x = wx-border_size;
2618 close_y = wy-title_height-border_size;
2619 //draw_close_box(close_x,close_y);
2620 newmenu_show_cursor();
2625 ofirst_item = first_item;
2626 #ifdef NEWMENU_MOUSE
2627 omouse_state = mouse_state;
2628 mouse_state = mouse_button_state(0);
2630 //see if redbook song needs to be restarted
2631 songs_check_redbook_repeat();
2635 if ( listbox_callback )
2636 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2650 else if (simukey==1)
2656 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
2657 case KEY_PRINT_SCREEN:
2658 MAC(newmenu_hide_cursor());
2659 save_screen_shot(0);
2661 MAC(newmenu_show_cursor());
2682 citem += LB_ITEMS_ON_SCREEN;
2686 citem -= LB_ITEMS_ON_SCREEN;
2689 if (allow_abort_flag) {
2699 case KEY_COMMAND+KEY_Q: {
2700 if ( !(Game_mode & GM_MULTI) )
2702 newmenu_show_cursor();
2709 int ascii = key_to_ascii(key);
2710 if ( ascii < 255 ) {
2713 if (cc1 < 0 ) cc1 = 0;
2714 if (cc1 >= nitems ) cc1 = 0;
2716 if ( cc < 0 ) cc = 0;
2717 if ( cc >= nitems ) cc = 0;
2718 if ( citem == cc ) break;
2720 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2737 if (citem< first_item)
2740 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2741 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2743 if (nitems <= LB_ITEMS_ON_SCREEN )
2746 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
2747 first_item = nitems-LB_ITEMS_ON_SCREEN;
2748 if (first_item < 0 ) first_item = 0;
2751 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
2762 #ifdef NEWMENU_MOUSE
2766 mouse_get_pos(&mx, &my);
2767 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2770 gr_get_string_size(items[i], &w, &h, &aw );
2773 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2775 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2787 //no double-click stuff for listbox
2788 //@@if (!mouse_state && omouse_state) {
2791 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
2792 //@@ mouse_get_pos(&mx, &my);
2794 //@@ x2 = wx + width;
2795 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
2797 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2798 //@@ if (dblclick_flag) done = 1;
2802 //check for close box clicked
2803 if ( !mouse_state && omouse_state ) {
2804 mouse_get_pos(&mx, &my);
2805 x1 = close_x + CLOSE_X + 2;
2806 x2 = x1 + CLOSE_SIZE - 2;
2807 y1 = close_y + CLOSE_Y + 2;
2808 y2 = y1 + CLOSE_SIZE - 2;
2809 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2819 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
2821 y1 = total_height-LHY(7);
2823 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
2831 if ( (ofirst_item != first_item) || redraw) {
2832 newmenu_hide_cursor();
2834 gr_setcolor( BM_XRGB( 0,0,0) );
2835 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
2837 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2838 if ( i >= nitems ) {
2839 gr_setcolor( BM_XRGB(0,0,0));
2840 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
2843 grd_curcanv->cv_font = SELECTED_FONT;
2845 grd_curcanv->cv_font = NORMAL_FONT;
2846 gr_get_string_size(items[i], &w, &h, &aw );
2847 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2848 gr_string( wx+5, y, items[i] );
2853 // If Win95 port, draw up/down arrows on left side of menu
2855 grd_curcanv->cv_font = NORMAL_FONT;
2857 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
2861 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
2865 if (show_down_arrow)
2866 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
2870 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
2877 newmenu_show_cursor();
2879 } else if ( citem != ocitem ) {
2882 newmenu_hide_cursor();
2885 if ( (i>=0) && (i<nitems) ) {
2886 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2888 grd_curcanv->cv_font = SELECTED_FONT;
2890 grd_curcanv->cv_font = NORMAL_FONT;
2891 gr_get_string_size(items[i], &w, &h, &aw );
2892 gr_rect( wx, y-1, wx+width-1, y+h+1 );
2893 gr_string( wx+5, y, items[i] );
2897 if ( (i>=0) && (i<nitems) ) {
2898 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
2900 grd_curcanv->cv_font = SELECTED_FONT;
2902 grd_curcanv->cv_font = NORMAL_FONT;
2903 gr_get_string_size( items[i], &w, &h, &aw );
2904 gr_rect( wx, y-1, wx+width-1, y+h );
2905 gr_string( wx+5, y, items[i] );
2908 newmenu_show_cursor();
2912 newmenu_hide_cursor();
2914 keyd_repeat = old_keyd_repeat;
2916 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2918 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2919 gr_free_bitmap(bg.background);
2922 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) );
2929 int newmenu_filelist( char * title, char * filespec, char * filename )
2932 char * Filenames[MAX_FILES];
2933 char FilenameText[MAX_FILES][14];
2934 FILEFINDSTRUCT find;
2937 if( !FileFindFirst( filespec, &find ) ) {
2939 if (NumFiles<MAX_FILES) {
2940 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
2941 Filenames[NumFiles] = FilenameText[NumFiles];
2946 } while( !FileFindNext( &find ) );
2950 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
2952 strcpy( filename, Filenames[i] );
2959 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
2960 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
2966 char nm_text[MESSAGEBOX_TEXT_SIZE];
2967 newmenu_item nm_message_items[5];
2969 va_start(args, nchoices );
2971 Assert( nchoices <= 5 );
2973 for (i=0; i<nchoices; i++ ) {
2974 s = va_arg( args, char * );
2975 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
2977 format = va_arg( args, char * );
2978 //sprintf( nm_text, "" ); // adb: ?
2979 vsprintf(nm_text,format,args);
2982 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
2984 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
2986 //end this section addition - Victor Rachels
2989 extern netgame_info Active_games[];
2990 extern int NumActiveNetgames;
2992 void show_extra_netgame_info(int choice)
2998 if (choice>=NumActiveNetgames)
3003 m[i].text=(char *)&mtext[i];
3004 m[i].type=NM_TYPE_TEXT;
3007 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3008 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3009 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3010 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3012 already_showing_info=1;
3013 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3014 already_showing_info=0;
3019 /* Spiffy word wrap string formatting function */
3021 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3027 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3030 wordptr = strtok(tbuf, " ");
3031 if (!wordptr) return;
3037 col = col+strlen(wordptr)+1;
3038 if (col >=line_length) {
3040 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3043 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3045 wordptr = strtok(NULL, " ");