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.
17 * FIXME: put description here
37 #include "pa_enabl.h" //$$POLY_ACC
84 #define MAXDISPLAYABLEITEMS 15
86 #define LHX(x) ((x)*(MenuHires?2:1))
87 #define LHY(y) ((y)*(MenuHires?2.4:1))
89 #define TITLE_FONT HUGE_FONT
90 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
91 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
92 #define SUBTITLE_FONT MEDIUM3_FONT
94 #define NORMAL_CHECK_BOX "
\81"
95 #define CHECKED_CHECK_BOX "
\82"
97 #define NORMAL_RADIO_BOX "
\7f"
98 #define CHECKED_RADIO_BOX "
\80"
99 #define CURSOR_STRING "_"
100 #define SLIDER_LEFT "
\83" // 131
101 #define SLIDER_RIGHT "
\84" // 132
102 #define SLIDER_MIDDLE "
\85" // 133
103 #define SLIDER_MARKER "
\86" // 134
104 #define UP_ARROW_MARKER "
\87" // 135
105 #define DOWN_ARROW_MARKER "
\88" // 136
107 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 );
108 void show_extra_netgame_info(int choice);
111 int Newmenu_first_time = 1;
112 //--unused-- int Newmenu_fade_in = 1;
115 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
116 grs_bitmap * saved; // The background under the menu.
117 grs_bitmap * background;
120 grs_bitmap nm_background,nm_background_save;
122 #define MESSAGEBOX_TEXT_SIZE 300 // How many characters in messagebox
123 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
125 extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
127 ubyte MenuReordering=0;
129 char Pauseable_menu=0;
130 char already_showing_info=0;
133 void newmenu_close() {
134 if ( nm_background.bm_data )
135 d_free(nm_background.bm_data);
137 if ( nm_background_save.bm_data )
138 d_free(nm_background_save.bm_data);
139 Newmenu_first_time = 1;
142 ubyte background_palette[768];
144 //should be called whenever the palette changes
145 void nm_remap_background()
147 if (!Newmenu_first_time) {
148 if (!nm_background.bm_data)
149 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
151 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
153 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
159 extern char last_palette_loaded[];
161 void nm_draw_background1(char * filename)
167 //@@//I think this only gets called to fill the whole screen
168 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
169 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
175 fp = cfopen(filename, "rb");
176 PCXHeader_read(&ph, fp);
177 bmp = gr_create_bitmap(ph.Xmax - ph.Xmin + 1, ph.Ymax - ph.Ymin + 1);
181 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
182 Assert(pcx_error == PCX_ERROR_NONE);
184 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
187 { //remap stuff. this code is kindof a hack
189 //now, before we bring up the menu, we need to
190 //do some stuff to make sure the palette is ok. First, we need to
191 //get our current palette into the 2d's array, so the remapping will
192 //work. Second, we need to remap the fonts. Third, we need to fill
193 //in part of the fade tables so the darkening of the menu edges works
195 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
196 remap_fonts_and_menus(1);
200 WIN(DDGRLOCK(dd_grd_curcanv));
201 #if defined(POLY_ACC)
203 pa_update_clut(gr_palette, 0, 256, 0);
206 #if defined(POLY_ACC)
209 WIN(DDGRUNLOCK(dd_grd_curcanv));
213 strcpy(last_palette_loaded,""); //force palette load next time
217 #define MENU_BACKGROUND_BITMAP ((MenuHires && cfexist("scoresb.pcx"))?"scoresb.pcx":"scores.pcx")
219 int Background_hires;
222 void nm_draw_background(int x1, int y1, int x2, int y2 )
226 if (Newmenu_first_time || MenuHires!=Background_hires) {
229 if (Newmenu_first_time) {
230 atexit( newmenu_close );
231 Newmenu_first_time = 0;
232 nm_background_save.bm_data=NULL;
235 if (nm_background_save.bm_data)
236 d_free(nm_background_save.bm_data);
237 if (nm_background.bm_data)
238 d_free(nm_background.bm_data);
241 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
242 Assert(pcx_error == PCX_ERROR_NONE);
244 nm_background = nm_background_save;
245 nm_background.bm_data=NULL;
246 nm_remap_background();
248 Background_hires = MenuHires;
251 if ( x1 < 0 ) x1 = 0;
252 if ( y1 < 0 ) y1 = 0;
257 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
258 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
264 grs_bitmap *tmp = gr_create_bitmap(w, h);
266 gr_bitmap_scale_to(&nm_background, tmp);
268 WIN(DDGRLOCK(dd_grd_curcanv));
270 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
272 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
277 Gr_scanline_darkening_level = 2*7;
279 gr_setcolor( BM_XRGB(0,0,0) );
280 gr_urect( x2-5, y1+5, x2-5, y2-5 );
281 gr_urect( x2-4, y1+4, x2-4, y2-5 );
282 gr_urect( x2-3, y1+3, x2-3, y2-5 );
283 gr_urect( x2-2, y1+2, x2-2, y2-5 );
284 gr_urect( x2-1, y1+1, x2-1, y2-5 );
285 gr_urect( x2+0, y1+0, x2-0, y2-5 );
287 gr_urect( x1+5, y2-5, x2, y2-5 );
288 gr_urect( x1+4, y2-4, x2, y2-4 );
289 gr_urect( x1+3, y2-3, x2, y2-3 );
290 gr_urect( x1+2, y2-2, x2, y2-2 );
291 gr_urect( x1+1, y2-1, x2, y2-1 );
292 gr_urect( x1+0, y2, x2, y2-0 );
294 WIN(DDGRUNLOCK(dd_grd_curcanv));
296 Gr_scanline_darkening_level = GR_FADE_LEVELS;
299 void nm_restore_background( int x, int y, int w, int h )
306 if ( x1 < 0 ) x1 = 0;
307 if ( y1 < 0 ) y1 = 0;
309 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
310 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
315 WIN(DDGRLOCK(dd_grd_curcanv));
316 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
317 WIN(DDGRUNLOCK(dd_grd_curcanv));
320 // Draw a left justfied string
321 void nm_string( bkg * b, int w1,int x, int y, char * s)
323 int w,h,aw,tx=0,t=0,i;
324 char *p,*s1,*s2,measure[2];
325 int XTabs[]={15,87,124,162,228,253};
331 XTabs[i]=(LHX(XTabs[i]));
338 p = strchr( s2, '\t' );
345 gr_get_string_size(s2, &w, &h, &aw );
351 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
352 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
355 for (i=0;i<strlen(s2);i++) {
356 if (s2[i]=='\t' && SurfingNet) {
362 gr_get_string_size(measure,&tx,&h,&aw);
363 gr_string(x,y,measure);
370 if (!SurfingNet && p && (w1>0) ) {
371 gr_get_string_size(s1, &w, &h, &aw );
373 gr_string( x+w1-w, y, s1 );
380 // Draw a slider and it's string
381 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
388 p = strchr( s, '\t' );
394 gr_get_string_size(s, &w, &h, &aw );
397 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
398 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
400 gr_string( x, y, s );
403 gr_get_string_size(s1, &w, &h, &aw );
406 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
408 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
410 gr_string( x+w1-w, y, s1 );
417 // Draw a left justfied string with black background.
418 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
421 gr_get_string_size(s, &w, &h, &aw );
425 WIN(DDGRLOCK(dd_grd_curcanv));
426 gr_setcolor( BM_XRGB(2,2,2) );
427 gr_rect( x-1, y-1, x-1, y+h-1 );
428 gr_rect( x-1, y-1, x+w1-1, y-1 );
431 gr_setcolor( BM_XRGB(5,5,5) );
432 gr_rect( x, y+h, x+w1, y+h);
433 gr_rect( x+w1, y-1, x+w1, y+h );
435 gr_setcolor( BM_XRGB(0,0,0) );
436 gr_rect( x, y, x+w1-1, y+h-1 );
438 gr_string( x+1, y+1, s );
439 WIN(DDGRUNLOCK(dd_grd_curcanv));
443 // Draw a right justfied string
444 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
447 gr_get_string_size(s, &w, &h, &aw );
452 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
455 WIN(DDGRLOCK(dd_grd_curcanv));
456 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
457 gr_string( x-w, y, s );
458 WIN(DDGRUNLOCK(dd_grd_curcanv));
463 //for text items, constantly redraw cursor (to achieve flash)
464 void update_cursor( newmenu_item *item)
467 fix time = timer_get_approx_seconds();
469 char * text = item->text;
471 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
474 gr_get_string_size(text, &w, &h, &aw );
475 if ( w > item->w-10 )
482 x = item->x+w; y = item->y;
484 WIN(DDGRLOCK(dd_grd_curcanv));
486 gr_string( x, y, CURSOR_STRING );
488 gr_setcolor( BM_XRGB(0,0,0) );
489 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
491 WIN(DDGRUNLOCK(dd_grd_curcanv));
494 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
499 gr_get_string_size(text, &w1, &h1, &aw );
508 nm_string_black( b, w, x, y, text );
511 gr_string( x+w1+1, y, CURSOR_STRING );
515 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
520 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
522 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
524 if (item->text[0]=='\t')
525 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
530 grd_curcanv->cv_font = SELECTED_FONT;
532 grd_curcanv->cv_font = NORMAL_FONT;
535 if (is_current && item->type == NM_TYPE_TEXT)
536 grd_curcanv->cv_font = NORMAL_FONT;
540 WIN(DDGRLOCK(dd_grd_curcanv));
541 switch( item->type ) {
543 // grd_curcanv->cv_font=TEXT_FONT;
544 // fall through on purpose
547 nm_string( b, item->w, item->x, item->y, item->text );
549 case NM_TYPE_SLIDER: {
551 if (item->value < item->min_value) item->value=item->min_value;
552 if (item->value > item->max_value) item->value=item->max_value;
553 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
554 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
555 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
557 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
559 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
561 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
564 case NM_TYPE_INPUT_MENU:
565 if ( item->group==0 ) {
566 nm_string( b, item->w, item->x, item->y, item->text );
568 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
572 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
575 nm_string( b, item->w, item->x, item->y, item->text );
577 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
579 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
582 nm_string( b, item->w, item->x, item->y, item->text );
584 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
586 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
588 case NM_TYPE_NUMBER: {
590 if (item->value < item->min_value) item->value=item->min_value;
591 if (item->value > item->max_value) item->value=item->max_value;
592 nm_string( b, item->w, item->x, item->y, item->text );
593 sprintf( text, "%d", item->value );
594 nm_rstring( b,item->right_offset,item->x, item->y, text );
598 WIN(DDGRUNLOCK(dd_grd_curcanv));
602 char *Newmenu_allowed_chars=NULL;
604 //returns true if char is allowed
605 int char_allowed(char c)
607 char *p = Newmenu_allowed_chars;
615 if (c>=p[0] && c<=p[1])
624 void strip_end_whitespace( char * text )
628 for (i=l-1; i>=0; i-- ) {
629 if ( isspace(text[i]) )
636 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
638 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
640 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
642 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
646 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
648 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
652 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 )
654 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
658 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 )
660 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
662 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 )
664 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
667 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){
668 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
669 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
670 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
673 //returns 1 if a control device button has been pressed
674 int check_button_press()
678 switch (Config_control_type) {
679 case CONTROL_JOYSTICK:
680 case CONTROL_FLIGHTSTICK_PRO:
681 case CONTROL_THRUSTMASTER_FCS:
682 case CONTROL_GRAVIS_GAMEPAD:
684 if (joy_get_button_down_cnt(i)>0) return 1;
687 case CONTROL_CYBERMAN:
688 #ifndef MACINTOSH // don't allow mouse to continue from menu
690 if (mouse_button_down_count(i)>0) return 1;
693 case CONTROL_WINJOYSTICK:
696 if (joy_get_button_down_cnt(i)>0) return 1;
699 case CONTROL_NONE: //keyboard only
701 if (key_checkch()) return 1;
706 Error("Bad control type (Config_control_type):%i",Config_control_type);
712 extern int network_request_player_names(int);
713 extern int RestoringMenu;
715 #if defined(WINDOWS) || defined(MACINTOSH)
716 ubyte Hack_DblClick_MenuMode=0;
719 MAC(extern ubyte joydefs_calibrating;)
723 #define CLOSE_SIZE 10
725 void draw_close_box(int x,int y)
727 WIN (DDGRLOCK(dd_grd_curcanv));
728 gr_setcolor( BM_XRGB(0, 0, 0) );
729 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
730 gr_setcolor( BM_XRGB(21, 21, 21) );
731 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
732 WIN (DDGRUNLOCK(dd_grd_curcanv));
735 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 )
737 int old_keyd_repeat, done;
738 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
739 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
740 grs_font * save_font;
741 int string_width, string_height, average_width;
744 int all_text=0; //set true if all text items
745 int sound_stopped=0,time_stopped=0;
746 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
749 int MaxOnMenu=MAXDISPLAYABLEITEMS;
750 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
751 #if defined(MACINTOSH) || defined(WINDOWS)
752 int mouse_state, omouse_state, dblclick_flag=0;
753 int mx=0, my=0, x1, x2, y1, y2;
757 EventRecord event; // looking for disk inserted events for CD mounts
760 PA_DFX (pa_set_frontbuffer_current());
761 PA_DFX (pa_set_front_to_read());
763 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
772 WIN(mouse_set_mode(0)); //disable centering mode
774 MaxDisplayable=nitems;
777 set_screen_mode(SCREEN_MENU);
781 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
782 digi_pause_digi_sounds();
786 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
799 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
801 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
803 save_font = grd_curcanv->cv_font;
808 grd_curcanv->cv_font = TITLE_FONT;
809 gr_get_string_size(title,&string_width,&string_height,&average_width );
814 grd_curcanv->cv_font = SUBTITLE_FONT;
815 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
816 if (string_width > tw )
821 th += LHY(8); //put some space between titles & body
824 grd_curcanv->cv_font = SMALL_FONT;
826 grd_curcanv->cv_font = NORMAL_FONT;
830 nmenus = nothers = 0;
832 // Find menu height & width (store in w,h)
833 for (i=0; i<nitems; i++ ) {
836 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
837 item[i].right_offset = 0;
840 string_height+=LHY(3);
842 item[i].saved_text[0] = '\0';
844 if ( item[i].type == NM_TYPE_SLIDER ) {
847 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
848 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
849 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
851 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
852 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
853 string_width += w1 + aw;
856 if ( item[i].type == NM_TYPE_MENU ) {
860 if ( item[i].type == NM_TYPE_CHECK ) {
863 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
864 item[i].right_offset = w1;
865 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
866 if (w1 > item[i].right_offset)
867 item[i].right_offset = w1;
870 if (item[i].type == NM_TYPE_RADIO ) {
873 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
874 item[i].right_offset = w1;
875 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
876 if (w1 > item[i].right_offset)
877 item[i].right_offset = w1;
880 if (item[i].type==NM_TYPE_NUMBER ) {
884 sprintf( test_text, "%d", item[i].max_value );
885 gr_get_string_size( test_text, &w1, &h1, &aw1 );
886 item[i].right_offset = w1;
887 sprintf( test_text, "%d", item[i].min_value );
888 gr_get_string_size( test_text, &w1, &h1, &aw1 );
889 if ( w1 > item[i].right_offset)
890 item[i].right_offset = w1;
893 if ( item[i].type == NM_TYPE_INPUT ) {
894 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
895 strcpy(item[i].saved_text, item[i].text );
897 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
898 if ( string_width > MAX_TEXT_WIDTH )
899 string_width = MAX_TEXT_WIDTH;
903 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
904 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
905 strcpy(item[i].saved_text, item[i].text );
907 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
912 item[i].w = string_width;
913 item[i].h = string_height;
915 if ( string_width > w )
916 w = string_width; // Save maximum width
917 if ( average_width > aw )
919 h += string_height+1; // Find the height of all strings
922 // Big hack for allowing the netgame options menu to spill over
924 MaxOnMenu=MAXDISPLAYABLEITEMS;
925 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
928 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
931 h=(MaxOnMenu*(string_height+1)+LHY(8));
932 MaxDisplayable=MaxOnMenu;
933 mprintf ((0,"Hey, this is a scroll box!\n"));
946 for (i=0; i<nitems; i++ ) {
948 if (item[i].right_offset > right_offset )
949 right_offset = item[i].right_offset;
951 if (right_offset > 0 )
954 //gr_get_string_size("",&string_width,&string_height,&average_width );
961 twidth = ( tw - w )/2;
966 { right_offset=0; twidth=0;}
968 mprintf(( 0, "Right offset = %d\n", right_offset ));
971 // Find min point of menu border
972 // x = (grd_curscreen->sc_w-w)/2;
973 // y = (grd_curscreen->sc_h-h)/2;
975 w += MenuHires?60:30;
976 h += MenuHires?60:30;
978 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
979 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
981 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
982 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
987 if ( filename != NULL ) {
988 nm_draw_background1( filename );
989 gr_palette_load(gr_palette);
992 // Save the background of the display
993 // Win95 must refer to the screen as a dd_grs_canvas, so...
994 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
995 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
997 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
998 gr_set_current_canvas(bg.menu_canvas) );
1000 if ( filename == NULL ) {
1001 // Save the background under the menu...
1007 #if defined(POLY_ACC)
1008 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1010 bg.saved = gr_create_bitmap( w, h );
1012 Assert( bg.saved != NULL );
1014 WIN (DDGRLOCK(dd_grd_curcanv));
1015 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1016 WIN (DDGRUNLOCK(dd_grd_curcanv));
1018 WINDOS ( dd_gr_set_current_canvas(NULL),
1019 gr_set_current_canvas( NULL )
1022 nm_draw_background(x,y,x+w-1,y+h-1);
1024 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1025 gr_set_current_canvas( bg.menu_canvas )
1028 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1032 #if defined(POLY_ACC)
1033 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1035 bg.background = gr_create_bitmap( w, h );
1037 Assert( bg.background != NULL );
1039 WIN (DDGRLOCK(dd_grd_curcanv));
1040 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1041 WIN (DDGRUNLOCK(dd_grd_curcanv));
1044 // ty = 15 + (yborder/4);
1046 ty = MenuHires?30:15;
1049 grd_curcanv->cv_font = TITLE_FONT;
1050 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1051 gr_get_string_size(title,&string_width,&string_height,&average_width );
1054 WIN (DDGRLOCK(dd_grd_curcanv));
1055 gr_printf( 0x8000, ty, title );
1056 WIN (DDGRUNLOCK(dd_grd_curcanv));
1061 grd_curcanv->cv_font = SUBTITLE_FONT;
1062 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1063 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1066 WIN (DDGRLOCK(dd_grd_curcanv));
1067 gr_printf( 0x8000, ty, subtitle );
1068 WIN (DDGRUNLOCK(dd_grd_curcanv));
1073 grd_curcanv->cv_font = SMALL_FONT;
1075 grd_curcanv->cv_font = NORMAL_FONT;
1077 // Update all item's x & y values.
1078 for (i=0; i<nitems; i++ ) {
1079 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1080 item[i].y += (MenuHires?30:15);
1081 if ( item[i].type==NM_TYPE_RADIO ) {
1082 fm = -1; // find first marked one
1083 for ( j=0; j<nitems; j++ ) {
1084 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1085 if (fm==-1 && item[j].value)
1097 old_keyd_repeat = keyd_repeat;
1103 if (citem < 0 ) citem = 0;
1104 if (citem > nitems-1 ) citem = nitems-1;
1107 #if defined(WINDOWS) || defined(MACINTOSH)
1111 while ( item[choice].type==NM_TYPE_TEXT ) {
1113 if (choice >= nitems ) {
1116 if (choice == citem ) {
1127 // Clear mouse, joystick to clear button presses.
1128 game_flush_inputs();
1130 #if defined(WINDOWS) || defined(MACINTOSH)
1131 mouse_state = omouse_state = 0;
1132 if (filename == NULL && !MenuReordering) {
1133 draw_close_box(0,0);
1139 if (!MenuReordering) {
1141 SetCursor (LoadCursor(NULL,IDC_ARROW));
1146 if (!joydefs_calibrating)
1150 mprintf ((0,"Set to true!\n"));
1156 DoMessageStuff(&msg);
1158 if (_RedrawScreen) {
1159 _RedrawScreen = FALSE;
1162 gr_free_bitmap(bg.saved);
1163 d_free( bg.background );
1166 gr_free_bitmap(bg.background);
1168 dd_gr_free_sub_canvas( bg.menu_canvas );
1169 grd_curcanv->cv_font = save_font;
1170 dd_grd_curcanv = save_canvas;
1172 goto RePaintNewmenu4;
1181 omouse_state = mouse_state;
1182 mouse_state = mouse_button_state(0);
1183 if (!joydefs_calibrating)
1184 show_cursor(); // possibly hidden
1188 omouse_state = mouse_state;
1189 if (!MenuReordering)
1190 mouse_state = mouse_button_state(0);
1191 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1194 //see if redbook song needs to be restarted
1195 songs_check_redbook_repeat();
1202 (*subfunction)(nitems,item,&k,choice);
1205 if (!time_stopped) {
1206 // Save current menu box
1207 if (multi_menu_poll() == -1)
1213 dont_restore = (k == -3); //-3 means don't restore
1219 if (check_button_press())
1223 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1226 old_choice = choice;
1232 if (SurfingNet && !already_showing_info)
1234 show_extra_netgame_info(choice-2);
1236 if (SurfingNet && already_showing_info)
1243 if (SurfingNet && !already_showing_info)
1245 network_request_player_names(choice-2);
1247 if (SurfingNet && already_showing_info)
1262 case KEY_TAB + KEY_SHIFTED:
1265 if (all_text) break;
1272 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1274 if (choice<TopChoice)
1275 { choice=TopChoice; break; }
1277 if (choice<ScrollOffset)
1279 for (i=0;i<nitems;i++)
1282 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1287 if (choice >= nitems ) choice=0;
1288 if (choice < 0 ) choice=nitems-1;
1290 } while ( item[choice].type==NM_TYPE_TEXT );
1291 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1292 item[choice].value = -1;
1293 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1294 item[old_choice].group=0;
1295 strcpy(item[old_choice].text, item[old_choice].saved_text );
1296 item[old_choice].value = -1;
1299 item[old_choice].redraw = 1;
1300 item[choice].redraw=1;
1305 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1306 if (all_text) break;
1313 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1316 { choice--; break; }
1318 if (choice>=MaxOnMenu+ScrollOffset)
1320 for (i=0;i<nitems;i++)
1323 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1328 if (choice < 0 ) choice=nitems-1;
1329 if (choice >= nitems ) choice=0;
1332 } while ( item[choice].type==NM_TYPE_TEXT );
1334 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1335 item[choice].value = -1;
1336 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1337 item[old_choice].group=0;
1338 strcpy(item[old_choice].text, item[old_choice].saved_text );
1339 item[old_choice].value = -1;
1342 item[old_choice].redraw=1;
1343 item[choice].redraw=1;
1346 if ( choice > -1 ) {
1347 switch( item[choice].type ) {
1350 case NM_TYPE_INPUT_MENU:
1353 if ( item[choice].value )
1354 item[choice].value = 0;
1356 item[choice].value = 1;
1357 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1360 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1362 mprintf ((0,"Special redraw!\n"));
1367 item[choice].redraw=1;
1370 for (i=0; i<nitems; i++ ) {
1371 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1376 item[choice].value = 1;
1377 item[choice].redraw = 1;
1383 case KEY_SHIFTED+KEY_UP:
1384 if (MenuReordering && choice!=TopChoice)
1386 Temp=item[choice].text;
1387 TempVal=item[choice].value;
1388 item[choice].text=item[choice-1].text;
1389 item[choice].value=item[choice-1].value;
1390 item[choice-1].text=Temp;
1391 item[choice-1].value=TempVal;
1392 item[choice].redraw=1;
1393 item[choice-1].redraw=1;
1397 case KEY_SHIFTED+KEY_DOWN:
1398 if (MenuReordering && choice!=(nitems-1))
1400 Temp=item[choice].text;
1401 TempVal=item[choice].value;
1402 item[choice].text=item[choice+1].text;
1403 item[choice].value=item[choice+1].value;
1404 item[choice+1].text=Temp;
1405 item[choice+1].value=TempVal;
1406 item[choice].redraw=1;
1407 item[choice+1].redraw=1;
1414 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1415 item[choice].group = 1;
1416 item[choice].redraw = 1;
1417 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1418 item[choice].text[0] = 0;
1419 item[choice].value = -1;
1421 strip_end_whitespace(item[choice].text);
1428 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1429 item[choice].group=0;
1430 strcpy(item[choice].text, item[choice].saved_text );
1431 item[choice].redraw=1;
1432 item[choice].value = -1;
1439 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1440 case KEY_PRINT_SCREEN:
1442 save_screen_shot(0);
1443 PA_DFX (pa_set_frontbuffer_current());
1444 PA_DFX (pa_set_front_to_read());
1445 for (i=0;i<nitems;i++)
1454 case KEY_COMMAND+KEY_RIGHT:
1455 songs_goto_next_song();
1457 case KEY_COMMAND+KEY_LEFT:
1458 songs_goto_prev_song();
1460 case KEY_COMMAND+KEY_UP:
1461 songs_play_level_song(1);
1463 case KEY_COMMAND+KEY_DOWN:
1464 songs_stop_redbook();
1467 case KEY_COMMAND+KEY_M:
1469 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1470 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1473 key_close(); // no processing of keys with keyboard handler.. jeez
1476 show_boxed_message ("Mounting CD\nESC to quit");
1477 RBAMountDisk(); // OS has totaly control of the CD.
1478 if (Function_mode == FMODE_MENU)
1479 songs_play_song(SONG_TITLE,1);
1480 else if (Function_mode == FMODE_GAME)
1481 songs_play_level_song( Current_level_num );
1482 clear_boxed_message();
1491 case KEY_COMMAND+KEY_E:
1492 songs_stop_redbook();
1494 k = -1; // force key not to register
1497 case KEY_COMMAND+KEY_Q: {
1498 extern void macintosh_quit();
1500 if ( !(Game_mode & GM_MULTI) )
1502 if (!joydefs_calibrating)
1504 k = -1; // force key not to register
1511 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1518 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1520 if ( !done && mouse_state && !omouse_state && !all_text ) {
1521 mouse_get_pos(&mx, &my);
1522 for (i=0; i<nitems; i++ ) {
1523 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1524 x2 = x1 + item[i].w;
1525 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1526 y2 = y1 + item[i].h;
1527 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1528 if (i+ScrollOffset != choice) {
1529 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1532 choice = i + ScrollOffset;
1534 switch( item[choice].type ) {
1536 if ( item[choice].value )
1537 item[choice].value = 0;
1539 item[choice].value = 1;
1540 item[choice].redraw=1;
1547 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1549 mprintf ((0,"Special redraw!\n"));
1556 for (i=0; i<nitems; i++ ) {
1557 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1562 item[choice].value = 1;
1563 item[choice].redraw = 1;
1566 item[old_choice].redraw=1;
1572 if (mouse_state && all_text)
1575 if ( !done && mouse_state && !all_text ) {
1576 mouse_get_pos(&mx, &my);
1578 // check possible scrollbar stuff first
1580 int arrow_width, arrow_height, aw;
1582 if (ScrollOffset != 0) {
1583 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1584 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1585 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1586 x1 = x1 - arrow_width;
1587 y2 = y1 + arrow_height;
1588 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1591 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1593 if (choice<ScrollOffset)
1595 for (i=0;i<nitems;i++)
1598 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1602 if (ScrollOffset+MaxDisplayable<nitems) {
1603 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1604 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1605 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1606 x1 = x1 - arrow_width;
1607 y2 = y1 + arrow_height;
1608 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1611 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1613 if (choice>=MaxOnMenu+ScrollOffset)
1615 for (i=0;i<nitems;i++)
1618 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1624 for (i=0; i<nitems; i++ ) {
1625 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1626 x2 = x1 + item[i].w;
1627 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1628 y2 = y1 + item[i].h;
1629 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1630 if (i+ScrollOffset != choice) {
1631 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1634 choice = i + ScrollOffset;
1636 if ( item[choice].type == NM_TYPE_SLIDER ) {
1637 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1638 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1640 strcpy(slider_text, item[choice].saved_text);
1641 p = strchr(slider_text, '\t');
1647 gr_get_string_size(s1, &slider_width, &height, &aw);
1648 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1649 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1650 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1652 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1653 x2 = x1 + slider_width + sright_width;
1654 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1655 item[choice].value = item[choice].min_value;
1656 item[choice].redraw = 2;
1657 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1658 item[choice].value = item[choice].max_value;
1659 item[choice].redraw = 2;
1660 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1661 int num_values, value_width, new_value;
1663 num_values = item[choice].max_value - item[choice].min_value + 1;
1664 value_width = (slider_width - sleft_width - sright_width) / num_values;
1665 new_value = (mx - x1 - sleft_width) / value_width;
1666 if ( item[choice].value != new_value ) {
1667 item[choice].value = new_value;
1668 item[choice].redraw = 2;
1674 if (choice == old_choice)
1676 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1677 item[choice].value = -1;
1678 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1679 item[old_choice].group=0;
1680 strcpy(item[old_choice].text, item[old_choice].saved_text );
1681 item[old_choice].value = -1;
1684 item[old_choice].redraw = 1;
1685 item[choice].redraw=1;
1691 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1692 mouse_get_pos(&mx, &my);
1693 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1694 x2 = x1 + item[choice].w;
1695 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1696 y2 = y1 + item[choice].h;
1697 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1698 if (Hack_DblClick_MenuMode) {
1699 if (dblclick_flag) done = 1;
1700 else dblclick_flag = 1;
1706 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1707 item[choice].group = 1;
1708 item[choice].redraw = 1;
1709 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1710 item[choice].text[0] = 0;
1711 item[choice].value = -1;
1713 strip_end_whitespace(item[choice].text);
1717 if ( !done && !mouse_state && omouse_state && close_box ) {
1718 mouse_get_pos(&mx, &my);
1719 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1720 x2 = x1 + CLOSE_SIZE;
1721 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1722 y2 = y1 + CLOSE_SIZE;
1723 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1729 // HACK! Don't redraw loadgame preview
1730 if (RestoringMenu) item[0].redraw = 0;
1731 #endif // ifdef MACINTOSH
1733 if ( choice > -1 ) {
1736 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1737 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1738 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1739 if (item[choice].value > 0)
1740 item[choice].value--;
1741 item[choice].text[item[choice].value] = 0;
1742 item[choice].redraw = 1;
1744 ascii = key_to_ascii(k);
1745 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1749 if (item[choice].value==-1) {
1750 item[choice].value = 0;
1753 allowed = char_allowed(ascii);
1755 if (!allowed && ascii==' ' && char_allowed('_')) {
1761 item[choice].text[item[choice].value++] = ascii;
1762 item[choice].text[item[choice].value] = 0;
1763 item[choice].redraw=1;
1767 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1768 ascii = key_to_ascii(k);
1770 int choice1 = choice;
1771 ascii = toupper(ascii);
1775 if (choice1 >= nitems ) choice1=0;
1776 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1777 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1778 (item[choice1].type==NM_TYPE_CHECK) ||
1779 (item[choice1].type==NM_TYPE_RADIO) ||
1780 (item[choice1].type==NM_TYPE_NUMBER) ||
1781 (item[choice1].type==NM_TYPE_SLIDER) )
1782 && (ascii==toupper(ch)) ) {
1786 item[old_choice].redraw=1;
1787 item[choice].redraw=1;
1789 } while (choice1 != choice );
1793 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1794 int ov=item[choice].value;
1799 case KEY_MINUS+KEY_SHIFTED:
1801 item[choice].value -= 1;
1806 case KEY_EQUAL+KEY_SHIFTED:
1808 item[choice].value++;
1813 item[choice].value += 10;
1818 item[choice].value -= 10;
1821 if (ov!=item[choice].value)
1822 item[choice].redraw=1;
1827 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1828 gr_set_current_canvas(bg.menu_canvas));
1830 // Redraw everything...
1831 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1833 if (item[i].redraw) // warning! ugly hack below
1835 item[i].y-=((string_height+1)*ScrollOffset);
1838 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1840 MAC(if (!joydefs_calibrating) show_cursor());
1841 WIN(if (!MenuReordering) ShowCursorW());
1842 item[i].y+=((string_height+1)*ScrollOffset);
1844 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1845 update_cursor( &item[i]);
1851 //grd_curcanv->cv_font = NORMAL_FONT;
1853 if (LastScrollCheck!=ScrollOffset)
1855 LastScrollCheck=ScrollOffset;
1856 grd_curcanv->cv_font = SELECTED_FONT;
1858 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1859 sx=item[ScrollOffset].x-(MenuHires?24:12);
1862 if (ScrollOffset!=0)
1863 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1865 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1867 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1868 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1870 if (ScrollOffset+MaxDisplayable<nitems)
1871 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1873 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1879 if ( !dont_restore && gr_palette_faded_out ) {
1880 gr_palette_fade_in( gr_palette, 32, 0 );
1887 // Restore everything...
1889 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1890 gr_set_current_canvas(bg.menu_canvas));
1892 if ( filename == NULL ) {
1893 // Save the background under the menu...
1894 WIN (DDGRLOCK(dd_grd_curcanv));
1895 gr_bitmap(0, 0, bg.saved);
1896 WIN (DDGRUNLOCK(dd_grd_curcanv));
1897 gr_free_bitmap(bg.saved);
1898 d_free( bg.background );
1900 if (!dont_restore) //info passed back from subfunction
1902 WIN (DDGRLOCK(dd_grd_curcanv));
1903 gr_bitmap(0, 0, bg.background);
1904 WIN (DDGRUNLOCK(dd_grd_curcanv));
1906 gr_free_bitmap(bg.background);
1909 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1910 gr_free_sub_canvas( bg.menu_canvas ) );
1912 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1913 grd_curcanv->cv_font = save_font;
1914 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1915 keyd_repeat = old_keyd_repeat;
1917 game_flush_inputs();
1928 if ( sound_stopped )
1929 digi_resume_digi_sounds();
1931 WIN(mouse_set_mode(1)); //re-enable centering mode
1938 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1944 char nm_text[MESSAGEBOX_TEXT_SIZE];
1945 newmenu_item nm_message_items[5];
1947 va_start(args, nchoices );
1949 Assert( nchoices <= 5 );
1951 for (i=0; i<nchoices; i++ ) {
1952 s = va_arg( args, char * );
1953 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1955 format = va_arg( args, char * );
1956 strcpy( nm_text, "" );
1957 vsprintf(nm_text,format,args);
1960 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1962 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1965 int nm_messagebox( char *title, int nchoices, ... )
1971 char nm_text[MESSAGEBOX_TEXT_SIZE];
1972 newmenu_item nm_message_items[5];
1974 va_start(args, nchoices );
1976 Assert( nchoices <= 5 );
1978 for (i=0; i<nchoices; i++ ) {
1979 s = va_arg( args, char * );
1980 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1982 format = va_arg( args, char * );
1983 strcpy( nm_text, "" );
1984 vsprintf(nm_text,format,args);
1987 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1989 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1995 void newmenu_file_sort( int n, char *list )
2002 for (i=incr; i<n; i++ ) {
2005 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
2006 memcpy( t, &list[j*14], FILENAME_LEN );
2007 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
2008 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2019 void delete_player_saved_games(char * name)
2024 for (i=0;i<10; i++) {
2026 sprintf( filename, "%s.sg%d", name, i );
2028 sprintf( filename, ":Players:%s.sg%d", name, i );
2034 #define MAX_FILES 300
2036 int MakeNewPlayerFile(int allow_abort);
2038 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2041 FILEFINDSTRUCT find;
2042 int NumFiles=0, key,done, citem, ocitem;
2043 char * filenames = NULL;
2044 int NumFiles_displayed = 8;
2045 int first_item = -1, ofirst_item;
2046 int old_keyd_repeat = keyd_repeat;
2049 int demos_deleted=0;
2050 int initialized = 0;
2052 int w_x, w_y, w_w, w_h, title_height;
2053 int box_x, box_y, box_w, box_h;
2054 bkg bg; // background under listbox
2055 #if defined(MACINTOSH) || defined(WINDOWS)
2056 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2057 int mouse2_state, omouse2_state;
2058 int dblclick_flag=0;
2060 int show_up_arrow=0,show_down_arrow=0;
2062 WIN(int win_redraw=0);
2064 w_x=w_y=w_w=w_h=title_height=0;
2065 box_x=box_y=box_w=box_h=0;
2067 filenames = d_malloc( MAX_FILES * 14 );
2068 if (filenames==NULL) return 0;
2073 WIN(mouse_set_mode(0)); //disable centering mode
2075 if (strstr( filespec, "*.plr" ))
2077 else if (strstr( filespec, "*.dem" ))
2084 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2086 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2091 if( !FileFindFirst( filespec, &find ) ) {
2093 if (NumFiles<MAX_FILES) {
2094 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2095 if ( player_mode ) {
2097 p = strchr(&filenames[NumFiles*14],'.');
2104 } while( !FileFindNext( &find ) );
2108 if ( (NumFiles < 1) && demos_deleted ) {
2112 if ( (NumFiles < 1) && demo_mode ) {
2113 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2119 if ( (NumFiles < 2) && player_mode ) {
2121 goto ExitFileMenuEarly;
2128 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2135 // set_screen_mode(SCREEN_MENU);
2141 dd_gr_set_current_canvas(NULL);
2143 gr_set_current_canvas(NULL);
2146 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2148 grd_curcanv->cv_font = SUBTITLE_FONT;
2150 WIN(DDGRUNLOCK(dd_grd_curcanv));
2155 for (i=0; i<NumFiles; i++ ) {
2157 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2163 gr_get_string_size( title, &w, &h, &aw );
2166 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2170 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2172 w_w += (grd_curfont->ft_w * 4);
2173 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2175 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2176 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2178 w_x = (grd_curcanv->cv_w-w_w)/2;
2179 w_y = (grd_curcanv->cv_h-w_h)/2;
2181 if ( w_x < 0 ) w_x = 0;
2182 if ( w_y < 0 ) w_y = 0;
2184 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2185 box_y = w_y + title_height;
2187 // save the screen behind the menu.
2191 #if !defined(WINDOWS)
2192 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2193 bg.background = &VR_offscreen_buffer->cv_bitmap;
2196 #if defined(POLY_ACC)
2197 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2199 bg.background = gr_create_bitmap( w_w, w_h );
2202 Assert( bg.background != NULL );
2205 WIN(DDGRLOCK(dd_grd_curcanv));
2206 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2207 WIN(DDGRUNLOCK(dd_grd_curcanv));
2211 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2212 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2213 dd_VR_offscreen_buffer, 0, 0,
2214 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2215 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2219 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2221 WIN(DDGRLOCK(dd_grd_curcanv))
2223 gr_string( 0x8000, w_y+10, title );
2225 WIN(DDGRUNLOCK(dd_grd_curcanv));
2232 if ( !player_mode ) {
2233 newmenu_file_sort( NumFiles, filenames );
2235 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2236 newmenu_file_sort( NumFiles, filenames );
2238 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2240 for ( i=0; i<NumFiles; i++ ) {
2241 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2242 #if defined(WINDOWS) || defined(MACINTOSH)
2250 #if defined(MACINTOSH) || defined(WINDOWS)
2251 mouse_state = omouse_state = 0;
2252 mouse2_state = omouse2_state = 0;
2253 draw_close_box(w_x,w_y);
2265 DoMessageStuff(&msg);
2267 if (_RedrawScreen) {
2268 _RedrawScreen = FALSE;
2270 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2271 gr_free_bitmap(bg.background);
2274 goto RePaintNewmenuFile;
2281 ofirst_item = first_item;
2284 #if defined(MACINTOSH) || defined(WINDOWS)
2285 omouse_state = mouse_state;
2286 omouse2_state = mouse2_state;
2287 mouse_state = mouse_button_state(0);
2288 mouse2_state = mouse_button_state(1);
2291 //see if redbook song needs to be restarted
2292 songs_check_redbook_repeat();
2295 if (!mouse2_state && omouse2_state)
2296 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2299 //NOTE LINK TO ABOVE ELSE
2305 else if (simukey==1)
2311 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2312 case KEY_PRINT_SCREEN:
2314 save_screen_shot(0);
2315 PA_DFX (pa_set_frontbuffer_current());
2316 PA_DFX (pa_set_front_to_read());
2322 case KEY_CTRLED+KEY_D:
2323 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2327 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2331 mouse_set_mode(1); //re-enable centering mode
2335 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2337 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2340 mouse_set_mode(0); //disenable centering mode
2346 char name[_MAX_PATH],dir[_MAX_DIR];
2348 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2352 _splitpath(filespec,name,dir,NULL,NULL);
2354 strcat(name,&filenames[citem*14]);
2361 if ( !strncmp(name, ".\\", 2) )
2362 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2363 name[i] = name[i+1];
2364 while ( (p = strchr(name, '\\')) )
2369 ret = unlink( name );
2373 if ((!ret) && player_mode) {
2374 delete_player_saved_games( &filenames[citem*14] );
2379 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2381 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2382 } else if (demo_mode)
2407 citem += NumFiles_displayed;
2411 citem -= NumFiles_displayed;
2414 if (allow_abort_flag) {
2425 case KEY_COMMAND+KEY_Q: {
2426 extern void macintosh_quit();
2428 if ( !(Game_mode & GM_MULTI) )
2439 int ascii = key_to_ascii(key);
2440 if ( ascii < 255 ) {
2443 if (cc1 < 0 ) cc1 = 0;
2444 if (cc1 >= NumFiles ) cc1 = 0;
2446 if ( cc < 0 ) cc = 0;
2447 if ( cc >= NumFiles ) cc = 0;
2448 if ( citem == cc ) break;
2450 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2465 if (citem>=NumFiles)
2468 if (citem< first_item)
2471 if (citem>=( first_item+NumFiles_displayed))
2473 first_item = citem-NumFiles_displayed+1;
2477 if (NumFiles>first_item+NumFiles_displayed)
2488 if (NumFiles <= NumFiles_displayed )
2491 if (first_item>NumFiles-NumFiles_displayed)
2493 first_item = NumFiles-NumFiles_displayed;
2496 if (first_item < 0 ) first_item = 0;
2498 #if defined(MACINTOSH) || defined(WINDOWS)
2500 if (mouse_state || mouse2_state) {
2503 mouse_get_pos(&mx, &my);
2504 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2505 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2507 x2 = box_x + box_w - 1;
2508 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2510 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2511 if (i == citem && !mouse2_state) {
2521 if (!mouse_state && omouse_state) {
2524 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2525 mouse_get_pos(&mx, &my);
2527 x2 = box_x + box_w - 1;
2528 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2530 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2531 if (dblclick_flag) done = 1;
2532 else dblclick_flag = 1;
2536 if ( !mouse_state && omouse_state ) {
2537 mouse_get_pos(&mx, &my);
2538 x1 = w_x + CLOSE_X + 2;
2539 x2 = x1 + CLOSE_SIZE - 2;
2540 y1 = w_y + CLOSE_Y + 2;
2541 y2 = y1 + CLOSE_SIZE - 2;
2542 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2551 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2553 y1 = box_y+box_h-LHY(7);
2555 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2562 WIN(DDGRLOCK(dd_grd_curcanv));
2563 gr_setcolor( BM_XRGB(2,2,2));
2564 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2565 gr_setcolor( BM_XRGB( 0,0,0) );
2568 if (ofirst_item != first_item || win_redraw) {
2571 if (ofirst_item != first_item) {
2575 gr_setcolor( BM_XRGB( 0,0,0) );
2576 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2578 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2580 if ( i >= NumFiles ) {
2582 gr_setcolor( BM_XRGB(5,5,5));
2583 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2584 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2586 gr_setcolor( BM_XRGB(2,2,2));
2587 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2589 gr_setcolor( BM_XRGB(0,0,0));
2590 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2594 grd_curcanv->cv_font = SELECTED_FONT;
2596 grd_curcanv->cv_font = NORMAL_FONT;
2597 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2599 gr_setcolor( BM_XRGB(5,5,5));
2600 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2601 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2603 gr_setcolor( BM_XRGB(2,2,2));
2604 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2605 gr_setcolor( BM_XRGB(0,0,0));
2607 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2608 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2613 } else if ( citem != ocitem ) {
2619 if ( (i>=0) && (i<NumFiles) ) {
2620 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2622 grd_curcanv->cv_font = SELECTED_FONT;
2624 grd_curcanv->cv_font = NORMAL_FONT;
2625 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2626 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2627 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2630 if ( (i>=0) && (i<NumFiles) ) {
2631 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2633 grd_curcanv->cv_font = SELECTED_FONT;
2635 grd_curcanv->cv_font = NORMAL_FONT;
2636 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2637 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2638 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2645 grd_curcanv->cv_font = NORMAL_FONT;
2647 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2651 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2655 if (show_down_arrow)
2656 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2660 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2668 WIN(DDGRUNLOCK(dd_grd_curcanv));
2674 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2681 keyd_repeat = old_keyd_repeat;
2683 if ( initialized ) {
2684 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2686 WIN (DDGRLOCK(dd_grd_curcanv));
2687 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2688 WIN (DDGRUNLOCK(dd_grd_curcanv));
2690 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2691 gr_free_bitmap(bg.background);
2694 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2695 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2697 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2698 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2708 WIN(mouse_set_mode(1)); //re-enable centering mode
2716 // Example listbox callback function...
2717 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2721 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2722 // if ( *nitems > 1 ) {
2723 // unlink( items[*citem] ); // Delete the file
2724 // for (i=*citem; i<*nitems-1; i++ ) {
2725 // items[i] = items[i+1];
2727 // *nitems = *nitems - 1;
2728 // d_free( items[*nitems] );
2729 // items[*nitems] = NULL;
2730 // return 1; // redraw;
2737 #define LB_ITEMS_ON_SCREEN 8
2739 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2741 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2744 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 ) )
2747 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2748 int old_keyd_repeat = keyd_repeat;
2749 int width, height, wx, wy, title_height, border_size;
2750 int total_width,total_height;
2752 #if defined(MACINTOSH) || defined(WINDOWS)
2753 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2754 int close_x,close_y;
2755 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2757 WIN(int win_redraw=0);
2761 PA_DFX (pa_set_frontbuffer_current());
2762 PA_DFX (pa_set_front_to_read());
2763 WIN(mouse_set_mode(0)); //disable centering mode
2765 // set_screen_mode(SCREEN_MENU);
2769 RePaintNewmenuListbox:
2771 dd_gr_set_current_canvas(NULL);
2773 gr_set_current_canvas(NULL);
2776 grd_curcanv->cv_font = SUBTITLE_FONT;
2779 for (i=0; i<nitems; i++ ) {
2781 gr_get_string_size( items[i], &w, &h, &aw );
2785 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2789 gr_get_string_size( title, &w, &h, &aw );
2792 title_height = h + 5;
2795 border_size = grd_curfont->ft_w;
2796 WIN (border_size=grd_curfont->ft_w*2);
2798 width += (grd_curfont->ft_w);
2799 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2800 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2802 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2803 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2804 if ( wy < title_height )
2807 total_width = width+2*border_size;
2808 total_height = height+2*border_size+title_height;
2812 #if !defined(WINDOWS)
2813 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2814 bg.background = &VR_offscreen_buffer->cv_bitmap;
2817 //bg.background = gr_create_bitmap( width, (height + title_height) );
2818 #if defined(POLY_ACC)
2819 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2821 bg.background = gr_create_bitmap(total_width,total_height);
2823 Assert( bg.background != NULL );
2825 WIN (DDGRLOCK(dd_grd_curcanv));
2826 //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 );
2827 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2828 WIN (DDGRUNLOCK(dd_grd_curcanv));
2832 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2833 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2834 dd_VR_offscreen_buffer, 0, 0,
2835 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2836 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2840 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2842 WIN(DDGRLOCK(dd_grd_curcanv));
2843 gr_string( 0x8000, wy - title_height, title );
2844 WIN(DDGRUNLOCK(dd_grd_curcanv));
2849 citem = default_item;
2850 if ( citem < 0 ) citem = 0;
2851 if ( citem >= nitems ) citem = 0;
2855 #if defined(MACINTOSH) || defined(WINDOWS)
2856 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2857 close_x = wx-border_size;
2858 close_y = wy-title_height-border_size;
2859 draw_close_box(close_x,close_y);
2871 DoMessageStuff(&msg);
2873 if (_RedrawScreen) {
2874 _RedrawScreen = FALSE;
2876 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2877 gr_free_bitmap(bg.background);
2879 goto RePaintNewmenuListbox;
2886 ofirst_item = first_item;
2887 #if defined(MACINTOSH) || defined(WINDOWS)
2888 omouse_state = mouse_state;
2889 mouse_state = mouse_button_state(0);
2891 //see if redbook song needs to be restarted
2892 songs_check_redbook_repeat();
2896 if ( listbox_callback )
2897 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2918 else if (simukey==1)
2924 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2925 case KEY_PRINT_SCREEN:
2927 save_screen_shot(0);
2928 PA_DFX (pa_set_frontbuffer_current());
2929 PA_DFX (pa_set_front_to_read());
2952 citem += LB_ITEMS_ON_SCREEN;
2956 citem -= LB_ITEMS_ON_SCREEN;
2959 if (allow_abort_flag) {
2970 case KEY_COMMAND+KEY_Q: {
2971 extern void macintosh_quit();
2973 if ( !(Game_mode & GM_MULTI) )
2983 int ascii = key_to_ascii(key);
2984 if ( ascii < 255 ) {
2987 if (cc1 < 0 ) cc1 = 0;
2988 if (cc1 >= nitems ) cc1 = 0;
2990 if ( cc < 0 ) cc = 0;
2991 if ( cc >= nitems ) cc = 0;
2992 if ( citem == cc ) break;
2994 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
3011 if (citem< first_item)
3014 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
3015 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3017 if (nitems <= LB_ITEMS_ON_SCREEN )
3020 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3021 first_item = nitems-LB_ITEMS_ON_SCREEN;
3022 if (first_item < 0 ) first_item = 0;
3025 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3036 #if defined(MACINTOSH) || defined(WINDOWS)
3041 mouse_get_pos(&mx, &my);
3042 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3045 gr_get_string_size(items[i], &w, &h, &aw );
3048 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3050 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3062 //no double-click stuff for listbox
3063 //@@if (!mouse_state && omouse_state) {
3066 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3067 //@@ mouse_get_pos(&mx, &my);
3069 //@@ x2 = wx + width;
3070 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3072 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3073 //@@ if (dblclick_flag) done = 1;
3077 //check for close box clicked
3078 if ( !mouse_state && omouse_state ) {
3079 mouse_get_pos(&mx, &my);
3080 x1 = close_x + CLOSE_X + 2;
3081 x2 = x1 + CLOSE_SIZE - 2;
3082 y1 = close_y + CLOSE_Y + 2;
3083 y2 = y1 + CLOSE_SIZE - 2;
3084 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3094 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3096 y1 = total_height-LHY(7);
3098 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3106 if ( (ofirst_item != first_item) || redraw) {
3109 WIN(DDGRLOCK(dd_grd_curcanv));
3111 gr_setcolor( BM_XRGB( 0,0,0) );
3112 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3114 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3115 if ( i >= nitems ) {
3116 gr_setcolor( BM_XRGB(0,0,0));
3117 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3120 grd_curcanv->cv_font = SELECTED_FONT;
3122 grd_curcanv->cv_font = NORMAL_FONT;
3123 gr_get_string_size(items[i], &w, &h, &aw );
3124 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3125 gr_string( wx+5, y, items[i] );
3130 // If Win95 port, draw up/down arrows on left side of menu
3132 grd_curcanv->cv_font = NORMAL_FONT;
3134 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3138 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3142 if (show_down_arrow)
3143 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3147 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3154 WIN(DDGRUNLOCK(dd_grd_curcanv));
3158 } else if ( citem != ocitem ) {
3164 WIN(DDGRLOCK(dd_grd_curcanv));
3167 if ( (i>=0) && (i<nitems) ) {
3168 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3170 grd_curcanv->cv_font = SELECTED_FONT;
3172 grd_curcanv->cv_font = NORMAL_FONT;
3173 gr_get_string_size(items[i], &w, &h, &aw );
3174 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3175 gr_string( wx+5, y, items[i] );
3179 if ( (i>=0) && (i<nitems) ) {
3180 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3182 grd_curcanv->cv_font = SELECTED_FONT;
3184 grd_curcanv->cv_font = NORMAL_FONT;
3185 gr_get_string_size( items[i], &w, &h, &aw );
3186 gr_rect( wx, y-1, wx+width-1, y+h );
3187 gr_string( wx+5, y, items[i] );
3189 WIN(DDGRUNLOCK(dd_grd_curcanv));
3199 keyd_repeat = old_keyd_repeat;
3201 WIN (DDGRLOCK(dd_grd_curcanv));
3202 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3203 WIN (DDGRUNLOCK(dd_grd_curcanv));
3205 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3206 gr_free_bitmap(bg.background);
3210 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3211 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3213 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3214 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3220 WIN(mouse_set_mode(1)); //re-enable centering mode
3225 int newmenu_filelist( char * title, char * filespec, char * filename )
3228 char * Filenames[MAX_FILES];
3229 char FilenameText[MAX_FILES][14];
3230 FILEFINDSTRUCT find;
3233 if( !FileFindFirst( filespec, &find ) ) {
3235 if (NumFiles<MAX_FILES) {
3236 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3237 Filenames[NumFiles] = FilenameText[NumFiles];
3242 } while( !FileFindNext( &find ) );
3246 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3248 strcpy( filename, Filenames[i] );
3254 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3255 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3261 char nm_text[MESSAGEBOX_TEXT_SIZE];
3262 newmenu_item nm_message_items[5];
3264 va_start(args, nchoices );
3266 Assert( nchoices <= 5 );
3268 for (i=0; i<nchoices; i++ ) {
3269 s = va_arg( args, char * );
3270 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3272 format = va_arg( args, char * );
3273 //sprintf( nm_text, "" ); // adb: ?
3274 vsprintf(nm_text,format,args);
3277 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3279 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3281 //end this section addition - Victor Rachels
3284 extern netgame_info Active_games[];
3285 extern int NumActiveNetgames;
3287 void show_extra_netgame_info(int choice)
3293 if (choice>=NumActiveNetgames)
3298 m[i].text=(char *)&mtext[i];
3299 m[i].type=NM_TYPE_TEXT;
3302 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3303 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3304 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3305 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3307 already_showing_info=1;
3308 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3309 already_showing_info=0;
3314 /* Spiffy word wrap string formatting function */
3316 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3322 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3325 wordptr = strtok(tbuf, " ");
3326 if (!wordptr) return;
3332 col = col+strlen(wordptr)+1;
3333 if (col >=line_length) {
3335 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3338 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3340 wordptr = strtok(NULL, " ");