1 /* $Id: newmenu.c,v 1.30 2005-01-25 21:20:29 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)
41 #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 PHYSFS_delete(filename);
2036 #define MAX_FILES 300
2038 //FIXME: should maybe put globbing ability back?
2039 int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
2045 int NumFiles=0, key,done, citem, ocitem;
2046 char * filenames = NULL;
2047 int NumFiles_displayed = 8;
2048 int first_item = -1, ofirst_item;
2049 int old_keyd_repeat = keyd_repeat;
2052 int demos_deleted=0;
2053 int initialized = 0;
2055 int w_x, w_y, w_w, w_h, title_height;
2056 int box_x, box_y, box_w, box_h;
2057 bkg bg; // background under listbox
2058 #ifdef NEWMENU_MOUSE
2059 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2060 int mouse2_state, omouse2_state;
2061 int dblclick_flag=0;
2064 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 (!stricmp(type, "plr"))
2082 else if (!stricmp(type, "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 find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
2097 for (f = find; *f != NULL; f++)
2101 ext = strrchr(*f, '.');
2102 if (!ext || strnicmp(ext, ".plr", 4))
2105 if (NumFiles < MAX_FILES)
2107 strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
2112 p = strchr(&filenames[NumFiles*14], '.');
2122 PHYSFS_freeList(find);
2124 if ( (NumFiles < 1) && demos_deleted ) {
2128 if ( (NumFiles < 1) && demo_mode ) {
2129 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2135 if ( (NumFiles < 2) && player_mode ) {
2137 goto ExitFileMenuEarly;
2144 nm_messagebox(NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND);
2151 // set_screen_mode(SCREEN_MENU);
2157 dd_gr_set_current_canvas(NULL);
2159 gr_set_current_canvas(NULL);
2162 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2164 grd_curcanv->cv_font = SUBTITLE_FONT;
2166 WIN(DDGRUNLOCK(dd_grd_curcanv));
2171 for (i=0; i<NumFiles; i++ ) {
2173 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2179 gr_get_string_size( title, &w, &h, &aw );
2182 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2186 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2188 w_w += (grd_curfont->ft_w * 4);
2189 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2191 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2192 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2194 w_x = (grd_curcanv->cv_w-w_w)/2;
2195 w_y = (grd_curcanv->cv_h-w_h)/2;
2197 if ( w_x < 0 ) w_x = 0;
2198 if ( w_y < 0 ) w_y = 0;
2200 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2201 box_y = w_y + title_height;
2203 // save the screen behind the menu.
2207 #if !defined(WINDOWS)
2208 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2209 bg.background = &VR_offscreen_buffer->cv_bitmap;
2212 #if defined(POLY_ACC)
2213 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2215 bg.background = gr_create_bitmap( w_w, w_h );
2218 Assert( bg.background != NULL );
2221 WIN(DDGRLOCK(dd_grd_curcanv));
2222 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2223 WIN(DDGRUNLOCK(dd_grd_curcanv));
2227 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2228 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2229 dd_VR_offscreen_buffer, 0, 0,
2230 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2231 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2235 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2237 WIN(DDGRLOCK(dd_grd_curcanv))
2239 gr_string( 0x8000, w_y+10, title );
2241 WIN(DDGRUNLOCK(dd_grd_curcanv));
2248 if ( !player_mode ) {
2249 newmenu_file_sort( NumFiles, filenames );
2251 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2252 newmenu_file_sort( NumFiles, filenames );
2254 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2256 for ( i=0; i<NumFiles; i++ ) {
2257 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2258 #ifdef NEWMENU_MOUSE
2266 #ifdef NEWMENU_MOUSE
2267 mouse_state = omouse_state = 0;
2268 mouse2_state = omouse2_state = 0;
2269 draw_close_box(w_x,w_y);
2270 newmenu_show_cursor();
2277 DoMessageStuff(&msg);
2279 if (_RedrawScreen) {
2280 _RedrawScreen = FALSE;
2282 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2283 gr_free_bitmap(bg.background);
2286 goto RePaintNewmenuFile;
2293 ofirst_item = first_item;
2296 #ifdef NEWMENU_MOUSE
2297 omouse_state = mouse_state;
2298 omouse2_state = mouse2_state;
2299 mouse_state = mouse_button_state(0);
2300 mouse2_state = mouse_button_state(1);
2303 //see if redbook song needs to be restarted
2304 songs_check_redbook_repeat();
2307 if (!mouse2_state && omouse2_state)
2308 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2311 //NOTE LINK TO ABOVE ELSE
2317 else if (simukey==1)
2323 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2324 case KEY_PRINT_SCREEN:
2325 MAC(newmenu_hide_cursor());
2326 save_screen_shot(0);
2327 PA_DFX (pa_set_frontbuffer_current());
2328 PA_DFX (pa_set_front_to_read());
2330 MAC(newmenu_show_cursor());
2334 case KEY_CTRLED+KEY_D:
2335 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2339 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2342 mouse_set_mode(1); //re-enable centering mode
2344 newmenu_hide_cursor();
2346 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2348 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2350 mouse_set_mode(0); //disenable centering mode
2352 newmenu_show_cursor();
2356 char name[PATH_MAX];
2358 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2362 strcpy(name, demo_mode?DEMO_DIR:"");
2363 strcat(name,&filenames[citem*14]);
2370 if ( !strncmp(name, ".\\", 2) )
2371 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2372 name[i] = name[i+1];
2373 while ( (p = strchr(name, '\\')) )
2378 ret = !PHYSFS_delete(name);
2382 if ((!ret) && player_mode) {
2383 delete_player_saved_games( &filenames[citem*14] );
2388 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2390 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2391 } else if (demo_mode)
2416 citem += NumFiles_displayed;
2420 citem -= NumFiles_displayed;
2423 if (allow_abort_flag) {
2434 case KEY_COMMAND+KEY_Q: {
2435 extern void macintosh_quit();
2437 if ( !(Game_mode & GM_MULTI) )
2439 newmenu_show_cursor();
2448 int ascii = key_to_ascii(key);
2449 if ( ascii < 255 ) {
2452 if (cc1 < 0 ) cc1 = 0;
2453 if (cc1 >= NumFiles ) cc1 = 0;
2455 if ( cc < 0 ) cc = 0;
2456 if ( cc >= NumFiles ) cc = 0;
2457 if ( citem == cc ) break;
2459 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2474 if (citem>=NumFiles)
2477 if (citem< first_item)
2480 if (citem>=( first_item+NumFiles_displayed))
2482 first_item = citem-NumFiles_displayed+1;
2486 if (NumFiles>first_item+NumFiles_displayed)
2497 if (NumFiles <= NumFiles_displayed )
2500 if (first_item>NumFiles-NumFiles_displayed)
2502 first_item = NumFiles-NumFiles_displayed;
2505 if (first_item < 0 ) first_item = 0;
2507 #ifdef NEWMENU_MOUSE
2509 if (mouse_state || mouse2_state) {
2512 mouse_get_pos(&mx, &my);
2513 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2514 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2516 x2 = box_x + box_w - 1;
2517 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2519 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2520 if (i == citem && !mouse2_state) {
2530 if (!mouse_state && omouse_state) {
2533 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2534 mouse_get_pos(&mx, &my);
2536 x2 = box_x + box_w - 1;
2537 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2539 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2540 if (dblclick_flag) done = 1;
2541 else dblclick_flag = 1;
2545 if ( !mouse_state && omouse_state ) {
2546 mouse_get_pos(&mx, &my);
2547 x1 = w_x + CLOSE_X + 2;
2548 x2 = x1 + CLOSE_SIZE - 2;
2549 y1 = w_y + CLOSE_Y + 2;
2550 y2 = y1 + CLOSE_SIZE - 2;
2551 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2560 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2562 y1 = box_y+box_h-LHY(7);
2564 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2571 WIN(DDGRLOCK(dd_grd_curcanv));
2572 gr_setcolor( BM_XRGB(2,2,2));
2573 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2574 gr_setcolor( BM_XRGB( 0,0,0) );
2577 if (ofirst_item != first_item || win_redraw) {
2580 if (ofirst_item != first_item) {
2582 newmenu_hide_cursor();
2583 gr_setcolor( BM_XRGB( 0,0,0) );
2584 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2586 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2588 if ( i >= NumFiles ) {
2590 gr_setcolor( BM_XRGB(5,5,5));
2591 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2592 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2594 gr_setcolor( BM_XRGB(2,2,2));
2595 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2597 gr_setcolor( BM_XRGB(0,0,0));
2598 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2602 grd_curcanv->cv_font = SELECTED_FONT;
2604 grd_curcanv->cv_font = NORMAL_FONT;
2605 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2607 gr_setcolor( BM_XRGB(5,5,5));
2608 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2609 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2611 gr_setcolor( BM_XRGB(2,2,2));
2612 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2613 gr_setcolor( BM_XRGB(0,0,0));
2615 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2616 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2619 newmenu_show_cursor();
2620 } else if ( citem != ocitem ) {
2623 newmenu_hide_cursor();
2625 if ( (i>=0) && (i<NumFiles) ) {
2626 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2628 grd_curcanv->cv_font = SELECTED_FONT;
2630 grd_curcanv->cv_font = NORMAL_FONT;
2631 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2632 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2633 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2636 if ( (i>=0) && (i<NumFiles) ) {
2637 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2639 grd_curcanv->cv_font = SELECTED_FONT;
2641 grd_curcanv->cv_font = NORMAL_FONT;
2642 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2643 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2644 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2646 newmenu_show_cursor();
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));
2677 MAC(newmenu_hide_cursor());
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
2714 WIN(newmenu_hide_cursor());
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 // PHYSFS_delete(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 #ifdef NEWMENU_MOUSE
2758 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2759 int close_x,close_y;
2761 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2764 WIN(int win_redraw=0);
2768 PA_DFX (pa_set_frontbuffer_current());
2769 PA_DFX (pa_set_front_to_read());
2770 WIN(mouse_set_mode(0)); //disable centering mode
2772 // set_screen_mode(SCREEN_MENU);
2776 RePaintNewmenuListbox:
2778 dd_gr_set_current_canvas(NULL);
2780 gr_set_current_canvas(NULL);
2783 grd_curcanv->cv_font = SUBTITLE_FONT;
2786 for (i=0; i<nitems; i++ ) {
2788 gr_get_string_size( items[i], &w, &h, &aw );
2792 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2796 gr_get_string_size( title, &w, &h, &aw );
2799 title_height = h + 5;
2802 border_size = grd_curfont->ft_w;
2803 WIN (border_size=grd_curfont->ft_w*2);
2805 width += (grd_curfont->ft_w);
2806 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2807 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2809 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2810 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2811 if ( wy < title_height )
2814 total_width = width+2*border_size;
2815 total_height = height+2*border_size+title_height;
2819 #if !defined(WINDOWS)
2820 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2821 bg.background = &VR_offscreen_buffer->cv_bitmap;
2824 //bg.background = gr_create_bitmap( width, (height + title_height) );
2825 #if defined(POLY_ACC)
2826 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2828 bg.background = gr_create_bitmap(total_width,total_height);
2830 Assert( bg.background != NULL );
2832 WIN (DDGRLOCK(dd_grd_curcanv));
2833 //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 );
2834 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2835 WIN (DDGRUNLOCK(dd_grd_curcanv));
2839 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2840 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2841 dd_VR_offscreen_buffer, 0, 0,
2842 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2843 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2847 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2849 WIN(DDGRLOCK(dd_grd_curcanv));
2850 gr_string( 0x8000, wy - title_height, title );
2851 WIN(DDGRUNLOCK(dd_grd_curcanv));
2856 citem = default_item;
2857 if ( citem < 0 ) citem = 0;
2858 if ( citem >= nitems ) citem = 0;
2862 #ifdef NEWMENU_MOUSE
2863 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2864 close_x = wx-border_size;
2865 close_y = wy-title_height-border_size;
2866 draw_close_box(close_x,close_y);
2867 newmenu_show_cursor();
2874 DoMessageStuff(&msg);
2876 if (_RedrawScreen) {
2877 _RedrawScreen = FALSE;
2879 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2880 gr_free_bitmap(bg.background);
2882 goto RePaintNewmenuListbox;
2889 ofirst_item = first_item;
2890 #ifdef NEWMENU_MOUSE
2891 omouse_state = mouse_state;
2892 mouse_state = mouse_button_state(0);
2894 //see if redbook song needs to be restarted
2895 songs_check_redbook_repeat();
2899 if ( listbox_callback )
2900 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2921 else if (simukey==1)
2927 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2928 case KEY_PRINT_SCREEN:
2929 MAC(newmenu_hide_cursor());
2930 save_screen_shot(0);
2931 PA_DFX (pa_set_frontbuffer_current());
2932 PA_DFX (pa_set_front_to_read());
2934 MAC(newmenu_show_cursor());
2955 citem += LB_ITEMS_ON_SCREEN;
2959 citem -= LB_ITEMS_ON_SCREEN;
2962 if (allow_abort_flag) {
2973 case KEY_COMMAND+KEY_Q: {
2974 extern void macintosh_quit();
2976 if ( !(Game_mode & GM_MULTI) )
2978 newmenu_show_cursor();
2986 int ascii = key_to_ascii(key);
2987 if ( ascii < 255 ) {
2990 if (cc1 < 0 ) cc1 = 0;
2991 if (cc1 >= nitems ) cc1 = 0;
2993 if ( cc < 0 ) cc = 0;
2994 if ( cc >= nitems ) cc = 0;
2995 if ( citem == cc ) break;
2997 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
3014 if (citem< first_item)
3017 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
3018 first_item = citem-LB_ITEMS_ON_SCREEN+1;
3020 if (nitems <= LB_ITEMS_ON_SCREEN )
3023 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3024 first_item = nitems-LB_ITEMS_ON_SCREEN;
3025 if (first_item < 0 ) first_item = 0;
3028 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3039 #ifdef NEWMENU_MOUSE
3044 mouse_get_pos(&mx, &my);
3045 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3048 gr_get_string_size(items[i], &w, &h, &aw );
3051 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3053 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3065 //no double-click stuff for listbox
3066 //@@if (!mouse_state && omouse_state) {
3069 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3070 //@@ mouse_get_pos(&mx, &my);
3072 //@@ x2 = wx + width;
3073 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3075 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3076 //@@ if (dblclick_flag) done = 1;
3080 //check for close box clicked
3081 if ( !mouse_state && omouse_state ) {
3082 mouse_get_pos(&mx, &my);
3083 x1 = close_x + CLOSE_X + 2;
3084 x2 = x1 + CLOSE_SIZE - 2;
3085 y1 = close_y + CLOSE_Y + 2;
3086 y2 = y1 + CLOSE_SIZE - 2;
3087 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3097 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3099 y1 = total_height-LHY(7);
3101 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3109 if ( (ofirst_item != first_item) || redraw) {
3110 newmenu_hide_cursor();
3111 WIN(DDGRLOCK(dd_grd_curcanv));
3113 gr_setcolor( BM_XRGB( 0,0,0) );
3114 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3116 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3117 if ( i >= nitems ) {
3118 gr_setcolor( BM_XRGB(0,0,0));
3119 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3122 grd_curcanv->cv_font = SELECTED_FONT;
3124 grd_curcanv->cv_font = NORMAL_FONT;
3125 gr_get_string_size(items[i], &w, &h, &aw );
3126 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3127 gr_string( wx+5, y, items[i] );
3132 // If Win95 port, draw up/down arrows on left side of menu
3134 grd_curcanv->cv_font = NORMAL_FONT;
3136 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3140 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3144 if (show_down_arrow)
3145 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3149 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3156 WIN(DDGRUNLOCK(dd_grd_curcanv));
3157 newmenu_show_cursor();
3159 } else if ( citem != ocitem ) {
3162 newmenu_hide_cursor();
3164 WIN(DDGRLOCK(dd_grd_curcanv));
3167 if ( (i>=0) && (i<nitems) ) {
3168 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3170 grd_curcanv->cv_font = SELECTED_FONT;
3172 grd_curcanv->cv_font = NORMAL_FONT;
3173 gr_get_string_size(items[i], &w, &h, &aw );
3174 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3175 gr_string( wx+5, y, items[i] );
3179 if ( (i>=0) && (i<nitems) ) {
3180 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3182 grd_curcanv->cv_font = SELECTED_FONT;
3184 grd_curcanv->cv_font = NORMAL_FONT;
3185 gr_get_string_size( items[i], &w, &h, &aw );
3186 gr_rect( wx, y-1, wx+width-1, y+h );
3187 gr_string( wx+5, y, items[i] );
3189 WIN(DDGRUNLOCK(dd_grd_curcanv));
3191 newmenu_show_cursor();
3195 newmenu_hide_cursor();
3197 keyd_repeat = old_keyd_repeat;
3199 WIN (DDGRLOCK(dd_grd_curcanv));
3200 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3201 WIN (DDGRUNLOCK(dd_grd_curcanv));
3203 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3204 gr_free_bitmap(bg.background);
3208 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3209 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3211 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3212 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3218 WIN(mouse_set_mode(1)); //re-enable centering mode
3224 int newmenu_filelist( char * title, char * filespec, char * filename )
3227 char * Filenames[MAX_FILES];
3228 char FilenameText[MAX_FILES][14];
3229 FILEFINDSTRUCT find;
3232 if( !FileFindFirst( filespec, &find ) ) {
3234 if (NumFiles<MAX_FILES) {
3235 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3236 Filenames[NumFiles] = FilenameText[NumFiles];
3241 } while( !FileFindNext( &find ) );
3245 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3247 strcpy( filename, Filenames[i] );
3254 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
3255 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
3261 char nm_text[MESSAGEBOX_TEXT_SIZE];
3262 newmenu_item nm_message_items[5];
3264 va_start(args, nchoices );
3266 Assert( nchoices <= 5 );
3268 for (i=0; i<nchoices; i++ ) {
3269 s = va_arg( args, char * );
3270 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
3272 format = va_arg( args, char * );
3273 //sprintf( nm_text, "" ); // adb: ?
3274 vsprintf(nm_text,format,args);
3277 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
3279 return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, 0, NULL, -1, -1 );
3281 //end this section addition - Victor Rachels
3284 extern netgame_info Active_games[];
3285 extern int NumActiveNetgames;
3287 void show_extra_netgame_info(int choice)
3293 if (choice>=NumActiveNetgames)
3298 m[i].text=(char *)&mtext[i];
3299 m[i].type=NM_TYPE_TEXT;
3302 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3303 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3304 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3305 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3307 already_showing_info=1;
3308 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3309 already_showing_info=0;
3314 /* Spiffy word wrap string formatting function */
3316 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3322 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3325 wordptr = strtok(tbuf, " ");
3326 if (!wordptr) return;
3332 col = col+strlen(wordptr)+1;
3333 if (col >=line_length) {
3335 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3338 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3340 wordptr = strtok(NULL, " ");