]> icculus.org git repositories - btb/d2x.git/blob - unused/ui/menubar.c
cruft removal
[btb/d2x.git] / unused / 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
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: menubar.c,v 1.1.1.1 2001-01-19 03:30:14 bradleyb Exp $";
17 #pragma on (unreferenced)
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <ctype.h>
23
24 #include "mem.h"
25 #include "fix.h"
26 #include "types.h"
27 #include "gr.h"
28 #include "ui.h"
29 #include "key.h"
30
31 #include "mono.h"
32
33 #include "func.h"
34
35 #include "error.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 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         keypress = keypress;
587         do_state_0(last_keypress);
588         
589         while (state > 0 )
590         {
591                 ui_mega_process();
592                 switch(state)
593                 {
594                 case 1:
595                         do_state_1(last_keypress);
596                         break;
597                 case 2:
598                         do_state_2(last_keypress);
599                         break;
600                 case 3:
601                         do_state_3(last_keypress);                      
602                         break;
603                 default:
604                         state = 0;
605                 }
606                 last_keypress  = 0;
607         }
608 }
609
610 void CommaParse( int n, char * dest, char * source )
611 {
612         int i = 0, j=0, cn = 0;
613
614         // Go to the n'th comma
615         while (cn < n )
616                 if (source[i++] == ',' )
617                         cn++;
618         // Read all the whitespace
619         while ( source[i]==' ' || source[i]=='\t' || source[i]==13 || source[i]==10 )
620                 i++;
621
622         // Read up until the next comma
623         while ( source[i] != ',' )
624         {
625                 dest[j] = source[i++];
626                 j++;            
627         }
628
629         // Null-terminate       
630         dest[j++] = 0;
631 }
632
633 //translate '&' characters to the underline character
634 void ul_xlate(char *s)
635 {
636         while ((s=strchr(s,'&'))!=NULL)
637                 *s = CC_UNDERLINE;
638 }
639
640
641 void menubar_init( char * file )
642 {
643         int i,j, np;
644         int aw, w, h;
645         FILE * infile;
646         char buffer[200];
647         char buf1[200];
648         char buf2[200];
649         int menu, item;
650                 
651         num_menus = state = 0;
652
653         for (i=0; i < MAXMENUS; i++ )
654         {
655                 Menu[i].x = Menu[i].y = Menu[i].w = Menu[i].h = 0;
656                 Menu[i].ShowBar = 0;
657                 Menu[i].CurrentItem = 0;
658                 Menu[i].NumItems = 0;
659                 Menu[i].Displayed = 0;
660                 Menu[i].Background = 0;
661                 for (j=0; j< MAXITEMS; j++ )
662                 {
663                         Menu[i].Item[j].x = Menu[i].Item[j].y = Menu[i].Item[j].w = Menu[i].Item[j].h = 0;
664                         Menu[i].Item[j].Text = NULL;
665                         Menu[i].Item[j].Hotkey = -1;
666                         Menu[i].Item[j].user_function = NULL;
667                 }
668         }
669                 
670         infile = fopen( file, "rt" );
671
672         if (!infile) return;
673                 
674         while ( fgets( buffer, 200, infile) != NULL )
675         {
676                 if ( buffer[0] == ';' ) continue;
677                 
678                 //mprintf( 0, "%s\n", buffer );
679                                 
680                 CommaParse( 0, buf1, buffer );
681                 menu = atoi( buf1 );
682                 if (menu >= MAXMENUS)
683                         Error("Too many menus (%d).",menu);
684
685                 CommaParse( 1, buf1, buffer );
686                 item = atoi(buf1 );
687                 if (item >= MAXITEMS)
688                         Error("Too many items (%d) in menu %d.",item+1,menu);
689
690                 CommaParse( 2, buf1, buffer );
691                 ul_xlate(buf1);
692
693                 if (buf1[0] != '-' )
694                 {
695                         sprintf( buf2, " %s ", buf1 );
696                         Menu[menu].Item[item].Text = strdup(buf2);
697                 } else 
698                         Menu[menu].Item[item].Text = strdup(buf1);
699                 
700                 Menu[menu].Item[item].InactiveText = strdup(Menu[menu].Item[item].Text);
701                 
702                 j= 0;
703                 for (i=0; i<=strlen(Menu[menu].Item[item].Text); i++ )
704                 {
705                         np = Menu[menu].Item[item].Text[i];
706                         if (np != CC_UNDERLINE) 
707                                 Menu[menu].Item[item].InactiveText[j++] = np;
708                 }
709
710                 CommaParse( 3, buf1, buffer );
711                 if (buf1[0]=='{' && buf1[1] =='}')
712                         Menu[menu].Item[item].Hotkey = -1;
713                 else                    {
714                         i = DecodeKeyText(buf1);
715                         if (i<1) {
716                                 Error("Unknown key, %s, in %s\n", buf1, file );
717                         } else {
718                                 Menu[menu].Item[item].Hotkey = i;
719                         }
720                 }
721                 CommaParse( 4, buf1, buffer );
722
723                 if (strlen(buf1))
724                 {
725                         Menu[menu].Item[item].user_function = func_get(buf1, &np);
726
727 //                      if (!strcmp(buf1,"do-wall-dialog")) {
728 //                              mprintf( 0, "Found function %s\n", buf1);
729 //                              mprintf( 0, "User function %s\n", Menu[menu].Item[item].user_function);
730 //                      }
731                                 
732                         if (Menu[menu].Item[item].user_function==NULL)
733                         {
734                                 Error( "Unknown function, %s, in %s\n", buf1, file );
735                                 //MessageBox( -2, -2, 1, buffer, "Ok" );
736                         }
737                 }
738                                 
739                 Menu[menu].Item[item].x = Menu[menu].x;
740                 Menu[menu].Item[item].y = Menu[menu].y;
741
742                 if ( Menu[menu].Item[item].Text[0] == '-' )
743                 {
744                         w = 1; h = 3;
745                 } else {
746                         gr_get_string_size( Menu[menu].Item[item].Text, &w, &h, &aw );
747                         w += 2;
748                         h += 2;
749                 }
750                                                                 
751                 if (menu==0)    {
752                         Menu[0].h = h;
753
754                         Menu[0].Item[item].x = Menu[0].x + Menu[0].w;
755
756                         Menu[0].Item[item].y = Menu[0].y;
757                         
758                         Menu[item+1].x = Menu[0].x + Menu[0].w;
759                         Menu[item+1].y = Menu[0].h - 2;
760
761                         Menu[0].Item[item].w = w;
762                         Menu[0].Item[item].h = h;
763
764                         Menu[0].w += w;
765
766                 }else   {
767                         if ( w > Menu[menu].w )
768                         {
769                                 Menu[menu].w = w;
770                                 for (i=0; i< Menu[menu].NumItems; i++ )
771                                         Menu[menu].Item[i].w = Menu[menu].w;
772                         }
773                         Menu[menu].Item[item].w = Menu[menu].w;
774                         Menu[menu].Item[item].x = Menu[menu].x;
775                         Menu[menu].Item[item].y = Menu[menu].y+Menu[menu].h;
776                         Menu[menu].Item[item].h = h;
777                         Menu[menu].h += h;
778                 }
779         
780                 if ( item >= Menu[menu].NumItems )
781                 {
782                         Menu[menu].NumItems = item+1;
783                 }
784
785                 if ( menu >= num_menus )
786                         num_menus = menu+1;
787
788         }
789
790         Menu[0].w = 700;
791                         
792         fclose( infile );
793
794         
795         for (i=0; i<num_menus; i++ )
796                 Menu[i].Background = gr_create_bitmap(Menu[i].w, Menu[i].h );
797
798         menubar_hid = 1;
799 }
800
801 void menubar_hide()
802 {
803         menubar_hid = 1;
804         state = 0;
805         menu_hide_all();
806         menu_hide( &Menu[0] );
807 }
808
809 void menubar_show()
810 {
811         menubar_hid = 0;
812         menu_show( &Menu[0] );
813 }
814
815 void menubar_close()
816 {
817         int i;
818
819         //menu_hide_all();
820         //menu_hide( &Menu[0] );
821         
822         for (i=0; i<num_menus; i++ )
823                 gr_free_bitmap( Menu[i].Background );
824
825 }