1 /* $Id: newmenu.c,v 1.28 2004-08-28 23:17:45 schaffner Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
34 #if !defined(_MSC_VER) && !defined(macintosh)
39 #include "pa_enabl.h" //$$POLY_ACC
86 #define MAXDISPLAYABLEITEMS 15
88 #define LHX(x) ((x)*(MenuHires?2:1))
89 #define LHY(y) ((y)*(MenuHires?2.4:1))
91 #define TITLE_FONT HUGE_FONT
92 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
93 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
94 #define SUBTITLE_FONT MEDIUM3_FONT
96 #define NORMAL_CHECK_BOX "
\81"
97 #define CHECKED_CHECK_BOX "
\82"
99 #define NORMAL_RADIO_BOX "
\7f"
100 #define CHECKED_RADIO_BOX "
\80"
101 #define CURSOR_STRING "_"
102 #define SLIDER_LEFT "
\83" // 131
103 #define SLIDER_RIGHT "
\84" // 132
104 #define SLIDER_MIDDLE "
\85" // 133
105 #define SLIDER_MARKER "
\86" // 134
106 #define UP_ARROW_MARKER "
\87" // 135
107 #define DOWN_ARROW_MARKER "
\88" // 136
109 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 );
110 void show_extra_netgame_info(int choice);
113 int Newmenu_first_time = 1;
114 //--unused-- int Newmenu_fade_in = 1;
117 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
118 grs_bitmap * saved; // The background under the menu.
119 grs_bitmap * background;
122 grs_bitmap nm_background,nm_background_save;
124 #define MESSAGEBOX_TEXT_SIZE 2176 // How many characters in messagebox (changed form 300 (fixes crash from show_game_score and friends) - 2000/01/18 Matt Mueller)
125 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
127 ubyte MenuReordering=0;
129 char Pauseable_menu=0;
130 char already_showing_info=0;
133 void newmenu_close() {
134 if ( nm_background.bm_data )
135 d_free(nm_background.bm_data);
137 if ( nm_background_save.bm_data )
138 d_free(nm_background_save.bm_data);
139 Newmenu_first_time = 1;
142 ubyte background_palette[768];
144 //should be called whenever the palette changes
145 void nm_remap_background()
147 if (!Newmenu_first_time) {
148 if (!nm_background.bm_data)
149 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
151 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
153 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
159 extern char last_palette_loaded[];
161 void nm_draw_background1(char * filename)
168 //@@//I think this only gets called to fill the whole screen
169 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
170 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
172 pcx_error = pcx_get_dimensions(filename, &width, &height);
173 if (pcx_error != PCX_ERROR_NONE)
174 Error("Could not open pcx file <%s>\n", filename);
176 bmp = gr_create_bitmap(width, height);
178 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
179 Assert(pcx_error == PCX_ERROR_NONE);
181 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
184 { //remap stuff. this code is kindof a hack
186 //now, before we bring up the menu, we need to
187 //do some stuff to make sure the palette is ok. First, we need to
188 //get our current palette into the 2d's array, so the remapping will
189 //work. Second, we need to remap the fonts. Third, we need to fill
190 //in part of the fade tables so the darkening of the menu edges works
192 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
194 gr_palette_load(gr_palette);
196 remap_fonts_and_menus(1);
200 WIN(DDGRLOCK(dd_grd_curcanv));
201 #if defined(POLY_ACC)
203 pa_update_clut(gr_palette, 0, 256, 0);
206 #if defined(POLY_ACC)
209 WIN(DDGRUNLOCK(dd_grd_curcanv));
213 strcpy(last_palette_loaded,""); //force palette load next time
217 #define MENU_BACKGROUND_BITMAP_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
218 #define MENU_BACKGROUND_BITMAP_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
220 #define MENU_BACKGROUND_BITMAP (MenuHires?MENU_BACKGROUND_BITMAP_HIRES:MENU_BACKGROUND_BITMAP_LORES)
222 int Background_hires;
225 void nm_draw_background(int x1, int y1, int x2, int y2 )
229 if (Newmenu_first_time || MenuHires!=Background_hires) {
232 if (Newmenu_first_time) {
233 atexit( newmenu_close );
234 Newmenu_first_time = 0;
235 nm_background_save.bm_data=NULL;
238 if (nm_background_save.bm_data)
239 d_free(nm_background_save.bm_data);
240 if (nm_background.bm_data)
241 d_free(nm_background.bm_data);
244 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
245 Assert(pcx_error == PCX_ERROR_NONE);
247 nm_background = nm_background_save;
248 nm_background.bm_data=NULL;
249 nm_remap_background();
251 Background_hires = MenuHires;
254 if ( x1 < 0 ) x1 = 0;
255 if ( y1 < 0 ) y1 = 0;
260 //if ( w > nm_background.bm_w ) w = nm_background.bm_w;
261 //if ( h > nm_background.bm_h ) h = nm_background.bm_h;
268 grs_bitmap *tmp = gr_create_bitmap(w, h);
270 gr_bitmap_scale_to(&nm_background, tmp);
272 WIN(DDGRLOCK(dd_grd_curcanv));
274 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), tmp, &(grd_curcanv->cv_bitmap) );
276 gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) );
280 WIN(DDGRLOCK(dd_grd_curcanv));
282 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
284 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
288 Gr_scanline_darkening_level = 2*7;
290 gr_setcolor( BM_XRGB(0,0,0) );
291 gr_urect( x2-5, y1+5, x2-5, y2-5 );
292 gr_urect( x2-4, y1+4, x2-4, y2-5 );
293 gr_urect( x2-3, y1+3, x2-3, y2-5 );
294 gr_urect( x2-2, y1+2, x2-2, y2-5 );
295 gr_urect( x2-1, y1+1, x2-1, y2-5 );
296 gr_urect( x2+0, y1+0, x2-0, y2-5 );
298 gr_urect( x1+5, y2-5, x2, y2-5 );
299 gr_urect( x1+4, y2-4, x2, y2-4 );
300 gr_urect( x1+3, y2-3, x2, y2-3 );
301 gr_urect( x1+2, y2-2, x2, y2-2 );
302 gr_urect( x1+1, y2-1, x2, y2-1 );
303 gr_urect( x1+0, y2, x2, y2-0 );
305 WIN(DDGRUNLOCK(dd_grd_curcanv));
307 Gr_scanline_darkening_level = GR_FADE_LEVELS;
310 void nm_restore_background( int x, int y, int w, int h )
317 if ( x1 < 0 ) x1 = 0;
318 if ( y1 < 0 ) y1 = 0;
320 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
321 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
326 WIN(DDGRLOCK(dd_grd_curcanv));
327 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
328 WIN(DDGRUNLOCK(dd_grd_curcanv));
331 // Draw a left justfied string
332 void nm_string( bkg * b, int w1,int x, int y, char * s)
334 int w,h,aw,tx=0,t=0,i;
335 char *p,*s1,*s2,measure[2];
336 int XTabs[]={15,87,124,162,228,253};
342 XTabs[i]=(LHX(XTabs[i]));
349 p = strchr( s2, '\t' );
356 gr_get_string_size(s2, &w, &h, &aw );
362 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
363 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
366 for (i=0;i<strlen(s2);i++) {
367 if (s2[i]=='\t' && SurfingNet) {
373 gr_get_string_size(measure,&tx,&h,&aw);
374 gr_string(x,y,measure);
381 if (!SurfingNet && p && (w1>0) ) {
382 gr_get_string_size(s1, &w, &h, &aw );
384 gr_string( x+w1-w, y, s1 );
391 // Draw a slider and it's string
392 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
399 p = strchr( s, '\t' );
405 gr_get_string_size(s, &w, &h, &aw );
408 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
409 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
411 gr_string( x, y, s );
414 gr_get_string_size(s1, &w, &h, &aw );
417 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
419 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
421 gr_string( x+w1-w, y, s1 );
428 // Draw a left justfied string with black background.
429 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
432 gr_get_string_size(s, &w, &h, &aw );
436 WIN(DDGRLOCK(dd_grd_curcanv));
437 gr_setcolor( BM_XRGB(2,2,2) );
438 gr_rect( x-1, y-1, x-1, y+h-1 );
439 gr_rect( x-1, y-1, x+w1-1, y-1 );
442 gr_setcolor( BM_XRGB(5,5,5) );
443 gr_rect( x, y+h, x+w1, y+h);
444 gr_rect( x+w1, y-1, x+w1, y+h );
446 gr_setcolor( BM_XRGB(0,0,0) );
447 gr_rect( x, y, x+w1-1, y+h-1 );
449 gr_string( x+1, y+1, s );
450 WIN(DDGRUNLOCK(dd_grd_curcanv));
454 // Draw a right justfied string
455 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
458 gr_get_string_size(s, &w, &h, &aw );
463 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
466 WIN(DDGRLOCK(dd_grd_curcanv));
467 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
468 gr_string( x-w, y, s );
469 WIN(DDGRUNLOCK(dd_grd_curcanv));
474 //for text items, constantly redraw cursor (to achieve flash)
475 void update_cursor( newmenu_item *item)
478 fix time = timer_get_approx_seconds();
480 char * text = item->text;
482 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
485 gr_get_string_size(text, &w, &h, &aw );
486 if ( w > item->w-10 )
493 x = item->x+w; y = item->y;
495 WIN(DDGRLOCK(dd_grd_curcanv));
497 gr_string( x, y, CURSOR_STRING );
499 gr_setcolor( BM_XRGB(0,0,0) );
500 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
502 WIN(DDGRUNLOCK(dd_grd_curcanv));
505 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
510 gr_get_string_size(text, &w1, &h1, &aw );
519 nm_string_black( b, w, x, y, text );
522 gr_string( x+w1+1, y, CURSOR_STRING );
526 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
531 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
533 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
535 if (item->text[0]=='\t')
536 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
541 grd_curcanv->cv_font = SELECTED_FONT;
543 grd_curcanv->cv_font = NORMAL_FONT;
546 if (is_current && item->type == NM_TYPE_TEXT)
547 grd_curcanv->cv_font = NORMAL_FONT;
551 WIN(DDGRLOCK(dd_grd_curcanv));
552 switch( item->type ) {
554 // grd_curcanv->cv_font=TEXT_FONT;
555 // fall through on purpose
558 nm_string( b, item->w, item->x, item->y, item->text );
560 case NM_TYPE_SLIDER: {
562 if (item->value < item->min_value) item->value=item->min_value;
563 if (item->value > item->max_value) item->value=item->max_value;
564 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
565 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
566 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
568 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
570 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
572 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
575 case NM_TYPE_INPUT_MENU:
576 if ( item->group==0 ) {
577 nm_string( b, item->w, item->x, item->y, item->text );
579 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
583 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
586 nm_string( b, item->w, item->x, item->y, item->text );
588 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
590 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
593 nm_string( b, item->w, item->x, item->y, item->text );
595 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
597 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
599 case NM_TYPE_NUMBER: {
601 if (item->value < item->min_value) item->value=item->min_value;
602 if (item->value > item->max_value) item->value=item->max_value;
603 nm_string( b, item->w, item->x, item->y, item->text );
604 sprintf( text, "%d", item->value );
605 nm_rstring( b,item->right_offset,item->x, item->y, text );
609 WIN(DDGRUNLOCK(dd_grd_curcanv));
613 char *Newmenu_allowed_chars=NULL;
615 //returns true if char is allowed
616 int char_allowed(char c)
618 char *p = Newmenu_allowed_chars;
626 if (c>=p[0] && c<=p[1])
635 void strip_end_whitespace( char * text )
639 for (i=l-1; i>=0; i-- ) {
640 if ( isspace(text[i]) )
647 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
649 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
651 int newmenu_dotiny( 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, LHX(310), -1, 1 );
657 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
659 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
663 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 )
665 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
669 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 )
671 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
673 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 )
675 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
678 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){
679 set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
680 // return newmenu_do3_real( title, subtitle, nitems, item, subfunction, citem, filename, width,height, GAME_FONT, GAME_FONT, GAME_FONT, GAME_FONT);
681 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width,height, 0);
684 //returns 1 if a control device button has been pressed
685 int check_button_press()
689 switch (Config_control_type) {
690 case CONTROL_JOYSTICK:
691 case CONTROL_FLIGHTSTICK_PRO:
692 case CONTROL_THRUSTMASTER_FCS:
693 case CONTROL_GRAVIS_GAMEPAD:
695 if (joy_get_button_down_cnt(i)>0) return 1;
698 case CONTROL_CYBERMAN:
699 #ifndef NEWMENU_MOUSE // don't allow mouse to continue from menu
701 if (mouse_button_down_count(i)>0) return 1;
704 case CONTROL_WINJOYSTICK:
707 if (joy_get_button_down_cnt(i)>0) return 1;
710 case CONTROL_NONE: //keyboard only
712 if (key_checkch()) return 1;
717 Error("Bad control type (Config_control_type):%i",Config_control_type);
723 extern int network_request_player_names(int);
724 extern int RestoringMenu;
727 ubyte Hack_DblClick_MenuMode=0;
731 extern ubyte joydefs_calibrating;
733 # define joydefs_calibrating 0
736 #define CLOSE_X (MenuHires?15:7)
737 #define CLOSE_Y (MenuHires?15:7)
738 #define CLOSE_SIZE (MenuHires?10:5)
740 void draw_close_box(int x,int y)
742 WIN (DDGRLOCK(dd_grd_curcanv));
743 gr_setcolor( BM_XRGB(0, 0, 0) );
744 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
745 gr_setcolor( BM_XRGB(21, 21, 21) );
746 gr_rect(x + CLOSE_X + LHX(1), y + CLOSE_Y + LHX(1), x + CLOSE_X + CLOSE_SIZE - LHX(1), y + CLOSE_Y + CLOSE_SIZE - LHX(1));
747 WIN (DDGRUNLOCK(dd_grd_curcanv));
750 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 )
752 int old_keyd_repeat, done;
753 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
754 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
755 grs_font * save_font;
756 int string_width, string_height, average_width;
759 int all_text=0; //set true if all text items
760 int sound_stopped=0,time_stopped=0;
761 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
764 int MaxOnMenu=MAXDISPLAYABLEITEMS;
765 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
767 int mouse_state, omouse_state, dblclick_flag=0;
768 int mx=0, my=0, x1 = 0, x2, y1, y2;
772 EventRecord event; // looking for disk inserted events for CD mounts
775 PA_DFX (pa_set_frontbuffer_current());
776 PA_DFX (pa_set_front_to_read());
778 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
779 newmenu_hide_cursor();
786 WIN(mouse_set_mode(0)); //disable centering mode
788 MaxDisplayable=nitems;
790 //set_screen_mode(SCREEN_MENU);
793 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
794 digi_pause_digi_sounds();
798 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
811 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
813 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
815 save_font = grd_curcanv->cv_font;
820 grd_curcanv->cv_font = TITLE_FONT;
821 gr_get_string_size(title,&string_width,&string_height,&average_width );
826 grd_curcanv->cv_font = SUBTITLE_FONT;
827 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
828 if (string_width > tw )
833 th += LHY(8); //put some space between titles & body
836 grd_curcanv->cv_font = SMALL_FONT;
838 grd_curcanv->cv_font = NORMAL_FONT;
842 nmenus = nothers = 0;
844 // Find menu height & width (store in w,h)
845 for (i=0; i<nitems; i++ ) {
848 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
849 item[i].right_offset = 0;
852 string_height+=LHY(3);
854 item[i].saved_text[0] = '\0';
856 if ( item[i].type == NM_TYPE_SLIDER ) {
859 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
860 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
861 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
863 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
864 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
865 string_width += w1 + aw;
868 if ( item[i].type == NM_TYPE_MENU ) {
872 if ( item[i].type == NM_TYPE_CHECK ) {
875 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
876 item[i].right_offset = w1;
877 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
878 if (w1 > item[i].right_offset)
879 item[i].right_offset = w1;
882 if (item[i].type == NM_TYPE_RADIO ) {
885 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
886 item[i].right_offset = w1;
887 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
888 if (w1 > item[i].right_offset)
889 item[i].right_offset = w1;
892 if (item[i].type==NM_TYPE_NUMBER ) {
896 sprintf( test_text, "%d", item[i].max_value );
897 gr_get_string_size( test_text, &w1, &h1, &aw1 );
898 item[i].right_offset = w1;
899 sprintf( test_text, "%d", item[i].min_value );
900 gr_get_string_size( test_text, &w1, &h1, &aw1 );
901 if ( w1 > item[i].right_offset)
902 item[i].right_offset = w1;
905 if ( item[i].type == NM_TYPE_INPUT ) {
906 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
907 strcpy(item[i].saved_text, item[i].text );
909 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
910 if ( string_width > MAX_TEXT_WIDTH )
911 string_width = MAX_TEXT_WIDTH;
915 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
916 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
917 strcpy(item[i].saved_text, item[i].text );
919 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
924 item[i].w = string_width;
925 item[i].h = string_height;
927 if ( string_width > w )
928 w = string_width; // Save maximum width
929 if ( average_width > aw )
931 h += string_height+1; // Find the height of all strings
934 // Big hack for allowing the netgame options menu to spill over
936 MaxOnMenu=MAXDISPLAYABLEITEMS;
937 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
940 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
943 h=(MaxOnMenu*(string_height+1)+LHY(8));
944 MaxDisplayable=MaxOnMenu;
945 mprintf ((0,"Hey, this is a scroll box!\n"));
958 for (i=0; i<nitems; i++ ) {
960 if (item[i].right_offset > right_offset )
961 right_offset = item[i].right_offset;
963 if (right_offset > 0 )
966 //gr_get_string_size("",&string_width,&string_height,&average_width );
973 twidth = ( tw - w )/2;
978 { right_offset=0; twidth=0;}
980 mprintf(( 0, "Right offset = %d\n", right_offset ));
983 // Find min point of menu border
984 // x = (grd_curscreen->sc_w-w)/2;
985 // y = (grd_curscreen->sc_h-h)/2;
987 w += MenuHires?60:30;
988 h += MenuHires?60:30;
990 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
991 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
993 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
994 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
999 if ( filename != NULL ) {
1000 nm_draw_background1( filename );
1001 gr_palette_load(gr_palette);
1004 // Save the background of the display
1005 // Win95 must refer to the screen as a dd_grs_canvas, so...
1006 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
1007 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
1009 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
1010 gr_set_current_canvas(bg.menu_canvas) );
1012 if ( filename == NULL ) {
1013 // Save the background under the menu...
1019 #if defined(POLY_ACC)
1020 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1022 bg.saved = gr_create_bitmap( w, h );
1024 Assert( bg.saved != NULL );
1026 WIN (DDGRLOCK(dd_grd_curcanv));
1027 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
1028 WIN (DDGRUNLOCK(dd_grd_curcanv));
1030 WINDOS ( dd_gr_set_current_canvas(NULL),
1031 gr_set_current_canvas( NULL )
1034 nm_draw_background(x,y,x+w-1,y+h-1);
1036 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1037 gr_set_current_canvas( bg.menu_canvas )
1040 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1044 #if defined(POLY_ACC)
1045 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1047 bg.background = gr_create_bitmap( w, h );
1049 Assert( bg.background != NULL );
1051 WIN (DDGRLOCK(dd_grd_curcanv));
1052 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1053 WIN (DDGRUNLOCK(dd_grd_curcanv));
1056 // ty = 15 + (yborder/4);
1058 ty = MenuHires?30:15;
1061 grd_curcanv->cv_font = TITLE_FONT;
1062 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1063 gr_get_string_size(title,&string_width,&string_height,&average_width );
1066 WIN (DDGRLOCK(dd_grd_curcanv));
1067 gr_printf( 0x8000, ty, title );
1068 WIN (DDGRUNLOCK(dd_grd_curcanv));
1073 grd_curcanv->cv_font = SUBTITLE_FONT;
1074 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1075 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1078 WIN (DDGRLOCK(dd_grd_curcanv));
1079 gr_printf( 0x8000, ty, subtitle );
1080 WIN (DDGRUNLOCK(dd_grd_curcanv));
1085 grd_curcanv->cv_font = SMALL_FONT;
1087 grd_curcanv->cv_font = NORMAL_FONT;
1089 // Update all item's x & y values.
1090 for (i=0; i<nitems; i++ ) {
1091 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1092 item[i].y += (MenuHires?30:15);
1093 if ( item[i].type==NM_TYPE_RADIO ) {
1094 fm = -1; // find first marked one
1095 for ( j=0; j<nitems; j++ ) {
1096 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1097 if (fm==-1 && item[j].value)
1109 old_keyd_repeat = keyd_repeat;
1115 if (citem < 0 ) citem = 0;
1116 if (citem > nitems-1 ) citem = nitems-1;
1119 #ifdef NEWMENU_MOUSE
1123 while ( item[choice].type==NM_TYPE_TEXT ) {
1125 if (choice >= nitems ) {
1128 if (choice == citem ) {
1139 // Clear mouse, joystick to clear button presses.
1140 game_flush_inputs();
1142 #ifdef NEWMENU_MOUSE
1143 mouse_state = omouse_state = 0;
1144 if (filename == NULL && !MenuReordering) {
1145 draw_close_box(0,0);
1149 if (!MenuReordering && !joydefs_calibrating)
1151 newmenu_show_cursor();
1153 SetCursor(LoadCursor(NULL,IDC_ARROW));
1158 mprintf ((0,"Set to true!\n"));
1164 DoMessageStuff(&msg);
1166 if (_RedrawScreen) {
1167 _RedrawScreen = FALSE;
1170 gr_free_bitmap(bg.saved);
1171 d_free( bg.background );
1174 gr_free_bitmap(bg.background);
1176 dd_gr_free_sub_canvas( bg.menu_canvas );
1177 grd_curcanv->cv_font = save_font;
1178 dd_grd_curcanv = save_canvas;
1180 goto RePaintNewmenu4;
1187 #ifdef NEWMENU_MOUSE
1188 if (!joydefs_calibrating)
1189 newmenu_show_cursor(); // possibly hidden
1190 omouse_state = mouse_state;
1191 if (!MenuReordering)
1192 mouse_state = mouse_button_state(0);
1193 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1196 //see if redbook song needs to be restarted
1197 songs_check_redbook_repeat();
1204 (*subfunction)(nitems,item,&k,choice);
1207 if (!time_stopped) {
1208 // Save current menu box
1209 if (multi_menu_poll() == -1)
1215 dont_restore = (k == -3); //-3 means don't restore
1221 if (check_button_press())
1225 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1228 old_choice = choice;
1234 if (SurfingNet && !already_showing_info)
1236 show_extra_netgame_info(choice-2);
1238 if (SurfingNet && already_showing_info)
1245 if (SurfingNet && !already_showing_info)
1247 network_request_player_names(choice-2);
1249 if (SurfingNet && already_showing_info)
1264 case KEY_TAB + KEY_SHIFTED:
1267 if (all_text) break;
1274 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1276 if (choice<TopChoice)
1277 { choice=TopChoice; break; }
1279 if (choice<ScrollOffset)
1281 for (i=0;i<nitems;i++)
1284 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1289 if (choice >= nitems ) choice=0;
1290 if (choice < 0 ) choice=nitems-1;
1292 } while ( item[choice].type==NM_TYPE_TEXT );
1293 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1294 item[choice].value = -1;
1295 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1296 item[old_choice].group=0;
1297 strcpy(item[old_choice].text, item[old_choice].saved_text );
1298 item[old_choice].value = -1;
1301 item[old_choice].redraw = 1;
1302 item[choice].redraw=1;
1307 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1308 if (all_text) break;
1315 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1318 { choice--; break; }
1320 if (choice>=MaxOnMenu+ScrollOffset)
1322 for (i=0;i<nitems;i++)
1325 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1330 if (choice < 0 ) choice=nitems-1;
1331 if (choice >= nitems ) choice=0;
1334 } while ( item[choice].type==NM_TYPE_TEXT );
1336 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1337 item[choice].value = -1;
1338 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1339 item[old_choice].group=0;
1340 strcpy(item[old_choice].text, item[old_choice].saved_text );
1341 item[old_choice].value = -1;
1344 item[old_choice].redraw=1;
1345 item[choice].redraw=1;
1348 if ( choice > -1 ) {
1349 switch( item[choice].type ) {
1352 case NM_TYPE_INPUT_MENU:
1355 if ( item[choice].value )
1356 item[choice].value = 0;
1358 item[choice].value = 1;
1359 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1362 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1364 mprintf ((0,"Special redraw!\n"));
1369 item[choice].redraw=1;
1372 for (i=0; i<nitems; i++ ) {
1373 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1378 item[choice].value = 1;
1379 item[choice].redraw = 1;
1385 case KEY_SHIFTED+KEY_UP:
1386 if (MenuReordering && choice!=TopChoice)
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;
1399 case KEY_SHIFTED+KEY_DOWN:
1400 if (MenuReordering && choice!=(nitems-1))
1402 Temp=item[choice].text;
1403 TempVal=item[choice].value;
1404 item[choice].text=item[choice+1].text;
1405 item[choice].value=item[choice+1].value;
1406 item[choice+1].text=Temp;
1407 item[choice+1].value=TempVal;
1408 item[choice].redraw=1;
1409 item[choice+1].redraw=1;
1416 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1417 item[choice].group = 1;
1418 item[choice].redraw = 1;
1419 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1420 item[choice].text[0] = 0;
1421 item[choice].value = -1;
1423 strip_end_whitespace(item[choice].text);
1430 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1431 item[choice].group=0;
1432 strcpy(item[choice].text, item[choice].saved_text );
1433 item[choice].redraw=1;
1434 item[choice].value = -1;
1441 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1442 case KEY_PRINT_SCREEN:
1443 MAC(newmenu_hide_cursor());
1444 save_screen_shot(0);
1445 PA_DFX (pa_set_frontbuffer_current());
1446 PA_DFX (pa_set_front_to_read());
1447 for (i=0;i<nitems;i++)
1450 MAC(newmenu_show_cursor());
1456 case KEY_COMMAND+KEY_RIGHT:
1457 songs_goto_next_song();
1459 case KEY_COMMAND+KEY_LEFT:
1460 songs_goto_prev_song();
1462 case KEY_COMMAND+KEY_UP:
1463 songs_play_level_song(1);
1465 case KEY_COMMAND+KEY_DOWN:
1466 songs_stop_redbook();
1469 case KEY_COMMAND+KEY_M:
1471 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1472 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1475 key_close(); // no processing of keys with keyboard handler.. jeez
1477 newmenu_hide_cursor();
1478 show_boxed_message ("Mounting CD\nESC to quit");
1479 RBAMountDisk(); // OS has totaly control of the CD.
1480 if (Function_mode == FMODE_MENU)
1481 songs_play_song(SONG_TITLE,1);
1482 else if (Function_mode == FMODE_GAME)
1483 songs_play_level_song( Current_level_num );
1484 clear_boxed_message();
1485 newmenu_show_cursor();
1493 case KEY_COMMAND+KEY_E:
1494 songs_stop_redbook();
1496 k = -1; // force key not to register
1499 case KEY_COMMAND+KEY_Q: {
1500 extern void macintosh_quit();
1502 if ( !(Game_mode & GM_MULTI) )
1504 if (!joydefs_calibrating)
1505 newmenu_show_cursor();
1506 k = -1; // force key not to register
1513 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1520 #ifdef NEWMENU_MOUSE // for mouse selection of menu's etc.
1522 if ( !done && mouse_state && !omouse_state && !all_text ) {
1523 mouse_get_pos(&mx, &my);
1524 for (i=0; i<nitems; i++ ) {
1525 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1526 x2 = x1 + item[i].w;
1527 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1528 y2 = y1 + item[i].h;
1529 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1530 if (i+ScrollOffset != choice) {
1531 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1534 choice = i + ScrollOffset;
1536 switch( item[choice].type ) {
1538 if ( item[choice].value )
1539 item[choice].value = 0;
1541 item[choice].value = 1;
1542 item[choice].redraw=1;
1549 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1551 mprintf ((0,"Special redraw!\n"));
1558 for (i=0; i<nitems; i++ ) {
1559 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1564 item[choice].value = 1;
1565 item[choice].redraw = 1;
1568 item[old_choice].redraw=1;
1574 if (mouse_state && all_text)
1577 if ( !done && mouse_state && !all_text ) {
1578 mouse_get_pos(&mx, &my);
1580 // check possible scrollbar stuff first
1582 int arrow_width, arrow_height, aw;
1584 if (ScrollOffset != 0) {
1585 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1586 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1587 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1588 x1 = x1 - arrow_width;
1589 y2 = y1 + arrow_height;
1590 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1593 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1595 if (choice<ScrollOffset)
1597 for (i=0;i<nitems;i++)
1600 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1604 if (ScrollOffset+MaxDisplayable<nitems) {
1605 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1606 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1607 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1608 x1 = x1 - arrow_width;
1609 y2 = y1 + arrow_height;
1610 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1613 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1615 if (choice>=MaxOnMenu+ScrollOffset)
1617 for (i=0;i<nitems;i++)
1620 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1626 for (i=0; i<nitems; i++ ) {
1627 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1628 x2 = x1 + item[i].w;
1629 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1630 y2 = y1 + item[i].h;
1631 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1632 if (i+ScrollOffset != choice) {
1633 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1636 choice = i + ScrollOffset;
1638 if ( item[choice].type == NM_TYPE_SLIDER ) {
1639 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1640 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1642 strcpy(slider_text, item[choice].saved_text);
1643 p = strchr(slider_text, '\t');
1649 gr_get_string_size(s1, &slider_width, &height, &aw);
1650 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1651 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1652 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1654 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1655 x2 = x1 + slider_width + sright_width;
1656 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1657 item[choice].value = item[choice].min_value;
1658 item[choice].redraw = 2;
1659 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1660 item[choice].value = item[choice].max_value;
1661 item[choice].redraw = 2;
1662 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1663 int num_values, value_width, new_value;
1665 num_values = item[choice].max_value - item[choice].min_value + 1;
1666 value_width = (slider_width - sleft_width - sright_width) / num_values;
1667 new_value = (mx - x1 - sleft_width) / value_width;
1668 if ( item[choice].value != new_value ) {
1669 item[choice].value = new_value;
1670 item[choice].redraw = 2;
1676 if (choice == old_choice)
1678 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1679 item[choice].value = -1;
1680 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1681 item[old_choice].group=0;
1682 strcpy(item[old_choice].text, item[old_choice].saved_text );
1683 item[old_choice].value = -1;
1686 item[old_choice].redraw = 1;
1687 item[choice].redraw=1;
1693 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1694 mouse_get_pos(&mx, &my);
1695 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1696 x2 = x1 + item[choice].w;
1697 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1698 y2 = y1 + item[choice].h;
1699 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1700 if (Hack_DblClick_MenuMode) {
1701 if (dblclick_flag) done = 1;
1702 else dblclick_flag = 1;
1708 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1709 item[choice].group = 1;
1710 item[choice].redraw = 1;
1711 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1712 item[choice].text[0] = 0;
1713 item[choice].value = -1;
1715 strip_end_whitespace(item[choice].text);
1719 if ( !done && !mouse_state && omouse_state && close_box ) {
1720 mouse_get_pos(&mx, &my);
1721 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1722 x2 = x1 + CLOSE_SIZE;
1723 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1724 y2 = y1 + CLOSE_SIZE;
1725 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1731 // HACK! Don't redraw loadgame preview
1732 if (RestoringMenu) item[0].redraw = 0;
1733 #endif // NEWMENU_MOUSE
1735 if ( choice > -1 ) {
1738 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1739 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1740 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1741 if (item[choice].value > 0)
1742 item[choice].value--;
1743 item[choice].text[item[choice].value] = 0;
1744 item[choice].redraw = 1;
1746 ascii = key_to_ascii(k);
1747 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1751 if (item[choice].value==-1) {
1752 item[choice].value = 0;
1755 allowed = char_allowed(ascii);
1757 if (!allowed && ascii==' ' && char_allowed('_')) {
1763 item[choice].text[item[choice].value++] = ascii;
1764 item[choice].text[item[choice].value] = 0;
1765 item[choice].redraw=1;
1769 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1770 ascii = key_to_ascii(k);
1772 int choice1 = choice;
1773 ascii = toupper(ascii);
1777 if (choice1 >= nitems ) choice1=0;
1778 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1779 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1780 (item[choice1].type==NM_TYPE_CHECK) ||
1781 (item[choice1].type==NM_TYPE_RADIO) ||
1782 (item[choice1].type==NM_TYPE_NUMBER) ||
1783 (item[choice1].type==NM_TYPE_SLIDER) )
1784 && (ascii==toupper(ch)) ) {
1788 item[old_choice].redraw=1;
1789 item[choice].redraw=1;
1791 } while (choice1 != choice );
1795 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1796 int ov=item[choice].value;
1801 case KEY_MINUS+KEY_SHIFTED:
1803 item[choice].value -= 1;
1808 case KEY_EQUAL+KEY_SHIFTED:
1810 item[choice].value++;
1815 item[choice].value += 10;
1820 item[choice].value -= 10;
1823 if (ov!=item[choice].value)
1824 item[choice].redraw=1;
1829 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1830 gr_set_current_canvas(bg.menu_canvas));
1832 // Redraw everything...
1833 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1835 if (item[i].redraw) // warning! ugly hack below
1837 item[i].y-=((string_height+1)*ScrollOffset);
1838 newmenu_hide_cursor();
1839 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1841 #ifdef NEWMENU_MOUSE
1842 if (!MenuReordering && !joydefs_calibrating)
1843 newmenu_show_cursor();
1845 item[i].y+=((string_height+1)*ScrollOffset);
1847 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1848 update_cursor( &item[i]);
1854 //grd_curcanv->cv_font = NORMAL_FONT;
1856 if (LastScrollCheck!=ScrollOffset)
1858 LastScrollCheck=ScrollOffset;
1859 grd_curcanv->cv_font = SELECTED_FONT;
1861 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1862 sx=item[ScrollOffset].x-(MenuHires?24:12);
1865 if (ScrollOffset!=0)
1866 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1868 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1870 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1871 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1873 if (ScrollOffset+MaxDisplayable<nitems)
1874 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1876 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1882 if ( !dont_restore && gr_palette_faded_out ) {
1883 gr_palette_fade_in( gr_palette, 32, 0 );
1887 newmenu_hide_cursor();
1889 // Restore everything...
1891 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1892 gr_set_current_canvas(bg.menu_canvas));
1894 if ( filename == NULL ) {
1895 // Save the background under the menu...
1896 WIN (DDGRLOCK(dd_grd_curcanv));
1897 gr_bitmap(0, 0, bg.saved);
1898 WIN (DDGRUNLOCK(dd_grd_curcanv));
1899 gr_free_bitmap(bg.saved);
1900 d_free( bg.background );
1902 if (!dont_restore) //info passed back from subfunction
1904 WIN (DDGRLOCK(dd_grd_curcanv));
1905 gr_bitmap(0, 0, bg.background);
1906 WIN (DDGRUNLOCK(dd_grd_curcanv));
1908 gr_free_bitmap(bg.background);
1911 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1912 gr_free_sub_canvas( bg.menu_canvas ) );
1914 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1915 grd_curcanv->cv_font = save_font;
1916 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1917 keyd_repeat = old_keyd_repeat;
1919 game_flush_inputs();
1930 if ( sound_stopped )
1931 digi_resume_digi_sounds();
1933 WIN(mouse_set_mode(1)); //re-enable centering mode
1940 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1946 char nm_text[MESSAGEBOX_TEXT_SIZE];
1947 newmenu_item nm_message_items[5];
1949 va_start(args, nchoices );
1951 Assert( nchoices <= 5 );
1953 for (i=0; i<nchoices; i++ ) {
1954 s = va_arg( args, char * );
1955 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1957 format = va_arg( args, char * );
1958 strcpy( nm_text, "" );
1959 vsprintf(nm_text,format,args);
1962 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1964 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1967 int nm_messagebox( char *title, int nchoices, ... )
1973 char nm_text[MESSAGEBOX_TEXT_SIZE];
1974 newmenu_item nm_message_items[5];
1976 va_start(args, nchoices );
1978 Assert( nchoices <= 5 );
1980 for (i=0; i<nchoices; i++ ) {
1981 s = va_arg( args, char * );
1982 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1984 format = va_arg( args, char * );
1985 strcpy( nm_text, "" );
1986 vsprintf(nm_text,format,args);
1989 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1991 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1997 void newmenu_file_sort( int n, char *list )
2004 for (i=incr; i<n; i++ ) {
2007 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
2008 memcpy( t, &list[j*14], FILENAME_LEN );
2009 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
2010 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
2021 void delete_player_saved_games(char * name)
2026 for (i=0;i<10; i++) {
2028 sprintf( filename, "%s.sg%d", name, i );
2030 sprintf( filename, ":Players:%s.sg%d", name, i );
2032 cfile_delete(filename);
2036 #define MAX_FILES 300
2038 int MakeNewPlayerFile(int allow_abort);
2040 extern char AltHogDir[64];
2041 extern char AltHogdir_initialized;
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 #ifdef NEWMENU_MOUSE
2061 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2062 int mouse2_state, omouse2_state;
2063 int dblclick_flag=0;
2066 int show_up_arrow=0,show_down_arrow=0;
2069 WIN(int win_redraw=0);
2071 w_x=w_y=w_w=w_h=title_height=0;
2072 box_x=box_y=box_w=box_h=0;
2074 filenames = d_malloc( MAX_FILES * 14 );
2075 if (filenames==NULL) return 0;
2080 WIN(mouse_set_mode(0)); //disable centering mode
2082 if (strstr( filespec, "*.plr" ))
2084 else if (strstr( filespec, "*.dem" ))
2091 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2093 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2098 if( !FileFindFirst( filespec, &find ) ) {
2100 if (NumFiles<MAX_FILES) {
2101 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2102 if ( player_mode ) {
2104 p = strchr(&filenames[NumFiles*14],'.');
2111 } while( !FileFindNext( &find ) );
2115 if (demo_mode && AltHogdir_initialized) {
2116 char filespec2[PATH_MAX + FILENAME_LEN];
2117 strcpy(filespec2, AltHogDir);
2118 strcat(filespec2, "/");
2119 strcat(filespec2, filespec);
2120 if ( !FileFindFirst( filespec2, &find ) ) {
2122 if (NumFiles<MAX_FILES) {
2123 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2128 } while( !FileFindNext( &find ) );
2133 if ( (NumFiles < 1) && demos_deleted ) {
2137 if ( (NumFiles < 1) && demo_mode ) {
2138 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2144 if ( (NumFiles < 2) && player_mode ) {
2146 goto ExitFileMenuEarly;
2153 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2160 // set_screen_mode(SCREEN_MENU);
2166 dd_gr_set_current_canvas(NULL);
2168 gr_set_current_canvas(NULL);
2171 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2173 grd_curcanv->cv_font = SUBTITLE_FONT;
2175 WIN(DDGRUNLOCK(dd_grd_curcanv));
2180 for (i=0; i<NumFiles; i++ ) {
2182 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2188 gr_get_string_size( title, &w, &h, &aw );
2191 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2195 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2197 w_w += (grd_curfont->ft_w * 4);
2198 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2200 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2201 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2203 w_x = (grd_curcanv->cv_w-w_w)/2;
2204 w_y = (grd_curcanv->cv_h-w_h)/2;
2206 if ( w_x < 0 ) w_x = 0;
2207 if ( w_y < 0 ) w_y = 0;
2209 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2210 box_y = w_y + title_height;
2212 // save the screen behind the menu.
2216 #if !defined(WINDOWS)
2217 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2218 bg.background = &VR_offscreen_buffer->cv_bitmap;
2221 #if defined(POLY_ACC)
2222 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2224 bg.background = gr_create_bitmap( w_w, w_h );
2227 Assert( bg.background != NULL );
2230 WIN(DDGRLOCK(dd_grd_curcanv));
2231 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2232 WIN(DDGRUNLOCK(dd_grd_curcanv));
2236 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2237 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2238 dd_VR_offscreen_buffer, 0, 0,
2239 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2240 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2244 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2246 WIN(DDGRLOCK(dd_grd_curcanv))
2248 gr_string( 0x8000, w_y+10, title );
2250 WIN(DDGRUNLOCK(dd_grd_curcanv));
2257 if ( !player_mode ) {
2258 newmenu_file_sort( NumFiles, filenames );
2260 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2261 newmenu_file_sort( NumFiles, filenames );
2263 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2265 for ( i=0; i<NumFiles; i++ ) {
2266 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2267 #ifdef NEWMENU_MOUSE
2275 #ifdef NEWMENU_MOUSE
2276 mouse_state = omouse_state = 0;
2277 mouse2_state = omouse2_state = 0;
2278 draw_close_box(w_x,w_y);
2279 newmenu_show_cursor();
2286 DoMessageStuff(&msg);
2288 if (_RedrawScreen) {
2289 _RedrawScreen = FALSE;
2291 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2292 gr_free_bitmap(bg.background);
2295 goto RePaintNewmenuFile;
2302 ofirst_item = first_item;
2305 #ifdef NEWMENU_MOUSE
2306 omouse_state = mouse_state;
2307 omouse2_state = mouse2_state;
2308 mouse_state = mouse_button_state(0);
2309 mouse2_state = mouse_button_state(1);
2312 //see if redbook song needs to be restarted
2313 songs_check_redbook_repeat();
2316 if (!mouse2_state && omouse2_state)
2317 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2320 //NOTE LINK TO ABOVE ELSE
2326 else if (simukey==1)
2332 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2333 case KEY_PRINT_SCREEN:
2334 MAC(newmenu_hide_cursor());
2335 save_screen_shot(0);
2336 PA_DFX (pa_set_frontbuffer_current());
2337 PA_DFX (pa_set_front_to_read());
2339 MAC(newmenu_show_cursor());
2343 case KEY_CTRLED+KEY_D:
2344 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2348 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2351 mouse_set_mode(1); //re-enable centering mode
2353 newmenu_hide_cursor();
2355 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2357 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2359 mouse_set_mode(0); //disenable centering mode
2361 newmenu_show_cursor();
2365 char name[_MAX_PATH],dir[_MAX_DIR];
2367 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2371 _splitpath(filespec,name,dir,NULL,NULL);
2373 strcat(name,&filenames[citem*14]);
2380 if ( !strncmp(name, ".\\", 2) )
2381 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2382 name[i] = name[i+1];
2383 while ( (p = strchr(name, '\\')) )
2388 ret = cfile_delete(name);
2392 if ((!ret) && player_mode) {
2393 delete_player_saved_games( &filenames[citem*14] );
2398 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2400 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2401 } else if (demo_mode)
2426 citem += NumFiles_displayed;
2430 citem -= NumFiles_displayed;
2433 if (allow_abort_flag) {
2444 case KEY_COMMAND+KEY_Q: {
2445 extern void macintosh_quit();
2447 if ( !(Game_mode & GM_MULTI) )
2449 newmenu_show_cursor();
2458 int ascii = key_to_ascii(key);
2459 if ( ascii < 255 ) {
2462 if (cc1 < 0 ) cc1 = 0;
2463 if (cc1 >= NumFiles ) cc1 = 0;
2465 if ( cc < 0 ) cc = 0;
2466 if ( cc >= NumFiles ) cc = 0;
2467 if ( citem == cc ) break;
2469 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2484 if (citem>=NumFiles)
2487 if (citem< first_item)
2490 if (citem>=( first_item+NumFiles_displayed))
2492 first_item = citem-NumFiles_displayed+1;
2496 if (NumFiles>first_item+NumFiles_displayed)
2507 if (NumFiles <= NumFiles_displayed )
2510 if (first_item>NumFiles-NumFiles_displayed)
2512 first_item = NumFiles-NumFiles_displayed;
2515 if (first_item < 0 ) first_item = 0;
2517 #ifdef NEWMENU_MOUSE
2519 if (mouse_state || mouse2_state) {
2522 mouse_get_pos(&mx, &my);
2523 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2524 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2526 x2 = box_x + box_w - 1;
2527 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2529 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2530 if (i == citem && !mouse2_state) {
2540 if (!mouse_state && omouse_state) {
2543 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2544 mouse_get_pos(&mx, &my);
2546 x2 = box_x + box_w - 1;
2547 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2549 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2550 if (dblclick_flag) done = 1;
2551 else dblclick_flag = 1;
2555 if ( !mouse_state && omouse_state ) {
2556 mouse_get_pos(&mx, &my);
2557 x1 = w_x + CLOSE_X + 2;
2558 x2 = x1 + CLOSE_SIZE - 2;
2559 y1 = w_y + CLOSE_Y + 2;
2560 y2 = y1 + CLOSE_SIZE - 2;
2561 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2570 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2572 y1 = box_y+box_h-LHY(7);
2574 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2581 WIN(DDGRLOCK(dd_grd_curcanv));
2582 gr_setcolor( BM_XRGB(2,2,2));
2583 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2584 gr_setcolor( BM_XRGB( 0,0,0) );
2587 if (ofirst_item != first_item || win_redraw) {
2590 if (ofirst_item != first_item) {
2592 newmenu_hide_cursor();
2593 gr_setcolor( BM_XRGB( 0,0,0) );
2594 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2596 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2598 if ( i >= NumFiles ) {
2600 gr_setcolor( BM_XRGB(5,5,5));
2601 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2602 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2604 gr_setcolor( BM_XRGB(2,2,2));
2605 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2607 gr_setcolor( BM_XRGB(0,0,0));
2608 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2612 grd_curcanv->cv_font = SELECTED_FONT;
2614 grd_curcanv->cv_font = NORMAL_FONT;
2615 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2617 gr_setcolor( BM_XRGB(5,5,5));
2618 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2619 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2621 gr_setcolor( BM_XRGB(2,2,2));
2622 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2623 gr_setcolor( BM_XRGB(0,0,0));
2625 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2626 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2629 newmenu_show_cursor();
2630 } else if ( citem != ocitem ) {
2633 newmenu_hide_cursor();
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_w - 1, y + h + 1 );
2643 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2646 if ( (i>=0) && (i<NumFiles) ) {
2647 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2649 grd_curcanv->cv_font = SELECTED_FONT;
2651 grd_curcanv->cv_font = NORMAL_FONT;
2652 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2653 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2654 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2656 newmenu_show_cursor();
2660 grd_curcanv->cv_font = NORMAL_FONT;
2662 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2666 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2670 if (show_down_arrow)
2671 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2675 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2683 WIN(DDGRUNLOCK(dd_grd_curcanv));
2687 MAC(newmenu_hide_cursor());
2689 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2696 keyd_repeat = old_keyd_repeat;
2698 if ( initialized ) {
2699 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2701 WIN (DDGRLOCK(dd_grd_curcanv));
2702 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2703 WIN (DDGRUNLOCK(dd_grd_curcanv));
2705 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2706 gr_free_bitmap(bg.background);
2709 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2710 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2712 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2713 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2723 WIN(mouse_set_mode(1)); //re-enable centering mode
2724 WIN(newmenu_hide_cursor());
2731 // Example listbox callback function...
2732 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2736 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2737 // if ( *nitems > 1 ) {
2738 // cfile_delete(items[*citem]); // Delete the file
2739 // for (i=*citem; i<*nitems-1; i++ ) {
2740 // items[i] = items[i+1];
2742 // *nitems = *nitems - 1;
2743 // d_free( items[*nitems] );
2744 // items[*nitems] = NULL;
2745 // return 1; // redraw;
2752 #define LB_ITEMS_ON_SCREEN 8
2754 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2756 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2759 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 ) )
2762 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2763 int old_keyd_repeat = keyd_repeat;
2764 int width, height, wx, wy, title_height, border_size;
2765 int total_width,total_height;
2767 #ifdef NEWMENU_MOUSE
2768 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2769 int close_x,close_y;
2771 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2774 WIN(int win_redraw=0);
2778 PA_DFX (pa_set_frontbuffer_current());
2779 PA_DFX (pa_set_front_to_read());
2780 WIN(mouse_set_mode(0)); //disable centering mode
2782 // set_screen_mode(SCREEN_MENU);
2786 RePaintNewmenuListbox:
2788 dd_gr_set_current_canvas(NULL);
2790 gr_set_current_canvas(NULL);
2793 grd_curcanv->cv_font = SUBTITLE_FONT;
2796 for (i=0; i<nitems; i++ ) {
2798 gr_get_string_size( items[i], &w, &h, &aw );
2802 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2806 gr_get_string_size( title, &w, &h, &aw );
2809 title_height = h + 5;
2812 border_size = grd_curfont->ft_w;
2813 WIN (border_size=grd_curfont->ft_w*2);
2815 width += (grd_curfont->ft_w);
2816 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2817 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2819 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2820 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2821 if ( wy < title_height )
2824 total_width = width+2*border_size;
2825 total_height = height+2*border_size+title_height;
2829 #if !defined(WINDOWS)
2830 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2831 bg.background = &VR_offscreen_buffer->cv_bitmap;
2834 //bg.background = gr_create_bitmap( width, (height + title_height) );
2835 #if defined(POLY_ACC)
2836 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2838 bg.background = gr_create_bitmap(total_width,total_height);
2840 Assert( bg.background != NULL );
2842 WIN (DDGRLOCK(dd_grd_curcanv));
2843 //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 );
2844 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2845 WIN (DDGRUNLOCK(dd_grd_curcanv));
2849 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2850 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2851 dd_VR_offscreen_buffer, 0, 0,
2852 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2853 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2857 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2859 WIN(DDGRLOCK(dd_grd_curcanv));
2860 gr_string( 0x8000, wy - title_height, title );
2861 WIN(DDGRUNLOCK(dd_grd_curcanv));
2866 citem = default_item;
2867 if ( citem < 0 ) citem = 0;
2868 if ( citem >= nitems ) citem = 0;
2872 #ifdef NEWMENU_MOUSE
2873 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2874 close_x = wx-border_size;
2875 close_y = wy-title_height-border_size;
2876 draw_close_box(close_x,close_y);
2877 newmenu_show_cursor();
2884 DoMessageStuff(&msg);
2886 if (_RedrawScreen) {
2887 _RedrawScreen = FALSE;
2889 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2890 gr_free_bitmap(bg.background);
2892 goto RePaintNewmenuListbox;
2899 ofirst_item = first_item;
2900 #ifdef NEWMENU_MOUSE
2901 omouse_state = mouse_state;
2902 mouse_state = mouse_button_state(0);
2904 //see if redbook song needs to be restarted
2905 songs_check_redbook_repeat();
2909 if ( listbox_callback )
2910 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2931 else if (simukey==1)
2937 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2938 case KEY_PRINT_SCREEN:
2939 MAC(newmenu_hide_cursor());
2940 save_screen_shot(0);
2941 PA_DFX (pa_set_frontbuffer_current());
2942 PA_DFX (pa_set_front_to_read());
2944 MAC(newmenu_show_cursor());
2965 citem += LB_ITEMS_ON_SCREEN;
2969 citem -= LB_ITEMS_ON_SCREEN;
2972 if (allow_abort_flag) {
2983 case KEY_COMMAND+KEY_Q: {
2984 extern void macintosh_quit();
2986 if ( !(Game_mode & GM_MULTI) )
2988 newmenu_show_cursor();
2996 int ascii = key_to_ascii(key);
2997 if ( ascii < 255 ) {
3000 if (cc1 < 0 ) cc1 = 0;
3001 if (cc1 >= nitems ) cc1 = 0;
3003 if ( cc < 0 ) cc = 0;
3004 if ( cc >= nitems ) cc = 0;
3005 if ( citem == cc ) break;
3007 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
3024 if (citem< first_item)
3027 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
3028 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3030 if (nitems <= LB_ITEMS_ON_SCREEN )
3033 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3034 first_item = nitems-LB_ITEMS_ON_SCREEN;
3035 if (first_item < 0 ) first_item = 0;
3038 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3049 #ifdef NEWMENU_MOUSE
3054 mouse_get_pos(&mx, &my);
3055 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3058 gr_get_string_size(items[i], &w, &h, &aw );
3061 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3063 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3075 //no double-click stuff for listbox
3076 //@@if (!mouse_state && omouse_state) {
3079 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3080 //@@ mouse_get_pos(&mx, &my);
3082 //@@ x2 = wx + width;
3083 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3085 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3086 //@@ if (dblclick_flag) done = 1;
3090 //check for close box clicked
3091 if ( !mouse_state && omouse_state ) {
3092 mouse_get_pos(&mx, &my);
3093 x1 = close_x + CLOSE_X + 2;
3094 x2 = x1 + CLOSE_SIZE - 2;
3095 y1 = close_y + CLOSE_Y + 2;
3096 y2 = y1 + CLOSE_SIZE - 2;
3097 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3107 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3109 y1 = total_height-LHY(7);
3111 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3119 if ( (ofirst_item != first_item) || redraw) {
3120 newmenu_hide_cursor();
3121 WIN(DDGRLOCK(dd_grd_curcanv));
3123 gr_setcolor( BM_XRGB( 0,0,0) );
3124 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3126 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3127 if ( i >= nitems ) {
3128 gr_setcolor( BM_XRGB(0,0,0));
3129 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3132 grd_curcanv->cv_font = SELECTED_FONT;
3134 grd_curcanv->cv_font = NORMAL_FONT;
3135 gr_get_string_size(items[i], &w, &h, &aw );
3136 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3137 gr_string( wx+5, y, items[i] );
3142 // If Win95 port, draw up/down arrows on left side of menu
3144 grd_curcanv->cv_font = NORMAL_FONT;
3146 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3150 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3154 if (show_down_arrow)
3155 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3159 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3166 WIN(DDGRUNLOCK(dd_grd_curcanv));
3167 newmenu_show_cursor();
3169 } else if ( citem != ocitem ) {
3172 newmenu_hide_cursor();
3174 WIN(DDGRLOCK(dd_grd_curcanv));
3177 if ( (i>=0) && (i<nitems) ) {
3178 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3180 grd_curcanv->cv_font = SELECTED_FONT;
3182 grd_curcanv->cv_font = NORMAL_FONT;
3183 gr_get_string_size(items[i], &w, &h, &aw );
3184 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3185 gr_string( wx+5, y, items[i] );
3189 if ( (i>=0) && (i<nitems) ) {
3190 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3192 grd_curcanv->cv_font = SELECTED_FONT;
3194 grd_curcanv->cv_font = NORMAL_FONT;
3195 gr_get_string_size( items[i], &w, &h, &aw );
3196 gr_rect( wx, y-1, wx+width-1, y+h );
3197 gr_string( wx+5, y, items[i] );
3199 WIN(DDGRUNLOCK(dd_grd_curcanv));
3201 newmenu_show_cursor();
3205 newmenu_hide_cursor();
3207 keyd_repeat = old_keyd_repeat;
3209 WIN (DDGRLOCK(dd_grd_curcanv));
3210 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3211 WIN (DDGRUNLOCK(dd_grd_curcanv));
3213 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3214 gr_free_bitmap(bg.background);
3218 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3219 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3221 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3222 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3228 WIN(mouse_set_mode(1)); //re-enable centering mode
3233 int newmenu_filelist( char * title, char * filespec, char * filename )
3236 char * Filenames[MAX_FILES];
3237 char FilenameText[MAX_FILES][14];
3238 FILEFINDSTRUCT find;
3241 if( !FileFindFirst( filespec, &find ) ) {
3243 if (NumFiles<MAX_FILES) {
3244 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3245 Filenames[NumFiles] = FilenameText[NumFiles];
3250 } while( !FileFindNext( &find ) );
3254 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3256 strcpy( filename, Filenames[i] );
3262 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3263 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3269 char nm_text[MESSAGEBOX_TEXT_SIZE];
3270 newmenu_item nm_message_items[5];
3272 va_start(args, nchoices );
3274 Assert( nchoices <= 5 );
3276 for (i=0; i<nchoices; i++ ) {
3277 s = va_arg( args, char * );
3278 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3280 format = va_arg( args, char * );
3281 //sprintf( nm_text, "" ); // adb: ?
3282 vsprintf(nm_text,format,args);
3285 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3287 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3289 //end this section addition - Victor Rachels
3292 extern netgame_info Active_games[];
3293 extern int NumActiveNetgames;
3295 void show_extra_netgame_info(int choice)
3301 if (choice>=NumActiveNetgames)
3306 m[i].text=(char *)&mtext[i];
3307 m[i].type=NM_TYPE_TEXT;
3310 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3311 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3312 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3313 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3315 already_showing_info=1;
3316 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3317 already_showing_info=0;
3322 /* Spiffy word wrap string formatting function */
3324 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3330 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3333 wordptr = strtok(tbuf, " ");
3334 if (!wordptr) return;
3340 col = col+strlen(wordptr)+1;
3341 if (col >=line_length) {
3343 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3346 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3348 wordptr = strtok(NULL, " ");