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_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
218 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
220 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
222 int Background_hires;
225 void nm_draw_background(int x1, int y1, int x2, int y2 )
229 if (Newmenu_first_time || MenuHires!=Background_hires) {
232 if (Newmenu_first_time) {
233 atexit( newmenu_close );
234 Newmenu_first_time = 0;
235 nm_background_save.bm_data=NULL;
238 if (nm_background_save.bm_data)
239 d_free(nm_background_save.bm_data);
240 if (nm_background.bm_data)
241 d_free(nm_background.bm_data);
244 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
245 Assert(pcx_error == PCX_ERROR_NONE);
247 nm_background = nm_background_save;
248 nm_background.bm_data=NULL;
249 nm_remap_background();
251 Background_hires = MenuHires;
254 if ( x1 < 0 ) x1 = 0;
255 if ( y1 < 0 ) y1 = 0;
260 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
261 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
267 grs_bitmap *tmp = gr_create_bitmap(w, h);
269 gr_bitmap_scale_to(&nm_background, tmp);
271 WIN(DDGRLOCK(dd_grd_curcanv));
273 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
275 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
280 Gr_scanline_darkening_level = 2*7;
282 gr_setcolor( BM_XRGB(0,0,0) );
283 gr_urect( x2-5, y1+5, x2-5, y2-5 );
284 gr_urect( x2-4, y1+4, x2-4, y2-5 );
285 gr_urect( x2-3, y1+3, x2-3, y2-5 );
286 gr_urect( x2-2, y1+2, x2-2, y2-5 );
287 gr_urect( x2-1, y1+1, x2-1, y2-5 );
288 gr_urect( x2+0, y1+0, x2-0, y2-5 );
290 gr_urect( x1+5, y2-5, x2, y2-5 );
291 gr_urect( x1+4, y2-4, x2, y2-4 );
292 gr_urect( x1+3, y2-3, x2, y2-3 );
293 gr_urect( x1+2, y2-2, x2, y2-2 );
294 gr_urect( x1+1, y2-1, x2, y2-1 );
295 gr_urect( x1+0, y2, x2, y2-0 );
297 WIN(DDGRUNLOCK(dd_grd_curcanv));
299 Gr_scanline_darkening_level = GR_FADE_LEVELS;
302 void nm_restore_background( int x, int y, int w, int h )
309 if ( x1 < 0 ) x1 = 0;
310 if ( y1 < 0 ) y1 = 0;
312 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
313 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
318 WIN(DDGRLOCK(dd_grd_curcanv));
319 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
320 WIN(DDGRUNLOCK(dd_grd_curcanv));
323 // Draw a left justfied string
324 void nm_string( bkg * b, int w1,int x, int y, char * s)
326 int w,h,aw,tx=0,t=0,i;
327 char *p,*s1,*s2,measure[2];
328 int XTabs[]={15,87,124,162,228,253};
334 XTabs[i]=(LHX(XTabs[i]));
341 p = strchr( s2, '\t' );
348 gr_get_string_size(s2, &w, &h, &aw );
354 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
355 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
358 for (i=0;i<strlen(s2);i++) {
359 if (s2[i]=='\t' && SurfingNet) {
365 gr_get_string_size(measure,&tx,&h,&aw);
366 gr_string(x,y,measure);
373 if (!SurfingNet && p && (w1>0) ) {
374 gr_get_string_size(s1, &w, &h, &aw );
376 gr_string( x+w1-w, y, s1 );
383 // Draw a slider and it's string
384 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
391 p = strchr( s, '\t' );
397 gr_get_string_size(s, &w, &h, &aw );
400 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
401 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
403 gr_string( x, y, s );
406 gr_get_string_size(s1, &w, &h, &aw );
409 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
411 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
413 gr_string( x+w1-w, y, s1 );
420 // Draw a left justfied string with black background.
421 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
424 gr_get_string_size(s, &w, &h, &aw );
428 WIN(DDGRLOCK(dd_grd_curcanv));
429 gr_setcolor( BM_XRGB(2,2,2) );
430 gr_rect( x-1, y-1, x-1, y+h-1 );
431 gr_rect( x-1, y-1, x+w1-1, y-1 );
434 gr_setcolor( BM_XRGB(5,5,5) );
435 gr_rect( x, y+h, x+w1, y+h);
436 gr_rect( x+w1, y-1, x+w1, y+h );
438 gr_setcolor( BM_XRGB(0,0,0) );
439 gr_rect( x, y, x+w1-1, y+h-1 );
441 gr_string( x+1, y+1, s );
442 WIN(DDGRUNLOCK(dd_grd_curcanv));
446 // Draw a right justfied string
447 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
450 gr_get_string_size(s, &w, &h, &aw );
455 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
458 WIN(DDGRLOCK(dd_grd_curcanv));
459 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
460 gr_string( x-w, y, s );
461 WIN(DDGRUNLOCK(dd_grd_curcanv));
466 //for text items, constantly redraw cursor (to achieve flash)
467 void update_cursor( newmenu_item *item)
470 fix time = timer_get_approx_seconds();
472 char * text = item->text;
474 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
477 gr_get_string_size(text, &w, &h, &aw );
478 if ( w > item->w-10 )
485 x = item->x+w; y = item->y;
487 WIN(DDGRLOCK(dd_grd_curcanv));
489 gr_string( x, y, CURSOR_STRING );
491 gr_setcolor( BM_XRGB(0,0,0) );
492 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
494 WIN(DDGRUNLOCK(dd_grd_curcanv));
497 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
502 gr_get_string_size(text, &w1, &h1, &aw );
511 nm_string_black( b, w, x, y, text );
514 gr_string( x+w1+1, y, CURSOR_STRING );
518 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
523 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
525 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
527 if (item->text[0]=='\t')
528 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
533 grd_curcanv->cv_font = SELECTED_FONT;
535 grd_curcanv->cv_font = NORMAL_FONT;
538 if (is_current && item->type == NM_TYPE_TEXT)
539 grd_curcanv->cv_font = NORMAL_FONT;
543 WIN(DDGRLOCK(dd_grd_curcanv));
544 switch( item->type ) {
546 // grd_curcanv->cv_font=TEXT_FONT;
547 // fall through on purpose
550 nm_string( b, item->w, item->x, item->y, item->text );
552 case NM_TYPE_SLIDER: {
554 if (item->value < item->min_value) item->value=item->min_value;
555 if (item->value > item->max_value) item->value=item->max_value;
556 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
557 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
558 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
560 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
562 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
564 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
567 case NM_TYPE_INPUT_MENU:
568 if ( item->group==0 ) {
569 nm_string( b, item->w, item->x, item->y, item->text );
571 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
575 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
578 nm_string( b, item->w, item->x, item->y, item->text );
580 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
582 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
585 nm_string( b, item->w, item->x, item->y, item->text );
587 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
589 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
591 case NM_TYPE_NUMBER: {
593 if (item->value < item->min_value) item->value=item->min_value;
594 if (item->value > item->max_value) item->value=item->max_value;
595 nm_string( b, item->w, item->x, item->y, item->text );
596 sprintf( text, "%d", item->value );
597 nm_rstring( b,item->right_offset,item->x, item->y, text );
601 WIN(DDGRUNLOCK(dd_grd_curcanv));
605 char *Newmenu_allowed_chars=NULL;
607 //returns true if char is allowed
608 int char_allowed(char c)
610 char *p = Newmenu_allowed_chars;
618 if (c>=p[0] && c<=p[1])
627 void strip_end_whitespace( char * text )
631 for (i=l-1; i>=0; i-- ) {
632 if ( isspace(text[i]) )
639 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
641 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
643 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
645 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
649 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
651 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
655 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 )
657 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
661 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 )
663 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
665 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 )
667 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
670 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){
671 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
672 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
673 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
676 //returns 1 if a control device button has been pressed
677 int check_button_press()
681 switch (Config_control_type) {
682 case CONTROL_JOYSTICK:
683 case CONTROL_FLIGHTSTICK_PRO:
684 case CONTROL_THRUSTMASTER_FCS:
685 case CONTROL_GRAVIS_GAMEPAD:
687 if (joy_get_button_down_cnt(i)>0) return 1;
690 case CONTROL_CYBERMAN:
691 #ifndef MACINTOSH // don't allow mouse to continue from menu
693 if (mouse_button_down_count(i)>0) return 1;
696 case CONTROL_WINJOYSTICK:
699 if (joy_get_button_down_cnt(i)>0) return 1;
702 case CONTROL_NONE: //keyboard only
704 if (key_checkch()) return 1;
709 Error("Bad control type (Config_control_type):%i",Config_control_type);
715 extern int network_request_player_names(int);
716 extern int RestoringMenu;
718 #if defined(WINDOWS) || defined(MACINTOSH)
719 ubyte Hack_DblClick_MenuMode=0;
722 MAC(extern ubyte joydefs_calibrating;)
726 #define CLOSE_SIZE 10
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 + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
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 );
754 #if defined(MACINTOSH) || defined(WINDOWS)
755 int mouse_state, omouse_state, dblclick_flag=0;
756 int mx=0, my=0, x1, x2, y1, y2;
760 EventRecord event; // looking for disk inserted events for CD mounts
763 PA_DFX (pa_set_frontbuffer_current());
764 PA_DFX (pa_set_front_to_read());
766 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
775 WIN(mouse_set_mode(0)); //disable centering mode
777 MaxDisplayable=nitems;
780 set_screen_mode(SCREEN_MENU);
784 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
785 digi_pause_digi_sounds();
789 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
802 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
804 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
806 save_font = grd_curcanv->cv_font;
811 grd_curcanv->cv_font = TITLE_FONT;
812 gr_get_string_size(title,&string_width,&string_height,&average_width );
817 grd_curcanv->cv_font = SUBTITLE_FONT;
818 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
819 if (string_width > tw )
824 th += LHY(8); //put some space between titles & body
827 grd_curcanv->cv_font = SMALL_FONT;
829 grd_curcanv->cv_font = NORMAL_FONT;
833 nmenus = nothers = 0;
835 // Find menu height & width (store in w,h)
836 for (i=0; i<nitems; i++ ) {
839 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
840 item[i].right_offset = 0;
843 string_height+=LHY(3);
845 item[i].saved_text[0] = '\0';
847 if ( item[i].type == NM_TYPE_SLIDER ) {
850 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
851 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
852 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
854 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
855 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
856 string_width += w1 + aw;
859 if ( item[i].type == NM_TYPE_MENU ) {
863 if ( item[i].type == NM_TYPE_CHECK ) {
866 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
867 item[i].right_offset = w1;
868 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
869 if (w1 > item[i].right_offset)
870 item[i].right_offset = w1;
873 if (item[i].type == NM_TYPE_RADIO ) {
876 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
877 item[i].right_offset = w1;
878 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
879 if (w1 > item[i].right_offset)
880 item[i].right_offset = w1;
883 if (item[i].type==NM_TYPE_NUMBER ) {
887 sprintf( test_text, "%d", item[i].max_value );
888 gr_get_string_size( test_text, &w1, &h1, &aw1 );
889 item[i].right_offset = w1;
890 sprintf( test_text, "%d", item[i].min_value );
891 gr_get_string_size( test_text, &w1, &h1, &aw1 );
892 if ( w1 > item[i].right_offset)
893 item[i].right_offset = w1;
896 if ( item[i].type == NM_TYPE_INPUT ) {
897 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
898 strcpy(item[i].saved_text, item[i].text );
900 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
901 if ( string_width > MAX_TEXT_WIDTH )
902 string_width = MAX_TEXT_WIDTH;
906 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
907 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
908 strcpy(item[i].saved_text, item[i].text );
910 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
915 item[i].w = string_width;
916 item[i].h = string_height;
918 if ( string_width > w )
919 w = string_width; // Save maximum width
920 if ( average_width > aw )
922 h += string_height+1; // Find the height of all strings
925 // Big hack for allowing the netgame options menu to spill over
927 MaxOnMenu=MAXDISPLAYABLEITEMS;
928 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
931 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
934 h=(MaxOnMenu*(string_height+1)+LHY(8));
935 MaxDisplayable=MaxOnMenu;
936 mprintf ((0,"Hey, this is a scroll box!\n"));
949 for (i=0; i<nitems; i++ ) {
951 if (item[i].right_offset > right_offset )
952 right_offset = item[i].right_offset;
954 if (right_offset > 0 )
957 //gr_get_string_size("",&string_width,&string_height,&average_width );
964 twidth = ( tw - w )/2;
969 { right_offset=0; twidth=0;}
971 mprintf(( 0, "Right offset = %d\n", right_offset ));
974 // Find min point of menu border
975 // x = (grd_curscreen->sc_w-w)/2;
976 // y = (grd_curscreen->sc_h-h)/2;
978 w += MenuHires?60:30;
979 h += MenuHires?60:30;
981 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
982 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
984 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
985 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
990 if ( filename != NULL ) {
991 nm_draw_background1( filename );
992 gr_palette_load(gr_palette);
995 // Save the background of the display
996 // Win95 must refer to the screen as a dd_grs_canvas, so...
997 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
998 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
1000 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
1001 gr_set_current_canvas(bg.menu_canvas) );
1003 if ( filename == NULL ) {
1004 // Save the background under the menu...
1010 #if defined(POLY_ACC)
1011 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1013 bg.saved = gr_create_bitmap( w, h );
1015 Assert( bg.saved != NULL );
1017 WIN (DDGRLOCK(dd_grd_curcanv));
1018 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1019 WIN (DDGRUNLOCK(dd_grd_curcanv));
1021 WINDOS ( dd_gr_set_current_canvas(NULL),
1022 gr_set_current_canvas( NULL )
1025 nm_draw_background(x,y,x+w-1,y+h-1);
1027 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1028 gr_set_current_canvas( bg.menu_canvas )
1031 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1035 #if defined(POLY_ACC)
1036 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1038 bg.background = gr_create_bitmap( w, h );
1040 Assert( bg.background != NULL );
1042 WIN (DDGRLOCK(dd_grd_curcanv));
1043 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1044 WIN (DDGRUNLOCK(dd_grd_curcanv));
1047 // ty = 15 + (yborder/4);
1049 ty = MenuHires?30:15;
1052 grd_curcanv->cv_font = TITLE_FONT;
1053 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1054 gr_get_string_size(title,&string_width,&string_height,&average_width );
1057 WIN (DDGRLOCK(dd_grd_curcanv));
1058 gr_printf( 0x8000, ty, title );
1059 WIN (DDGRUNLOCK(dd_grd_curcanv));
1064 grd_curcanv->cv_font = SUBTITLE_FONT;
1065 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1066 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1069 WIN (DDGRLOCK(dd_grd_curcanv));
1070 gr_printf( 0x8000, ty, subtitle );
1071 WIN (DDGRUNLOCK(dd_grd_curcanv));
1076 grd_curcanv->cv_font = SMALL_FONT;
1078 grd_curcanv->cv_font = NORMAL_FONT;
1080 // Update all item's x & y values.
1081 for (i=0; i<nitems; i++ ) {
1082 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1083 item[i].y += (MenuHires?30:15);
1084 if ( item[i].type==NM_TYPE_RADIO ) {
1085 fm = -1; // find first marked one
1086 for ( j=0; j<nitems; j++ ) {
1087 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1088 if (fm==-1 && item[j].value)
1100 old_keyd_repeat = keyd_repeat;
1106 if (citem < 0 ) citem = 0;
1107 if (citem > nitems-1 ) citem = nitems-1;
1110 #if defined(WINDOWS) || defined(MACINTOSH)
1114 while ( item[choice].type==NM_TYPE_TEXT ) {
1116 if (choice >= nitems ) {
1119 if (choice == citem ) {
1130 // Clear mouse, joystick to clear button presses.
1131 game_flush_inputs();
1133 #if defined(WINDOWS) || defined(MACINTOSH)
1134 mouse_state = omouse_state = 0;
1135 if (filename == NULL && !MenuReordering) {
1136 draw_close_box(0,0);
1142 if (!MenuReordering) {
1144 SetCursor (LoadCursor(NULL,IDC_ARROW));
1149 if (!joydefs_calibrating)
1153 mprintf ((0,"Set to true!\n"));
1159 DoMessageStuff(&msg);
1161 if (_RedrawScreen) {
1162 _RedrawScreen = FALSE;
1165 gr_free_bitmap(bg.saved);
1166 d_free( bg.background );
1169 gr_free_bitmap(bg.background);
1171 dd_gr_free_sub_canvas( bg.menu_canvas );
1172 grd_curcanv->cv_font = save_font;
1173 dd_grd_curcanv = save_canvas;
1175 goto RePaintNewmenu4;
1184 omouse_state = mouse_state;
1185 mouse_state = mouse_button_state(0);
1186 if (!joydefs_calibrating)
1187 show_cursor(); // possibly hidden
1191 omouse_state = mouse_state;
1192 if (!MenuReordering)
1193 mouse_state = mouse_button_state(0);
1194 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1197 //see if redbook song needs to be restarted
1198 songs_check_redbook_repeat();
1205 (*subfunction)(nitems,item,&k,choice);
1208 if (!time_stopped) {
1209 // Save current menu box
1210 if (multi_menu_poll() == -1)
1216 dont_restore = (k == -3); //-3 means don't restore
1222 if (check_button_press())
1226 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1229 old_choice = choice;
1235 if (SurfingNet && !already_showing_info)
1237 show_extra_netgame_info(choice-2);
1239 if (SurfingNet && already_showing_info)
1246 if (SurfingNet && !already_showing_info)
1248 network_request_player_names(choice-2);
1250 if (SurfingNet && already_showing_info)
1265 case KEY_TAB + KEY_SHIFTED:
1268 if (all_text) break;
1275 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1277 if (choice<TopChoice)
1278 { choice=TopChoice; break; }
1280 if (choice<ScrollOffset)
1282 for (i=0;i<nitems;i++)
1285 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1290 if (choice >= nitems ) choice=0;
1291 if (choice < 0 ) choice=nitems-1;
1293 } while ( item[choice].type==NM_TYPE_TEXT );
1294 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1295 item[choice].value = -1;
1296 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1297 item[old_choice].group=0;
1298 strcpy(item[old_choice].text, item[old_choice].saved_text );
1299 item[old_choice].value = -1;
1302 item[old_choice].redraw = 1;
1303 item[choice].redraw=1;
1308 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1309 if (all_text) break;
1316 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1319 { choice--; break; }
1321 if (choice>=MaxOnMenu+ScrollOffset)
1323 for (i=0;i<nitems;i++)
1326 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1331 if (choice < 0 ) choice=nitems-1;
1332 if (choice >= nitems ) choice=0;
1335 } while ( item[choice].type==NM_TYPE_TEXT );
1337 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1338 item[choice].value = -1;
1339 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1340 item[old_choice].group=0;
1341 strcpy(item[old_choice].text, item[old_choice].saved_text );
1342 item[old_choice].value = -1;
1345 item[old_choice].redraw=1;
1346 item[choice].redraw=1;
1349 if ( choice > -1 ) {
1350 switch( item[choice].type ) {
1353 case NM_TYPE_INPUT_MENU:
1356 if ( item[choice].value )
1357 item[choice].value = 0;
1359 item[choice].value = 1;
1360 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1363 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1365 mprintf ((0,"Special redraw!\n"));
1370 item[choice].redraw=1;
1373 for (i=0; i<nitems; i++ ) {
1374 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1379 item[choice].value = 1;
1380 item[choice].redraw = 1;
1386 case KEY_SHIFTED+KEY_UP:
1387 if (MenuReordering && choice!=TopChoice)
1389 Temp=item[choice].text;
1390 TempVal=item[choice].value;
1391 item[choice].text=item[choice-1].text;
1392 item[choice].value=item[choice-1].value;
1393 item[choice-1].text=Temp;
1394 item[choice-1].value=TempVal;
1395 item[choice].redraw=1;
1396 item[choice-1].redraw=1;
1400 case KEY_SHIFTED+KEY_DOWN:
1401 if (MenuReordering && choice!=(nitems-1))
1403 Temp=item[choice].text;
1404 TempVal=item[choice].value;
1405 item[choice].text=item[choice+1].text;
1406 item[choice].value=item[choice+1].value;
1407 item[choice+1].text=Temp;
1408 item[choice+1].value=TempVal;
1409 item[choice].redraw=1;
1410 item[choice+1].redraw=1;
1417 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1418 item[choice].group = 1;
1419 item[choice].redraw = 1;
1420 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1421 item[choice].text[0] = 0;
1422 item[choice].value = -1;
1424 strip_end_whitespace(item[choice].text);
1431 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1432 item[choice].group=0;
1433 strcpy(item[choice].text, item[choice].saved_text );
1434 item[choice].redraw=1;
1435 item[choice].value = -1;
1442 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1443 case KEY_PRINT_SCREEN:
1445 save_screen_shot(0);
1446 PA_DFX (pa_set_frontbuffer_current());
1447 PA_DFX (pa_set_front_to_read());
1448 for (i=0;i<nitems;i++)
1457 case KEY_COMMAND+KEY_RIGHT:
1458 songs_goto_next_song();
1460 case KEY_COMMAND+KEY_LEFT:
1461 songs_goto_prev_song();
1463 case KEY_COMMAND+KEY_UP:
1464 songs_play_level_song(1);
1466 case KEY_COMMAND+KEY_DOWN:
1467 songs_stop_redbook();
1470 case KEY_COMMAND+KEY_M:
1472 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1473 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1476 key_close(); // no processing of keys with keyboard handler.. jeez
1479 show_boxed_message ("Mounting CD\nESC to quit");
1480 RBAMountDisk(); // OS has totaly control of the CD.
1481 if (Function_mode == FMODE_MENU)
1482 songs_play_song(SONG_TITLE,1);
1483 else if (Function_mode == FMODE_GAME)
1484 songs_play_level_song( Current_level_num );
1485 clear_boxed_message();
1494 case KEY_COMMAND+KEY_E:
1495 songs_stop_redbook();
1497 k = -1; // force key not to register
1500 case KEY_COMMAND+KEY_Q: {
1501 extern void macintosh_quit();
1503 if ( !(Game_mode & GM_MULTI) )
1505 if (!joydefs_calibrating)
1507 k = -1; // force key not to register
1514 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1521 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1523 if ( !done && mouse_state && !omouse_state && !all_text ) {
1524 mouse_get_pos(&mx, &my);
1525 for (i=0; i<nitems; i++ ) {
1526 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1527 x2 = x1 + item[i].w;
1528 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1529 y2 = y1 + item[i].h;
1530 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1531 if (i+ScrollOffset != choice) {
1532 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1535 choice = i + ScrollOffset;
1537 switch( item[choice].type ) {
1539 if ( item[choice].value )
1540 item[choice].value = 0;
1542 item[choice].value = 1;
1543 item[choice].redraw=1;
1550 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1552 mprintf ((0,"Special redraw!\n"));
1559 for (i=0; i<nitems; i++ ) {
1560 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1565 item[choice].value = 1;
1566 item[choice].redraw = 1;
1569 item[old_choice].redraw=1;
1575 if (mouse_state && all_text)
1578 if ( !done && mouse_state && !all_text ) {
1579 mouse_get_pos(&mx, &my);
1581 // check possible scrollbar stuff first
1583 int arrow_width, arrow_height, aw;
1585 if (ScrollOffset != 0) {
1586 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1587 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1588 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1589 x1 = x1 - arrow_width;
1590 y2 = y1 + arrow_height;
1591 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1594 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1596 if (choice<ScrollOffset)
1598 for (i=0;i<nitems;i++)
1601 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1605 if (ScrollOffset+MaxDisplayable<nitems) {
1606 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1607 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1608 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1609 x1 = x1 - arrow_width;
1610 y2 = y1 + arrow_height;
1611 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1614 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1616 if (choice>=MaxOnMenu+ScrollOffset)
1618 for (i=0;i<nitems;i++)
1621 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1627 for (i=0; i<nitems; i++ ) {
1628 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1629 x2 = x1 + item[i].w;
1630 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1631 y2 = y1 + item[i].h;
1632 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1633 if (i+ScrollOffset != choice) {
1634 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1637 choice = i + ScrollOffset;
1639 if ( item[choice].type == NM_TYPE_SLIDER ) {
1640 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1641 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1643 strcpy(slider_text, item[choice].saved_text);
1644 p = strchr(slider_text, '\t');
1650 gr_get_string_size(s1, &slider_width, &height, &aw);
1651 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1652 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1653 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1655 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1656 x2 = x1 + slider_width + sright_width;
1657 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1658 item[choice].value = item[choice].min_value;
1659 item[choice].redraw = 2;
1660 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1661 item[choice].value = item[choice].max_value;
1662 item[choice].redraw = 2;
1663 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1664 int num_values, value_width, new_value;
1666 num_values = item[choice].max_value - item[choice].min_value + 1;
1667 value_width = (slider_width - sleft_width - sright_width) / num_values;
1668 new_value = (mx - x1 - sleft_width) / value_width;
1669 if ( item[choice].value != new_value ) {
1670 item[choice].value = new_value;
1671 item[choice].redraw = 2;
1677 if (choice == old_choice)
1679 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1680 item[choice].value = -1;
1681 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1682 item[old_choice].group=0;
1683 strcpy(item[old_choice].text, item[old_choice].saved_text );
1684 item[old_choice].value = -1;
1687 item[old_choice].redraw = 1;
1688 item[choice].redraw=1;
1694 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1695 mouse_get_pos(&mx, &my);
1696 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1697 x2 = x1 + item[choice].w;
1698 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1699 y2 = y1 + item[choice].h;
1700 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1701 if (Hack_DblClick_MenuMode) {
1702 if (dblclick_flag) done = 1;
1703 else dblclick_flag = 1;
1709 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1710 item[choice].group = 1;
1711 item[choice].redraw = 1;
1712 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1713 item[choice].text[0] = 0;
1714 item[choice].value = -1;
1716 strip_end_whitespace(item[choice].text);
1720 if ( !done && !mouse_state && omouse_state && close_box ) {
1721 mouse_get_pos(&mx, &my);
1722 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1723 x2 = x1 + CLOSE_SIZE;
1724 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1725 y2 = y1 + CLOSE_SIZE;
1726 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1732 // HACK! Don't redraw loadgame preview
1733 if (RestoringMenu) item[0].redraw = 0;
1734 #endif // ifdef MACINTOSH
1736 if ( choice > -1 ) {
1739 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1740 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1741 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1742 if (item[choice].value > 0)
1743 item[choice].value--;
1744 item[choice].text[item[choice].value] = 0;
1745 item[choice].redraw = 1;
1747 ascii = key_to_ascii(k);
1748 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1752 if (item[choice].value==-1) {
1753 item[choice].value = 0;
1756 allowed = char_allowed(ascii);
1758 if (!allowed && ascii==' ' && char_allowed('_')) {
1764 item[choice].text[item[choice].value++] = ascii;
1765 item[choice].text[item[choice].value] = 0;
1766 item[choice].redraw=1;
1770 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1771 ascii = key_to_ascii(k);
1773 int choice1 = choice;
1774 ascii = toupper(ascii);
1778 if (choice1 >= nitems ) choice1=0;
1779 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1780 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1781 (item[choice1].type==NM_TYPE_CHECK) ||
1782 (item[choice1].type==NM_TYPE_RADIO) ||
1783 (item[choice1].type==NM_TYPE_NUMBER) ||
1784 (item[choice1].type==NM_TYPE_SLIDER) )
1785 && (ascii==toupper(ch)) ) {
1789 item[old_choice].redraw=1;
1790 item[choice].redraw=1;
1792 } while (choice1 != choice );
1796 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1797 int ov=item[choice].value;
1802 case KEY_MINUS+KEY_SHIFTED:
1804 item[choice].value -= 1;
1809 case KEY_EQUAL+KEY_SHIFTED:
1811 item[choice].value++;
1816 item[choice].value += 10;
1821 item[choice].value -= 10;
1824 if (ov!=item[choice].value)
1825 item[choice].redraw=1;
1830 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1831 gr_set_current_canvas(bg.menu_canvas));
1833 // Redraw everything...
1834 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1836 if (item[i].redraw) // warning! ugly hack below
1838 item[i].y-=((string_height+1)*ScrollOffset);
1841 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1843 MAC(if (!joydefs_calibrating) show_cursor());
1844 WIN(if (!MenuReordering) ShowCursorW());
1845 item[i].y+=((string_height+1)*ScrollOffset);
1847 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1848 update_cursor( &item[i]);
1854 //grd_curcanv->cv_font = NORMAL_FONT;
1856 if (LastScrollCheck!=ScrollOffset)
1858 LastScrollCheck=ScrollOffset;
1859 grd_curcanv->cv_font = SELECTED_FONT;
1861 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1862 sx=item[ScrollOffset].x-(MenuHires?24:12);
1865 if (ScrollOffset!=0)
1866 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1868 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1870 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1871 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1873 if (ScrollOffset+MaxDisplayable<nitems)
1874 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1876 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1882 if ( !dont_restore && gr_palette_faded_out ) {
1883 gr_palette_fade_in( gr_palette, 32, 0 );
1890 // Restore everything...
1892 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1893 gr_set_current_canvas(bg.menu_canvas));
1895 if ( filename == NULL ) {
1896 // Save the background under the menu...
1897 WIN (DDGRLOCK(dd_grd_curcanv));
1898 gr_bitmap(0, 0, bg.saved);
1899 WIN (DDGRUNLOCK(dd_grd_curcanv));
1900 gr_free_bitmap(bg.saved);
1901 d_free( bg.background );
1903 if (!dont_restore) //info passed back from subfunction
1905 WIN (DDGRLOCK(dd_grd_curcanv));
1906 gr_bitmap(0, 0, bg.background);
1907 WIN (DDGRUNLOCK(dd_grd_curcanv));
1909 gr_free_bitmap(bg.background);
1912 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1913 gr_free_sub_canvas( bg.menu_canvas ) );
1915 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1916 grd_curcanv->cv_font = save_font;
1917 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1918 keyd_repeat = old_keyd_repeat;
1920 game_flush_inputs();
1931 if ( sound_stopped )
1932 digi_resume_digi_sounds();
1934 WIN(mouse_set_mode(1)); //re-enable centering mode
1941 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1947 char nm_text[MESSAGEBOX_TEXT_SIZE];
1948 newmenu_item nm_message_items[5];
1950 va_start(args, nchoices );
1952 Assert( nchoices <= 5 );
1954 for (i=0; i<nchoices; i++ ) {
1955 s = va_arg( args, char * );
1956 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1958 format = va_arg( args, char * );
1959 strcpy( nm_text, "" );
1960 vsprintf(nm_text,format,args);
1963 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1965 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1968 int nm_messagebox( char *title, int nchoices, ... )
1974 char nm_text[MESSAGEBOX_TEXT_SIZE];
1975 newmenu_item nm_message_items[5];
1977 va_start(args, nchoices );
1979 Assert( nchoices <= 5 );
1981 for (i=0; i<nchoices; i++ ) {
1982 s = va_arg( args, char * );
1983 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1985 format = va_arg( args, char * );
1986 strcpy( nm_text, "" );
1987 vsprintf(nm_text,format,args);
1990 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1992 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1998 void newmenu_file_sort( int n, char *list )
2005 for (i=incr; i<n; i++ ) {
2008 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
2009 memcpy( t, &list[j*14], FILENAME_LEN );
2010 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
2011 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2022 void delete_player_saved_games(char * name)
2027 for (i=0;i<10; i++) {
2029 sprintf( filename, "%s.sg%d", name, i );
2031 sprintf( filename, ":Players:%s.sg%d", name, i );
2037 #define MAX_FILES 300
2039 int MakeNewPlayerFile(int allow_abort);
2041 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2044 FILEFINDSTRUCT find;
2045 int NumFiles=0, key,done, citem, ocitem;
2046 char * filenames = NULL;
2047 int NumFiles_displayed = 8;
2048 int first_item = -1, ofirst_item;
2049 int old_keyd_repeat = keyd_repeat;
2052 int demos_deleted=0;
2053 int initialized = 0;
2055 int w_x, w_y, w_w, w_h, title_height;
2056 int box_x, box_y, box_w, box_h;
2057 bkg bg; // background under listbox
2058 #if defined(MACINTOSH) || defined(WINDOWS)
2059 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2060 int mouse2_state, omouse2_state;
2061 int dblclick_flag=0;
2063 int show_up_arrow=0,show_down_arrow=0;
2065 WIN(int win_redraw=0);
2067 w_x=w_y=w_w=w_h=title_height=0;
2068 box_x=box_y=box_w=box_h=0;
2070 filenames = d_malloc( MAX_FILES * 14 );
2071 if (filenames==NULL) return 0;
2076 WIN(mouse_set_mode(0)); //disable centering mode
2078 if (strstr( filespec, "*.plr" ))
2080 else if (strstr( filespec, "*.dem" ))
2087 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2089 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2094 if( !FileFindFirst( filespec, &find ) ) {
2096 if (NumFiles<MAX_FILES) {
2097 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2098 if ( player_mode ) {
2100 p = strchr(&filenames[NumFiles*14],'.');
2107 } while( !FileFindNext( &find ) );
2111 if ( (NumFiles < 1) && demos_deleted ) {
2115 if ( (NumFiles < 1) && demo_mode ) {
2116 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2122 if ( (NumFiles < 2) && player_mode ) {
2124 goto ExitFileMenuEarly;
2131 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2138 // set_screen_mode(SCREEN_MENU);
2144 dd_gr_set_current_canvas(NULL);
2146 gr_set_current_canvas(NULL);
2149 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2151 grd_curcanv->cv_font = SUBTITLE_FONT;
2153 WIN(DDGRUNLOCK(dd_grd_curcanv));
2158 for (i=0; i<NumFiles; i++ ) {
2160 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2166 gr_get_string_size( title, &w, &h, &aw );
2169 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2173 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2175 w_w += (grd_curfont->ft_w * 4);
2176 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2178 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2179 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2181 w_x = (grd_curcanv->cv_w-w_w)/2;
2182 w_y = (grd_curcanv->cv_h-w_h)/2;
2184 if ( w_x < 0 ) w_x = 0;
2185 if ( w_y < 0 ) w_y = 0;
2187 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2188 box_y = w_y + title_height;
2190 // save the screen behind the menu.
2194 #if !defined(WINDOWS)
2195 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2196 bg.background = &VR_offscreen_buffer->cv_bitmap;
2199 #if defined(POLY_ACC)
2200 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2202 bg.background = gr_create_bitmap( w_w, w_h );
2205 Assert( bg.background != NULL );
2208 WIN(DDGRLOCK(dd_grd_curcanv));
2209 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2210 WIN(DDGRUNLOCK(dd_grd_curcanv));
2214 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2215 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2216 dd_VR_offscreen_buffer, 0, 0,
2217 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2218 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2222 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2224 WIN(DDGRLOCK(dd_grd_curcanv))
2226 gr_string( 0x8000, w_y+10, title );
2228 WIN(DDGRUNLOCK(dd_grd_curcanv));
2235 if ( !player_mode ) {
2236 newmenu_file_sort( NumFiles, filenames );
2238 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2239 newmenu_file_sort( NumFiles, filenames );
2241 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2243 for ( i=0; i<NumFiles; i++ ) {
2244 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2245 #if defined(WINDOWS) || defined(MACINTOSH)
2253 #if defined(MACINTOSH) || defined(WINDOWS)
2254 mouse_state = omouse_state = 0;
2255 mouse2_state = omouse2_state = 0;
2256 draw_close_box(w_x,w_y);
2268 DoMessageStuff(&msg);
2270 if (_RedrawScreen) {
2271 _RedrawScreen = FALSE;
2273 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2274 gr_free_bitmap(bg.background);
2277 goto RePaintNewmenuFile;
2284 ofirst_item = first_item;
2287 #if defined(MACINTOSH) || defined(WINDOWS)
2288 omouse_state = mouse_state;
2289 omouse2_state = mouse2_state;
2290 mouse_state = mouse_button_state(0);
2291 mouse2_state = mouse_button_state(1);
2294 //see if redbook song needs to be restarted
2295 songs_check_redbook_repeat();
2298 if (!mouse2_state && omouse2_state)
2299 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2302 //NOTE LINK TO ABOVE ELSE
2308 else if (simukey==1)
2314 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2315 case KEY_PRINT_SCREEN:
2317 save_screen_shot(0);
2318 PA_DFX (pa_set_frontbuffer_current());
2319 PA_DFX (pa_set_front_to_read());
2325 case KEY_CTRLED+KEY_D:
2326 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2330 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2334 mouse_set_mode(1); //re-enable centering mode
2338 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2340 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2343 mouse_set_mode(0); //disenable centering mode
2349 char name[_MAX_PATH],dir[_MAX_DIR];
2351 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2355 _splitpath(filespec,name,dir,NULL,NULL);
2357 strcat(name,&filenames[citem*14]);
2364 if ( !strncmp(name, ".\\", 2) )
2365 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2366 name[i] = name[i+1];
2367 while ( (p = strchr(name, '\\')) )
2372 ret = unlink( name );
2376 if ((!ret) && player_mode) {
2377 delete_player_saved_games( &filenames[citem*14] );
2382 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2384 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2385 } else if (demo_mode)
2410 citem += NumFiles_displayed;
2414 citem -= NumFiles_displayed;
2417 if (allow_abort_flag) {
2428 case KEY_COMMAND+KEY_Q: {
2429 extern void macintosh_quit();
2431 if ( !(Game_mode & GM_MULTI) )
2442 int ascii = key_to_ascii(key);
2443 if ( ascii < 255 ) {
2446 if (cc1 < 0 ) cc1 = 0;
2447 if (cc1 >= NumFiles ) cc1 = 0;
2449 if ( cc < 0 ) cc = 0;
2450 if ( cc >= NumFiles ) cc = 0;
2451 if ( citem == cc ) break;
2453 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2468 if (citem>=NumFiles)
2471 if (citem< first_item)
2474 if (citem>=( first_item+NumFiles_displayed))
2476 first_item = citem-NumFiles_displayed+1;
2480 if (NumFiles>first_item+NumFiles_displayed)
2491 if (NumFiles <= NumFiles_displayed )
2494 if (first_item>NumFiles-NumFiles_displayed)
2496 first_item = NumFiles-NumFiles_displayed;
2499 if (first_item < 0 ) first_item = 0;
2501 #if defined(MACINTOSH) || defined(WINDOWS)
2503 if (mouse_state || mouse2_state) {
2506 mouse_get_pos(&mx, &my);
2507 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2508 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2510 x2 = box_x + box_w - 1;
2511 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2513 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2514 if (i == citem && !mouse2_state) {
2524 if (!mouse_state && omouse_state) {
2527 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2528 mouse_get_pos(&mx, &my);
2530 x2 = box_x + box_w - 1;
2531 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2533 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2534 if (dblclick_flag) done = 1;
2535 else dblclick_flag = 1;
2539 if ( !mouse_state && omouse_state ) {
2540 mouse_get_pos(&mx, &my);
2541 x1 = w_x + CLOSE_X + 2;
2542 x2 = x1 + CLOSE_SIZE - 2;
2543 y1 = w_y + CLOSE_Y + 2;
2544 y2 = y1 + CLOSE_SIZE - 2;
2545 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2554 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2556 y1 = box_y+box_h-LHY(7);
2558 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2565 WIN(DDGRLOCK(dd_grd_curcanv));
2566 gr_setcolor( BM_XRGB(2,2,2));
2567 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2568 gr_setcolor( BM_XRGB( 0,0,0) );
2571 if (ofirst_item != first_item || win_redraw) {
2574 if (ofirst_item != first_item) {
2578 gr_setcolor( BM_XRGB( 0,0,0) );
2579 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2581 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2583 if ( i >= NumFiles ) {
2585 gr_setcolor( BM_XRGB(5,5,5));
2586 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2587 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2589 gr_setcolor( BM_XRGB(2,2,2));
2590 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2592 gr_setcolor( BM_XRGB(0,0,0));
2593 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
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 );
2602 gr_setcolor( BM_XRGB(5,5,5));
2603 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2604 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2606 gr_setcolor( BM_XRGB(2,2,2));
2607 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2608 gr_setcolor( BM_XRGB(0,0,0));
2610 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2611 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2616 } else if ( citem != ocitem ) {
2622 if ( (i>=0) && (i<NumFiles) ) {
2623 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2625 grd_curcanv->cv_font = SELECTED_FONT;
2627 grd_curcanv->cv_font = NORMAL_FONT;
2628 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2629 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2630 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2633 if ( (i>=0) && (i<NumFiles) ) {
2634 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2636 grd_curcanv->cv_font = SELECTED_FONT;
2638 grd_curcanv->cv_font = NORMAL_FONT;
2639 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2640 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2641 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2648 grd_curcanv->cv_font = NORMAL_FONT;
2650 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2654 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2658 if (show_down_arrow)
2659 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2663 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2671 WIN(DDGRUNLOCK(dd_grd_curcanv));
2677 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2684 keyd_repeat = old_keyd_repeat;
2686 if ( initialized ) {
2687 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2689 WIN (DDGRLOCK(dd_grd_curcanv));
2690 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2691 WIN (DDGRUNLOCK(dd_grd_curcanv));
2693 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2694 gr_free_bitmap(bg.background);
2697 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2698 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2700 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2701 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2711 WIN(mouse_set_mode(1)); //re-enable centering mode
2719 // Example listbox callback function...
2720 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2724 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2725 // if ( *nitems > 1 ) {
2726 // unlink( items[*citem] ); // Delete the file
2727 // for (i=*citem; i<*nitems-1; i++ ) {
2728 // items[i] = items[i+1];
2730 // *nitems = *nitems - 1;
2731 // d_free( items[*nitems] );
2732 // items[*nitems] = NULL;
2733 // return 1; // redraw;
2740 #define LB_ITEMS_ON_SCREEN 8
2742 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2744 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2747 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 ) )
2750 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2751 int old_keyd_repeat = keyd_repeat;
2752 int width, height, wx, wy, title_height, border_size;
2753 int total_width,total_height;
2755 #if defined(MACINTOSH) || defined(WINDOWS)
2756 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2757 int close_x,close_y;
2758 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2760 WIN(int win_redraw=0);
2764 PA_DFX (pa_set_frontbuffer_current());
2765 PA_DFX (pa_set_front_to_read());
2766 WIN(mouse_set_mode(0)); //disable centering mode
2768 // set_screen_mode(SCREEN_MENU);
2772 RePaintNewmenuListbox:
2774 dd_gr_set_current_canvas(NULL);
2776 gr_set_current_canvas(NULL);
2779 grd_curcanv->cv_font = SUBTITLE_FONT;
2782 for (i=0; i<nitems; i++ ) {
2784 gr_get_string_size( items[i], &w, &h, &aw );
2788 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2792 gr_get_string_size( title, &w, &h, &aw );
2795 title_height = h + 5;
2798 border_size = grd_curfont->ft_w;
2799 WIN (border_size=grd_curfont->ft_w*2);
2801 width += (grd_curfont->ft_w);
2802 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2803 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2805 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2806 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2807 if ( wy < title_height )
2810 total_width = width+2*border_size;
2811 total_height = height+2*border_size+title_height;
2815 #if !defined(WINDOWS)
2816 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2817 bg.background = &VR_offscreen_buffer->cv_bitmap;
2820 //bg.background = gr_create_bitmap( width, (height + title_height) );
2821 #if defined(POLY_ACC)
2822 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2824 bg.background = gr_create_bitmap(total_width,total_height);
2826 Assert( bg.background != NULL );
2828 WIN (DDGRLOCK(dd_grd_curcanv));
2829 //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 );
2830 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2831 WIN (DDGRUNLOCK(dd_grd_curcanv));
2835 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2836 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2837 dd_VR_offscreen_buffer, 0, 0,
2838 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2839 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2843 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2845 WIN(DDGRLOCK(dd_grd_curcanv));
2846 gr_string( 0x8000, wy - title_height, title );
2847 WIN(DDGRUNLOCK(dd_grd_curcanv));
2852 citem = default_item;
2853 if ( citem < 0 ) citem = 0;
2854 if ( citem >= nitems ) citem = 0;
2858 #if defined(MACINTOSH) || defined(WINDOWS)
2859 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2860 close_x = wx-border_size;
2861 close_y = wy-title_height-border_size;
2862 draw_close_box(close_x,close_y);
2874 DoMessageStuff(&msg);
2876 if (_RedrawScreen) {
2877 _RedrawScreen = FALSE;
2879 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2880 gr_free_bitmap(bg.background);
2882 goto RePaintNewmenuListbox;
2889 ofirst_item = first_item;
2890 #if defined(MACINTOSH) || defined(WINDOWS)
2891 omouse_state = mouse_state;
2892 mouse_state = mouse_button_state(0);
2894 //see if redbook song needs to be restarted
2895 songs_check_redbook_repeat();
2899 if ( listbox_callback )
2900 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2921 else if (simukey==1)
2927 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2928 case KEY_PRINT_SCREEN:
2930 save_screen_shot(0);
2931 PA_DFX (pa_set_frontbuffer_current());
2932 PA_DFX (pa_set_front_to_read());
2955 citem += LB_ITEMS_ON_SCREEN;
2959 citem -= LB_ITEMS_ON_SCREEN;
2962 if (allow_abort_flag) {
2973 case KEY_COMMAND+KEY_Q: {
2974 extern void macintosh_quit();
2976 if ( !(Game_mode & GM_MULTI) )
2986 int ascii = key_to_ascii(key);
2987 if ( ascii < 255 ) {
2990 if (cc1 < 0 ) cc1 = 0;
2991 if (cc1 >= nitems ) cc1 = 0;
2993 if ( cc < 0 ) cc = 0;
2994 if ( cc >= nitems ) cc = 0;
2995 if ( citem == cc ) break;
2997 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
3014 if (citem< first_item)
3017 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
3018 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3020 if (nitems <= LB_ITEMS_ON_SCREEN )
3023 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3024 first_item = nitems-LB_ITEMS_ON_SCREEN;
3025 if (first_item < 0 ) first_item = 0;
3028 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3039 #if defined(MACINTOSH) || defined(WINDOWS)
3044 mouse_get_pos(&mx, &my);
3045 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3048 gr_get_string_size(items[i], &w, &h, &aw );
3051 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3053 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3065 //no double-click stuff for listbox
3066 //@@if (!mouse_state && omouse_state) {
3069 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3070 //@@ mouse_get_pos(&mx, &my);
3072 //@@ x2 = wx + width;
3073 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3075 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3076 //@@ if (dblclick_flag) done = 1;
3080 //check for close box clicked
3081 if ( !mouse_state && omouse_state ) {
3082 mouse_get_pos(&mx, &my);
3083 x1 = close_x + CLOSE_X + 2;
3084 x2 = x1 + CLOSE_SIZE - 2;
3085 y1 = close_y + CLOSE_Y + 2;
3086 y2 = y1 + CLOSE_SIZE - 2;
3087 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3097 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3099 y1 = total_height-LHY(7);
3101 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3109 if ( (ofirst_item != first_item) || redraw) {
3112 WIN(DDGRLOCK(dd_grd_curcanv));
3114 gr_setcolor( BM_XRGB( 0,0,0) );
3115 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3117 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3118 if ( i >= nitems ) {
3119 gr_setcolor( BM_XRGB(0,0,0));
3120 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3123 grd_curcanv->cv_font = SELECTED_FONT;
3125 grd_curcanv->cv_font = NORMAL_FONT;
3126 gr_get_string_size(items[i], &w, &h, &aw );
3127 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3128 gr_string( wx+5, y, items[i] );
3133 // If Win95 port, draw up/down arrows on left side of menu
3135 grd_curcanv->cv_font = NORMAL_FONT;
3137 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3141 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3145 if (show_down_arrow)
3146 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3150 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3157 WIN(DDGRUNLOCK(dd_grd_curcanv));
3161 } else if ( citem != ocitem ) {
3167 WIN(DDGRLOCK(dd_grd_curcanv));
3170 if ( (i>=0) && (i<nitems) ) {
3171 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3173 grd_curcanv->cv_font = SELECTED_FONT;
3175 grd_curcanv->cv_font = NORMAL_FONT;
3176 gr_get_string_size(items[i], &w, &h, &aw );
3177 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3178 gr_string( wx+5, y, items[i] );
3182 if ( (i>=0) && (i<nitems) ) {
3183 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3185 grd_curcanv->cv_font = SELECTED_FONT;
3187 grd_curcanv->cv_font = NORMAL_FONT;
3188 gr_get_string_size( items[i], &w, &h, &aw );
3189 gr_rect( wx, y-1, wx+width-1, y+h );
3190 gr_string( wx+5, y, items[i] );
3192 WIN(DDGRUNLOCK(dd_grd_curcanv));
3202 keyd_repeat = old_keyd_repeat;
3204 WIN (DDGRLOCK(dd_grd_curcanv));
3205 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3206 WIN (DDGRUNLOCK(dd_grd_curcanv));
3208 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3209 gr_free_bitmap(bg.background);
3213 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3214 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3216 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3217 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3223 WIN(mouse_set_mode(1)); //re-enable centering mode
3228 int newmenu_filelist( char * title, char * filespec, char * filename )
3231 char * Filenames[MAX_FILES];
3232 char FilenameText[MAX_FILES][14];
3233 FILEFINDSTRUCT find;
3236 if( !FileFindFirst( filespec, &find ) ) {
3238 if (NumFiles<MAX_FILES) {
3239 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3240 Filenames[NumFiles] = FilenameText[NumFiles];
3245 } while( !FileFindNext( &find ) );
3249 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3251 strcpy( filename, Filenames[i] );
3257 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3258 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3264 char nm_text[MESSAGEBOX_TEXT_SIZE];
3265 newmenu_item nm_message_items[5];
3267 va_start(args, nchoices );
3269 Assert( nchoices <= 5 );
3271 for (i=0; i<nchoices; i++ ) {
3272 s = va_arg( args, char * );
3273 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3275 format = va_arg( args, char * );
3276 //sprintf( nm_text, "" ); // adb: ?
3277 vsprintf(nm_text,format,args);
3280 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3282 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3284 //end this section addition - Victor Rachels
3287 extern netgame_info Active_games[];
3288 extern int NumActiveNetgames;
3290 void show_extra_netgame_info(int choice)
3296 if (choice>=NumActiveNetgames)
3301 m[i].text=(char *)&mtext[i];
3302 m[i].type=NM_TYPE_TEXT;
3305 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3306 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3307 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3308 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3310 already_showing_info=1;
3311 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3312 already_showing_info=0;
3317 /* Spiffy word wrap string formatting function */
3319 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3325 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3328 wordptr = strtok(tbuf, " ");
3329 if (!wordptr) return;
3335 col = col+strlen(wordptr)+1;
3336 if (col >=line_length) {
3338 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3341 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3343 wordptr = strtok(NULL, " ");