2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
19 static char rcsid[] = "$Id: newmenu.c,v 1.3 2001-01-31 15:17:56 bradleyb Exp $";
33 #include "pa_enabl.h" //$$POLY_ACC
78 #define MAXDISPLAYABLEITEMS 15
80 #define LHX(x) ((x)*(MenuHires?2:1))
81 #define LHY(y) ((y)*(MenuHires?2.4:1))
83 #define TITLE_FONT HUGE_FONT
84 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
85 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
86 #define SUBTITLE_FONT MEDIUM3_FONT
88 #define NORMAL_CHECK_BOX "
\81"
89 #define CHECKED_CHECK_BOX "
\82"
91 #define NORMAL_RADIO_BOX "
\7f"
92 #define CHECKED_RADIO_BOX "
\80"
93 #define CURSOR_STRING "_"
94 #define SLIDER_LEFT "
\83" // 131
95 #define SLIDER_RIGHT "
\84" // 132
96 #define SLIDER_MIDDLE "
\85" // 133
97 #define SLIDER_MARKER "
\86" // 134
98 #define UP_ARROW_MARKER "
\87" // 135
99 #define DOWN_ARROW_MARKER "
\88" // 136
101 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 );
102 void show_extra_netgame_info(int choice);
105 int Newmenu_first_time = 1;
106 //--unused-- int Newmenu_fade_in = 1;
109 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
110 grs_bitmap * saved; // The background under the menu.
111 grs_bitmap * background;
114 grs_bitmap nm_background,nm_background_save;
116 #define MESSAGEBOX_TEXT_SIZE 300 // How many characters in messagebox
117 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
119 extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
121 ubyte MenuReordering=0;
123 char Pauseable_menu=0;
124 char already_showing_info=0;
127 void newmenu_close() {
128 if ( nm_background.bm_data )
129 d_free(nm_background.bm_data);
131 if ( nm_background_save.bm_data )
132 d_free(nm_background_save.bm_data);
133 Newmenu_first_time = 1;
136 ubyte background_palette[768];
138 //should be called whenever the palette changes
139 void nm_remap_background()
141 if (!Newmenu_first_time) {
142 if (!nm_background.bm_data)
143 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
145 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
147 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
153 extern char last_palette_loaded[];
155 void nm_draw_background1(char * filename)
161 //@@//I think this only gets called to fill the whole screen
162 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
163 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
165 bmp = gr_create_bitmap(grd_curcanv->cv_bitmap.bm_w,grd_curcanv->cv_bitmap.bm_h);
167 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
168 Assert(pcx_error == PCX_ERROR_NONE);
170 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
173 { //remap stuff. this code is kindof a hack
175 //now, before we bring up the menu, we need to
176 //do some stuff to make sure the palette is ok. First, we need to
177 //get our current palette into the 2d's array, so the remapping will
178 //work. Second, we need to remap the fonts. Third, we need to fill
179 //in part of the fade tables so the darkening of the menu edges works
181 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
182 remap_fonts_and_menus(1);
186 WIN(DDGRLOCK(dd_grd_curcanv));
187 #if defined(POLY_ACC)
189 pa_update_clut(gr_palette, 0, 256, 0);
192 #if defined(POLY_ACC)
195 WIN(DDGRUNLOCK(dd_grd_curcanv));
199 strcpy(last_palette_loaded,""); //force palette load next time
204 #define MENU_BACKGROUND_BITMAP (MenuHires?"\x01scoresb.pcx":"\x01scores.pcx") //read only from hog file
206 #define MENU_BACKGROUND_BITMAP (MenuHires?"scoresb.pcx":"scores.pcx")
209 int Background_hires;
212 void nm_draw_background(int x1, int y1, int x2, int y2 )
216 if (Newmenu_first_time || MenuHires!=Background_hires) {
219 if (Newmenu_first_time) {
220 atexit( newmenu_close );
221 Newmenu_first_time = 0;
222 nm_background_save.bm_data=NULL;
225 if (nm_background_save.bm_data)
226 d_free(nm_background_save.bm_data);
227 if (nm_background.bm_data)
228 d_free(nm_background.bm_data);
231 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
232 Assert(pcx_error == PCX_ERROR_NONE);
234 nm_background = nm_background_save;
235 nm_background.bm_data=NULL;
236 nm_remap_background();
238 Background_hires = MenuHires;
241 if ( x1 < 0 ) x1 = 0;
242 if ( y1 < 0 ) y1 = 0;
247 if ( w > nm_background.bm_w ) w = nm_background.bm_w;
248 if ( h > nm_background.bm_h ) h = nm_background.bm_h;
253 WIN(DDGRLOCK(dd_grd_curcanv));
255 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
257 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
262 Gr_scanline_darkening_level = 2*7;
265 gr_setcolor( BM_XRGB(0,0,0) );
266 gr_urect( x2-5, y1+5, x2-5, y2-5 );
267 gr_urect( x2-4, y1+4, x2-4, y2-5 );
268 gr_urect( x2-3, y1+3, x2-3, y2-5 );
269 gr_urect( x2-2, y1+2, x2-2, y2-5 );
270 gr_urect( x2-1, y1+1, x2-1, y2-5 );
271 gr_urect( x2+0, y1+0, x2-0, y2-5 );
273 gr_urect( x1+5, y2-5, x2, y2-5 );
274 gr_urect( x1+4, y2-4, x2, y2-4 );
275 gr_urect( x1+3, y2-3, x2, y2-3 );
276 gr_urect( x1+2, y2-2, x2, y2-2 );
277 gr_urect( x1+1, y2-1, x2, y2-1 );
278 gr_urect( x1+0, y2, x2, y2-0 );
280 WIN(DDGRUNLOCK(dd_grd_curcanv));
282 Gr_scanline_darkening_level = GR_FADE_LEVELS;
285 void nm_restore_background( int x, int y, int w, int h )
292 if ( x1 < 0 ) x1 = 0;
293 if ( y1 < 0 ) y1 = 0;
295 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
296 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
301 WIN(DDGRLOCK(dd_grd_curcanv));
302 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
303 WIN(DDGRUNLOCK(dd_grd_curcanv));
306 // Draw a left justfied string
307 void nm_string( bkg * b, int w1,int x, int y, char * s)
309 int w,h,aw,tx=0,t=0,i;
310 char *p,*s1,measure[2];
311 int XTabs[]={15,87,124,162,228,253};
317 XTabs[i]=(LHX(XTabs[i]));
325 p = strchr( s, '\t' );
332 gr_get_string_size(s, &w, &h, &aw );
338 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
339 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
343 for (i=0;i<strlen(s);i++)
345 if (s[i]=='\t' && SurfingNet)
352 gr_get_string_size(measure,&tx,&h,&aw);
353 gr_string(x,y,measure);
357 else gr_string (x,y,s);
359 if (!SurfingNet && p && (w1>0) ) {
360 gr_get_string_size(s1, &w, &h, &aw );
362 gr_string( x+w1-w, y, s1 );
368 // Draw a slider and it's string
369 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
376 p = strchr( s, '\t' );
382 gr_get_string_size(s, &w, &h, &aw );
385 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
386 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
388 gr_string( x, y, s );
391 gr_get_string_size(s1, &w, &h, &aw );
394 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
396 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
398 gr_string( x+w1-w, y, s1 );
405 // Draw a left justfied string with black background.
406 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
409 gr_get_string_size(s, &w, &h, &aw );
413 WIN(DDGRLOCK(dd_grd_curcanv));
414 gr_setcolor( BM_XRGB(2,2,2) );
415 gr_rect( x-1, y-1, x-1, y+h-1 );
416 gr_rect( x-1, y-1, x+w1-1, y-1 );
419 gr_setcolor( BM_XRGB(5,5,5) );
420 gr_rect( x, y+h, x+w1, y+h);
421 gr_rect( x+w1, y-1, x+w1, y+h );
423 gr_setcolor( BM_XRGB(0,0,0) );
424 gr_rect( x, y, x+w1-1, y+h-1 );
426 gr_string( x+1, y+1, s );
427 WIN(DDGRUNLOCK(dd_grd_curcanv));
431 // Draw a right justfied string
432 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
435 gr_get_string_size(s, &w, &h, &aw );
440 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
443 WIN(DDGRLOCK(dd_grd_curcanv));
444 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
445 gr_string( x-w, y, s );
446 WIN(DDGRUNLOCK(dd_grd_curcanv));
451 //for text items, constantly redraw cursor (to achieve flash)
452 void update_cursor( newmenu_item *item)
455 fix time = timer_get_approx_seconds();
457 char * text = item->text;
459 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
462 gr_get_string_size(text, &w, &h, &aw );
463 if ( w > item->w-10 )
470 x = item->x+w; y = item->y;
472 WIN(DDGRLOCK(dd_grd_curcanv));
474 gr_string( x, y, CURSOR_STRING );
476 gr_setcolor( BM_XRGB(0,0,0) );
477 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
479 WIN(DDGRUNLOCK(dd_grd_curcanv));
482 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
487 gr_get_string_size(text, &w1, &h1, &aw );
496 nm_string_black( b, w, x, y, text );
499 gr_string( x+w1+1, y, CURSOR_STRING );
503 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
508 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
510 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
512 if (item->text[0]=='\t')
513 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
518 grd_curcanv->cv_font = SELECTED_FONT;
520 grd_curcanv->cv_font = NORMAL_FONT;
523 if (is_current && item->type == NM_TYPE_TEXT)
524 grd_curcanv->cv_font = NORMAL_FONT;
528 WIN(DDGRLOCK(dd_grd_curcanv));
529 switch( item->type ) {
531 // grd_curcanv->cv_font=TEXT_FONT;
532 // fall through on purpose
535 nm_string( b, item->w, item->x, item->y, item->text );
537 case NM_TYPE_SLIDER: {
539 if (item->value < item->min_value) item->value=item->min_value;
540 if (item->value > item->max_value) item->value=item->max_value;
541 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
542 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
543 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
545 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
547 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
549 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
552 case NM_TYPE_INPUT_MENU:
553 if ( item->group==0 ) {
554 nm_string( b, item->w, item->x, item->y, item->text );
556 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
560 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
563 nm_string( b, item->w, item->x, item->y, item->text );
565 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
567 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
570 nm_string( b, item->w, item->x, item->y, item->text );
572 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
574 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
576 case NM_TYPE_NUMBER: {
578 if (item->value < item->min_value) item->value=item->min_value;
579 if (item->value > item->max_value) item->value=item->max_value;
580 nm_string( b, item->w, item->x, item->y, item->text );
581 sprintf( text, "%d", item->value );
582 nm_rstring( b,item->right_offset,item->x, item->y, text );
586 WIN(DDGRUNLOCK(dd_grd_curcanv));
590 char *Newmenu_allowed_chars=NULL;
592 //returns true if char is allowed
593 int char_allowed(char c)
595 char *p = Newmenu_allowed_chars;
603 if (c>=p[0] && c<=p[1])
612 void strip_end_whitespace( char * text )
616 for (i=l-1; i>=0; i-- ) {
617 if ( isspace(text[i]) )
624 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
626 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
628 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
630 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
634 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
636 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
640 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 )
642 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
646 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 )
648 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
650 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 )
652 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
655 //returns 1 if a control device button has been pressed
656 int check_button_press()
660 switch (Config_control_type) {
661 case CONTROL_JOYSTICK:
662 case CONTROL_FLIGHTSTICK_PRO:
663 case CONTROL_THRUSTMASTER_FCS:
664 case CONTROL_GRAVIS_GAMEPAD:
666 if (joy_get_button_down_cnt(i)>0) return 1;
669 case CONTROL_CYBERMAN:
670 #ifndef MACINTOSH // don't allow mouse to continue from menu
672 if (mouse_button_down_count(i)>0) return 1;
675 case CONTROL_WINJOYSTICK:
678 if (joy_get_button_down_cnt(i)>0) return 1;
681 case CONTROL_NONE: //keyboard only
683 if (key_checkch()) return 1;
688 Error("Bad control type (Config_control_type):%i",Config_control_type);
694 extern int network_request_player_names(int);
695 extern int RestoringMenu;
697 #if defined(WINDOWS) || defined(MACINTOSH)
698 ubyte Hack_DblClick_MenuMode=0;
701 MAC(extern ubyte joydefs_calibrating;)
705 #define CLOSE_SIZE 10
707 void draw_close_box(int x,int y)
709 WIN (DDGRLOCK(dd_grd_curcanv));
710 gr_setcolor( BM_XRGB(0, 0, 0) );
711 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
712 gr_setcolor( BM_XRGB(21, 21, 21) );
713 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
714 WIN (DDGRUNLOCK(dd_grd_curcanv));
717 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 )
719 int old_keyd_repeat, done;
720 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
721 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
722 grs_font * save_font;
723 int string_width, string_height, average_width;
726 int all_text=0; //set true if all text items
727 int sound_stopped=0,time_stopped=0;
728 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
731 int MaxOnMenu=MAXDISPLAYABLEITEMS;
732 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
733 #if defined(MACINTOSH) || defined(WINDOWS)
734 int mouse_state, omouse_state, dblclick_flag=0;
735 int mx=0, my=0, x1, x2, y1, y2;
739 EventRecord event; // looking for disk inserted events for CD mounts
742 PA_DFX (pa_set_frontbuffer_current());
743 PA_DFX (pa_set_front_to_read());
745 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
754 WIN(mouse_set_mode(0)); //disable centering mode
756 MaxDisplayable=nitems;
758 // set_screen_mode(SCREEN_MENU);
761 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
762 digi_pause_digi_sounds();
766 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
779 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
781 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
783 save_font = grd_curcanv->cv_font;
788 grd_curcanv->cv_font = TITLE_FONT;
789 gr_get_string_size(title,&string_width,&string_height,&average_width );
794 grd_curcanv->cv_font = SUBTITLE_FONT;
795 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
796 if (string_width > tw )
801 th += LHY(8); //put some space between titles & body
804 grd_curcanv->cv_font = SMALL_FONT;
806 grd_curcanv->cv_font = NORMAL_FONT;
810 nmenus = nothers = 0;
812 // Find menu height & width (store in w,h)
813 for (i=0; i<nitems; i++ ) {
816 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
817 item[i].right_offset = 0;
820 string_height+=LHY(3);
822 item[i].saved_text[0] = '\0';
824 if ( item[i].type == NM_TYPE_SLIDER ) {
827 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
828 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
829 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
831 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
832 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
833 string_width += w1 + aw;
836 if ( item[i].type == NM_TYPE_MENU ) {
840 if ( item[i].type == NM_TYPE_CHECK ) {
843 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
844 item[i].right_offset = w1;
845 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
846 if (w1 > item[i].right_offset)
847 item[i].right_offset = w1;
850 if (item[i].type == NM_TYPE_RADIO ) {
853 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
854 item[i].right_offset = w1;
855 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
856 if (w1 > item[i].right_offset)
857 item[i].right_offset = w1;
860 if (item[i].type==NM_TYPE_NUMBER ) {
864 sprintf( test_text, "%d", item[i].max_value );
865 gr_get_string_size( test_text, &w1, &h1, &aw1 );
866 item[i].right_offset = w1;
867 sprintf( test_text, "%d", item[i].min_value );
868 gr_get_string_size( test_text, &w1, &h1, &aw1 );
869 if ( w1 > item[i].right_offset)
870 item[i].right_offset = w1;
873 if ( item[i].type == NM_TYPE_INPUT ) {
874 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
875 strcpy(item[i].saved_text, item[i].text );
877 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
878 if ( string_width > MAX_TEXT_WIDTH )
879 string_width = MAX_TEXT_WIDTH;
883 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
884 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
885 strcpy(item[i].saved_text, item[i].text );
887 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
892 item[i].w = string_width;
893 item[i].h = string_height;
895 if ( string_width > w )
896 w = string_width; // Save maximum width
897 if ( average_width > aw )
899 h += string_height+1; // Find the height of all strings
902 // Big hack for allowing the netgame options menu to spill over
904 MaxOnMenu=MAXDISPLAYABLEITEMS;
905 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
908 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
911 h=(MaxOnMenu*(string_height+1)+LHY(8));
912 MaxDisplayable=MaxOnMenu;
913 mprintf ((0,"Hey, this is a scroll box!\n"));
926 for (i=0; i<nitems; i++ ) {
928 if (item[i].right_offset > right_offset )
929 right_offset = item[i].right_offset;
931 if (right_offset > 0 )
934 //gr_get_string_size("",&string_width,&string_height,&average_width );
941 twidth = ( tw - w )/2;
946 { right_offset=0; twidth=0;}
948 mprintf(( 0, "Right offset = %d\n", right_offset ));
951 // Find min point of menu border
952 // x = (grd_curscreen->sc_w-w)/2;
953 // y = (grd_curscreen->sc_h-h)/2;
955 w += MenuHires?60:30;
956 h += MenuHires?60:30;
958 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
959 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
961 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
962 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
967 if ( filename != NULL ) {
968 nm_draw_background1( filename );
969 gr_palette_load(gr_palette);
972 // Save the background of the display
973 // Win95 must refer to the screen as a dd_grs_canvas, so...
974 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
975 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
977 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
978 gr_set_current_canvas(bg.menu_canvas) );
980 if ( filename == NULL ) {
981 // Save the background under the menu...
987 #if defined(POLY_ACC)
988 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
990 bg.saved = gr_create_bitmap( w, h );
992 Assert( bg.saved != NULL );
994 WIN (DDGRLOCK(dd_grd_curcanv));
995 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
996 WIN (DDGRUNLOCK(dd_grd_curcanv));
998 WINDOS ( dd_gr_set_current_canvas(NULL),
999 gr_set_current_canvas( NULL )
1002 nm_draw_background(x,y,x+w-1,y+h-1);
1004 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1005 gr_set_current_canvas( bg.menu_canvas )
1008 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1012 #if defined(POLY_ACC)
1013 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1015 bg.background = gr_create_bitmap( w, h );
1017 Assert( bg.background != NULL );
1019 WIN (DDGRLOCK(dd_grd_curcanv));
1020 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1021 WIN (DDGRUNLOCK(dd_grd_curcanv));
1024 // ty = 15 + (yborder/4);
1026 ty = MenuHires?30:15;
1029 grd_curcanv->cv_font = TITLE_FONT;
1030 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1031 gr_get_string_size(title,&string_width,&string_height,&average_width );
1034 WIN (DDGRLOCK(dd_grd_curcanv));
1035 gr_printf( 0x8000, ty, title );
1036 WIN (DDGRUNLOCK(dd_grd_curcanv));
1041 grd_curcanv->cv_font = SUBTITLE_FONT;
1042 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1043 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1046 WIN (DDGRLOCK(dd_grd_curcanv));
1047 gr_printf( 0x8000, ty, subtitle );
1048 WIN (DDGRUNLOCK(dd_grd_curcanv));
1053 grd_curcanv->cv_font = SMALL_FONT;
1055 grd_curcanv->cv_font = NORMAL_FONT;
1057 // Update all item's x & y values.
1058 for (i=0; i<nitems; i++ ) {
1059 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1060 item[i].y += (MenuHires?30:15);
1061 if ( item[i].type==NM_TYPE_RADIO ) {
1062 fm = -1; // find first marked one
1063 for ( j=0; j<nitems; j++ ) {
1064 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1065 if (fm==-1 && item[j].value)
1077 old_keyd_repeat = keyd_repeat;
1083 if (citem < 0 ) citem = 0;
1084 if (citem > nitems-1 ) citem = nitems-1;
1087 #if defined(WINDOWS) || defined(MACINTOSH)
1091 while ( item[choice].type==NM_TYPE_TEXT ) {
1093 if (choice >= nitems ) {
1096 if (choice == citem ) {
1107 // Clear mouse, joystick to clear button presses.
1108 game_flush_inputs();
1110 #if defined(WINDOWS) || defined(MACINTOSH)
1111 mouse_state = omouse_state = 0;
1112 if (filename == NULL && !MenuReordering) {
1113 draw_close_box(0,0);
1119 if (!MenuReordering) {
1121 SetCursor (LoadCursor(NULL,IDC_ARROW));
1126 if (!joydefs_calibrating)
1130 mprintf ((0,"Set to true!\n"));
1136 DoMessageStuff(&msg);
1138 if (_RedrawScreen) {
1139 _RedrawScreen = FALSE;
1142 gr_free_bitmap(bg.saved);
1143 d_free( bg.background );
1146 gr_free_bitmap(bg.background);
1148 dd_gr_free_sub_canvas( bg.menu_canvas );
1149 grd_curcanv->cv_font = save_font;
1150 dd_grd_curcanv = save_canvas;
1152 goto RePaintNewmenu4;
1161 omouse_state = mouse_state;
1162 mouse_state = mouse_button_state(0);
1163 if (!joydefs_calibrating)
1164 show_cursor(); // possibly hidden
1168 omouse_state = mouse_state;
1169 if (!MenuReordering)
1170 mouse_state = mouse_button_state(0);
1171 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1174 //see if redbook song needs to be restarted
1175 songs_check_redbook_repeat();
1182 (*subfunction)(nitems,item,&k,choice);
1185 if (!time_stopped) {
1186 // Save current menu box
1187 if (multi_menu_poll() == -1)
1193 dont_restore = (k == -3); //-3 means don't restore
1199 if (check_button_press())
1203 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1206 old_choice = choice;
1212 if (SurfingNet && !already_showing_info)
1214 show_extra_netgame_info(choice-2);
1216 if (SurfingNet && already_showing_info)
1223 if (SurfingNet && !already_showing_info)
1225 network_request_player_names(choice-2);
1227 if (SurfingNet && already_showing_info)
1242 case KEY_TAB + KEY_SHIFTED:
1245 if (all_text) break;
1252 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1254 if (choice<TopChoice)
1255 { choice=TopChoice; break; }
1257 if (choice<ScrollOffset)
1259 for (i=0;i<nitems;i++)
1262 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1267 if (choice >= nitems ) choice=0;
1268 if (choice < 0 ) choice=nitems-1;
1270 } while ( item[choice].type==NM_TYPE_TEXT );
1271 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1272 item[choice].value = -1;
1273 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1274 item[old_choice].group=0;
1275 strcpy(item[old_choice].text, item[old_choice].saved_text );
1276 item[old_choice].value = -1;
1279 item[old_choice].redraw = 1;
1280 item[choice].redraw=1;
1285 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1286 if (all_text) break;
1293 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1296 { choice--; break; }
1298 if (choice>=MaxOnMenu+ScrollOffset)
1300 for (i=0;i<nitems;i++)
1303 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1308 if (choice < 0 ) choice=nitems-1;
1309 if (choice >= nitems ) choice=0;
1312 } while ( item[choice].type==NM_TYPE_TEXT );
1314 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1315 item[choice].value = -1;
1316 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1317 item[old_choice].group=0;
1318 strcpy(item[old_choice].text, item[old_choice].saved_text );
1319 item[old_choice].value = -1;
1322 item[old_choice].redraw=1;
1323 item[choice].redraw=1;
1326 if ( choice > -1 ) {
1327 switch( item[choice].type ) {
1330 case NM_TYPE_INPUT_MENU:
1333 if ( item[choice].value )
1334 item[choice].value = 0;
1336 item[choice].value = 1;
1337 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1340 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1342 mprintf ((0,"Special redraw!\n"));
1347 item[choice].redraw=1;
1350 for (i=0; i<nitems; i++ ) {
1351 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1356 item[choice].value = 1;
1357 item[choice].redraw = 1;
1363 case KEY_SHIFTED+KEY_UP:
1364 if (MenuReordering && choice!=TopChoice)
1366 Temp=item[choice].text;
1367 TempVal=item[choice].value;
1368 item[choice].text=item[choice-1].text;
1369 item[choice].value=item[choice-1].value;
1370 item[choice-1].text=Temp;
1371 item[choice-1].value=TempVal;
1372 item[choice].redraw=1;
1373 item[choice-1].redraw=1;
1377 case KEY_SHIFTED+KEY_DOWN:
1378 if (MenuReordering && choice!=(nitems-1))
1380 Temp=item[choice].text;
1381 TempVal=item[choice].value;
1382 item[choice].text=item[choice+1].text;
1383 item[choice].value=item[choice+1].value;
1384 item[choice+1].text=Temp;
1385 item[choice+1].value=TempVal;
1386 item[choice].redraw=1;
1387 item[choice+1].redraw=1;
1394 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1395 item[choice].group = 1;
1396 item[choice].redraw = 1;
1397 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1398 item[choice].text[0] = 0;
1399 item[choice].value = -1;
1401 strip_end_whitespace(item[choice].text);
1408 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1409 item[choice].group=0;
1410 strcpy(item[choice].text, item[choice].saved_text );
1411 item[choice].redraw=1;
1412 item[choice].value = -1;
1419 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1420 case KEY_PRINT_SCREEN:
1422 save_screen_shot(0);
1423 PA_DFX (pa_set_frontbuffer_current());
1424 PA_DFX (pa_set_front_to_read());
1425 for (i=0;i<nitems;i++)
1434 case KEY_COMMAND+KEY_RIGHT:
1435 songs_goto_next_song();
1437 case KEY_COMMAND+KEY_LEFT:
1438 songs_goto_prev_song();
1440 case KEY_COMMAND+KEY_UP:
1441 songs_play_level_song(1);
1443 case KEY_COMMAND+KEY_DOWN:
1444 songs_stop_redbook();
1447 case KEY_COMMAND+KEY_M:
1449 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1450 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1453 key_close(); // no processing of keys with keyboard handler.. jeez
1456 show_boxed_message ("Mounting CD\nESC to quit");
1457 RBAMountDisk(); // OS has totaly control of the CD.
1458 if (Function_mode == FMODE_MENU)
1459 songs_play_song(SONG_TITLE,1);
1460 else if (Function_mode == FMODE_GAME)
1461 songs_play_level_song( Current_level_num );
1462 clear_boxed_message();
1471 case KEY_COMMAND+KEY_E:
1472 songs_stop_redbook();
1474 k = -1; // force key not to register
1477 case KEY_COMMAND+KEY_Q: {
1478 extern void macintosh_quit();
1480 if ( !(Game_mode & GM_MULTI) )
1482 if (!joydefs_calibrating)
1484 k = -1; // force key not to register
1491 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1498 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1500 if ( !done && mouse_state && !omouse_state && !all_text ) {
1501 mouse_get_pos(&mx, &my);
1502 for (i=0; i<nitems; i++ ) {
1503 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1504 x2 = x1 + item[i].w;
1505 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1506 y2 = y1 + item[i].h;
1507 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1508 if (i+ScrollOffset != choice) {
1509 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1512 choice = i + ScrollOffset;
1514 switch( item[choice].type ) {
1516 if ( item[choice].value )
1517 item[choice].value = 0;
1519 item[choice].value = 1;
1520 item[choice].redraw=1;
1527 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1529 mprintf ((0,"Special redraw!\n"));
1536 for (i=0; i<nitems; i++ ) {
1537 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1542 item[choice].value = 1;
1543 item[choice].redraw = 1;
1546 item[old_choice].redraw=1;
1552 if (mouse_state && all_text)
1555 if ( !done && mouse_state && !all_text ) {
1556 mouse_get_pos(&mx, &my);
1558 // check possible scrollbar stuff first
1560 int arrow_width, arrow_height, aw;
1562 if (ScrollOffset != 0) {
1563 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1564 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1565 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1566 x1 = x1 - arrow_width;
1567 y2 = y1 + arrow_height;
1568 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1571 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1573 if (choice<ScrollOffset)
1575 for (i=0;i<nitems;i++)
1578 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1582 if (ScrollOffset+MaxDisplayable<nitems) {
1583 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1584 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1585 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1586 x1 = x1 - arrow_width;
1587 y2 = y1 + arrow_height;
1588 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1591 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1593 if (choice>=MaxOnMenu+ScrollOffset)
1595 for (i=0;i<nitems;i++)
1598 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1604 for (i=0; i<nitems; i++ ) {
1605 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1606 x2 = x1 + item[i].w;
1607 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1608 y2 = y1 + item[i].h;
1609 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1610 if (i+ScrollOffset != choice) {
1611 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1614 choice = i + ScrollOffset;
1616 if ( item[choice].type == NM_TYPE_SLIDER ) {
1617 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1618 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1620 strcpy(slider_text, item[choice].saved_text);
1621 p = strchr(slider_text, '\t');
1627 gr_get_string_size(s1, &slider_width, &height, &aw);
1628 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1629 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1630 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1632 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1633 x2 = x1 + slider_width + sright_width;
1634 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1635 item[choice].value = item[choice].min_value;
1636 item[choice].redraw = 2;
1637 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1638 item[choice].value = item[choice].max_value;
1639 item[choice].redraw = 2;
1640 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1641 int num_values, value_width, new_value;
1643 num_values = item[choice].max_value - item[choice].min_value + 1;
1644 value_width = (slider_width - sleft_width - sright_width) / num_values;
1645 new_value = (mx - x1 - sleft_width) / value_width;
1646 if ( item[choice].value != new_value ) {
1647 item[choice].value = new_value;
1648 item[choice].redraw = 2;
1654 if (choice == old_choice)
1656 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1657 item[choice].value = -1;
1658 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1659 item[old_choice].group=0;
1660 strcpy(item[old_choice].text, item[old_choice].saved_text );
1661 item[old_choice].value = -1;
1664 item[old_choice].redraw = 1;
1665 item[choice].redraw=1;
1671 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1672 mouse_get_pos(&mx, &my);
1673 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1674 x2 = x1 + item[choice].w;
1675 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1676 y2 = y1 + item[choice].h;
1677 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1678 if (Hack_DblClick_MenuMode) {
1679 if (dblclick_flag) done = 1;
1680 else dblclick_flag = 1;
1686 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1687 item[choice].group = 1;
1688 item[choice].redraw = 1;
1689 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1690 item[choice].text[0] = 0;
1691 item[choice].value = -1;
1693 strip_end_whitespace(item[choice].text);
1697 if ( !done && !mouse_state && omouse_state && close_box ) {
1698 mouse_get_pos(&mx, &my);
1699 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1700 x2 = x1 + CLOSE_SIZE;
1701 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1702 y2 = y1 + CLOSE_SIZE;
1703 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1709 // HACK! Don't redraw loadgame preview
1710 if (RestoringMenu) item[0].redraw = 0;
1711 #endif // ifdef MACINTOSH
1713 if ( choice > -1 ) {
1716 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1717 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1718 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1719 if (item[choice].value > 0)
1720 item[choice].value--;
1721 item[choice].text[item[choice].value] = 0;
1722 item[choice].redraw = 1;
1724 ascii = key_to_ascii(k);
1725 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1729 if (item[choice].value==-1) {
1730 item[choice].value = 0;
1733 allowed = char_allowed(ascii);
1735 if (!allowed && ascii==' ' && char_allowed('_')) {
1741 item[choice].text[item[choice].value++] = ascii;
1742 item[choice].text[item[choice].value] = 0;
1743 item[choice].redraw=1;
1747 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1748 ascii = key_to_ascii(k);
1750 int choice1 = choice;
1751 ascii = toupper(ascii);
1755 if (choice1 >= nitems ) choice1=0;
1756 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1757 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1758 (item[choice1].type==NM_TYPE_CHECK) ||
1759 (item[choice1].type==NM_TYPE_RADIO) ||
1760 (item[choice1].type==NM_TYPE_NUMBER) ||
1761 (item[choice1].type==NM_TYPE_SLIDER) )
1762 && (ascii==toupper(ch)) ) {
1766 item[old_choice].redraw=1;
1767 item[choice].redraw=1;
1769 } while (choice1 != choice );
1773 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1774 int ov=item[choice].value;
1779 case KEY_MINUS+KEY_SHIFTED:
1781 item[choice].value -= 1;
1786 case KEY_EQUAL+KEY_SHIFTED:
1788 item[choice].value++;
1793 item[choice].value += 10;
1798 item[choice].value -= 10;
1801 if (ov!=item[choice].value)
1802 item[choice].redraw=1;
1807 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1808 gr_set_current_canvas(bg.menu_canvas));
1810 // Redraw everything...
1811 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1813 if (item[i].redraw) // warning! ugly hack below
1815 item[i].y-=((string_height+1)*ScrollOffset);
1818 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1820 MAC(if (!joydefs_calibrating) show_cursor());
1821 WIN(if (!MenuReordering) ShowCursorW());
1822 item[i].y+=((string_height+1)*ScrollOffset);
1824 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1825 update_cursor( &item[i]);
1831 //grd_curcanv->cv_font = NORMAL_FONT;
1833 if (LastScrollCheck!=ScrollOffset)
1835 LastScrollCheck=ScrollOffset;
1836 grd_curcanv->cv_font = SELECTED_FONT;
1838 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1839 sx=item[ScrollOffset].x-(MenuHires?24:12);
1842 if (ScrollOffset!=0)
1843 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1845 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1847 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1848 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1850 if (ScrollOffset+MaxDisplayable<nitems)
1851 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1853 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1859 if ( !dont_restore && gr_palette_faded_out ) {
1860 gr_palette_fade_in( gr_palette, 32, 0 );
1867 // Restore everything...
1869 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1870 gr_set_current_canvas(bg.menu_canvas));
1872 if ( filename == NULL ) {
1873 // Save the background under the menu...
1874 WIN (DDGRLOCK(dd_grd_curcanv));
1875 gr_bitmap(0, 0, bg.saved);
1876 WIN (DDGRUNLOCK(dd_grd_curcanv));
1877 gr_free_bitmap(bg.saved);
1878 d_free( bg.background );
1880 if (!dont_restore) //info passed back from subfunction
1882 WIN (DDGRLOCK(dd_grd_curcanv));
1883 gr_bitmap(0, 0, bg.background);
1884 WIN (DDGRUNLOCK(dd_grd_curcanv));
1886 gr_free_bitmap(bg.background);
1889 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1890 gr_free_sub_canvas( bg.menu_canvas ) );
1892 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1893 grd_curcanv->cv_font = save_font;
1894 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1895 keyd_repeat = old_keyd_repeat;
1897 game_flush_inputs();
1908 if ( sound_stopped )
1909 digi_resume_digi_sounds();
1911 WIN(mouse_set_mode(1)); //re-enable centering mode
1918 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1924 char nm_text[MESSAGEBOX_TEXT_SIZE];
1925 newmenu_item nm_message_items[5];
1927 va_start(args, nchoices );
1929 Assert( nchoices <= 5 );
1931 for (i=0; i<nchoices; i++ ) {
1932 s = va_arg( args, char * );
1933 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1935 format = va_arg( args, char * );
1936 strcpy( nm_text, "" );
1937 vsprintf(nm_text,format,args);
1940 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1942 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1945 int nm_messagebox( char *title, int nchoices, ... )
1951 char nm_text[MESSAGEBOX_TEXT_SIZE];
1952 newmenu_item nm_message_items[5];
1954 va_start(args, nchoices );
1956 Assert( nchoices <= 5 );
1958 for (i=0; i<nchoices; i++ ) {
1959 s = va_arg( args, char * );
1960 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1962 format = va_arg( args, char * );
1963 strcpy( nm_text, "" );
1964 vsprintf(nm_text,format,args);
1967 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1969 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1975 void newmenu_file_sort( int n, char *list )
1982 for (i=incr; i<n; i++ ) {
1985 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1986 memcpy( t, &list[j*14], FILENAME_LEN );
1987 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1988 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1999 void delete_player_saved_games(char * name)
2004 for (i=0;i<10; i++) {
2006 sprintf( filename, "%s.sg%d", name, i );
2008 sprintf( filename, ":Players:%s.sg%d", name, i );
2014 #define MAX_FILES 300
2016 int MakeNewPlayerFile(int allow_abort);
2018 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2021 FILEFINDSTRUCT find;
2022 int NumFiles=0, key,done, citem, ocitem;
2023 char * filenames = NULL;
2024 int NumFiles_displayed = 8;
2025 int first_item = -1, ofirst_item;
2026 int old_keyd_repeat = keyd_repeat;
2029 int demos_deleted=0;
2030 int initialized = 0;
2032 int w_x, w_y, w_w, w_h, title_height;
2033 int box_x, box_y, box_w, box_h;
2034 bkg bg; // background under listbox
2035 #if defined(MACINTOSH) || defined(WINDOWS)
2036 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2037 int mouse2_state, omouse2_state;
2038 int dblclick_flag=0;
2040 int show_up_arrow=0,show_down_arrow=0;
2042 WIN(int win_redraw=0);
2044 w_x=w_y=w_w=w_h=title_height=0;
2045 box_x=box_y=box_w=box_h=0;
2047 filenames = d_malloc( MAX_FILES * 14 );
2048 if (filenames==NULL) return 0;
2053 WIN(mouse_set_mode(0)); //disable centering mode
2055 if (strstr( filespec, "*.plr" ))
2057 else if (strstr( filespec, "*.dem" ))
2064 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2066 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2071 if( !FileFindFirst( filespec, &find ) ) {
2073 if (NumFiles<MAX_FILES) {
2074 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2075 if ( player_mode ) {
2077 p = strchr(&filenames[NumFiles*14],'.');
2084 } while( !FileFindNext( &find ) );
2088 if ( (NumFiles < 1) && demos_deleted ) {
2092 if ( (NumFiles < 1) && demo_mode ) {
2093 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2099 if ( (NumFiles < 2) && player_mode ) {
2101 goto ExitFileMenuEarly;
2108 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2115 // set_screen_mode(SCREEN_MENU);
2121 dd_gr_set_current_canvas(NULL);
2123 gr_set_current_canvas(NULL);
2126 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2128 grd_curcanv->cv_font = SUBTITLE_FONT;
2130 WIN(DDGRUNLOCK(dd_grd_curcanv));
2135 for (i=0; i<NumFiles; i++ ) {
2137 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2143 gr_get_string_size( title, &w, &h, &aw );
2146 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2150 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2152 w_w += (grd_curfont->ft_w * 4);
2153 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2155 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2156 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2158 w_x = (grd_curcanv->cv_w-w_w)/2;
2159 w_y = (grd_curcanv->cv_h-w_h)/2;
2161 if ( w_x < 0 ) w_x = 0;
2162 if ( w_y < 0 ) w_y = 0;
2164 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2165 box_y = w_y + title_height;
2167 // save the screen behind the menu.
2171 #if !defined(WINDOWS)
2172 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2173 bg.background = &VR_offscreen_buffer->cv_bitmap;
2176 #if defined(POLY_ACC)
2177 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2179 bg.background = gr_create_bitmap( w_w, w_h );
2182 Assert( bg.background != NULL );
2185 WIN(DDGRLOCK(dd_grd_curcanv));
2186 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2187 WIN(DDGRUNLOCK(dd_grd_curcanv));
2191 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2192 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2193 dd_VR_offscreen_buffer, 0, 0,
2194 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2195 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2199 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2201 WIN(DDGRLOCK(dd_grd_curcanv))
2203 gr_string( 0x8000, w_y+10, title );
2205 WIN(DDGRUNLOCK(dd_grd_curcanv));
2212 if ( !player_mode ) {
2213 newmenu_file_sort( NumFiles, filenames );
2215 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2216 newmenu_file_sort( NumFiles, filenames );
2218 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2220 for ( i=0; i<NumFiles; i++ ) {
2221 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2222 #if defined(WINDOWS) || defined(MACINTOSH)
2230 #if defined(MACINTOSH) || defined(WINDOWS)
2231 mouse_state = omouse_state = 0;
2232 mouse2_state = omouse2_state = 0;
2233 draw_close_box(w_x,w_y);
2245 DoMessageStuff(&msg);
2247 if (_RedrawScreen) {
2248 _RedrawScreen = FALSE;
2250 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2251 gr_free_bitmap(bg.background);
2254 goto RePaintNewmenuFile;
2261 ofirst_item = first_item;
2264 #if defined(MACINTOSH) || defined(WINDOWS)
2265 omouse_state = mouse_state;
2266 omouse2_state = mouse2_state;
2267 mouse_state = mouse_button_state(0);
2268 mouse2_state = mouse_button_state(1);
2271 //see if redbook song needs to be restarted
2272 songs_check_redbook_repeat();
2275 if (!mouse2_state && omouse2_state)
2276 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2279 //NOTE LINK TO ABOVE ELSE
2285 else if (simukey==1)
2291 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2292 case KEY_PRINT_SCREEN:
2294 save_screen_shot(0);
2295 PA_DFX (pa_set_frontbuffer_current());
2296 PA_DFX (pa_set_front_to_read());
2302 case KEY_CTRLED+KEY_D:
2303 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2307 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2311 mouse_set_mode(1); //re-enable centering mode
2315 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2317 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2320 mouse_set_mode(0); //disenable centering mode
2326 char name[_MAX_PATH],dir[_MAX_DIR];
2328 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2332 _splitpath(filespec,name,dir,NULL,NULL);
2334 strcat(name,&filenames[citem*14]);
2341 if ( !strncmp(name, ".\\", 2) )
2342 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2343 name[i] = name[i+1];
2344 while ( (p = strchr(name, '\\')) )
2349 ret = unlink( name );
2353 if ((!ret) && player_mode) {
2354 delete_player_saved_games( &filenames[citem*14] );
2359 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2361 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2362 } else if (demo_mode)
2387 citem += NumFiles_displayed;
2391 citem -= NumFiles_displayed;
2394 if (allow_abort_flag) {
2405 case KEY_COMMAND+KEY_Q: {
2406 extern void macintosh_quit();
2408 if ( !(Game_mode & GM_MULTI) )
2419 int ascii = key_to_ascii(key);
2420 if ( ascii < 255 ) {
2423 if (cc1 < 0 ) cc1 = 0;
2424 if (cc1 >= NumFiles ) cc1 = 0;
2426 if ( cc < 0 ) cc = 0;
2427 if ( cc >= NumFiles ) cc = 0;
2428 if ( citem == cc ) break;
2430 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2445 if (citem>=NumFiles)
2448 if (citem< first_item)
2451 if (citem>=( first_item+NumFiles_displayed))
2453 first_item = citem-NumFiles_displayed+1;
2457 if (NumFiles>first_item+NumFiles_displayed)
2468 if (NumFiles <= NumFiles_displayed )
2471 if (first_item>NumFiles-NumFiles_displayed)
2473 first_item = NumFiles-NumFiles_displayed;
2476 if (first_item < 0 ) first_item = 0;
2478 #if defined(MACINTOSH) || defined(WINDOWS)
2480 if (mouse_state || mouse2_state) {
2483 mouse_get_pos(&mx, &my);
2484 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2485 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2487 x2 = box_x + box_w - 1;
2488 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2490 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2491 if (i == citem && !mouse2_state) {
2501 if (!mouse_state && omouse_state) {
2504 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2505 mouse_get_pos(&mx, &my);
2507 x2 = box_x + box_w - 1;
2508 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2510 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2511 if (dblclick_flag) done = 1;
2512 else dblclick_flag = 1;
2516 if ( !mouse_state && omouse_state ) {
2517 mouse_get_pos(&mx, &my);
2518 x1 = w_x + CLOSE_X + 2;
2519 x2 = x1 + CLOSE_SIZE - 2;
2520 y1 = w_y + CLOSE_Y + 2;
2521 y2 = y1 + CLOSE_SIZE - 2;
2522 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2531 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2533 y1 = box_y+box_h-LHY(7);
2535 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2542 WIN(DDGRLOCK(dd_grd_curcanv));
2543 gr_setcolor( BM_XRGB(2,2,2));
2544 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2545 gr_setcolor( BM_XRGB( 0,0,0) );
2548 if (ofirst_item != first_item || win_redraw) {
2551 if (ofirst_item != first_item) {
2555 gr_setcolor( BM_XRGB( 0,0,0) );
2556 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2558 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2560 if ( i >= NumFiles ) {
2562 gr_setcolor( BM_XRGB(5,5,5));
2563 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2564 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2566 gr_setcolor( BM_XRGB(2,2,2));
2567 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2569 gr_setcolor( BM_XRGB(0,0,0));
2570 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2574 grd_curcanv->cv_font = SELECTED_FONT;
2576 grd_curcanv->cv_font = NORMAL_FONT;
2577 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2579 gr_setcolor( BM_XRGB(5,5,5));
2580 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2581 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2583 gr_setcolor( BM_XRGB(2,2,2));
2584 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2585 gr_setcolor( BM_XRGB(0,0,0));
2587 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2588 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2593 } else if ( citem != ocitem ) {
2599 if ( (i>=0) && (i<NumFiles) ) {
2600 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
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 );
2606 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2607 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2610 if ( (i>=0) && (i<NumFiles) ) {
2611 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2613 grd_curcanv->cv_font = SELECTED_FONT;
2615 grd_curcanv->cv_font = NORMAL_FONT;
2616 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2617 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2618 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2625 grd_curcanv->cv_font = NORMAL_FONT;
2627 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2631 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2635 if (show_down_arrow)
2636 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2640 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2648 WIN(DDGRUNLOCK(dd_grd_curcanv));
2654 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2661 keyd_repeat = old_keyd_repeat;
2663 if ( initialized ) {
2664 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2666 WIN (DDGRLOCK(dd_grd_curcanv));
2667 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2668 WIN (DDGRUNLOCK(dd_grd_curcanv));
2670 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2671 gr_free_bitmap(bg.background);
2674 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2675 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2677 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2678 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2688 WIN(mouse_set_mode(1)); //re-enable centering mode
2696 // Example listbox callback function...
2697 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2701 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2702 // if ( *nitems > 1 ) {
2703 // unlink( items[*citem] ); // Delete the file
2704 // for (i=*citem; i<*nitems-1; i++ ) {
2705 // items[i] = items[i+1];
2707 // *nitems = *nitems - 1;
2708 // d_free( items[*nitems] );
2709 // items[*nitems] = NULL;
2710 // return 1; // redraw;
2717 #define LB_ITEMS_ON_SCREEN 8
2719 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2721 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2724 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 ) )
2727 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2728 int old_keyd_repeat = keyd_repeat;
2729 int width, height, wx, wy, title_height, border_size;
2730 int total_width,total_height;
2732 #if defined(MACINTOSH) || defined(WINDOWS)
2733 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2734 int close_x,close_y;
2735 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2737 WIN(int win_redraw=0);
2741 PA_DFX (pa_set_frontbuffer_current());
2742 PA_DFX (pa_set_front_to_read());
2743 WIN(mouse_set_mode(0)); //disable centering mode
2745 // set_screen_mode(SCREEN_MENU);
2749 RePaintNewmenuListbox:
2751 dd_gr_set_current_canvas(NULL);
2753 gr_set_current_canvas(NULL);
2756 grd_curcanv->cv_font = SUBTITLE_FONT;
2759 for (i=0; i<nitems; i++ ) {
2761 gr_get_string_size( items[i], &w, &h, &aw );
2765 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2769 gr_get_string_size( title, &w, &h, &aw );
2772 title_height = h + 5;
2775 border_size = grd_curfont->ft_w;
2776 WIN (border_size=grd_curfont->ft_w*2);
2778 width += (grd_curfont->ft_w);
2779 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2780 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2782 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2783 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2784 if ( wy < title_height )
2787 total_width = width+2*border_size;
2788 total_height = height+2*border_size+title_height;
2792 #if !defined(WINDOWS)
2793 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2794 bg.background = &VR_offscreen_buffer->cv_bitmap;
2797 //bg.background = gr_create_bitmap( width, (height + title_height) );
2798 #if defined(POLY_ACC)
2799 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2801 bg.background = gr_create_bitmap(total_width,total_height);
2803 Assert( bg.background != NULL );
2805 WIN (DDGRLOCK(dd_grd_curcanv));
2806 //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 );
2807 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2808 WIN (DDGRUNLOCK(dd_grd_curcanv));
2812 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2813 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2814 dd_VR_offscreen_buffer, 0, 0,
2815 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2816 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2820 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2822 WIN(DDGRLOCK(dd_grd_curcanv));
2823 gr_string( 0x8000, wy - title_height, title );
2824 WIN(DDGRUNLOCK(dd_grd_curcanv));
2829 citem = default_item;
2830 if ( citem < 0 ) citem = 0;
2831 if ( citem >= nitems ) citem = 0;
2835 #if defined(MACINTOSH) || defined(WINDOWS)
2836 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2837 close_x = wx-border_size;
2838 close_y = wy-title_height-border_size;
2839 draw_close_box(close_x,close_y);
2851 DoMessageStuff(&msg);
2853 if (_RedrawScreen) {
2854 _RedrawScreen = FALSE;
2856 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2857 gr_free_bitmap(bg.background);
2859 goto RePaintNewmenuListbox;
2866 ofirst_item = first_item;
2867 #if defined(MACINTOSH) || defined(WINDOWS)
2868 omouse_state = mouse_state;
2869 mouse_state = mouse_button_state(0);
2871 //see if redbook song needs to be restarted
2872 songs_check_redbook_repeat();
2876 if ( listbox_callback )
2877 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2898 else if (simukey==1)
2904 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2905 case KEY_PRINT_SCREEN:
2907 save_screen_shot(0);
2908 PA_DFX (pa_set_frontbuffer_current());
2909 PA_DFX (pa_set_front_to_read());
2932 citem += LB_ITEMS_ON_SCREEN;
2936 citem -= LB_ITEMS_ON_SCREEN;
2939 if (allow_abort_flag) {
2950 case KEY_COMMAND+KEY_Q: {
2951 extern void macintosh_quit();
2953 if ( !(Game_mode & GM_MULTI) )
2963 int ascii = key_to_ascii(key);
2964 if ( ascii < 255 ) {
2967 if (cc1 < 0 ) cc1 = 0;
2968 if (cc1 >= nitems ) cc1 = 0;
2970 if ( cc < 0 ) cc = 0;
2971 if ( cc >= nitems ) cc = 0;
2972 if ( citem == cc ) break;
2974 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2991 if (citem< first_item)
2994 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2995 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2997 if (nitems <= LB_ITEMS_ON_SCREEN )
3000 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
3001 first_item = nitems-LB_ITEMS_ON_SCREEN;
3002 if (first_item < 0 ) first_item = 0;
3005 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3016 #if defined(MACINTOSH) || defined(WINDOWS)
3021 mouse_get_pos(&mx, &my);
3022 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3025 gr_get_string_size(items[i], &w, &h, &aw );
3028 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3030 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3042 //no double-click stuff for listbox
3043 //@@if (!mouse_state && omouse_state) {
3046 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3047 //@@ mouse_get_pos(&mx, &my);
3049 //@@ x2 = wx + width;
3050 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3052 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3053 //@@ if (dblclick_flag) done = 1;
3057 //check for close box clicked
3058 if ( !mouse_state && omouse_state ) {
3059 mouse_get_pos(&mx, &my);
3060 x1 = close_x + CLOSE_X + 2;
3061 x2 = x1 + CLOSE_SIZE - 2;
3062 y1 = close_y + CLOSE_Y + 2;
3063 y2 = y1 + CLOSE_SIZE - 2;
3064 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3074 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3076 y1 = total_height-LHY(7);
3078 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3086 if ( (ofirst_item != first_item) || redraw) {
3089 WIN(DDGRLOCK(dd_grd_curcanv));
3091 gr_setcolor( BM_XRGB( 0,0,0) );
3092 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3094 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3095 if ( i >= nitems ) {
3096 gr_setcolor( BM_XRGB(0,0,0));
3097 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3100 grd_curcanv->cv_font = SELECTED_FONT;
3102 grd_curcanv->cv_font = NORMAL_FONT;
3103 gr_get_string_size(items[i], &w, &h, &aw );
3104 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3105 gr_string( wx+5, y, items[i] );
3110 // If Win95 port, draw up/down arrows on left side of menu
3112 grd_curcanv->cv_font = NORMAL_FONT;
3114 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3118 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3122 if (show_down_arrow)
3123 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3127 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3134 WIN(DDGRUNLOCK(dd_grd_curcanv));
3138 } else if ( citem != ocitem ) {
3144 WIN(DDGRLOCK(dd_grd_curcanv));
3147 if ( (i>=0) && (i<nitems) ) {
3148 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3150 grd_curcanv->cv_font = SELECTED_FONT;
3152 grd_curcanv->cv_font = NORMAL_FONT;
3153 gr_get_string_size(items[i], &w, &h, &aw );
3154 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3155 gr_string( wx+5, y, items[i] );
3159 if ( (i>=0) && (i<nitems) ) {
3160 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3162 grd_curcanv->cv_font = SELECTED_FONT;
3164 grd_curcanv->cv_font = NORMAL_FONT;
3165 gr_get_string_size( items[i], &w, &h, &aw );
3166 gr_rect( wx, y-1, wx+width-1, y+h );
3167 gr_string( wx+5, y, items[i] );
3169 WIN(DDGRUNLOCK(dd_grd_curcanv));
3179 keyd_repeat = old_keyd_repeat;
3181 WIN (DDGRLOCK(dd_grd_curcanv));
3182 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3183 WIN (DDGRUNLOCK(dd_grd_curcanv));
3185 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3186 gr_free_bitmap(bg.background);
3190 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3191 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3193 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3194 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3200 WIN(mouse_set_mode(1)); //re-enable centering mode
3205 int newmenu_filelist( char * title, char * filespec, char * filename )
3208 char * Filenames[MAX_FILES];
3209 char FilenameText[MAX_FILES][14];
3210 FILEFINDSTRUCT find;
3213 if( !FileFindFirst( filespec, &find ) ) {
3215 if (NumFiles<MAX_FILES) {
3216 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3217 Filenames[NumFiles] = FilenameText[NumFiles];
3222 } while( !FileFindNext( &find ) );
3226 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3228 strcpy( filename, Filenames[i] );
3235 extern netgame_info Active_games[];
3236 extern int NumActiveNetgames;
3238 void show_extra_netgame_info(int choice)
3244 if (choice>=NumActiveNetgames)
3249 m[i].text=(char *)&mtext[i];
3250 m[i].type=NM_TYPE_TEXT;
3253 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3254 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3255 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3256 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3258 already_showing_info=1;
3259 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3260 already_showing_info=0;
3265 /* Spiffy word wrap string formatting function */
3267 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3273 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3276 wordptr = strtok(tbuf, " ");
3277 if (!wordptr) return;
3283 col = col+strlen(wordptr)+1;
3284 if (col >=line_length) {
3286 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3289 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3291 wordptr = strtok(NULL, " ");