]> icculus.org git repositories - btb/d2x.git/blob - ui/menubar.c
Rename include/error.h to include/dxxerror.h
[btb/d2x.git] / ui / menubar.c
1 /*
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.
12 */
13
14 #ifdef HAVE_CONFIG_H
15 #include "conf.h"
16 #endif
17
18 #include <stdlib.h>
19 #include <string.h>
20 #include <ctype.h>
21
22 #include "u_mem.h"
23 #include "fix.h"
24 #include "pstypes.h"
25 #include "gr.h"
26 #include "ui.h"
27 #include "key.h"
28 #include "vid.h"
29 #include "cfile.h"
30
31 #include "mono.h"
32
33 #include "func.h"
34
35 #include "dxxerror.h"
36
37
38 #define MAXMENUS 30
39 #define MAXITEMS 32
40
41 typedef struct {
42         short                   x, y, w, h;
43         char                            *Text;
44         char                            *InactiveText;
45         short                   Hotkey;
46         int                     (*user_function)(void);
47 } ITEM;
48
49 typedef struct {
50         short                   x, y, w, h;
51         short                           ShowBar;
52         short                           CurrentItem;
53         short                           NumItems;
54         short                           Displayed;
55         short                           Active;
56         grs_bitmap *    Background;
57         ITEM                            Item[MAXITEMS];
58 } MENU;
59
60 MENU Menu[MAXMENUS];
61
62 static int num_menus = 0;
63 static int state;
64 static int menubar_hid;
65
66 #define CMENU (Menu[0].CurrentItem+1)
67
68 //------------------------- Show a menu item -------------------
69
70 void item_show( MENU * menu, int n )
71 {
72         ITEM * item = &menu->Item[n];
73         
74         gr_set_current_canvas(NULL);
75         // If this is a seperator, then draw it.
76         if ( item->Text[0] == '-'  )
77         {
78                 gr_setcolor( CBLACK );
79                 gr_urect( item->x, item->y+item->h/2, item->x+item->w-1, item->y+item->h/2 );
80                 return;
81         }       
82
83         if ( menu->CurrentItem==n && menu->ShowBar )
84         {
85                 if ( menu != &Menu[0] )
86                 {
87                         gr_setcolor( CBLACK );
88                         gr_urect( item->x+1, item->y+1, item->x+menu->w-2, item->y+item->h-2 );
89                 }
90                 gr_set_fontcolor( CWHITE, CBLACK );
91         }else {
92                 if ( menu != &Menu[0] )
93                 {
94                         gr_setcolor( CGREY );
95                         gr_urect( item->x+1, item->y+1, item->x+menu->w-2, item->y+item->h-2 );
96                 }
97                 gr_set_fontcolor( CBLACK, CGREY );
98         }
99
100         if ( menu != &Menu[0] )
101         {
102                 if ( menu->Active)
103                         gr_ustring( item->x+1, item->y+1, item->Text );
104                 else
105                         gr_ustring( item->x+1, item->y+1, item->InactiveText );
106         } else {
107                 if ( menu->Active)
108                         gr_ustring( item->x, item->y, item->Text );
109                 else
110                         gr_ustring( item->x, item->y, item->InactiveText );
111         }
112 }
113
114 //---------------------------- Show a menu ---------------------
115
116 void menu_show( MENU * menu )
117 {
118         int i;
119
120         ui_mouse_hide();
121
122         gr_set_current_canvas(NULL);
123         // Don't save background it if it's already drawn
124         if (!menu->Displayed) 
125         {
126                 // Save the background
127                 gr_bm_ubitblt(menu->w, menu->h, 0, 0, menu->x, menu->y, &(grd_curscreen->sc_canvas.cv_bitmap), menu->Background);
128
129                 // Draw the menu background
130                 gr_setcolor( CGREY );
131                 gr_urect( menu->x, menu->y, menu->x + menu->w - 1, menu->y + menu->h - 1 );
132                 if ( menu != &Menu[0] )
133                 {
134                         gr_setcolor( CBLACK );
135                         gr_ubox( menu->x, menu->y, menu->x + menu->w - 1, menu->y + menu->h - 1 );
136                 }
137         }
138                 
139         // Draw the items
140         
141         for (i=0; i< menu->NumItems; i++ )
142                 item_show( menu, i );
143
144         ui_mouse_show();
145         
146         // Mark as displayed.
147         menu->Displayed = 1;
148 }
149
150 //-------------------------- Hide a menu -----------------------
151
152 void menu_hide( MENU * menu )
153 {
154
155         // Can't hide if it's not already drawn
156         if (!menu->Displayed) return;
157
158         menu->Active = 0;
159                 
160         // Restore the background
161         ui_mouse_hide();
162
163         gr_bm_ubitblt(menu->w, menu->h, menu->x, menu->y, 0, 0, menu->Background, &(grd_curscreen->sc_canvas.cv_bitmap));
164
165         ui_mouse_show();
166         
167         // Mark as hidden.
168         menu->Displayed = 0;
169 }
170
171
172 //------------------------- Move the menu bar ------------------
173
174 void menu_move_bar_to( MENU * menu, int number )
175 {
176         int old_item;
177
178         old_item = menu->CurrentItem;
179         menu->CurrentItem = number;
180         
181         if (menu->Displayed && (number != old_item))
182         {
183                 ui_mouse_hide();
184
185                 item_show( menu, old_item );
186                 item_show( menu, number );
187
188                 ui_mouse_show();
189         }
190 }
191
192 //------------------------ Match keypress to item ------------------
193 int menu_match_keypress( MENU * menu, int keypress )
194 {
195         int i;
196         char c;
197         char *letter;
198
199         if ((keypress & KEY_CTRLED) || (keypress & KEY_SHIFTED))
200                 return -1;
201         
202         keypress &= 0xFF;
203
204         c = key_to_ascii(keypress);
205                         
206         for (i=0; i< menu->NumItems; i++ )
207         {
208                 letter = strrchr( menu->Item[i].Text, CC_UNDERLINE );
209                 if (letter)
210                 {
211                         letter++;
212                         if (c==tolower(*letter))
213                                 return i;
214                 }
215         }
216         return -1;
217 }
218
219
220 int menu_is_mouse_on( ITEM * item )
221 {
222         if ((Mouse.x >= item->x) &&
223                 (Mouse.x < item->x + item->w ) &&
224                 (Mouse.y >= item->y) &&
225                 (Mouse.y <= item->y + item->h ) )
226                 return 1;
227         else
228                 return 0;
229 }
230
231 int menu_check_mouse_item( MENU * menu )
232 {
233         int i;
234         
235         for (i=0; i<menu->NumItems; i++ )
236         {
237                 if (menu_is_mouse_on( &menu->Item[i] ))
238                 {
239                         if (menu->Item[i].Text[0] == '-')
240                                 return -1;
241                         else
242                                 return i;
243                 }
244         }
245         return -1;
246 }
247
248
249 void menu_hide_all()
250 {
251         int i;
252
253         for (i=1; i<num_menus; i++) 
254                 menu_hide( &Menu[i] );
255         
256         Menu[0].ShowBar = 0;
257         Menu[0].Active = 0;
258         menu_show( &Menu[0] );
259
260 }
261
262
263 static int state2_alt_down;
264
265 void do_state_0( int keypress )
266 {
267         int i, j;
268         
269         Menu[0].Active = 0;
270         Menu[0].ShowBar = 0;
271         if (Menu[0].Displayed==0)
272                 menu_show( &Menu[0] );
273
274         if ( keypress & KEY_ALTED )     {
275                 i = menu_match_keypress( &Menu[0], keypress );
276                 if (i > -1 )
277                 {
278                         Menu[0].CurrentItem = i;
279                         Menu[0].Active = 0;
280                         state = 3;      
281                         Menu[ CMENU ].ShowBar = 1;
282                         Menu[ CMENU ].Active = 1;
283                         Menu[0].ShowBar = 1;
284         
285                         menu_show( &Menu[ CMENU ] );
286                         menu_show( &Menu[0] );
287                 }
288         }
289         
290         for (i=0; i<num_menus; i++ )
291                 for (j=0; j< Menu[i].NumItems; j++ )
292                 {
293                         if ( Menu[i].Item[j].Hotkey == keypress )
294                         {
295                                 if (Menu[i].Item[j].user_function)
296                                         Menu[i].Item[j].user_function();
297                                 last_keypress = 0;
298                                 return;
299                         }
300                 }
301                 
302         if (keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] || ((keypress & 0xFF) == KEY_LALT) )
303         //if ( (keypress & 0xFF) == KEY_LALT )
304         {
305                 state = 1;
306                 Menu[0].Active = 1;
307                 menu_show( &Menu[0] );
308                 return;
309         }
310
311         i = menu_check_mouse_item( &Menu[0] );
312
313         if ( B1_PRESSED && (i > -1))
314         {
315                 Menu[0].CurrentItem = i;
316                 state = 3;      
317                 Menu[ CMENU ].ShowBar = 1;
318                 Menu[0].ShowBar = 1;
319                 Menu[ CMENU ].Active = 1;
320                 Menu[0].Active = 0;
321                 menu_show( &Menu[ CMENU ] );
322                 menu_show( &Menu[0] );
323                 return;
324         }
325 }
326
327 void do_state_1( int keypress )
328 {
329         int i;
330
331         if (!keyd_pressed[KEY_LALT] && !keyd_pressed[KEY_RALT] )
332         {
333                 //state = 2;
334                 //state2_alt_down = 0;
335                 //Menu[0].ShowBar = 1;
336                 //Menu[0].Active = 1;
337                 //menu_show( &Menu[0] );
338                 state = 0;
339                 menu_hide_all();
340         }
341
342         i = menu_match_keypress( &Menu[0], keypress );
343         
344         if (i > -1 )
345         {
346                 Menu[0].CurrentItem = i;
347                 Menu[0].Active = 0;
348                 state = 3;      
349                 Menu[ CMENU ].ShowBar = 1;
350                 Menu[ CMENU ].Active = 1;
351                 Menu[0].ShowBar = 1;
352
353                 menu_show( &Menu[ CMENU ] );
354                 menu_show( &Menu[0] );
355         }
356
357         i = menu_check_mouse_item( &Menu[0] );
358
359         if ( (i == -1) && B1_JUST_RELEASED )
360         {
361                 state = 0;
362                 menu_hide_all();
363         }
364
365         if ( B1_PRESSED && (i > -1))
366         {
367                 Menu[0].CurrentItem = i;
368                 state = 3;      
369                 Menu[ CMENU ].ShowBar = 1;
370                 Menu[ CMENU ].Active = 1;
371                 Menu[0].ShowBar = 1;
372                 Menu[0].Active = 0;
373                 menu_show( &Menu[ CMENU ] );
374                 menu_show( &Menu[0] );
375         }
376 }
377
378 void do_state_2(int keypress)
379 {
380         int i;
381
382         if (keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] )
383                 state2_alt_down = 1;
384
385         if (!keyd_pressed[KEY_LALT] && !keyd_pressed[KEY_RALT] && state2_alt_down )
386         {
387                 state = 0;
388                 menu_hide_all();
389         }                       
390
391         switch( keypress )
392         {
393         case KEY_ESC:
394                 state = 0;
395                 menu_hide_all();
396                 break;
397         case KEY_LEFT:
398         case KEY_PAD4:
399                 i = Menu[0].CurrentItem-1;
400                 if (i < 0 ) i = Menu[0].NumItems-1;
401                 menu_move_bar_to( &Menu[0], i );
402                 break;
403         case KEY_RIGHT:
404         case KEY_PAD6:
405                 i = Menu[0].CurrentItem+1;
406                 if (i >= Menu[0].NumItems ) i = 0;
407                 menu_move_bar_to( &Menu[0], i );
408                 break;
409         case KEY_ENTER:
410         case KEY_PADENTER:
411         case KEY_DOWN:
412         case KEY_PAD2:
413                 state = 3;      
414                 Menu[ CMENU ].ShowBar = 1;
415                 Menu[ CMENU ].Active = 1;
416                 Menu[0].Active = 0;
417                 menu_show( &Menu[ 0 ] );
418                 menu_show( &Menu[ CMENU ] );
419                 break;
420         
421         default:
422                 i = menu_match_keypress( &Menu[0], keypress );
423         
424                 if (i > -1 )
425                 {
426                         Menu[0].CurrentItem = i;
427                         Menu[0].Active = 0;
428                         state = 3;      
429                         Menu[ CMENU ].ShowBar = 1;
430                         Menu[ CMENU ].Active = 1;
431                         Menu[0].ShowBar = 1;
432                         menu_show( &Menu[ CMENU ] );
433                         menu_show( &Menu[0] );
434                         break;
435                 }
436
437                 i = menu_check_mouse_item( &Menu[0] );
438
439                 if ( (i == -1) && B1_JUST_RELEASED )
440                 {
441                         state = 0;
442                         menu_hide_all();
443                         break;
444                 }
445
446                 if ( B1_PRESSED && (i > -1))
447                 {
448                         Menu[0].CurrentItem = i;
449                         Menu[0].Active = 0;
450                         state = 3;      
451                         Menu[ CMENU ].ShowBar = 1;
452                         Menu[ CMENU ].Active = 1;
453                         Menu[0].ShowBar = 1;
454                         menu_show( &Menu[ CMENU ] );
455                         menu_show( &Menu[0] );
456                         break;
457                 }
458
459
460         }
461 }
462
463
464
465 void do_state_3( int keypress )
466 {
467         int i;
468         
469         switch( keypress )
470         {
471         case KEY_ESC:
472                 state = 0;
473                 menu_hide_all();
474                 break;
475         case KEY_DOWN:
476         case KEY_PAD2:
477                 i = Menu[ CMENU ].CurrentItem;
478                 do {
479                         i++;            
480                         if ( i >= Menu[ CMENU ].NumItems )
481                                 i = 0;
482                 } while( Menu[CMENU].Item[i].Text[0] == '-');
483                 menu_move_bar_to( &Menu[ CMENU ], i );
484                 break;
485         case KEY_UP:
486         case KEY_PAD8:
487                 i = Menu[ CMENU ].CurrentItem;
488                 do 
489                 {
490                         i--;
491                         if ( i < 0 )
492                                 i = Menu[ CMENU ].NumItems-1;
493                 } while( Menu[CMENU].Item[i].Text[0] == '-');
494                 menu_move_bar_to( &Menu[ CMENU ], i );
495                 break;
496         case KEY_RIGHT:
497         case KEY_PAD6:
498                 menu_hide( &Menu[ CMENU ] );
499                 i = Menu[0].CurrentItem+1;
500                 if (i >= Menu[0].NumItems ) i = 0;
501                 menu_move_bar_to( &Menu[0], i );
502                 Menu[CMENU].ShowBar = 1;
503                 Menu[CMENU].Active = 1;
504                 menu_show( &Menu[CMENU] );
505                 break;
506         case KEY_LEFT:
507         case KEY_PAD4:
508                 menu_hide( &Menu[ CMENU ] );
509                 i = Menu[0].CurrentItem-1;
510                 if (i < 0 ) i = Menu[0].NumItems-1;
511                 menu_move_bar_to( &Menu[0], i );
512                 Menu[ CMENU ].ShowBar = 1;
513                 Menu[CMENU].Active = 1;
514                 menu_show( &Menu[ CMENU ] );
515                 break;
516         case KEY_ENTER:
517         case KEY_PADENTER:
518                 state = 0;
519                 menu_hide_all();
520
521                 if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
522                         Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
523                 
524                 break;
525                 
526         default:
527                 i = menu_match_keypress( &Menu[ CMENU ], keypress );
528
529                 if (i > -1 )
530                 {
531                         menu_move_bar_to( &Menu[ CMENU ], i );
532                         state = 0;
533                         menu_hide_all();
534                                                         
535                         if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
536                                 Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
537                         break;
538                 }
539                 i = menu_check_mouse_item( &Menu[CMENU] );
540                         
541                 if (i > -1 )
542                 {
543                         if ( B1_PRESSED )
544                                 menu_move_bar_to( &Menu[ CMENU ], i );
545                         else if ( B1_JUST_RELEASED )
546                         {
547                                 menu_move_bar_to( &Menu[ CMENU ], i );
548                                 state = 0;
549                                 menu_hide_all();
550                                                                 
551                                 if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
552                                         Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
553                                 break;
554                         }
555                 } else {
556                         i = menu_check_mouse_item( &Menu[0] );
557
558                         if ( B1_PRESSED && (i > -1))
559                         {
560                                 if ( Menu[0].CurrentItem != i)  {
561                                         menu_hide( &Menu[ CMENU ] );
562                                         menu_move_bar_to( &Menu[0], i );
563                                         Menu[ CMENU ].ShowBar = 1;
564                                         Menu[CMENU].Active = 1;
565                                         menu_show( &Menu[ CMENU ] );
566                                         break;
567                                 }
568                         }
569
570                         if ( B1_JUST_RELEASED )
571                         {
572                                 state = 0;
573                                 menu_hide_all();
574                                 break;
575                         }
576
577                 }
578
579         }
580 }
581         
582 void menubar_do( int keypress )
583 {
584         if (menubar_hid) return;
585                 
586         do_state_0(last_keypress);
587         
588         while (state > 0 )
589         {
590                 ui_mega_process();
591                 switch(state)
592                 {
593                 case 1:
594                         do_state_1(last_keypress);
595                         break;
596                 case 2:
597                         do_state_2(last_keypress);
598                         break;
599                 case 3:
600                         do_state_3(last_keypress);                      
601                         break;
602                 default:
603                         state = 0;
604                 }
605                 last_keypress  = 0;
606
607                 vid_update();
608         }
609 }
610
611 void CommaParse( int n, char * dest, char * source )
612 {
613         int i = 0, j=0, cn = 0;
614
615         // Go to the n'th comma
616         while (cn < n )
617                 if (source[i++] == ',' )
618                         cn++;
619         // Read all the whitespace
620         while ( source[i]==' ' || source[i]=='\t' || source[i]==13 || source[i]==10 )
621                 i++;
622
623         // Read up until the next comma
624         while ( source[i] != ',' )
625         {
626                 dest[j] = source[i++];
627                 j++;            
628         }
629
630         // Null-terminate       
631         dest[j++] = 0;
632 }
633
634 //translate '&' characters to the underline character
635 void ul_xlate(char *s)
636 {
637         while ((s=strchr(s,'&'))!=NULL)
638                 *s = CC_UNDERLINE;
639 }
640
641
642 void menubar_init( char * file )
643 {
644         int i,j, np;
645         int aw, w, h;
646         CFILE * infile;
647         char buffer[200];
648         char buf1[200];
649         char buf2[200];
650         int menu, item;
651                 
652         num_menus = state = 0;
653
654         for (i=0; i < MAXMENUS; i++ )
655         {
656                 Menu[i].x = Menu[i].y = Menu[i].w = Menu[i].h = 0;
657                 Menu[i].ShowBar = 0;
658                 Menu[i].CurrentItem = 0;
659                 Menu[i].NumItems = 0;
660                 Menu[i].Displayed = 0;
661                 Menu[i].Background = 0;
662                 for (j=0; j< MAXITEMS; j++ )
663                 {
664                         Menu[i].Item[j].x = Menu[i].Item[j].y = Menu[i].Item[j].w = Menu[i].Item[j].h = 0;
665                         Menu[i].Item[j].Text = NULL;
666                         Menu[i].Item[j].Hotkey = -1;
667                         Menu[i].Item[j].user_function = NULL;
668                 }
669         }
670                 
671         infile = cfopen( file, "rt" );
672
673         if (!infile) return;
674                 
675         while ( cfgets( buffer, 200, infile) != NULL )
676         {
677                 if ( buffer[0] == ';' ) continue;
678                 
679                 //mprintf( 0, "%s\n", buffer );
680                                 
681                 CommaParse( 0, buf1, buffer );
682                 menu = atoi( buf1 );
683                 if (menu >= MAXMENUS)
684                         Error("Too many menus (%d).",menu);
685
686                 CommaParse( 1, buf1, buffer );
687                 item = atoi(buf1 );
688                 if (item >= MAXITEMS)
689                         Error("Too many items (%d) in menu %d.",item+1,menu);
690
691                 CommaParse( 2, buf1, buffer );
692                 ul_xlate(buf1);
693
694                 if (buf1[0] != '-' )
695                 {
696                         sprintf( buf2, " %s ", buf1 );
697                         Menu[menu].Item[item].Text = d_strdup(buf2);
698                 } else 
699                         Menu[menu].Item[item].Text = d_strdup(buf1);
700                 
701                 Menu[menu].Item[item].InactiveText = d_strdup(Menu[menu].Item[item].Text);
702                 
703                 j= 0;
704                 for (i=0; i<=strlen(Menu[menu].Item[item].Text); i++ )
705                 {
706                         np = Menu[menu].Item[item].Text[i];
707                         if (np != CC_UNDERLINE) 
708                                 Menu[menu].Item[item].InactiveText[j++] = np;
709                 }
710
711                 CommaParse( 3, buf1, buffer );
712                 if (buf1[0]=='{' && buf1[1] =='}')
713                         Menu[menu].Item[item].Hotkey = -1;
714                 else                    {
715                         i = DecodeKeyText(buf1);
716                         if (i<1) {
717                                 Error("Unknown key, %s, in %s\n", buf1, file );
718                         } else {
719                                 Menu[menu].Item[item].Hotkey = i;
720                         }
721                 }
722                 CommaParse( 4, buf1, buffer );
723
724                 if (strlen(buf1))
725                 {
726                         Menu[menu].Item[item].user_function = func_get(buf1, &np);
727
728 //                      if (!strcmp(buf1,"do-wall-dialog")) {
729 //                              mprintf( 0, "Found function %s\n", buf1);
730 //                              mprintf( 0, "User function %s\n", Menu[menu].Item[item].user_function);
731 //                      }
732                                 
733                         if (Menu[menu].Item[item].user_function==NULL)
734                         {
735                                 Error( "Unknown function, %s, in %s\n", buf1, file );
736                                 //ui_messagebox( -2, -2, 1, buffer, "Ok" );
737                         }
738                 }
739                                 
740                 Menu[menu].Item[item].x = Menu[menu].x;
741                 Menu[menu].Item[item].y = Menu[menu].y;
742
743                 if ( Menu[menu].Item[item].Text[0] == '-' )
744                 {
745                         w = 1; h = 3;
746                 } else {
747                         gr_get_string_size( Menu[menu].Item[item].Text, &w, &h, &aw );
748                         w += 2;
749                         h += 2;
750                 }
751                                                                 
752                 if (menu==0)    {
753                         Menu[0].h = h;
754
755                         Menu[0].Item[item].x = Menu[0].x + Menu[0].w;
756
757                         Menu[0].Item[item].y = Menu[0].y;
758                         
759                         Menu[item+1].x = Menu[0].x + Menu[0].w;
760                         Menu[item+1].y = Menu[0].h - 2;
761
762                         Menu[0].Item[item].w = w;
763                         Menu[0].Item[item].h = h;
764
765                         Menu[0].w += w;
766
767                 }else   {
768                         if ( w > Menu[menu].w )
769                         {
770                                 Menu[menu].w = w;
771                                 for (i=0; i< Menu[menu].NumItems; i++ )
772                                         Menu[menu].Item[i].w = Menu[menu].w;
773                         }
774                         Menu[menu].Item[item].w = Menu[menu].w;
775                         Menu[menu].Item[item].x = Menu[menu].x;
776                         Menu[menu].Item[item].y = Menu[menu].y+Menu[menu].h;
777                         Menu[menu].Item[item].h = h;
778                         Menu[menu].h += h;
779                 }
780         
781                 if ( item >= Menu[menu].NumItems )
782                 {
783                         Menu[menu].NumItems = item+1;
784                 }
785
786                 if ( menu >= num_menus )
787                         num_menus = menu+1;
788
789         }
790
791         Menu[0].w = 700;
792                         
793         cfclose( infile );
794
795         
796         for (i=0; i<num_menus; i++ )
797                 Menu[i].Background = gr_create_bitmap(Menu[i].w, Menu[i].h );
798
799         menubar_hid = 1;
800 }
801
802 void menubar_hide()
803 {
804         menubar_hid = 1;
805         state = 0;
806         menu_hide_all();
807         menu_hide( &Menu[0] );
808 }
809
810 void menubar_show()
811 {
812         menubar_hid = 0;
813         menu_show( &Menu[0] );
814 }
815
816 void menubar_close()
817 {
818         int i;
819
820         //menu_hide_all();
821         //menu_hide( &Menu[0] );
822         
823         for (i=0; i<num_menus; i++ )
824                 gr_free_bitmap( Menu[i].Background );
825
826 }