1 /* $Id: newmenu.c,v 1.31 2005-07-30 01:50:17 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.
34 #if !defined(_MSC_VER) && !defined(macintosh)
81 #define MAXDISPLAYABLEITEMS 15
83 #define LHX(x) ((x)*(MenuHires?2:1))
84 #define LHY(y) ((y)*(MenuHires?2.4:1))
86 #define TITLE_FONT HUGE_FONT
87 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
88 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
89 #define SUBTITLE_FONT MEDIUM3_FONT
91 #define NORMAL_CHECK_BOX "
\81"
92 #define CHECKED_CHECK_BOX "
\82"
94 #define NORMAL_RADIO_BOX "
\7f"
95 #define CHECKED_RADIO_BOX "
\80"
96 #define CURSOR_STRING "_"
97 #define SLIDER_LEFT "
\83" // 131
98 #define SLIDER_RIGHT "
\84" // 132
99 #define SLIDER_MIDDLE "
\85" // 133
100 #define SLIDER_MARKER "
\86" // 134
101 #define UP_ARROW_MARKER "
\87" // 135
102 #define DOWN_ARROW_MARKER "
\88" // 136
104 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 );
105 void show_extra_netgame_info(int choice);
108 int Newmenu_first_time = 1;
109 //--unused-- int Newmenu_fade_in = 1;
112 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
113 grs_bitmap * saved; // The background under the menu.
114 grs_bitmap * background;
117 grs_bitmap nm_background,nm_background_save;
119 #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)
120 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
122 ubyte MenuReordering=0;
124 char Pauseable_menu=0;
125 char already_showing_info=0;
128 void newmenu_close() {
129 if ( nm_background.bm_data )
130 d_free(nm_background.bm_data);
132 if ( nm_background_save.bm_data )
133 d_free(nm_background_save.bm_data);
134 Newmenu_first_time = 1;
137 ubyte background_palette[768];
139 //should be called whenever the palette changes
140 void nm_remap_background()
142 if (!Newmenu_first_time) {
143 if (!nm_background.bm_data)
144 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
146 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
148 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
154 extern char last_palette_loaded[];
156 void nm_draw_background1(char * filename)
163 //@@//I think this only gets called to fill the whole screen
164 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
165 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
167 pcx_error = pcx_get_dimensions(filename, &width, &height);
168 if (pcx_error != PCX_ERROR_NONE)
169 Error("Could not open pcx file <%s>\n", filename);
171 bmp = gr_create_bitmap(width, height);
173 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
174 Assert(pcx_error == PCX_ERROR_NONE);
176 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
179 { //remap stuff. this code is kindof a hack
181 //now, before we bring up the menu, we need to
182 //do some stuff to make sure the palette is ok. First, we need to
183 //get our current palette into the 2d's array, so the remapping will
184 //work. Second, we need to remap the fonts. Third, we need to fill
185 //in part of the fade tables so the darkening of the menu edges works
187 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
189 gr_palette_load(gr_palette);
191 remap_fonts_and_menus(1);
195 WIN(DDGRLOCK(dd_grd_curcanv));
197 WIN(DDGRUNLOCK(dd_grd_curcanv));
201 strcpy(last_palette_loaded,""); //force palette load next time
205 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
206 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
208 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
210 int Background_hires;
213 void nm_draw_background(int x1, int y1, int x2, int y2 )
217 if (Newmenu_first_time || MenuHires!=Background_hires) {
220 if (Newmenu_first_time) {
221 atexit( newmenu_close );
222 Newmenu_first_time = 0;
223 nm_background_save.bm_data=NULL;
226 if (nm_background_save.bm_data)
227 d_free(nm_background_save.bm_data);
228 if (nm_background.bm_data)
229 d_free(nm_background.bm_data);
232 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
233 Assert(pcx_error == PCX_ERROR_NONE);
235 nm_background = nm_background_save;
236 nm_background.bm_data=NULL;
237 nm_remap_background();
239 Background_hires = MenuHires;
242 if ( x1 < 0 ) x1 = 0;
243 if ( y1 < 0 ) y1 = 0;
248 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
249 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
256 grs_bitmap *tmp = gr_create_bitmap(w, h);
258 gr_bitmap_scale_to(&nm_background, tmp);
260 WIN(DDGRLOCK(dd_grd_curcanv));
262 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
264 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
268 WIN(DDGRLOCK(dd_grd_curcanv));
270 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
272 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
276 Gr_scanline_darkening_level = 2*7;
278 gr_setcolor( BM_XRGB(0,0,0) );
279 gr_urect( x2-5, y1+5, x2-5, y2-5 );
280 gr_urect( x2-4, y1+4, x2-4, y2-5 );
281 gr_urect( x2-3, y1+3, x2-3, y2-5 );
282 gr_urect( x2-2, y1+2, x2-2, y2-5 );
283 gr_urect( x2-1, y1+1, x2-1, y2-5 );
284 gr_urect( x2+0, y1+0, x2-0, y2-5 );
286 gr_urect( x1+5, y2-5, x2, y2-5 );
287 gr_urect( x1+4, y2-4, x2, y2-4 );
288 gr_urect( x1+3, y2-3, x2, y2-3 );
289 gr_urect( x1+2, y2-2, x2, y2-2 );
290 gr_urect( x1+1, y2-1, x2, y2-1 );
291 gr_urect( x1+0, y2, x2, y2-0 );
293 WIN(DDGRUNLOCK(dd_grd_curcanv));
295 Gr_scanline_darkening_level = GR_FADE_LEVELS;
298 void nm_restore_background( int x, int y, int w, int h )
305 if ( x1 < 0 ) x1 = 0;
306 if ( y1 < 0 ) y1 = 0;
308 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
309 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
314 WIN(DDGRLOCK(dd_grd_curcanv));
315 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
316 WIN(DDGRUNLOCK(dd_grd_curcanv));
319 // Draw a left justfied string
320 void nm_string( bkg * b, int w1,int x, int y, char * s)
322 int w,h,aw,tx=0,t=0,i;
323 char *p,*s1,*s2,measure[2];
324 int XTabs[]={15,87,124,162,228,253};
330 XTabs[i]=(LHX(XTabs[i]));
337 p = strchr( s2, '\t' );
344 gr_get_string_size(s2, &w, &h, &aw );
350 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
351 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
354 for (i=0;i<strlen(s2);i++) {
355 if (s2[i]=='\t' && SurfingNet) {
361 gr_get_string_size(measure,&tx,&h,&aw);
362 gr_string(x,y,measure);
369 if (!SurfingNet && p && (w1>0) ) {
370 gr_get_string_size(s1, &w, &h, &aw );
372 gr_string( x+w1-w, y, s1 );
379 // Draw a slider and it's string
380 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
387 p = strchr( s, '\t' );
393 gr_get_string_size(s, &w, &h, &aw );
396 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
397 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
399 gr_string( x, y, s );
402 gr_get_string_size(s1, &w, &h, &aw );
405 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
407 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
409 gr_string( x+w1-w, y, s1 );
416 // Draw a left justfied string with black background.
417 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
420 gr_get_string_size(s, &w, &h, &aw );
424 WIN(DDGRLOCK(dd_grd_curcanv));
425 gr_setcolor( BM_XRGB(2,2,2) );
426 gr_rect( x-1, y-1, x-1, y+h-1 );
427 gr_rect( x-1, y-1, x+w1-1, y-1 );
430 gr_setcolor( BM_XRGB(5,5,5) );
431 gr_rect( x, y+h, x+w1, y+h);
432 gr_rect( x+w1, y-1, x+w1, y+h );
434 gr_setcolor( BM_XRGB(0,0,0) );
435 gr_rect( x, y, x+w1-1, y+h-1 );
437 gr_string( x+1, y+1, s );
438 WIN(DDGRUNLOCK(dd_grd_curcanv));
442 // Draw a right justfied string
443 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
446 gr_get_string_size(s, &w, &h, &aw );
451 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
454 WIN(DDGRLOCK(dd_grd_curcanv));
455 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
456 gr_string( x-w, y, s );
457 WIN(DDGRUNLOCK(dd_grd_curcanv));
462 //for text items, constantly redraw cursor (to achieve flash)
463 void update_cursor( newmenu_item *item)
466 fix time = timer_get_approx_seconds();
468 char * text = item->text;
470 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
473 gr_get_string_size(text, &w, &h, &aw );
474 if ( w > item->w-10 )
481 x = item->x+w; y = item->y;
483 WIN(DDGRLOCK(dd_grd_curcanv));
485 gr_string( x, y, CURSOR_STRING );
487 gr_setcolor( BM_XRGB(0,0,0) );
488 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
490 WIN(DDGRUNLOCK(dd_grd_curcanv));
493 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
498 gr_get_string_size(text, &w1, &h1, &aw );
507 nm_string_black( b, w, x, y, text );
510 gr_string( x+w1+1, y, CURSOR_STRING );
514 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
519 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
521 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
523 if (item->text[0]=='\t')
524 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
529 grd_curcanv->cv_font = SELECTED_FONT;
531 grd_curcanv->cv_font = NORMAL_FONT;
534 if (is_current && item->type == NM_TYPE_TEXT)
535 grd_curcanv->cv_font = NORMAL_FONT;
539 WIN(DDGRLOCK(dd_grd_curcanv));
540 switch( item->type ) {
542 // grd_curcanv->cv_font=TEXT_FONT;
543 // fall through on purpose
546 nm_string( b, item->w, item->x, item->y, item->text );
548 case NM_TYPE_SLIDER: {
550 if (item->value < item->min_value) item->value=item->min_value;
551 if (item->value > item->max_value) item->value=item->max_value;
552 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
553 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
554 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
556 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
558 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
560 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
563 case NM_TYPE_INPUT_MENU:
564 if ( item->group==0 ) {
565 nm_string( b, item->w, item->x, item->y, item->text );
567 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
571 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
574 nm_string( b, item->w, item->x, item->y, item->text );
576 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
578 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
581 nm_string( b, item->w, item->x, item->y, item->text );
583 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
585 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
587 case NM_TYPE_NUMBER: {
589 if (item->value < item->min_value) item->value=item->min_value;
590 if (item->value > item->max_value) item->value=item->max_value;
591 nm_string( b, item->w, item->x, item->y, item->text );
592 sprintf( text, "%d", item->value );
593 nm_rstring( b,item->right_offset,item->x, item->y, text );
597 WIN(DDGRUNLOCK(dd_grd_curcanv));
601 char *Newmenu_allowed_chars=NULL;
603 //returns true if char is allowed
604 int char_allowed(char c)
606 char *p = Newmenu_allowed_chars;
614 if (c>=p[0] && c<=p[1])
623 void strip_end_whitespace( char * text )
627 for (i=l-1; i>=0; i-- ) {
628 if ( isspace(text[i]) )
635 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
637 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
639 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
641 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
645 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
647 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
651 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 )
653 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
657 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 )
659 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
661 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 )
663 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
666 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){
667 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
668 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
669 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
672 //returns 1 if a control device button has been pressed
673 int check_button_press()
677 switch (Config_control_type) {
678 case CONTROL_JOYSTICK:
679 case CONTROL_FLIGHTSTICK_PRO:
680 case CONTROL_THRUSTMASTER_FCS:
681 case CONTROL_GRAVIS_GAMEPAD:
683 if (joy_get_button_down_cnt(i)>0) return 1;
686 case CONTROL_CYBERMAN:
687 #ifndef NEWMENU_MOUSE // don't allow mouse to continue from menu
689 if (mouse_button_down_count(i)>0) return 1;
692 case CONTROL_WINJOYSTICK:
695 if (joy_get_button_down_cnt(i)>0) return 1;
698 case CONTROL_NONE: //keyboard only
700 if (key_checkch()) return 1;
705 Error("Bad control type (Config_control_type):%i",Config_control_type);
711 extern int network_request_player_names(int);
712 extern int RestoringMenu;
715 ubyte Hack_DblClick_MenuMode=0;
719 extern ubyte joydefs_calibrating;
721 # define joydefs_calibrating 0
724 #define CLOSE_X (MenuHires?15:7)
725 #define CLOSE_Y (MenuHires?15:7)
726 #define CLOSE_SIZE (MenuHires?10:5)
728 void draw_close_box(int x,int y)
730 WIN (DDGRLOCK(dd_grd_curcanv));
731 gr_setcolor( BM_XRGB(0, 0, 0) );
732 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
733 gr_setcolor( BM_XRGB(21, 21, 21) );
734 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));
735 WIN (DDGRUNLOCK(dd_grd_curcanv));
738 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 )
740 int old_keyd_repeat, done;
741 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
742 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
743 grs_font * save_font;
744 int string_width, string_height, average_width;
747 int all_text=0; //set true if all text items
748 int sound_stopped=0,time_stopped=0;
749 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
752 int MaxOnMenu=MAXDISPLAYABLEITEMS;
753 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
755 int mouse_state, omouse_state, dblclick_flag=0;
756 int mx=0, my=0, x1 = 0, x2, y1, y2;
760 EventRecord event; // looking for disk inserted events for CD mounts
763 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
764 newmenu_hide_cursor();
771 WIN(mouse_set_mode(0)); //disable centering mode
773 MaxDisplayable=nitems;
775 //set_screen_mode(SCREEN_MENU);
778 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
779 digi_pause_digi_sounds();
783 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
796 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
798 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
800 save_font = grd_curcanv->cv_font;
805 grd_curcanv->cv_font = TITLE_FONT;
806 gr_get_string_size(title,&string_width,&string_height,&average_width );
811 grd_curcanv->cv_font = SUBTITLE_FONT;
812 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
813 if (string_width > tw )
818 th += LHY(8); //put some space between titles & body
821 grd_curcanv->cv_font = SMALL_FONT;
823 grd_curcanv->cv_font = NORMAL_FONT;
827 nmenus = nothers = 0;
829 // Find menu height & width (store in w,h)
830 for (i=0; i<nitems; i++ ) {
833 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
834 item[i].right_offset = 0;
837 string_height+=LHY(3);
839 item[i].saved_text[0] = '\0';
841 if ( item[i].type == NM_TYPE_SLIDER ) {
844 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
845 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
846 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
848 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
849 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
850 string_width += w1 + aw;
853 if ( item[i].type == NM_TYPE_MENU ) {
857 if ( item[i].type == NM_TYPE_CHECK ) {
860 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
861 item[i].right_offset = w1;
862 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
863 if (w1 > item[i].right_offset)
864 item[i].right_offset = w1;
867 if (item[i].type == NM_TYPE_RADIO ) {
870 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
871 item[i].right_offset = w1;
872 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
873 if (w1 > item[i].right_offset)
874 item[i].right_offset = w1;
877 if (item[i].type==NM_TYPE_NUMBER ) {
881 sprintf( test_text, "%d", item[i].max_value );
882 gr_get_string_size( test_text, &w1, &h1, &aw1 );
883 item[i].right_offset = w1;
884 sprintf( test_text, "%d", item[i].min_value );
885 gr_get_string_size( test_text, &w1, &h1, &aw1 );
886 if ( w1 > item[i].right_offset)
887 item[i].right_offset = w1;
890 if ( item[i].type == NM_TYPE_INPUT ) {
891 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
892 strcpy(item[i].saved_text, item[i].text );
894 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
895 if ( string_width > MAX_TEXT_WIDTH )
896 string_width = MAX_TEXT_WIDTH;
900 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
901 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
902 strcpy(item[i].saved_text, item[i].text );
904 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
909 item[i].w = string_width;
910 item[i].h = string_height;
912 if ( string_width > w )
913 w = string_width; // Save maximum width
914 if ( average_width > aw )
916 h += string_height+1; // Find the height of all strings
919 // Big hack for allowing the netgame options menu to spill over
921 MaxOnMenu=MAXDISPLAYABLEITEMS;
922 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
925 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
928 h=(MaxOnMenu*(string_height+1)+LHY(8));
929 MaxDisplayable=MaxOnMenu;
930 mprintf ((0,"Hey, this is a scroll box!\n"));
943 for (i=0; i<nitems; i++ ) {
945 if (item[i].right_offset > right_offset )
946 right_offset = item[i].right_offset;
948 if (right_offset > 0 )
951 //gr_get_string_size("",&string_width,&string_height,&average_width );
958 twidth = ( tw - w )/2;
963 { right_offset=0; twidth=0;}
965 mprintf(( 0, "Right offset = %d\n", right_offset ));
968 // Find min point of menu border
969 // x = (grd_curscreen->sc_w-w)/2;
970 // y = (grd_curscreen->sc_h-h)/2;
972 w += MenuHires?60:30;
973 h += MenuHires?60:30;
975 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
976 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
978 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
979 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
984 if ( filename != NULL ) {
985 nm_draw_background1( filename );
986 gr_palette_load(gr_palette);
989 // Save the background of the display
990 // Win95 must refer to the screen as a dd_grs_canvas, so...
991 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
992 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
994 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
995 gr_set_current_canvas(bg.menu_canvas) );
997 if ( filename == NULL ) {
998 // Save the background under the menu...
1004 bg.saved = gr_create_bitmap( w, h );
1005 Assert( bg.saved != NULL );
1007 WIN (DDGRLOCK(dd_grd_curcanv));
1008 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1009 WIN (DDGRUNLOCK(dd_grd_curcanv));
1011 WINDOS ( dd_gr_set_current_canvas(NULL),
1012 gr_set_current_canvas( NULL )
1015 nm_draw_background(x,y,x+w-1,y+h-1);
1017 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1018 gr_set_current_canvas( bg.menu_canvas )
1021 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1025 bg.background = gr_create_bitmap( w, h );
1026 Assert( bg.background != NULL );
1028 WIN (DDGRLOCK(dd_grd_curcanv));
1029 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1030 WIN (DDGRUNLOCK(dd_grd_curcanv));
1033 // ty = 15 + (yborder/4);
1035 ty = MenuHires?30:15;
1038 grd_curcanv->cv_font = TITLE_FONT;
1039 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1040 gr_get_string_size(title,&string_width,&string_height,&average_width );
1043 WIN (DDGRLOCK(dd_grd_curcanv));
1044 gr_printf( 0x8000, ty, title );
1045 WIN (DDGRUNLOCK(dd_grd_curcanv));
1050 grd_curcanv->cv_font = SUBTITLE_FONT;
1051 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1052 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1055 WIN (DDGRLOCK(dd_grd_curcanv));
1056 gr_printf( 0x8000, ty, subtitle );
1057 WIN (DDGRUNLOCK(dd_grd_curcanv));
1062 grd_curcanv->cv_font = SMALL_FONT;
1064 grd_curcanv->cv_font = NORMAL_FONT;
1066 // Update all item's x & y values.
1067 for (i=0; i<nitems; i++ ) {
1068 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1069 item[i].y += (MenuHires?30:15);
1070 if ( item[i].type==NM_TYPE_RADIO ) {
1071 fm = -1; // find first marked one
1072 for ( j=0; j<nitems; j++ ) {
1073 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1074 if (fm==-1 && item[j].value)
1086 old_keyd_repeat = keyd_repeat;
1092 if (citem < 0 ) citem = 0;
1093 if (citem > nitems-1 ) citem = nitems-1;
1096 #ifdef NEWMENU_MOUSE
1100 while ( item[choice].type==NM_TYPE_TEXT ) {
1102 if (choice >= nitems ) {
1105 if (choice == citem ) {
1116 // Clear mouse, joystick to clear button presses.
1117 game_flush_inputs();
1119 #ifdef NEWMENU_MOUSE
1120 mouse_state = omouse_state = 0;
1121 if (filename == NULL && !MenuReordering) {
1122 draw_close_box(0,0);
1126 if (!MenuReordering && !joydefs_calibrating)
1128 newmenu_show_cursor();
1130 SetCursor(LoadCursor(NULL,IDC_ARROW));
1135 mprintf ((0,"Set to true!\n"));
1141 DoMessageStuff(&msg);
1143 if (_RedrawScreen) {
1144 _RedrawScreen = FALSE;
1147 gr_free_bitmap(bg.saved);
1148 d_free( bg.background );
1151 gr_free_bitmap(bg.background);
1153 dd_gr_free_sub_canvas( bg.menu_canvas );
1154 grd_curcanv->cv_font = save_font;
1155 dd_grd_curcanv = save_canvas;
1157 goto RePaintNewmenu4;
1164 #ifdef NEWMENU_MOUSE
1165 if (!joydefs_calibrating)
1166 newmenu_show_cursor(); // possibly hidden
1167 omouse_state = mouse_state;
1168 if (!MenuReordering)
1169 mouse_state = mouse_button_state(0);
1170 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1173 //see if redbook song needs to be restarted
1174 songs_check_redbook_repeat();
1181 (*subfunction)(nitems,item,&k,choice);
1184 if (!time_stopped) {
1185 // Save current menu box
1186 if (multi_menu_poll() == -1)
1192 dont_restore = (k == -3); //-3 means don't restore
1198 if (check_button_press())
1202 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1205 old_choice = choice;
1211 if (SurfingNet && !already_showing_info)
1213 show_extra_netgame_info(choice-2);
1215 if (SurfingNet && already_showing_info)
1222 if (SurfingNet && !already_showing_info)
1224 network_request_player_names(choice-2);
1226 if (SurfingNet && already_showing_info)
1241 case KEY_TAB + KEY_SHIFTED:
1244 if (all_text) break;
1251 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1253 if (choice<TopChoice)
1254 { choice=TopChoice; break; }
1256 if (choice<ScrollOffset)
1258 for (i=0;i<nitems;i++)
1261 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1266 if (choice >= nitems ) choice=0;
1267 if (choice < 0 ) choice=nitems-1;
1269 } while ( item[choice].type==NM_TYPE_TEXT );
1270 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1271 item[choice].value = -1;
1272 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1273 item[old_choice].group=0;
1274 strcpy(item[old_choice].text, item[old_choice].saved_text );
1275 item[old_choice].value = -1;
1278 item[old_choice].redraw = 1;
1279 item[choice].redraw=1;
1284 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1285 if (all_text) break;
1292 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1295 { choice--; break; }
1297 if (choice>=MaxOnMenu+ScrollOffset)
1299 for (i=0;i<nitems;i++)
1302 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1307 if (choice < 0 ) choice=nitems-1;
1308 if (choice >= nitems ) choice=0;
1311 } while ( item[choice].type==NM_TYPE_TEXT );
1313 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1314 item[choice].value = -1;
1315 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1316 item[old_choice].group=0;
1317 strcpy(item[old_choice].text, item[old_choice].saved_text );
1318 item[old_choice].value = -1;
1321 item[old_choice].redraw=1;
1322 item[choice].redraw=1;
1325 if ( choice > -1 ) {
1326 switch( item[choice].type ) {
1329 case NM_TYPE_INPUT_MENU:
1332 if ( item[choice].value )
1333 item[choice].value = 0;
1335 item[choice].value = 1;
1336 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1339 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1341 mprintf ((0,"Special redraw!\n"));
1346 item[choice].redraw=1;
1349 for (i=0; i<nitems; i++ ) {
1350 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1355 item[choice].value = 1;
1356 item[choice].redraw = 1;
1362 case KEY_SHIFTED+KEY_UP:
1363 if (MenuReordering && choice!=TopChoice)
1365 Temp=item[choice].text;
1366 TempVal=item[choice].value;
1367 item[choice].text=item[choice-1].text;
1368 item[choice].value=item[choice-1].value;
1369 item[choice-1].text=Temp;
1370 item[choice-1].value=TempVal;
1371 item[choice].redraw=1;
1372 item[choice-1].redraw=1;
1376 case KEY_SHIFTED+KEY_DOWN:
1377 if (MenuReordering && choice!=(nitems-1))
1379 Temp=item[choice].text;
1380 TempVal=item[choice].value;
1381 item[choice].text=item[choice+1].text;
1382 item[choice].value=item[choice+1].value;
1383 item[choice+1].text=Temp;
1384 item[choice+1].value=TempVal;
1385 item[choice].redraw=1;
1386 item[choice+1].redraw=1;
1393 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1394 item[choice].group = 1;
1395 item[choice].redraw = 1;
1396 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1397 item[choice].text[0] = 0;
1398 item[choice].value = -1;
1400 strip_end_whitespace(item[choice].text);
1407 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1408 item[choice].group=0;
1409 strcpy(item[choice].text, item[choice].saved_text );
1410 item[choice].redraw=1;
1411 item[choice].value = -1;
1418 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1419 case KEY_PRINT_SCREEN:
1420 MAC(newmenu_hide_cursor());
1421 save_screen_shot(0);
1422 for (i=0;i<nitems;i++)
1425 MAC(newmenu_show_cursor());
1431 case KEY_COMMAND+KEY_RIGHT:
1432 songs_goto_next_song();
1434 case KEY_COMMAND+KEY_LEFT:
1435 songs_goto_prev_song();
1437 case KEY_COMMAND+KEY_UP:
1438 songs_play_level_song(1);
1440 case KEY_COMMAND+KEY_DOWN:
1441 songs_stop_redbook();
1444 case KEY_COMMAND+KEY_M:
1446 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1447 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1450 key_close(); // no processing of keys with keyboard handler.. jeez
1452 newmenu_hide_cursor();
1453 show_boxed_message ("Mounting CD\nESC to quit");
1454 RBAMountDisk(); // OS has totaly control of the CD.
1455 if (Function_mode == FMODE_MENU)
1456 songs_play_song(SONG_TITLE,1);
1457 else if (Function_mode == FMODE_GAME)
1458 songs_play_level_song( Current_level_num );
1459 clear_boxed_message();
1460 newmenu_show_cursor();
1468 case KEY_COMMAND+KEY_E:
1469 songs_stop_redbook();
1471 k = -1; // force key not to register
1474 case KEY_COMMAND+KEY_Q: {
1475 extern void macintosh_quit();
1477 if ( !(Game_mode & GM_MULTI) )
1479 if (!joydefs_calibrating)
1480 newmenu_show_cursor();
1481 k = -1; // force key not to register
1488 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1495 #ifdef NEWMENU_MOUSE // for mouse selection of menu's etc.
1497 if ( !done && mouse_state && !omouse_state && !all_text ) {
1498 mouse_get_pos(&mx, &my);
1499 for (i=0; i<nitems; i++ ) {
1500 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1501 x2 = x1 + item[i].w;
1502 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1503 y2 = y1 + item[i].h;
1504 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1505 if (i+ScrollOffset != choice) {
1506 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1509 choice = i + ScrollOffset;
1511 switch( item[choice].type ) {
1513 if ( item[choice].value )
1514 item[choice].value = 0;
1516 item[choice].value = 1;
1517 item[choice].redraw=1;
1524 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1526 mprintf ((0,"Special redraw!\n"));
1533 for (i=0; i<nitems; i++ ) {
1534 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1539 item[choice].value = 1;
1540 item[choice].redraw = 1;
1543 item[old_choice].redraw=1;
1549 if (mouse_state && all_text)
1552 if ( !done && mouse_state && !all_text ) {
1553 mouse_get_pos(&mx, &my);
1555 // check possible scrollbar stuff first
1557 int arrow_width, arrow_height, aw;
1559 if (ScrollOffset != 0) {
1560 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1561 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1562 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1563 x1 = x1 - arrow_width;
1564 y2 = y1 + arrow_height;
1565 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1568 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1570 if (choice<ScrollOffset)
1572 for (i=0;i<nitems;i++)
1575 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1579 if (ScrollOffset+MaxDisplayable<nitems) {
1580 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1581 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1582 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1583 x1 = x1 - arrow_width;
1584 y2 = y1 + arrow_height;
1585 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1588 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1590 if (choice>=MaxOnMenu+ScrollOffset)
1592 for (i=0;i<nitems;i++)
1595 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1601 for (i=0; i<nitems; i++ ) {
1602 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1603 x2 = x1 + item[i].w;
1604 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1605 y2 = y1 + item[i].h;
1606 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1607 if (i+ScrollOffset != choice) {
1608 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1611 choice = i + ScrollOffset;
1613 if ( item[choice].type == NM_TYPE_SLIDER ) {
1614 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1615 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1617 strcpy(slider_text, item[choice].saved_text);
1618 p = strchr(slider_text, '\t');
1624 gr_get_string_size(s1, &slider_width, &height, &aw);
1625 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1626 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1627 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1629 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1630 x2 = x1 + slider_width + sright_width;
1631 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1632 item[choice].value = item[choice].min_value;
1633 item[choice].redraw = 2;
1634 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1635 item[choice].value = item[choice].max_value;
1636 item[choice].redraw = 2;
1637 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1638 int num_values, value_width, new_value;
1640 num_values = item[choice].max_value - item[choice].min_value + 1;
1641 value_width = (slider_width - sleft_width - sright_width) / num_values;
1642 new_value = (mx - x1 - sleft_width) / value_width;
1643 if ( item[choice].value != new_value ) {
1644 item[choice].value = new_value;
1645 item[choice].redraw = 2;
1651 if (choice == old_choice)
1653 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1654 item[choice].value = -1;
1655 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1656 item[old_choice].group=0;
1657 strcpy(item[old_choice].text, item[old_choice].saved_text );
1658 item[old_choice].value = -1;
1661 item[old_choice].redraw = 1;
1662 item[choice].redraw=1;
1668 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1669 mouse_get_pos(&mx, &my);
1670 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1671 x2 = x1 + item[choice].w;
1672 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1673 y2 = y1 + item[choice].h;
1674 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1675 if (Hack_DblClick_MenuMode) {
1676 if (dblclick_flag) done = 1;
1677 else dblclick_flag = 1;
1683 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1684 item[choice].group = 1;
1685 item[choice].redraw = 1;
1686 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1687 item[choice].text[0] = 0;
1688 item[choice].value = -1;
1690 strip_end_whitespace(item[choice].text);
1694 if ( !done && !mouse_state && omouse_state && close_box ) {
1695 mouse_get_pos(&mx, &my);
1696 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1697 x2 = x1 + CLOSE_SIZE;
1698 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1699 y2 = y1 + CLOSE_SIZE;
1700 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1706 // HACK! Don't redraw loadgame preview
1707 if (RestoringMenu) item[0].redraw = 0;
1708 #endif // NEWMENU_MOUSE
1710 if ( choice > -1 ) {
1713 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1714 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1715 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1716 if (item[choice].value > 0)
1717 item[choice].value--;
1718 item[choice].text[item[choice].value] = 0;
1719 item[choice].redraw = 1;
1721 ascii = key_to_ascii(k);
1722 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1726 if (item[choice].value==-1) {
1727 item[choice].value = 0;
1730 allowed = char_allowed(ascii);
1732 if (!allowed && ascii==' ' && char_allowed('_')) {
1738 item[choice].text[item[choice].value++] = ascii;
1739 item[choice].text[item[choice].value] = 0;
1740 item[choice].redraw=1;
1744 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1745 ascii = key_to_ascii(k);
1747 int choice1 = choice;
1748 ascii = toupper(ascii);
1752 if (choice1 >= nitems ) choice1=0;
1753 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1754 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1755 (item[choice1].type==NM_TYPE_CHECK) ||
1756 (item[choice1].type==NM_TYPE_RADIO) ||
1757 (item[choice1].type==NM_TYPE_NUMBER) ||
1758 (item[choice1].type==NM_TYPE_SLIDER) )
1759 && (ascii==toupper(ch)) ) {
1763 item[old_choice].redraw=1;
1764 item[choice].redraw=1;
1766 } while (choice1 != choice );
1770 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1771 int ov=item[choice].value;
1776 case KEY_MINUS+KEY_SHIFTED:
1778 item[choice].value -= 1;
1783 case KEY_EQUAL+KEY_SHIFTED:
1785 item[choice].value++;
1790 item[choice].value += 10;
1795 item[choice].value -= 10;
1798 if (ov!=item[choice].value)
1799 item[choice].redraw=1;
1804 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1805 gr_set_current_canvas(bg.menu_canvas));
1807 // Redraw everything...
1808 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1810 if (item[i].redraw) // warning! ugly hack below
1812 item[i].y-=((string_height+1)*ScrollOffset);
1813 newmenu_hide_cursor();
1814 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1816 #ifdef NEWMENU_MOUSE
1817 if (!MenuReordering && !joydefs_calibrating)
1818 newmenu_show_cursor();
1820 item[i].y+=((string_height+1)*ScrollOffset);
1822 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1823 update_cursor( &item[i]);
1829 //grd_curcanv->cv_font = NORMAL_FONT;
1831 if (LastScrollCheck!=ScrollOffset)
1833 LastScrollCheck=ScrollOffset;
1834 grd_curcanv->cv_font = SELECTED_FONT;
1836 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1837 sx=item[ScrollOffset].x-(MenuHires?24:12);
1840 if (ScrollOffset!=0)
1841 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1843 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1845 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1846 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1848 if (ScrollOffset+MaxDisplayable<nitems)
1849 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1851 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1857 if ( !dont_restore && gr_palette_faded_out ) {
1858 gr_palette_fade_in( gr_palette, 32, 0 );
1862 newmenu_hide_cursor();
1864 // Restore everything...
1866 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1867 gr_set_current_canvas(bg.menu_canvas));
1869 if ( filename == NULL ) {
1870 // Save the background under the menu...
1871 WIN (DDGRLOCK(dd_grd_curcanv));
1872 gr_bitmap(0, 0, bg.saved);
1873 WIN (DDGRUNLOCK(dd_grd_curcanv));
1874 gr_free_bitmap(bg.saved);
1875 d_free( bg.background );
1877 if (!dont_restore) //info passed back from subfunction
1879 WIN (DDGRLOCK(dd_grd_curcanv));
1880 gr_bitmap(0, 0, bg.background);
1881 WIN (DDGRUNLOCK(dd_grd_curcanv));
1883 gr_free_bitmap(bg.background);
1886 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1887 gr_free_sub_canvas( bg.menu_canvas ) );
1889 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1890 grd_curcanv->cv_font = save_font;
1891 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1892 keyd_repeat = old_keyd_repeat;
1894 game_flush_inputs();
1905 if ( sound_stopped )
1906 digi_resume_digi_sounds();
1908 WIN(mouse_set_mode(1)); //re-enable centering mode
1915 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1921 char nm_text[MESSAGEBOX_TEXT_SIZE];
1922 newmenu_item nm_message_items[5];
1924 va_start(args, nchoices );
1926 Assert( nchoices <= 5 );
1928 for (i=0; i<nchoices; i++ ) {
1929 s = va_arg( args, char * );
1930 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1932 format = va_arg( args, char * );
1933 strcpy( nm_text, "" );
1934 vsprintf(nm_text,format,args);
1937 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1939 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1942 int nm_messagebox( char *title, int nchoices, ... )
1948 char nm_text[MESSAGEBOX_TEXT_SIZE];
1949 newmenu_item nm_message_items[5];
1951 va_start(args, nchoices );
1953 Assert( nchoices <= 5 );
1955 for (i=0; i<nchoices; i++ ) {
1956 s = va_arg( args, char * );
1957 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1959 format = va_arg( args, char * );
1960 strcpy( nm_text, "" );
1961 vsprintf(nm_text,format,args);
1964 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1966 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1972 void newmenu_file_sort( int n, char *list )
1979 for (i=incr; i<n; i++ ) {
1982 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1983 memcpy( t, &list[j*14], FILENAME_LEN );
1984 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1985 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1996 void delete_player_saved_games(char * name)
2001 for (i=0;i<10; i++) {
2003 sprintf( filename, "%s.sg%d", name, i );
2005 sprintf(filename, "Players/%s.sg%d", name, i);
2007 PHYSFS_delete(filename);
2011 #define MAX_FILES 300
2013 //FIXME: should maybe put globbing ability back?
2014 int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
2020 int NumFiles=0, key,done, citem, ocitem;
2021 char * filenames = NULL;
2022 int NumFiles_displayed = 8;
2023 int first_item = -1, ofirst_item;
2024 int old_keyd_repeat = keyd_repeat;
2027 int demos_deleted=0;
2028 int initialized = 0;
2030 int w_x, w_y, w_w, w_h, title_height;
2031 int box_x, box_y, box_w, box_h;
2032 bkg bg; // background under listbox
2033 #ifdef NEWMENU_MOUSE
2034 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2035 int mouse2_state, omouse2_state;
2036 int dblclick_flag=0;
2039 int show_up_arrow=0, show_down_arrow=0;
2042 WIN(int win_redraw=0);
2044 w_x=w_y=w_w=w_h=title_height=0;
2045 box_x=box_y=box_w=box_h=0;
2047 filenames = d_malloc( MAX_FILES * 14 );
2048 if (filenames==NULL) return 0;
2053 WIN(mouse_set_mode(0)); //disable centering mode
2055 if (!stricmp(type, "plr"))
2057 else if (!stricmp(type, "dem"))
2064 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2066 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2071 find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
2072 for (f = find; *f != NULL; f++)
2076 ext = strrchr(*f, '.');
2077 if (!ext || strnicmp(ext, ".plr", 4))
2080 if (NumFiles < MAX_FILES)
2082 strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
2087 p = strchr(&filenames[NumFiles*14], '.');
2097 PHYSFS_freeList(find);
2099 if ( (NumFiles < 1) && demos_deleted ) {
2103 if ( (NumFiles < 1) && demo_mode ) {
2104 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2110 if ( (NumFiles < 2) && player_mode ) {
2112 goto ExitFileMenuEarly;
2119 nm_messagebox(NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND);
2126 // set_screen_mode(SCREEN_MENU);
2132 dd_gr_set_current_canvas(NULL);
2134 gr_set_current_canvas(NULL);
2137 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2139 grd_curcanv->cv_font = SUBTITLE_FONT;
2141 WIN(DDGRUNLOCK(dd_grd_curcanv));
2146 for (i=0; i<NumFiles; i++ ) {
2148 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2154 gr_get_string_size( title, &w, &h, &aw );
2157 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2161 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2163 w_w += (grd_curfont->ft_w * 4);
2164 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2166 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2167 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2169 w_x = (grd_curcanv->cv_w-w_w)/2;
2170 w_y = (grd_curcanv->cv_h-w_h)/2;
2172 if ( w_x < 0 ) w_x = 0;
2173 if ( w_y < 0 ) w_y = 0;
2175 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2176 box_y = w_y + title_height;
2178 // save the screen behind the menu.
2182 #if !defined(WINDOWS)
2183 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2184 bg.background = &VR_offscreen_buffer->cv_bitmap;
2187 bg.background = gr_create_bitmap( w_w, w_h );
2189 Assert( bg.background != NULL );
2192 WIN(DDGRLOCK(dd_grd_curcanv));
2193 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2194 WIN(DDGRUNLOCK(dd_grd_curcanv));
2198 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2199 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2200 dd_VR_offscreen_buffer, 0, 0,
2201 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2202 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2206 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2208 WIN(DDGRLOCK(dd_grd_curcanv))
2210 gr_string( 0x8000, w_y+10, title );
2212 WIN(DDGRUNLOCK(dd_grd_curcanv));
2219 if ( !player_mode ) {
2220 newmenu_file_sort( NumFiles, filenames );
2222 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2223 newmenu_file_sort( NumFiles, filenames );
2225 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2227 for ( i=0; i<NumFiles; i++ ) {
2228 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2229 #ifdef NEWMENU_MOUSE
2237 #ifdef NEWMENU_MOUSE
2238 mouse_state = omouse_state = 0;
2239 mouse2_state = omouse2_state = 0;
2240 draw_close_box(w_x,w_y);
2241 newmenu_show_cursor();
2248 DoMessageStuff(&msg);
2250 if (_RedrawScreen) {
2251 _RedrawScreen = FALSE;
2253 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2254 gr_free_bitmap(bg.background);
2257 goto RePaintNewmenuFile;
2264 ofirst_item = first_item;
2267 #ifdef NEWMENU_MOUSE
2268 omouse_state = mouse_state;
2269 omouse2_state = mouse2_state;
2270 mouse_state = mouse_button_state(0);
2271 mouse2_state = mouse_button_state(1);
2274 //see if redbook song needs to be restarted
2275 songs_check_redbook_repeat();
2278 if (!mouse2_state && omouse2_state)
2279 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2282 //NOTE LINK TO ABOVE ELSE
2288 else if (simukey==1)
2294 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2295 case KEY_PRINT_SCREEN:
2296 MAC(newmenu_hide_cursor());
2297 save_screen_shot(0);
2299 MAC(newmenu_show_cursor());
2303 case KEY_CTRLED+KEY_D:
2304 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2308 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2311 mouse_set_mode(1); //re-enable centering mode
2313 newmenu_hide_cursor();
2315 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2317 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2319 mouse_set_mode(0); //disenable centering mode
2321 newmenu_show_cursor();
2325 char name[PATH_MAX];
2327 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2331 strcpy(name, demo_mode?DEMO_DIR:"");
2332 strcat(name,&filenames[citem*14]);
2339 if ( !strncmp(name, ".\\", 2) )
2340 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2341 name[i] = name[i+1];
2342 while ( (p = strchr(name, '\\')) )
2347 ret = !PHYSFS_delete(name);
2351 if ((!ret) && player_mode) {
2352 delete_player_saved_games( &filenames[citem*14] );
2357 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2359 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2360 } else if (demo_mode)
2385 citem += NumFiles_displayed;
2389 citem -= NumFiles_displayed;
2392 if (allow_abort_flag) {
2403 case KEY_COMMAND+KEY_Q: {
2404 extern void macintosh_quit();
2406 if ( !(Game_mode & GM_MULTI) )
2408 newmenu_show_cursor();
2417 int ascii = key_to_ascii(key);
2418 if ( ascii < 255 ) {
2421 if (cc1 < 0 ) cc1 = 0;
2422 if (cc1 >= NumFiles ) cc1 = 0;
2424 if ( cc < 0 ) cc = 0;
2425 if ( cc >= NumFiles ) cc = 0;
2426 if ( citem == cc ) break;
2428 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2443 if (citem>=NumFiles)
2446 if (citem< first_item)
2449 if (citem>=( first_item+NumFiles_displayed))
2451 first_item = citem-NumFiles_displayed+1;
2455 if (NumFiles>first_item+NumFiles_displayed)
2466 if (NumFiles <= NumFiles_displayed )
2469 if (first_item>NumFiles-NumFiles_displayed)
2471 first_item = NumFiles-NumFiles_displayed;
2474 if (first_item < 0 ) first_item = 0;
2476 #ifdef NEWMENU_MOUSE
2478 if (mouse_state || mouse2_state) {
2481 mouse_get_pos(&mx, &my);
2482 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2483 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2485 x2 = box_x + box_w - 1;
2486 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2488 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2489 if (i == citem && !mouse2_state) {
2499 if (!mouse_state && omouse_state) {
2502 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2503 mouse_get_pos(&mx, &my);
2505 x2 = box_x + box_w - 1;
2506 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2508 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2509 if (dblclick_flag) done = 1;
2510 else dblclick_flag = 1;
2514 if ( !mouse_state && omouse_state ) {
2515 mouse_get_pos(&mx, &my);
2516 x1 = w_x + CLOSE_X + 2;
2517 x2 = x1 + CLOSE_SIZE - 2;
2518 y1 = w_y + CLOSE_Y + 2;
2519 y2 = y1 + CLOSE_SIZE - 2;
2520 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2529 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2531 y1 = box_y+box_h-LHY(7);
2533 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2540 WIN(DDGRLOCK(dd_grd_curcanv));
2541 gr_setcolor( BM_XRGB(2,2,2));
2542 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2543 gr_setcolor( BM_XRGB( 0,0,0) );
2546 if (ofirst_item != first_item || win_redraw) {
2549 if (ofirst_item != first_item) {
2551 newmenu_hide_cursor();
2552 gr_setcolor( BM_XRGB( 0,0,0) );
2553 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2555 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2557 if ( i >= NumFiles ) {
2559 gr_setcolor( BM_XRGB(5,5,5));
2560 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2561 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2563 gr_setcolor( BM_XRGB(2,2,2));
2564 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2566 gr_setcolor( BM_XRGB(0,0,0));
2567 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2571 grd_curcanv->cv_font = SELECTED_FONT;
2573 grd_curcanv->cv_font = NORMAL_FONT;
2574 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2576 gr_setcolor( BM_XRGB(5,5,5));
2577 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2578 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2580 gr_setcolor( BM_XRGB(2,2,2));
2581 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2582 gr_setcolor( BM_XRGB(0,0,0));
2584 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2585 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2588 newmenu_show_cursor();
2589 } else if ( citem != ocitem ) {
2592 newmenu_hide_cursor();
2594 if ( (i>=0) && (i<NumFiles) ) {
2595 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2597 grd_curcanv->cv_font = SELECTED_FONT;
2599 grd_curcanv->cv_font = NORMAL_FONT;
2600 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2601 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2602 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2605 if ( (i>=0) && (i<NumFiles) ) {
2606 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2608 grd_curcanv->cv_font = SELECTED_FONT;
2610 grd_curcanv->cv_font = NORMAL_FONT;
2611 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2612 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2613 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2615 newmenu_show_cursor();
2619 grd_curcanv->cv_font = NORMAL_FONT;
2621 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2625 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2629 if (show_down_arrow)
2630 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2634 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2642 WIN(DDGRUNLOCK(dd_grd_curcanv));
2646 MAC(newmenu_hide_cursor());
2648 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2655 keyd_repeat = old_keyd_repeat;
2657 if ( initialized ) {
2658 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2660 WIN (DDGRLOCK(dd_grd_curcanv));
2661 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2662 WIN (DDGRUNLOCK(dd_grd_curcanv));
2664 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2665 gr_free_bitmap(bg.background);
2668 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2669 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2671 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2672 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2682 WIN(mouse_set_mode(1)); //re-enable centering mode
2683 WIN(newmenu_hide_cursor());
2690 // Example listbox callback function...
2691 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2695 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2696 // if ( *nitems > 1 ) {
2697 // PHYSFS_delete(items[*citem]); // Delete the file
2698 // for (i=*citem; i<*nitems-1; i++ ) {
2699 // items[i] = items[i+1];
2701 // *nitems = *nitems - 1;
2702 // d_free( items[*nitems] );
2703 // items[*nitems] = NULL;
2704 // return 1; // redraw;
2711 #define LB_ITEMS_ON_SCREEN 8
2713 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2715 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2718 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 ) )
2721 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2722 int old_keyd_repeat = keyd_repeat;
2723 int width, height, wx, wy, title_height, border_size;
2724 int total_width,total_height;
2726 #ifdef NEWMENU_MOUSE
2727 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2728 int close_x,close_y;
2730 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2733 WIN(int win_redraw=0);
2737 WIN(mouse_set_mode(0)); //disable centering mode
2739 // set_screen_mode(SCREEN_MENU);
2743 RePaintNewmenuListbox:
2745 dd_gr_set_current_canvas(NULL);
2747 gr_set_current_canvas(NULL);
2750 grd_curcanv->cv_font = SUBTITLE_FONT;
2753 for (i=0; i<nitems; i++ ) {
2755 gr_get_string_size( items[i], &w, &h, &aw );
2759 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2763 gr_get_string_size( title, &w, &h, &aw );
2766 title_height = h + 5;
2769 border_size = grd_curfont->ft_w;
2770 WIN (border_size=grd_curfont->ft_w*2);
2772 width += (grd_curfont->ft_w);
2773 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2774 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2776 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2777 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2778 if ( wy < title_height )
2781 total_width = width+2*border_size;
2782 total_height = height+2*border_size+title_height;
2786 #if !defined(WINDOWS)
2787 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2788 bg.background = &VR_offscreen_buffer->cv_bitmap;
2791 //bg.background = gr_create_bitmap( width, (height + title_height) );
2792 bg.background = gr_create_bitmap(total_width,total_height);
2793 Assert( bg.background != NULL );
2795 WIN (DDGRLOCK(dd_grd_curcanv));
2796 //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 );
2797 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2798 WIN (DDGRUNLOCK(dd_grd_curcanv));
2802 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2803 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2804 dd_VR_offscreen_buffer, 0, 0,
2805 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2806 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2810 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2812 WIN(DDGRLOCK(dd_grd_curcanv));
2813 gr_string( 0x8000, wy - title_height, title );
2814 WIN(DDGRUNLOCK(dd_grd_curcanv));
2819 citem = default_item;
2820 if ( citem < 0 ) citem = 0;
2821 if ( citem >= nitems ) citem = 0;
2825 #ifdef NEWMENU_MOUSE
2826 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2827 close_x = wx-border_size;
2828 close_y = wy-title_height-border_size;
2829 draw_close_box(close_x,close_y);
2830 newmenu_show_cursor();
2837 DoMessageStuff(&msg);
2839 if (_RedrawScreen) {
2840 _RedrawScreen = FALSE;
2842 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2843 gr_free_bitmap(bg.background);
2845 goto RePaintNewmenuListbox;
2852 ofirst_item = first_item;
2853 #ifdef NEWMENU_MOUSE
2854 omouse_state = mouse_state;
2855 mouse_state = mouse_button_state(0);
2857 //see if redbook song needs to be restarted
2858 songs_check_redbook_repeat();
2862 if ( listbox_callback )
2863 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2884 else if (simukey==1)
2890 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2891 case KEY_PRINT_SCREEN:
2892 MAC(newmenu_hide_cursor());
2893 save_screen_shot(0);
2895 MAC(newmenu_show_cursor());
2916 citem += LB_ITEMS_ON_SCREEN;
2920 citem -= LB_ITEMS_ON_SCREEN;
2923 if (allow_abort_flag) {
2934 case KEY_COMMAND+KEY_Q: {
2935 extern void macintosh_quit();
2937 if ( !(Game_mode & GM_MULTI) )
2939 newmenu_show_cursor();
2947 int ascii = key_to_ascii(key);
2948 if ( ascii < 255 ) {
2951 if (cc1 < 0 ) cc1 = 0;
2952 if (cc1 >= nitems ) cc1 = 0;
2954 if ( cc < 0 ) cc = 0;
2955 if ( cc >= nitems ) cc = 0;
2956 if ( citem == cc ) break;
2958 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2975 if (citem< first_item)
2978 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2979 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2981 if (nitems <= LB_ITEMS_ON_SCREEN )
2984 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
2985 first_item = nitems-LB_ITEMS_ON_SCREEN;
2986 if (first_item < 0 ) first_item = 0;
2989 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3000 #ifdef NEWMENU_MOUSE
3005 mouse_get_pos(&mx, &my);
3006 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3009 gr_get_string_size(items[i], &w, &h, &aw );
3012 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3014 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3026 //no double-click stuff for listbox
3027 //@@if (!mouse_state && omouse_state) {
3030 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3031 //@@ mouse_get_pos(&mx, &my);
3033 //@@ x2 = wx + width;
3034 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3036 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3037 //@@ if (dblclick_flag) done = 1;
3041 //check for close box clicked
3042 if ( !mouse_state && omouse_state ) {
3043 mouse_get_pos(&mx, &my);
3044 x1 = close_x + CLOSE_X + 2;
3045 x2 = x1 + CLOSE_SIZE - 2;
3046 y1 = close_y + CLOSE_Y + 2;
3047 y2 = y1 + CLOSE_SIZE - 2;
3048 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3058 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3060 y1 = total_height-LHY(7);
3062 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3070 if ( (ofirst_item != first_item) || redraw) {
3071 newmenu_hide_cursor();
3072 WIN(DDGRLOCK(dd_grd_curcanv));
3074 gr_setcolor( BM_XRGB( 0,0,0) );
3075 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3077 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3078 if ( i >= nitems ) {
3079 gr_setcolor( BM_XRGB(0,0,0));
3080 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3083 grd_curcanv->cv_font = SELECTED_FONT;
3085 grd_curcanv->cv_font = NORMAL_FONT;
3086 gr_get_string_size(items[i], &w, &h, &aw );
3087 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3088 gr_string( wx+5, y, items[i] );
3093 // If Win95 port, draw up/down arrows on left side of menu
3095 grd_curcanv->cv_font = NORMAL_FONT;
3097 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3101 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3105 if (show_down_arrow)
3106 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3110 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3117 WIN(DDGRUNLOCK(dd_grd_curcanv));
3118 newmenu_show_cursor();
3120 } else if ( citem != ocitem ) {
3123 newmenu_hide_cursor();
3125 WIN(DDGRLOCK(dd_grd_curcanv));
3128 if ( (i>=0) && (i<nitems) ) {
3129 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3131 grd_curcanv->cv_font = SELECTED_FONT;
3133 grd_curcanv->cv_font = NORMAL_FONT;
3134 gr_get_string_size(items[i], &w, &h, &aw );
3135 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3136 gr_string( wx+5, y, items[i] );
3140 if ( (i>=0) && (i<nitems) ) {
3141 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3143 grd_curcanv->cv_font = SELECTED_FONT;
3145 grd_curcanv->cv_font = NORMAL_FONT;
3146 gr_get_string_size( items[i], &w, &h, &aw );
3147 gr_rect( wx, y-1, wx+width-1, y+h );
3148 gr_string( wx+5, y, items[i] );
3150 WIN(DDGRUNLOCK(dd_grd_curcanv));
3152 newmenu_show_cursor();
3156 newmenu_hide_cursor();
3158 keyd_repeat = old_keyd_repeat;
3160 WIN (DDGRLOCK(dd_grd_curcanv));
3161 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3162 WIN (DDGRUNLOCK(dd_grd_curcanv));
3164 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3165 gr_free_bitmap(bg.background);
3169 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3170 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3172 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3173 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3179 WIN(mouse_set_mode(1)); //re-enable centering mode
3185 int newmenu_filelist( char * title, char * filespec, char * filename )
3188 char * Filenames[MAX_FILES];
3189 char FilenameText[MAX_FILES][14];
3190 FILEFINDSTRUCT find;
3193 if( !FileFindFirst( filespec, &find ) ) {
3195 if (NumFiles<MAX_FILES) {
3196 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3197 Filenames[NumFiles] = FilenameText[NumFiles];
3202 } while( !FileFindNext( &find ) );
3206 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3208 strcpy( filename, Filenames[i] );
3215 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3216 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3222 char nm_text[MESSAGEBOX_TEXT_SIZE];
3223 newmenu_item nm_message_items[5];
3225 va_start(args, nchoices );
3227 Assert( nchoices <= 5 );
3229 for (i=0; i<nchoices; i++ ) {
3230 s = va_arg( args, char * );
3231 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3233 format = va_arg( args, char * );
3234 //sprintf( nm_text, "" ); // adb: ?
3235 vsprintf(nm_text,format,args);
3238 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3240 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3242 //end this section addition - Victor Rachels
3245 extern netgame_info Active_games[];
3246 extern int NumActiveNetgames;
3248 void show_extra_netgame_info(int choice)
3254 if (choice>=NumActiveNetgames)
3259 m[i].text=(char *)&mtext[i];
3260 m[i].type=NM_TYPE_TEXT;
3263 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3264 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3265 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3266 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3268 already_showing_info=1;
3269 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3270 already_showing_info=0;
3275 /* Spiffy word wrap string formatting function */
3277 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3283 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3286 wordptr = strtok(tbuf, " ");
3287 if (!wordptr) return;
3293 col = col+strlen(wordptr)+1;
3294 if (col >=line_length) {
3296 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3299 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3301 wordptr = strtok(NULL, " ");