2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 static char rcsid[] = "$Id: newmenu.c,v 1.2 2001-01-20 13:49:16 bradleyb Exp $";
32 #include "pa_enabl.h" //$$POLY_ACC
77 #define MAXDISPLAYABLEITEMS 15
79 #define LHX(x) ((x)*(MenuHires?2:1))
80 #define LHY(y) ((y)*(MenuHires?2.4:1))
82 #define TITLE_FONT HUGE_FONT
83 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
84 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
85 #define SUBTITLE_FONT MEDIUM3_FONT
87 #define NORMAL_CHECK_BOX "
\81"
88 #define CHECKED_CHECK_BOX "
\82"
90 #define NORMAL_RADIO_BOX "
\7f"
91 #define CHECKED_RADIO_BOX "
\80"
92 #define CURSOR_STRING "_"
93 #define SLIDER_LEFT "
\83" // 131
94 #define SLIDER_RIGHT "
\84" // 132
95 #define SLIDER_MIDDLE "
\85" // 133
96 #define SLIDER_MARKER "
\86" // 134
97 #define UP_ARROW_MARKER "
\87" // 135
98 #define DOWN_ARROW_MARKER "
\88" // 136
100 int newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem, char * filename, int width, int height, int TinyMode );
101 void show_extra_netgame_info(int choice);
104 int Newmenu_first_time = 1;
105 //--unused-- int Newmenu_fade_in = 1;
108 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
109 grs_bitmap * saved; // The background under the menu.
110 grs_bitmap * background;
113 grs_bitmap nm_background,nm_background_save;
115 #define MESSAGEBOX_TEXT_SIZE 300 // How many characters in messagebox
116 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
118 extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
120 ubyte MenuReordering=0;
122 char Pauseable_menu=0;
123 char already_showing_info=0;
126 void newmenu_close() {
127 if ( nm_background.bm_data )
128 d_free(nm_background.bm_data);
130 if ( nm_background_save.bm_data )
131 d_free(nm_background_save.bm_data);
132 Newmenu_first_time = 1;
135 ubyte background_palette[768];
137 //should be called whenever the palette changes
138 void nm_remap_background()
140 if (!Newmenu_first_time) {
141 if (!nm_background.bm_data)
142 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
144 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
146 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
152 extern char last_palette_loaded[];
154 void nm_draw_background1(char * filename)
160 //@@//I think this only gets called to fill the whole screen
161 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
162 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
164 bmp = gr_create_bitmap(grd_curcanv->cv_bitmap.bm_w,grd_curcanv->cv_bitmap.bm_h);
166 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
167 Assert(pcx_error == PCX_ERROR_NONE);
169 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
172 { //remap stuff. this code is kindof a hack
174 //now, before we bring up the menu, we need to
175 //do some stuff to make sure the palette is ok. First, we need to
176 //get our current palette into the 2d's array, so the remapping will
177 //work. Second, we need to remap the fonts. Third, we need to fill
178 //in part of the fade tables so the darkening of the menu edges works
180 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
181 remap_fonts_and_menus(1);
185 WIN(DDGRLOCK(dd_grd_curcanv));
186 #if defined(POLY_ACC)
188 pa_update_clut(gr_palette, 0, 256, 0);
191 #if defined(POLY_ACC)
194 WIN(DDGRUNLOCK(dd_grd_curcanv));
198 strcpy(last_palette_loaded,""); //force palette load next time
203 #define MENU_BACKGROUND_BITMAP (MenuHires?"\x01scoresb.pcx":"\x01scores.pcx") //read only from hog file
205 #define MENU_BACKGROUND_BITMAP (MenuHires?"scoresb.pcx":"scores.pcx")
208 int Background_hires;
211 void nm_draw_background(int x1, int y1, int x2, int y2 )
215 if (Newmenu_first_time || MenuHires!=Background_hires) {
218 if (Newmenu_first_time) {
219 atexit( newmenu_close );
220 Newmenu_first_time = 0;
221 nm_background_save.bm_data=NULL;
224 if (nm_background_save.bm_data)
225 d_free(nm_background_save.bm_data);
226 if (nm_background.bm_data)
227 d_free(nm_background.bm_data);
230 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
231 Assert(pcx_error == PCX_ERROR_NONE);
233 nm_background = nm_background_save;
234 nm_background.bm_data=NULL;
235 nm_remap_background();
237 Background_hires = MenuHires;
240 if ( x1 < 0 ) x1 = 0;
241 if ( y1 < 0 ) y1 = 0;
246 if ( w > nm_background.bm_w ) w = nm_background.bm_w;
247 if ( h > nm_background.bm_h ) h = nm_background.bm_h;
252 WIN(DDGRLOCK(dd_grd_curcanv));
254 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
256 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
261 Gr_scanline_darkening_level = 2*7;
264 gr_setcolor( BM_XRGB(0,0,0) );
265 gr_urect( x2-5, y1+5, x2-5, y2-5 );
266 gr_urect( x2-4, y1+4, x2-4, y2-5 );
267 gr_urect( x2-3, y1+3, x2-3, y2-5 );
268 gr_urect( x2-2, y1+2, x2-2, y2-5 );
269 gr_urect( x2-1, y1+1, x2-1, y2-5 );
270 gr_urect( x2+0, y1+0, x2-0, y2-5 );
272 gr_urect( x1+5, y2-5, x2, y2-5 );
273 gr_urect( x1+4, y2-4, x2, y2-4 );
274 gr_urect( x1+3, y2-3, x2, y2-3 );
275 gr_urect( x1+2, y2-2, x2, y2-2 );
276 gr_urect( x1+1, y2-1, x2, y2-1 );
277 gr_urect( x1+0, y2, x2, y2-0 );
279 WIN(DDGRUNLOCK(dd_grd_curcanv));
281 Gr_scanline_darkening_level = GR_FADE_LEVELS;
284 void nm_restore_background( int x, int y, int w, int h )
291 if ( x1 < 0 ) x1 = 0;
292 if ( y1 < 0 ) y1 = 0;
294 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
295 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
300 WIN(DDGRLOCK(dd_grd_curcanv));
301 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
302 WIN(DDGRUNLOCK(dd_grd_curcanv));
305 // Draw a left justfied string
306 void nm_string( bkg * b, int w1,int x, int y, char * s)
308 int w,h,aw,tx=0,t=0,i;
309 char *p,*s1,measure[2];
310 int XTabs[]={15,87,124,162,228,253};
316 XTabs[i]=(LHX(XTabs[i]));
324 p = strchr( s, '\t' );
331 gr_get_string_size(s, &w, &h, &aw );
337 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
338 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
342 for (i=0;i<strlen(s);i++)
344 if (s[i]=='\t' && SurfingNet)
351 gr_get_string_size(measure,&tx,&h,&aw);
352 gr_string(x,y,measure);
356 else gr_string (x,y,s);
358 if (!SurfingNet && p && (w1>0) ) {
359 gr_get_string_size(s1, &w, &h, &aw );
361 gr_string( x+w1-w, y, s1 );
367 // Draw a slider and it's string
368 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
375 p = strchr( s, '\t' );
381 gr_get_string_size(s, &w, &h, &aw );
384 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
385 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
387 gr_string( x, y, s );
390 gr_get_string_size(s1, &w, &h, &aw );
393 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
395 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
397 gr_string( x+w1-w, y, s1 );
404 // Draw a left justfied string with black background.
405 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
408 gr_get_string_size(s, &w, &h, &aw );
412 WIN(DDGRLOCK(dd_grd_curcanv));
413 gr_setcolor( BM_XRGB(2,2,2) );
414 gr_rect( x-1, y-1, x-1, y+h-1 );
415 gr_rect( x-1, y-1, x+w1-1, y-1 );
418 gr_setcolor( BM_XRGB(5,5,5) );
419 gr_rect( x, y+h, x+w1, y+h);
420 gr_rect( x+w1, y-1, x+w1, y+h );
422 gr_setcolor( BM_XRGB(0,0,0) );
423 gr_rect( x, y, x+w1-1, y+h-1 );
425 gr_string( x+1, y+1, s );
426 WIN(DDGRUNLOCK(dd_grd_curcanv));
430 // Draw a right justfied string
431 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
434 gr_get_string_size(s, &w, &h, &aw );
439 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
442 WIN(DDGRLOCK(dd_grd_curcanv));
443 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
444 gr_string( x-w, y, s );
445 WIN(DDGRUNLOCK(dd_grd_curcanv));
450 //for text items, constantly redraw cursor (to achieve flash)
451 void update_cursor( newmenu_item *item)
454 fix time = timer_get_approx_seconds();
456 char * text = item->text;
458 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
461 gr_get_string_size(text, &w, &h, &aw );
462 if ( w > item->w-10 )
469 x = item->x+w; y = item->y;
471 WIN(DDGRLOCK(dd_grd_curcanv));
473 gr_string( x, y, CURSOR_STRING );
475 gr_setcolor( BM_XRGB(0,0,0) );
476 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
478 WIN(DDGRUNLOCK(dd_grd_curcanv));
481 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
486 gr_get_string_size(text, &w1, &h1, &aw );
495 nm_string_black( b, w, x, y, text );
498 gr_string( x+w1+1, y, CURSOR_STRING );
502 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
507 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
509 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
511 if (item->text[0]=='\t')
512 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
517 grd_curcanv->cv_font = SELECTED_FONT;
519 grd_curcanv->cv_font = NORMAL_FONT;
522 if (is_current && item->type == NM_TYPE_TEXT)
523 grd_curcanv->cv_font = NORMAL_FONT;
527 WIN(DDGRLOCK(dd_grd_curcanv));
528 switch( item->type ) {
530 // grd_curcanv->cv_font=TEXT_FONT;
531 // fall through on purpose
534 nm_string( b, item->w, item->x, item->y, item->text );
536 case NM_TYPE_SLIDER: {
538 if (item->value < item->min_value) item->value=item->min_value;
539 if (item->value > item->max_value) item->value=item->max_value;
540 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
541 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
542 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
544 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
546 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
548 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
551 case NM_TYPE_INPUT_MENU:
552 if ( item->group==0 ) {
553 nm_string( b, item->w, item->x, item->y, item->text );
555 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
559 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
562 nm_string( b, item->w, item->x, item->y, item->text );
564 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
566 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
569 nm_string( b, item->w, item->x, item->y, item->text );
571 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
573 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
575 case NM_TYPE_NUMBER: {
577 if (item->value < item->min_value) item->value=item->min_value;
578 if (item->value > item->max_value) item->value=item->max_value;
579 nm_string( b, item->w, item->x, item->y, item->text );
580 sprintf( text, "%d", item->value );
581 nm_rstring( b,item->right_offset,item->x, item->y, text );
585 WIN(DDGRUNLOCK(dd_grd_curcanv));
589 char *Newmenu_allowed_chars=NULL;
591 //returns true if char is allowed
592 int char_allowed(char c)
594 char *p = Newmenu_allowed_chars;
602 if (c>=p[0] && c<=p[1])
611 void strip_end_whitespace( char * text )
615 for (i=l-1; i>=0; i-- ) {
616 if ( isspace(text[i]) )
623 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
625 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
627 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
629 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
633 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
635 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
639 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 )
641 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
645 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 )
647 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
649 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 )
651 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
654 //returns 1 if a control device button has been pressed
655 int check_button_press()
659 switch (Config_control_type) {
660 case CONTROL_JOYSTICK:
661 case CONTROL_FLIGHTSTICK_PRO:
662 case CONTROL_THRUSTMASTER_FCS:
663 case CONTROL_GRAVIS_GAMEPAD:
665 if (joy_get_button_down_cnt(i)>0) return 1;
668 case CONTROL_CYBERMAN:
669 #ifndef MACINTOSH // don't allow mouse to continue from menu
671 if (mouse_button_down_count(i)>0) return 1;
674 case CONTROL_WINJOYSTICK:
677 if (joy_get_button_down_cnt(i)>0) return 1;
680 case CONTROL_NONE: //keyboard only
682 if (key_checkch()) return 1;
687 Error("Bad control type (Config_control_type):%i",Config_control_type);
693 extern int network_request_player_names(int);
694 extern int RestoringMenu;
696 #if defined(WINDOWS) || defined(MACINTOSH)
697 ubyte Hack_DblClick_MenuMode=0;
700 MAC(extern ubyte joydefs_calibrating;)
704 #define CLOSE_SIZE 10
706 void draw_close_box(int x,int y)
708 WIN (DDGRLOCK(dd_grd_curcanv));
709 gr_setcolor( BM_XRGB(0, 0, 0) );
710 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
711 gr_setcolor( BM_XRGB(21, 21, 21) );
712 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
713 WIN (DDGRUNLOCK(dd_grd_curcanv));
716 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 )
718 int old_keyd_repeat, done;
719 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
720 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
721 grs_font * save_font;
722 int string_width, string_height, average_width;
725 int all_text=0; //set true if all text items
726 int sound_stopped=0,time_stopped=0;
727 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
730 int MaxOnMenu=MAXDISPLAYABLEITEMS;
731 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
732 #if defined(MACINTOSH) || defined(WINDOWS)
733 int mouse_state, omouse_state, dblclick_flag=0;
734 int mx=0, my=0, x1, x2, y1, y2;
738 EventRecord event; // looking for disk inserted events for CD mounts
741 PA_DFX (pa_set_frontbuffer_current());
742 PA_DFX (pa_set_front_to_read());
744 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
753 WIN(mouse_set_mode(0)); //disable centering mode
755 MaxDisplayable=nitems;
757 // set_screen_mode(SCREEN_MENU);
760 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
761 digi_pause_digi_sounds();
765 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
778 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
780 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
782 save_font = grd_curcanv->cv_font;
787 grd_curcanv->cv_font = TITLE_FONT;
788 gr_get_string_size(title,&string_width,&string_height,&average_width );
793 grd_curcanv->cv_font = SUBTITLE_FONT;
794 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
795 if (string_width > tw )
800 th += LHY(8); //put some space between titles & body
803 grd_curcanv->cv_font = SMALL_FONT;
805 grd_curcanv->cv_font = NORMAL_FONT;
809 nmenus = nothers = 0;
811 // Find menu height & width (store in w,h)
812 for (i=0; i<nitems; i++ ) {
815 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
816 item[i].right_offset = 0;
819 string_height+=LHY(3);
821 item[i].saved_text[0] = '\0';
823 if ( item[i].type == NM_TYPE_SLIDER ) {
826 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
827 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
828 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
830 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
831 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
832 string_width += w1 + aw;
835 if ( item[i].type == NM_TYPE_MENU ) {
839 if ( item[i].type == NM_TYPE_CHECK ) {
842 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
843 item[i].right_offset = w1;
844 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
845 if (w1 > item[i].right_offset)
846 item[i].right_offset = w1;
849 if (item[i].type == NM_TYPE_RADIO ) {
852 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
853 item[i].right_offset = w1;
854 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
855 if (w1 > item[i].right_offset)
856 item[i].right_offset = w1;
859 if (item[i].type==NM_TYPE_NUMBER ) {
863 sprintf( test_text, "%d", item[i].max_value );
864 gr_get_string_size( test_text, &w1, &h1, &aw1 );
865 item[i].right_offset = w1;
866 sprintf( test_text, "%d", item[i].min_value );
867 gr_get_string_size( test_text, &w1, &h1, &aw1 );
868 if ( w1 > item[i].right_offset)
869 item[i].right_offset = w1;
872 if ( item[i].type == NM_TYPE_INPUT ) {
873 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
874 strcpy(item[i].saved_text, item[i].text );
876 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
877 if ( string_width > MAX_TEXT_WIDTH )
878 string_width = MAX_TEXT_WIDTH;
882 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
883 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
884 strcpy(item[i].saved_text, item[i].text );
886 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
891 item[i].w = string_width;
892 item[i].h = string_height;
894 if ( string_width > w )
895 w = string_width; // Save maximum width
896 if ( average_width > aw )
898 h += string_height+1; // Find the height of all strings
901 // Big hack for allowing the netgame options menu to spill over
903 MaxOnMenu=MAXDISPLAYABLEITEMS;
904 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
907 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
910 h=(MaxOnMenu*(string_height+1)+LHY(8));
911 MaxDisplayable=MaxOnMenu;
912 mprintf ((0,"Hey, this is a scroll box!\n"));
925 for (i=0; i<nitems; i++ ) {
927 if (item[i].right_offset > right_offset )
928 right_offset = item[i].right_offset;
930 if (right_offset > 0 )
933 //gr_get_string_size("",&string_width,&string_height,&average_width );
940 twidth = ( tw - w )/2;
945 { right_offset=0; twidth=0;}
947 mprintf(( 0, "Right offset = %d\n", right_offset ));
950 // Find min point of menu border
951 // x = (grd_curscreen->sc_w-w)/2;
952 // y = (grd_curscreen->sc_h-h)/2;
954 w += MenuHires?60:30;
955 h += MenuHires?60:30;
957 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
958 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
960 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
961 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
966 if ( filename != NULL ) {
967 nm_draw_background1( filename );
968 gr_palette_load(gr_palette);
971 // Save the background of the display
972 // Win95 must refer to the screen as a dd_grs_canvas, so...
973 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
974 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
976 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
977 gr_set_current_canvas(bg.menu_canvas) );
979 if ( filename == NULL ) {
980 // Save the background under the menu...
986 #if defined(POLY_ACC)
987 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
989 bg.saved = gr_create_bitmap( w, h );
991 Assert( bg.saved != NULL );
993 WIN (DDGRLOCK(dd_grd_curcanv));
994 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
995 WIN (DDGRUNLOCK(dd_grd_curcanv));
997 WINDOS ( dd_gr_set_current_canvas(NULL),
998 gr_set_current_canvas( NULL )
1001 nm_draw_background(x,y,x+w-1,y+h-1);
1003 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1004 gr_set_current_canvas( bg.menu_canvas )
1007 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1011 #if defined(POLY_ACC)
1012 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1014 bg.background = gr_create_bitmap( w, h );
1016 Assert( bg.background != NULL );
1018 WIN (DDGRLOCK(dd_grd_curcanv));
1019 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1020 WIN (DDGRUNLOCK(dd_grd_curcanv));
1023 // ty = 15 + (yborder/4);
1025 ty = MenuHires?30:15;
1028 grd_curcanv->cv_font = TITLE_FONT;
1029 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1030 gr_get_string_size(title,&string_width,&string_height,&average_width );
1033 WIN (DDGRLOCK(dd_grd_curcanv));
1034 gr_printf( 0x8000, ty, title );
1035 WIN (DDGRUNLOCK(dd_grd_curcanv));
1040 grd_curcanv->cv_font = SUBTITLE_FONT;
1041 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1042 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1045 WIN (DDGRLOCK(dd_grd_curcanv));
1046 gr_printf( 0x8000, ty, subtitle );
1047 WIN (DDGRUNLOCK(dd_grd_curcanv));
1052 grd_curcanv->cv_font = SMALL_FONT;
1054 grd_curcanv->cv_font = NORMAL_FONT;
1056 // Update all item's x & y values.
1057 for (i=0; i<nitems; i++ ) {
1058 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1059 item[i].y += (MenuHires?30:15);
1060 if ( item[i].type==NM_TYPE_RADIO ) {
1061 fm = -1; // find first marked one
1062 for ( j=0; j<nitems; j++ ) {
1063 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1064 if (fm==-1 && item[j].value)
1076 old_keyd_repeat = keyd_repeat;
1082 if (citem < 0 ) citem = 0;
1083 if (citem > nitems-1 ) citem = nitems-1;
1086 #if defined(WINDOWS) || defined(MACINTOSH)
1090 while ( item[choice].type==NM_TYPE_TEXT ) {
1092 if (choice >= nitems ) {
1095 if (choice == citem ) {
1106 // Clear mouse, joystick to clear button presses.
1107 game_flush_inputs();
1109 #if defined(WINDOWS) || defined(MACINTOSH)
1110 mouse_state = omouse_state = 0;
1111 if (filename == NULL && !MenuReordering) {
1112 draw_close_box(0,0);
1118 if (!MenuReordering) {
1120 SetCursor (LoadCursor(NULL,IDC_ARROW));
1125 if (!joydefs_calibrating)
1129 mprintf ((0,"Set to true!\n"));
1135 DoMessageStuff(&msg);
1137 if (_RedrawScreen) {
1138 _RedrawScreen = FALSE;
1141 gr_free_bitmap(bg.saved);
1142 d_free( bg.background );
1145 gr_free_bitmap(bg.background);
1147 dd_gr_free_sub_canvas( bg.menu_canvas );
1148 grd_curcanv->cv_font = save_font;
1149 dd_grd_curcanv = save_canvas;
1151 goto RePaintNewmenu4;
1160 omouse_state = mouse_state;
1161 mouse_state = mouse_button_state(0);
1162 if (!joydefs_calibrating)
1163 show_cursor(); // possibly hidden
1167 omouse_state = mouse_state;
1168 if (!MenuReordering)
1169 mouse_state = mouse_button_state(0);
1170 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1173 //see if redbook song needs to be restarted
1174 songs_check_redbook_repeat();
1181 (*subfunction)(nitems,item,&k,choice);
1184 if (!time_stopped) {
1185 // Save current menu box
1186 if (multi_menu_poll() == -1)
1192 dont_restore = (k == -3); //-3 means don't restore
1198 if (check_button_press())
1202 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1205 old_choice = choice;
1211 if (SurfingNet && !already_showing_info)
1213 show_extra_netgame_info(choice-2);
1215 if (SurfingNet && already_showing_info)
1222 if (SurfingNet && !already_showing_info)
1224 network_request_player_names(choice-2);
1226 if (SurfingNet && already_showing_info)
1241 case KEY_TAB + KEY_SHIFTED:
1244 if (all_text) break;
1251 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1253 if (choice<TopChoice)
1254 { choice=TopChoice; break; }
1256 if (choice<ScrollOffset)
1258 for (i=0;i<nitems;i++)
1261 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1266 if (choice >= nitems ) choice=0;
1267 if (choice < 0 ) choice=nitems-1;
1269 } while ( item[choice].type==NM_TYPE_TEXT );
1270 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1271 item[choice].value = -1;
1272 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1273 item[old_choice].group=0;
1274 strcpy(item[old_choice].text, item[old_choice].saved_text );
1275 item[old_choice].value = -1;
1278 item[old_choice].redraw = 1;
1279 item[choice].redraw=1;
1284 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1285 if (all_text) break;
1292 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1295 { choice--; break; }
1297 if (choice>=MaxOnMenu+ScrollOffset)
1299 for (i=0;i<nitems;i++)
1302 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1307 if (choice < 0 ) choice=nitems-1;
1308 if (choice >= nitems ) choice=0;
1311 } while ( item[choice].type==NM_TYPE_TEXT );
1313 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1314 item[choice].value = -1;
1315 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1316 item[old_choice].group=0;
1317 strcpy(item[old_choice].text, item[old_choice].saved_text );
1318 item[old_choice].value = -1;
1321 item[old_choice].redraw=1;
1322 item[choice].redraw=1;
1325 if ( choice > -1 ) {
1326 switch( item[choice].type ) {
1329 case NM_TYPE_INPUT_MENU:
1332 if ( item[choice].value )
1333 item[choice].value = 0;
1335 item[choice].value = 1;
1336 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1339 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1341 mprintf ((0,"Special redraw!\n"));
1346 item[choice].redraw=1;
1349 for (i=0; i<nitems; i++ ) {
1350 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1355 item[choice].value = 1;
1356 item[choice].redraw = 1;
1362 case KEY_SHIFTED+KEY_UP:
1363 if (MenuReordering && choice!=TopChoice)
1365 Temp=item[choice].text;
1366 TempVal=item[choice].value;
1367 item[choice].text=item[choice-1].text;
1368 item[choice].value=item[choice-1].value;
1369 item[choice-1].text=Temp;
1370 item[choice-1].value=TempVal;
1371 item[choice].redraw=1;
1372 item[choice-1].redraw=1;
1376 case KEY_SHIFTED+KEY_DOWN:
1377 if (MenuReordering && choice!=(nitems-1))
1379 Temp=item[choice].text;
1380 TempVal=item[choice].value;
1381 item[choice].text=item[choice+1].text;
1382 item[choice].value=item[choice+1].value;
1383 item[choice+1].text=Temp;
1384 item[choice+1].value=TempVal;
1385 item[choice].redraw=1;
1386 item[choice+1].redraw=1;
1393 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1394 item[choice].group = 1;
1395 item[choice].redraw = 1;
1396 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1397 item[choice].text[0] = 0;
1398 item[choice].value = -1;
1400 strip_end_whitespace(item[choice].text);
1407 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1408 item[choice].group=0;
1409 strcpy(item[choice].text, item[choice].saved_text );
1410 item[choice].redraw=1;
1411 item[choice].value = -1;
1418 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1419 case KEY_PRINT_SCREEN:
1421 save_screen_shot(0);
1422 PA_DFX (pa_set_frontbuffer_current());
1423 PA_DFX (pa_set_front_to_read());
1424 for (i=0;i<nitems;i++)
1433 case KEY_COMMAND+KEY_RIGHT:
1434 songs_goto_next_song();
1436 case KEY_COMMAND+KEY_LEFT:
1437 songs_goto_prev_song();
1439 case KEY_COMMAND+KEY_UP:
1440 songs_play_level_song(1);
1442 case KEY_COMMAND+KEY_DOWN:
1443 songs_stop_redbook();
1446 case KEY_COMMAND+KEY_M:
1448 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1449 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1452 key_close(); // no processing of keys with keyboard handler.. jeez
1455 show_boxed_message ("Mounting CD\nESC to quit");
1456 RBAMountDisk(); // OS has totaly control of the CD.
1457 if (Function_mode == FMODE_MENU)
1458 songs_play_song(SONG_TITLE,1);
1459 else if (Function_mode == FMODE_GAME)
1460 songs_play_level_song( Current_level_num );
1461 clear_boxed_message();
1470 case KEY_COMMAND+KEY_E:
1471 songs_stop_redbook();
1473 k = -1; // force key not to register
1476 case KEY_COMMAND+KEY_Q: {
1477 extern void macintosh_quit();
1479 if ( !(Game_mode & GM_MULTI) )
1481 if (!joydefs_calibrating)
1483 k = -1; // force key not to register
1490 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1497 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1499 if ( !done && mouse_state && !omouse_state && !all_text ) {
1500 mouse_get_pos(&mx, &my);
1501 for (i=0; i<nitems; i++ ) {
1502 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1503 x2 = x1 + item[i].w;
1504 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1505 y2 = y1 + item[i].h;
1506 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1507 if (i+ScrollOffset != choice) {
1508 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1511 choice = i + ScrollOffset;
1513 switch( item[choice].type ) {
1515 if ( item[choice].value )
1516 item[choice].value = 0;
1518 item[choice].value = 1;
1519 item[choice].redraw=1;
1526 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1528 mprintf ((0,"Special redraw!\n"));
1535 for (i=0; i<nitems; i++ ) {
1536 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1541 item[choice].value = 1;
1542 item[choice].redraw = 1;
1545 item[old_choice].redraw=1;
1551 if (mouse_state && all_text)
1554 if ( !done && mouse_state && !all_text ) {
1555 mouse_get_pos(&mx, &my);
1557 // check possible scrollbar stuff first
1559 int arrow_width, arrow_height, aw;
1561 if (ScrollOffset != 0) {
1562 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1563 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1564 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1565 x1 = x1 - arrow_width;
1566 y2 = y1 + arrow_height;
1567 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1570 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1572 if (choice<ScrollOffset)
1574 for (i=0;i<nitems;i++)
1577 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1581 if (ScrollOffset+MaxDisplayable<nitems) {
1582 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1583 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1584 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].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>=MaxOnMenu+ScrollOffset)
1594 for (i=0;i<nitems;i++)
1597 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1603 for (i=0; i<nitems; i++ ) {
1604 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1605 x2 = x1 + item[i].w;
1606 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1607 y2 = y1 + item[i].h;
1608 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1609 if (i+ScrollOffset != choice) {
1610 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1613 choice = i + ScrollOffset;
1615 if ( item[choice].type == NM_TYPE_SLIDER ) {
1616 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1617 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1619 strcpy(slider_text, item[choice].saved_text);
1620 p = strchr(slider_text, '\t');
1626 gr_get_string_size(s1, &slider_width, &height, &aw);
1627 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1628 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1629 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1631 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1632 x2 = x1 + slider_width + sright_width;
1633 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1634 item[choice].value = item[choice].min_value;
1635 item[choice].redraw = 2;
1636 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1637 item[choice].value = item[choice].max_value;
1638 item[choice].redraw = 2;
1639 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1640 int num_values, value_width, new_value;
1642 num_values = item[choice].max_value - item[choice].min_value + 1;
1643 value_width = (slider_width - sleft_width - sright_width) / num_values;
1644 new_value = (mx - x1 - sleft_width) / value_width;
1645 if ( item[choice].value != new_value ) {
1646 item[choice].value = new_value;
1647 item[choice].redraw = 2;
1653 if (choice == old_choice)
1655 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1656 item[choice].value = -1;
1657 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1658 item[old_choice].group=0;
1659 strcpy(item[old_choice].text, item[old_choice].saved_text );
1660 item[old_choice].value = -1;
1663 item[old_choice].redraw = 1;
1664 item[choice].redraw=1;
1670 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1671 mouse_get_pos(&mx, &my);
1672 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1673 x2 = x1 + item[choice].w;
1674 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1675 y2 = y1 + item[choice].h;
1676 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1677 if (Hack_DblClick_MenuMode) {
1678 if (dblclick_flag) done = 1;
1679 else dblclick_flag = 1;
1685 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1686 item[choice].group = 1;
1687 item[choice].redraw = 1;
1688 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1689 item[choice].text[0] = 0;
1690 item[choice].value = -1;
1692 strip_end_whitespace(item[choice].text);
1696 if ( !done && !mouse_state && omouse_state && close_box ) {
1697 mouse_get_pos(&mx, &my);
1698 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1699 x2 = x1 + CLOSE_SIZE;
1700 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1701 y2 = y1 + CLOSE_SIZE;
1702 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1708 // HACK! Don't redraw loadgame preview
1709 if (RestoringMenu) item[0].redraw = 0;
1710 #endif // ifdef MACINTOSH
1712 if ( choice > -1 ) {
1715 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1716 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1717 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1718 if (item[choice].value > 0)
1719 item[choice].value--;
1720 item[choice].text[item[choice].value] = 0;
1721 item[choice].redraw = 1;
1723 ascii = key_to_ascii(k);
1724 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1728 if (item[choice].value==-1) {
1729 item[choice].value = 0;
1732 allowed = char_allowed(ascii);
1734 if (!allowed && ascii==' ' && char_allowed('_')) {
1740 item[choice].text[item[choice].value++] = ascii;
1741 item[choice].text[item[choice].value] = 0;
1742 item[choice].redraw=1;
1746 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1747 ascii = key_to_ascii(k);
1749 int choice1 = choice;
1750 ascii = toupper(ascii);
1754 if (choice1 >= nitems ) choice1=0;
1755 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1756 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1757 (item[choice1].type==NM_TYPE_CHECK) ||
1758 (item[choice1].type==NM_TYPE_RADIO) ||
1759 (item[choice1].type==NM_TYPE_NUMBER) ||
1760 (item[choice1].type==NM_TYPE_SLIDER) )
1761 && (ascii==toupper(ch)) ) {
1765 item[old_choice].redraw=1;
1766 item[choice].redraw=1;
1768 } while (choice1 != choice );
1772 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1773 int ov=item[choice].value;
1778 case KEY_MINUS+KEY_SHIFTED:
1780 item[choice].value -= 1;
1785 case KEY_EQUAL+KEY_SHIFTED:
1787 item[choice].value++;
1792 item[choice].value += 10;
1797 item[choice].value -= 10;
1800 if (ov!=item[choice].value)
1801 item[choice].redraw=1;
1806 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1807 gr_set_current_canvas(bg.menu_canvas));
1809 // Redraw everything...
1810 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1812 if (item[i].redraw) // warning! ugly hack below
1814 item[i].y-=((string_height+1)*ScrollOffset);
1817 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1819 MAC(if (!joydefs_calibrating) show_cursor());
1820 WIN(if (!MenuReordering) ShowCursorW());
1821 item[i].y+=((string_height+1)*ScrollOffset);
1823 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1824 update_cursor( &item[i]);
1830 //grd_curcanv->cv_font = NORMAL_FONT;
1832 if (LastScrollCheck!=ScrollOffset)
1834 LastScrollCheck=ScrollOffset;
1835 grd_curcanv->cv_font = SELECTED_FONT;
1837 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1838 sx=item[ScrollOffset].x-(MenuHires?24:12);
1841 if (ScrollOffset!=0)
1842 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1844 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1846 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1847 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1849 if (ScrollOffset+MaxDisplayable<nitems)
1850 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1852 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1858 if ( !dont_restore && gr_palette_faded_out ) {
1859 gr_palette_fade_in( gr_palette, 32, 0 );
1866 // Restore everything...
1868 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1869 gr_set_current_canvas(bg.menu_canvas));
1871 if ( filename == NULL ) {
1872 // Save the background under the menu...
1873 WIN (DDGRLOCK(dd_grd_curcanv));
1874 gr_bitmap(0, 0, bg.saved);
1875 WIN (DDGRUNLOCK(dd_grd_curcanv));
1876 gr_free_bitmap(bg.saved);
1877 d_free( bg.background );
1879 if (!dont_restore) //info passed back from subfunction
1881 WIN (DDGRLOCK(dd_grd_curcanv));
1882 gr_bitmap(0, 0, bg.background);
1883 WIN (DDGRUNLOCK(dd_grd_curcanv));
1885 gr_free_bitmap(bg.background);
1888 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1889 gr_free_sub_canvas( bg.menu_canvas ) );
1891 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1892 grd_curcanv->cv_font = save_font;
1893 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1894 keyd_repeat = old_keyd_repeat;
1896 game_flush_inputs();
1907 if ( sound_stopped )
1908 digi_resume_digi_sounds();
1910 WIN(mouse_set_mode(1)); //re-enable centering mode
1917 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1923 char nm_text[MESSAGEBOX_TEXT_SIZE];
1924 newmenu_item nm_message_items[5];
1926 va_start(args, nchoices );
1928 Assert( nchoices <= 5 );
1930 for (i=0; i<nchoices; i++ ) {
1931 s = va_arg( args, char * );
1932 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1934 format = va_arg( args, char * );
1935 strcpy( nm_text, "" );
1936 vsprintf(nm_text,format,args);
1939 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1941 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1944 int nm_messagebox( char *title, int nchoices, ... )
1950 char nm_text[MESSAGEBOX_TEXT_SIZE];
1951 newmenu_item nm_message_items[5];
1953 va_start(args, nchoices );
1955 Assert( nchoices <= 5 );
1957 for (i=0; i<nchoices; i++ ) {
1958 s = va_arg( args, char * );
1959 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1961 format = va_arg( args, char * );
1962 strcpy( nm_text, "" );
1963 vsprintf(nm_text,format,args);
1966 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1968 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1974 void newmenu_file_sort( int n, char *list )
1981 for (i=incr; i<n; i++ ) {
1984 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1985 memcpy( t, &list[j*14], FILENAME_LEN );
1986 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1987 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1998 void delete_player_saved_games(char * name)
2003 for (i=0;i<10; i++) {
2005 sprintf( filename, "%s.sg%d", name, i );
2007 sprintf( filename, ":Players:%s.sg%d", name, i );
2013 #define MAX_FILES 300
2015 int MakeNewPlayerFile(int allow_abort);
2017 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2020 FILEFINDSTRUCT find;
2021 int NumFiles=0, key,done, citem, ocitem;
2022 char * filenames = NULL;
2023 int NumFiles_displayed = 8;
2024 int first_item = -1, ofirst_item;
2025 int old_keyd_repeat = keyd_repeat;
2028 int demos_deleted=0;
2029 int initialized = 0;
2031 int w_x, w_y, w_w, w_h, title_height;
2032 int box_x, box_y, box_w, box_h;
2033 bkg bg; // background under listbox
2034 #if defined(MACINTOSH) || defined(WINDOWS)
2035 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2036 int mouse2_state, omouse2_state;
2037 int dblclick_flag=0;
2039 int show_up_arrow=0,show_down_arrow=0;
2041 WIN(int win_redraw=0);
2043 w_x=w_y=w_w=w_h=title_height=0;
2044 box_x=box_y=box_w=box_h=0;
2046 filenames = d_malloc( MAX_FILES * 14 );
2047 if (filenames==NULL) return 0;
2052 WIN(mouse_set_mode(0)); //disable centering mode
2054 if (strstr( filespec, "*.plr" ))
2056 else if (strstr( filespec, "*.dem" ))
2063 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2065 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2070 if( !FileFindFirst( filespec, &find ) ) {
2072 if (NumFiles<MAX_FILES) {
2073 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2074 if ( player_mode ) {
2076 p = strchr(&filenames[NumFiles*14],'.');
2083 } while( !FileFindNext( &find ) );
2087 if ( (NumFiles < 1) && demos_deleted ) {
2091 if ( (NumFiles < 1) && demo_mode ) {
2092 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2098 if ( (NumFiles < 2) && player_mode ) {
2100 goto ExitFileMenuEarly;
2107 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2114 // set_screen_mode(SCREEN_MENU);
2120 dd_gr_set_current_canvas(NULL);
2122 gr_set_current_canvas(NULL);
2125 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2127 grd_curcanv->cv_font = SUBTITLE_FONT;
2129 WIN(DDGRUNLOCK(dd_grd_curcanv));
2134 for (i=0; i<NumFiles; i++ ) {
2136 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2142 gr_get_string_size( title, &w, &h, &aw );
2145 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2149 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2151 w_w += (grd_curfont->ft_w * 4);
2152 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2154 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2155 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2157 w_x = (grd_curcanv->cv_w-w_w)/2;
2158 w_y = (grd_curcanv->cv_h-w_h)/2;
2160 if ( w_x < 0 ) w_x = 0;
2161 if ( w_y < 0 ) w_y = 0;
2163 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2164 box_y = w_y + title_height;
2166 // save the screen behind the menu.
2170 #if !defined(WINDOWS)
2171 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2172 bg.background = &VR_offscreen_buffer->cv_bitmap;
2175 #if defined(POLY_ACC)
2176 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2178 bg.background = gr_create_bitmap( w_w, w_h );
2181 Assert( bg.background != NULL );
2184 WIN(DDGRLOCK(dd_grd_curcanv));
2185 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2186 WIN(DDGRUNLOCK(dd_grd_curcanv));
2190 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2191 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2192 dd_VR_offscreen_buffer, 0, 0,
2193 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2194 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2198 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2200 WIN(DDGRLOCK(dd_grd_curcanv))
2202 gr_string( 0x8000, w_y+10, title );
2204 WIN(DDGRUNLOCK(dd_grd_curcanv));
2211 if ( !player_mode ) {
2212 newmenu_file_sort( NumFiles, filenames );
2214 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2215 newmenu_file_sort( NumFiles, filenames );
2217 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2219 for ( i=0; i<NumFiles; i++ ) {
2220 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2221 #if defined(WINDOWS) || defined(MACINTOSH)
2229 #if defined(MACINTOSH) || defined(WINDOWS)
2230 mouse_state = omouse_state = 0;
2231 mouse2_state = omouse2_state = 0;
2232 draw_close_box(w_x,w_y);
2244 DoMessageStuff(&msg);
2246 if (_RedrawScreen) {
2247 _RedrawScreen = FALSE;
2249 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2250 gr_free_bitmap(bg.background);
2253 goto RePaintNewmenuFile;
2260 ofirst_item = first_item;
2263 #if defined(MACINTOSH) || defined(WINDOWS)
2264 omouse_state = mouse_state;
2265 omouse2_state = mouse2_state;
2266 mouse_state = mouse_button_state(0);
2267 mouse2_state = mouse_button_state(1);
2270 //see if redbook song needs to be restarted
2271 songs_check_redbook_repeat();
2274 if (!mouse2_state && omouse2_state)
2275 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2278 //NOTE LINK TO ABOVE ELSE
2284 else if (simukey==1)
2290 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2291 case KEY_PRINT_SCREEN:
2293 save_screen_shot(0);
2294 PA_DFX (pa_set_frontbuffer_current());
2295 PA_DFX (pa_set_front_to_read());
2301 case KEY_CTRLED+KEY_D:
2302 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2306 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2310 mouse_set_mode(1); //re-enable centering mode
2314 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2316 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2319 mouse_set_mode(0); //disenable centering mode
2325 char name[_MAX_PATH],dir[_MAX_DIR];
2327 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2331 _splitpath(filespec,name,dir,NULL,NULL);
2333 strcat(name,&filenames[citem*14]);
2340 if ( !strncmp(name, ".\\", 2) )
2341 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2342 name[i] = name[i+1];
2343 while ( (p = strchr(name, '\\')) )
2348 ret = unlink( name );
2352 if ((!ret) && player_mode) {
2353 delete_player_saved_games( &filenames[citem*14] );
2358 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2360 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2361 } else if (demo_mode)
2386 citem += NumFiles_displayed;
2390 citem -= NumFiles_displayed;
2393 if (allow_abort_flag) {
2404 case KEY_COMMAND+KEY_Q: {
2405 extern void macintosh_quit();
2407 if ( !(Game_mode & GM_MULTI) )
2418 int ascii = key_to_ascii(key);
2419 if ( ascii < 255 ) {
2422 if (cc1 < 0 ) cc1 = 0;
2423 if (cc1 >= NumFiles ) cc1 = 0;
2425 if ( cc < 0 ) cc = 0;
2426 if ( cc >= NumFiles ) cc = 0;
2427 if ( citem == cc ) break;
2429 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2444 if (citem>=NumFiles)
2447 if (citem< first_item)
2450 if (citem>=( first_item+NumFiles_displayed))
2452 first_item = citem-NumFiles_displayed+1;
2456 if (NumFiles>first_item+NumFiles_displayed)
2467 if (NumFiles <= NumFiles_displayed )
2470 if (first_item>NumFiles-NumFiles_displayed)
2472 first_item = NumFiles-NumFiles_displayed;
2475 if (first_item < 0 ) first_item = 0;
2477 #if defined(MACINTOSH) || defined(WINDOWS)
2479 if (mouse_state || mouse2_state) {
2482 mouse_get_pos(&mx, &my);
2483 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2484 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2486 x2 = box_x + box_w - 1;
2487 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2489 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2490 if (i == citem && !mouse2_state) {
2500 if (!mouse_state && omouse_state) {
2503 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2504 mouse_get_pos(&mx, &my);
2506 x2 = box_x + box_w - 1;
2507 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2509 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2510 if (dblclick_flag) done = 1;
2511 else dblclick_flag = 1;
2515 if ( !mouse_state && omouse_state ) {
2516 mouse_get_pos(&mx, &my);
2517 x1 = w_x + CLOSE_X + 2;
2518 x2 = x1 + CLOSE_SIZE - 2;
2519 y1 = w_y + CLOSE_Y + 2;
2520 y2 = y1 + CLOSE_SIZE - 2;
2521 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2530 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2532 y1 = box_y+box_h-LHY(7);
2534 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2541 WIN(DDGRLOCK(dd_grd_curcanv));
2542 gr_setcolor( BM_XRGB(2,2,2));
2543 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2544 gr_setcolor( BM_XRGB( 0,0,0) );
2547 if (ofirst_item != first_item || win_redraw) {
2550 if (ofirst_item != first_item) {
2554 gr_setcolor( BM_XRGB( 0,0,0) );
2555 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2557 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2559 if ( i >= NumFiles ) {
2561 gr_setcolor( BM_XRGB(5,5,5));
2562 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2563 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2565 gr_setcolor( BM_XRGB(2,2,2));
2566 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2568 gr_setcolor( BM_XRGB(0,0,0));
2569 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2573 grd_curcanv->cv_font = SELECTED_FONT;
2575 grd_curcanv->cv_font = NORMAL_FONT;
2576 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2578 gr_setcolor( BM_XRGB(5,5,5));
2579 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2580 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2582 gr_setcolor( BM_XRGB(2,2,2));
2583 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2584 gr_setcolor( BM_XRGB(0,0,0));
2586 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2587 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2592 } else if ( citem != ocitem ) {
2598 if ( (i>=0) && (i<NumFiles) ) {
2599 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2601 grd_curcanv->cv_font = SELECTED_FONT;
2603 grd_curcanv->cv_font = NORMAL_FONT;
2604 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2605 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2606 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2609 if ( (i>=0) && (i<NumFiles) ) {
2610 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2612 grd_curcanv->cv_font = SELECTED_FONT;
2614 grd_curcanv->cv_font = NORMAL_FONT;
2615 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2616 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2617 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2624 grd_curcanv->cv_font = NORMAL_FONT;
2626 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2630 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2634 if (show_down_arrow)
2635 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2639 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2647 WIN(DDGRUNLOCK(dd_grd_curcanv));
2653 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2660 keyd_repeat = old_keyd_repeat;
2662 if ( initialized ) {
2663 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2665 WIN (DDGRLOCK(dd_grd_curcanv));
2666 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2667 WIN (DDGRUNLOCK(dd_grd_curcanv));
2669 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2670 gr_free_bitmap(bg.background);
2673 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2674 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2676 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2677 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2687 WIN(mouse_set_mode(1)); //re-enable centering mode
2695 // Example listbox callback function...
2696 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2700 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2701 // if ( *nitems > 1 ) {
2702 // unlink( items[*citem] ); // Delete the file
2703 // for (i=*citem; i<*nitems-1; i++ ) {
2704 // items[i] = items[i+1];
2706 // *nitems = *nitems - 1;
2707 // d_free( items[*nitems] );
2708 // items[*nitems] = NULL;
2709 // return 1; // redraw;
2716 #define LB_ITEMS_ON_SCREEN 8
2718 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2720 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2723 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 ) )
2726 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2727 int old_keyd_repeat = keyd_repeat;
2728 int width, height, wx, wy, title_height, border_size;
2729 int total_width,total_height;
2731 #if defined(MACINTOSH) || defined(WINDOWS)
2732 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2733 int close_x,close_y;
2734 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2736 WIN(int win_redraw=0);
2740 PA_DFX (pa_set_frontbuffer_current());
2741 PA_DFX (pa_set_front_to_read());
2742 WIN(mouse_set_mode(0)); //disable centering mode
2744 // set_screen_mode(SCREEN_MENU);
2748 RePaintNewmenuListbox:
2750 dd_gr_set_current_canvas(NULL);
2752 gr_set_current_canvas(NULL);
2755 grd_curcanv->cv_font = SUBTITLE_FONT;
2758 for (i=0; i<nitems; i++ ) {
2760 gr_get_string_size( items[i], &w, &h, &aw );
2764 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2768 gr_get_string_size( title, &w, &h, &aw );
2771 title_height = h + 5;
2774 border_size = grd_curfont->ft_w;
2775 WIN (border_size=grd_curfont->ft_w*2);
2777 width += (grd_curfont->ft_w);
2778 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2779 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2781 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2782 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2783 if ( wy < title_height )
2786 total_width = width+2*border_size;
2787 total_height = height+2*border_size+title_height;
2791 #if !defined(WINDOWS)
2792 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2793 bg.background = &VR_offscreen_buffer->cv_bitmap;
2796 //bg.background = gr_create_bitmap( width, (height + title_height) );
2797 #if defined(POLY_ACC)
2798 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2800 bg.background = gr_create_bitmap(total_width,total_height);
2802 Assert( bg.background != NULL );
2804 WIN (DDGRLOCK(dd_grd_curcanv));
2805 //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 );
2806 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2807 WIN (DDGRUNLOCK(dd_grd_curcanv));
2811 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2812 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2813 dd_VR_offscreen_buffer, 0, 0,
2814 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2815 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2819 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2821 WIN(DDGRLOCK(dd_grd_curcanv));
2822 gr_string( 0x8000, wy - title_height, title );
2823 WIN(DDGRUNLOCK(dd_grd_curcanv));
2828 citem = default_item;
2829 if ( citem < 0 ) citem = 0;
2830 if ( citem >= nitems ) citem = 0;
2834 #if defined(MACINTOSH) || defined(WINDOWS)
2835 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2836 close_x = wx-border_size;
2837 close_y = wy-title_height-border_size;
2838 draw_close_box(close_x,close_y);
2850 DoMessageStuff(&msg);
2852 if (_RedrawScreen) {
2853 _RedrawScreen = FALSE;
2855 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2856 gr_free_bitmap(bg.background);
2858 goto RePaintNewmenuListbox;
2865 ofirst_item = first_item;
2866 #if defined(MACINTOSH) || defined(WINDOWS)
2867 omouse_state = mouse_state;
2868 mouse_state = mouse_button_state(0);
2870 //see if redbook song needs to be restarted
2871 songs_check_redbook_repeat();
2875 if ( listbox_callback )
2876 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2897 else if (simukey==1)
2903 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2904 case KEY_PRINT_SCREEN:
2906 save_screen_shot(0);
2907 PA_DFX (pa_set_frontbuffer_current());
2908 PA_DFX (pa_set_front_to_read());
2931 citem += LB_ITEMS_ON_SCREEN;
2935 citem -= LB_ITEMS_ON_SCREEN;
2938 if (allow_abort_flag) {
2949 case KEY_COMMAND+KEY_Q: {
2950 extern void macintosh_quit();
2952 if ( !(Game_mode & GM_MULTI) )
2962 int ascii = key_to_ascii(key);
2963 if ( ascii < 255 ) {
2966 if (cc1 < 0 ) cc1 = 0;
2967 if (cc1 >= nitems ) cc1 = 0;
2969 if ( cc < 0 ) cc = 0;
2970 if ( cc >= nitems ) cc = 0;
2971 if ( citem == cc ) break;
2973 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2990 if (citem< first_item)
2993 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2994 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2996 if (nitems <= LB_ITEMS_ON_SCREEN )
2999 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3000 first_item = nitems-LB_ITEMS_ON_SCREEN;
3001 if (first_item < 0 ) first_item = 0;
3004 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3015 #if defined(MACINTOSH) || defined(WINDOWS)
3020 mouse_get_pos(&mx, &my);
3021 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3024 gr_get_string_size(items[i], &w, &h, &aw );
3027 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3029 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3041 //no double-click stuff for listbox
3042 //@@if (!mouse_state && omouse_state) {
3045 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3046 //@@ mouse_get_pos(&mx, &my);
3048 //@@ x2 = wx + width;
3049 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3051 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3052 //@@ if (dblclick_flag) done = 1;
3056 //check for close box clicked
3057 if ( !mouse_state && omouse_state ) {
3058 mouse_get_pos(&mx, &my);
3059 x1 = close_x + CLOSE_X + 2;
3060 x2 = x1 + CLOSE_SIZE - 2;
3061 y1 = close_y + CLOSE_Y + 2;
3062 y2 = y1 + CLOSE_SIZE - 2;
3063 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3073 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3075 y1 = total_height-LHY(7);
3077 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3085 if ( (ofirst_item != first_item) || redraw) {
3088 WIN(DDGRLOCK(dd_grd_curcanv));
3090 gr_setcolor( BM_XRGB( 0,0,0) );
3091 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3093 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3094 if ( i >= nitems ) {
3095 gr_setcolor( BM_XRGB(0,0,0));
3096 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3099 grd_curcanv->cv_font = SELECTED_FONT;
3101 grd_curcanv->cv_font = NORMAL_FONT;
3102 gr_get_string_size(items[i], &w, &h, &aw );
3103 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3104 gr_string( wx+5, y, items[i] );
3109 // If Win95 port, draw up/down arrows on left side of menu
3111 grd_curcanv->cv_font = NORMAL_FONT;
3113 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3117 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3121 if (show_down_arrow)
3122 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3126 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3133 WIN(DDGRUNLOCK(dd_grd_curcanv));
3137 } else if ( citem != ocitem ) {
3143 WIN(DDGRLOCK(dd_grd_curcanv));
3146 if ( (i>=0) && (i<nitems) ) {
3147 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3149 grd_curcanv->cv_font = SELECTED_FONT;
3151 grd_curcanv->cv_font = NORMAL_FONT;
3152 gr_get_string_size(items[i], &w, &h, &aw );
3153 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3154 gr_string( wx+5, y, items[i] );
3158 if ( (i>=0) && (i<nitems) ) {
3159 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3161 grd_curcanv->cv_font = SELECTED_FONT;
3163 grd_curcanv->cv_font = NORMAL_FONT;
3164 gr_get_string_size( items[i], &w, &h, &aw );
3165 gr_rect( wx, y-1, wx+width-1, y+h );
3166 gr_string( wx+5, y, items[i] );
3168 WIN(DDGRUNLOCK(dd_grd_curcanv));
3178 keyd_repeat = old_keyd_repeat;
3180 WIN (DDGRLOCK(dd_grd_curcanv));
3181 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3182 WIN (DDGRUNLOCK(dd_grd_curcanv));
3184 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3185 gr_free_bitmap(bg.background);
3189 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3190 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3192 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3193 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3199 WIN(mouse_set_mode(1)); //re-enable centering mode
3204 int newmenu_filelist( char * title, char * filespec, char * filename )
3207 char * Filenames[MAX_FILES];
3208 char FilenameText[MAX_FILES][14];
3209 FILEFINDSTRUCT find;
3212 if( !FileFindFirst( filespec, &find ) ) {
3214 if (NumFiles<MAX_FILES) {
3215 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3216 Filenames[NumFiles] = FilenameText[NumFiles];
3221 } while( !FileFindNext( &find ) );
3225 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3227 strcpy( filename, Filenames[i] );
3234 extern netgame_info Active_games[];
3235 extern int NumActiveNetgames;
3237 void show_extra_netgame_info(int choice)
3243 if (choice>=NumActiveNetgames)
3248 m[i].text=(char *)&mtext[i];
3249 m[i].type=NM_TYPE_TEXT;
3252 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3253 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3254 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3255 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3257 already_showing_info=1;
3258 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3259 already_showing_info=0;
3264 /* Spiffy word wrap string formatting function */
3266 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3272 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3275 wordptr = strtok(tbuf, " ");
3276 if (!wordptr) return;
3282 col = col+strlen(wordptr)+1;
3283 if (col >=line_length) {
3285 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3288 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3290 wordptr = strtok(NULL, " ");