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.
15 * $Source: /cvs/cvsroot/d2x/main/newmenu.c,v $
18 * $Date: 2002-02-13 10:39:22 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
23 * Revision 1.7 2002/02/11 07:39:11 bradleyb
24 * added fixedfont menu functions
44 #include "pa_enabl.h" //$$POLY_ACC
91 #define MAXDISPLAYABLEITEMS 15
93 #define LHX(x) ((x)*(MenuHires?2:1))
94 #define LHY(y) ((y)*(MenuHires?2.4:1))
96 #define TITLE_FONT HUGE_FONT
97 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
98 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
99 #define SUBTITLE_FONT MEDIUM3_FONT
101 #define NORMAL_CHECK_BOX "
\81"
102 #define CHECKED_CHECK_BOX "
\82"
104 #define NORMAL_RADIO_BOX "
\7f"
105 #define CHECKED_RADIO_BOX "
\80"
106 #define CURSOR_STRING "_"
107 #define SLIDER_LEFT "
\83" // 131
108 #define SLIDER_RIGHT "
\84" // 132
109 #define SLIDER_MIDDLE "
\85" // 133
110 #define SLIDER_MARKER "
\86" // 134
111 #define UP_ARROW_MARKER "
\87" // 135
112 #define DOWN_ARROW_MARKER "
\88" // 136
114 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 );
115 void show_extra_netgame_info(int choice);
118 int Newmenu_first_time = 1;
119 //--unused-- int Newmenu_fade_in = 1;
122 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
123 grs_bitmap * saved; // The background under the menu.
124 grs_bitmap * background;
127 grs_bitmap nm_background,nm_background_save;
129 #define MESSAGEBOX_TEXT_SIZE 300 // How many characters in messagebox
130 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
132 extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
134 ubyte MenuReordering=0;
136 char Pauseable_menu=0;
137 char already_showing_info=0;
140 void newmenu_close() {
141 if ( nm_background.bm_data )
142 d_free(nm_background.bm_data);
144 if ( nm_background_save.bm_data )
145 d_free(nm_background_save.bm_data);
146 Newmenu_first_time = 1;
149 ubyte background_palette[768];
151 //should be called whenever the palette changes
152 void nm_remap_background()
154 if (!Newmenu_first_time) {
155 if (!nm_background.bm_data)
156 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
158 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
160 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
166 extern char last_palette_loaded[];
168 void nm_draw_background1(char * filename)
174 //@@//I think this only gets called to fill the whole screen
175 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
176 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
178 bmp = gr_create_bitmap(grd_curcanv->cv_bitmap.bm_w,grd_curcanv->cv_bitmap.bm_h);
180 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
181 Assert(pcx_error == PCX_ERROR_NONE);
183 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
186 { //remap stuff. this code is kindof a hack
188 //now, before we bring up the menu, we need to
189 //do some stuff to make sure the palette is ok. First, we need to
190 //get our current palette into the 2d's array, so the remapping will
191 //work. Second, we need to remap the fonts. Third, we need to fill
192 //in part of the fade tables so the darkening of the menu edges works
194 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
195 remap_fonts_and_menus(1);
199 WIN(DDGRLOCK(dd_grd_curcanv));
200 #if defined(POLY_ACC)
202 pa_update_clut(gr_palette, 0, 256, 0);
205 #if defined(POLY_ACC)
208 WIN(DDGRUNLOCK(dd_grd_curcanv));
212 strcpy(last_palette_loaded,""); //force palette load next time
217 #define MENU_BACKGROUND_BITMAP "scores.pcx"
220 #define MENU_BACKGROUND_BITMAP (MenuHires?"\x01scoresb.pcx":"\x01scores.pcx") //read only from hog file
222 #define MENU_BACKGROUND_BITMAP (MenuHires?"scoresb.pcx":"scores.pcx")
226 int Background_hires;
229 void nm_draw_background(int x1, int y1, int x2, int y2 )
233 if (Newmenu_first_time || MenuHires!=Background_hires) {
236 if (Newmenu_first_time) {
237 atexit( newmenu_close );
238 Newmenu_first_time = 0;
239 nm_background_save.bm_data=NULL;
242 if (nm_background_save.bm_data)
243 d_free(nm_background_save.bm_data);
244 if (nm_background.bm_data)
245 d_free(nm_background.bm_data);
248 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
249 Assert(pcx_error == PCX_ERROR_NONE);
251 nm_background = nm_background_save;
252 nm_background.bm_data=NULL;
253 nm_remap_background();
255 Background_hires = MenuHires;
258 if ( x1 < 0 ) x1 = 0;
259 if ( y1 < 0 ) y1 = 0;
264 if ( w > nm_background.bm_w ) w = nm_background.bm_w;
265 if ( h > nm_background.bm_h ) h = nm_background.bm_h;
270 WIN(DDGRLOCK(dd_grd_curcanv));
272 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
274 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
279 Gr_scanline_darkening_level = 2*7;
282 gr_setcolor( BM_XRGB(0,0,0) );
283 gr_urect( x2-5, y1+5, x2-5, y2-5 );
284 gr_urect( x2-4, y1+4, x2-4, y2-5 );
285 gr_urect( x2-3, y1+3, x2-3, y2-5 );
286 gr_urect( x2-2, y1+2, x2-2, y2-5 );
287 gr_urect( x2-1, y1+1, x2-1, y2-5 );
288 gr_urect( x2+0, y1+0, x2-0, y2-5 );
290 gr_urect( x1+5, y2-5, x2, y2-5 );
291 gr_urect( x1+4, y2-4, x2, y2-4 );
292 gr_urect( x1+3, y2-3, x2, y2-3 );
293 gr_urect( x1+2, y2-2, x2, y2-2 );
294 gr_urect( x1+1, y2-1, x2, y2-1 );
295 gr_urect( x1+0, y2, x2, y2-0 );
297 WIN(DDGRUNLOCK(dd_grd_curcanv));
299 Gr_scanline_darkening_level = GR_FADE_LEVELS;
302 void nm_restore_background( int x, int y, int w, int h )
309 if ( x1 < 0 ) x1 = 0;
310 if ( y1 < 0 ) y1 = 0;
312 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
313 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
318 WIN(DDGRLOCK(dd_grd_curcanv));
319 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
320 WIN(DDGRUNLOCK(dd_grd_curcanv));
323 // Draw a left justfied string
324 void nm_string( bkg * b, int w1,int x, int y, char * s)
326 int w,h,aw,tx=0,t=0,i;
327 char *p,*s1,measure[2];
328 int XTabs[]={15,87,124,162,228,253};
334 XTabs[i]=(LHX(XTabs[i]));
342 p = strchr( s, '\t' );
349 gr_get_string_size(s, &w, &h, &aw );
355 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
356 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
360 for (i=0;i<strlen(s);i++)
362 if (s[i]=='\t' && SurfingNet)
369 gr_get_string_size(measure,&tx,&h,&aw);
370 gr_string(x,y,measure);
374 else gr_string (x,y,s);
376 if (!SurfingNet && p && (w1>0) ) {
377 gr_get_string_size(s1, &w, &h, &aw );
379 gr_string( x+w1-w, y, s1 );
385 // Draw a slider and it's string
386 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
393 p = strchr( s, '\t' );
399 gr_get_string_size(s, &w, &h, &aw );
402 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
403 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
405 gr_string( x, y, s );
408 gr_get_string_size(s1, &w, &h, &aw );
411 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
413 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
415 gr_string( x+w1-w, y, s1 );
422 // Draw a left justfied string with black background.
423 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
426 gr_get_string_size(s, &w, &h, &aw );
430 WIN(DDGRLOCK(dd_grd_curcanv));
431 gr_setcolor( BM_XRGB(2,2,2) );
432 gr_rect( x-1, y-1, x-1, y+h-1 );
433 gr_rect( x-1, y-1, x+w1-1, y-1 );
436 gr_setcolor( BM_XRGB(5,5,5) );
437 gr_rect( x, y+h, x+w1, y+h);
438 gr_rect( x+w1, y-1, x+w1, y+h );
440 gr_setcolor( BM_XRGB(0,0,0) );
441 gr_rect( x, y, x+w1-1, y+h-1 );
443 gr_string( x+1, y+1, s );
444 WIN(DDGRUNLOCK(dd_grd_curcanv));
448 // Draw a right justfied string
449 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
452 gr_get_string_size(s, &w, &h, &aw );
457 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
460 WIN(DDGRLOCK(dd_grd_curcanv));
461 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
462 gr_string( x-w, y, s );
463 WIN(DDGRUNLOCK(dd_grd_curcanv));
468 //for text items, constantly redraw cursor (to achieve flash)
469 void update_cursor( newmenu_item *item)
472 fix time = timer_get_approx_seconds();
474 char * text = item->text;
476 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
479 gr_get_string_size(text, &w, &h, &aw );
480 if ( w > item->w-10 )
487 x = item->x+w; y = item->y;
489 WIN(DDGRLOCK(dd_grd_curcanv));
491 gr_string( x, y, CURSOR_STRING );
493 gr_setcolor( BM_XRGB(0,0,0) );
494 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
496 WIN(DDGRUNLOCK(dd_grd_curcanv));
499 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
504 gr_get_string_size(text, &w1, &h1, &aw );
513 nm_string_black( b, w, x, y, text );
516 gr_string( x+w1+1, y, CURSOR_STRING );
520 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
525 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
527 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
529 if (item->text[0]=='\t')
530 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
535 grd_curcanv->cv_font = SELECTED_FONT;
537 grd_curcanv->cv_font = NORMAL_FONT;
540 if (is_current && item->type == NM_TYPE_TEXT)
541 grd_curcanv->cv_font = NORMAL_FONT;
545 WIN(DDGRLOCK(dd_grd_curcanv));
546 switch( item->type ) {
548 // grd_curcanv->cv_font=TEXT_FONT;
549 // fall through on purpose
552 nm_string( b, item->w, item->x, item->y, item->text );
554 case NM_TYPE_SLIDER: {
556 if (item->value < item->min_value) item->value=item->min_value;
557 if (item->value > item->max_value) item->value=item->max_value;
558 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
559 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
560 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
562 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
564 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
566 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
569 case NM_TYPE_INPUT_MENU:
570 if ( item->group==0 ) {
571 nm_string( b, item->w, item->x, item->y, item->text );
573 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
577 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
580 nm_string( b, item->w, item->x, item->y, item->text );
582 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
584 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
587 nm_string( b, item->w, item->x, item->y, item->text );
589 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
591 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
593 case NM_TYPE_NUMBER: {
595 if (item->value < item->min_value) item->value=item->min_value;
596 if (item->value > item->max_value) item->value=item->max_value;
597 nm_string( b, item->w, item->x, item->y, item->text );
598 sprintf( text, "%d", item->value );
599 nm_rstring( b,item->right_offset,item->x, item->y, text );
603 WIN(DDGRUNLOCK(dd_grd_curcanv));
607 char *Newmenu_allowed_chars=NULL;
609 //returns true if char is allowed
610 int char_allowed(char c)
612 char *p = Newmenu_allowed_chars;
620 if (c>=p[0] && c<=p[1])
629 void strip_end_whitespace( char * text )
633 for (i=l-1; i>=0; i-- ) {
634 if ( isspace(text[i]) )
641 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
643 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
645 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
647 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
651 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
653 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
657 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 )
659 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
663 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 )
665 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
667 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 )
669 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
672 int newmenu_do_fixedfont( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int citem, char * filename, int width, int height){
673 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
674 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
675 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
678 //returns 1 if a control device button has been pressed
679 int check_button_press()
683 switch (Config_control_type) {
684 case CONTROL_JOYSTICK:
685 case CONTROL_FLIGHTSTICK_PRO:
686 case CONTROL_THRUSTMASTER_FCS:
687 case CONTROL_GRAVIS_GAMEPAD:
689 if (joy_get_button_down_cnt(i)>0) return 1;
692 case CONTROL_CYBERMAN:
693 #ifndef MACINTOSH // don't allow mouse to continue from menu
695 if (mouse_button_down_count(i)>0) return 1;
698 case CONTROL_WINJOYSTICK:
701 if (joy_get_button_down_cnt(i)>0) return 1;
704 case CONTROL_NONE: //keyboard only
706 if (key_checkch()) return 1;
711 Error("Bad control type (Config_control_type):%i",Config_control_type);
717 extern int network_request_player_names(int);
718 extern int RestoringMenu;
720 #if defined(WINDOWS) || defined(MACINTOSH)
721 ubyte Hack_DblClick_MenuMode=0;
724 MAC(extern ubyte joydefs_calibrating;)
728 #define CLOSE_SIZE 10
730 void draw_close_box(int x,int y)
732 WIN (DDGRLOCK(dd_grd_curcanv));
733 gr_setcolor( BM_XRGB(0, 0, 0) );
734 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
735 gr_setcolor( BM_XRGB(21, 21, 21) );
736 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
737 WIN (DDGRUNLOCK(dd_grd_curcanv));
740 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 )
742 int old_keyd_repeat, done;
743 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
744 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
745 grs_font * save_font;
746 int string_width, string_height, average_width;
749 int all_text=0; //set true if all text items
750 int sound_stopped=0,time_stopped=0;
751 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
754 int MaxOnMenu=MAXDISPLAYABLEITEMS;
755 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
756 #if defined(MACINTOSH) || defined(WINDOWS)
757 int mouse_state, omouse_state, dblclick_flag=0;
758 int mx=0, my=0, x1, x2, y1, y2;
762 EventRecord event; // looking for disk inserted events for CD mounts
765 PA_DFX (pa_set_frontbuffer_current());
766 PA_DFX (pa_set_front_to_read());
768 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
777 WIN(mouse_set_mode(0)); //disable centering mode
779 MaxDisplayable=nitems;
782 set_screen_mode(SCREEN_MENU);
786 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
787 digi_pause_digi_sounds();
791 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
804 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
806 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
808 save_font = grd_curcanv->cv_font;
813 grd_curcanv->cv_font = TITLE_FONT;
814 gr_get_string_size(title,&string_width,&string_height,&average_width );
819 grd_curcanv->cv_font = SUBTITLE_FONT;
820 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
821 if (string_width > tw )
826 th += LHY(8); //put some space between titles & body
829 grd_curcanv->cv_font = SMALL_FONT;
831 grd_curcanv->cv_font = NORMAL_FONT;
835 nmenus = nothers = 0;
837 // Find menu height & width (store in w,h)
838 for (i=0; i<nitems; i++ ) {
841 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
842 item[i].right_offset = 0;
845 string_height+=LHY(3);
847 item[i].saved_text[0] = '\0';
849 if ( item[i].type == NM_TYPE_SLIDER ) {
852 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
853 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
854 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
856 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
857 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
858 string_width += w1 + aw;
861 if ( item[i].type == NM_TYPE_MENU ) {
865 if ( item[i].type == NM_TYPE_CHECK ) {
868 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
869 item[i].right_offset = w1;
870 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
871 if (w1 > item[i].right_offset)
872 item[i].right_offset = w1;
875 if (item[i].type == NM_TYPE_RADIO ) {
878 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
879 item[i].right_offset = w1;
880 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
881 if (w1 > item[i].right_offset)
882 item[i].right_offset = w1;
885 if (item[i].type==NM_TYPE_NUMBER ) {
889 sprintf( test_text, "%d", item[i].max_value );
890 gr_get_string_size( test_text, &w1, &h1, &aw1 );
891 item[i].right_offset = w1;
892 sprintf( test_text, "%d", item[i].min_value );
893 gr_get_string_size( test_text, &w1, &h1, &aw1 );
894 if ( w1 > item[i].right_offset)
895 item[i].right_offset = w1;
898 if ( item[i].type == NM_TYPE_INPUT ) {
899 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
900 strcpy(item[i].saved_text, item[i].text );
902 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
903 if ( string_width > MAX_TEXT_WIDTH )
904 string_width = MAX_TEXT_WIDTH;
908 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
909 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
910 strcpy(item[i].saved_text, item[i].text );
912 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
917 item[i].w = string_width;
918 item[i].h = string_height;
920 if ( string_width > w )
921 w = string_width; // Save maximum width
922 if ( average_width > aw )
924 h += string_height+1; // Find the height of all strings
927 // Big hack for allowing the netgame options menu to spill over
929 MaxOnMenu=MAXDISPLAYABLEITEMS;
930 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
933 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
936 h=(MaxOnMenu*(string_height+1)+LHY(8));
937 MaxDisplayable=MaxOnMenu;
938 mprintf ((0,"Hey, this is a scroll box!\n"));
951 for (i=0; i<nitems; i++ ) {
953 if (item[i].right_offset > right_offset )
954 right_offset = item[i].right_offset;
956 if (right_offset > 0 )
959 //gr_get_string_size("",&string_width,&string_height,&average_width );
966 twidth = ( tw - w )/2;
971 { right_offset=0; twidth=0;}
973 mprintf(( 0, "Right offset = %d\n", right_offset ));
976 // Find min point of menu border
977 // x = (grd_curscreen->sc_w-w)/2;
978 // y = (grd_curscreen->sc_h-h)/2;
980 w += MenuHires?60:30;
981 h += MenuHires?60:30;
983 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
984 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
986 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
987 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
992 if ( filename != NULL ) {
993 nm_draw_background1( filename );
994 gr_palette_load(gr_palette);
997 // Save the background of the display
998 // Win95 must refer to the screen as a dd_grs_canvas, so...
999 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
1000 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
1002 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
1003 gr_set_current_canvas(bg.menu_canvas) );
1005 if ( filename == NULL ) {
1006 // Save the background under the menu...
1012 #if defined(POLY_ACC)
1013 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1015 bg.saved = gr_create_bitmap( w, h );
1017 Assert( bg.saved != NULL );
1019 WIN (DDGRLOCK(dd_grd_curcanv));
1020 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1021 WIN (DDGRUNLOCK(dd_grd_curcanv));
1023 WINDOS ( dd_gr_set_current_canvas(NULL),
1024 gr_set_current_canvas( NULL )
1027 nm_draw_background(x,y,x+w-1,y+h-1);
1029 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1030 gr_set_current_canvas( bg.menu_canvas )
1033 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1037 #if defined(POLY_ACC)
1038 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1040 bg.background = gr_create_bitmap( w, h );
1042 Assert( bg.background != NULL );
1044 WIN (DDGRLOCK(dd_grd_curcanv));
1045 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1046 WIN (DDGRUNLOCK(dd_grd_curcanv));
1049 // ty = 15 + (yborder/4);
1051 ty = MenuHires?30:15;
1054 grd_curcanv->cv_font = TITLE_FONT;
1055 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1056 gr_get_string_size(title,&string_width,&string_height,&average_width );
1059 WIN (DDGRLOCK(dd_grd_curcanv));
1060 gr_printf( 0x8000, ty, title );
1061 WIN (DDGRUNLOCK(dd_grd_curcanv));
1066 grd_curcanv->cv_font = SUBTITLE_FONT;
1067 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1068 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1071 WIN (DDGRLOCK(dd_grd_curcanv));
1072 gr_printf( 0x8000, ty, subtitle );
1073 WIN (DDGRUNLOCK(dd_grd_curcanv));
1078 grd_curcanv->cv_font = SMALL_FONT;
1080 grd_curcanv->cv_font = NORMAL_FONT;
1082 // Update all item's x & y values.
1083 for (i=0; i<nitems; i++ ) {
1084 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1085 item[i].y += (MenuHires?30:15);
1086 if ( item[i].type==NM_TYPE_RADIO ) {
1087 fm = -1; // find first marked one
1088 for ( j=0; j<nitems; j++ ) {
1089 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1090 if (fm==-1 && item[j].value)
1102 old_keyd_repeat = keyd_repeat;
1108 if (citem < 0 ) citem = 0;
1109 if (citem > nitems-1 ) citem = nitems-1;
1112 #if defined(WINDOWS) || defined(MACINTOSH)
1116 while ( item[choice].type==NM_TYPE_TEXT ) {
1118 if (choice >= nitems ) {
1121 if (choice == citem ) {
1132 // Clear mouse, joystick to clear button presses.
1133 game_flush_inputs();
1135 #if defined(WINDOWS) || defined(MACINTOSH)
1136 mouse_state = omouse_state = 0;
1137 if (filename == NULL && !MenuReordering) {
1138 draw_close_box(0,0);
1144 if (!MenuReordering) {
1146 SetCursor (LoadCursor(NULL,IDC_ARROW));
1151 if (!joydefs_calibrating)
1155 mprintf ((0,"Set to true!\n"));
1161 DoMessageStuff(&msg);
1163 if (_RedrawScreen) {
1164 _RedrawScreen = FALSE;
1167 gr_free_bitmap(bg.saved);
1168 d_free( bg.background );
1171 gr_free_bitmap(bg.background);
1173 dd_gr_free_sub_canvas( bg.menu_canvas );
1174 grd_curcanv->cv_font = save_font;
1175 dd_grd_curcanv = save_canvas;
1177 goto RePaintNewmenu4;
1186 omouse_state = mouse_state;
1187 mouse_state = mouse_button_state(0);
1188 if (!joydefs_calibrating)
1189 show_cursor(); // possibly hidden
1193 omouse_state = mouse_state;
1194 if (!MenuReordering)
1195 mouse_state = mouse_button_state(0);
1196 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1199 //see if redbook song needs to be restarted
1200 songs_check_redbook_repeat();
1207 (*subfunction)(nitems,item,&k,choice);
1210 if (!time_stopped) {
1211 // Save current menu box
1212 if (multi_menu_poll() == -1)
1218 dont_restore = (k == -3); //-3 means don't restore
1224 if (check_button_press())
1228 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1231 old_choice = choice;
1237 if (SurfingNet && !already_showing_info)
1239 show_extra_netgame_info(choice-2);
1241 if (SurfingNet && already_showing_info)
1248 if (SurfingNet && !already_showing_info)
1250 network_request_player_names(choice-2);
1252 if (SurfingNet && already_showing_info)
1267 case KEY_TAB + KEY_SHIFTED:
1270 if (all_text) break;
1277 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1279 if (choice<TopChoice)
1280 { choice=TopChoice; break; }
1282 if (choice<ScrollOffset)
1284 for (i=0;i<nitems;i++)
1287 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1292 if (choice >= nitems ) choice=0;
1293 if (choice < 0 ) choice=nitems-1;
1295 } while ( item[choice].type==NM_TYPE_TEXT );
1296 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1297 item[choice].value = -1;
1298 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1299 item[old_choice].group=0;
1300 strcpy(item[old_choice].text, item[old_choice].saved_text );
1301 item[old_choice].value = -1;
1304 item[old_choice].redraw = 1;
1305 item[choice].redraw=1;
1310 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1311 if (all_text) break;
1318 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1321 { choice--; break; }
1323 if (choice>=MaxOnMenu+ScrollOffset)
1325 for (i=0;i<nitems;i++)
1328 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1333 if (choice < 0 ) choice=nitems-1;
1334 if (choice >= nitems ) choice=0;
1337 } while ( item[choice].type==NM_TYPE_TEXT );
1339 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1340 item[choice].value = -1;
1341 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1342 item[old_choice].group=0;
1343 strcpy(item[old_choice].text, item[old_choice].saved_text );
1344 item[old_choice].value = -1;
1347 item[old_choice].redraw=1;
1348 item[choice].redraw=1;
1351 if ( choice > -1 ) {
1352 switch( item[choice].type ) {
1355 case NM_TYPE_INPUT_MENU:
1358 if ( item[choice].value )
1359 item[choice].value = 0;
1361 item[choice].value = 1;
1362 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1365 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1367 mprintf ((0,"Special redraw!\n"));
1372 item[choice].redraw=1;
1375 for (i=0; i<nitems; i++ ) {
1376 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1381 item[choice].value = 1;
1382 item[choice].redraw = 1;
1388 case KEY_SHIFTED+KEY_UP:
1389 if (MenuReordering && choice!=TopChoice)
1391 Temp=item[choice].text;
1392 TempVal=item[choice].value;
1393 item[choice].text=item[choice-1].text;
1394 item[choice].value=item[choice-1].value;
1395 item[choice-1].text=Temp;
1396 item[choice-1].value=TempVal;
1397 item[choice].redraw=1;
1398 item[choice-1].redraw=1;
1402 case KEY_SHIFTED+KEY_DOWN:
1403 if (MenuReordering && choice!=(nitems-1))
1405 Temp=item[choice].text;
1406 TempVal=item[choice].value;
1407 item[choice].text=item[choice+1].text;
1408 item[choice].value=item[choice+1].value;
1409 item[choice+1].text=Temp;
1410 item[choice+1].value=TempVal;
1411 item[choice].redraw=1;
1412 item[choice+1].redraw=1;
1419 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1420 item[choice].group = 1;
1421 item[choice].redraw = 1;
1422 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1423 item[choice].text[0] = 0;
1424 item[choice].value = -1;
1426 strip_end_whitespace(item[choice].text);
1433 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1434 item[choice].group=0;
1435 strcpy(item[choice].text, item[choice].saved_text );
1436 item[choice].redraw=1;
1437 item[choice].value = -1;
1444 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1445 case KEY_PRINT_SCREEN:
1447 save_screen_shot(0);
1448 PA_DFX (pa_set_frontbuffer_current());
1449 PA_DFX (pa_set_front_to_read());
1450 for (i=0;i<nitems;i++)
1459 case KEY_COMMAND+KEY_RIGHT:
1460 songs_goto_next_song();
1462 case KEY_COMMAND+KEY_LEFT:
1463 songs_goto_prev_song();
1465 case KEY_COMMAND+KEY_UP:
1466 songs_play_level_song(1);
1468 case KEY_COMMAND+KEY_DOWN:
1469 songs_stop_redbook();
1472 case KEY_COMMAND+KEY_M:
1474 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1475 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1478 key_close(); // no processing of keys with keyboard handler.. jeez
1481 show_boxed_message ("Mounting CD\nESC to quit");
1482 RBAMountDisk(); // OS has totaly control of the CD.
1483 if (Function_mode == FMODE_MENU)
1484 songs_play_song(SONG_TITLE,1);
1485 else if (Function_mode == FMODE_GAME)
1486 songs_play_level_song( Current_level_num );
1487 clear_boxed_message();
1496 case KEY_COMMAND+KEY_E:
1497 songs_stop_redbook();
1499 k = -1; // force key not to register
1502 case KEY_COMMAND+KEY_Q: {
1503 extern void macintosh_quit();
1505 if ( !(Game_mode & GM_MULTI) )
1507 if (!joydefs_calibrating)
1509 k = -1; // force key not to register
1516 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1523 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1525 if ( !done && mouse_state && !omouse_state && !all_text ) {
1526 mouse_get_pos(&mx, &my);
1527 for (i=0; i<nitems; i++ ) {
1528 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1529 x2 = x1 + item[i].w;
1530 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1531 y2 = y1 + item[i].h;
1532 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1533 if (i+ScrollOffset != choice) {
1534 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1537 choice = i + ScrollOffset;
1539 switch( item[choice].type ) {
1541 if ( item[choice].value )
1542 item[choice].value = 0;
1544 item[choice].value = 1;
1545 item[choice].redraw=1;
1552 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1554 mprintf ((0,"Special redraw!\n"));
1561 for (i=0; i<nitems; i++ ) {
1562 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1567 item[choice].value = 1;
1568 item[choice].redraw = 1;
1571 item[old_choice].redraw=1;
1577 if (mouse_state && all_text)
1580 if ( !done && mouse_state && !all_text ) {
1581 mouse_get_pos(&mx, &my);
1583 // check possible scrollbar stuff first
1585 int arrow_width, arrow_height, aw;
1587 if (ScrollOffset != 0) {
1588 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1589 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1590 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1591 x1 = x1 - arrow_width;
1592 y2 = y1 + arrow_height;
1593 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1596 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1598 if (choice<ScrollOffset)
1600 for (i=0;i<nitems;i++)
1603 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1607 if (ScrollOffset+MaxDisplayable<nitems) {
1608 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1609 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1610 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1611 x1 = x1 - arrow_width;
1612 y2 = y1 + arrow_height;
1613 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1616 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1618 if (choice>=MaxOnMenu+ScrollOffset)
1620 for (i=0;i<nitems;i++)
1623 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1629 for (i=0; i<nitems; i++ ) {
1630 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1631 x2 = x1 + item[i].w;
1632 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1633 y2 = y1 + item[i].h;
1634 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1635 if (i+ScrollOffset != choice) {
1636 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1639 choice = i + ScrollOffset;
1641 if ( item[choice].type == NM_TYPE_SLIDER ) {
1642 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1643 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1645 strcpy(slider_text, item[choice].saved_text);
1646 p = strchr(slider_text, '\t');
1652 gr_get_string_size(s1, &slider_width, &height, &aw);
1653 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1654 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1655 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1657 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1658 x2 = x1 + slider_width + sright_width;
1659 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1660 item[choice].value = item[choice].min_value;
1661 item[choice].redraw = 2;
1662 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1663 item[choice].value = item[choice].max_value;
1664 item[choice].redraw = 2;
1665 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1666 int num_values, value_width, new_value;
1668 num_values = item[choice].max_value - item[choice].min_value + 1;
1669 value_width = (slider_width - sleft_width - sright_width) / num_values;
1670 new_value = (mx - x1 - sleft_width) / value_width;
1671 if ( item[choice].value != new_value ) {
1672 item[choice].value = new_value;
1673 item[choice].redraw = 2;
1679 if (choice == old_choice)
1681 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1682 item[choice].value = -1;
1683 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1684 item[old_choice].group=0;
1685 strcpy(item[old_choice].text, item[old_choice].saved_text );
1686 item[old_choice].value = -1;
1689 item[old_choice].redraw = 1;
1690 item[choice].redraw=1;
1696 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1697 mouse_get_pos(&mx, &my);
1698 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1699 x2 = x1 + item[choice].w;
1700 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1701 y2 = y1 + item[choice].h;
1702 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1703 if (Hack_DblClick_MenuMode) {
1704 if (dblclick_flag) done = 1;
1705 else dblclick_flag = 1;
1711 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1712 item[choice].group = 1;
1713 item[choice].redraw = 1;
1714 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1715 item[choice].text[0] = 0;
1716 item[choice].value = -1;
1718 strip_end_whitespace(item[choice].text);
1722 if ( !done && !mouse_state && omouse_state && close_box ) {
1723 mouse_get_pos(&mx, &my);
1724 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1725 x2 = x1 + CLOSE_SIZE;
1726 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1727 y2 = y1 + CLOSE_SIZE;
1728 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1734 // HACK! Don't redraw loadgame preview
1735 if (RestoringMenu) item[0].redraw = 0;
1736 #endif // ifdef MACINTOSH
1738 if ( choice > -1 ) {
1741 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1742 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1743 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1744 if (item[choice].value > 0)
1745 item[choice].value--;
1746 item[choice].text[item[choice].value] = 0;
1747 item[choice].redraw = 1;
1749 ascii = key_to_ascii(k);
1750 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1754 if (item[choice].value==-1) {
1755 item[choice].value = 0;
1758 allowed = char_allowed(ascii);
1760 if (!allowed && ascii==' ' && char_allowed('_')) {
1766 item[choice].text[item[choice].value++] = ascii;
1767 item[choice].text[item[choice].value] = 0;
1768 item[choice].redraw=1;
1772 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1773 ascii = key_to_ascii(k);
1775 int choice1 = choice;
1776 ascii = toupper(ascii);
1780 if (choice1 >= nitems ) choice1=0;
1781 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1782 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1783 (item[choice1].type==NM_TYPE_CHECK) ||
1784 (item[choice1].type==NM_TYPE_RADIO) ||
1785 (item[choice1].type==NM_TYPE_NUMBER) ||
1786 (item[choice1].type==NM_TYPE_SLIDER) )
1787 && (ascii==toupper(ch)) ) {
1791 item[old_choice].redraw=1;
1792 item[choice].redraw=1;
1794 } while (choice1 != choice );
1798 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1799 int ov=item[choice].value;
1804 case KEY_MINUS+KEY_SHIFTED:
1806 item[choice].value -= 1;
1811 case KEY_EQUAL+KEY_SHIFTED:
1813 item[choice].value++;
1818 item[choice].value += 10;
1823 item[choice].value -= 10;
1826 if (ov!=item[choice].value)
1827 item[choice].redraw=1;
1832 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1833 gr_set_current_canvas(bg.menu_canvas));
1835 // Redraw everything...
1836 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1838 if (item[i].redraw) // warning! ugly hack below
1840 item[i].y-=((string_height+1)*ScrollOffset);
1843 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1845 MAC(if (!joydefs_calibrating) show_cursor());
1846 WIN(if (!MenuReordering) ShowCursorW());
1847 item[i].y+=((string_height+1)*ScrollOffset);
1849 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1850 update_cursor( &item[i]);
1856 //grd_curcanv->cv_font = NORMAL_FONT;
1858 if (LastScrollCheck!=ScrollOffset)
1860 LastScrollCheck=ScrollOffset;
1861 grd_curcanv->cv_font = SELECTED_FONT;
1863 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1864 sx=item[ScrollOffset].x-(MenuHires?24:12);
1867 if (ScrollOffset!=0)
1868 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1870 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1872 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1873 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1875 if (ScrollOffset+MaxDisplayable<nitems)
1876 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1878 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1884 if ( !dont_restore && gr_palette_faded_out ) {
1885 gr_palette_fade_in( gr_palette, 32, 0 );
1892 // Restore everything...
1894 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1895 gr_set_current_canvas(bg.menu_canvas));
1897 if ( filename == NULL ) {
1898 // Save the background under the menu...
1899 WIN (DDGRLOCK(dd_grd_curcanv));
1900 gr_bitmap(0, 0, bg.saved);
1901 WIN (DDGRUNLOCK(dd_grd_curcanv));
1902 gr_free_bitmap(bg.saved);
1903 d_free( bg.background );
1905 if (!dont_restore) //info passed back from subfunction
1907 WIN (DDGRLOCK(dd_grd_curcanv));
1908 gr_bitmap(0, 0, bg.background);
1909 WIN (DDGRUNLOCK(dd_grd_curcanv));
1911 gr_free_bitmap(bg.background);
1914 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1915 gr_free_sub_canvas( bg.menu_canvas ) );
1917 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1918 grd_curcanv->cv_font = save_font;
1919 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1920 keyd_repeat = old_keyd_repeat;
1922 game_flush_inputs();
1933 if ( sound_stopped )
1934 digi_resume_digi_sounds();
1936 WIN(mouse_set_mode(1)); //re-enable centering mode
1943 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1949 char nm_text[MESSAGEBOX_TEXT_SIZE];
1950 newmenu_item nm_message_items[5];
1952 va_start(args, nchoices );
1954 Assert( nchoices <= 5 );
1956 for (i=0; i<nchoices; i++ ) {
1957 s = va_arg( args, char * );
1958 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1960 format = va_arg( args, char * );
1961 strcpy( nm_text, "" );
1962 vsprintf(nm_text,format,args);
1965 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1967 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1970 int nm_messagebox( char *title, int nchoices, ... )
1976 char nm_text[MESSAGEBOX_TEXT_SIZE];
1977 newmenu_item nm_message_items[5];
1979 va_start(args, nchoices );
1981 Assert( nchoices <= 5 );
1983 for (i=0; i<nchoices; i++ ) {
1984 s = va_arg( args, char * );
1985 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1987 format = va_arg( args, char * );
1988 strcpy( nm_text, "" );
1989 vsprintf(nm_text,format,args);
1992 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1994 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
2000 void newmenu_file_sort( int n, char *list )
2007 for (i=incr; i<n; i++ ) {
2010 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
2011 memcpy( t, &list[j*14], FILENAME_LEN );
2012 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
2013 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2024 void delete_player_saved_games(char * name)
2029 for (i=0;i<10; i++) {
2031 sprintf( filename, "%s.sg%d", name, i );
2033 sprintf( filename, ":Players:%s.sg%d", name, i );
2039 #define MAX_FILES 300
2041 int MakeNewPlayerFile(int allow_abort);
2043 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2046 FILEFINDSTRUCT find;
2047 int NumFiles=0, key,done, citem, ocitem;
2048 char * filenames = NULL;
2049 int NumFiles_displayed = 8;
2050 int first_item = -1, ofirst_item;
2051 int old_keyd_repeat = keyd_repeat;
2054 int demos_deleted=0;
2055 int initialized = 0;
2057 int w_x, w_y, w_w, w_h, title_height;
2058 int box_x, box_y, box_w, box_h;
2059 bkg bg; // background under listbox
2060 #if defined(MACINTOSH) || defined(WINDOWS)
2061 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2062 int mouse2_state, omouse2_state;
2063 int dblclick_flag=0;
2065 int show_up_arrow=0,show_down_arrow=0;
2067 WIN(int win_redraw=0);
2069 w_x=w_y=w_w=w_h=title_height=0;
2070 box_x=box_y=box_w=box_h=0;
2072 filenames = d_malloc( MAX_FILES * 14 );
2073 if (filenames==NULL) return 0;
2078 WIN(mouse_set_mode(0)); //disable centering mode
2080 if (strstr( filespec, "*.plr" ))
2082 else if (strstr( filespec, "*.dem" ))
2089 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2091 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2096 if( !FileFindFirst( filespec, &find ) ) {
2098 if (NumFiles<MAX_FILES) {
2099 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2100 if ( player_mode ) {
2102 p = strchr(&filenames[NumFiles*14],'.');
2109 } while( !FileFindNext( &find ) );
2113 if ( (NumFiles < 1) && demos_deleted ) {
2117 if ( (NumFiles < 1) && demo_mode ) {
2118 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2124 if ( (NumFiles < 2) && player_mode ) {
2126 goto ExitFileMenuEarly;
2133 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2140 // set_screen_mode(SCREEN_MENU);
2146 dd_gr_set_current_canvas(NULL);
2148 gr_set_current_canvas(NULL);
2151 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2153 grd_curcanv->cv_font = SUBTITLE_FONT;
2155 WIN(DDGRUNLOCK(dd_grd_curcanv));
2160 for (i=0; i<NumFiles; i++ ) {
2162 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2168 gr_get_string_size( title, &w, &h, &aw );
2171 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2175 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2177 w_w += (grd_curfont->ft_w * 4);
2178 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2180 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2181 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2183 w_x = (grd_curcanv->cv_w-w_w)/2;
2184 w_y = (grd_curcanv->cv_h-w_h)/2;
2186 if ( w_x < 0 ) w_x = 0;
2187 if ( w_y < 0 ) w_y = 0;
2189 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2190 box_y = w_y + title_height;
2192 // save the screen behind the menu.
2196 #if !defined(WINDOWS)
2197 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2198 bg.background = &VR_offscreen_buffer->cv_bitmap;
2201 #if defined(POLY_ACC)
2202 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2204 bg.background = gr_create_bitmap( w_w, w_h );
2207 Assert( bg.background != NULL );
2210 WIN(DDGRLOCK(dd_grd_curcanv));
2211 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2212 WIN(DDGRUNLOCK(dd_grd_curcanv));
2216 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2217 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2218 dd_VR_offscreen_buffer, 0, 0,
2219 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2220 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2224 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2226 WIN(DDGRLOCK(dd_grd_curcanv))
2228 gr_string( 0x8000, w_y+10, title );
2230 WIN(DDGRUNLOCK(dd_grd_curcanv));
2237 if ( !player_mode ) {
2238 newmenu_file_sort( NumFiles, filenames );
2240 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2241 newmenu_file_sort( NumFiles, filenames );
2243 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2245 for ( i=0; i<NumFiles; i++ ) {
2246 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2247 #if defined(WINDOWS) || defined(MACINTOSH)
2255 #if defined(MACINTOSH) || defined(WINDOWS)
2256 mouse_state = omouse_state = 0;
2257 mouse2_state = omouse2_state = 0;
2258 draw_close_box(w_x,w_y);
2270 DoMessageStuff(&msg);
2272 if (_RedrawScreen) {
2273 _RedrawScreen = FALSE;
2275 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2276 gr_free_bitmap(bg.background);
2279 goto RePaintNewmenuFile;
2286 ofirst_item = first_item;
2289 #if defined(MACINTOSH) || defined(WINDOWS)
2290 omouse_state = mouse_state;
2291 omouse2_state = mouse2_state;
2292 mouse_state = mouse_button_state(0);
2293 mouse2_state = mouse_button_state(1);
2296 //see if redbook song needs to be restarted
2297 songs_check_redbook_repeat();
2300 if (!mouse2_state && omouse2_state)
2301 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2304 //NOTE LINK TO ABOVE ELSE
2310 else if (simukey==1)
2316 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2317 case KEY_PRINT_SCREEN:
2319 save_screen_shot(0);
2320 PA_DFX (pa_set_frontbuffer_current());
2321 PA_DFX (pa_set_front_to_read());
2327 case KEY_CTRLED+KEY_D:
2328 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2332 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2336 mouse_set_mode(1); //re-enable centering mode
2340 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2342 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2345 mouse_set_mode(0); //disenable centering mode
2351 char name[_MAX_PATH],dir[_MAX_DIR];
2353 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2357 _splitpath(filespec,name,dir,NULL,NULL);
2359 strcat(name,&filenames[citem*14]);
2366 if ( !strncmp(name, ".\\", 2) )
2367 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2368 name[i] = name[i+1];
2369 while ( (p = strchr(name, '\\')) )
2374 ret = unlink( name );
2378 if ((!ret) && player_mode) {
2379 delete_player_saved_games( &filenames[citem*14] );
2384 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2386 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2387 } else if (demo_mode)
2412 citem += NumFiles_displayed;
2416 citem -= NumFiles_displayed;
2419 if (allow_abort_flag) {
2430 case KEY_COMMAND+KEY_Q: {
2431 extern void macintosh_quit();
2433 if ( !(Game_mode & GM_MULTI) )
2444 int ascii = key_to_ascii(key);
2445 if ( ascii < 255 ) {
2448 if (cc1 < 0 ) cc1 = 0;
2449 if (cc1 >= NumFiles ) cc1 = 0;
2451 if ( cc < 0 ) cc = 0;
2452 if ( cc >= NumFiles ) cc = 0;
2453 if ( citem == cc ) break;
2455 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2470 if (citem>=NumFiles)
2473 if (citem< first_item)
2476 if (citem>=( first_item+NumFiles_displayed))
2478 first_item = citem-NumFiles_displayed+1;
2482 if (NumFiles>first_item+NumFiles_displayed)
2493 if (NumFiles <= NumFiles_displayed )
2496 if (first_item>NumFiles-NumFiles_displayed)
2498 first_item = NumFiles-NumFiles_displayed;
2501 if (first_item < 0 ) first_item = 0;
2503 #if defined(MACINTOSH) || defined(WINDOWS)
2505 if (mouse_state || mouse2_state) {
2508 mouse_get_pos(&mx, &my);
2509 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2510 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2512 x2 = box_x + box_w - 1;
2513 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2515 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2516 if (i == citem && !mouse2_state) {
2526 if (!mouse_state && omouse_state) {
2529 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2530 mouse_get_pos(&mx, &my);
2532 x2 = box_x + box_w - 1;
2533 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2535 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2536 if (dblclick_flag) done = 1;
2537 else dblclick_flag = 1;
2541 if ( !mouse_state && omouse_state ) {
2542 mouse_get_pos(&mx, &my);
2543 x1 = w_x + CLOSE_X + 2;
2544 x2 = x1 + CLOSE_SIZE - 2;
2545 y1 = w_y + CLOSE_Y + 2;
2546 y2 = y1 + CLOSE_SIZE - 2;
2547 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2556 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2558 y1 = box_y+box_h-LHY(7);
2560 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2567 WIN(DDGRLOCK(dd_grd_curcanv));
2568 gr_setcolor( BM_XRGB(2,2,2));
2569 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2570 gr_setcolor( BM_XRGB( 0,0,0) );
2573 if (ofirst_item != first_item || win_redraw) {
2576 if (ofirst_item != first_item) {
2580 gr_setcolor( BM_XRGB( 0,0,0) );
2581 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2583 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2585 if ( i >= NumFiles ) {
2587 gr_setcolor( BM_XRGB(5,5,5));
2588 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2589 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2591 gr_setcolor( BM_XRGB(2,2,2));
2592 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2594 gr_setcolor( BM_XRGB(0,0,0));
2595 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2599 grd_curcanv->cv_font = SELECTED_FONT;
2601 grd_curcanv->cv_font = NORMAL_FONT;
2602 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2604 gr_setcolor( BM_XRGB(5,5,5));
2605 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2606 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2608 gr_setcolor( BM_XRGB(2,2,2));
2609 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2610 gr_setcolor( BM_XRGB(0,0,0));
2612 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2613 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2618 } else if ( citem != ocitem ) {
2624 if ( (i>=0) && (i<NumFiles) ) {
2625 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2627 grd_curcanv->cv_font = SELECTED_FONT;
2629 grd_curcanv->cv_font = NORMAL_FONT;
2630 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2631 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2632 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2635 if ( (i>=0) && (i<NumFiles) ) {
2636 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2638 grd_curcanv->cv_font = SELECTED_FONT;
2640 grd_curcanv->cv_font = NORMAL_FONT;
2641 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2642 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2643 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2650 grd_curcanv->cv_font = NORMAL_FONT;
2652 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2656 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2660 if (show_down_arrow)
2661 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2665 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2673 WIN(DDGRUNLOCK(dd_grd_curcanv));
2679 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2686 keyd_repeat = old_keyd_repeat;
2688 if ( initialized ) {
2689 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2691 WIN (DDGRLOCK(dd_grd_curcanv));
2692 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2693 WIN (DDGRUNLOCK(dd_grd_curcanv));
2695 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2696 gr_free_bitmap(bg.background);
2699 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2700 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2702 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2703 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2713 WIN(mouse_set_mode(1)); //re-enable centering mode
2721 // Example listbox callback function...
2722 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2726 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2727 // if ( *nitems > 1 ) {
2728 // unlink( items[*citem] ); // Delete the file
2729 // for (i=*citem; i<*nitems-1; i++ ) {
2730 // items[i] = items[i+1];
2732 // *nitems = *nitems - 1;
2733 // d_free( items[*nitems] );
2734 // items[*nitems] = NULL;
2735 // return 1; // redraw;
2742 #define LB_ITEMS_ON_SCREEN 8
2744 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2746 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2749 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 ) )
2752 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2753 int old_keyd_repeat = keyd_repeat;
2754 int width, height, wx, wy, title_height, border_size;
2755 int total_width,total_height;
2757 #if defined(MACINTOSH) || defined(WINDOWS)
2758 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2759 int close_x,close_y;
2760 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2762 WIN(int win_redraw=0);
2766 PA_DFX (pa_set_frontbuffer_current());
2767 PA_DFX (pa_set_front_to_read());
2768 WIN(mouse_set_mode(0)); //disable centering mode
2770 // set_screen_mode(SCREEN_MENU);
2774 RePaintNewmenuListbox:
2776 dd_gr_set_current_canvas(NULL);
2778 gr_set_current_canvas(NULL);
2781 grd_curcanv->cv_font = SUBTITLE_FONT;
2784 for (i=0; i<nitems; i++ ) {
2786 gr_get_string_size( items[i], &w, &h, &aw );
2790 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2794 gr_get_string_size( title, &w, &h, &aw );
2797 title_height = h + 5;
2800 border_size = grd_curfont->ft_w;
2801 WIN (border_size=grd_curfont->ft_w*2);
2803 width += (grd_curfont->ft_w);
2804 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2805 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2807 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2808 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2809 if ( wy < title_height )
2812 total_width = width+2*border_size;
2813 total_height = height+2*border_size+title_height;
2817 #if !defined(WINDOWS)
2818 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2819 bg.background = &VR_offscreen_buffer->cv_bitmap;
2822 //bg.background = gr_create_bitmap( width, (height + title_height) );
2823 #if defined(POLY_ACC)
2824 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2826 bg.background = gr_create_bitmap(total_width,total_height);
2828 Assert( bg.background != NULL );
2830 WIN (DDGRLOCK(dd_grd_curcanv));
2831 //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 );
2832 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2833 WIN (DDGRUNLOCK(dd_grd_curcanv));
2837 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2838 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2839 dd_VR_offscreen_buffer, 0, 0,
2840 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2841 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2845 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2847 WIN(DDGRLOCK(dd_grd_curcanv));
2848 gr_string( 0x8000, wy - title_height, title );
2849 WIN(DDGRUNLOCK(dd_grd_curcanv));
2854 citem = default_item;
2855 if ( citem < 0 ) citem = 0;
2856 if ( citem >= nitems ) citem = 0;
2860 #if defined(MACINTOSH) || defined(WINDOWS)
2861 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2862 close_x = wx-border_size;
2863 close_y = wy-title_height-border_size;
2864 draw_close_box(close_x,close_y);
2876 DoMessageStuff(&msg);
2878 if (_RedrawScreen) {
2879 _RedrawScreen = FALSE;
2881 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2882 gr_free_bitmap(bg.background);
2884 goto RePaintNewmenuListbox;
2891 ofirst_item = first_item;
2892 #if defined(MACINTOSH) || defined(WINDOWS)
2893 omouse_state = mouse_state;
2894 mouse_state = mouse_button_state(0);
2896 //see if redbook song needs to be restarted
2897 songs_check_redbook_repeat();
2901 if ( listbox_callback )
2902 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2923 else if (simukey==1)
2929 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2930 case KEY_PRINT_SCREEN:
2932 save_screen_shot(0);
2933 PA_DFX (pa_set_frontbuffer_current());
2934 PA_DFX (pa_set_front_to_read());
2957 citem += LB_ITEMS_ON_SCREEN;
2961 citem -= LB_ITEMS_ON_SCREEN;
2964 if (allow_abort_flag) {
2975 case KEY_COMMAND+KEY_Q: {
2976 extern void macintosh_quit();
2978 if ( !(Game_mode & GM_MULTI) )
2988 int ascii = key_to_ascii(key);
2989 if ( ascii < 255 ) {
2992 if (cc1 < 0 ) cc1 = 0;
2993 if (cc1 >= nitems ) cc1 = 0;
2995 if ( cc < 0 ) cc = 0;
2996 if ( cc >= nitems ) cc = 0;
2997 if ( citem == cc ) break;
2999 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
3016 if (citem< first_item)
3019 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
3020 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3022 if (nitems <= LB_ITEMS_ON_SCREEN )
3025 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3026 first_item = nitems-LB_ITEMS_ON_SCREEN;
3027 if (first_item < 0 ) first_item = 0;
3030 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3041 #if defined(MACINTOSH) || defined(WINDOWS)
3046 mouse_get_pos(&mx, &my);
3047 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3050 gr_get_string_size(items[i], &w, &h, &aw );
3053 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3055 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3067 //no double-click stuff for listbox
3068 //@@if (!mouse_state && omouse_state) {
3071 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3072 //@@ mouse_get_pos(&mx, &my);
3074 //@@ x2 = wx + width;
3075 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3077 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3078 //@@ if (dblclick_flag) done = 1;
3082 //check for close box clicked
3083 if ( !mouse_state && omouse_state ) {
3084 mouse_get_pos(&mx, &my);
3085 x1 = close_x + CLOSE_X + 2;
3086 x2 = x1 + CLOSE_SIZE - 2;
3087 y1 = close_y + CLOSE_Y + 2;
3088 y2 = y1 + CLOSE_SIZE - 2;
3089 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3099 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3101 y1 = total_height-LHY(7);
3103 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3111 if ( (ofirst_item != first_item) || redraw) {
3114 WIN(DDGRLOCK(dd_grd_curcanv));
3116 gr_setcolor( BM_XRGB( 0,0,0) );
3117 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3119 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3120 if ( i >= nitems ) {
3121 gr_setcolor( BM_XRGB(0,0,0));
3122 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3125 grd_curcanv->cv_font = SELECTED_FONT;
3127 grd_curcanv->cv_font = NORMAL_FONT;
3128 gr_get_string_size(items[i], &w, &h, &aw );
3129 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3130 gr_string( wx+5, y, items[i] );
3135 // If Win95 port, draw up/down arrows on left side of menu
3137 grd_curcanv->cv_font = NORMAL_FONT;
3139 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3143 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3147 if (show_down_arrow)
3148 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3152 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3159 WIN(DDGRUNLOCK(dd_grd_curcanv));
3163 } else if ( citem != ocitem ) {
3169 WIN(DDGRLOCK(dd_grd_curcanv));
3172 if ( (i>=0) && (i<nitems) ) {
3173 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3175 grd_curcanv->cv_font = SELECTED_FONT;
3177 grd_curcanv->cv_font = NORMAL_FONT;
3178 gr_get_string_size(items[i], &w, &h, &aw );
3179 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3180 gr_string( wx+5, y, items[i] );
3184 if ( (i>=0) && (i<nitems) ) {
3185 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3187 grd_curcanv->cv_font = SELECTED_FONT;
3189 grd_curcanv->cv_font = NORMAL_FONT;
3190 gr_get_string_size( items[i], &w, &h, &aw );
3191 gr_rect( wx, y-1, wx+width-1, y+h );
3192 gr_string( wx+5, y, items[i] );
3194 WIN(DDGRUNLOCK(dd_grd_curcanv));
3204 keyd_repeat = old_keyd_repeat;
3206 WIN (DDGRLOCK(dd_grd_curcanv));
3207 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3208 WIN (DDGRUNLOCK(dd_grd_curcanv));
3210 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3211 gr_free_bitmap(bg.background);
3215 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3216 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3218 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3219 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3225 WIN(mouse_set_mode(1)); //re-enable centering mode
3230 int newmenu_filelist( char * title, char * filespec, char * filename )
3233 char * Filenames[MAX_FILES];
3234 char FilenameText[MAX_FILES][14];
3235 FILEFINDSTRUCT find;
3238 if( !FileFindFirst( filespec, &find ) ) {
3240 if (NumFiles<MAX_FILES) {
3241 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3242 Filenames[NumFiles] = FilenameText[NumFiles];
3247 } while( !FileFindNext( &find ) );
3251 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3253 strcpy( filename, Filenames[i] );
3259 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3260 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3266 char nm_text[MESSAGEBOX_TEXT_SIZE];
3267 newmenu_item nm_message_items[5];
3269 va_start(args, nchoices );
3271 Assert( nchoices <= 5 );
3273 for (i=0; i<nchoices; i++ ) {
3274 s = va_arg( args, char * );
3275 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3277 format = va_arg( args, char * );
3278 //sprintf( nm_text, "" ); // adb: ?
3279 vsprintf(nm_text,format,args);
3282 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3284 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3286 //end this section addition - Victor Rachels
3289 extern netgame_info Active_games[];
3290 extern int NumActiveNetgames;
3292 void show_extra_netgame_info(int choice)
3298 if (choice>=NumActiveNetgames)
3303 m[i].text=(char *)&mtext[i];
3304 m[i].type=NM_TYPE_TEXT;
3307 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3308 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3309 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3310 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3312 already_showing_info=1;
3313 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3314 already_showing_info=0;
3319 /* Spiffy word wrap string formatting function */
3321 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3327 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3330 wordptr = strtok(tbuf, " ");
3331 if (!wordptr) return;
3337 col = col+strlen(wordptr)+1;
3338 if (col >=line_length) {
3340 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3343 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3345 wordptr = strtok(NULL, " ");