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.4 2001-10-25 02:15:57 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;
760 // set_screen_mode(SCREEN_MENU);
763 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
764 digi_pause_digi_sounds();
768 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
781 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
783 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
785 save_font = grd_curcanv->cv_font;
790 grd_curcanv->cv_font = TITLE_FONT;
791 gr_get_string_size(title,&string_width,&string_height,&average_width );
796 grd_curcanv->cv_font = SUBTITLE_FONT;
797 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
798 if (string_width > tw )
803 th += LHY(8); //put some space between titles & body
806 grd_curcanv->cv_font = SMALL_FONT;
808 grd_curcanv->cv_font = NORMAL_FONT;
812 nmenus = nothers = 0;
814 // Find menu height & width (store in w,h)
815 for (i=0; i<nitems; i++ ) {
818 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
819 item[i].right_offset = 0;
822 string_height+=LHY(3);
824 item[i].saved_text[0] = '\0';
826 if ( item[i].type == NM_TYPE_SLIDER ) {
829 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
830 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
831 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
833 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
834 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
835 string_width += w1 + aw;
838 if ( item[i].type == NM_TYPE_MENU ) {
842 if ( item[i].type == NM_TYPE_CHECK ) {
845 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
846 item[i].right_offset = w1;
847 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
848 if (w1 > item[i].right_offset)
849 item[i].right_offset = w1;
852 if (item[i].type == NM_TYPE_RADIO ) {
855 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
856 item[i].right_offset = w1;
857 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
858 if (w1 > item[i].right_offset)
859 item[i].right_offset = w1;
862 if (item[i].type==NM_TYPE_NUMBER ) {
866 sprintf( test_text, "%d", item[i].max_value );
867 gr_get_string_size( test_text, &w1, &h1, &aw1 );
868 item[i].right_offset = w1;
869 sprintf( test_text, "%d", item[i].min_value );
870 gr_get_string_size( test_text, &w1, &h1, &aw1 );
871 if ( w1 > item[i].right_offset)
872 item[i].right_offset = w1;
875 if ( item[i].type == NM_TYPE_INPUT ) {
876 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
877 strcpy(item[i].saved_text, item[i].text );
879 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
880 if ( string_width > MAX_TEXT_WIDTH )
881 string_width = MAX_TEXT_WIDTH;
885 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
886 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
887 strcpy(item[i].saved_text, item[i].text );
889 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
894 item[i].w = string_width;
895 item[i].h = string_height;
897 if ( string_width > w )
898 w = string_width; // Save maximum width
899 if ( average_width > aw )
901 h += string_height+1; // Find the height of all strings
904 // Big hack for allowing the netgame options menu to spill over
906 MaxOnMenu=MAXDISPLAYABLEITEMS;
907 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
910 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
913 h=(MaxOnMenu*(string_height+1)+LHY(8));
914 MaxDisplayable=MaxOnMenu;
915 mprintf ((0,"Hey, this is a scroll box!\n"));
928 for (i=0; i<nitems; i++ ) {
930 if (item[i].right_offset > right_offset )
931 right_offset = item[i].right_offset;
933 if (right_offset > 0 )
936 //gr_get_string_size("",&string_width,&string_height,&average_width );
943 twidth = ( tw - w )/2;
948 { right_offset=0; twidth=0;}
950 mprintf(( 0, "Right offset = %d\n", right_offset ));
953 // Find min point of menu border
954 // x = (grd_curscreen->sc_w-w)/2;
955 // y = (grd_curscreen->sc_h-h)/2;
957 w += MenuHires?60:30;
958 h += MenuHires?60:30;
960 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
961 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
963 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
964 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
969 if ( filename != NULL ) {
970 nm_draw_background1( filename );
971 gr_palette_load(gr_palette);
974 // Save the background of the display
975 // Win95 must refer to the screen as a dd_grs_canvas, so...
976 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
977 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
979 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
980 gr_set_current_canvas(bg.menu_canvas) );
982 if ( filename == NULL ) {
983 // Save the background under the menu...
989 #if defined(POLY_ACC)
990 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
992 bg.saved = gr_create_bitmap( w, h );
994 Assert( bg.saved != NULL );
996 WIN (DDGRLOCK(dd_grd_curcanv));
997 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
998 WIN (DDGRUNLOCK(dd_grd_curcanv));
1000 WINDOS ( dd_gr_set_current_canvas(NULL),
1001 gr_set_current_canvas( NULL )
1004 nm_draw_background(x,y,x+w-1,y+h-1);
1006 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1007 gr_set_current_canvas( bg.menu_canvas )
1010 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1014 #if defined(POLY_ACC)
1015 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1017 bg.background = gr_create_bitmap( w, h );
1019 Assert( bg.background != NULL );
1021 WIN (DDGRLOCK(dd_grd_curcanv));
1022 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1023 WIN (DDGRUNLOCK(dd_grd_curcanv));
1026 // ty = 15 + (yborder/4);
1028 ty = MenuHires?30:15;
1031 grd_curcanv->cv_font = TITLE_FONT;
1032 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1033 gr_get_string_size(title,&string_width,&string_height,&average_width );
1036 WIN (DDGRLOCK(dd_grd_curcanv));
1037 gr_printf( 0x8000, ty, title );
1038 WIN (DDGRUNLOCK(dd_grd_curcanv));
1043 grd_curcanv->cv_font = SUBTITLE_FONT;
1044 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1045 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1048 WIN (DDGRLOCK(dd_grd_curcanv));
1049 gr_printf( 0x8000, ty, subtitle );
1050 WIN (DDGRUNLOCK(dd_grd_curcanv));
1055 grd_curcanv->cv_font = SMALL_FONT;
1057 grd_curcanv->cv_font = NORMAL_FONT;
1059 // Update all item's x & y values.
1060 for (i=0; i<nitems; i++ ) {
1061 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1062 item[i].y += (MenuHires?30:15);
1063 if ( item[i].type==NM_TYPE_RADIO ) {
1064 fm = -1; // find first marked one
1065 for ( j=0; j<nitems; j++ ) {
1066 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1067 if (fm==-1 && item[j].value)
1079 old_keyd_repeat = keyd_repeat;
1085 if (citem < 0 ) citem = 0;
1086 if (citem > nitems-1 ) citem = nitems-1;
1089 #if defined(WINDOWS) || defined(MACINTOSH)
1093 while ( item[choice].type==NM_TYPE_TEXT ) {
1095 if (choice >= nitems ) {
1098 if (choice == citem ) {
1109 // Clear mouse, joystick to clear button presses.
1110 game_flush_inputs();
1112 #if defined(WINDOWS) || defined(MACINTOSH)
1113 mouse_state = omouse_state = 0;
1114 if (filename == NULL && !MenuReordering) {
1115 draw_close_box(0,0);
1121 if (!MenuReordering) {
1123 SetCursor (LoadCursor(NULL,IDC_ARROW));
1128 if (!joydefs_calibrating)
1132 mprintf ((0,"Set to true!\n"));
1138 DoMessageStuff(&msg);
1140 if (_RedrawScreen) {
1141 _RedrawScreen = FALSE;
1144 gr_free_bitmap(bg.saved);
1145 d_free( bg.background );
1148 gr_free_bitmap(bg.background);
1150 dd_gr_free_sub_canvas( bg.menu_canvas );
1151 grd_curcanv->cv_font = save_font;
1152 dd_grd_curcanv = save_canvas;
1154 goto RePaintNewmenu4;
1163 omouse_state = mouse_state;
1164 mouse_state = mouse_button_state(0);
1165 if (!joydefs_calibrating)
1166 show_cursor(); // possibly hidden
1170 omouse_state = mouse_state;
1171 if (!MenuReordering)
1172 mouse_state = mouse_button_state(0);
1173 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1176 //see if redbook song needs to be restarted
1177 songs_check_redbook_repeat();
1184 (*subfunction)(nitems,item,&k,choice);
1187 if (!time_stopped) {
1188 // Save current menu box
1189 if (multi_menu_poll() == -1)
1195 dont_restore = (k == -3); //-3 means don't restore
1201 if (check_button_press())
1205 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1208 old_choice = choice;
1214 if (SurfingNet && !already_showing_info)
1216 show_extra_netgame_info(choice-2);
1218 if (SurfingNet && already_showing_info)
1225 if (SurfingNet && !already_showing_info)
1227 network_request_player_names(choice-2);
1229 if (SurfingNet && already_showing_info)
1244 case KEY_TAB + KEY_SHIFTED:
1247 if (all_text) break;
1254 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1256 if (choice<TopChoice)
1257 { choice=TopChoice; break; }
1259 if (choice<ScrollOffset)
1261 for (i=0;i<nitems;i++)
1264 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1269 if (choice >= nitems ) choice=0;
1270 if (choice < 0 ) choice=nitems-1;
1272 } while ( item[choice].type==NM_TYPE_TEXT );
1273 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1274 item[choice].value = -1;
1275 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1276 item[old_choice].group=0;
1277 strcpy(item[old_choice].text, item[old_choice].saved_text );
1278 item[old_choice].value = -1;
1281 item[old_choice].redraw = 1;
1282 item[choice].redraw=1;
1287 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1288 if (all_text) break;
1295 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1298 { choice--; break; }
1300 if (choice>=MaxOnMenu+ScrollOffset)
1302 for (i=0;i<nitems;i++)
1305 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1310 if (choice < 0 ) choice=nitems-1;
1311 if (choice >= nitems ) choice=0;
1314 } while ( item[choice].type==NM_TYPE_TEXT );
1316 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1317 item[choice].value = -1;
1318 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1319 item[old_choice].group=0;
1320 strcpy(item[old_choice].text, item[old_choice].saved_text );
1321 item[old_choice].value = -1;
1324 item[old_choice].redraw=1;
1325 item[choice].redraw=1;
1328 if ( choice > -1 ) {
1329 switch( item[choice].type ) {
1332 case NM_TYPE_INPUT_MENU:
1335 if ( item[choice].value )
1336 item[choice].value = 0;
1338 item[choice].value = 1;
1339 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1342 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1344 mprintf ((0,"Special redraw!\n"));
1349 item[choice].redraw=1;
1352 for (i=0; i<nitems; i++ ) {
1353 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1358 item[choice].value = 1;
1359 item[choice].redraw = 1;
1365 case KEY_SHIFTED+KEY_UP:
1366 if (MenuReordering && choice!=TopChoice)
1368 Temp=item[choice].text;
1369 TempVal=item[choice].value;
1370 item[choice].text=item[choice-1].text;
1371 item[choice].value=item[choice-1].value;
1372 item[choice-1].text=Temp;
1373 item[choice-1].value=TempVal;
1374 item[choice].redraw=1;
1375 item[choice-1].redraw=1;
1379 case KEY_SHIFTED+KEY_DOWN:
1380 if (MenuReordering && choice!=(nitems-1))
1382 Temp=item[choice].text;
1383 TempVal=item[choice].value;
1384 item[choice].text=item[choice+1].text;
1385 item[choice].value=item[choice+1].value;
1386 item[choice+1].text=Temp;
1387 item[choice+1].value=TempVal;
1388 item[choice].redraw=1;
1389 item[choice+1].redraw=1;
1396 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1397 item[choice].group = 1;
1398 item[choice].redraw = 1;
1399 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1400 item[choice].text[0] = 0;
1401 item[choice].value = -1;
1403 strip_end_whitespace(item[choice].text);
1410 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1411 item[choice].group=0;
1412 strcpy(item[choice].text, item[choice].saved_text );
1413 item[choice].redraw=1;
1414 item[choice].value = -1;
1421 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1422 case KEY_PRINT_SCREEN:
1424 save_screen_shot(0);
1425 PA_DFX (pa_set_frontbuffer_current());
1426 PA_DFX (pa_set_front_to_read());
1427 for (i=0;i<nitems;i++)
1436 case KEY_COMMAND+KEY_RIGHT:
1437 songs_goto_next_song();
1439 case KEY_COMMAND+KEY_LEFT:
1440 songs_goto_prev_song();
1442 case KEY_COMMAND+KEY_UP:
1443 songs_play_level_song(1);
1445 case KEY_COMMAND+KEY_DOWN:
1446 songs_stop_redbook();
1449 case KEY_COMMAND+KEY_M:
1451 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1452 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1455 key_close(); // no processing of keys with keyboard handler.. jeez
1458 show_boxed_message ("Mounting CD\nESC to quit");
1459 RBAMountDisk(); // OS has totaly control of the CD.
1460 if (Function_mode == FMODE_MENU)
1461 songs_play_song(SONG_TITLE,1);
1462 else if (Function_mode == FMODE_GAME)
1463 songs_play_level_song( Current_level_num );
1464 clear_boxed_message();
1473 case KEY_COMMAND+KEY_E:
1474 songs_stop_redbook();
1476 k = -1; // force key not to register
1479 case KEY_COMMAND+KEY_Q: {
1480 extern void macintosh_quit();
1482 if ( !(Game_mode & GM_MULTI) )
1484 if (!joydefs_calibrating)
1486 k = -1; // force key not to register
1493 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1500 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1502 if ( !done && mouse_state && !omouse_state && !all_text ) {
1503 mouse_get_pos(&mx, &my);
1504 for (i=0; i<nitems; i++ ) {
1505 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1506 x2 = x1 + item[i].w;
1507 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1508 y2 = y1 + item[i].h;
1509 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1510 if (i+ScrollOffset != choice) {
1511 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1514 choice = i + ScrollOffset;
1516 switch( item[choice].type ) {
1518 if ( item[choice].value )
1519 item[choice].value = 0;
1521 item[choice].value = 1;
1522 item[choice].redraw=1;
1529 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1531 mprintf ((0,"Special redraw!\n"));
1538 for (i=0; i<nitems; i++ ) {
1539 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1544 item[choice].value = 1;
1545 item[choice].redraw = 1;
1548 item[old_choice].redraw=1;
1554 if (mouse_state && all_text)
1557 if ( !done && mouse_state && !all_text ) {
1558 mouse_get_pos(&mx, &my);
1560 // check possible scrollbar stuff first
1562 int arrow_width, arrow_height, aw;
1564 if (ScrollOffset != 0) {
1565 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1566 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1567 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1568 x1 = x1 - arrow_width;
1569 y2 = y1 + arrow_height;
1570 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1573 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1575 if (choice<ScrollOffset)
1577 for (i=0;i<nitems;i++)
1580 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1584 if (ScrollOffset+MaxDisplayable<nitems) {
1585 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1586 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1587 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1588 x1 = x1 - arrow_width;
1589 y2 = y1 + arrow_height;
1590 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1593 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1595 if (choice>=MaxOnMenu+ScrollOffset)
1597 for (i=0;i<nitems;i++)
1600 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1606 for (i=0; i<nitems; i++ ) {
1607 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1608 x2 = x1 + item[i].w;
1609 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1610 y2 = y1 + item[i].h;
1611 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1612 if (i+ScrollOffset != choice) {
1613 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1616 choice = i + ScrollOffset;
1618 if ( item[choice].type == NM_TYPE_SLIDER ) {
1619 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1620 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1622 strcpy(slider_text, item[choice].saved_text);
1623 p = strchr(slider_text, '\t');
1629 gr_get_string_size(s1, &slider_width, &height, &aw);
1630 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1631 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1632 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1634 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1635 x2 = x1 + slider_width + sright_width;
1636 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1637 item[choice].value = item[choice].min_value;
1638 item[choice].redraw = 2;
1639 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1640 item[choice].value = item[choice].max_value;
1641 item[choice].redraw = 2;
1642 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1643 int num_values, value_width, new_value;
1645 num_values = item[choice].max_value - item[choice].min_value + 1;
1646 value_width = (slider_width - sleft_width - sright_width) / num_values;
1647 new_value = (mx - x1 - sleft_width) / value_width;
1648 if ( item[choice].value != new_value ) {
1649 item[choice].value = new_value;
1650 item[choice].redraw = 2;
1656 if (choice == old_choice)
1658 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1659 item[choice].value = -1;
1660 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1661 item[old_choice].group=0;
1662 strcpy(item[old_choice].text, item[old_choice].saved_text );
1663 item[old_choice].value = -1;
1666 item[old_choice].redraw = 1;
1667 item[choice].redraw=1;
1673 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1674 mouse_get_pos(&mx, &my);
1675 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1676 x2 = x1 + item[choice].w;
1677 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1678 y2 = y1 + item[choice].h;
1679 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1680 if (Hack_DblClick_MenuMode) {
1681 if (dblclick_flag) done = 1;
1682 else dblclick_flag = 1;
1688 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1689 item[choice].group = 1;
1690 item[choice].redraw = 1;
1691 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1692 item[choice].text[0] = 0;
1693 item[choice].value = -1;
1695 strip_end_whitespace(item[choice].text);
1699 if ( !done && !mouse_state && omouse_state && close_box ) {
1700 mouse_get_pos(&mx, &my);
1701 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1702 x2 = x1 + CLOSE_SIZE;
1703 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1704 y2 = y1 + CLOSE_SIZE;
1705 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1711 // HACK! Don't redraw loadgame preview
1712 if (RestoringMenu) item[0].redraw = 0;
1713 #endif // ifdef MACINTOSH
1715 if ( choice > -1 ) {
1718 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1719 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1720 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1721 if (item[choice].value > 0)
1722 item[choice].value--;
1723 item[choice].text[item[choice].value] = 0;
1724 item[choice].redraw = 1;
1726 ascii = key_to_ascii(k);
1727 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1731 if (item[choice].value==-1) {
1732 item[choice].value = 0;
1735 allowed = char_allowed(ascii);
1737 if (!allowed && ascii==' ' && char_allowed('_')) {
1743 item[choice].text[item[choice].value++] = ascii;
1744 item[choice].text[item[choice].value] = 0;
1745 item[choice].redraw=1;
1749 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1750 ascii = key_to_ascii(k);
1752 int choice1 = choice;
1753 ascii = toupper(ascii);
1757 if (choice1 >= nitems ) choice1=0;
1758 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1759 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1760 (item[choice1].type==NM_TYPE_CHECK) ||
1761 (item[choice1].type==NM_TYPE_RADIO) ||
1762 (item[choice1].type==NM_TYPE_NUMBER) ||
1763 (item[choice1].type==NM_TYPE_SLIDER) )
1764 && (ascii==toupper(ch)) ) {
1768 item[old_choice].redraw=1;
1769 item[choice].redraw=1;
1771 } while (choice1 != choice );
1775 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1776 int ov=item[choice].value;
1781 case KEY_MINUS+KEY_SHIFTED:
1783 item[choice].value -= 1;
1788 case KEY_EQUAL+KEY_SHIFTED:
1790 item[choice].value++;
1795 item[choice].value += 10;
1800 item[choice].value -= 10;
1803 if (ov!=item[choice].value)
1804 item[choice].redraw=1;
1809 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1810 gr_set_current_canvas(bg.menu_canvas));
1812 // Redraw everything...
1813 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1815 if (item[i].redraw) // warning! ugly hack below
1817 item[i].y-=((string_height+1)*ScrollOffset);
1820 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1822 MAC(if (!joydefs_calibrating) show_cursor());
1823 WIN(if (!MenuReordering) ShowCursorW());
1824 item[i].y+=((string_height+1)*ScrollOffset);
1826 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1827 update_cursor( &item[i]);
1833 //grd_curcanv->cv_font = NORMAL_FONT;
1835 if (LastScrollCheck!=ScrollOffset)
1837 LastScrollCheck=ScrollOffset;
1838 grd_curcanv->cv_font = SELECTED_FONT;
1840 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1841 sx=item[ScrollOffset].x-(MenuHires?24:12);
1844 if (ScrollOffset!=0)
1845 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1847 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1849 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1850 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1852 if (ScrollOffset+MaxDisplayable<nitems)
1853 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1855 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1861 if ( !dont_restore && gr_palette_faded_out ) {
1862 gr_palette_fade_in( gr_palette, 32, 0 );
1869 // Restore everything...
1871 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1872 gr_set_current_canvas(bg.menu_canvas));
1874 if ( filename == NULL ) {
1875 // Save the background under the menu...
1876 WIN (DDGRLOCK(dd_grd_curcanv));
1877 gr_bitmap(0, 0, bg.saved);
1878 WIN (DDGRUNLOCK(dd_grd_curcanv));
1879 gr_free_bitmap(bg.saved);
1880 d_free( bg.background );
1882 if (!dont_restore) //info passed back from subfunction
1884 WIN (DDGRLOCK(dd_grd_curcanv));
1885 gr_bitmap(0, 0, bg.background);
1886 WIN (DDGRUNLOCK(dd_grd_curcanv));
1888 gr_free_bitmap(bg.background);
1891 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1892 gr_free_sub_canvas( bg.menu_canvas ) );
1894 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1895 grd_curcanv->cv_font = save_font;
1896 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1897 keyd_repeat = old_keyd_repeat;
1899 game_flush_inputs();
1910 if ( sound_stopped )
1911 digi_resume_digi_sounds();
1913 WIN(mouse_set_mode(1)); //re-enable centering mode
1920 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1926 char nm_text[MESSAGEBOX_TEXT_SIZE];
1927 newmenu_item nm_message_items[5];
1929 va_start(args, nchoices );
1931 Assert( nchoices <= 5 );
1933 for (i=0; i<nchoices; i++ ) {
1934 s = va_arg( args, char * );
1935 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1937 format = va_arg( args, char * );
1938 strcpy( nm_text, "" );
1939 vsprintf(nm_text,format,args);
1942 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1944 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1947 int nm_messagebox( char *title, int nchoices, ... )
1953 char nm_text[MESSAGEBOX_TEXT_SIZE];
1954 newmenu_item nm_message_items[5];
1956 va_start(args, nchoices );
1958 Assert( nchoices <= 5 );
1960 for (i=0; i<nchoices; i++ ) {
1961 s = va_arg( args, char * );
1962 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1964 format = va_arg( args, char * );
1965 strcpy( nm_text, "" );
1966 vsprintf(nm_text,format,args);
1969 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1971 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1977 void newmenu_file_sort( int n, char *list )
1984 for (i=incr; i<n; i++ ) {
1987 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1988 memcpy( t, &list[j*14], FILENAME_LEN );
1989 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1990 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2001 void delete_player_saved_games(char * name)
2006 for (i=0;i<10; i++) {
2008 sprintf( filename, "%s.sg%d", name, i );
2010 sprintf( filename, ":Players:%s.sg%d", name, i );
2016 #define MAX_FILES 300
2018 int MakeNewPlayerFile(int allow_abort);
2020 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2023 FILEFINDSTRUCT find;
2024 int NumFiles=0, key,done, citem, ocitem;
2025 char * filenames = NULL;
2026 int NumFiles_displayed = 8;
2027 int first_item = -1, ofirst_item;
2028 int old_keyd_repeat = keyd_repeat;
2031 int demos_deleted=0;
2032 int initialized = 0;
2034 int w_x, w_y, w_w, w_h, title_height;
2035 int box_x, box_y, box_w, box_h;
2036 bkg bg; // background under listbox
2037 #if defined(MACINTOSH) || defined(WINDOWS)
2038 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2039 int mouse2_state, omouse2_state;
2040 int dblclick_flag=0;
2042 int show_up_arrow=0,show_down_arrow=0;
2044 WIN(int win_redraw=0);
2046 w_x=w_y=w_w=w_h=title_height=0;
2047 box_x=box_y=box_w=box_h=0;
2049 filenames = d_malloc( MAX_FILES * 14 );
2050 if (filenames==NULL) return 0;
2055 WIN(mouse_set_mode(0)); //disable centering mode
2057 if (strstr( filespec, "*.plr" ))
2059 else if (strstr( filespec, "*.dem" ))
2066 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2068 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2073 if( !FileFindFirst( filespec, &find ) ) {
2075 if (NumFiles<MAX_FILES) {
2076 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2077 if ( player_mode ) {
2079 p = strchr(&filenames[NumFiles*14],'.');
2086 } while( !FileFindNext( &find ) );
2090 if ( (NumFiles < 1) && demos_deleted ) {
2094 if ( (NumFiles < 1) && demo_mode ) {
2095 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2101 if ( (NumFiles < 2) && player_mode ) {
2103 goto ExitFileMenuEarly;
2110 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2117 // set_screen_mode(SCREEN_MENU);
2123 dd_gr_set_current_canvas(NULL);
2125 gr_set_current_canvas(NULL);
2128 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2130 grd_curcanv->cv_font = SUBTITLE_FONT;
2132 WIN(DDGRUNLOCK(dd_grd_curcanv));
2137 for (i=0; i<NumFiles; i++ ) {
2139 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2145 gr_get_string_size( title, &w, &h, &aw );
2148 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2152 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2154 w_w += (grd_curfont->ft_w * 4);
2155 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2157 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2158 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2160 w_x = (grd_curcanv->cv_w-w_w)/2;
2161 w_y = (grd_curcanv->cv_h-w_h)/2;
2163 if ( w_x < 0 ) w_x = 0;
2164 if ( w_y < 0 ) w_y = 0;
2166 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2167 box_y = w_y + title_height;
2169 // save the screen behind the menu.
2173 #if !defined(WINDOWS)
2174 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2175 bg.background = &VR_offscreen_buffer->cv_bitmap;
2178 #if defined(POLY_ACC)
2179 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2181 bg.background = gr_create_bitmap( w_w, w_h );
2184 Assert( bg.background != NULL );
2187 WIN(DDGRLOCK(dd_grd_curcanv));
2188 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2189 WIN(DDGRUNLOCK(dd_grd_curcanv));
2193 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2194 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2195 dd_VR_offscreen_buffer, 0, 0,
2196 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2197 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2201 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2203 WIN(DDGRLOCK(dd_grd_curcanv))
2205 gr_string( 0x8000, w_y+10, title );
2207 WIN(DDGRUNLOCK(dd_grd_curcanv));
2214 if ( !player_mode ) {
2215 newmenu_file_sort( NumFiles, filenames );
2217 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2218 newmenu_file_sort( NumFiles, filenames );
2220 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2222 for ( i=0; i<NumFiles; i++ ) {
2223 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2224 #if defined(WINDOWS) || defined(MACINTOSH)
2232 #if defined(MACINTOSH) || defined(WINDOWS)
2233 mouse_state = omouse_state = 0;
2234 mouse2_state = omouse2_state = 0;
2235 draw_close_box(w_x,w_y);
2247 DoMessageStuff(&msg);
2249 if (_RedrawScreen) {
2250 _RedrawScreen = FALSE;
2252 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2253 gr_free_bitmap(bg.background);
2256 goto RePaintNewmenuFile;
2263 ofirst_item = first_item;
2266 #if defined(MACINTOSH) || defined(WINDOWS)
2267 omouse_state = mouse_state;
2268 omouse2_state = mouse2_state;
2269 mouse_state = mouse_button_state(0);
2270 mouse2_state = mouse_button_state(1);
2273 //see if redbook song needs to be restarted
2274 songs_check_redbook_repeat();
2277 if (!mouse2_state && omouse2_state)
2278 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2281 //NOTE LINK TO ABOVE ELSE
2287 else if (simukey==1)
2293 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2294 case KEY_PRINT_SCREEN:
2296 save_screen_shot(0);
2297 PA_DFX (pa_set_frontbuffer_current());
2298 PA_DFX (pa_set_front_to_read());
2304 case KEY_CTRLED+KEY_D:
2305 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2309 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2313 mouse_set_mode(1); //re-enable centering mode
2317 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2319 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2322 mouse_set_mode(0); //disenable centering mode
2328 char name[_MAX_PATH],dir[_MAX_DIR];
2330 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2334 _splitpath(filespec,name,dir,NULL,NULL);
2336 strcat(name,&filenames[citem*14]);
2343 if ( !strncmp(name, ".\\", 2) )
2344 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2345 name[i] = name[i+1];
2346 while ( (p = strchr(name, '\\')) )
2351 ret = unlink( name );
2355 if ((!ret) && player_mode) {
2356 delete_player_saved_games( &filenames[citem*14] );
2361 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2363 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2364 } else if (demo_mode)
2389 citem += NumFiles_displayed;
2393 citem -= NumFiles_displayed;
2396 if (allow_abort_flag) {
2407 case KEY_COMMAND+KEY_Q: {
2408 extern void macintosh_quit();
2410 if ( !(Game_mode & GM_MULTI) )
2421 int ascii = key_to_ascii(key);
2422 if ( ascii < 255 ) {
2425 if (cc1 < 0 ) cc1 = 0;
2426 if (cc1 >= NumFiles ) cc1 = 0;
2428 if ( cc < 0 ) cc = 0;
2429 if ( cc >= NumFiles ) cc = 0;
2430 if ( citem == cc ) break;
2432 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2447 if (citem>=NumFiles)
2450 if (citem< first_item)
2453 if (citem>=( first_item+NumFiles_displayed))
2455 first_item = citem-NumFiles_displayed+1;
2459 if (NumFiles>first_item+NumFiles_displayed)
2470 if (NumFiles <= NumFiles_displayed )
2473 if (first_item>NumFiles-NumFiles_displayed)
2475 first_item = NumFiles-NumFiles_displayed;
2478 if (first_item < 0 ) first_item = 0;
2480 #if defined(MACINTOSH) || defined(WINDOWS)
2482 if (mouse_state || mouse2_state) {
2485 mouse_get_pos(&mx, &my);
2486 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2487 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2489 x2 = box_x + box_w - 1;
2490 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2492 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2493 if (i == citem && !mouse2_state) {
2503 if (!mouse_state && omouse_state) {
2506 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2507 mouse_get_pos(&mx, &my);
2509 x2 = box_x + box_w - 1;
2510 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2512 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2513 if (dblclick_flag) done = 1;
2514 else dblclick_flag = 1;
2518 if ( !mouse_state && omouse_state ) {
2519 mouse_get_pos(&mx, &my);
2520 x1 = w_x + CLOSE_X + 2;
2521 x2 = x1 + CLOSE_SIZE - 2;
2522 y1 = w_y + CLOSE_Y + 2;
2523 y2 = y1 + CLOSE_SIZE - 2;
2524 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2533 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2535 y1 = box_y+box_h-LHY(7);
2537 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2544 WIN(DDGRLOCK(dd_grd_curcanv));
2545 gr_setcolor( BM_XRGB(2,2,2));
2546 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2547 gr_setcolor( BM_XRGB( 0,0,0) );
2550 if (ofirst_item != first_item || win_redraw) {
2553 if (ofirst_item != first_item) {
2557 gr_setcolor( BM_XRGB( 0,0,0) );
2558 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2560 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2562 if ( i >= NumFiles ) {
2564 gr_setcolor( BM_XRGB(5,5,5));
2565 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2566 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2568 gr_setcolor( BM_XRGB(2,2,2));
2569 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2571 gr_setcolor( BM_XRGB(0,0,0));
2572 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2576 grd_curcanv->cv_font = SELECTED_FONT;
2578 grd_curcanv->cv_font = NORMAL_FONT;
2579 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2581 gr_setcolor( BM_XRGB(5,5,5));
2582 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2583 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2585 gr_setcolor( BM_XRGB(2,2,2));
2586 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2587 gr_setcolor( BM_XRGB(0,0,0));
2589 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2590 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2595 } else if ( citem != ocitem ) {
2601 if ( (i>=0) && (i<NumFiles) ) {
2602 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2604 grd_curcanv->cv_font = SELECTED_FONT;
2606 grd_curcanv->cv_font = NORMAL_FONT;
2607 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2608 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2609 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2612 if ( (i>=0) && (i<NumFiles) ) {
2613 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2615 grd_curcanv->cv_font = SELECTED_FONT;
2617 grd_curcanv->cv_font = NORMAL_FONT;
2618 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2619 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2620 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2627 grd_curcanv->cv_font = NORMAL_FONT;
2629 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2633 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2637 if (show_down_arrow)
2638 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2642 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2650 WIN(DDGRUNLOCK(dd_grd_curcanv));
2656 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2663 keyd_repeat = old_keyd_repeat;
2665 if ( initialized ) {
2666 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2668 WIN (DDGRLOCK(dd_grd_curcanv));
2669 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2670 WIN (DDGRUNLOCK(dd_grd_curcanv));
2672 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2673 gr_free_bitmap(bg.background);
2676 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2677 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2679 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2680 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2690 WIN(mouse_set_mode(1)); //re-enable centering mode
2698 // Example listbox callback function...
2699 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2703 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2704 // if ( *nitems > 1 ) {
2705 // unlink( items[*citem] ); // Delete the file
2706 // for (i=*citem; i<*nitems-1; i++ ) {
2707 // items[i] = items[i+1];
2709 // *nitems = *nitems - 1;
2710 // d_free( items[*nitems] );
2711 // items[*nitems] = NULL;
2712 // return 1; // redraw;
2719 #define LB_ITEMS_ON_SCREEN 8
2721 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2723 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2726 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 ) )
2729 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2730 int old_keyd_repeat = keyd_repeat;
2731 int width, height, wx, wy, title_height, border_size;
2732 int total_width,total_height;
2734 #if defined(MACINTOSH) || defined(WINDOWS)
2735 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2736 int close_x,close_y;
2737 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2739 WIN(int win_redraw=0);
2743 PA_DFX (pa_set_frontbuffer_current());
2744 PA_DFX (pa_set_front_to_read());
2745 WIN(mouse_set_mode(0)); //disable centering mode
2747 // set_screen_mode(SCREEN_MENU);
2751 RePaintNewmenuListbox:
2753 dd_gr_set_current_canvas(NULL);
2755 gr_set_current_canvas(NULL);
2758 grd_curcanv->cv_font = SUBTITLE_FONT;
2761 for (i=0; i<nitems; i++ ) {
2763 gr_get_string_size( items[i], &w, &h, &aw );
2767 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2771 gr_get_string_size( title, &w, &h, &aw );
2774 title_height = h + 5;
2777 border_size = grd_curfont->ft_w;
2778 WIN (border_size=grd_curfont->ft_w*2);
2780 width += (grd_curfont->ft_w);
2781 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2782 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2784 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2785 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2786 if ( wy < title_height )
2789 total_width = width+2*border_size;
2790 total_height = height+2*border_size+title_height;
2794 #if !defined(WINDOWS)
2795 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2796 bg.background = &VR_offscreen_buffer->cv_bitmap;
2799 //bg.background = gr_create_bitmap( width, (height + title_height) );
2800 #if defined(POLY_ACC)
2801 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2803 bg.background = gr_create_bitmap(total_width,total_height);
2805 Assert( bg.background != NULL );
2807 WIN (DDGRLOCK(dd_grd_curcanv));
2808 //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 );
2809 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2810 WIN (DDGRUNLOCK(dd_grd_curcanv));
2814 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2815 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2816 dd_VR_offscreen_buffer, 0, 0,
2817 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2818 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2822 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2824 WIN(DDGRLOCK(dd_grd_curcanv));
2825 gr_string( 0x8000, wy - title_height, title );
2826 WIN(DDGRUNLOCK(dd_grd_curcanv));
2831 citem = default_item;
2832 if ( citem < 0 ) citem = 0;
2833 if ( citem >= nitems ) citem = 0;
2837 #if defined(MACINTOSH) || defined(WINDOWS)
2838 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2839 close_x = wx-border_size;
2840 close_y = wy-title_height-border_size;
2841 draw_close_box(close_x,close_y);
2853 DoMessageStuff(&msg);
2855 if (_RedrawScreen) {
2856 _RedrawScreen = FALSE;
2858 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2859 gr_free_bitmap(bg.background);
2861 goto RePaintNewmenuListbox;
2868 ofirst_item = first_item;
2869 #if defined(MACINTOSH) || defined(WINDOWS)
2870 omouse_state = mouse_state;
2871 mouse_state = mouse_button_state(0);
2873 //see if redbook song needs to be restarted
2874 songs_check_redbook_repeat();
2878 if ( listbox_callback )
2879 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2900 else if (simukey==1)
2906 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2907 case KEY_PRINT_SCREEN:
2909 save_screen_shot(0);
2910 PA_DFX (pa_set_frontbuffer_current());
2911 PA_DFX (pa_set_front_to_read());
2934 citem += LB_ITEMS_ON_SCREEN;
2938 citem -= LB_ITEMS_ON_SCREEN;
2941 if (allow_abort_flag) {
2952 case KEY_COMMAND+KEY_Q: {
2953 extern void macintosh_quit();
2955 if ( !(Game_mode & GM_MULTI) )
2965 int ascii = key_to_ascii(key);
2966 if ( ascii < 255 ) {
2969 if (cc1 < 0 ) cc1 = 0;
2970 if (cc1 >= nitems ) cc1 = 0;
2972 if ( cc < 0 ) cc = 0;
2973 if ( cc >= nitems ) cc = 0;
2974 if ( citem == cc ) break;
2976 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2993 if (citem< first_item)
2996 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2997 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2999 if (nitems <= LB_ITEMS_ON_SCREEN )
3002 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3003 first_item = nitems-LB_ITEMS_ON_SCREEN;
3004 if (first_item < 0 ) first_item = 0;
3007 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3018 #if defined(MACINTOSH) || defined(WINDOWS)
3023 mouse_get_pos(&mx, &my);
3024 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3027 gr_get_string_size(items[i], &w, &h, &aw );
3030 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3032 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3044 //no double-click stuff for listbox
3045 //@@if (!mouse_state && omouse_state) {
3048 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3049 //@@ mouse_get_pos(&mx, &my);
3051 //@@ x2 = wx + width;
3052 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3054 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3055 //@@ if (dblclick_flag) done = 1;
3059 //check for close box clicked
3060 if ( !mouse_state && omouse_state ) {
3061 mouse_get_pos(&mx, &my);
3062 x1 = close_x + CLOSE_X + 2;
3063 x2 = x1 + CLOSE_SIZE - 2;
3064 y1 = close_y + CLOSE_Y + 2;
3065 y2 = y1 + CLOSE_SIZE - 2;
3066 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3076 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3078 y1 = total_height-LHY(7);
3080 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3088 if ( (ofirst_item != first_item) || redraw) {
3091 WIN(DDGRLOCK(dd_grd_curcanv));
3093 gr_setcolor( BM_XRGB( 0,0,0) );
3094 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3096 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3097 if ( i >= nitems ) {
3098 gr_setcolor( BM_XRGB(0,0,0));
3099 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3102 grd_curcanv->cv_font = SELECTED_FONT;
3104 grd_curcanv->cv_font = NORMAL_FONT;
3105 gr_get_string_size(items[i], &w, &h, &aw );
3106 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3107 gr_string( wx+5, y, items[i] );
3112 // If Win95 port, draw up/down arrows on left side of menu
3114 grd_curcanv->cv_font = NORMAL_FONT;
3116 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3120 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3124 if (show_down_arrow)
3125 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3129 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3136 WIN(DDGRUNLOCK(dd_grd_curcanv));
3140 } else if ( citem != ocitem ) {
3146 WIN(DDGRLOCK(dd_grd_curcanv));
3149 if ( (i>=0) && (i<nitems) ) {
3150 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3152 grd_curcanv->cv_font = SELECTED_FONT;
3154 grd_curcanv->cv_font = NORMAL_FONT;
3155 gr_get_string_size(items[i], &w, &h, &aw );
3156 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3157 gr_string( wx+5, y, items[i] );
3161 if ( (i>=0) && (i<nitems) ) {
3162 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3164 grd_curcanv->cv_font = SELECTED_FONT;
3166 grd_curcanv->cv_font = NORMAL_FONT;
3167 gr_get_string_size( items[i], &w, &h, &aw );
3168 gr_rect( wx, y-1, wx+width-1, y+h );
3169 gr_string( wx+5, y, items[i] );
3171 WIN(DDGRUNLOCK(dd_grd_curcanv));
3181 keyd_repeat = old_keyd_repeat;
3183 WIN (DDGRLOCK(dd_grd_curcanv));
3184 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3185 WIN (DDGRUNLOCK(dd_grd_curcanv));
3187 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3188 gr_free_bitmap(bg.background);
3192 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3193 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3195 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3196 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3202 WIN(mouse_set_mode(1)); //re-enable centering mode
3207 int newmenu_filelist( char * title, char * filespec, char * filename )
3210 char * Filenames[MAX_FILES];
3211 char FilenameText[MAX_FILES][14];
3212 FILEFINDSTRUCT find;
3215 if( !FileFindFirst( filespec, &find ) ) {
3217 if (NumFiles<MAX_FILES) {
3218 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3219 Filenames[NumFiles] = FilenameText[NumFiles];
3224 } while( !FileFindNext( &find ) );
3228 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3230 strcpy( filename, Filenames[i] );
3237 extern netgame_info Active_games[];
3238 extern int NumActiveNetgames;
3240 void show_extra_netgame_info(int choice)
3246 if (choice>=NumActiveNetgames)
3251 m[i].text=(char *)&mtext[i];
3252 m[i].type=NM_TYPE_TEXT;
3255 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3256 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3257 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3258 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3260 already_showing_info=1;
3261 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3262 already_showing_info=0;
3267 /* Spiffy word wrap string formatting function */
3269 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3275 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3278 wordptr = strtok(tbuf, " ");
3279 if (!wordptr) return;
3285 col = col+strlen(wordptr)+1;
3286 if (col >=line_length) {
3288 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3291 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3293 wordptr = strtok(NULL, " ");