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)
168 //@@//I think this only gets called to fill the whole screen
169 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
170 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
172 pcx_error = pcx_get_dimensions(filename, &width, &height);
173 Assert(pcx_error == PCX_ERROR_NONE);
175 bmp = gr_create_bitmap(width, height);
177 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
178 Assert(pcx_error == PCX_ERROR_NONE);
180 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
183 { //remap stuff. this code is kindof a hack
185 //now, before we bring up the menu, we need to
186 //do some stuff to make sure the palette is ok. First, we need to
187 //get our current palette into the 2d's array, so the remapping will
188 //work. Second, we need to remap the fonts. Third, we need to fill
189 //in part of the fade tables so the darkening of the menu edges works
191 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
192 remap_fonts_and_menus(1);
196 WIN(DDGRLOCK(dd_grd_curcanv));
197 #if defined(POLY_ACC)
199 pa_update_clut(gr_palette, 0, 256, 0);
202 #if defined(POLY_ACC)
205 WIN(DDGRUNLOCK(dd_grd_curcanv));
209 strcpy(last_palette_loaded,""); //force palette load next time
213 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
214 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
216 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
218 int Background_hires;
221 void nm_draw_background(int x1, int y1, int x2, int y2 )
225 if (Newmenu_first_time || MenuHires!=Background_hires) {
228 if (Newmenu_first_time) {
229 atexit( newmenu_close );
230 Newmenu_first_time = 0;
231 nm_background_save.bm_data=NULL;
234 if (nm_background_save.bm_data)
235 d_free(nm_background_save.bm_data);
236 if (nm_background.bm_data)
237 d_free(nm_background.bm_data);
240 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
241 Assert(pcx_error == PCX_ERROR_NONE);
243 nm_background = nm_background_save;
244 nm_background.bm_data=NULL;
245 nm_remap_background();
247 Background_hires = MenuHires;
250 if ( x1 < 0 ) x1 = 0;
251 if ( y1 < 0 ) y1 = 0;
256 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
257 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
263 grs_bitmap *tmp = gr_create_bitmap(w, h);
265 gr_bitmap_scale_to(&nm_background, tmp);
267 WIN(DDGRLOCK(dd_grd_curcanv));
269 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
271 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
276 Gr_scanline_darkening_level = 2*7;
278 gr_setcolor( BM_XRGB(0,0,0) );
279 gr_urect( x2-5, y1+5, x2-5, y2-5 );
280 gr_urect( x2-4, y1+4, x2-4, y2-5 );
281 gr_urect( x2-3, y1+3, x2-3, y2-5 );
282 gr_urect( x2-2, y1+2, x2-2, y2-5 );
283 gr_urect( x2-1, y1+1, x2-1, y2-5 );
284 gr_urect( x2+0, y1+0, x2-0, y2-5 );
286 gr_urect( x1+5, y2-5, x2, y2-5 );
287 gr_urect( x1+4, y2-4, x2, y2-4 );
288 gr_urect( x1+3, y2-3, x2, y2-3 );
289 gr_urect( x1+2, y2-2, x2, y2-2 );
290 gr_urect( x1+1, y2-1, x2, y2-1 );
291 gr_urect( x1+0, y2, x2, y2-0 );
293 WIN(DDGRUNLOCK(dd_grd_curcanv));
295 Gr_scanline_darkening_level = GR_FADE_LEVELS;
298 void nm_restore_background( int x, int y, int w, int h )
305 if ( x1 < 0 ) x1 = 0;
306 if ( y1 < 0 ) y1 = 0;
308 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
309 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
314 WIN(DDGRLOCK(dd_grd_curcanv));
315 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
316 WIN(DDGRUNLOCK(dd_grd_curcanv));
319 // Draw a left justfied string
320 void nm_string( bkg * b, int w1,int x, int y, char * s)
322 int w,h,aw,tx=0,t=0,i;
323 char *p,*s1,*s2,measure[2];
324 int XTabs[]={15,87,124,162,228,253};
330 XTabs[i]=(LHX(XTabs[i]));
337 p = strchr( s2, '\t' );
344 gr_get_string_size(s2, &w, &h, &aw );
350 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
351 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
354 for (i=0;i<strlen(s2);i++) {
355 if (s2[i]=='\t' && SurfingNet) {
361 gr_get_string_size(measure,&tx,&h,&aw);
362 gr_string(x,y,measure);
369 if (!SurfingNet && p && (w1>0) ) {
370 gr_get_string_size(s1, &w, &h, &aw );
372 gr_string( x+w1-w, y, s1 );
379 // Draw a slider and it's string
380 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
387 p = strchr( s, '\t' );
393 gr_get_string_size(s, &w, &h, &aw );
396 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
397 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
399 gr_string( x, y, s );
402 gr_get_string_size(s1, &w, &h, &aw );
405 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
407 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
409 gr_string( x+w1-w, y, s1 );
416 // Draw a left justfied string with black background.
417 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
420 gr_get_string_size(s, &w, &h, &aw );
424 WIN(DDGRLOCK(dd_grd_curcanv));
425 gr_setcolor( BM_XRGB(2,2,2) );
426 gr_rect( x-1, y-1, x-1, y+h-1 );
427 gr_rect( x-1, y-1, x+w1-1, y-1 );
430 gr_setcolor( BM_XRGB(5,5,5) );
431 gr_rect( x, y+h, x+w1, y+h);
432 gr_rect( x+w1, y-1, x+w1, y+h );
434 gr_setcolor( BM_XRGB(0,0,0) );
435 gr_rect( x, y, x+w1-1, y+h-1 );
437 gr_string( x+1, y+1, s );
438 WIN(DDGRUNLOCK(dd_grd_curcanv));
442 // Draw a right justfied string
443 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
446 gr_get_string_size(s, &w, &h, &aw );
451 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
454 WIN(DDGRLOCK(dd_grd_curcanv));
455 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
456 gr_string( x-w, y, s );
457 WIN(DDGRUNLOCK(dd_grd_curcanv));
462 //for text items, constantly redraw cursor (to achieve flash)
463 void update_cursor( newmenu_item *item)
466 fix time = timer_get_approx_seconds();
468 char * text = item->text;
470 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
473 gr_get_string_size(text, &w, &h, &aw );
474 if ( w > item->w-10 )
481 x = item->x+w; y = item->y;
483 WIN(DDGRLOCK(dd_grd_curcanv));
485 gr_string( x, y, CURSOR_STRING );
487 gr_setcolor( BM_XRGB(0,0,0) );
488 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
490 WIN(DDGRUNLOCK(dd_grd_curcanv));
493 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
498 gr_get_string_size(text, &w1, &h1, &aw );
507 nm_string_black( b, w, x, y, text );
510 gr_string( x+w1+1, y, CURSOR_STRING );
514 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
519 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
521 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
523 if (item->text[0]=='\t')
524 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
529 grd_curcanv->cv_font = SELECTED_FONT;
531 grd_curcanv->cv_font = NORMAL_FONT;
534 if (is_current && item->type == NM_TYPE_TEXT)
535 grd_curcanv->cv_font = NORMAL_FONT;
539 WIN(DDGRLOCK(dd_grd_curcanv));
540 switch( item->type ) {
542 // grd_curcanv->cv_font=TEXT_FONT;
543 // fall through on purpose
546 nm_string( b, item->w, item->x, item->y, item->text );
548 case NM_TYPE_SLIDER: {
550 if (item->value < item->min_value) item->value=item->min_value;
551 if (item->value > item->max_value) item->value=item->max_value;
552 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
553 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
554 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
556 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
558 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
560 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
563 case NM_TYPE_INPUT_MENU:
564 if ( item->group==0 ) {
565 nm_string( b, item->w, item->x, item->y, item->text );
567 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
571 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
574 nm_string( b, item->w, item->x, item->y, item->text );
576 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
578 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
581 nm_string( b, item->w, item->x, item->y, item->text );
583 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
585 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
587 case NM_TYPE_NUMBER: {
589 if (item->value < item->min_value) item->value=item->min_value;
590 if (item->value > item->max_value) item->value=item->max_value;
591 nm_string( b, item->w, item->x, item->y, item->text );
592 sprintf( text, "%d", item->value );
593 nm_rstring( b,item->right_offset,item->x, item->y, text );
597 WIN(DDGRUNLOCK(dd_grd_curcanv));
601 char *Newmenu_allowed_chars=NULL;
603 //returns true if char is allowed
604 int char_allowed(char c)
606 char *p = Newmenu_allowed_chars;
614 if (c>=p[0] && c<=p[1])
623 void strip_end_whitespace( char * text )
627 for (i=l-1; i>=0; i-- ) {
628 if ( isspace(text[i]) )
635 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
637 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
639 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
641 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
645 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
647 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
651 int newmenu_do1( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem )
653 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
657 int newmenu_do2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem, char * filename )
659 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
661 int newmenu_do3( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem, char * filename, int width, int height )
663 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
666 int newmenu_do_fixedfont( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem, char * filename, int width, int height){
667 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
668 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
669 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
672 //returns 1 if a control device button has been pressed
673 int check_button_press()
677 switch (Config_control_type) {
678 case CONTROL_JOYSTICK:
679 case CONTROL_FLIGHTSTICK_PRO:
680 case CONTROL_THRUSTMASTER_FCS:
681 case CONTROL_GRAVIS_GAMEPAD:
683 if (joy_get_button_down_cnt(i)>0) return 1;
686 case CONTROL_CYBERMAN:
687 #ifndef MACINTOSH // don't allow mouse to continue from menu
689 if (mouse_button_down_count(i)>0) return 1;
692 case CONTROL_WINJOYSTICK:
695 if (joy_get_button_down_cnt(i)>0) return 1;
698 case CONTROL_NONE: //keyboard only
700 if (key_checkch()) return 1;
705 Error("Bad control type (Config_control_type):%i",Config_control_type);
711 extern int network_request_player_names(int);
712 extern int RestoringMenu;
714 #if defined(WINDOWS) || defined(MACINTOSH)
715 ubyte Hack_DblClick_MenuMode=0;
718 MAC(extern ubyte joydefs_calibrating;)
722 #define CLOSE_SIZE 10
724 void draw_close_box(int x,int y)
726 WIN (DDGRLOCK(dd_grd_curcanv));
727 gr_setcolor( BM_XRGB(0, 0, 0) );
728 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
729 gr_setcolor( BM_XRGB(21, 21, 21) );
730 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
731 WIN (DDGRUNLOCK(dd_grd_curcanv));
734 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 )
736 int old_keyd_repeat, done;
737 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
738 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
739 grs_font * save_font;
740 int string_width, string_height, average_width;
743 int all_text=0; //set true if all text items
744 int sound_stopped=0,time_stopped=0;
745 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
748 int MaxOnMenu=MAXDISPLAYABLEITEMS;
749 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
750 #if defined(MACINTOSH) || defined(WINDOWS)
751 int mouse_state, omouse_state, dblclick_flag=0;
752 int mx=0, my=0, x1, x2, y1, y2;
756 EventRecord event; // looking for disk inserted events for CD mounts
759 PA_DFX (pa_set_frontbuffer_current());
760 PA_DFX (pa_set_front_to_read());
762 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
771 WIN(mouse_set_mode(0)); //disable centering mode
773 MaxDisplayable=nitems;
776 set_screen_mode(SCREEN_MENU);
780 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
781 digi_pause_digi_sounds();
785 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
798 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
800 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
802 save_font = grd_curcanv->cv_font;
807 grd_curcanv->cv_font = TITLE_FONT;
808 gr_get_string_size(title,&string_width,&string_height,&average_width );
813 grd_curcanv->cv_font = SUBTITLE_FONT;
814 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
815 if (string_width > tw )
820 th += LHY(8); //put some space between titles & body
823 grd_curcanv->cv_font = SMALL_FONT;
825 grd_curcanv->cv_font = NORMAL_FONT;
829 nmenus = nothers = 0;
831 // Find menu height & width (store in w,h)
832 for (i=0; i<nitems; i++ ) {
835 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
836 item[i].right_offset = 0;
839 string_height+=LHY(3);
841 item[i].saved_text[0] = '\0';
843 if ( item[i].type == NM_TYPE_SLIDER ) {
846 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
847 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
848 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
850 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
851 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
852 string_width += w1 + aw;
855 if ( item[i].type == NM_TYPE_MENU ) {
859 if ( item[i].type == NM_TYPE_CHECK ) {
862 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
863 item[i].right_offset = w1;
864 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
865 if (w1 > item[i].right_offset)
866 item[i].right_offset = w1;
869 if (item[i].type == NM_TYPE_RADIO ) {
872 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
873 item[i].right_offset = w1;
874 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
875 if (w1 > item[i].right_offset)
876 item[i].right_offset = w1;
879 if (item[i].type==NM_TYPE_NUMBER ) {
883 sprintf( test_text, "%d", item[i].max_value );
884 gr_get_string_size( test_text, &w1, &h1, &aw1 );
885 item[i].right_offset = w1;
886 sprintf( test_text, "%d", item[i].min_value );
887 gr_get_string_size( test_text, &w1, &h1, &aw1 );
888 if ( w1 > item[i].right_offset)
889 item[i].right_offset = w1;
892 if ( item[i].type == NM_TYPE_INPUT ) {
893 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
894 strcpy(item[i].saved_text, item[i].text );
896 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
897 if ( string_width > MAX_TEXT_WIDTH )
898 string_width = MAX_TEXT_WIDTH;
902 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
903 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
904 strcpy(item[i].saved_text, item[i].text );
906 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
911 item[i].w = string_width;
912 item[i].h = string_height;
914 if ( string_width > w )
915 w = string_width; // Save maximum width
916 if ( average_width > aw )
918 h += string_height+1; // Find the height of all strings
921 // Big hack for allowing the netgame options menu to spill over
923 MaxOnMenu=MAXDISPLAYABLEITEMS;
924 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
927 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
930 h=(MaxOnMenu*(string_height+1)+LHY(8));
931 MaxDisplayable=MaxOnMenu;
932 mprintf ((0,"Hey, this is a scroll box!\n"));
945 for (i=0; i<nitems; i++ ) {
947 if (item[i].right_offset > right_offset )
948 right_offset = item[i].right_offset;
950 if (right_offset > 0 )
953 //gr_get_string_size("",&string_width,&string_height,&average_width );
960 twidth = ( tw - w )/2;
965 { right_offset=0; twidth=0;}
967 mprintf(( 0, "Right offset = %d\n", right_offset ));
970 // Find min point of menu border
971 // x = (grd_curscreen->sc_w-w)/2;
972 // y = (grd_curscreen->sc_h-h)/2;
974 w += MenuHires?60:30;
975 h += MenuHires?60:30;
977 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
978 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
980 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
981 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
986 if ( filename != NULL ) {
987 nm_draw_background1( filename );
988 gr_palette_load(gr_palette);
991 // Save the background of the display
992 // Win95 must refer to the screen as a dd_grs_canvas, so...
993 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
994 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
996 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
997 gr_set_current_canvas(bg.menu_canvas) );
999 if ( filename == NULL ) {
1000 // Save the background under the menu...
1006 #if defined(POLY_ACC)
1007 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1009 bg.saved = gr_create_bitmap( w, h );
1011 Assert( bg.saved != NULL );
1013 WIN (DDGRLOCK(dd_grd_curcanv));
1014 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1015 WIN (DDGRUNLOCK(dd_grd_curcanv));
1017 WINDOS ( dd_gr_set_current_canvas(NULL),
1018 gr_set_current_canvas( NULL )
1021 nm_draw_background(x,y,x+w-1,y+h-1);
1023 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1024 gr_set_current_canvas( bg.menu_canvas )
1027 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1031 #if defined(POLY_ACC)
1032 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1034 bg.background = gr_create_bitmap( w, h );
1036 Assert( bg.background != NULL );
1038 WIN (DDGRLOCK(dd_grd_curcanv));
1039 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1040 WIN (DDGRUNLOCK(dd_grd_curcanv));
1043 // ty = 15 + (yborder/4);
1045 ty = MenuHires?30:15;
1048 grd_curcanv->cv_font = TITLE_FONT;
1049 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1050 gr_get_string_size(title,&string_width,&string_height,&average_width );
1053 WIN (DDGRLOCK(dd_grd_curcanv));
1054 gr_printf( 0x8000, ty, title );
1055 WIN (DDGRUNLOCK(dd_grd_curcanv));
1060 grd_curcanv->cv_font = SUBTITLE_FONT;
1061 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1062 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1065 WIN (DDGRLOCK(dd_grd_curcanv));
1066 gr_printf( 0x8000, ty, subtitle );
1067 WIN (DDGRUNLOCK(dd_grd_curcanv));
1072 grd_curcanv->cv_font = SMALL_FONT;
1074 grd_curcanv->cv_font = NORMAL_FONT;
1076 // Update all item's x & y values.
1077 for (i=0; i<nitems; i++ ) {
1078 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1079 item[i].y += (MenuHires?30:15);
1080 if ( item[i].type==NM_TYPE_RADIO ) {
1081 fm = -1; // find first marked one
1082 for ( j=0; j<nitems; j++ ) {
1083 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1084 if (fm==-1 && item[j].value)
1096 old_keyd_repeat = keyd_repeat;
1102 if (citem < 0 ) citem = 0;
1103 if (citem > nitems-1 ) citem = nitems-1;
1106 #if defined(WINDOWS) || defined(MACINTOSH)
1110 while ( item[choice].type==NM_TYPE_TEXT ) {
1112 if (choice >= nitems ) {
1115 if (choice == citem ) {
1126 // Clear mouse, joystick to clear button presses.
1127 game_flush_inputs();
1129 #if defined(WINDOWS) || defined(MACINTOSH)
1130 mouse_state = omouse_state = 0;
1131 if (filename == NULL && !MenuReordering) {
1132 draw_close_box(0,0);
1138 if (!MenuReordering) {
1140 SetCursor (LoadCursor(NULL,IDC_ARROW));
1145 if (!joydefs_calibrating)
1149 mprintf ((0,"Set to true!\n"));
1155 DoMessageStuff(&msg);
1157 if (_RedrawScreen) {
1158 _RedrawScreen = FALSE;
1161 gr_free_bitmap(bg.saved);
1162 d_free( bg.background );
1165 gr_free_bitmap(bg.background);
1167 dd_gr_free_sub_canvas( bg.menu_canvas );
1168 grd_curcanv->cv_font = save_font;
1169 dd_grd_curcanv = save_canvas;
1171 goto RePaintNewmenu4;
1180 omouse_state = mouse_state;
1181 mouse_state = mouse_button_state(0);
1182 if (!joydefs_calibrating)
1183 show_cursor(); // possibly hidden
1187 omouse_state = mouse_state;
1188 if (!MenuReordering)
1189 mouse_state = mouse_button_state(0);
1190 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1193 //see if redbook song needs to be restarted
1194 songs_check_redbook_repeat();
1201 (*subfunction)(nitems,item,&k,choice);
1204 if (!time_stopped) {
1205 // Save current menu box
1206 if (multi_menu_poll() == -1)
1212 dont_restore = (k == -3); //-3 means don't restore
1218 if (check_button_press())
1222 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1225 old_choice = choice;
1231 if (SurfingNet && !already_showing_info)
1233 show_extra_netgame_info(choice-2);
1235 if (SurfingNet && already_showing_info)
1242 if (SurfingNet && !already_showing_info)
1244 network_request_player_names(choice-2);
1246 if (SurfingNet && already_showing_info)
1261 case KEY_TAB + KEY_SHIFTED:
1264 if (all_text) break;
1271 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1273 if (choice<TopChoice)
1274 { choice=TopChoice; break; }
1276 if (choice<ScrollOffset)
1278 for (i=0;i<nitems;i++)
1281 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1286 if (choice >= nitems ) choice=0;
1287 if (choice < 0 ) choice=nitems-1;
1289 } while ( item[choice].type==NM_TYPE_TEXT );
1290 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1291 item[choice].value = -1;
1292 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1293 item[old_choice].group=0;
1294 strcpy(item[old_choice].text, item[old_choice].saved_text );
1295 item[old_choice].value = -1;
1298 item[old_choice].redraw = 1;
1299 item[choice].redraw=1;
1304 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1305 if (all_text) break;
1312 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1315 { choice--; break; }
1317 if (choice>=MaxOnMenu+ScrollOffset)
1319 for (i=0;i<nitems;i++)
1322 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1327 if (choice < 0 ) choice=nitems-1;
1328 if (choice >= nitems ) choice=0;
1331 } while ( item[choice].type==NM_TYPE_TEXT );
1333 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1334 item[choice].value = -1;
1335 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1336 item[old_choice].group=0;
1337 strcpy(item[old_choice].text, item[old_choice].saved_text );
1338 item[old_choice].value = -1;
1341 item[old_choice].redraw=1;
1342 item[choice].redraw=1;
1345 if ( choice > -1 ) {
1346 switch( item[choice].type ) {
1349 case NM_TYPE_INPUT_MENU:
1352 if ( item[choice].value )
1353 item[choice].value = 0;
1355 item[choice].value = 1;
1356 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1359 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1361 mprintf ((0,"Special redraw!\n"));
1366 item[choice].redraw=1;
1369 for (i=0; i<nitems; i++ ) {
1370 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1375 item[choice].value = 1;
1376 item[choice].redraw = 1;
1382 case KEY_SHIFTED+KEY_UP:
1383 if (MenuReordering && choice!=TopChoice)
1385 Temp=item[choice].text;
1386 TempVal=item[choice].value;
1387 item[choice].text=item[choice-1].text;
1388 item[choice].value=item[choice-1].value;
1389 item[choice-1].text=Temp;
1390 item[choice-1].value=TempVal;
1391 item[choice].redraw=1;
1392 item[choice-1].redraw=1;
1396 case KEY_SHIFTED+KEY_DOWN:
1397 if (MenuReordering && choice!=(nitems-1))
1399 Temp=item[choice].text;
1400 TempVal=item[choice].value;
1401 item[choice].text=item[choice+1].text;
1402 item[choice].value=item[choice+1].value;
1403 item[choice+1].text=Temp;
1404 item[choice+1].value=TempVal;
1405 item[choice].redraw=1;
1406 item[choice+1].redraw=1;
1413 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1414 item[choice].group = 1;
1415 item[choice].redraw = 1;
1416 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1417 item[choice].text[0] = 0;
1418 item[choice].value = -1;
1420 strip_end_whitespace(item[choice].text);
1427 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1428 item[choice].group=0;
1429 strcpy(item[choice].text, item[choice].saved_text );
1430 item[choice].redraw=1;
1431 item[choice].value = -1;
1438 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1439 case KEY_PRINT_SCREEN:
1441 save_screen_shot(0);
1442 PA_DFX (pa_set_frontbuffer_current());
1443 PA_DFX (pa_set_front_to_read());
1444 for (i=0;i<nitems;i++)
1453 case KEY_COMMAND+KEY_RIGHT:
1454 songs_goto_next_song();
1456 case KEY_COMMAND+KEY_LEFT:
1457 songs_goto_prev_song();
1459 case KEY_COMMAND+KEY_UP:
1460 songs_play_level_song(1);
1462 case KEY_COMMAND+KEY_DOWN:
1463 songs_stop_redbook();
1466 case KEY_COMMAND+KEY_M:
1468 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1469 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1472 key_close(); // no processing of keys with keyboard handler.. jeez
1475 show_boxed_message ("Mounting CD\nESC to quit");
1476 RBAMountDisk(); // OS has totaly control of the CD.
1477 if (Function_mode == FMODE_MENU)
1478 songs_play_song(SONG_TITLE,1);
1479 else if (Function_mode == FMODE_GAME)
1480 songs_play_level_song( Current_level_num );
1481 clear_boxed_message();
1490 case KEY_COMMAND+KEY_E:
1491 songs_stop_redbook();
1493 k = -1; // force key not to register
1496 case KEY_COMMAND+KEY_Q: {
1497 extern void macintosh_quit();
1499 if ( !(Game_mode & GM_MULTI) )
1501 if (!joydefs_calibrating)
1503 k = -1; // force key not to register
1510 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1517 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1519 if ( !done && mouse_state && !omouse_state && !all_text ) {
1520 mouse_get_pos(&mx, &my);
1521 for (i=0; i<nitems; i++ ) {
1522 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1523 x2 = x1 + item[i].w;
1524 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1525 y2 = y1 + item[i].h;
1526 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1527 if (i+ScrollOffset != choice) {
1528 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1531 choice = i + ScrollOffset;
1533 switch( item[choice].type ) {
1535 if ( item[choice].value )
1536 item[choice].value = 0;
1538 item[choice].value = 1;
1539 item[choice].redraw=1;
1546 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1548 mprintf ((0,"Special redraw!\n"));
1555 for (i=0; i<nitems; i++ ) {
1556 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1561 item[choice].value = 1;
1562 item[choice].redraw = 1;
1565 item[old_choice].redraw=1;
1571 if (mouse_state && all_text)
1574 if ( !done && mouse_state && !all_text ) {
1575 mouse_get_pos(&mx, &my);
1577 // check possible scrollbar stuff first
1579 int arrow_width, arrow_height, aw;
1581 if (ScrollOffset != 0) {
1582 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1583 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1584 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1585 x1 = x1 - arrow_width;
1586 y2 = y1 + arrow_height;
1587 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1590 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1592 if (choice<ScrollOffset)
1594 for (i=0;i<nitems;i++)
1597 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1601 if (ScrollOffset+MaxDisplayable<nitems) {
1602 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1603 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1604 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1605 x1 = x1 - arrow_width;
1606 y2 = y1 + arrow_height;
1607 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1610 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1612 if (choice>=MaxOnMenu+ScrollOffset)
1614 for (i=0;i<nitems;i++)
1617 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1623 for (i=0; i<nitems; i++ ) {
1624 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1625 x2 = x1 + item[i].w;
1626 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1627 y2 = y1 + item[i].h;
1628 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1629 if (i+ScrollOffset != choice) {
1630 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1633 choice = i + ScrollOffset;
1635 if ( item[choice].type == NM_TYPE_SLIDER ) {
1636 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1637 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1639 strcpy(slider_text, item[choice].saved_text);
1640 p = strchr(slider_text, '\t');
1646 gr_get_string_size(s1, &slider_width, &height, &aw);
1647 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1648 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1649 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1651 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1652 x2 = x1 + slider_width + sright_width;
1653 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1654 item[choice].value = item[choice].min_value;
1655 item[choice].redraw = 2;
1656 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1657 item[choice].value = item[choice].max_value;
1658 item[choice].redraw = 2;
1659 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1660 int num_values, value_width, new_value;
1662 num_values = item[choice].max_value - item[choice].min_value + 1;
1663 value_width = (slider_width - sleft_width - sright_width) / num_values;
1664 new_value = (mx - x1 - sleft_width) / value_width;
1665 if ( item[choice].value != new_value ) {
1666 item[choice].value = new_value;
1667 item[choice].redraw = 2;
1673 if (choice == old_choice)
1675 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1676 item[choice].value = -1;
1677 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1678 item[old_choice].group=0;
1679 strcpy(item[old_choice].text, item[old_choice].saved_text );
1680 item[old_choice].value = -1;
1683 item[old_choice].redraw = 1;
1684 item[choice].redraw=1;
1690 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1691 mouse_get_pos(&mx, &my);
1692 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1693 x2 = x1 + item[choice].w;
1694 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1695 y2 = y1 + item[choice].h;
1696 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1697 if (Hack_DblClick_MenuMode) {
1698 if (dblclick_flag) done = 1;
1699 else dblclick_flag = 1;
1705 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1706 item[choice].group = 1;
1707 item[choice].redraw = 1;
1708 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1709 item[choice].text[0] = 0;
1710 item[choice].value = -1;
1712 strip_end_whitespace(item[choice].text);
1716 if ( !done && !mouse_state && omouse_state && close_box ) {
1717 mouse_get_pos(&mx, &my);
1718 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1719 x2 = x1 + CLOSE_SIZE;
1720 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1721 y2 = y1 + CLOSE_SIZE;
1722 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1728 // HACK! Don't redraw loadgame preview
1729 if (RestoringMenu) item[0].redraw = 0;
1730 #endif // ifdef MACINTOSH
1732 if ( choice > -1 ) {
1735 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1736 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1737 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1738 if (item[choice].value > 0)
1739 item[choice].value--;
1740 item[choice].text[item[choice].value] = 0;
1741 item[choice].redraw = 1;
1743 ascii = key_to_ascii(k);
1744 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1748 if (item[choice].value==-1) {
1749 item[choice].value = 0;
1752 allowed = char_allowed(ascii);
1754 if (!allowed && ascii==' ' && char_allowed('_')) {
1760 item[choice].text[item[choice].value++] = ascii;
1761 item[choice].text[item[choice].value] = 0;
1762 item[choice].redraw=1;
1766 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1767 ascii = key_to_ascii(k);
1769 int choice1 = choice;
1770 ascii = toupper(ascii);
1774 if (choice1 >= nitems ) choice1=0;
1775 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1776 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1777 (item[choice1].type==NM_TYPE_CHECK) ||
1778 (item[choice1].type==NM_TYPE_RADIO) ||
1779 (item[choice1].type==NM_TYPE_NUMBER) ||
1780 (item[choice1].type==NM_TYPE_SLIDER) )
1781 && (ascii==toupper(ch)) ) {
1785 item[old_choice].redraw=1;
1786 item[choice].redraw=1;
1788 } while (choice1 != choice );
1792 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1793 int ov=item[choice].value;
1798 case KEY_MINUS+KEY_SHIFTED:
1800 item[choice].value -= 1;
1805 case KEY_EQUAL+KEY_SHIFTED:
1807 item[choice].value++;
1812 item[choice].value += 10;
1817 item[choice].value -= 10;
1820 if (ov!=item[choice].value)
1821 item[choice].redraw=1;
1826 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1827 gr_set_current_canvas(bg.menu_canvas));
1829 // Redraw everything...
1830 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1832 if (item[i].redraw) // warning! ugly hack below
1834 item[i].y-=((string_height+1)*ScrollOffset);
1837 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1839 MAC(if (!joydefs_calibrating) show_cursor());
1840 WIN(if (!MenuReordering) ShowCursorW());
1841 item[i].y+=((string_height+1)*ScrollOffset);
1843 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1844 update_cursor( &item[i]);
1850 //grd_curcanv->cv_font = NORMAL_FONT;
1852 if (LastScrollCheck!=ScrollOffset)
1854 LastScrollCheck=ScrollOffset;
1855 grd_curcanv->cv_font = SELECTED_FONT;
1857 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1858 sx=item[ScrollOffset].x-(MenuHires?24:12);
1861 if (ScrollOffset!=0)
1862 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1864 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1866 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1867 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1869 if (ScrollOffset+MaxDisplayable<nitems)
1870 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1872 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1878 if ( !dont_restore && gr_palette_faded_out ) {
1879 gr_palette_fade_in( gr_palette, 32, 0 );
1886 // Restore everything...
1888 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1889 gr_set_current_canvas(bg.menu_canvas));
1891 if ( filename == NULL ) {
1892 // Save the background under the menu...
1893 WIN (DDGRLOCK(dd_grd_curcanv));
1894 gr_bitmap(0, 0, bg.saved);
1895 WIN (DDGRUNLOCK(dd_grd_curcanv));
1896 gr_free_bitmap(bg.saved);
1897 d_free( bg.background );
1899 if (!dont_restore) //info passed back from subfunction
1901 WIN (DDGRLOCK(dd_grd_curcanv));
1902 gr_bitmap(0, 0, bg.background);
1903 WIN (DDGRUNLOCK(dd_grd_curcanv));
1905 gr_free_bitmap(bg.background);
1908 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1909 gr_free_sub_canvas( bg.menu_canvas ) );
1911 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1912 grd_curcanv->cv_font = save_font;
1913 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1914 keyd_repeat = old_keyd_repeat;
1916 game_flush_inputs();
1927 if ( sound_stopped )
1928 digi_resume_digi_sounds();
1930 WIN(mouse_set_mode(1)); //re-enable centering mode
1937 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1943 char nm_text[MESSAGEBOX_TEXT_SIZE];
1944 newmenu_item nm_message_items[5];
1946 va_start(args, nchoices );
1948 Assert( nchoices <= 5 );
1950 for (i=0; i<nchoices; i++ ) {
1951 s = va_arg( args, char * );
1952 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1954 format = va_arg( args, char * );
1955 strcpy( nm_text, "" );
1956 vsprintf(nm_text,format,args);
1959 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1961 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1964 int nm_messagebox( char *title, int nchoices, ... )
1970 char nm_text[MESSAGEBOX_TEXT_SIZE];
1971 newmenu_item nm_message_items[5];
1973 va_start(args, nchoices );
1975 Assert( nchoices <= 5 );
1977 for (i=0; i<nchoices; i++ ) {
1978 s = va_arg( args, char * );
1979 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1981 format = va_arg( args, char * );
1982 strcpy( nm_text, "" );
1983 vsprintf(nm_text,format,args);
1986 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1988 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1994 void newmenu_file_sort( int n, char *list )
2001 for (i=incr; i<n; i++ ) {
2004 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
2005 memcpy( t, &list[j*14], FILENAME_LEN );
2006 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
2007 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2018 void delete_player_saved_games(char * name)
2023 for (i=0;i<10; i++) {
2025 sprintf( filename, "%s.sg%d", name, i );
2027 sprintf( filename, ":Players:%s.sg%d", name, i );
2033 #define MAX_FILES 300
2035 int MakeNewPlayerFile(int allow_abort);
2037 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2040 FILEFINDSTRUCT find;
2041 int NumFiles=0, key,done, citem, ocitem;
2042 char * filenames = NULL;
2043 int NumFiles_displayed = 8;
2044 int first_item = -1, ofirst_item;
2045 int old_keyd_repeat = keyd_repeat;
2048 int demos_deleted=0;
2049 int initialized = 0;
2051 int w_x, w_y, w_w, w_h, title_height;
2052 int box_x, box_y, box_w, box_h;
2053 bkg bg; // background under listbox
2054 #if defined(MACINTOSH) || defined(WINDOWS)
2055 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2056 int mouse2_state, omouse2_state;
2057 int dblclick_flag=0;
2059 int show_up_arrow=0,show_down_arrow=0;
2061 WIN(int win_redraw=0);
2063 w_x=w_y=w_w=w_h=title_height=0;
2064 box_x=box_y=box_w=box_h=0;
2066 filenames = d_malloc( MAX_FILES * 14 );
2067 if (filenames==NULL) return 0;
2072 WIN(mouse_set_mode(0)); //disable centering mode
2074 if (strstr( filespec, "*.plr" ))
2076 else if (strstr( filespec, "*.dem" ))
2083 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2085 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2090 if( !FileFindFirst( filespec, &find ) ) {
2092 if (NumFiles<MAX_FILES) {
2093 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2094 if ( player_mode ) {
2096 p = strchr(&filenames[NumFiles*14],'.');
2103 } while( !FileFindNext( &find ) );
2107 if ( (NumFiles < 1) && demos_deleted ) {
2111 if ( (NumFiles < 1) && demo_mode ) {
2112 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2118 if ( (NumFiles < 2) && player_mode ) {
2120 goto ExitFileMenuEarly;
2127 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2134 // set_screen_mode(SCREEN_MENU);
2140 dd_gr_set_current_canvas(NULL);
2142 gr_set_current_canvas(NULL);
2145 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2147 grd_curcanv->cv_font = SUBTITLE_FONT;
2149 WIN(DDGRUNLOCK(dd_grd_curcanv));
2154 for (i=0; i<NumFiles; i++ ) {
2156 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2162 gr_get_string_size( title, &w, &h, &aw );
2165 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2169 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2171 w_w += (grd_curfont->ft_w * 4);
2172 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2174 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2175 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2177 w_x = (grd_curcanv->cv_w-w_w)/2;
2178 w_y = (grd_curcanv->cv_h-w_h)/2;
2180 if ( w_x < 0 ) w_x = 0;
2181 if ( w_y < 0 ) w_y = 0;
2183 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2184 box_y = w_y + title_height;
2186 // save the screen behind the menu.
2190 #if !defined(WINDOWS)
2191 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2192 bg.background = &VR_offscreen_buffer->cv_bitmap;
2195 #if defined(POLY_ACC)
2196 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2198 bg.background = gr_create_bitmap( w_w, w_h );
2201 Assert( bg.background != NULL );
2204 WIN(DDGRLOCK(dd_grd_curcanv));
2205 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2206 WIN(DDGRUNLOCK(dd_grd_curcanv));
2210 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2211 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2212 dd_VR_offscreen_buffer, 0, 0,
2213 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2214 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2218 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2220 WIN(DDGRLOCK(dd_grd_curcanv))
2222 gr_string( 0x8000, w_y+10, title );
2224 WIN(DDGRUNLOCK(dd_grd_curcanv));
2231 if ( !player_mode ) {
2232 newmenu_file_sort( NumFiles, filenames );
2234 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2235 newmenu_file_sort( NumFiles, filenames );
2237 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2239 for ( i=0; i<NumFiles; i++ ) {
2240 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2241 #if defined(WINDOWS) || defined(MACINTOSH)
2249 #if defined(MACINTOSH) || defined(WINDOWS)
2250 mouse_state = omouse_state = 0;
2251 mouse2_state = omouse2_state = 0;
2252 draw_close_box(w_x,w_y);
2264 DoMessageStuff(&msg);
2266 if (_RedrawScreen) {
2267 _RedrawScreen = FALSE;
2269 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2270 gr_free_bitmap(bg.background);
2273 goto RePaintNewmenuFile;
2280 ofirst_item = first_item;
2283 #if defined(MACINTOSH) || defined(WINDOWS)
2284 omouse_state = mouse_state;
2285 omouse2_state = mouse2_state;
2286 mouse_state = mouse_button_state(0);
2287 mouse2_state = mouse_button_state(1);
2290 //see if redbook song needs to be restarted
2291 songs_check_redbook_repeat();
2294 if (!mouse2_state && omouse2_state)
2295 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2298 //NOTE LINK TO ABOVE ELSE
2304 else if (simukey==1)
2310 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2311 case KEY_PRINT_SCREEN:
2313 save_screen_shot(0);
2314 PA_DFX (pa_set_frontbuffer_current());
2315 PA_DFX (pa_set_front_to_read());
2321 case KEY_CTRLED+KEY_D:
2322 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2326 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2330 mouse_set_mode(1); //re-enable centering mode
2334 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2336 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2339 mouse_set_mode(0); //disenable centering mode
2345 char name[_MAX_PATH],dir[_MAX_DIR];
2347 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2351 _splitpath(filespec,name,dir,NULL,NULL);
2353 strcat(name,&filenames[citem*14]);
2360 if ( !strncmp(name, ".\\", 2) )
2361 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2362 name[i] = name[i+1];
2363 while ( (p = strchr(name, '\\')) )
2368 ret = unlink( name );
2372 if ((!ret) && player_mode) {
2373 delete_player_saved_games( &filenames[citem*14] );
2378 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2380 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2381 } else if (demo_mode)
2406 citem += NumFiles_displayed;
2410 citem -= NumFiles_displayed;
2413 if (allow_abort_flag) {
2424 case KEY_COMMAND+KEY_Q: {
2425 extern void macintosh_quit();
2427 if ( !(Game_mode & GM_MULTI) )
2438 int ascii = key_to_ascii(key);
2439 if ( ascii < 255 ) {
2442 if (cc1 < 0 ) cc1 = 0;
2443 if (cc1 >= NumFiles ) cc1 = 0;
2445 if ( cc < 0 ) cc = 0;
2446 if ( cc >= NumFiles ) cc = 0;
2447 if ( citem == cc ) break;
2449 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2464 if (citem>=NumFiles)
2467 if (citem< first_item)
2470 if (citem>=( first_item+NumFiles_displayed))
2472 first_item = citem-NumFiles_displayed+1;
2476 if (NumFiles>first_item+NumFiles_displayed)
2487 if (NumFiles <= NumFiles_displayed )
2490 if (first_item>NumFiles-NumFiles_displayed)
2492 first_item = NumFiles-NumFiles_displayed;
2495 if (first_item < 0 ) first_item = 0;
2497 #if defined(MACINTOSH) || defined(WINDOWS)
2499 if (mouse_state || mouse2_state) {
2502 mouse_get_pos(&mx, &my);
2503 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2504 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2506 x2 = box_x + box_w - 1;
2507 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2509 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2510 if (i == citem && !mouse2_state) {
2520 if (!mouse_state && omouse_state) {
2523 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2524 mouse_get_pos(&mx, &my);
2526 x2 = box_x + box_w - 1;
2527 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2529 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2530 if (dblclick_flag) done = 1;
2531 else dblclick_flag = 1;
2535 if ( !mouse_state && omouse_state ) {
2536 mouse_get_pos(&mx, &my);
2537 x1 = w_x + CLOSE_X + 2;
2538 x2 = x1 + CLOSE_SIZE - 2;
2539 y1 = w_y + CLOSE_Y + 2;
2540 y2 = y1 + CLOSE_SIZE - 2;
2541 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2550 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2552 y1 = box_y+box_h-LHY(7);
2554 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2561 WIN(DDGRLOCK(dd_grd_curcanv));
2562 gr_setcolor( BM_XRGB(2,2,2));
2563 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2564 gr_setcolor( BM_XRGB( 0,0,0) );
2567 if (ofirst_item != first_item || win_redraw) {
2570 if (ofirst_item != first_item) {
2574 gr_setcolor( BM_XRGB( 0,0,0) );
2575 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2577 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2579 if ( i >= NumFiles ) {
2581 gr_setcolor( BM_XRGB(5,5,5));
2582 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2583 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2585 gr_setcolor( BM_XRGB(2,2,2));
2586 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2588 gr_setcolor( BM_XRGB(0,0,0));
2589 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2593 grd_curcanv->cv_font = SELECTED_FONT;
2595 grd_curcanv->cv_font = NORMAL_FONT;
2596 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2598 gr_setcolor( BM_XRGB(5,5,5));
2599 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2600 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2602 gr_setcolor( BM_XRGB(2,2,2));
2603 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2604 gr_setcolor( BM_XRGB(0,0,0));
2606 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2607 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2612 } else if ( citem != ocitem ) {
2618 if ( (i>=0) && (i<NumFiles) ) {
2619 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2621 grd_curcanv->cv_font = SELECTED_FONT;
2623 grd_curcanv->cv_font = NORMAL_FONT;
2624 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2625 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2626 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2629 if ( (i>=0) && (i<NumFiles) ) {
2630 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2632 grd_curcanv->cv_font = SELECTED_FONT;
2634 grd_curcanv->cv_font = NORMAL_FONT;
2635 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2636 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2637 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2644 grd_curcanv->cv_font = NORMAL_FONT;
2646 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2650 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2654 if (show_down_arrow)
2655 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2659 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2667 WIN(DDGRUNLOCK(dd_grd_curcanv));
2673 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2680 keyd_repeat = old_keyd_repeat;
2682 if ( initialized ) {
2683 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2685 WIN (DDGRLOCK(dd_grd_curcanv));
2686 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2687 WIN (DDGRUNLOCK(dd_grd_curcanv));
2689 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2690 gr_free_bitmap(bg.background);
2693 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2694 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2696 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2697 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2707 WIN(mouse_set_mode(1)); //re-enable centering mode
2715 // Example listbox callback function...
2716 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2720 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2721 // if ( *nitems > 1 ) {
2722 // unlink( items[*citem] ); // Delete the file
2723 // for (i=*citem; i<*nitems-1; i++ ) {
2724 // items[i] = items[i+1];
2726 // *nitems = *nitems - 1;
2727 // d_free( items[*nitems] );
2728 // items[*nitems] = NULL;
2729 // return 1; // redraw;
2736 #define LB_ITEMS_ON_SCREEN 8
2738 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2740 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2743 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 ) )
2746 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2747 int old_keyd_repeat = keyd_repeat;
2748 int width, height, wx, wy, title_height, border_size;
2749 int total_width,total_height;
2751 #if defined(MACINTOSH) || defined(WINDOWS)
2752 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2753 int close_x,close_y;
2754 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2756 WIN(int win_redraw=0);
2760 PA_DFX (pa_set_frontbuffer_current());
2761 PA_DFX (pa_set_front_to_read());
2762 WIN(mouse_set_mode(0)); //disable centering mode
2764 // set_screen_mode(SCREEN_MENU);
2768 RePaintNewmenuListbox:
2770 dd_gr_set_current_canvas(NULL);
2772 gr_set_current_canvas(NULL);
2775 grd_curcanv->cv_font = SUBTITLE_FONT;
2778 for (i=0; i<nitems; i++ ) {
2780 gr_get_string_size( items[i], &w, &h, &aw );
2784 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2788 gr_get_string_size( title, &w, &h, &aw );
2791 title_height = h + 5;
2794 border_size = grd_curfont->ft_w;
2795 WIN (border_size=grd_curfont->ft_w*2);
2797 width += (grd_curfont->ft_w);
2798 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2799 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2801 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2802 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2803 if ( wy < title_height )
2806 total_width = width+2*border_size;
2807 total_height = height+2*border_size+title_height;
2811 #if !defined(WINDOWS)
2812 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2813 bg.background = &VR_offscreen_buffer->cv_bitmap;
2816 //bg.background = gr_create_bitmap( width, (height + title_height) );
2817 #if defined(POLY_ACC)
2818 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2820 bg.background = gr_create_bitmap(total_width,total_height);
2822 Assert( bg.background != NULL );
2824 WIN (DDGRLOCK(dd_grd_curcanv));
2825 //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 );
2826 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2827 WIN (DDGRUNLOCK(dd_grd_curcanv));
2831 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2832 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2833 dd_VR_offscreen_buffer, 0, 0,
2834 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2835 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2839 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2841 WIN(DDGRLOCK(dd_grd_curcanv));
2842 gr_string( 0x8000, wy - title_height, title );
2843 WIN(DDGRUNLOCK(dd_grd_curcanv));
2848 citem = default_item;
2849 if ( citem < 0 ) citem = 0;
2850 if ( citem >= nitems ) citem = 0;
2854 #if defined(MACINTOSH) || defined(WINDOWS)
2855 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2856 close_x = wx-border_size;
2857 close_y = wy-title_height-border_size;
2858 draw_close_box(close_x,close_y);
2870 DoMessageStuff(&msg);
2872 if (_RedrawScreen) {
2873 _RedrawScreen = FALSE;
2875 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2876 gr_free_bitmap(bg.background);
2878 goto RePaintNewmenuListbox;
2885 ofirst_item = first_item;
2886 #if defined(MACINTOSH) || defined(WINDOWS)
2887 omouse_state = mouse_state;
2888 mouse_state = mouse_button_state(0);
2890 //see if redbook song needs to be restarted
2891 songs_check_redbook_repeat();
2895 if ( listbox_callback )
2896 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2917 else if (simukey==1)
2923 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2924 case KEY_PRINT_SCREEN:
2926 save_screen_shot(0);
2927 PA_DFX (pa_set_frontbuffer_current());
2928 PA_DFX (pa_set_front_to_read());
2951 citem += LB_ITEMS_ON_SCREEN;
2955 citem -= LB_ITEMS_ON_SCREEN;
2958 if (allow_abort_flag) {
2969 case KEY_COMMAND+KEY_Q: {
2970 extern void macintosh_quit();
2972 if ( !(Game_mode & GM_MULTI) )
2982 int ascii = key_to_ascii(key);
2983 if ( ascii < 255 ) {
2986 if (cc1 < 0 ) cc1 = 0;
2987 if (cc1 >= nitems ) cc1 = 0;
2989 if ( cc < 0 ) cc = 0;
2990 if ( cc >= nitems ) cc = 0;
2991 if ( citem == cc ) break;
2993 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
3010 if (citem< first_item)
3013 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
3014 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3016 if (nitems <= LB_ITEMS_ON_SCREEN )
3019 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3020 first_item = nitems-LB_ITEMS_ON_SCREEN;
3021 if (first_item < 0 ) first_item = 0;
3024 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3035 #if defined(MACINTOSH) || defined(WINDOWS)
3040 mouse_get_pos(&mx, &my);
3041 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3044 gr_get_string_size(items[i], &w, &h, &aw );
3047 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3049 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3061 //no double-click stuff for listbox
3062 //@@if (!mouse_state && omouse_state) {
3065 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3066 //@@ mouse_get_pos(&mx, &my);
3068 //@@ x2 = wx + width;
3069 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3071 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3072 //@@ if (dblclick_flag) done = 1;
3076 //check for close box clicked
3077 if ( !mouse_state && omouse_state ) {
3078 mouse_get_pos(&mx, &my);
3079 x1 = close_x + CLOSE_X + 2;
3080 x2 = x1 + CLOSE_SIZE - 2;
3081 y1 = close_y + CLOSE_Y + 2;
3082 y2 = y1 + CLOSE_SIZE - 2;
3083 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3093 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3095 y1 = total_height-LHY(7);
3097 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3105 if ( (ofirst_item != first_item) || redraw) {
3108 WIN(DDGRLOCK(dd_grd_curcanv));
3110 gr_setcolor( BM_XRGB( 0,0,0) );
3111 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3113 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3114 if ( i >= nitems ) {
3115 gr_setcolor( BM_XRGB(0,0,0));
3116 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3119 grd_curcanv->cv_font = SELECTED_FONT;
3121 grd_curcanv->cv_font = NORMAL_FONT;
3122 gr_get_string_size(items[i], &w, &h, &aw );
3123 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3124 gr_string( wx+5, y, items[i] );
3129 // If Win95 port, draw up/down arrows on left side of menu
3131 grd_curcanv->cv_font = NORMAL_FONT;
3133 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3137 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3141 if (show_down_arrow)
3142 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3146 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3153 WIN(DDGRUNLOCK(dd_grd_curcanv));
3157 } else if ( citem != ocitem ) {
3163 WIN(DDGRLOCK(dd_grd_curcanv));
3166 if ( (i>=0) && (i<nitems) ) {
3167 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3169 grd_curcanv->cv_font = SELECTED_FONT;
3171 grd_curcanv->cv_font = NORMAL_FONT;
3172 gr_get_string_size(items[i], &w, &h, &aw );
3173 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3174 gr_string( wx+5, y, items[i] );
3178 if ( (i>=0) && (i<nitems) ) {
3179 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3181 grd_curcanv->cv_font = SELECTED_FONT;
3183 grd_curcanv->cv_font = NORMAL_FONT;
3184 gr_get_string_size( items[i], &w, &h, &aw );
3185 gr_rect( wx, y-1, wx+width-1, y+h );
3186 gr_string( wx+5, y, items[i] );
3188 WIN(DDGRUNLOCK(dd_grd_curcanv));
3198 keyd_repeat = old_keyd_repeat;
3200 WIN (DDGRLOCK(dd_grd_curcanv));
3201 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3202 WIN (DDGRUNLOCK(dd_grd_curcanv));
3204 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3205 gr_free_bitmap(bg.background);
3209 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3210 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3212 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3213 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3219 WIN(mouse_set_mode(1)); //re-enable centering mode
3224 int newmenu_filelist( char * title, char * filespec, char * filename )
3227 char * Filenames[MAX_FILES];
3228 char FilenameText[MAX_FILES][14];
3229 FILEFINDSTRUCT find;
3232 if( !FileFindFirst( filespec, &find ) ) {
3234 if (NumFiles<MAX_FILES) {
3235 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3236 Filenames[NumFiles] = FilenameText[NumFiles];
3241 } while( !FileFindNext( &find ) );
3245 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3247 strcpy( filename, Filenames[i] );
3253 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3254 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3260 char nm_text[MESSAGEBOX_TEXT_SIZE];
3261 newmenu_item nm_message_items[5];
3263 va_start(args, nchoices );
3265 Assert( nchoices <= 5 );
3267 for (i=0; i<nchoices; i++ ) {
3268 s = va_arg( args, char * );
3269 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3271 format = va_arg( args, char * );
3272 //sprintf( nm_text, "" ); // adb: ?
3273 vsprintf(nm_text,format,args);
3276 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3278 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3280 //end this section addition - Victor Rachels
3283 extern netgame_info Active_games[];
3284 extern int NumActiveNetgames;
3286 void show_extra_netgame_info(int choice)
3292 if (choice>=NumActiveNetgames)
3297 m[i].text=(char *)&mtext[i];
3298 m[i].type=NM_TYPE_TEXT;
3301 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3302 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3303 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3304 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3306 already_showing_info=1;
3307 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3308 already_showing_info=0;
3313 /* Spiffy word wrap string formatting function */
3315 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3321 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3324 wordptr = strtok(tbuf, " ");
3325 if (!wordptr) return;
3331 col = col+strlen(wordptr)+1;
3332 if (col >=line_length) {
3334 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3337 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3339 wordptr = strtok(NULL, " ");