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.6 2001-11-08 10:30:28 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 "scores.pcx"
209 #define MENU_BACKGROUND_BITMAP (MenuHires?"\x01scoresb.pcx":"\x01scores.pcx") //read only from hog file
211 #define MENU_BACKGROUND_BITMAP (MenuHires?"scoresb.pcx":"scores.pcx")
215 int Background_hires;
218 void nm_draw_background(int x1, int y1, int x2, int y2 )
222 if (Newmenu_first_time || MenuHires!=Background_hires) {
225 if (Newmenu_first_time) {
226 atexit( newmenu_close );
227 Newmenu_first_time = 0;
228 nm_background_save.bm_data=NULL;
231 if (nm_background_save.bm_data)
232 d_free(nm_background_save.bm_data);
233 if (nm_background.bm_data)
234 d_free(nm_background.bm_data);
237 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
238 Assert(pcx_error == PCX_ERROR_NONE);
240 nm_background = nm_background_save;
241 nm_background.bm_data=NULL;
242 nm_remap_background();
244 Background_hires = MenuHires;
247 if ( x1 < 0 ) x1 = 0;
248 if ( y1 < 0 ) y1 = 0;
253 if ( w > nm_background.bm_w ) w = nm_background.bm_w;
254 if ( h > nm_background.bm_h ) h = nm_background.bm_h;
259 WIN(DDGRLOCK(dd_grd_curcanv));
261 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
263 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
268 Gr_scanline_darkening_level = 2*7;
271 gr_setcolor( BM_XRGB(0,0,0) );
272 gr_urect( x2-5, y1+5, x2-5, y2-5 );
273 gr_urect( x2-4, y1+4, x2-4, y2-5 );
274 gr_urect( x2-3, y1+3, x2-3, y2-5 );
275 gr_urect( x2-2, y1+2, x2-2, y2-5 );
276 gr_urect( x2-1, y1+1, x2-1, y2-5 );
277 gr_urect( x2+0, y1+0, x2-0, y2-5 );
279 gr_urect( x1+5, y2-5, x2, y2-5 );
280 gr_urect( x1+4, y2-4, x2, y2-4 );
281 gr_urect( x1+3, y2-3, x2, y2-3 );
282 gr_urect( x1+2, y2-2, x2, y2-2 );
283 gr_urect( x1+1, y2-1, x2, y2-1 );
284 gr_urect( x1+0, y2, x2, y2-0 );
286 WIN(DDGRUNLOCK(dd_grd_curcanv));
288 Gr_scanline_darkening_level = GR_FADE_LEVELS;
291 void nm_restore_background( int x, int y, int w, int h )
298 if ( x1 < 0 ) x1 = 0;
299 if ( y1 < 0 ) y1 = 0;
301 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
302 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
307 WIN(DDGRLOCK(dd_grd_curcanv));
308 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
309 WIN(DDGRUNLOCK(dd_grd_curcanv));
312 // Draw a left justfied string
313 void nm_string( bkg * b, int w1,int x, int y, char * s)
315 int w,h,aw,tx=0,t=0,i;
316 char *p,*s1,measure[2];
317 int XTabs[]={15,87,124,162,228,253};
323 XTabs[i]=(LHX(XTabs[i]));
331 p = strchr( s, '\t' );
338 gr_get_string_size(s, &w, &h, &aw );
344 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
345 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
349 for (i=0;i<strlen(s);i++)
351 if (s[i]=='\t' && SurfingNet)
358 gr_get_string_size(measure,&tx,&h,&aw);
359 gr_string(x,y,measure);
363 else gr_string (x,y,s);
365 if (!SurfingNet && p && (w1>0) ) {
366 gr_get_string_size(s1, &w, &h, &aw );
368 gr_string( x+w1-w, y, s1 );
374 // Draw a slider and it's string
375 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
382 p = strchr( s, '\t' );
388 gr_get_string_size(s, &w, &h, &aw );
391 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
392 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
394 gr_string( x, y, s );
397 gr_get_string_size(s1, &w, &h, &aw );
400 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
402 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
404 gr_string( x+w1-w, y, s1 );
411 // Draw a left justfied string with black background.
412 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
415 gr_get_string_size(s, &w, &h, &aw );
419 WIN(DDGRLOCK(dd_grd_curcanv));
420 gr_setcolor( BM_XRGB(2,2,2) );
421 gr_rect( x-1, y-1, x-1, y+h-1 );
422 gr_rect( x-1, y-1, x+w1-1, y-1 );
425 gr_setcolor( BM_XRGB(5,5,5) );
426 gr_rect( x, y+h, x+w1, y+h);
427 gr_rect( x+w1, y-1, x+w1, y+h );
429 gr_setcolor( BM_XRGB(0,0,0) );
430 gr_rect( x, y, x+w1-1, y+h-1 );
432 gr_string( x+1, y+1, s );
433 WIN(DDGRUNLOCK(dd_grd_curcanv));
437 // Draw a right justfied string
438 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
441 gr_get_string_size(s, &w, &h, &aw );
446 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
449 WIN(DDGRLOCK(dd_grd_curcanv));
450 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
451 gr_string( x-w, y, s );
452 WIN(DDGRUNLOCK(dd_grd_curcanv));
457 //for text items, constantly redraw cursor (to achieve flash)
458 void update_cursor( newmenu_item *item)
461 fix time = timer_get_approx_seconds();
463 char * text = item->text;
465 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
468 gr_get_string_size(text, &w, &h, &aw );
469 if ( w > item->w-10 )
476 x = item->x+w; y = item->y;
478 WIN(DDGRLOCK(dd_grd_curcanv));
480 gr_string( x, y, CURSOR_STRING );
482 gr_setcolor( BM_XRGB(0,0,0) );
483 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
485 WIN(DDGRUNLOCK(dd_grd_curcanv));
488 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
493 gr_get_string_size(text, &w1, &h1, &aw );
502 nm_string_black( b, w, x, y, text );
505 gr_string( x+w1+1, y, CURSOR_STRING );
509 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
514 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
516 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
518 if (item->text[0]=='\t')
519 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
524 grd_curcanv->cv_font = SELECTED_FONT;
526 grd_curcanv->cv_font = NORMAL_FONT;
529 if (is_current && item->type == NM_TYPE_TEXT)
530 grd_curcanv->cv_font = NORMAL_FONT;
534 WIN(DDGRLOCK(dd_grd_curcanv));
535 switch( item->type ) {
537 // grd_curcanv->cv_font=TEXT_FONT;
538 // fall through on purpose
541 nm_string( b, item->w, item->x, item->y, item->text );
543 case NM_TYPE_SLIDER: {
545 if (item->value < item->min_value) item->value=item->min_value;
546 if (item->value > item->max_value) item->value=item->max_value;
547 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
548 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
549 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
551 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
553 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
555 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
558 case NM_TYPE_INPUT_MENU:
559 if ( item->group==0 ) {
560 nm_string( b, item->w, item->x, item->y, item->text );
562 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
566 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
569 nm_string( b, item->w, item->x, item->y, item->text );
571 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
573 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
576 nm_string( b, item->w, item->x, item->y, item->text );
578 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
580 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
582 case NM_TYPE_NUMBER: {
584 if (item->value < item->min_value) item->value=item->min_value;
585 if (item->value > item->max_value) item->value=item->max_value;
586 nm_string( b, item->w, item->x, item->y, item->text );
587 sprintf( text, "%d", item->value );
588 nm_rstring( b,item->right_offset,item->x, item->y, text );
592 WIN(DDGRUNLOCK(dd_grd_curcanv));
596 char *Newmenu_allowed_chars=NULL;
598 //returns true if char is allowed
599 int char_allowed(char c)
601 char *p = Newmenu_allowed_chars;
609 if (c>=p[0] && c<=p[1])
618 void strip_end_whitespace( char * text )
622 for (i=l-1; i>=0; i-- ) {
623 if ( isspace(text[i]) )
630 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
632 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
634 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
636 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
640 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
642 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
646 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 )
648 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
652 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 )
654 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
656 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 )
658 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
661 //returns 1 if a control device button has been pressed
662 int check_button_press()
666 switch (Config_control_type) {
667 case CONTROL_JOYSTICK:
668 case CONTROL_FLIGHTSTICK_PRO:
669 case CONTROL_THRUSTMASTER_FCS:
670 case CONTROL_GRAVIS_GAMEPAD:
672 if (joy_get_button_down_cnt(i)>0) return 1;
675 case CONTROL_CYBERMAN:
676 #ifndef MACINTOSH // don't allow mouse to continue from menu
678 if (mouse_button_down_count(i)>0) return 1;
681 case CONTROL_WINJOYSTICK:
684 if (joy_get_button_down_cnt(i)>0) return 1;
687 case CONTROL_NONE: //keyboard only
689 if (key_checkch()) return 1;
694 Error("Bad control type (Config_control_type):%i",Config_control_type);
700 extern int network_request_player_names(int);
701 extern int RestoringMenu;
703 #if defined(WINDOWS) || defined(MACINTOSH)
704 ubyte Hack_DblClick_MenuMode=0;
707 MAC(extern ubyte joydefs_calibrating;)
711 #define CLOSE_SIZE 10
713 void draw_close_box(int x,int y)
715 WIN (DDGRLOCK(dd_grd_curcanv));
716 gr_setcolor( BM_XRGB(0, 0, 0) );
717 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
718 gr_setcolor( BM_XRGB(21, 21, 21) );
719 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
720 WIN (DDGRUNLOCK(dd_grd_curcanv));
723 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 )
725 int old_keyd_repeat, done;
726 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
727 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
728 grs_font * save_font;
729 int string_width, string_height, average_width;
732 int all_text=0; //set true if all text items
733 int sound_stopped=0,time_stopped=0;
734 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
737 int MaxOnMenu=MAXDISPLAYABLEITEMS;
738 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
739 #if defined(MACINTOSH) || defined(WINDOWS)
740 int mouse_state, omouse_state, dblclick_flag=0;
741 int mx=0, my=0, x1, x2, y1, y2;
745 EventRecord event; // looking for disk inserted events for CD mounts
748 PA_DFX (pa_set_frontbuffer_current());
749 PA_DFX (pa_set_front_to_read());
751 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
760 WIN(mouse_set_mode(0)); //disable centering mode
762 MaxDisplayable=nitems;
765 set_screen_mode(SCREEN_MENU);
769 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
770 digi_pause_digi_sounds();
774 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
787 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
789 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
791 save_font = grd_curcanv->cv_font;
796 grd_curcanv->cv_font = TITLE_FONT;
797 gr_get_string_size(title,&string_width,&string_height,&average_width );
802 grd_curcanv->cv_font = SUBTITLE_FONT;
803 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
804 if (string_width > tw )
809 th += LHY(8); //put some space between titles & body
812 grd_curcanv->cv_font = SMALL_FONT;
814 grd_curcanv->cv_font = NORMAL_FONT;
818 nmenus = nothers = 0;
820 // Find menu height & width (store in w,h)
821 for (i=0; i<nitems; i++ ) {
824 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
825 item[i].right_offset = 0;
828 string_height+=LHY(3);
830 item[i].saved_text[0] = '\0';
832 if ( item[i].type == NM_TYPE_SLIDER ) {
835 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
836 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
837 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
839 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
840 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
841 string_width += w1 + aw;
844 if ( item[i].type == NM_TYPE_MENU ) {
848 if ( item[i].type == NM_TYPE_CHECK ) {
851 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
852 item[i].right_offset = w1;
853 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
854 if (w1 > item[i].right_offset)
855 item[i].right_offset = w1;
858 if (item[i].type == NM_TYPE_RADIO ) {
861 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
862 item[i].right_offset = w1;
863 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
864 if (w1 > item[i].right_offset)
865 item[i].right_offset = w1;
868 if (item[i].type==NM_TYPE_NUMBER ) {
872 sprintf( test_text, "%d", item[i].max_value );
873 gr_get_string_size( test_text, &w1, &h1, &aw1 );
874 item[i].right_offset = w1;
875 sprintf( test_text, "%d", item[i].min_value );
876 gr_get_string_size( test_text, &w1, &h1, &aw1 );
877 if ( w1 > item[i].right_offset)
878 item[i].right_offset = w1;
881 if ( item[i].type == NM_TYPE_INPUT ) {
882 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
883 strcpy(item[i].saved_text, item[i].text );
885 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
886 if ( string_width > MAX_TEXT_WIDTH )
887 string_width = MAX_TEXT_WIDTH;
891 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
892 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
893 strcpy(item[i].saved_text, item[i].text );
895 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
900 item[i].w = string_width;
901 item[i].h = string_height;
903 if ( string_width > w )
904 w = string_width; // Save maximum width
905 if ( average_width > aw )
907 h += string_height+1; // Find the height of all strings
910 // Big hack for allowing the netgame options menu to spill over
912 MaxOnMenu=MAXDISPLAYABLEITEMS;
913 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
916 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
919 h=(MaxOnMenu*(string_height+1)+LHY(8));
920 MaxDisplayable=MaxOnMenu;
921 mprintf ((0,"Hey, this is a scroll box!\n"));
934 for (i=0; i<nitems; i++ ) {
936 if (item[i].right_offset > right_offset )
937 right_offset = item[i].right_offset;
939 if (right_offset > 0 )
942 //gr_get_string_size("",&string_width,&string_height,&average_width );
949 twidth = ( tw - w )/2;
954 { right_offset=0; twidth=0;}
956 mprintf(( 0, "Right offset = %d\n", right_offset ));
959 // Find min point of menu border
960 // x = (grd_curscreen->sc_w-w)/2;
961 // y = (grd_curscreen->sc_h-h)/2;
963 w += MenuHires?60:30;
964 h += MenuHires?60:30;
966 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
967 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
969 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
970 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
975 if ( filename != NULL ) {
976 nm_draw_background1( filename );
977 gr_palette_load(gr_palette);
980 // Save the background of the display
981 // Win95 must refer to the screen as a dd_grs_canvas, so...
982 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
983 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
985 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
986 gr_set_current_canvas(bg.menu_canvas) );
988 if ( filename == NULL ) {
989 // Save the background under the menu...
995 #if defined(POLY_ACC)
996 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
998 bg.saved = gr_create_bitmap( w, h );
1000 Assert( bg.saved != NULL );
1002 WIN (DDGRLOCK(dd_grd_curcanv));
1003 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1004 WIN (DDGRUNLOCK(dd_grd_curcanv));
1006 WINDOS ( dd_gr_set_current_canvas(NULL),
1007 gr_set_current_canvas( NULL )
1010 nm_draw_background(x,y,x+w-1,y+h-1);
1012 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1013 gr_set_current_canvas( bg.menu_canvas )
1016 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1020 #if defined(POLY_ACC)
1021 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1023 bg.background = gr_create_bitmap( w, h );
1025 Assert( bg.background != NULL );
1027 WIN (DDGRLOCK(dd_grd_curcanv));
1028 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1029 WIN (DDGRUNLOCK(dd_grd_curcanv));
1032 // ty = 15 + (yborder/4);
1034 ty = MenuHires?30:15;
1037 grd_curcanv->cv_font = TITLE_FONT;
1038 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1039 gr_get_string_size(title,&string_width,&string_height,&average_width );
1042 WIN (DDGRLOCK(dd_grd_curcanv));
1043 gr_printf( 0x8000, ty, title );
1044 WIN (DDGRUNLOCK(dd_grd_curcanv));
1049 grd_curcanv->cv_font = SUBTITLE_FONT;
1050 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1051 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1054 WIN (DDGRLOCK(dd_grd_curcanv));
1055 gr_printf( 0x8000, ty, subtitle );
1056 WIN (DDGRUNLOCK(dd_grd_curcanv));
1061 grd_curcanv->cv_font = SMALL_FONT;
1063 grd_curcanv->cv_font = NORMAL_FONT;
1065 // Update all item's x & y values.
1066 for (i=0; i<nitems; i++ ) {
1067 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1068 item[i].y += (MenuHires?30:15);
1069 if ( item[i].type==NM_TYPE_RADIO ) {
1070 fm = -1; // find first marked one
1071 for ( j=0; j<nitems; j++ ) {
1072 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1073 if (fm==-1 && item[j].value)
1085 old_keyd_repeat = keyd_repeat;
1091 if (citem < 0 ) citem = 0;
1092 if (citem > nitems-1 ) citem = nitems-1;
1095 #if defined(WINDOWS) || defined(MACINTOSH)
1099 while ( item[choice].type==NM_TYPE_TEXT ) {
1101 if (choice >= nitems ) {
1104 if (choice == citem ) {
1115 // Clear mouse, joystick to clear button presses.
1116 game_flush_inputs();
1118 #if defined(WINDOWS) || defined(MACINTOSH)
1119 mouse_state = omouse_state = 0;
1120 if (filename == NULL && !MenuReordering) {
1121 draw_close_box(0,0);
1127 if (!MenuReordering) {
1129 SetCursor (LoadCursor(NULL,IDC_ARROW));
1134 if (!joydefs_calibrating)
1138 mprintf ((0,"Set to true!\n"));
1144 DoMessageStuff(&msg);
1146 if (_RedrawScreen) {
1147 _RedrawScreen = FALSE;
1150 gr_free_bitmap(bg.saved);
1151 d_free( bg.background );
1154 gr_free_bitmap(bg.background);
1156 dd_gr_free_sub_canvas( bg.menu_canvas );
1157 grd_curcanv->cv_font = save_font;
1158 dd_grd_curcanv = save_canvas;
1160 goto RePaintNewmenu4;
1169 omouse_state = mouse_state;
1170 mouse_state = mouse_button_state(0);
1171 if (!joydefs_calibrating)
1172 show_cursor(); // possibly hidden
1176 omouse_state = mouse_state;
1177 if (!MenuReordering)
1178 mouse_state = mouse_button_state(0);
1179 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1182 //see if redbook song needs to be restarted
1183 songs_check_redbook_repeat();
1190 (*subfunction)(nitems,item,&k,choice);
1193 if (!time_stopped) {
1194 // Save current menu box
1195 if (multi_menu_poll() == -1)
1201 dont_restore = (k == -3); //-3 means don't restore
1207 if (check_button_press())
1211 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1214 old_choice = choice;
1220 if (SurfingNet && !already_showing_info)
1222 show_extra_netgame_info(choice-2);
1224 if (SurfingNet && already_showing_info)
1231 if (SurfingNet && !already_showing_info)
1233 network_request_player_names(choice-2);
1235 if (SurfingNet && already_showing_info)
1250 case KEY_TAB + KEY_SHIFTED:
1253 if (all_text) break;
1260 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1262 if (choice<TopChoice)
1263 { choice=TopChoice; break; }
1265 if (choice<ScrollOffset)
1267 for (i=0;i<nitems;i++)
1270 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1275 if (choice >= nitems ) choice=0;
1276 if (choice < 0 ) choice=nitems-1;
1278 } while ( item[choice].type==NM_TYPE_TEXT );
1279 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1280 item[choice].value = -1;
1281 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1282 item[old_choice].group=0;
1283 strcpy(item[old_choice].text, item[old_choice].saved_text );
1284 item[old_choice].value = -1;
1287 item[old_choice].redraw = 1;
1288 item[choice].redraw=1;
1293 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1294 if (all_text) break;
1301 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1304 { choice--; break; }
1306 if (choice>=MaxOnMenu+ScrollOffset)
1308 for (i=0;i<nitems;i++)
1311 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1316 if (choice < 0 ) choice=nitems-1;
1317 if (choice >= nitems ) choice=0;
1320 } while ( item[choice].type==NM_TYPE_TEXT );
1322 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1323 item[choice].value = -1;
1324 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1325 item[old_choice].group=0;
1326 strcpy(item[old_choice].text, item[old_choice].saved_text );
1327 item[old_choice].value = -1;
1330 item[old_choice].redraw=1;
1331 item[choice].redraw=1;
1334 if ( choice > -1 ) {
1335 switch( item[choice].type ) {
1338 case NM_TYPE_INPUT_MENU:
1341 if ( item[choice].value )
1342 item[choice].value = 0;
1344 item[choice].value = 1;
1345 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1348 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1350 mprintf ((0,"Special redraw!\n"));
1355 item[choice].redraw=1;
1358 for (i=0; i<nitems; i++ ) {
1359 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1364 item[choice].value = 1;
1365 item[choice].redraw = 1;
1371 case KEY_SHIFTED+KEY_UP:
1372 if (MenuReordering && choice!=TopChoice)
1374 Temp=item[choice].text;
1375 TempVal=item[choice].value;
1376 item[choice].text=item[choice-1].text;
1377 item[choice].value=item[choice-1].value;
1378 item[choice-1].text=Temp;
1379 item[choice-1].value=TempVal;
1380 item[choice].redraw=1;
1381 item[choice-1].redraw=1;
1385 case KEY_SHIFTED+KEY_DOWN:
1386 if (MenuReordering && choice!=(nitems-1))
1388 Temp=item[choice].text;
1389 TempVal=item[choice].value;
1390 item[choice].text=item[choice+1].text;
1391 item[choice].value=item[choice+1].value;
1392 item[choice+1].text=Temp;
1393 item[choice+1].value=TempVal;
1394 item[choice].redraw=1;
1395 item[choice+1].redraw=1;
1402 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1403 item[choice].group = 1;
1404 item[choice].redraw = 1;
1405 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1406 item[choice].text[0] = 0;
1407 item[choice].value = -1;
1409 strip_end_whitespace(item[choice].text);
1416 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1417 item[choice].group=0;
1418 strcpy(item[choice].text, item[choice].saved_text );
1419 item[choice].redraw=1;
1420 item[choice].value = -1;
1427 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1428 case KEY_PRINT_SCREEN:
1430 save_screen_shot(0);
1431 PA_DFX (pa_set_frontbuffer_current());
1432 PA_DFX (pa_set_front_to_read());
1433 for (i=0;i<nitems;i++)
1442 case KEY_COMMAND+KEY_RIGHT:
1443 songs_goto_next_song();
1445 case KEY_COMMAND+KEY_LEFT:
1446 songs_goto_prev_song();
1448 case KEY_COMMAND+KEY_UP:
1449 songs_play_level_song(1);
1451 case KEY_COMMAND+KEY_DOWN:
1452 songs_stop_redbook();
1455 case KEY_COMMAND+KEY_M:
1457 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1458 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1461 key_close(); // no processing of keys with keyboard handler.. jeez
1464 show_boxed_message ("Mounting CD\nESC to quit");
1465 RBAMountDisk(); // OS has totaly control of the CD.
1466 if (Function_mode == FMODE_MENU)
1467 songs_play_song(SONG_TITLE,1);
1468 else if (Function_mode == FMODE_GAME)
1469 songs_play_level_song( Current_level_num );
1470 clear_boxed_message();
1479 case KEY_COMMAND+KEY_E:
1480 songs_stop_redbook();
1482 k = -1; // force key not to register
1485 case KEY_COMMAND+KEY_Q: {
1486 extern void macintosh_quit();
1488 if ( !(Game_mode & GM_MULTI) )
1490 if (!joydefs_calibrating)
1492 k = -1; // force key not to register
1499 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1506 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1508 if ( !done && mouse_state && !omouse_state && !all_text ) {
1509 mouse_get_pos(&mx, &my);
1510 for (i=0; i<nitems; i++ ) {
1511 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1512 x2 = x1 + item[i].w;
1513 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1514 y2 = y1 + item[i].h;
1515 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1516 if (i+ScrollOffset != choice) {
1517 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1520 choice = i + ScrollOffset;
1522 switch( item[choice].type ) {
1524 if ( item[choice].value )
1525 item[choice].value = 0;
1527 item[choice].value = 1;
1528 item[choice].redraw=1;
1535 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1537 mprintf ((0,"Special redraw!\n"));
1544 for (i=0; i<nitems; i++ ) {
1545 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1550 item[choice].value = 1;
1551 item[choice].redraw = 1;
1554 item[old_choice].redraw=1;
1560 if (mouse_state && all_text)
1563 if ( !done && mouse_state && !all_text ) {
1564 mouse_get_pos(&mx, &my);
1566 // check possible scrollbar stuff first
1568 int arrow_width, arrow_height, aw;
1570 if (ScrollOffset != 0) {
1571 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1572 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1573 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1574 x1 = x1 - arrow_width;
1575 y2 = y1 + arrow_height;
1576 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1579 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1581 if (choice<ScrollOffset)
1583 for (i=0;i<nitems;i++)
1586 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1590 if (ScrollOffset+MaxDisplayable<nitems) {
1591 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1592 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1593 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1594 x1 = x1 - arrow_width;
1595 y2 = y1 + arrow_height;
1596 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1599 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1601 if (choice>=MaxOnMenu+ScrollOffset)
1603 for (i=0;i<nitems;i++)
1606 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1612 for (i=0; i<nitems; i++ ) {
1613 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1614 x2 = x1 + item[i].w;
1615 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1616 y2 = y1 + item[i].h;
1617 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1618 if (i+ScrollOffset != choice) {
1619 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1622 choice = i + ScrollOffset;
1624 if ( item[choice].type == NM_TYPE_SLIDER ) {
1625 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1626 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1628 strcpy(slider_text, item[choice].saved_text);
1629 p = strchr(slider_text, '\t');
1635 gr_get_string_size(s1, &slider_width, &height, &aw);
1636 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1637 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1638 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1640 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1641 x2 = x1 + slider_width + sright_width;
1642 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1643 item[choice].value = item[choice].min_value;
1644 item[choice].redraw = 2;
1645 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1646 item[choice].value = item[choice].max_value;
1647 item[choice].redraw = 2;
1648 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1649 int num_values, value_width, new_value;
1651 num_values = item[choice].max_value - item[choice].min_value + 1;
1652 value_width = (slider_width - sleft_width - sright_width) / num_values;
1653 new_value = (mx - x1 - sleft_width) / value_width;
1654 if ( item[choice].value != new_value ) {
1655 item[choice].value = new_value;
1656 item[choice].redraw = 2;
1662 if (choice == old_choice)
1664 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1665 item[choice].value = -1;
1666 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1667 item[old_choice].group=0;
1668 strcpy(item[old_choice].text, item[old_choice].saved_text );
1669 item[old_choice].value = -1;
1672 item[old_choice].redraw = 1;
1673 item[choice].redraw=1;
1679 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1680 mouse_get_pos(&mx, &my);
1681 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1682 x2 = x1 + item[choice].w;
1683 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1684 y2 = y1 + item[choice].h;
1685 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1686 if (Hack_DblClick_MenuMode) {
1687 if (dblclick_flag) done = 1;
1688 else dblclick_flag = 1;
1694 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1695 item[choice].group = 1;
1696 item[choice].redraw = 1;
1697 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1698 item[choice].text[0] = 0;
1699 item[choice].value = -1;
1701 strip_end_whitespace(item[choice].text);
1705 if ( !done && !mouse_state && omouse_state && close_box ) {
1706 mouse_get_pos(&mx, &my);
1707 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1708 x2 = x1 + CLOSE_SIZE;
1709 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1710 y2 = y1 + CLOSE_SIZE;
1711 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1717 // HACK! Don't redraw loadgame preview
1718 if (RestoringMenu) item[0].redraw = 0;
1719 #endif // ifdef MACINTOSH
1721 if ( choice > -1 ) {
1724 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1725 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1726 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1727 if (item[choice].value > 0)
1728 item[choice].value--;
1729 item[choice].text[item[choice].value] = 0;
1730 item[choice].redraw = 1;
1732 ascii = key_to_ascii(k);
1733 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1737 if (item[choice].value==-1) {
1738 item[choice].value = 0;
1741 allowed = char_allowed(ascii);
1743 if (!allowed && ascii==' ' && char_allowed('_')) {
1749 item[choice].text[item[choice].value++] = ascii;
1750 item[choice].text[item[choice].value] = 0;
1751 item[choice].redraw=1;
1755 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1756 ascii = key_to_ascii(k);
1758 int choice1 = choice;
1759 ascii = toupper(ascii);
1763 if (choice1 >= nitems ) choice1=0;
1764 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1765 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1766 (item[choice1].type==NM_TYPE_CHECK) ||
1767 (item[choice1].type==NM_TYPE_RADIO) ||
1768 (item[choice1].type==NM_TYPE_NUMBER) ||
1769 (item[choice1].type==NM_TYPE_SLIDER) )
1770 && (ascii==toupper(ch)) ) {
1774 item[old_choice].redraw=1;
1775 item[choice].redraw=1;
1777 } while (choice1 != choice );
1781 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1782 int ov=item[choice].value;
1787 case KEY_MINUS+KEY_SHIFTED:
1789 item[choice].value -= 1;
1794 case KEY_EQUAL+KEY_SHIFTED:
1796 item[choice].value++;
1801 item[choice].value += 10;
1806 item[choice].value -= 10;
1809 if (ov!=item[choice].value)
1810 item[choice].redraw=1;
1815 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1816 gr_set_current_canvas(bg.menu_canvas));
1818 // Redraw everything...
1819 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1821 if (item[i].redraw) // warning! ugly hack below
1823 item[i].y-=((string_height+1)*ScrollOffset);
1826 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1828 MAC(if (!joydefs_calibrating) show_cursor());
1829 WIN(if (!MenuReordering) ShowCursorW());
1830 item[i].y+=((string_height+1)*ScrollOffset);
1832 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1833 update_cursor( &item[i]);
1839 //grd_curcanv->cv_font = NORMAL_FONT;
1841 if (LastScrollCheck!=ScrollOffset)
1843 LastScrollCheck=ScrollOffset;
1844 grd_curcanv->cv_font = SELECTED_FONT;
1846 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1847 sx=item[ScrollOffset].x-(MenuHires?24:12);
1850 if (ScrollOffset!=0)
1851 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1853 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1855 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1856 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1858 if (ScrollOffset+MaxDisplayable<nitems)
1859 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1861 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1867 if ( !dont_restore && gr_palette_faded_out ) {
1868 gr_palette_fade_in( gr_palette, 32, 0 );
1875 // Restore everything...
1877 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1878 gr_set_current_canvas(bg.menu_canvas));
1880 if ( filename == NULL ) {
1881 // Save the background under the menu...
1882 WIN (DDGRLOCK(dd_grd_curcanv));
1883 gr_bitmap(0, 0, bg.saved);
1884 WIN (DDGRUNLOCK(dd_grd_curcanv));
1885 gr_free_bitmap(bg.saved);
1886 d_free( bg.background );
1888 if (!dont_restore) //info passed back from subfunction
1890 WIN (DDGRLOCK(dd_grd_curcanv));
1891 gr_bitmap(0, 0, bg.background);
1892 WIN (DDGRUNLOCK(dd_grd_curcanv));
1894 gr_free_bitmap(bg.background);
1897 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1898 gr_free_sub_canvas( bg.menu_canvas ) );
1900 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1901 grd_curcanv->cv_font = save_font;
1902 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1903 keyd_repeat = old_keyd_repeat;
1905 game_flush_inputs();
1916 if ( sound_stopped )
1917 digi_resume_digi_sounds();
1919 WIN(mouse_set_mode(1)); //re-enable centering mode
1926 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1932 char nm_text[MESSAGEBOX_TEXT_SIZE];
1933 newmenu_item nm_message_items[5];
1935 va_start(args, nchoices );
1937 Assert( nchoices <= 5 );
1939 for (i=0; i<nchoices; i++ ) {
1940 s = va_arg( args, char * );
1941 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1943 format = va_arg( args, char * );
1944 strcpy( nm_text, "" );
1945 vsprintf(nm_text,format,args);
1948 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1950 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1953 int nm_messagebox( char *title, int nchoices, ... )
1959 char nm_text[MESSAGEBOX_TEXT_SIZE];
1960 newmenu_item nm_message_items[5];
1962 va_start(args, nchoices );
1964 Assert( nchoices <= 5 );
1966 for (i=0; i<nchoices; i++ ) {
1967 s = va_arg( args, char * );
1968 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1970 format = va_arg( args, char * );
1971 strcpy( nm_text, "" );
1972 vsprintf(nm_text,format,args);
1975 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1977 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1983 void newmenu_file_sort( int n, char *list )
1990 for (i=incr; i<n; i++ ) {
1993 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1994 memcpy( t, &list[j*14], FILENAME_LEN );
1995 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1996 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2007 void delete_player_saved_games(char * name)
2012 for (i=0;i<10; i++) {
2014 sprintf( filename, "%s.sg%d", name, i );
2016 sprintf( filename, ":Players:%s.sg%d", name, i );
2022 #define MAX_FILES 300
2024 int MakeNewPlayerFile(int allow_abort);
2026 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2029 FILEFINDSTRUCT find;
2030 int NumFiles=0, key,done, citem, ocitem;
2031 char * filenames = NULL;
2032 int NumFiles_displayed = 8;
2033 int first_item = -1, ofirst_item;
2034 int old_keyd_repeat = keyd_repeat;
2037 int demos_deleted=0;
2038 int initialized = 0;
2040 int w_x, w_y, w_w, w_h, title_height;
2041 int box_x, box_y, box_w, box_h;
2042 bkg bg; // background under listbox
2043 #if defined(MACINTOSH) || defined(WINDOWS)
2044 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2045 int mouse2_state, omouse2_state;
2046 int dblclick_flag=0;
2048 int show_up_arrow=0,show_down_arrow=0;
2050 WIN(int win_redraw=0);
2052 w_x=w_y=w_w=w_h=title_height=0;
2053 box_x=box_y=box_w=box_h=0;
2055 filenames = d_malloc( MAX_FILES * 14 );
2056 if (filenames==NULL) return 0;
2061 WIN(mouse_set_mode(0)); //disable centering mode
2063 if (strstr( filespec, "*.plr" ))
2065 else if (strstr( filespec, "*.dem" ))
2072 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2074 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2079 if( !FileFindFirst( filespec, &find ) ) {
2081 if (NumFiles<MAX_FILES) {
2082 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2083 if ( player_mode ) {
2085 p = strchr(&filenames[NumFiles*14],'.');
2092 } while( !FileFindNext( &find ) );
2096 if ( (NumFiles < 1) && demos_deleted ) {
2100 if ( (NumFiles < 1) && demo_mode ) {
2101 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2107 if ( (NumFiles < 2) && player_mode ) {
2109 goto ExitFileMenuEarly;
2116 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2123 // set_screen_mode(SCREEN_MENU);
2129 dd_gr_set_current_canvas(NULL);
2131 gr_set_current_canvas(NULL);
2134 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2136 grd_curcanv->cv_font = SUBTITLE_FONT;
2138 WIN(DDGRUNLOCK(dd_grd_curcanv));
2143 for (i=0; i<NumFiles; i++ ) {
2145 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2151 gr_get_string_size( title, &w, &h, &aw );
2154 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2158 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2160 w_w += (grd_curfont->ft_w * 4);
2161 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2163 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2164 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2166 w_x = (grd_curcanv->cv_w-w_w)/2;
2167 w_y = (grd_curcanv->cv_h-w_h)/2;
2169 if ( w_x < 0 ) w_x = 0;
2170 if ( w_y < 0 ) w_y = 0;
2172 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2173 box_y = w_y + title_height;
2175 // save the screen behind the menu.
2179 #if !defined(WINDOWS)
2180 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2181 bg.background = &VR_offscreen_buffer->cv_bitmap;
2184 #if defined(POLY_ACC)
2185 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2187 bg.background = gr_create_bitmap( w_w, w_h );
2190 Assert( bg.background != NULL );
2193 WIN(DDGRLOCK(dd_grd_curcanv));
2194 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2195 WIN(DDGRUNLOCK(dd_grd_curcanv));
2199 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2200 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2201 dd_VR_offscreen_buffer, 0, 0,
2202 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2203 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2207 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2209 WIN(DDGRLOCK(dd_grd_curcanv))
2211 gr_string( 0x8000, w_y+10, title );
2213 WIN(DDGRUNLOCK(dd_grd_curcanv));
2220 if ( !player_mode ) {
2221 newmenu_file_sort( NumFiles, filenames );
2223 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2224 newmenu_file_sort( NumFiles, filenames );
2226 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2228 for ( i=0; i<NumFiles; i++ ) {
2229 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2230 #if defined(WINDOWS) || defined(MACINTOSH)
2238 #if defined(MACINTOSH) || defined(WINDOWS)
2239 mouse_state = omouse_state = 0;
2240 mouse2_state = omouse2_state = 0;
2241 draw_close_box(w_x,w_y);
2253 DoMessageStuff(&msg);
2255 if (_RedrawScreen) {
2256 _RedrawScreen = FALSE;
2258 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2259 gr_free_bitmap(bg.background);
2262 goto RePaintNewmenuFile;
2269 ofirst_item = first_item;
2272 #if defined(MACINTOSH) || defined(WINDOWS)
2273 omouse_state = mouse_state;
2274 omouse2_state = mouse2_state;
2275 mouse_state = mouse_button_state(0);
2276 mouse2_state = mouse_button_state(1);
2279 //see if redbook song needs to be restarted
2280 songs_check_redbook_repeat();
2283 if (!mouse2_state && omouse2_state)
2284 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2287 //NOTE LINK TO ABOVE ELSE
2293 else if (simukey==1)
2299 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2300 case KEY_PRINT_SCREEN:
2302 save_screen_shot(0);
2303 PA_DFX (pa_set_frontbuffer_current());
2304 PA_DFX (pa_set_front_to_read());
2310 case KEY_CTRLED+KEY_D:
2311 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2315 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2319 mouse_set_mode(1); //re-enable centering mode
2323 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2325 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2328 mouse_set_mode(0); //disenable centering mode
2334 char name[_MAX_PATH],dir[_MAX_DIR];
2336 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2340 _splitpath(filespec,name,dir,NULL,NULL);
2342 strcat(name,&filenames[citem*14]);
2349 if ( !strncmp(name, ".\\", 2) )
2350 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2351 name[i] = name[i+1];
2352 while ( (p = strchr(name, '\\')) )
2357 ret = unlink( name );
2361 if ((!ret) && player_mode) {
2362 delete_player_saved_games( &filenames[citem*14] );
2367 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2369 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2370 } else if (demo_mode)
2395 citem += NumFiles_displayed;
2399 citem -= NumFiles_displayed;
2402 if (allow_abort_flag) {
2413 case KEY_COMMAND+KEY_Q: {
2414 extern void macintosh_quit();
2416 if ( !(Game_mode & GM_MULTI) )
2427 int ascii = key_to_ascii(key);
2428 if ( ascii < 255 ) {
2431 if (cc1 < 0 ) cc1 = 0;
2432 if (cc1 >= NumFiles ) cc1 = 0;
2434 if ( cc < 0 ) cc = 0;
2435 if ( cc >= NumFiles ) cc = 0;
2436 if ( citem == cc ) break;
2438 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2453 if (citem>=NumFiles)
2456 if (citem< first_item)
2459 if (citem>=( first_item+NumFiles_displayed))
2461 first_item = citem-NumFiles_displayed+1;
2465 if (NumFiles>first_item+NumFiles_displayed)
2476 if (NumFiles <= NumFiles_displayed )
2479 if (first_item>NumFiles-NumFiles_displayed)
2481 first_item = NumFiles-NumFiles_displayed;
2484 if (first_item < 0 ) first_item = 0;
2486 #if defined(MACINTOSH) || defined(WINDOWS)
2488 if (mouse_state || mouse2_state) {
2491 mouse_get_pos(&mx, &my);
2492 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2493 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2495 x2 = box_x + box_w - 1;
2496 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2498 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2499 if (i == citem && !mouse2_state) {
2509 if (!mouse_state && omouse_state) {
2512 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2513 mouse_get_pos(&mx, &my);
2515 x2 = box_x + box_w - 1;
2516 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2518 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2519 if (dblclick_flag) done = 1;
2520 else dblclick_flag = 1;
2524 if ( !mouse_state && omouse_state ) {
2525 mouse_get_pos(&mx, &my);
2526 x1 = w_x + CLOSE_X + 2;
2527 x2 = x1 + CLOSE_SIZE - 2;
2528 y1 = w_y + CLOSE_Y + 2;
2529 y2 = y1 + CLOSE_SIZE - 2;
2530 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2539 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2541 y1 = box_y+box_h-LHY(7);
2543 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2550 WIN(DDGRLOCK(dd_grd_curcanv));
2551 gr_setcolor( BM_XRGB(2,2,2));
2552 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2553 gr_setcolor( BM_XRGB( 0,0,0) );
2556 if (ofirst_item != first_item || win_redraw) {
2559 if (ofirst_item != first_item) {
2563 gr_setcolor( BM_XRGB( 0,0,0) );
2564 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2566 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2568 if ( i >= NumFiles ) {
2570 gr_setcolor( BM_XRGB(5,5,5));
2571 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2572 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2574 gr_setcolor( BM_XRGB(2,2,2));
2575 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2577 gr_setcolor( BM_XRGB(0,0,0));
2578 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2582 grd_curcanv->cv_font = SELECTED_FONT;
2584 grd_curcanv->cv_font = NORMAL_FONT;
2585 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2587 gr_setcolor( BM_XRGB(5,5,5));
2588 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2589 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2591 gr_setcolor( BM_XRGB(2,2,2));
2592 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2593 gr_setcolor( BM_XRGB(0,0,0));
2595 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2596 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2601 } else if ( citem != ocitem ) {
2607 if ( (i>=0) && (i<NumFiles) ) {
2608 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2610 grd_curcanv->cv_font = SELECTED_FONT;
2612 grd_curcanv->cv_font = NORMAL_FONT;
2613 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2614 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2615 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2618 if ( (i>=0) && (i<NumFiles) ) {
2619 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2621 grd_curcanv->cv_font = SELECTED_FONT;
2623 grd_curcanv->cv_font = NORMAL_FONT;
2624 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2625 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2626 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2633 grd_curcanv->cv_font = NORMAL_FONT;
2635 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2639 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2643 if (show_down_arrow)
2644 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2648 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2656 WIN(DDGRUNLOCK(dd_grd_curcanv));
2662 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2669 keyd_repeat = old_keyd_repeat;
2671 if ( initialized ) {
2672 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2674 WIN (DDGRLOCK(dd_grd_curcanv));
2675 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2676 WIN (DDGRUNLOCK(dd_grd_curcanv));
2678 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2679 gr_free_bitmap(bg.background);
2682 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2683 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2685 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2686 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2696 WIN(mouse_set_mode(1)); //re-enable centering mode
2704 // Example listbox callback function...
2705 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2709 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2710 // if ( *nitems > 1 ) {
2711 // unlink( items[*citem] ); // Delete the file
2712 // for (i=*citem; i<*nitems-1; i++ ) {
2713 // items[i] = items[i+1];
2715 // *nitems = *nitems - 1;
2716 // d_free( items[*nitems] );
2717 // items[*nitems] = NULL;
2718 // return 1; // redraw;
2725 #define LB_ITEMS_ON_SCREEN 8
2727 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2729 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2732 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 ) )
2735 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2736 int old_keyd_repeat = keyd_repeat;
2737 int width, height, wx, wy, title_height, border_size;
2738 int total_width,total_height;
2740 #if defined(MACINTOSH) || defined(WINDOWS)
2741 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2742 int close_x,close_y;
2743 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2745 WIN(int win_redraw=0);
2749 PA_DFX (pa_set_frontbuffer_current());
2750 PA_DFX (pa_set_front_to_read());
2751 WIN(mouse_set_mode(0)); //disable centering mode
2753 // set_screen_mode(SCREEN_MENU);
2757 RePaintNewmenuListbox:
2759 dd_gr_set_current_canvas(NULL);
2761 gr_set_current_canvas(NULL);
2764 grd_curcanv->cv_font = SUBTITLE_FONT;
2767 for (i=0; i<nitems; i++ ) {
2769 gr_get_string_size( items[i], &w, &h, &aw );
2773 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2777 gr_get_string_size( title, &w, &h, &aw );
2780 title_height = h + 5;
2783 border_size = grd_curfont->ft_w;
2784 WIN (border_size=grd_curfont->ft_w*2);
2786 width += (grd_curfont->ft_w);
2787 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2788 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2790 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2791 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2792 if ( wy < title_height )
2795 total_width = width+2*border_size;
2796 total_height = height+2*border_size+title_height;
2800 #if !defined(WINDOWS)
2801 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2802 bg.background = &VR_offscreen_buffer->cv_bitmap;
2805 //bg.background = gr_create_bitmap( width, (height + title_height) );
2806 #if defined(POLY_ACC)
2807 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2809 bg.background = gr_create_bitmap(total_width,total_height);
2811 Assert( bg.background != NULL );
2813 WIN (DDGRLOCK(dd_grd_curcanv));
2814 //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 );
2815 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2816 WIN (DDGRUNLOCK(dd_grd_curcanv));
2820 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2821 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2822 dd_VR_offscreen_buffer, 0, 0,
2823 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2824 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2828 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2830 WIN(DDGRLOCK(dd_grd_curcanv));
2831 gr_string( 0x8000, wy - title_height, title );
2832 WIN(DDGRUNLOCK(dd_grd_curcanv));
2837 citem = default_item;
2838 if ( citem < 0 ) citem = 0;
2839 if ( citem >= nitems ) citem = 0;
2843 #if defined(MACINTOSH) || defined(WINDOWS)
2844 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2845 close_x = wx-border_size;
2846 close_y = wy-title_height-border_size;
2847 draw_close_box(close_x,close_y);
2859 DoMessageStuff(&msg);
2861 if (_RedrawScreen) {
2862 _RedrawScreen = FALSE;
2864 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2865 gr_free_bitmap(bg.background);
2867 goto RePaintNewmenuListbox;
2874 ofirst_item = first_item;
2875 #if defined(MACINTOSH) || defined(WINDOWS)
2876 omouse_state = mouse_state;
2877 mouse_state = mouse_button_state(0);
2879 //see if redbook song needs to be restarted
2880 songs_check_redbook_repeat();
2884 if ( listbox_callback )
2885 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2906 else if (simukey==1)
2912 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2913 case KEY_PRINT_SCREEN:
2915 save_screen_shot(0);
2916 PA_DFX (pa_set_frontbuffer_current());
2917 PA_DFX (pa_set_front_to_read());
2940 citem += LB_ITEMS_ON_SCREEN;
2944 citem -= LB_ITEMS_ON_SCREEN;
2947 if (allow_abort_flag) {
2958 case KEY_COMMAND+KEY_Q: {
2959 extern void macintosh_quit();
2961 if ( !(Game_mode & GM_MULTI) )
2971 int ascii = key_to_ascii(key);
2972 if ( ascii < 255 ) {
2975 if (cc1 < 0 ) cc1 = 0;
2976 if (cc1 >= nitems ) cc1 = 0;
2978 if ( cc < 0 ) cc = 0;
2979 if ( cc >= nitems ) cc = 0;
2980 if ( citem == cc ) break;
2982 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2999 if (citem< first_item)
3002 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
3003 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3005 if (nitems <= LB_ITEMS_ON_SCREEN )
3008 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3009 first_item = nitems-LB_ITEMS_ON_SCREEN;
3010 if (first_item < 0 ) first_item = 0;
3013 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3024 #if defined(MACINTOSH) || defined(WINDOWS)
3029 mouse_get_pos(&mx, &my);
3030 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3033 gr_get_string_size(items[i], &w, &h, &aw );
3036 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3038 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3050 //no double-click stuff for listbox
3051 //@@if (!mouse_state && omouse_state) {
3054 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3055 //@@ mouse_get_pos(&mx, &my);
3057 //@@ x2 = wx + width;
3058 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3060 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3061 //@@ if (dblclick_flag) done = 1;
3065 //check for close box clicked
3066 if ( !mouse_state && omouse_state ) {
3067 mouse_get_pos(&mx, &my);
3068 x1 = close_x + CLOSE_X + 2;
3069 x2 = x1 + CLOSE_SIZE - 2;
3070 y1 = close_y + CLOSE_Y + 2;
3071 y2 = y1 + CLOSE_SIZE - 2;
3072 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3082 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3084 y1 = total_height-LHY(7);
3086 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3094 if ( (ofirst_item != first_item) || redraw) {
3097 WIN(DDGRLOCK(dd_grd_curcanv));
3099 gr_setcolor( BM_XRGB( 0,0,0) );
3100 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3102 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3103 if ( i >= nitems ) {
3104 gr_setcolor( BM_XRGB(0,0,0));
3105 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3108 grd_curcanv->cv_font = SELECTED_FONT;
3110 grd_curcanv->cv_font = NORMAL_FONT;
3111 gr_get_string_size(items[i], &w, &h, &aw );
3112 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3113 gr_string( wx+5, y, items[i] );
3118 // If Win95 port, draw up/down arrows on left side of menu
3120 grd_curcanv->cv_font = NORMAL_FONT;
3122 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3126 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3130 if (show_down_arrow)
3131 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3135 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3142 WIN(DDGRUNLOCK(dd_grd_curcanv));
3146 } else if ( citem != ocitem ) {
3152 WIN(DDGRLOCK(dd_grd_curcanv));
3155 if ( (i>=0) && (i<nitems) ) {
3156 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3158 grd_curcanv->cv_font = SELECTED_FONT;
3160 grd_curcanv->cv_font = NORMAL_FONT;
3161 gr_get_string_size(items[i], &w, &h, &aw );
3162 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3163 gr_string( wx+5, y, items[i] );
3167 if ( (i>=0) && (i<nitems) ) {
3168 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3170 grd_curcanv->cv_font = SELECTED_FONT;
3172 grd_curcanv->cv_font = NORMAL_FONT;
3173 gr_get_string_size( items[i], &w, &h, &aw );
3174 gr_rect( wx, y-1, wx+width-1, y+h );
3175 gr_string( wx+5, y, items[i] );
3177 WIN(DDGRUNLOCK(dd_grd_curcanv));
3187 keyd_repeat = old_keyd_repeat;
3189 WIN (DDGRLOCK(dd_grd_curcanv));
3190 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3191 WIN (DDGRUNLOCK(dd_grd_curcanv));
3193 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3194 gr_free_bitmap(bg.background);
3198 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3199 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3201 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3202 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3208 WIN(mouse_set_mode(1)); //re-enable centering mode
3213 int newmenu_filelist( char * title, char * filespec, char * filename )
3216 char * Filenames[MAX_FILES];
3217 char FilenameText[MAX_FILES][14];
3218 FILEFINDSTRUCT find;
3221 if( !FileFindFirst( filespec, &find ) ) {
3223 if (NumFiles<MAX_FILES) {
3224 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3225 Filenames[NumFiles] = FilenameText[NumFiles];
3230 } while( !FileFindNext( &find ) );
3234 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3236 strcpy( filename, Filenames[i] );
3243 extern netgame_info Active_games[];
3244 extern int NumActiveNetgames;
3246 void show_extra_netgame_info(int choice)
3252 if (choice>=NumActiveNetgames)
3257 m[i].text=(char *)&mtext[i];
3258 m[i].type=NM_TYPE_TEXT;
3261 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3262 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3263 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3264 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3266 already_showing_info=1;
3267 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3268 already_showing_info=0;
3273 /* Spiffy word wrap string formatting function */
3275 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3281 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3284 wordptr = strtok(tbuf, " ");
3285 if (!wordptr) return;
3291 col = col+strlen(wordptr)+1;
3292 if (col >=line_length) {
3294 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3297 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3299 wordptr = strtok(NULL, " ");