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.
16 static char rcsid[] = "$Id: newmenu.c,v 1.1.1.1 2001-01-19 03:30:01 bradleyb Exp $";
32 #include "pa_enabl.h" //$$POLY_ACC
77 #define MAXDISPLAYABLEITEMS 15
79 #define LHX(x) ((x)*(MenuHires?2:1))
80 #define LHY(y) ((y)*(MenuHires?2.4:1))
82 #define TITLE_FONT HUGE_FONT
83 #define NORMAL_FONT MEDIUM1_FONT //normal, non-highlighted item
84 #define SELECTED_FONT MEDIUM2_FONT //highlighted item
85 #define SUBTITLE_FONT MEDIUM3_FONT
87 #define NORMAL_CHECK_BOX "
\81"
88 #define CHECKED_CHECK_BOX "
\82"
90 #define NORMAL_RADIO_BOX "
\7f"
91 #define CHECKED_RADIO_BOX "
\80"
92 #define CURSOR_STRING "_"
93 #define SLIDER_LEFT "
\83" // 131
94 #define SLIDER_RIGHT "
\84" // 132
95 #define SLIDER_MIDDLE "
\85" // 133
96 #define SLIDER_MARKER "
\86" // 134
97 #define UP_ARROW_MARKER "
\87" // 135
98 #define DOWN_ARROW_MARKER "
\88" // 136
100 int Newmenu_first_time = 1;
101 //--unused-- int Newmenu_fade_in = 1;
104 WINDOS (dd_grs_canvas *menu_canvas, grs_canvas * menu_canvas);
105 grs_bitmap * saved; // The background under the menu.
106 grs_bitmap * background;
109 grs_bitmap nm_background,nm_background_save;
111 #define MESSAGEBOX_TEXT_SIZE 300 // How many characters in messagebox
112 #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be
114 extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
116 ubyte MenuReordering=0;
118 char Pauseable_menu=0;
119 char already_showing_info=0;
122 void newmenu_close() {
123 if ( nm_background.bm_data )
124 d_free(nm_background.bm_data);
126 if ( nm_background_save.bm_data )
127 d_free(nm_background_save.bm_data);
128 Newmenu_first_time = 1;
131 ubyte background_palette[768];
133 //should be called whenever the palette changes
134 void nm_remap_background()
136 if (!Newmenu_first_time) {
137 if (!nm_background.bm_data)
138 nm_background.bm_data = d_malloc(nm_background.bm_w * nm_background.bm_h);
140 memcpy(nm_background.bm_data,nm_background_save.bm_data,nm_background.bm_w * nm_background.bm_h);
142 gr_remap_bitmap_good( &nm_background, background_palette, -1, -1 );
148 extern char last_palette_loaded[];
150 void nm_draw_background1(char * filename)
156 //@@//I think this only gets called to fill the whole screen
157 //@@Assert(grd_curcanv->cv_bitmap.bm_w == 320);
158 //@@Assert(grd_curcanv->cv_bitmap.bm_h == 200);
160 bmp = gr_create_bitmap(grd_curcanv->cv_bitmap.bm_w,grd_curcanv->cv_bitmap.bm_h);
162 pcx_error = pcx_read_bitmap(filename,bmp,bmp->bm_type,pal);
163 Assert(pcx_error == PCX_ERROR_NONE);
165 //@@gr_remap_bitmap_good( bmp, pal, -1, -1 );
168 { //remap stuff. this code is kindof a hack
170 //now, before we bring up the menu, we need to
171 //do some stuff to make sure the palette is ok. First, we need to
172 //get our current palette into the 2d's array, so the remapping will
173 //work. Second, we need to remap the fonts. Third, we need to fill
174 //in part of the fade tables so the darkening of the menu edges works
176 gr_copy_palette(gr_palette, pal, sizeof(gr_palette));
177 remap_fonts_and_menus(1);
181 WIN(DDGRLOCK(dd_grd_curcanv));
182 #if defined(POLY_ACC)
184 pa_update_clut(gr_palette, 0, 256, 0);
187 #if defined(POLY_ACC)
190 WIN(DDGRUNLOCK(dd_grd_curcanv));
194 strcpy(last_palette_loaded,""); //force palette load next time
199 #define MENU_BACKGROUND_BITMAP (MenuHires?"\x01scoresb.pcx":"\x01scores.pcx") //read only from hog file
201 #define MENU_BACKGROUND_BITMAP (MenuHires?"scoresb.pcx":"scores.pcx")
204 int Background_hires;
207 void nm_draw_background(int x1, int y1, int x2, int y2 )
211 if (Newmenu_first_time || MenuHires!=Background_hires) {
214 if (Newmenu_first_time) {
215 atexit( newmenu_close );
216 Newmenu_first_time = 0;
217 nm_background_save.bm_data=NULL;
220 if (nm_background_save.bm_data)
221 d_free(nm_background_save.bm_data);
222 if (nm_background.bm_data)
223 d_free(nm_background.bm_data);
226 pcx_error = pcx_read_bitmap(MENU_BACKGROUND_BITMAP,&nm_background_save,BM_LINEAR,background_palette);
227 Assert(pcx_error == PCX_ERROR_NONE);
229 nm_background = nm_background_save;
230 nm_background.bm_data=NULL;
231 nm_remap_background();
233 Background_hires = MenuHires;
236 if ( x1 < 0 ) x1 = 0;
237 if ( y1 < 0 ) y1 = 0;
242 if ( w > nm_background.bm_w ) w = nm_background.bm_w;
243 if ( h > nm_background.bm_h ) h = nm_background.bm_h;
248 WIN(DDGRLOCK(dd_grd_curcanv));
250 gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) );
252 gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) );
257 Gr_scanline_darkening_level = 2*7;
260 gr_setcolor( BM_XRGB(0,0,0) );
261 gr_urect( x2-5, y1+5, x2-5, y2-5 );
262 gr_urect( x2-4, y1+4, x2-4, y2-5 );
263 gr_urect( x2-3, y1+3, x2-3, y2-5 );
264 gr_urect( x2-2, y1+2, x2-2, y2-5 );
265 gr_urect( x2-1, y1+1, x2-1, y2-5 );
266 gr_urect( x2+0, y1+0, x2-0, y2-5 );
268 gr_urect( x1+5, y2-5, x2, y2-5 );
269 gr_urect( x1+4, y2-4, x2, y2-4 );
270 gr_urect( x1+3, y2-3, x2, y2-3 );
271 gr_urect( x1+2, y2-2, x2, y2-2 );
272 gr_urect( x1+1, y2-1, x2, y2-1 );
273 gr_urect( x1+0, y2, x2, y2-0 );
275 WIN(DDGRUNLOCK(dd_grd_curcanv));
277 Gr_scanline_darkening_level = GR_FADE_LEVELS;
280 void nm_restore_background( int x, int y, int w, int h )
287 if ( x1 < 0 ) x1 = 0;
288 if ( y1 < 0 ) y1 = 0;
290 if ( x2 >= nm_background.bm_w ) x2=nm_background.bm_w-1;
291 if ( y2 >= nm_background.bm_h ) y2=nm_background.bm_h-1;
296 WIN(DDGRLOCK(dd_grd_curcanv));
297 gr_bm_bitblt(w, h, x1, y1, x1, y1, &nm_background, &(grd_curcanv->cv_bitmap) );
298 WIN(DDGRUNLOCK(dd_grd_curcanv));
301 // Draw a left justfied string
302 void nm_string( bkg * b, int w1,int x, int y, char * s)
304 int w,h,aw,tx=0,t=0,i;
305 char *p,*s1,measure[2];
306 int XTabs[]={15,87,124,162,228,253};
310 XTabs[i]=(LHX(XTabs[i]));
318 p = strchr( s, '\t' );
325 gr_get_string_size(s, &w, &h, &aw );
331 gr_bm_bitblt(b->background->bm_w-15, h+2, 5, y-1, 5, y-1, b->background, &(grd_curcanv->cv_bitmap) );
332 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
336 for (i=0;i<strlen(s);i++)
338 if (s[i]=='\t' && SurfingNet)
345 gr_get_string_size(measure,&tx,&h,&aw);
346 gr_string(x,y,measure);
350 else gr_string (x,y,s);
352 if (!SurfingNet && p && (w1>0) ) {
353 gr_get_string_size(s1, &w, &h, &aw );
355 gr_string( x+w1-w, y, s1 );
361 // Draw a slider and it's string
362 void nm_string_slider( bkg * b, int w1,int x, int y, char * s )
367 p = strchr( s, '\t' );
373 gr_get_string_size(s, &w, &h, &aw );
376 gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) );
377 //gr_bm_bitblt(w, h, x, y, x, y, b->background, &(grd_curcanv->cv_bitmap) );
379 gr_string( x, y, s );
382 gr_get_string_size(s1, &w, &h, &aw );
385 gr_bm_bitblt(w, 1, x+w1-w, y, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
387 gr_bm_bitblt(w, 1, x+w1-w, y+h-1, x+w1-w, y, b->background, &(grd_curcanv->cv_bitmap) );
389 gr_string( x+w1-w, y, s1 );
396 // Draw a left justfied string with black background.
397 void nm_string_black( bkg * b, int w1,int x, int y, char * s )
400 gr_get_string_size(s, &w, &h, &aw );
404 WIN(DDGRLOCK(dd_grd_curcanv));
405 gr_setcolor( BM_XRGB(2,2,2) );
406 gr_rect( x-1, y-1, x-1, y+h-1 );
407 gr_rect( x-1, y-1, x+w1-1, y-1 );
410 gr_setcolor( BM_XRGB(5,5,5) );
411 gr_rect( x, y+h, x+w1, y+h);
412 gr_rect( x+w1, y-1, x+w1, y+h );
414 gr_setcolor( BM_XRGB(0,0,0) );
415 gr_rect( x, y, x+w1-1, y+h-1 );
417 gr_string( x+1, y+1, s );
418 WIN(DDGRUNLOCK(dd_grd_curcanv));
422 // Draw a right justfied string
423 void nm_rstring( bkg * b,int w1,int x, int y, char * s )
426 gr_get_string_size(s, &w, &h, &aw );
431 //mprintf( 0, "Width = %d, string='%s'\n", w, s );
434 WIN(DDGRLOCK(dd_grd_curcanv));
435 gr_bm_bitblt(w1, h, x-w1, y, x-w1, y, b->background, &(grd_curcanv->cv_bitmap) );
436 gr_string( x-w, y, s );
437 WIN(DDGRUNLOCK(dd_grd_curcanv));
442 //for text items, constantly redraw cursor (to achieve flash)
443 void update_cursor( newmenu_item *item)
446 fix time = timer_get_approx_seconds();
448 char * text = item->text;
450 Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
453 gr_get_string_size(text, &w, &h, &aw );
454 if ( w > item->w-10 )
461 x = item->x+w; y = item->y;
463 WIN(DDGRLOCK(dd_grd_curcanv));
465 gr_string( x, y, CURSOR_STRING );
467 gr_setcolor( BM_XRGB(0,0,0) );
468 gr_rect( x, y, x+grd_curcanv->cv_font->ft_w-1, y+grd_curcanv->cv_font->ft_h-1 );
470 WIN(DDGRUNLOCK(dd_grd_curcanv));
473 void nm_string_inputbox( bkg *b, int w, int x, int y, char * text, int current )
478 gr_get_string_size(text, &w1, &h1, &aw );
487 nm_string_black( b, w, x, y, text );
490 gr_string( x+w1+1, y, CURSOR_STRING );
494 void draw_item( bkg * b, newmenu_item *item, int is_current,int tiny )
499 gr_set_fontcolor(gr_find_closest_color_current(57,49,20),-1);
501 gr_set_fontcolor(gr_find_closest_color_current(29,29,47),-1);
503 if (item->text[0]=='\t')
504 gr_set_fontcolor (gr_find_closest_color_current(63,63,63),-1);
509 grd_curcanv->cv_font = SELECTED_FONT;
511 grd_curcanv->cv_font = NORMAL_FONT;
514 if (is_current && item->type == NM_TYPE_TEXT)
515 grd_curcanv->cv_font = NORMAL_FONT;
519 WIN(DDGRLOCK(dd_grd_curcanv));
520 switch( item->type ) {
522 // grd_curcanv->cv_font=TEXT_FONT;
523 // fall through on purpose
526 nm_string( b, item->w, item->x, item->y, item->text );
528 case NM_TYPE_SLIDER: {
530 if (item->value < item->min_value) item->value=item->min_value;
531 if (item->value > item->max_value) item->value=item->max_value;
532 sprintf( item->saved_text, "%s\t%s", item->text, SLIDER_LEFT );
533 for (j=0; j<(item->max_value-item->min_value+1); j++ ) {
534 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_MIDDLE );
536 sprintf( item->saved_text, "%s%s", item->saved_text,SLIDER_RIGHT );
538 item->saved_text[item->value+1+strlen(item->text)+1] = SLIDER_MARKER[0];
540 nm_string_slider( b, item->w, item->x, item->y, item->saved_text );
543 case NM_TYPE_INPUT_MENU:
544 if ( item->group==0 ) {
545 nm_string( b, item->w, item->x, item->y, item->text );
547 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
551 nm_string_inputbox( b, item->w, item->x, item->y, item->text, is_current );
554 nm_string( b, item->w, item->x, item->y, item->text );
556 nm_rstring( b,item->right_offset,item->x, item->y, CHECKED_CHECK_BOX );
558 nm_rstring( b,item->right_offset,item->x, item->y, NORMAL_CHECK_BOX );
561 nm_string( b, item->w, item->x, item->y, item->text );
563 nm_rstring( b,item->right_offset, item->x, item->y, CHECKED_RADIO_BOX );
565 nm_rstring( b,item->right_offset, item->x, item->y, NORMAL_RADIO_BOX );
567 case NM_TYPE_NUMBER: {
569 if (item->value < item->min_value) item->value=item->min_value;
570 if (item->value > item->max_value) item->value=item->max_value;
571 nm_string( b, item->w, item->x, item->y, item->text );
572 sprintf( text, "%d", item->value );
573 nm_rstring( b,item->right_offset,item->x, item->y, text );
577 WIN(DDGRUNLOCK(dd_grd_curcanv));
581 char *Newmenu_allowed_chars=NULL;
583 //returns true if char is allowed
584 int char_allowed(char c)
586 char *p = Newmenu_allowed_chars;
594 if (c>=p[0] && c<=p[1])
603 void strip_end_whitespace( char * text )
607 for (i=l-1; i>=0; i-- ) {
608 if ( isspace(text[i]) )
615 int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
617 return newmenu_do3( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1 );
619 int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
621 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, LHX(310), -1, 1 );
625 int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) )
627 return newmenu_do4( title, subtitle, nitems, item, subfunction, 0, NULL, -1, -1, 1 );
631 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 )
633 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, NULL, -1, -1 );
637 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 )
639 return newmenu_do3( title, subtitle, nitems, item, subfunction, citem, filename, -1, -1 );
641 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 )
643 return newmenu_do4( title, subtitle, nitems, item, subfunction, citem, filename, width, height,0 );
646 //returns 1 if a control device button has been pressed
647 int check_button_press()
651 switch (Config_control_type) {
652 case CONTROL_JOYSTICK:
653 case CONTROL_FLIGHTSTICK_PRO:
654 case CONTROL_THRUSTMASTER_FCS:
655 case CONTROL_GRAVIS_GAMEPAD:
657 if (joy_get_button_down_cnt(i)>0) return 1;
660 case CONTROL_CYBERMAN:
661 #ifndef MACINTOSH // don't allow mouse to continue from menu
663 if (mouse_button_down_count(i)>0) return 1;
666 case CONTROL_WINJOYSTICK:
669 if (joy_get_button_down_cnt(i)>0) return 1;
672 case CONTROL_NONE: //keyboard only
674 if (key_checkch()) return 1;
679 Error("Bad control type (Config_control_type):%i",Config_control_type);
685 extern int network_request_player_names(int);
686 extern int RestoringMenu;
688 #if defined(WINDOWS) || defined(MACINTOSH)
689 ubyte Hack_DblClick_MenuMode=0;
692 MAC(extern ubyte joydefs_calibrating;)
696 #define CLOSE_SIZE 10
698 void draw_close_box(int x,int y)
700 WIN (DDGRLOCK(dd_grd_curcanv));
701 gr_setcolor( BM_XRGB(0, 0, 0) );
702 gr_rect(x + CLOSE_X, y + CLOSE_Y, x + CLOSE_X + CLOSE_SIZE, y + CLOSE_Y + CLOSE_SIZE);
703 gr_setcolor( BM_XRGB(21, 21, 21) );
704 gr_rect( x + CLOSE_X + 2, y + CLOSE_Y + 2, x + CLOSE_X + CLOSE_SIZE - 2, y + CLOSE_Y + CLOSE_SIZE - 2 );
705 WIN (DDGRUNLOCK(dd_grd_curcanv));
708 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 )
710 int old_keyd_repeat, done;
711 int choice,old_choice,i,j,x,y,w,h,aw, tw, th, twidth,fm,right_offset;
712 int k, nmenus, nothers,ScrollOffset=0,LastScrollCheck=-1,MaxDisplayable,sx,sy;
713 grs_font * save_font;
714 int string_width, string_height, average_width;
717 int all_text=0; //set true if all text items
718 int sound_stopped=0,time_stopped=0;
719 int TopChoice,IsScrollBox=0; // Is this a scrolling box? Set to false at init
722 int MaxOnMenu=MAXDISPLAYABLEITEMS;
723 WINDOS(dd_grs_canvas *save_canvas, grs_canvas *save_canvas );
724 #if defined(MACINTOSH) || defined(WINDOWS)
725 int mouse_state, omouse_state, dblclick_flag=0;
726 int mx=0, my=0, x1, x2, y1, y2;
730 EventRecord event; // looking for disk inserted events for CD mounts
733 PA_DFX (pa_set_frontbuffer_current());
734 PA_DFX (pa_set_front_to_read());
736 WIN(if (!_AppActive) return -1); // Don't draw message if minimized!
745 WIN(mouse_set_mode(0)); //disable centering mode
747 MaxDisplayable=nitems;
749 // set_screen_mode(SCREEN_MENU);
752 if ( Function_mode == FMODE_GAME && !(Game_mode & GM_MULTI)) {
753 digi_pause_digi_sounds();
757 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
768 WINDOS( save_canvas = dd_grd_curcanv, save_canvas = grd_curcanv );
770 WINDOS( dd_gr_set_current_canvas(NULL), gr_set_current_canvas(NULL) );
772 save_font = grd_curcanv->cv_font;
777 grd_curcanv->cv_font = TITLE_FONT;
778 gr_get_string_size(title,&string_width,&string_height,&average_width );
783 grd_curcanv->cv_font = SUBTITLE_FONT;
784 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
785 if (string_width > tw )
790 th += LHY(8); //put some space between titles & body
793 grd_curcanv->cv_font = SMALL_FONT;
795 grd_curcanv->cv_font = NORMAL_FONT;
799 nmenus = nothers = 0;
801 // Find menu height & width (store in w,h)
802 for (i=0; i<nitems; i++ ) {
805 gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
806 item[i].right_offset = 0;
809 string_height+=LHY(3);
811 item[i].saved_text[0] = '\0';
813 if ( item[i].type == NM_TYPE_SLIDER ) {
816 sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
817 for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
818 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_MIDDLE );
820 sprintf( item[i].saved_text, "%s%s", item[i].saved_text,SLIDER_RIGHT );
821 gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
822 string_width += w1 + aw;
825 if ( item[i].type == NM_TYPE_MENU ) {
829 if ( item[i].type == NM_TYPE_CHECK ) {
832 gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
833 item[i].right_offset = w1;
834 gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
835 if (w1 > item[i].right_offset)
836 item[i].right_offset = w1;
839 if (item[i].type == NM_TYPE_RADIO ) {
842 gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
843 item[i].right_offset = w1;
844 gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
845 if (w1 > item[i].right_offset)
846 item[i].right_offset = w1;
849 if (item[i].type==NM_TYPE_NUMBER ) {
853 sprintf( test_text, "%d", item[i].max_value );
854 gr_get_string_size( test_text, &w1, &h1, &aw1 );
855 item[i].right_offset = w1;
856 sprintf( test_text, "%d", item[i].min_value );
857 gr_get_string_size( test_text, &w1, &h1, &aw1 );
858 if ( w1 > item[i].right_offset)
859 item[i].right_offset = w1;
862 if ( item[i].type == NM_TYPE_INPUT ) {
863 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
864 strcpy(item[i].saved_text, item[i].text );
866 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
867 if ( string_width > MAX_TEXT_WIDTH )
868 string_width = MAX_TEXT_WIDTH;
872 if ( item[i].type == NM_TYPE_INPUT_MENU ) {
873 Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
874 strcpy(item[i].saved_text, item[i].text );
876 string_width = item[i].text_len*grd_curcanv->cv_font->ft_w+((MenuHires?3:1)*item[i].text_len);
881 item[i].w = string_width;
882 item[i].h = string_height;
884 if ( string_width > w )
885 w = string_width; // Save maximum width
886 if ( average_width > aw )
888 h += string_height+1; // Find the height of all strings
891 // Big hack for allowing the netgame options menu to spill over
893 MaxOnMenu=MAXDISPLAYABLEITEMS;
894 if (ExtGameStatus==GAMESTAT_NETGAME_OPTIONS || ExtGameStatus==GAMESTAT_MORE_NETGAME_OPTIONS)
897 if (!TinyMode && (h>((MaxOnMenu+1)*(string_height+1))+(LHY(8))))
900 h=(MaxOnMenu*(string_height+1)+LHY(8));
901 MaxDisplayable=MaxOnMenu;
902 mprintf ((0,"Hey, this is a scroll box!\n"));
915 for (i=0; i<nitems; i++ ) {
917 if (item[i].right_offset > right_offset )
918 right_offset = item[i].right_offset;
920 if (right_offset > 0 )
923 //gr_get_string_size("",&string_width,&string_height,&average_width );
930 twidth = ( tw - w )/2;
935 { right_offset=0; twidth=0;}
937 mprintf(( 0, "Right offset = %d\n", right_offset ));
940 // Find min point of menu border
941 // x = (grd_curscreen->sc_w-w)/2;
942 // y = (grd_curscreen->sc_h-h)/2;
944 w += MenuHires?60:30;
945 h += MenuHires?60:30;
947 if ( w > grd_curcanv->cv_bitmap.bm_w ) w = grd_curcanv->cv_bitmap.bm_w;
948 if ( h > grd_curcanv->cv_bitmap.bm_h ) h = grd_curcanv->cv_bitmap.bm_h;
950 x = (grd_curcanv->cv_bitmap.bm_w-w)/2;
951 y = (grd_curcanv->cv_bitmap.bm_h-h)/2;
956 if ( filename != NULL ) {
957 nm_draw_background1( filename );
958 gr_palette_load(gr_palette);
961 // Save the background of the display
962 // Win95 must refer to the screen as a dd_grs_canvas, so...
963 WINDOS ( bg.menu_canvas = dd_gr_create_sub_canvas( dd_grd_screencanv, x, y, w, h ),
964 bg.menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h )
966 WINDOS ( dd_gr_set_current_canvas( bg.menu_canvas ),
967 gr_set_current_canvas(bg.menu_canvas) );
969 if ( filename == NULL ) {
970 // Save the background under the menu...
976 #if defined(POLY_ACC)
977 bg.saved = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
979 bg.saved = gr_create_bitmap( w, h );
981 Assert( bg.saved != NULL );
983 WIN (DDGRLOCK(dd_grd_curcanv));
984 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.saved );
985 WIN (DDGRUNLOCK(dd_grd_curcanv));
987 WINDOS ( dd_gr_set_current_canvas(NULL),
988 gr_set_current_canvas( NULL )
991 nm_draw_background(x,y,x+w-1,y+h-1);
993 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
994 gr_set_current_canvas( bg.menu_canvas )
997 bg.background = gr_create_sub_bitmap(&nm_background,0,0,w,h);
1001 #if defined(POLY_ACC)
1002 bg.background = gr_create_bitmap2( w, h, grd_curcanv->cv_bitmap.bm_type, NULL );
1004 bg.background = gr_create_bitmap( w, h );
1006 Assert( bg.background != NULL );
1008 WIN (DDGRLOCK(dd_grd_curcanv));
1009 gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg.background );
1010 WIN (DDGRUNLOCK(dd_grd_curcanv));
1013 // ty = 15 + (yborder/4);
1015 ty = MenuHires?30:15;
1018 grd_curcanv->cv_font = TITLE_FONT;
1019 gr_set_fontcolor( GR_GETCOLOR(31,31,31), -1 );
1020 gr_get_string_size(title,&string_width,&string_height,&average_width );
1023 WIN (DDGRLOCK(dd_grd_curcanv));
1024 gr_printf( 0x8000, ty, title );
1025 WIN (DDGRUNLOCK(dd_grd_curcanv));
1030 grd_curcanv->cv_font = SUBTITLE_FONT;
1031 gr_set_fontcolor( GR_GETCOLOR(21,21,21), -1 );
1032 gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
1035 WIN (DDGRLOCK(dd_grd_curcanv));
1036 gr_printf( 0x8000, ty, subtitle );
1037 WIN (DDGRUNLOCK(dd_grd_curcanv));
1042 grd_curcanv->cv_font = SMALL_FONT;
1044 grd_curcanv->cv_font = NORMAL_FONT;
1046 // Update all item's x & y values.
1047 for (i=0; i<nitems; i++ ) {
1048 item[i].x = (MenuHires?30:15) + twidth + right_offset;
1049 item[i].y += (MenuHires?30:15);
1050 if ( item[i].type==NM_TYPE_RADIO ) {
1051 fm = -1; // find first marked one
1052 for ( j=0; j<nitems; j++ ) {
1053 if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
1054 if (fm==-1 && item[j].value)
1066 old_keyd_repeat = keyd_repeat;
1072 if (citem < 0 ) citem = 0;
1073 if (citem > nitems-1 ) citem = nitems-1;
1076 #if defined(WINDOWS) || defined(MACINTOSH)
1080 while ( item[choice].type==NM_TYPE_TEXT ) {
1082 if (choice >= nitems ) {
1085 if (choice == citem ) {
1096 // Clear mouse, joystick to clear button presses.
1097 game_flush_inputs();
1099 #if defined(WINDOWS) || defined(MACINTOSH)
1100 mouse_state = omouse_state = 0;
1101 if (filename == NULL && !MenuReordering) {
1102 draw_close_box(0,0);
1108 if (!MenuReordering) {
1110 SetCursor (LoadCursor(NULL,IDC_ARROW));
1115 if (!joydefs_calibrating)
1119 mprintf ((0,"Set to true!\n"));
1125 DoMessageStuff(&msg);
1127 if (_RedrawScreen) {
1128 _RedrawScreen = FALSE;
1131 gr_free_bitmap(bg.saved);
1132 d_free( bg.background );
1135 gr_free_bitmap(bg.background);
1137 dd_gr_free_sub_canvas( bg.menu_canvas );
1138 grd_curcanv->cv_font = save_font;
1139 dd_grd_curcanv = save_canvas;
1141 goto RePaintNewmenu4;
1150 omouse_state = mouse_state;
1151 mouse_state = mouse_button_state(0);
1152 if (!joydefs_calibrating)
1153 show_cursor(); // possibly hidden
1157 omouse_state = mouse_state;
1158 if (!MenuReordering)
1159 mouse_state = mouse_button_state(0);
1160 //@@ mprintf ((0,"mouse state:%d\n",mouse_state));
1163 //see if redbook song needs to be restarted
1164 songs_check_redbook_repeat();
1171 (*subfunction)(nitems,item,&k,choice);
1174 if (!time_stopped) {
1175 // Save current menu box
1176 if (multi_menu_poll() == -1)
1182 dont_restore = (k == -3); //-3 means don't restore
1188 if (check_button_press())
1192 // if ( (nmenus<2) && (k>0) && (nothers==0) )
1195 old_choice = choice;
1201 if (SurfingNet && !already_showing_info)
1203 show_extra_netgame_info(choice-2);
1205 if (SurfingNet && already_showing_info)
1212 if (SurfingNet && !already_showing_info)
1214 network_request_player_names(choice-2);
1216 if (SurfingNet && already_showing_info)
1231 case KEY_TAB + KEY_SHIFTED:
1234 if (all_text) break;
1241 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1243 if (choice<TopChoice)
1244 { choice=TopChoice; break; }
1246 if (choice<ScrollOffset)
1248 for (i=0;i<nitems;i++)
1251 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1256 if (choice >= nitems ) choice=0;
1257 if (choice < 0 ) choice=nitems-1;
1259 } while ( item[choice].type==NM_TYPE_TEXT );
1260 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1261 item[choice].value = -1;
1262 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1263 item[old_choice].group=0;
1264 strcpy(item[old_choice].text, item[old_choice].saved_text );
1265 item[old_choice].value = -1;
1268 item[old_choice].redraw = 1;
1269 item[choice].redraw=1;
1274 // ((0,"Pressing down! IsScrollBox=%d",IsScrollBox));
1275 if (all_text) break;
1282 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1285 { choice--; break; }
1287 if (choice>=MaxOnMenu+ScrollOffset)
1289 for (i=0;i<nitems;i++)
1292 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1297 if (choice < 0 ) choice=nitems-1;
1298 if (choice >= nitems ) choice=0;
1301 } while ( item[choice].type==NM_TYPE_TEXT );
1303 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1304 item[choice].value = -1;
1305 if ( (old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1306 item[old_choice].group=0;
1307 strcpy(item[old_choice].text, item[old_choice].saved_text );
1308 item[old_choice].value = -1;
1311 item[old_choice].redraw=1;
1312 item[choice].redraw=1;
1315 if ( choice > -1 ) {
1316 switch( item[choice].type ) {
1319 case NM_TYPE_INPUT_MENU:
1322 if ( item[choice].value )
1323 item[choice].value = 0;
1325 item[choice].value = 1;
1326 mprintf ((0,"ISB=%d MDI=%d SO=%d choice=%d\n",IsScrollBox,MAXDISPLAYABLEITEMS,ScrollOffset,choice));
1329 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1331 mprintf ((0,"Special redraw!\n"));
1336 item[choice].redraw=1;
1339 for (i=0; i<nitems; i++ ) {
1340 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1345 item[choice].value = 1;
1346 item[choice].redraw = 1;
1352 case KEY_SHIFTED+KEY_UP:
1353 if (MenuReordering && choice!=TopChoice)
1355 Temp=item[choice].text;
1356 TempVal=item[choice].value;
1357 item[choice].text=item[choice-1].text;
1358 item[choice].value=item[choice-1].value;
1359 item[choice-1].text=Temp;
1360 item[choice-1].value=TempVal;
1361 item[choice].redraw=1;
1362 item[choice-1].redraw=1;
1366 case KEY_SHIFTED+KEY_DOWN:
1367 if (MenuReordering && choice!=(nitems-1))
1369 Temp=item[choice].text;
1370 TempVal=item[choice].value;
1371 item[choice].text=item[choice+1].text;
1372 item[choice].value=item[choice+1].value;
1373 item[choice+1].text=Temp;
1374 item[choice+1].value=TempVal;
1375 item[choice].redraw=1;
1376 item[choice+1].redraw=1;
1383 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1384 item[choice].group = 1;
1385 item[choice].redraw = 1;
1386 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1387 item[choice].text[0] = 0;
1388 item[choice].value = -1;
1390 strip_end_whitespace(item[choice].text);
1397 if ( (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==1)) {
1398 item[choice].group=0;
1399 strcpy(item[choice].text, item[choice].saved_text );
1400 item[choice].redraw=1;
1401 item[choice].value = -1;
1408 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1409 case KEY_PRINT_SCREEN:
1411 save_screen_shot(0);
1412 PA_DFX (pa_set_frontbuffer_current());
1413 PA_DFX (pa_set_front_to_read());
1414 for (i=0;i<nitems;i++)
1423 case KEY_COMMAND+KEY_RIGHT:
1424 songs_goto_next_song();
1426 case KEY_COMMAND+KEY_LEFT:
1427 songs_goto_prev_song();
1429 case KEY_COMMAND+KEY_UP:
1430 songs_play_level_song(1);
1432 case KEY_COMMAND+KEY_DOWN:
1433 songs_stop_redbook();
1436 case KEY_COMMAND+KEY_M:
1438 #if !defined(SHAREWARE) || defined(APPLE_DEMO)
1439 if ( (Game_mode & GM_MULTI) ) // don't process in multiplayer games
1442 key_close(); // no processing of keys with keyboard handler.. jeez
1445 show_boxed_message ("Mounting CD\nESC to quit");
1446 RBAMountDisk(); // OS has totaly control of the CD.
1447 if (Function_mode == FMODE_MENU)
1448 songs_play_song(SONG_TITLE,1);
1449 else if (Function_mode == FMODE_GAME)
1450 songs_play_level_song( Current_level_num );
1451 clear_boxed_message();
1460 case KEY_COMMAND+KEY_E:
1461 songs_stop_redbook();
1463 k = -1; // force key not to register
1466 case KEY_COMMAND+KEY_Q: {
1467 extern void macintosh_quit();
1469 if ( !(Game_mode & GM_MULTI) )
1471 if (!joydefs_calibrating)
1473 k = -1; // force key not to register
1480 if ( (choice>-1) && (item[choice].type!=NM_TYPE_INPUT)&&(item[choice].type!=NM_TYPE_INPUT_MENU))
1487 #if defined(MACINTOSH) || defined(WINDOWS) // for mouse selection of menu's etc.
1489 if ( !done && mouse_state && !omouse_state && !all_text ) {
1490 mouse_get_pos(&mx, &my);
1491 for (i=0; i<nitems; i++ ) {
1492 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1493 x2 = x1 + item[i].w;
1494 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1495 y2 = y1 + item[i].h;
1496 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1497 if (i+ScrollOffset != choice) {
1498 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1501 choice = i + ScrollOffset;
1503 switch( item[choice].type ) {
1505 if ( item[choice].value )
1506 item[choice].value = 0;
1508 item[choice].value = 1;
1509 item[choice].redraw=1;
1516 if (choice==(MaxOnMenu+ScrollOffset-1) || choice==ScrollOffset)
1518 mprintf ((0,"Special redraw!\n"));
1525 for (i=0; i<nitems; i++ ) {
1526 if ((i!=choice) && (item[i].type==NM_TYPE_RADIO) && (item[i].group==item[choice].group) && (item[i].value) ) {
1531 item[choice].value = 1;
1532 item[choice].redraw = 1;
1535 item[old_choice].redraw=1;
1541 if (mouse_state && all_text)
1544 if ( !done && mouse_state && !all_text ) {
1545 mouse_get_pos(&mx, &my);
1547 // check possible scrollbar stuff first
1549 int arrow_width, arrow_height, aw;
1551 if (ScrollOffset != 0) {
1552 gr_get_string_size(UP_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1553 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset].x-(MenuHires?24:12);
1554 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1555 x1 = x1 - arrow_width;
1556 y2 = y1 + arrow_height;
1557 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1560 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1562 if (choice<ScrollOffset)
1564 for (i=0;i<nitems;i++)
1567 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1571 if (ScrollOffset+MaxDisplayable<nitems) {
1572 gr_get_string_size(DOWN_ARROW_MARKER, &arrow_width, &arrow_height, &aw);
1573 x2 = grd_curcanv->cv_bitmap.bm_x + item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1574 y1 = grd_curcanv->cv_bitmap.bm_y + item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1575 x1 = x1 - arrow_width;
1576 y2 = y1 + arrow_height;
1577 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1580 mprintf ((0,"Scrolling! Choice=%d\n",choice));
1582 if (choice>=MaxOnMenu+ScrollOffset)
1584 for (i=0;i<nitems;i++)
1587 mprintf ((0,"ScrollOffset=%d\n",ScrollOffset));
1593 for (i=0; i<nitems; i++ ) {
1594 x1 = grd_curcanv->cv_bitmap.bm_x + item[i].x - item[i].right_offset - 6;
1595 x2 = x1 + item[i].w;
1596 y1 = grd_curcanv->cv_bitmap.bm_y + item[i].y;
1597 y2 = y1 + item[i].h;
1598 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && (item[i].type != NM_TYPE_TEXT) ) {
1599 if (i+ScrollOffset != choice) {
1600 if(Hack_DblClick_MenuMode) dblclick_flag = 0;
1603 choice = i + ScrollOffset;
1605 if ( item[choice].type == NM_TYPE_SLIDER ) {
1606 char slider_text[NM_MAX_TEXT_LEN+1], *p, *s1;
1607 int slider_width, height, aw, sleft_width, sright_width, smiddle_width;
1609 strcpy(slider_text, item[choice].saved_text);
1610 p = strchr(slider_text, '\t');
1616 gr_get_string_size(s1, &slider_width, &height, &aw);
1617 gr_get_string_size(SLIDER_LEFT, &sleft_width, &height, &aw);
1618 gr_get_string_size(SLIDER_RIGHT, &sright_width, &height, &aw);
1619 gr_get_string_size(SLIDER_MIDDLE, &smiddle_width, &height, &aw);
1621 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x + item[choice].w - slider_width;
1622 x2 = x1 + slider_width + sright_width;
1623 if ( (mx > x1) && (mx < (x1 + sleft_width)) && (item[choice].value != item[choice].min_value) ) {
1624 item[choice].value = item[choice].min_value;
1625 item[choice].redraw = 2;
1626 } else if ( (mx < x2) && (mx > (x2 - sright_width)) && (item[choice].value != item[choice].max_value) ) {
1627 item[choice].value = item[choice].max_value;
1628 item[choice].redraw = 2;
1629 } else if ( (mx > (x1 + sleft_width)) && (mx < (x2 - sright_width)) ) {
1630 int num_values, value_width, new_value;
1632 num_values = item[choice].max_value - item[choice].min_value + 1;
1633 value_width = (slider_width - sleft_width - sright_width) / num_values;
1634 new_value = (mx - x1 - sleft_width) / value_width;
1635 if ( item[choice].value != new_value ) {
1636 item[choice].value = new_value;
1637 item[choice].redraw = 2;
1643 if (choice == old_choice)
1645 if ((item[choice].type==NM_TYPE_INPUT) && (choice!=old_choice))
1646 item[choice].value = -1;
1647 if ((old_choice>-1) && (item[old_choice].type==NM_TYPE_INPUT_MENU) && (old_choice!=choice)) {
1648 item[old_choice].group=0;
1649 strcpy(item[old_choice].text, item[old_choice].saved_text );
1650 item[old_choice].value = -1;
1653 item[old_choice].redraw = 1;
1654 item[choice].redraw=1;
1660 if ( !done && !mouse_state && omouse_state && !all_text && (choice != -1) && (item[choice].type == NM_TYPE_MENU) ) {
1661 mouse_get_pos(&mx, &my);
1662 x1 = grd_curcanv->cv_bitmap.bm_x + item[choice].x;
1663 x2 = x1 + item[choice].w;
1664 y1 = grd_curcanv->cv_bitmap.bm_y + item[choice].y;
1665 y2 = y1 + item[choice].h;
1666 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1667 if (Hack_DblClick_MenuMode) {
1668 if (dblclick_flag) done = 1;
1669 else dblclick_flag = 1;
1675 if ( !done && !mouse_state && omouse_state && (choice>-1) && (item[choice].type==NM_TYPE_INPUT_MENU) && (item[choice].group==0)) {
1676 item[choice].group = 1;
1677 item[choice].redraw = 1;
1678 if ( !strnicmp( item[choice].saved_text, TXT_EMPTY, strlen(TXT_EMPTY) ) ) {
1679 item[choice].text[0] = 0;
1680 item[choice].value = -1;
1682 strip_end_whitespace(item[choice].text);
1686 if ( !done && !mouse_state && omouse_state && close_box ) {
1687 mouse_get_pos(&mx, &my);
1688 x1 = grd_curcanv->cv_bitmap.bm_x + CLOSE_X;
1689 x2 = x1 + CLOSE_SIZE;
1690 y1 = grd_curcanv->cv_bitmap.bm_y + CLOSE_Y;
1691 y2 = y1 + CLOSE_SIZE;
1692 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1698 // HACK! Don't redraw loadgame preview
1699 if (RestoringMenu) item[0].redraw = 0;
1700 #endif // ifdef MACINTOSH
1702 if ( choice > -1 ) {
1705 if ( ((item[choice].type==NM_TYPE_INPUT)||((item[choice].type==NM_TYPE_INPUT_MENU)&&(item[choice].group==1)) )&& (old_choice==choice) ) {
1706 if ( k==KEY_LEFT || k==KEY_BACKSP || k==KEY_PAD4 ) {
1707 if (item[choice].value==-1) item[choice].value = strlen(item[choice].text);
1708 if (item[choice].value > 0)
1709 item[choice].value--;
1710 item[choice].text[item[choice].value] = 0;
1711 item[choice].redraw = 1;
1713 ascii = key_to_ascii(k);
1714 if ((ascii < 255 ) && (item[choice].value < item[choice].text_len ))
1718 if (item[choice].value==-1) {
1719 item[choice].value = 0;
1722 allowed = char_allowed(ascii);
1724 if (!allowed && ascii==' ' && char_allowed('_')) {
1730 item[choice].text[item[choice].value++] = ascii;
1731 item[choice].text[item[choice].value] = 0;
1732 item[choice].redraw=1;
1736 } else if ((item[choice].type!=NM_TYPE_INPUT) && (item[choice].type!=NM_TYPE_INPUT_MENU) ) {
1737 ascii = key_to_ascii(k);
1739 int choice1 = choice;
1740 ascii = toupper(ascii);
1744 if (choice1 >= nitems ) choice1=0;
1745 for (i=0;(ch=item[choice1].text[i])!=0 && ch==' ';i++);
1746 if ( ( (item[choice1].type==NM_TYPE_MENU) ||
1747 (item[choice1].type==NM_TYPE_CHECK) ||
1748 (item[choice1].type==NM_TYPE_RADIO) ||
1749 (item[choice1].type==NM_TYPE_NUMBER) ||
1750 (item[choice1].type==NM_TYPE_SLIDER) )
1751 && (ascii==toupper(ch)) ) {
1755 item[old_choice].redraw=1;
1756 item[choice].redraw=1;
1758 } while (choice1 != choice );
1762 if ( (item[choice].type==NM_TYPE_NUMBER) || (item[choice].type==NM_TYPE_SLIDER)) {
1763 int ov=item[choice].value;
1768 case KEY_MINUS+KEY_SHIFTED:
1770 item[choice].value -= 1;
1775 case KEY_EQUAL+KEY_SHIFTED:
1777 item[choice].value++;
1782 item[choice].value += 10;
1787 item[choice].value -= 10;
1790 if (ov!=item[choice].value)
1791 item[choice].redraw=1;
1796 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1797 gr_set_current_canvas(bg.menu_canvas));
1799 // Redraw everything...
1800 for (i=ScrollOffset; i<MaxDisplayable+ScrollOffset; i++ )
1802 if (item[i].redraw) // warning! ugly hack below
1804 item[i].y-=((string_height+1)*ScrollOffset);
1807 draw_item( &bg, &item[i], (i==choice && !all_text),TinyMode );
1809 MAC(if (!joydefs_calibrating) show_cursor());
1810 WIN(if (!MenuReordering) ShowCursorW());
1811 item[i].y+=((string_height+1)*ScrollOffset);
1813 if (i==choice && (item[i].type==NM_TYPE_INPUT || (item[i].type==NM_TYPE_INPUT_MENU && item[i].group)))
1814 update_cursor( &item[i]);
1820 //grd_curcanv->cv_font = NORMAL_FONT;
1822 if (LastScrollCheck!=ScrollOffset)
1824 LastScrollCheck=ScrollOffset;
1825 grd_curcanv->cv_font = SELECTED_FONT;
1827 sy=item[ScrollOffset].y-((string_height+1)*ScrollOffset);
1828 sx=item[ScrollOffset].x-(MenuHires?24:12);
1831 if (ScrollOffset!=0)
1832 nm_rstring( &bg, (MenuHires?20:10), sx, sy, UP_ARROW_MARKER );
1834 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1836 sy=item[ScrollOffset+MaxDisplayable-1].y-((string_height+1)*ScrollOffset);
1837 sx=item[ScrollOffset+MaxDisplayable-1].x-(MenuHires?24:12);
1839 if (ScrollOffset+MaxDisplayable<nitems)
1840 nm_rstring( &bg, (MenuHires?20:10), sx, sy, DOWN_ARROW_MARKER );
1842 nm_rstring( &bg, (MenuHires?20:10), sx, sy, " " );
1848 if ( !dont_restore && gr_palette_faded_out ) {
1849 gr_palette_fade_in( gr_palette, 32, 0 );
1856 // Restore everything...
1858 WINDOS ( dd_gr_set_current_canvas(bg.menu_canvas),
1859 gr_set_current_canvas(bg.menu_canvas));
1861 if ( filename == NULL ) {
1862 // Save the background under the menu...
1863 WIN (DDGRLOCK(dd_grd_curcanv));
1864 gr_bitmap(0, 0, bg.saved);
1865 WIN (DDGRUNLOCK(dd_grd_curcanv));
1866 gr_free_bitmap(bg.saved);
1867 d_free( bg.background );
1869 if (!dont_restore) //info passed back from subfunction
1871 WIN (DDGRLOCK(dd_grd_curcanv));
1872 gr_bitmap(0, 0, bg.background);
1873 WIN (DDGRUNLOCK(dd_grd_curcanv));
1875 gr_free_bitmap(bg.background);
1878 WINDOS ( dd_gr_free_sub_canvas(bg.menu_canvas),
1879 gr_free_sub_canvas( bg.menu_canvas ) );
1881 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( NULL ));
1882 grd_curcanv->cv_font = save_font;
1883 WINDOS (dd_gr_set_current_canvas(NULL), gr_set_current_canvas( save_canvas ));
1884 keyd_repeat = old_keyd_repeat;
1886 game_flush_inputs();
1897 if ( sound_stopped )
1898 digi_resume_digi_sounds();
1900 WIN(mouse_set_mode(1)); //re-enable centering mode
1907 int nm_messagebox1( char *title, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem), int nchoices, ... )
1913 char nm_text[MESSAGEBOX_TEXT_SIZE];
1914 newmenu_item nm_message_items[5];
1916 va_start(args, nchoices );
1918 Assert( nchoices <= 5 );
1920 for (i=0; i<nchoices; i++ ) {
1921 s = va_arg( args, char * );
1922 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1924 format = va_arg( args, char * );
1925 sprintf( nm_text, "" );
1926 vsprintf(nm_text,format,args);
1929 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE);
1931 return newmenu_do( title, nm_text, nchoices, nm_message_items, subfunction );
1934 int nm_messagebox( char *title, int nchoices, ... )
1940 char nm_text[MESSAGEBOX_TEXT_SIZE];
1941 newmenu_item nm_message_items[5];
1943 va_start(args, nchoices );
1945 Assert( nchoices <= 5 );
1947 for (i=0; i<nchoices; i++ ) {
1948 s = va_arg( args, char * );
1949 nm_message_items[i].type = NM_TYPE_MENU; nm_message_items[i].text = s;
1951 format = va_arg( args, char * );
1952 sprintf( nm_text, "" );
1953 vsprintf(nm_text,format,args);
1956 Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
1958 return newmenu_do( title, nm_text, nchoices, nm_message_items, NULL );
1964 void newmenu_file_sort( int n, char *list )
1971 for (i=incr; i<n; i++ ) {
1974 if (strncmp(&list[j*14], &list[(j+incr)*14], 12) > 0) {
1975 memcpy( t, &list[j*14], FILENAME_LEN );
1976 memcpy( &list[j*14], &list[(j+incr)*14], FILENAME_LEN );
1977 memcpy( &list[(j+incr)*14], t, FILENAME_LEN );
1988 void delete_player_saved_games(char * name)
1993 for (i=0;i<10; i++) {
1995 sprintf( filename, "%s.sg%d", name, i );
1997 sprintf( filename, ":Players:%s.sg%d", name, i );
2003 #define MAX_FILES 300
2005 int MakeNewPlayerFile(int allow_abort);
2007 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
2010 FILEFINDSTRUCT find;
2011 int NumFiles=0, key,done, citem, ocitem;
2012 char * filenames = NULL;
2013 int NumFiles_displayed = 8;
2014 int first_item = -1, ofirst_item;
2015 int old_keyd_repeat = keyd_repeat;
2018 int demos_deleted=0;
2019 int initialized = 0;
2021 int w_x, w_y, w_w, w_h, title_height;
2022 int box_x, box_y, box_w, box_h;
2023 bkg bg; // background under listbox
2024 #if defined(MACINTOSH) || defined(WINDOWS)
2025 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state;
2026 int mouse2_state, omouse2_state;
2027 int dblclick_flag=0;
2029 int show_up_arrow=0,show_down_arrow=0;
2031 WIN(int win_redraw=0);
2033 filenames = d_malloc( MAX_FILES * 14 );
2034 if (filenames==NULL) return 0;
2039 WIN(mouse_set_mode(0)); //disable centering mode
2041 if (strstr( filespec, "*.plr" ))
2043 else if (strstr( filespec, "*.dem" ))
2050 #if !defined(APPLE_DEMO) // no new pilots for special apple oem version
2052 strncpy( &filenames[NumFiles*14], TXT_CREATE_NEW, FILENAME_LEN );
2057 if( !FileFindFirst( filespec, &find ) ) {
2059 if (NumFiles<MAX_FILES) {
2060 strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
2061 if ( player_mode ) {
2063 p = strchr(&filenames[NumFiles*14],'.');
2070 } while( !FileFindNext( &find ) );
2074 if ( (NumFiles < 1) && demos_deleted ) {
2078 if ( (NumFiles < 1) && demo_mode ) {
2079 nm_messagebox( NULL, 1, TXT_OK, "%s %s\n%s", TXT_NO_DEMO_FILES, TXT_USE_F5, TXT_TO_CREATE_ONE);
2085 if ( (NumFiles < 2) && player_mode ) {
2087 goto ExitFileMenuEarly;
2094 nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
2101 // set_screen_mode(SCREEN_MENU);
2107 dd_gr_set_current_canvas(NULL);
2109 gr_set_current_canvas(NULL);
2112 WIN(DDGRLOCK(dd_grd_curcanv)) //mwa put these here -- are these needed Samir???
2114 grd_curcanv->cv_font = SUBTITLE_FONT;
2116 WIN(DDGRUNLOCK(dd_grd_curcanv));
2121 for (i=0; i<NumFiles; i++ ) {
2123 gr_get_string_size( &filenames[i*14], &w, &h, &aw );
2129 gr_get_string_size( title, &w, &h, &aw );
2132 title_height = h + (grd_curfont->ft_h*2); // add a little space at the bottom of the title
2136 box_h = ((grd_curfont->ft_h + 2) * NumFiles_displayed);
2138 w_w += (grd_curfont->ft_w * 4);
2139 w_h = title_height + box_h + (grd_curfont->ft_h * 2); // more space at bottom
2141 if ( w_w > grd_curcanv->cv_w ) w_w = grd_curcanv->cv_w;
2142 if ( w_h > grd_curcanv->cv_h ) w_h = grd_curcanv->cv_h;
2144 w_x = (grd_curcanv->cv_w-w_w)/2;
2145 w_y = (grd_curcanv->cv_h-w_h)/2;
2147 if ( w_x < 0 ) w_x = 0;
2148 if ( w_y < 0 ) w_y = 0;
2150 box_x = w_x + (grd_curfont->ft_w*2); // must be in sync with w_w!!!
2151 box_y = w_y + title_height;
2153 // save the screen behind the menu.
2157 #if !defined(WINDOWS)
2158 if ( (VR_offscreen_buffer->cv_w >= w_w) && (VR_offscreen_buffer->cv_h >= w_h) )
2159 bg.background = &VR_offscreen_buffer->cv_bitmap;
2162 #if defined(POLY_ACC)
2163 bg.background = gr_create_bitmap2( w_w, w_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2165 bg.background = gr_create_bitmap( w_w, w_h );
2168 Assert( bg.background != NULL );
2171 WIN(DDGRLOCK(dd_grd_curcanv));
2172 gr_bm_bitblt(w_w, w_h, 0, 0, w_x, w_y, &grd_curcanv->cv_bitmap, bg.background );
2173 WIN(DDGRUNLOCK(dd_grd_curcanv));
2177 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2178 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2179 dd_VR_offscreen_buffer, 0, 0,
2180 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2181 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2185 nm_draw_background( w_x,w_y,w_x+w_w-1,w_y+w_h-1 );
2187 WIN(DDGRLOCK(dd_grd_curcanv))
2189 gr_string( 0x8000, w_y+10, title );
2191 WIN(DDGRUNLOCK(dd_grd_curcanv));
2198 if ( !player_mode ) {
2199 newmenu_file_sort( NumFiles, filenames );
2201 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2202 newmenu_file_sort( NumFiles, filenames );
2204 newmenu_file_sort( NumFiles-1, &filenames[14] ); // Don't sort first one!
2206 for ( i=0; i<NumFiles; i++ ) {
2207 if (!stricmp(Players[Player_num].callsign, &filenames[i*14]) ) {
2208 #if defined(WINDOWS) || defined(MACINTOSH)
2216 #if defined(MACINTOSH) || defined(WINDOWS)
2217 mouse_state = omouse_state = 0;
2218 mouse2_state = omouse2_state = 0;
2219 draw_close_box(w_x,w_y);
2231 DoMessageStuff(&msg);
2233 if (_RedrawScreen) {
2234 _RedrawScreen = FALSE;
2236 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2237 gr_free_bitmap(bg.background);
2240 goto RePaintNewmenuFile;
2247 ofirst_item = first_item;
2250 #if defined(MACINTOSH) || defined(WINDOWS)
2251 omouse_state = mouse_state;
2252 omouse2_state = mouse2_state;
2253 mouse_state = mouse_button_state(0);
2254 mouse2_state = mouse_button_state(1);
2257 //see if redbook song needs to be restarted
2258 songs_check_redbook_repeat();
2261 if (!mouse2_state && omouse2_state)
2262 key = KEY_CTRLED+KEY_D; //fake ctrl-d
2265 //NOTE LINK TO ABOVE ELSE
2271 else if (simukey==1)
2277 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2278 case KEY_PRINT_SCREEN:
2280 save_screen_shot(0);
2281 PA_DFX (pa_set_frontbuffer_current());
2282 PA_DFX (pa_set_front_to_read());
2288 case KEY_CTRLED+KEY_D:
2289 #if defined(MACINTOSH) && defined(APPLE_DEMO)
2293 if ( ((player_mode)&&(citem>0)) || ((demo_mode)&&(citem>=0)) ) {
2297 mouse_set_mode(1); //re-enable centering mode
2301 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2303 x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2306 mouse_set_mode(0); //disenable centering mode
2312 char name[_MAX_PATH],dir[_MAX_DIR];
2314 p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
2318 _splitpath(filespec,name,dir,NULL,NULL);
2320 strcat(name,&filenames[citem*14]);
2327 if ( !strncmp(name, ".\\", 2) )
2328 for (i = 0; i < strlen(name); i++) // don't subtract 1 from strlen to get the EOS marker
2329 name[i] = name[i+1];
2330 while ( (p = strchr(name, '\\')) )
2335 ret = unlink( name );
2339 if ((!ret) && player_mode) {
2340 delete_player_saved_games( &filenames[citem*14] );
2345 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_PILOT, &filenames[citem*14]+((player_mode && filenames[citem*14]=='$')?1:0) );
2347 nm_messagebox( NULL, 1, TXT_OK, "%s %s %s", TXT_COULDNT, TXT_DELETE_DEMO, &filenames[citem*14]+((demo_mode && filenames[citem*14]=='$')?1:0) );
2348 } else if (demo_mode)
2373 citem += NumFiles_displayed;
2377 citem -= NumFiles_displayed;
2380 if (allow_abort_flag) {
2391 case KEY_COMMAND+KEY_Q: {
2392 extern void macintosh_quit();
2394 if ( !(Game_mode & GM_MULTI) )
2405 int ascii = key_to_ascii(key);
2406 if ( ascii < 255 ) {
2409 if (cc1 < 0 ) cc1 = 0;
2410 if (cc1 >= NumFiles ) cc1 = 0;
2412 if ( cc < 0 ) cc = 0;
2413 if ( cc >= NumFiles ) cc = 0;
2414 if ( citem == cc ) break;
2416 if ( toupper(filenames[cc*14]) == toupper(ascii) ) {
2431 if (citem>=NumFiles)
2434 if (citem< first_item)
2437 if (citem>=( first_item+NumFiles_displayed))
2439 first_item = citem-NumFiles_displayed+1;
2443 if (NumFiles>first_item+NumFiles_displayed)
2454 if (NumFiles <= NumFiles_displayed )
2457 if (first_item>NumFiles-NumFiles_displayed)
2459 first_item = NumFiles-NumFiles_displayed;
2462 if (first_item < 0 ) first_item = 0;
2464 #if defined(MACINTOSH) || defined(WINDOWS)
2466 if (mouse_state || mouse2_state) {
2469 mouse_get_pos(&mx, &my);
2470 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2471 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2473 x2 = box_x + box_w - 1;
2474 y1 = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2476 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2477 if (i == citem && !mouse2_state) {
2487 if (!mouse_state && omouse_state) {
2490 gr_get_string_size(&filenames[citem*14], &w, &h, &aw );
2491 mouse_get_pos(&mx, &my);
2493 x2 = box_x + box_w - 1;
2494 y1 = (citem-first_item)*(grd_curfont->ft_h + 2) + box_y;
2496 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2497 if (dblclick_flag) done = 1;
2498 else dblclick_flag = 1;
2502 if ( !mouse_state && omouse_state ) {
2503 mouse_get_pos(&mx, &my);
2504 x1 = w_x + CLOSE_X + 2;
2505 x2 = x1 + CLOSE_SIZE - 2;
2506 y1 = w_y + CLOSE_Y + 2;
2507 y2 = y1 + CLOSE_SIZE - 2;
2508 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
2517 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow )
2519 y1 = box_y+box_h-LHY(7);
2521 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow)
2528 WIN(DDGRLOCK(dd_grd_curcanv));
2529 gr_setcolor( BM_XRGB(2,2,2));
2530 //gr_rect( box_x - 1, box_y-2, box_x + box_w, box_y-2 );
2531 gr_setcolor( BM_XRGB( 0,0,0) );
2534 if (ofirst_item != first_item || win_redraw) {
2537 if (ofirst_item != first_item) {
2541 gr_setcolor( BM_XRGB( 0,0,0) );
2542 for (i=first_item; i<first_item+NumFiles_displayed; i++ ) {
2544 y = (i-first_item)*(grd_curfont->ft_h + 2) + box_y;
2546 if ( i >= NumFiles ) {
2548 gr_setcolor( BM_XRGB(5,5,5));
2549 gr_rect( box_x + box_w, y-1, box_x + box_w, y + grd_curfont->ft_h + 1);
2550 //gr_rect( box_x, y + grd_curfont->ft_h + 2, box_x + box_w, y + grd_curfont->ft_h + 2);
2552 gr_setcolor( BM_XRGB(2,2,2));
2553 gr_rect( box_x - 1, y - 1, box_x - 1, y + grd_curfont->ft_h + 2 );
2555 gr_setcolor( BM_XRGB(0,0,0));
2556 gr_rect( box_x, y - 1, box_x + box_w - 1, y + grd_curfont->ft_h + 1);
2560 grd_curcanv->cv_font = SELECTED_FONT;
2562 grd_curcanv->cv_font = NORMAL_FONT;
2563 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2565 gr_setcolor( BM_XRGB(5,5,5));
2566 // gr_rect( box_x, y + h + 2, box_x + box_w, y + h + 2);
2567 gr_rect( box_x + box_w, y - 1, box_x + box_w, y + h + 1);
2569 gr_setcolor( BM_XRGB(2,2,2));
2570 gr_rect( box_x - 1, y - 1, box_x - 1, y + h + 1);
2571 gr_setcolor( BM_XRGB(0,0,0));
2573 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2574 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2579 } else if ( citem != ocitem ) {
2585 if ( (i>=0) && (i<NumFiles) ) {
2586 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2588 grd_curcanv->cv_font = SELECTED_FONT;
2590 grd_curcanv->cv_font = NORMAL_FONT;
2591 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2592 gr_rect( box_x, y-1, box_x + box_w - 1, y + h + 1 );
2593 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2596 if ( (i>=0) && (i<NumFiles) ) {
2597 y = (i-first_item)*(grd_curfont->ft_h+2)+box_y;
2599 grd_curcanv->cv_font = SELECTED_FONT;
2601 grd_curcanv->cv_font = NORMAL_FONT;
2602 gr_get_string_size(&filenames[i*14], &w, &h, &aw );
2603 gr_rect( box_x, y-1, box_x + box_x - 1, y + h + 1 );
2604 gr_string( box_x + 5, y, (&filenames[i*14])+((player_mode && filenames[i*14]=='$')?1:0) );
2611 grd_curcanv->cv_font = NORMAL_FONT;
2613 gr_string( box_x-LHX(10), box_y ,UP_ARROW_MARKER );
2617 nm_draw_background (box_x-LHX(10),box_y,box_x-2,box_y+LHY(7));
2621 if (show_down_arrow)
2622 gr_string( box_x-LHX(10), box_y+box_h-LHY(7) ,DOWN_ARROW_MARKER );
2626 nm_draw_background (box_x-LHX(10),box_y+box_h-LHY(7),box_x-2,box_y+box_h);
2634 WIN(DDGRUNLOCK(dd_grd_curcanv));
2640 strncpy( filename, (&filenames[citem*14])+((player_mode && filenames[citem*14]=='$')?1:0), FILENAME_LEN );
2647 keyd_repeat = old_keyd_repeat;
2649 if ( initialized ) {
2650 if (Newdemo_state != ND_STATE_PLAYBACK) //horrible hack to prevent restore when screen has been cleared
2652 WIN (DDGRLOCK(dd_grd_curcanv));
2653 gr_bm_bitblt(w_w, w_h, w_x, w_y, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
2654 WIN (DDGRUNLOCK(dd_grd_curcanv));
2656 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2657 gr_free_bitmap(bg.background);
2660 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
2661 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2663 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2664 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
2674 WIN(mouse_set_mode(1)); //re-enable centering mode
2682 // Example listbox callback function...
2683 // int lb_callback( int * citem, int *nitems, char * items[], int *keypress )
2687 // if ( *keypress = KEY_CTRLED+KEY_D ) {
2688 // if ( *nitems > 1 ) {
2689 // unlink( items[*citem] ); // Delete the file
2690 // for (i=*citem; i<*nitems-1; i++ ) {
2691 // items[i] = items[i+1];
2693 // *nitems = *nitems - 1;
2694 // d_free( items[*nitems] );
2695 // items[*nitems] = NULL;
2696 // return 1; // redraw;
2703 #define LB_ITEMS_ON_SCREEN 8
2705 int newmenu_listbox( char * title, int nitems, char * items[], int allow_abort_flag, int (*listbox_callback)( int * citem, int *nitems, char * items[], int *keypress ) )
2707 return newmenu_listbox1( title, nitems, items, allow_abort_flag, 0, listbox_callback );
2710 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 ) )
2713 int done, ocitem,citem, ofirst_item, first_item, key, redraw;
2714 int old_keyd_repeat = keyd_repeat;
2715 int width, height, wx, wy, title_height, border_size;
2716 int total_width,total_height;
2718 #if defined(MACINTOSH) || defined(WINDOWS)
2719 int mx, my, x1, x2, y1, y2, mouse_state, omouse_state; //, dblclick_flag;
2720 int close_x,close_y;
2721 int simukey=0,show_up_arrow=0,show_down_arrow=0;
2723 WIN(int win_redraw=0);
2727 PA_DFX (pa_set_frontbuffer_current());
2728 PA_DFX (pa_set_front_to_read());
2729 WIN(mouse_set_mode(0)); //disable centering mode
2731 // set_screen_mode(SCREEN_MENU);
2734 RePaintNewmenuListbox:
2737 dd_gr_set_current_canvas(NULL);
2739 gr_set_current_canvas(NULL);
2742 grd_curcanv->cv_font = SUBTITLE_FONT;
2745 for (i=0; i<nitems; i++ ) {
2747 gr_get_string_size( items[i], &w, &h, &aw );
2751 height = (grd_curfont->ft_h + 2) * LB_ITEMS_ON_SCREEN;
2755 gr_get_string_size( title, &w, &h, &aw );
2758 title_height = h + 5;
2761 border_size = grd_curfont->ft_w;
2762 WIN (border_size=grd_curfont->ft_w*2);
2764 width += (grd_curfont->ft_w);
2765 if ( width > grd_curcanv->cv_w - (grd_curfont->ft_w * 3) )
2766 width = grd_curcanv->cv_w - (grd_curfont->ft_w * 3);
2768 wx = (grd_curcanv->cv_bitmap.bm_w-width)/2;
2769 wy = (grd_curcanv->cv_bitmap.bm_h-(height+title_height))/2 + title_height;
2770 if ( wy < title_height )
2773 total_width = width+2*border_size;
2774 total_height = height+2*border_size+title_height;
2778 #if !defined(WINDOWS)
2779 if ( (VR_offscreen_buffer->cv_w >= total_width) && (VR_offscreen_buffer->cv_h >= total_height) )
2780 bg.background = &VR_offscreen_buffer->cv_bitmap;
2783 //bg.background = gr_create_bitmap( width, (height + title_height) );
2784 #if defined(POLY_ACC)
2785 bg.background = gr_create_bitmap2(total_width, total_height, grd_curcanv->cv_bitmap.bm_type, NULL);
2787 bg.background = gr_create_bitmap(total_width,total_height);
2789 Assert( bg.background != NULL );
2791 WIN (DDGRLOCK(dd_grd_curcanv));
2792 //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 );
2793 gr_bm_bitblt(total_width,total_height, 0, 0, wx-border_size, wy-title_height-border_size, &grd_curcanv->cv_bitmap, bg.background );
2794 WIN (DDGRUNLOCK(dd_grd_curcanv));
2798 dd_gr_blt_notrans(dd_grd_curcanv, 0, 0,
2799 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
2800 dd_VR_offscreen_buffer, 0, 0,
2801 _DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
2802 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(grd_curcanv->cv_bitmap), &(VR_offscreen_buffer->cv_bitmap) )
2806 nm_draw_background( wx-border_size,wy-title_height-border_size,wx+width+border_size-1,wy+height+border_size-1 );
2808 WIN(DDGRLOCK(dd_grd_curcanv));
2809 gr_string( 0x8000, wy - title_height, title );
2810 WIN(DDGRUNLOCK(dd_grd_curcanv));
2815 citem = default_item;
2816 if ( citem < 0 ) citem = 0;
2817 if ( citem >= nitems ) citem = 0;
2821 #if defined(MACINTOSH) || defined(WINDOWS)
2822 mouse_state = omouse_state = 0; //dblclick_flag = 0;
2823 close_x = wx-border_size;
2824 close_y = wy-title_height-border_size;
2825 draw_close_box(close_x,close_y);
2837 DoMessageStuff(&msg);
2839 if (_RedrawScreen) {
2840 _RedrawScreen = FALSE;
2842 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
2843 gr_free_bitmap(bg.background);
2845 goto RePaintNewmenuListbox;
2852 ofirst_item = first_item;
2853 #if defined(MACINTOSH) || defined(WINDOWS)
2854 omouse_state = mouse_state;
2855 mouse_state = mouse_button_state(0);
2857 //see if redbook song needs to be restarted
2858 songs_check_redbook_repeat();
2862 if ( listbox_callback )
2863 redraw = (*listbox_callback)(&citem, &nitems, items, &key );
2884 else if (simukey==1)
2890 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
2891 case KEY_PRINT_SCREEN:
2893 save_screen_shot(0);
2894 PA_DFX (pa_set_frontbuffer_current());
2895 PA_DFX (pa_set_front_to_read());
2918 citem += LB_ITEMS_ON_SCREEN;
2922 citem -= LB_ITEMS_ON_SCREEN;
2925 if (allow_abort_flag) {
2936 case KEY_COMMAND+KEY_Q: {
2937 extern void macintosh_quit();
2939 if ( !(Game_mode & GM_MULTI) )
2949 int ascii = key_to_ascii(key);
2950 if ( ascii < 255 ) {
2953 if (cc1 < 0 ) cc1 = 0;
2954 if (cc1 >= nitems ) cc1 = 0;
2956 if ( cc < 0 ) cc = 0;
2957 if ( cc >= nitems ) cc = 0;
2958 if ( citem == cc ) break;
2960 if ( toupper( items[cc][0] ) == toupper(ascii) ) {
2977 if (citem< first_item)
2980 if (citem>=( first_item+LB_ITEMS_ON_SCREEN))
2981 first_item = citem-LB_ITEMS_ON_SCREEN+1;
2983 if (nitems <= LB_ITEMS_ON_SCREEN )
2986 if (first_item>nitems-LB_ITEMS_ON_SCREEN)
2987 first_item = nitems-LB_ITEMS_ON_SCREEN;
2988 if (first_item < 0 ) first_item = 0;
2991 if (nitems>first_item+LB_ITEMS_ON_SCREEN)
3002 #if defined(MACINTOSH) || defined(WINDOWS)
3007 mouse_get_pos(&mx, &my);
3008 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3011 gr_get_string_size(items[i], &w, &h, &aw );
3014 y1 = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3016 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3028 //no double-click stuff for listbox
3029 //@@if (!mouse_state && omouse_state) {
3032 //@@ gr_get_string_size(items[citem], &w, &h, &aw );
3033 //@@ mouse_get_pos(&mx, &my);
3035 //@@ x2 = wx + width;
3036 //@@ y1 = (citem-first_item)*(grd_curfont->ft_h+2)+wy;
3038 //@@ if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3039 //@@ if (dblclick_flag) done = 1;
3043 //check for close box clicked
3044 if ( !mouse_state && omouse_state ) {
3045 mouse_get_pos(&mx, &my);
3046 x1 = close_x + CLOSE_X + 2;
3047 x2 = x1 + CLOSE_SIZE - 2;
3048 y1 = close_y + CLOSE_Y + 2;
3049 y2 = y1 + CLOSE_SIZE - 2;
3050 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
3060 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_up_arrow)
3062 y1 = total_height-LHY(7);
3064 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) && show_down_arrow )
3072 if ( (ofirst_item != first_item) || redraw) {
3075 WIN(DDGRLOCK(dd_grd_curcanv));
3077 gr_setcolor( BM_XRGB( 0,0,0) );
3078 for (i=first_item; i<first_item+LB_ITEMS_ON_SCREEN; i++ ) {
3080 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3081 if ( i >= nitems ) {
3082 gr_setcolor( BM_XRGB(0,0,0));
3083 gr_rect( wx, y-1, wx+width-1, y+grd_curfont->ft_h + 1 );
3086 grd_curcanv->cv_font = SELECTED_FONT;
3088 grd_curcanv->cv_font = NORMAL_FONT;
3089 gr_get_string_size(items[i], &w, &h, &aw );
3090 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3091 gr_string( wx+5, y, items[i] );
3096 // If Win95 port, draw up/down arrows on left side of menu
3098 grd_curcanv->cv_font = NORMAL_FONT;
3100 gr_string( wx-LHX(10), wy ,UP_ARROW_MARKER );
3104 nm_draw_background (wx-LHX(10),wy,wx-2,wy+LHY(7));
3108 if (show_down_arrow)
3109 gr_string( wx-LHX(10), wy+total_height-LHY(7) ,DOWN_ARROW_MARKER );
3113 nm_draw_background (wx-LHX(10),wy+total_height-LHY(7),wx-2,wy+total_height);
3120 WIN(DDGRUNLOCK(dd_grd_curcanv));
3124 } else if ( citem != ocitem ) {
3130 WIN(DDGRLOCK(dd_grd_curcanv));
3133 if ( (i>=0) && (i<nitems) ) {
3134 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3136 grd_curcanv->cv_font = SELECTED_FONT;
3138 grd_curcanv->cv_font = NORMAL_FONT;
3139 gr_get_string_size(items[i], &w, &h, &aw );
3140 gr_rect( wx, y-1, wx+width-1, y+h+1 );
3141 gr_string( wx+5, y, items[i] );
3145 if ( (i>=0) && (i<nitems) ) {
3146 y = (i-first_item)*(grd_curfont->ft_h+2)+wy;
3148 grd_curcanv->cv_font = SELECTED_FONT;
3150 grd_curcanv->cv_font = NORMAL_FONT;
3151 gr_get_string_size( items[i], &w, &h, &aw );
3152 gr_rect( wx, y-1, wx+width-1, y+h );
3153 gr_string( wx+5, y, items[i] );
3155 WIN(DDGRUNLOCK(dd_grd_curcanv));
3165 keyd_repeat = old_keyd_repeat;
3167 WIN (DDGRLOCK(dd_grd_curcanv));
3168 gr_bm_bitblt(total_width,total_height, wx-border_size, wy-title_height-border_size, 0, 0, bg.background, &grd_curcanv->cv_bitmap );
3169 WIN (DDGRUNLOCK(dd_grd_curcanv));
3171 if ( bg.background != &VR_offscreen_buffer->cv_bitmap )
3172 gr_free_bitmap(bg.background);
3176 dd_gr_blt_notrans(dd_VR_offscreen_buffer,
3177 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh,
3179 0,0,_DDModeList[W95DisplayMode].rw, _DDModeList[W95DisplayMode].rh),
3180 gr_bm_bitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curcanv->cv_bitmap) )
3186 WIN(mouse_set_mode(1)); //re-enable centering mode
3191 int newmenu_filelist( char * title, char * filespec, char * filename )
3194 char * Filenames[MAX_FILES];
3195 char FilenameText[MAX_FILES][14];
3196 FILEFINDSTRUCT find;
3199 if( !FileFindFirst( filespec, &find ) ) {
3201 if (NumFiles<MAX_FILES) {
3202 strncpy( FilenameText[NumFiles], find.name, FILENAME_LEN);
3203 Filenames[NumFiles] = FilenameText[NumFiles];
3208 } while( !FileFindNext( &find ) );
3212 i = newmenu_listbox( title, NumFiles, Filenames, 1, NULL );
3214 strcpy( filename, Filenames[i] );
3221 extern netgame_info Active_games[];
3222 extern int NumActiveNetgames;
3224 void show_extra_netgame_info(int choice)
3230 if (choice>=NumActiveNetgames)
3235 m[i].text=&mtext[i];
3236 m[i].type=NM_TYPE_TEXT;
3239 sprintf (mtext[num],"Game: %s",Active_games[choice].game_name); num++;
3240 sprintf (mtext[num],"Mission: %s",Active_games[choice].mission_title); num++;
3241 sprintf (mtext[num],"Current Level: %d",Active_games[choice].levelnum); num++;
3242 sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Active_games[choice].difficulty)); num++;
3244 already_showing_info=1;
3245 newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
3246 already_showing_info=0;
3251 /* Spiffy word wrap string formatting function */
3253 void nm_wrap_text(char *dbuf, char *sbuf, int line_length)
3259 tbuf = (char *)d_malloc(strlen(sbuf)+1);
3262 wordptr = strtok(tbuf, " ");
3263 if (!wordptr) return;
3269 col = col+strlen(wordptr)+1;
3270 if (col >=line_length) {
3272 sprintf(dbuf, "%s\n%s ", dbuf, wordptr);
3275 sprintf(dbuf, "%s%s ", dbuf, wordptr);
3277 wordptr = strtok(NULL, " ");