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.
19 static char rcsid[] = "$Id: newmenu.c,v 1.5 2001-10-31 09:59:34 bradleyb Exp $";
33 #include "pa_enabl.h" //$$POLY_ACC
80 #define MAXDISPLAYABLEITEMS 15
82 #define LHX(x) ((x)*(MenuHires?2:1))
83 #define LHY(y) ((y)*(MenuHires?2.4:1))
85 #define TITLE_FONT HUGE_FONT
86 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
87 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
88 #define SUBTITLE_FONT MEDIUM3_FONT
90 #define NORMAL_CHECK_BOX "
\81"
91 #define CHECKED_CHECK_BOX "
\82"
93 #define NORMAL_RADIO_BOX "
\7f"
94 #define CHECKED_RADIO_BOX "
\80"
95 #define CURSOR_STRING "_"
96 #define SLIDER_LEFT "
\83" // 131
97 #define SLIDER_RIGHT "
\84" // 132
98 #define SLIDER_MIDDLE "
\85" // 133
99 #define SLIDER_MARKER "
\86" // 134
100 #define UP_ARROW_MARKER "
\87" // 135
101 #define DOWN_ARROW_MARKER "
\88" // 136
103 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 );
104 void show_extra_netgame_info(int choice);
107 int Newmenu_first_time = 1;
108 //--unused-- int Newmenu_fade_in = 1;
111 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
112 grs_bitmap * saved; // The background under the menu.
113 grs_bitmap * background;
116 grs_bitmap nm_background,nm_background_save;
118 #define MESSAGEBOX_TEXT_SIZE 300 // How many characters in messagebox
119 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
121 extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
123 ubyte MenuReordering=0;
125 char Pauseable_menu=0;
126 char already_showing_info=0;
129 void newmenu_close() {
130 if ( nm_background.bm_data )
131 d_free(nm_background.bm_data);
133 if ( nm_background_save.bm_data )
134 d_free(nm_background_save.bm_data);
135 Newmenu_first_time = 1;
138 ubyte background_palette[768];
140 //should be called whenever the palette changes
141 void nm_remap_background()
143 if (!Newmenu_first_time) {
144 if (!nm_background.bm_data)
145 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
147 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
149 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
155 extern char last_palette_loaded[];
157 void nm_draw_background1(char * filename)
163 //@@//I think this only gets called to fill the whole screen
164 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
165 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
167 bmp = gr_create_bitmap(grd_curcanv->cv_bitmap.bm_w,grd_curcanv->cv_bitmap.bm_h);
169 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
170 Assert(pcx_error == PCX_ERROR_NONE);
172 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
175 { //remap stuff. this code is kindof a hack
177 //now, before we bring up the menu, we need to
178 //do some stuff to make sure the palette is ok. First, we need to
179 //get our current palette into the 2d's array, so the remapping will
180 //work. Second, we need to remap the fonts. Third, we need to fill
181 //in part of the fade tables so the darkening of the menu edges works
183 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
184 remap_fonts_and_menus(1);
188 WIN(DDGRLOCK(dd_grd_curcanv));
189 #if defined(POLY_ACC)
191 pa_update_clut(gr_palette, 0, 256, 0);
194 #if defined(POLY_ACC)
197 WIN(DDGRUNLOCK(dd_grd_curcanv));
201 strcpy(last_palette_loaded,""); //force palette load next time
206 #define MENU_BACKGROUND_BITMAP (MenuHires?"\x01scoresb.pcx":"\x01scores.pcx") //read only from hog file
208 #define MENU_BACKGROUND_BITMAP (MenuHires?"scoresb.pcx":"scores.pcx")
211 int Background_hires;
214 void nm_draw_background(int x1, int y1, int x2, int y2 )
218 if (Newmenu_first_time || MenuHires!=Background_hires) {
221 if (Newmenu_first_time) {
222 atexit( newmenu_close );
223 Newmenu_first_time = 0;
224 nm_background_save.bm_data=NULL;
227 if (nm_background_save.bm_data)
228 d_free(nm_background_save.bm_data);
229 if (nm_background.bm_data)
230 d_free(nm_background.bm_data);
233 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
234 Assert(pcx_error == PCX_ERROR_NONE);
236 nm_background = nm_background_save;
237 nm_background.bm_data=NULL;
238 nm_remap_background();
240 Background_hires = MenuHires;
243 if ( x1 < 0 ) x1 = 0;
244 if ( y1 < 0 ) y1 = 0;
249 if ( w > nm_background.bm_w ) w = nm_background.bm_w;
250 if ( h > nm_background.bm_h ) h = nm_background.bm_h;
255 WIN(DDGRLOCK(dd_grd_curcanv));
257 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
259 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
264 Gr_scanline_darkening_level = 2*7;
267 gr_setcolor( BM_XRGB(0,0,0) );
268 gr_urect( x2-5, y1+5, x2-5, y2-5 );
269 gr_urect( x2-4, y1+4, x2-4, y2-5 );
270 gr_urect( x2-3, y1+3, x2-3, y2-5 );
271 gr_urect( x2-2, y1+2, x2-2, y2-5 );
272 gr_urect( x2-1, y1+1, x2-1, y2-5 );
273 gr_urect( x2+0, y1+0, x2-0, y2-5 );
275 gr_urect( x1+5, y2-5, x2, y2-5 );
276 gr_urect( x1+4, y2-4, x2, y2-4 );
277 gr_urect( x1+3, y2-3, x2, y2-3 );
278 gr_urect( x1+2, y2-2, x2, y2-2 );
279 gr_urect( x1+1, y2-1, x2, y2-1 );
280 gr_urect( x1+0, y2, x2, y2-0 );
282 WIN(DDGRUNLOCK(dd_grd_curcanv));
284 Gr_scanline_darkening_level = GR_FADE_LEVELS;
287 void nm_restore_background( int x, int y, int w, int h )
294 if ( x1 < 0 ) x1 = 0;
295 if ( y1 < 0 ) y1 = 0;
297 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
298 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
303 WIN(DDGRLOCK(dd_grd_curcanv));
304 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
305 WIN(DDGRUNLOCK(dd_grd_curcanv));
308 // Draw a left justfied string
309 void nm_string( bkg * b, int w1,int x, int y, char * s)
311 int w,h,aw,tx=0,t=0,i;
312 char *p,*s1,measure[2];
313 int XTabs[]={15,87,124,162,228,253};
319 XTabs[i]=(LHX(XTabs[i]));
327 p = strchr( s, '\t' );
334 gr_get_string_size(s, &w, &h, &aw );
340 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
341 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
345 for (i=0;i<strlen(s);i++)
347 if (s[i]=='\t' && SurfingNet)
354 gr_get_string_size(measure,&tx,&h,&aw);
355 gr_string(x,y,measure);
359 else gr_string (x,y,s);
361 if (!SurfingNet && p && (w1>0) ) {
362 gr_get_string_size(s1, &w, &h, &aw );
364 gr_string( x+w1-w, y, s1 );
370 // Draw a slider and it's string
371 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
378 p = strchr( s, '\t' );
384 gr_get_string_size(s, &w, &h, &aw );
387 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
388 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
390 gr_string( x, y, s );
393 gr_get_string_size(s1, &w, &h, &aw );
396 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
398 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
400 gr_string( x+w1-w, y, s1 );
407 // Draw a left justfied string with black background.
408 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
411 gr_get_string_size(s, &w, &h, &aw );
415 WIN(DDGRLOCK(dd_grd_curcanv));
416 gr_setcolor( BM_XRGB(2,2,2) );
417 gr_rect( x-1, y-1, x-1, y+h-1 );
418 gr_rect( x-1, y-1, x+w1-1, y-1 );
421 gr_setcolor( BM_XRGB(5,5,5) );
422 gr_rect( x, y+h, x+w1, y+h);
423 gr_rect( x+w1, y-1, x+w1, y+h );
425 gr_setcolor( BM_XRGB(0,0,0) );
426 gr_rect( x, y, x+w1-1, y+h-1 );
428 gr_string( x+1, y+1, s );
429 WIN(DDGRUNLOCK(dd_grd_curcanv));
433 // Draw a right justfied string
434 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
437 gr_get_string_size(s, &w, &h, &aw );
442 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
445 WIN(DDGRLOCK(dd_grd_curcanv));
446 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
447 gr_string( x-w, y, s );
448 WIN(DDGRUNLOCK(dd_grd_curcanv));
453 //for text items, constantly redraw cursor (to achieve flash)
454 void update_cursor( newmenu_item *item)
457 fix time = timer_get_approx_seconds();
459 char * text = item->text;
461 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
464 gr_get_string_size(text, &w, &h, &aw );
465 if ( w > item->w-10 )
472 x = item->x+w; y = item->y;
474 WIN(DDGRLOCK(dd_grd_curcanv));
476 gr_string( x, y, CURSOR_STRING );
478 gr_setcolor( BM_XRGB(0,0,0) );
479 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
481 WIN(DDGRUNLOCK(dd_grd_curcanv));
484 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
489 gr_get_string_size(text, &w1, &h1, &aw );
498 nm_string_black( b, w, x, y, text );
501 gr_string( x+w1+1, y, CURSOR_STRING );
505 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
510 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
512 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
514 if (item->text[0]=='\t')
515 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
520 grd_curcanv->cv_font = SELECTED_FONT;
522 grd_curcanv->cv_font = NORMAL_FONT;
525 if (is_current && item->type == NM_TYPE_TEXT)
526 grd_curcanv->cv_font = NORMAL_FONT;
530 WIN(DDGRLOCK(dd_grd_curcanv));
531 switch( item->type ) {
533 // grd_curcanv->cv_font=TEXT_FONT;
534 // fall through on purpose
537 nm_string( b, item->w, item->x, item->y, item->text );
539 case NM_TYPE_SLIDER: {
541 if (item->value < item->min_value) item->value=item->min_value;
542 if (item->value > item->max_value) item->value=item->max_value;
543 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
544 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
545 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
547 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
549 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
551 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
554 case NM_TYPE_INPUT_MENU:
555 if ( item->group==0 ) {
556 nm_string( b, item->w, item->x, item->y, item->text );
558 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
562 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
565 nm_string( b, item->w, item->x, item->y, item->text );
567 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
569 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
572 nm_string( b, item->w, item->x, item->y, item->text );
574 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
576 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
578 case NM_TYPE_NUMBER: {
580 if (item->value < item->min_value) item->value=item->min_value;
581 if (item->value > item->max_value) item->value=item->max_value;
582 nm_string( b, item->w, item->x, item->y, item->text );
583 sprintf( text, "%d", item->value );
584 nm_rstring( b,item->right_offset,item->x, item->y, text );
588 WIN(DDGRUNLOCK(dd_grd_curcanv));
592 char *Newmenu_allowed_chars=NULL;
594 //returns true if char is allowed
595 int char_allowed(char c)
597 char *p = Newmenu_allowed_chars;
605 if (c>=p[0] && c<=p[1])
614 void strip_end_whitespace( char * text )
618 for (i=l-1; i>=0; i-- ) {
619 if ( isspace(text[i]) )
626 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
628 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
630 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
632 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
636 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
638 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
642 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 )
644 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
648 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 )
650 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
652 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 )
654 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
657 //returns 1 if a control device button has been pressed
658 int check_button_press()
662 switch (Config_control_type) {
663 case CONTROL_JOYSTICK:
664 case CONTROL_FLIGHTSTICK_PRO:
665 case CONTROL_THRUSTMASTER_FCS:
666 case CONTROL_GRAVIS_GAMEPAD:
668 if (joy_get_button_down_cnt(i)>0) return 1;
671 case CONTROL_CYBERMAN:
672 #ifndef MACINTOSH // don't allow mouse to continue from menu
674 if (mouse_button_down_count(i)>0) return 1;
677 case CONTROL_WINJOYSTICK:
680 if (joy_get_button_down_cnt(i)>0) return 1;
683 case CONTROL_NONE: //keyboard only
685 if (key_checkch()) return 1;
690 Error("Bad control type (Config_control_type):%i",Config_control_type);
696 extern int network_request_player_names(int);
697 extern int RestoringMenu;
699 #if defined(WINDOWS) || defined(MACINTOSH)
700 ubyte Hack_DblClick_MenuMode=0;
703 MAC(extern ubyte joydefs_calibrating;)
707 #define CLOSE_SIZE 10
709 void draw_close_box(int x,int y)
711 WIN (DDGRLOCK(dd_grd_curcanv));
712 gr_setcolor( BM_XRGB(0, 0, 0) );
713 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
714 gr_setcolor( BM_XRGB(21, 21, 21) );
715 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
716 WIN (DDGRUNLOCK(dd_grd_curcanv));
719 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 )
721 int old_keyd_repeat, done;
722 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
723 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
724 grs_font * save_font;
725 int string_width, string_height, average_width;
728 int all_text=0; //set true if all text items
729 int sound_stopped=0,time_stopped=0;
730 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
733 int MaxOnMenu=MAXDISPLAYABLEITEMS;
734 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
735 #if defined(MACINTOSH) || defined(WINDOWS)
736 int mouse_state, omouse_state, dblclick_flag=0;
737 int mx=0, my=0, x1, x2, y1, y2;
741 EventRecord event; // looking for disk inserted events for CD mounts
744 PA_DFX (pa_set_frontbuffer_current());
745 PA_DFX (pa_set_front_to_read());
747 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
756 WIN(mouse_set_mode(0)); //disable centering mode
758 MaxDisplayable=nitems;
761 set_screen_mode(SCREEN_MENU);
765 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
766 digi_pause_digi_sounds();
770 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
783 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
785 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
787 save_font = grd_curcanv->cv_font;
792 grd_curcanv->cv_font = TITLE_FONT;
793 gr_get_string_size(title,&string_width,&string_height,&average_width );
798 grd_curcanv->cv_font = SUBTITLE_FONT;
799 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
800 if (string_width > tw )
805 th += LHY(8); //put some space between titles & body
808 grd_curcanv->cv_font = SMALL_FONT;
810 grd_curcanv->cv_font = NORMAL_FONT;
814 nmenus = nothers = 0;
816 // Find menu height & width (store in w,h)
817 for (i=0; i<nitems; i++ ) {
820 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
821 item[i].right_offset = 0;
824 string_height+=LHY(3);
826 item[i].saved_text[0] = '\0';
828 if ( item[i].type == NM_TYPE_SLIDER ) {
831 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
832 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
833 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
835 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
836 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
837 string_width += w1 + aw;
840 if ( item[i].type == NM_TYPE_MENU ) {
844 if ( item[i].type == NM_TYPE_CHECK ) {
847 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
848 item[i].right_offset = w1;
849 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
850 if (w1 > item[i].right_offset)
851 item[i].right_offset = w1;
854 if (item[i].type == NM_TYPE_RADIO ) {
857 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
858 item[i].right_offset = w1;
859 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
860 if (w1 > item[i].right_offset)
861 item[i].right_offset = w1;
864 if (item[i].type==NM_TYPE_NUMBER ) {
868 sprintf( test_text, "%d", item[i].max_value );
869 gr_get_string_size( test_text, &w1, &h1, &aw1 );
870 item[i].right_offset = w1;
871 sprintf( test_text, "%d", item[i].min_value );
872 gr_get_string_size( test_text, &w1, &h1, &aw1 );
873 if ( w1 > item[i].right_offset)
874 item[i].right_offset = w1;
877 if ( item[i].type == NM_TYPE_INPUT ) {
878 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
879 strcpy(item[i].saved_text, item[i].text );
881 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
882 if ( string_width > MAX_TEXT_WIDTH )
883 string_width = MAX_TEXT_WIDTH;
887 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
888 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
889 strcpy(item[i].saved_text, item[i].text );
891 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
896 item[i].w = string_width;
897 item[i].h = string_height;
899 if ( string_width > w )
900 w = string_width; // Save maximum width
901 if ( average_width > aw )
903 h += string_height+1; // Find the height of all strings
906 // Big hack for allowing the netgame options menu to spill over
908 MaxOnMenu=MAXDISPLAYABLEITEMS;
909 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
912 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
915 h=(MaxOnMenu*(string_height+1)+LHY(8));
916 MaxDisplayable=MaxOnMenu;
917 mprintf ((0,"Hey, this is a scroll box!\n"));
930 for (i=0; i<nitems; i++ ) {
932 if (item[i].right_offset > right_offset )
933 right_offset = item[i].right_offset;
935 if (right_offset > 0 )
938 //gr_get_string_size("",&string_width,&string_height,&average_width );
945 twidth = ( tw - w )/2;
950 { right_offset=0; twidth=0;}
952 mprintf(( 0, "Right offset = %d\n", right_offset ));
955 // Find min point of menu border
956 // x = (grd_curscreen->sc_w-w)/2;
957 // y = (grd_curscreen->sc_h-h)/2;
959 w += MenuHires?60:30;
960 h += MenuHires?60:30;
962 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
963 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
965 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
966 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
971 if ( filename != NULL ) {
972 nm_draw_background1( filename );
973 gr_palette_load(gr_palette);
976 // Save the background of the display
977 // Win95 must refer to the screen as a dd_grs_canvas, so...
978 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
979 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
981 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
982 gr_set_current_canvas(bg.menu_canvas) );
984 if ( filename == NULL ) {
985 // Save the background under the menu...
991 #if defined(POLY_ACC)
992 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
994 bg.saved = gr_create_bitmap( w, h );
996 Assert( bg.saved != NULL );
998 WIN (DDGRLOCK(dd_grd_curcanv));
999 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1000 WIN (DDGRUNLOCK(dd_grd_curcanv));
1002 WINDOS ( dd_gr_set_current_canvas(NULL),
1003 gr_set_current_canvas( NULL )
1006 nm_draw_background(x,y,x+w-1,y+h-1);
1008 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1009 gr_set_current_canvas( bg.menu_canvas )
1012 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1016 #if defined(POLY_ACC)
1017 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1019 bg.background = gr_create_bitmap( w, h );
1021 Assert( bg.background != NULL );
1023 WIN (DDGRLOCK(dd_grd_curcanv));
1024 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1025 WIN (DDGRUNLOCK(dd_grd_curcanv));
1028 // ty = 15 + (yborder/4);
1030 ty = MenuHires?30:15;
1033 grd_curcanv->cv_font = TITLE_FONT;
1034 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1035 gr_get_string_size(title,&string_width,&string_height,&average_width );
1038 WIN (DDGRLOCK(dd_grd_curcanv));
1039 gr_printf( 0x8000, ty, title );
1040 WIN (DDGRUNLOCK(dd_grd_curcanv));
1045 grd_curcanv->cv_font = SUBTITLE_FONT;
1046 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1047 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1050 WIN (DDGRLOCK(dd_grd_curcanv));
1051 gr_printf( 0x8000, ty, subtitle );
1052 WIN (DDGRUNLOCK(dd_grd_curcanv));
1057 grd_curcanv->cv_font = SMALL_FONT;
1059 grd_curcanv->cv_font = NORMAL_FONT;
1061 // Update all item's x & y values.
1062 for (i=0; i<nitems; i++ ) {
1063 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1064 item[i].y += (MenuHires?30:15);
1065 if ( item[i].type==NM_TYPE_RADIO ) {
1066 fm = -1; // find first marked one
1067 for ( j=0; j<nitems; j++ ) {
1068 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1069 if (fm==-1 && item[j].value)
1081 old_keyd_repeat = keyd_repeat;
1087 if (citem < 0 ) citem = 0;
1088 if (citem > nitems-1 ) citem = nitems-1;
1091 #if defined(WINDOWS) || defined(MACINTOSH)
1095 while ( item[choice].type==NM_TYPE_TEXT ) {
1097 if (choice >= nitems ) {
1100 if (choice == citem ) {
1111 // Clear mouse, joystick to clear button presses.
1112 game_flush_inputs();
1114 #if defined(WINDOWS) || defined(MACINTOSH)
1115 mouse_state = omouse_state = 0;
1116 if (filename == NULL && !MenuReordering) {
1117 draw_close_box(0,0);
1123 if (!MenuReordering) {
1125 SetCursor (LoadCursor(NULL,IDC_ARROW));
1130 if (!joydefs_calibrating)
1134 mprintf ((0,"Set to true!\n"));
1140 DoMessageStuff(&msg);
1142 if (_RedrawScreen) {
1143 _RedrawScreen = FALSE;
1146 gr_free_bitmap(bg.saved);
1147 d_free( bg.background );
1150 gr_free_bitmap(bg.background);
1152 dd_gr_free_sub_canvas( bg.menu_canvas );
1153 grd_curcanv->cv_font = save_font;
1154 dd_grd_curcanv = save_canvas;
1156 goto RePaintNewmenu4;
1165 omouse_state = mouse_state;
1166 mouse_state = mouse_button_state(0);
1167 if (!joydefs_calibrating)
1168 show_cursor(); // possibly hidden
1172 omouse_state = mouse_state;
1173 if (!MenuReordering)
1174 mouse_state = mouse_button_state(0);
1175 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1178 //see if redbook song needs to be restarted
1179 songs_check_redbook_repeat();
1186 (*subfunction)(nitems,item,&k,choice);
1189 if (!time_stopped) {
1190 // Save current menu box
1191 if (multi_menu_poll() == -1)
1197 dont_restore = (k == -3); //-3 means don't restore
1203 if (check_button_press())
1207 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1210 old_choice = choice;
1216 if (SurfingNet && !already_showing_info)
1218 show_extra_netgame_info(choice-2);
1220 if (SurfingNet && already_showing_info)
1227 if (SurfingNet && !already_showing_info)
1229 network_request_player_names(choice-2);
1231 if (SurfingNet && already_showing_info)
1246 case KEY_TAB + KEY_SHIFTED:
1249 if (all_text) break;
1256 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1258 if (choice<TopChoice)
1259 { choice=TopChoice; break; }
1261 if (choice<ScrollOffset)
1263 for (i=0;i<nitems;i++)
1266 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1271 if (choice >= nitems ) choice=0;
1272 if (choice < 0 ) choice=nitems-1;
1274 } while ( item[choice].type==NM_TYPE_TEXT );
1275 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1276 item[choice].value = -1;
1277 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1278 item[old_choice].group=0;
1279 strcpy(item[old_choice].text, item[old_choice].saved_text );
1280 item[old_choice].value = -1;
1283 item[old_choice].redraw = 1;
1284 item[choice].redraw=1;
1289 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1290 if (all_text) break;
1297 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1300 { choice--; break; }
1302 if (choice>=MaxOnMenu+ScrollOffset)
1304 for (i=0;i<nitems;i++)
1307 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1312 if (choice < 0 ) choice=nitems-1;
1313 if (choice >= nitems ) choice=0;
1316 } while ( item[choice].type==NM_TYPE_TEXT );
1318 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1319 item[choice].value = -1;
1320 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1321 item[old_choice].group=0;
1322 strcpy(item[old_choice].text, item[old_choice].saved_text );
1323 item[old_choice].value = -1;
1326 item[old_choice].redraw=1;
1327 item[choice].redraw=1;
1330 if ( choice > -1 ) {
1331 switch( item[choice].type ) {
1334 case NM_TYPE_INPUT_MENU:
1337 if ( item[choice].value )
1338 item[choice].value = 0;
1340 item[choice].value = 1;
1341 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1344 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1346 mprintf ((0,"Special redraw!\n"));
1351 item[choice].redraw=1;
1354 for (i=0; i<nitems; i++ ) {
1355 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1360 item[choice].value = 1;
1361 item[choice].redraw = 1;
1367 case KEY_SHIFTED+KEY_UP:
1368 if (MenuReordering && choice!=TopChoice)
1370 Temp=item[choice].text;
1371 TempVal=item[choice].value;
1372 item[choice].text=item[choice-1].text;
1373 item[choice].value=item[choice-1].value;
1374 item[choice-1].text=Temp;
1375 item[choice-1].value=TempVal;
1376 item[choice].redraw=1;
1377 item[choice-1].redraw=1;
1381 case KEY_SHIFTED+KEY_DOWN:
1382 if (MenuReordering && choice!=(nitems-1))
1384 Temp=item[choice].text;
1385 TempVal=item[choice].value;
1386 item[choice].text=item[choice+1].text;
1387 item[choice].value=item[choice+1].value;
1388 item[choice+1].text=Temp;
1389 item[choice+1].value=TempVal;
1390 item[choice].redraw=1;
1391 item[choice+1].redraw=1;
1398 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1399 item[choice].group = 1;
1400 item[choice].redraw = 1;
1401 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1402 item[choice].text[0] = 0;
1403 item[choice].value = -1;
1405 strip_end_whitespace(item[choice].text);
1412 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1413 item[choice].group=0;
1414 strcpy(item[choice].text, item[choice].saved_text );
1415 item[choice].redraw=1;
1416 item[choice].value = -1;
1423 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1424 case KEY_PRINT_SCREEN:
1426 save_screen_shot(0);
1427 PA_DFX (pa_set_frontbuffer_current());
1428 PA_DFX (pa_set_front_to_read());
1429 for (i=0;i<nitems;i++)
1438 case KEY_COMMAND+KEY_RIGHT:
1439 songs_goto_next_song();
1441 case KEY_COMMAND+KEY_LEFT:
1442 songs_goto_prev_song();
1444 case KEY_COMMAND+KEY_UP:
1445 songs_play_level_song(1);
1447 case KEY_COMMAND+KEY_DOWN:
1448 songs_stop_redbook();
1451 case KEY_COMMAND+KEY_M:
1453 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1454 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1457 key_close(); // no processing of keys with keyboard handler.. jeez
1460 show_boxed_message ("Mounting CD\nESC to quit");
1461 RBAMountDisk(); // OS has totaly control of the CD.
1462 if (Function_mode == FMODE_MENU)
1463 songs_play_song(SONG_TITLE,1);
1464 else if (Function_mode == FMODE_GAME)
1465 songs_play_level_song( Current_level_num );
1466 clear_boxed_message();
1475 case KEY_COMMAND+KEY_E:
1476 songs_stop_redbook();
1478 k = -1; // force key not to register
1481 case KEY_COMMAND+KEY_Q: {
1482 extern void macintosh_quit();
1484 if ( !(Game_mode & GM_MULTI) )
1486 if (!joydefs_calibrating)
1488 k = -1; // force key not to register
1495 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1502 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1504 if ( !done && mouse_state && !omouse_state && !all_text ) {
1505 mouse_get_pos(&mx, &my);
1506 for (i=0; i<nitems; i++ ) {
1507 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1508 x2 = x1 + item[i].w;
1509 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1510 y2 = y1 + item[i].h;
1511 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1512 if (i+ScrollOffset != choice) {
1513 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1516 choice = i + ScrollOffset;
1518 switch( item[choice].type ) {
1520 if ( item[choice].value )
1521 item[choice].value = 0;
1523 item[choice].value = 1;
1524 item[choice].redraw=1;
1531 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1533 mprintf ((0,"Special redraw!\n"));
1540 for (i=0; i<nitems; i++ ) {
1541 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1546 item[choice].value = 1;
1547 item[choice].redraw = 1;
1550 item[old_choice].redraw=1;
1556 if (mouse_state && all_text)
1559 if ( !done && mouse_state && !all_text ) {
1560 mouse_get_pos(&mx, &my);
1562 // check possible scrollbar stuff first
1564 int arrow_width, arrow_height, aw;
1566 if (ScrollOffset != 0) {
1567 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1568 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1569 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1570 x1 = x1 - arrow_width;
1571 y2 = y1 + arrow_height;
1572 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1575 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1577 if (choice<ScrollOffset)
1579 for (i=0;i<nitems;i++)
1582 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1586 if (ScrollOffset+MaxDisplayable<nitems) {
1587 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1588 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1589 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1590 x1 = x1 - arrow_width;
1591 y2 = y1 + arrow_height;
1592 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1595 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1597 if (choice>=MaxOnMenu+ScrollOffset)
1599 for (i=0;i<nitems;i++)
1602 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1608 for (i=0; i<nitems; i++ ) {
1609 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1610 x2 = x1 + item[i].w;
1611 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1612 y2 = y1 + item[i].h;
1613 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1614 if (i+ScrollOffset != choice) {
1615 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1618 choice = i + ScrollOffset;
1620 if ( item[choice].type == NM_TYPE_SLIDER ) {
1621 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1622 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1624 strcpy(slider_text, item[choice].saved_text);
1625 p = strchr(slider_text, '\t');
1631 gr_get_string_size(s1, &slider_width, &height, &aw);
1632 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1633 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1634 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1636 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1637 x2 = x1 + slider_width + sright_width;
1638 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1639 item[choice].value = item[choice].min_value;
1640 item[choice].redraw = 2;
1641 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1642 item[choice].value = item[choice].max_value;
1643 item[choice].redraw = 2;
1644 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1645 int num_values, value_width, new_value;
1647 num_values = item[choice].max_value - item[choice].min_value + 1;
1648 value_width = (slider_width - sleft_width - sright_width) / num_values;
1649 new_value = (mx - x1 - sleft_width) / value_width;
1650 if ( item[choice].value != new_value ) {
1651 item[choice].value = new_value;
1652 item[choice].redraw = 2;
1658 if (choice == old_choice)
1660 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1661 item[choice].value = -1;
1662 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1663 item[old_choice].group=0;
1664 strcpy(item[old_choice].text, item[old_choice].saved_text );
1665 item[old_choice].value = -1;
1668 item[old_choice].redraw = 1;
1669 item[choice].redraw=1;
1675 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1676 mouse_get_pos(&mx, &my);
1677 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1678 x2 = x1 + item[choice].w;
1679 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1680 y2 = y1 + item[choice].h;
1681 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1682 if (Hack_DblClick_MenuMode) {
1683 if (dblclick_flag) done = 1;
1684 else dblclick_flag = 1;
1690 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1691 item[choice].group = 1;
1692 item[choice].redraw = 1;
1693 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1694 item[choice].text[0] = 0;
1695 item[choice].value = -1;
1697 strip_end_whitespace(item[choice].text);
1701 if ( !done && !mouse_state && omouse_state && close_box ) {
1702 mouse_get_pos(&mx, &my);
1703 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1704 x2 = x1 + CLOSE_SIZE;
1705 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1706 y2 = y1 + CLOSE_SIZE;
1707 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1713 // HACK! Don't redraw loadgame preview
1714 if (RestoringMenu) item[0].redraw = 0;
1715 #endif // ifdef MACINTOSH
1717 if ( choice > -1 ) {
1720 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1721 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1722 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1723 if (item[choice].value > 0)
1724 item[choice].value--;
1725 item[choice].text[item[choice].value] = 0;
1726 item[choice].redraw = 1;
1728 ascii = key_to_ascii(k);
1729 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1733 if (item[choice].value==-1) {
1734 item[choice].value = 0;
1737 allowed = char_allowed(ascii);
1739 if (!allowed && ascii==' ' && char_allowed('_')) {
1745 item[choice].text[item[choice].value++] = ascii;
1746 item[choice].text[item[choice].value] = 0;
1747 item[choice].redraw=1;
1751 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1752 ascii = key_to_ascii(k);
1754 int choice1 = choice;
1755 ascii = toupper(ascii);
1759 if (choice1 >= nitems ) choice1=0;
1760 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1761 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1762 (item[choice1].type==NM_TYPE_CHECK) ||
1763 (item[choice1].type==NM_TYPE_RADIO) ||
1764 (item[choice1].type==NM_TYPE_NUMBER) ||
1765 (item[choice1].type==NM_TYPE_SLIDER) )
1766 && (ascii==toupper(ch)) ) {
1770 item[old_choice].redraw=1;
1771 item[choice].redraw=1;
1773 } while (choice1 != choice );
1777 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1778 int ov=item[choice].value;
1783 case KEY_MINUS+KEY_SHIFTED:
1785 item[choice].value -= 1;
1790 case KEY_EQUAL+KEY_SHIFTED:
1792 item[choice].value++;
1797 item[choice].value += 10;
1802 item[choice].value -= 10;
1805 if (ov!=item[choice].value)
1806 item[choice].redraw=1;
1811 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1812 gr_set_current_canvas(bg.menu_canvas));
1814 // Redraw everything...
1815 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1817 if (item[i].redraw) // warning! ugly hack below
1819 item[i].y-=((string_height+1)*ScrollOffset);
1822 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1824 MAC(if (!joydefs_calibrating) show_cursor());
1825 WIN(if (!MenuReordering) ShowCursorW());
1826 item[i].y+=((string_height+1)*ScrollOffset);
1828 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1829 update_cursor( &item[i]);
1835 //grd_curcanv->cv_font = NORMAL_FONT;
1837 if (LastScrollCheck!=ScrollOffset)
1839 LastScrollCheck=ScrollOffset;
1840 grd_curcanv->cv_font = SELECTED_FONT;
1842 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1843 sx=item[ScrollOffset].x-(MenuHires?24:12);
1846 if (ScrollOffset!=0)
1847 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1849 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1851 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1852 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1854 if (ScrollOffset+MaxDisplayable<nitems)
1855 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1857 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1863 if ( !dont_restore && gr_palette_faded_out ) {
1864 gr_palette_fade_in( gr_palette, 32, 0 );
1871 // Restore everything...
1873 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1874 gr_set_current_canvas(bg.menu_canvas));
1876 if ( filename == NULL ) {
1877 // Save the background under the menu...
1878 WIN (DDGRLOCK(dd_grd_curcanv));
1879 gr_bitmap(0, 0, bg.saved);
1880 WIN (DDGRUNLOCK(dd_grd_curcanv));
1881 gr_free_bitmap(bg.saved);
1882 d_free( bg.background );
1884 if (!dont_restore) //info passed back from subfunction
1886 WIN (DDGRLOCK(dd_grd_curcanv));
1887 gr_bitmap(0, 0, bg.background);
1888 WIN (DDGRUNLOCK(dd_grd_curcanv));
1890 gr_free_bitmap(bg.background);
1893 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1894 gr_free_sub_canvas( bg.menu_canvas ) );
1896 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1897 grd_curcanv->cv_font = save_font;
1898 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1899 keyd_repeat = old_keyd_repeat;
1901 game_flush_inputs();
1912 if ( sound_stopped )
1913 digi_resume_digi_sounds();
1915 WIN(mouse_set_mode(1)); //re-enable centering mode
1922 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1928 char nm_text[MESSAGEBOX_TEXT_SIZE];
1929 newmenu_item nm_message_items[5];
1931 va_start(args, nchoices );
1933 Assert( nchoices <= 5 );
1935 for (i=0; i<nchoices; i++ ) {
1936 s = va_arg( args, char * );
1937 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1939 format = va_arg( args, char * );
1940 strcpy( nm_text, "" );
1941 vsprintf(nm_text,format,args);
1944 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1946 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1949 int nm_messagebox( char *title, int nchoices, ... )
1955 char nm_text[MESSAGEBOX_TEXT_SIZE];
1956 newmenu_item nm_message_items[5];
1958 va_start(args, nchoices );
1960 Assert( nchoices <= 5 );
1962 for (i=0; i<nchoices; i++ ) {
1963 s = va_arg( args, char * );
1964 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1966 format = va_arg( args, char * );
1967 strcpy( nm_text, "" );
1968 vsprintf(nm_text,format,args);
1971 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1973 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1979 void newmenu_file_sort( int n, char *list )
1986 for (i=incr; i<n; i++ ) {
1989 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1990 memcpy( t, &list[j*14], FILENAME_LEN );
1991 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1992 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2003 void delete_player_saved_games(char * name)
2008 for (i=0;i<10; i++) {
2010 sprintf( filename, "%s.sg%d", name, i );
2012 sprintf( filename, ":Players:%s.sg%d", name, i );
2018 #define MAX_FILES 300
2020 int MakeNewPlayerFile(int allow_abort);
2022 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2025 FILEFINDSTRUCT find;
2026 int NumFiles=0, key,done, citem, ocitem;
2027 char * filenames = NULL;
2028 int NumFiles_displayed = 8;
2029 int first_item = -1, ofirst_item;
2030 int old_keyd_repeat = keyd_repeat;
2033 int demos_deleted=0;
2034 int initialized = 0;
2036 int w_x, w_y, w_w, w_h, title_height;
2037 int box_x, box_y, box_w, box_h;
2038 bkg bg; // background under listbox
2039 #if defined(MACINTOSH) || defined(WINDOWS)
2040 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2041 int mouse2_state, omouse2_state;
2042 int dblclick_flag=0;
2044 int show_up_arrow=0,show_down_arrow=0;
2046 WIN(int win_redraw=0);
2048 w_x=w_y=w_w=w_h=title_height=0;
2049 box_x=box_y=box_w=box_h=0;
2051 filenames = d_malloc( MAX_FILES * 14 );
2052 if (filenames==NULL) return 0;
2057 WIN(mouse_set_mode(0)); //disable centering mode
2059 if (strstr( filespec, "*.plr" ))
2061 else if (strstr( filespec, "*.dem" ))
2068 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2070 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2075 if( !FileFindFirst( filespec, &find ) ) {
2077 if (NumFiles<MAX_FILES) {
2078 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2079 if ( player_mode ) {
2081 p = strchr(&filenames[NumFiles*14],'.');
2088 } while( !FileFindNext( &find ) );
2092 if ( (NumFiles < 1) && demos_deleted ) {
2096 if ( (NumFiles < 1) && demo_mode ) {
2097 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2103 if ( (NumFiles < 2) && player_mode ) {
2105 goto ExitFileMenuEarly;
2112 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2119 // set_screen_mode(SCREEN_MENU);
2125 dd_gr_set_current_canvas(NULL);
2127 gr_set_current_canvas(NULL);
2130 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2132 grd_curcanv->cv_font = SUBTITLE_FONT;
2134 WIN(DDGRUNLOCK(dd_grd_curcanv));
2139 for (i=0; i<NumFiles; i++ ) {
2141 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2147 gr_get_string_size( title, &w, &h, &aw );
2150 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2154 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2156 w_w += (grd_curfont->ft_w * 4);
2157 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2159 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2160 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2162 w_x = (grd_curcanv->cv_w-w_w)/2;
2163 w_y = (grd_curcanv->cv_h-w_h)/2;
2165 if ( w_x < 0 ) w_x = 0;
2166 if ( w_y < 0 ) w_y = 0;
2168 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2169 box_y = w_y + title_height;
2171 // save the screen behind the menu.
2175 #if !defined(WINDOWS)
2176 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2177 bg.background = &VR_offscreen_buffer->cv_bitmap;
2180 #if defined(POLY_ACC)
2181 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2183 bg.background = gr_create_bitmap( w_w, w_h );
2186 Assert( bg.background != NULL );
2189 WIN(DDGRLOCK(dd_grd_curcanv));
2190 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2191 WIN(DDGRUNLOCK(dd_grd_curcanv));
2195 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2196 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2197 dd_VR_offscreen_buffer, 0, 0,
2198 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2199 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2203 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2205 WIN(DDGRLOCK(dd_grd_curcanv))
2207 gr_string( 0x8000, w_y+10, title );
2209 WIN(DDGRUNLOCK(dd_grd_curcanv));
2216 if ( !player_mode ) {
2217 newmenu_file_sort( NumFiles, filenames );
2219 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2220 newmenu_file_sort( NumFiles, filenames );
2222 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2224 for ( i=0; i<NumFiles; i++ ) {
2225 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2226 #if defined(WINDOWS) || defined(MACINTOSH)
2234 #if defined(MACINTOSH) || defined(WINDOWS)
2235 mouse_state = omouse_state = 0;
2236 mouse2_state = omouse2_state = 0;
2237 draw_close_box(w_x,w_y);
2249 DoMessageStuff(&msg);
2251 if (_RedrawScreen) {
2252 _RedrawScreen = FALSE;
2254 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2255 gr_free_bitmap(bg.background);
2258 goto RePaintNewmenuFile;
2265 ofirst_item = first_item;
2268 #if defined(MACINTOSH) || defined(WINDOWS)
2269 omouse_state = mouse_state;
2270 omouse2_state = mouse2_state;
2271 mouse_state = mouse_button_state(0);
2272 mouse2_state = mouse_button_state(1);
2275 //see if redbook song needs to be restarted
2276 songs_check_redbook_repeat();
2279 if (!mouse2_state && omouse2_state)
2280 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2283 //NOTE LINK TO ABOVE ELSE
2289 else if (simukey==1)
2295 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2296 case KEY_PRINT_SCREEN:
2298 save_screen_shot(0);
2299 PA_DFX (pa_set_frontbuffer_current());
2300 PA_DFX (pa_set_front_to_read());
2306 case KEY_CTRLED+KEY_D:
2307 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2311 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2315 mouse_set_mode(1); //re-enable centering mode
2319 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2321 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2324 mouse_set_mode(0); //disenable centering mode
2330 char name[_MAX_PATH],dir[_MAX_DIR];
2332 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2336 _splitpath(filespec,name,dir,NULL,NULL);
2338 strcat(name,&filenames[citem*14]);
2345 if ( !strncmp(name, ".\\", 2) )
2346 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2347 name[i] = name[i+1];
2348 while ( (p = strchr(name, '\\')) )
2353 ret = unlink( name );
2357 if ((!ret) && player_mode) {
2358 delete_player_saved_games( &filenames[citem*14] );
2363 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2365 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2366 } else if (demo_mode)
2391 citem += NumFiles_displayed;
2395 citem -= NumFiles_displayed;
2398 if (allow_abort_flag) {
2409 case KEY_COMMAND+KEY_Q: {
2410 extern void macintosh_quit();
2412 if ( !(Game_mode & GM_MULTI) )
2423 int ascii = key_to_ascii(key);
2424 if ( ascii < 255 ) {
2427 if (cc1 < 0 ) cc1 = 0;
2428 if (cc1 >= NumFiles ) cc1 = 0;
2430 if ( cc < 0 ) cc = 0;
2431 if ( cc >= NumFiles ) cc = 0;
2432 if ( citem == cc ) break;
2434 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2449 if (citem>=NumFiles)
2452 if (citem< first_item)
2455 if (citem>=( first_item+NumFiles_displayed))
2457 first_item = citem-NumFiles_displayed+1;
2461 if (NumFiles>first_item+NumFiles_displayed)
2472 if (NumFiles <= NumFiles_displayed )
2475 if (first_item>NumFiles-NumFiles_displayed)
2477 first_item = NumFiles-NumFiles_displayed;
2480 if (first_item < 0 ) first_item = 0;
2482 #if defined(MACINTOSH) || defined(WINDOWS)
2484 if (mouse_state || mouse2_state) {
2487 mouse_get_pos(&mx, &my);
2488 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2489 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2491 x2 = box_x + box_w - 1;
2492 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2494 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2495 if (i == citem && !mouse2_state) {
2505 if (!mouse_state && omouse_state) {
2508 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2509 mouse_get_pos(&mx, &my);
2511 x2 = box_x + box_w - 1;
2512 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2514 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2515 if (dblclick_flag) done = 1;
2516 else dblclick_flag = 1;
2520 if ( !mouse_state && omouse_state ) {
2521 mouse_get_pos(&mx, &my);
2522 x1 = w_x + CLOSE_X + 2;
2523 x2 = x1 + CLOSE_SIZE - 2;
2524 y1 = w_y + CLOSE_Y + 2;
2525 y2 = y1 + CLOSE_SIZE - 2;
2526 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2535 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2537 y1 = box_y+box_h-LHY(7);
2539 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2546 WIN(DDGRLOCK(dd_grd_curcanv));
2547 gr_setcolor( BM_XRGB(2,2,2));
2548 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2549 gr_setcolor( BM_XRGB( 0,0,0) );
2552 if (ofirst_item != first_item || win_redraw) {
2555 if (ofirst_item != first_item) {
2559 gr_setcolor( BM_XRGB( 0,0,0) );
2560 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2562 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2564 if ( i >= NumFiles ) {
2566 gr_setcolor( BM_XRGB(5,5,5));
2567 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2568 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2570 gr_setcolor( BM_XRGB(2,2,2));
2571 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2573 gr_setcolor( BM_XRGB(0,0,0));
2574 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2578 grd_curcanv->cv_font = SELECTED_FONT;
2580 grd_curcanv->cv_font = NORMAL_FONT;
2581 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2583 gr_setcolor( BM_XRGB(5,5,5));
2584 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2585 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2587 gr_setcolor( BM_XRGB(2,2,2));
2588 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2589 gr_setcolor( BM_XRGB(0,0,0));
2591 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2592 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2597 } else if ( citem != ocitem ) {
2603 if ( (i>=0) && (i<NumFiles) ) {
2604 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2606 grd_curcanv->cv_font = SELECTED_FONT;
2608 grd_curcanv->cv_font = NORMAL_FONT;
2609 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2610 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2611 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2614 if ( (i>=0) && (i<NumFiles) ) {
2615 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2617 grd_curcanv->cv_font = SELECTED_FONT;
2619 grd_curcanv->cv_font = NORMAL_FONT;
2620 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2621 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2622 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2629 grd_curcanv->cv_font = NORMAL_FONT;
2631 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2635 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2639 if (show_down_arrow)
2640 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2644 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2652 WIN(DDGRUNLOCK(dd_grd_curcanv));
2658 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2665 keyd_repeat = old_keyd_repeat;
2667 if ( initialized ) {
2668 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2670 WIN (DDGRLOCK(dd_grd_curcanv));
2671 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2672 WIN (DDGRUNLOCK(dd_grd_curcanv));
2674 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2675 gr_free_bitmap(bg.background);
2678 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2679 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2681 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2682 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2692 WIN(mouse_set_mode(1)); //re-enable centering mode
2700 // Example listbox callback function...
2701 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2705 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2706 // if ( *nitems > 1 ) {
2707 // unlink( items[*citem] ); // Delete the file
2708 // for (i=*citem; i<*nitems-1; i++ ) {
2709 // items[i] = items[i+1];
2711 // *nitems = *nitems - 1;
2712 // d_free( items[*nitems] );
2713 // items[*nitems] = NULL;
2714 // return 1; // redraw;
2721 #define LB_ITEMS_ON_SCREEN 8
2723 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2725 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2728 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 ) )
2731 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2732 int old_keyd_repeat = keyd_repeat;
2733 int width, height, wx, wy, title_height, border_size;
2734 int total_width,total_height;
2736 #if defined(MACINTOSH) || defined(WINDOWS)
2737 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2738 int close_x,close_y;
2739 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2741 WIN(int win_redraw=0);
2745 PA_DFX (pa_set_frontbuffer_current());
2746 PA_DFX (pa_set_front_to_read());
2747 WIN(mouse_set_mode(0)); //disable centering mode
2749 // set_screen_mode(SCREEN_MENU);
2753 RePaintNewmenuListbox:
2755 dd_gr_set_current_canvas(NULL);
2757 gr_set_current_canvas(NULL);
2760 grd_curcanv->cv_font = SUBTITLE_FONT;
2763 for (i=0; i<nitems; i++ ) {
2765 gr_get_string_size( items[i], &w, &h, &aw );
2769 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2773 gr_get_string_size( title, &w, &h, &aw );
2776 title_height = h + 5;
2779 border_size = grd_curfont->ft_w;
2780 WIN (border_size=grd_curfont->ft_w*2);
2782 width += (grd_curfont->ft_w);
2783 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2784 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2786 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2787 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2788 if ( wy < title_height )
2791 total_width = width+2*border_size;
2792 total_height = height+2*border_size+title_height;
2796 #if !defined(WINDOWS)
2797 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2798 bg.background = &VR_offscreen_buffer->cv_bitmap;
2801 //bg.background = gr_create_bitmap( width, (height + title_height) );
2802 #if defined(POLY_ACC)
2803 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2805 bg.background = gr_create_bitmap(total_width,total_height);
2807 Assert( bg.background != NULL );
2809 WIN (DDGRLOCK(dd_grd_curcanv));
2810 //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 );
2811 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2812 WIN (DDGRUNLOCK(dd_grd_curcanv));
2816 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2817 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2818 dd_VR_offscreen_buffer, 0, 0,
2819 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2820 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2824 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2826 WIN(DDGRLOCK(dd_grd_curcanv));
2827 gr_string( 0x8000, wy - title_height, title );
2828 WIN(DDGRUNLOCK(dd_grd_curcanv));
2833 citem = default_item;
2834 if ( citem < 0 ) citem = 0;
2835 if ( citem >= nitems ) citem = 0;
2839 #if defined(MACINTOSH) || defined(WINDOWS)
2840 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2841 close_x = wx-border_size;
2842 close_y = wy-title_height-border_size;
2843 draw_close_box(close_x,close_y);
2855 DoMessageStuff(&msg);
2857 if (_RedrawScreen) {
2858 _RedrawScreen = FALSE;
2860 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2861 gr_free_bitmap(bg.background);
2863 goto RePaintNewmenuListbox;
2870 ofirst_item = first_item;
2871 #if defined(MACINTOSH) || defined(WINDOWS)
2872 omouse_state = mouse_state;
2873 mouse_state = mouse_button_state(0);
2875 //see if redbook song needs to be restarted
2876 songs_check_redbook_repeat();
2880 if ( listbox_callback )
2881 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2902 else if (simukey==1)
2908 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2909 case KEY_PRINT_SCREEN:
2911 save_screen_shot(0);
2912 PA_DFX (pa_set_frontbuffer_current());
2913 PA_DFX (pa_set_front_to_read());
2936 citem += LB_ITEMS_ON_SCREEN;
2940 citem -= LB_ITEMS_ON_SCREEN;
2943 if (allow_abort_flag) {
2954 case KEY_COMMAND+KEY_Q: {
2955 extern void macintosh_quit();
2957 if ( !(Game_mode & GM_MULTI) )
2967 int ascii = key_to_ascii(key);
2968 if ( ascii < 255 ) {
2971 if (cc1 < 0 ) cc1 = 0;
2972 if (cc1 >= nitems ) cc1 = 0;
2974 if ( cc < 0 ) cc = 0;
2975 if ( cc >= nitems ) cc = 0;
2976 if ( citem == cc ) break;
2978 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2995 if (citem< first_item)
2998 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2999 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3001 if (nitems <= LB_ITEMS_ON_SCREEN )
3004 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3005 first_item = nitems-LB_ITEMS_ON_SCREEN;
3006 if (first_item < 0 ) first_item = 0;
3009 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3020 #if defined(MACINTOSH) || defined(WINDOWS)
3025 mouse_get_pos(&mx, &my);
3026 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3029 gr_get_string_size(items[i], &w, &h, &aw );
3032 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3034 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3046 //no double-click stuff for listbox
3047 //@@if (!mouse_state && omouse_state) {
3050 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3051 //@@ mouse_get_pos(&mx, &my);
3053 //@@ x2 = wx + width;
3054 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3056 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3057 //@@ if (dblclick_flag) done = 1;
3061 //check for close box clicked
3062 if ( !mouse_state && omouse_state ) {
3063 mouse_get_pos(&mx, &my);
3064 x1 = close_x + CLOSE_X + 2;
3065 x2 = x1 + CLOSE_SIZE - 2;
3066 y1 = close_y + CLOSE_Y + 2;
3067 y2 = y1 + CLOSE_SIZE - 2;
3068 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3078 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3080 y1 = total_height-LHY(7);
3082 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3090 if ( (ofirst_item != first_item) || redraw) {
3093 WIN(DDGRLOCK(dd_grd_curcanv));
3095 gr_setcolor( BM_XRGB( 0,0,0) );
3096 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3098 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3099 if ( i >= nitems ) {
3100 gr_setcolor( BM_XRGB(0,0,0));
3101 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3104 grd_curcanv->cv_font = SELECTED_FONT;
3106 grd_curcanv->cv_font = NORMAL_FONT;
3107 gr_get_string_size(items[i], &w, &h, &aw );
3108 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3109 gr_string( wx+5, y, items[i] );
3114 // If Win95 port, draw up/down arrows on left side of menu
3116 grd_curcanv->cv_font = NORMAL_FONT;
3118 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3122 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3126 if (show_down_arrow)
3127 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3131 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3138 WIN(DDGRUNLOCK(dd_grd_curcanv));
3142 } else if ( citem != ocitem ) {
3148 WIN(DDGRLOCK(dd_grd_curcanv));
3151 if ( (i>=0) && (i<nitems) ) {
3152 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3154 grd_curcanv->cv_font = SELECTED_FONT;
3156 grd_curcanv->cv_font = NORMAL_FONT;
3157 gr_get_string_size(items[i], &w, &h, &aw );
3158 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3159 gr_string( wx+5, y, items[i] );
3163 if ( (i>=0) && (i<nitems) ) {
3164 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3166 grd_curcanv->cv_font = SELECTED_FONT;
3168 grd_curcanv->cv_font = NORMAL_FONT;
3169 gr_get_string_size( items[i], &w, &h, &aw );
3170 gr_rect( wx, y-1, wx+width-1, y+h );
3171 gr_string( wx+5, y, items[i] );
3173 WIN(DDGRUNLOCK(dd_grd_curcanv));
3183 keyd_repeat = old_keyd_repeat;
3185 WIN (DDGRLOCK(dd_grd_curcanv));
3186 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3187 WIN (DDGRUNLOCK(dd_grd_curcanv));
3189 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3190 gr_free_bitmap(bg.background);
3194 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3195 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3197 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3198 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3204 WIN(mouse_set_mode(1)); //re-enable centering mode
3209 int newmenu_filelist( char * title, char * filespec, char * filename )
3212 char * Filenames[MAX_FILES];
3213 char FilenameText[MAX_FILES][14];
3214 FILEFINDSTRUCT find;
3217 if( !FileFindFirst( filespec, &find ) ) {
3219 if (NumFiles<MAX_FILES) {
3220 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3221 Filenames[NumFiles] = FilenameText[NumFiles];
3226 } while( !FileFindNext( &find ) );
3230 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3232 strcpy( filename, Filenames[i] );
3239 extern netgame_info Active_games[];
3240 extern int NumActiveNetgames;
3242 void show_extra_netgame_info(int choice)
3248 if (choice>=NumActiveNetgames)
3253 m[i].text=(char *)&mtext[i];
3254 m[i].type=NM_TYPE_TEXT;
3257 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3258 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3259 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3260 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3262 already_showing_info=1;
3263 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3264 already_showing_info=0;
3269 /* Spiffy word wrap string formatting function */
3271 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3277 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3280 wordptr = strtok(tbuf, " ");
3281 if (!wordptr) return;
3287 col = col+strlen(wordptr)+1;
3288 if (col >=line_length) {
3290 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3293 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3295 wordptr = strtok(NULL, " ");