]> git.mxchange.org Git - flightgear.git/blob - src/GUI/gui.cxx
- make repeatable for keys and joystick buttons default to false
[flightgear.git] / src / GUI / gui.cxx
1 /**************************************************************************
2  * gui.cxx
3  *
4  * Written 1998 by Durk Talsma, started Juni, 1998.  For the flight gear
5  * project.
6  *
7  * Additional mouse supported added by David Megginson, 1999.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * $Id$
24  **************************************************************************/
25
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #include <simgear/compiler.h>
32
33 #ifdef SG_MATH_EXCEPTION_CLASH
34 #  include <math.h>
35 #endif
36
37 #ifdef HAVE_WINDOWS_H
38 #  include <windows.h>
39 #endif
40
41 #include <GL/glut.h>
42 #include <GL/gl.h>
43
44 #if defined(FX) && defined(XMESA)
45 #  include <GL/xmesa.h>
46 #endif
47
48 #include STL_FSTREAM
49 #include STL_STRING
50
51 #include <stdlib.h>
52 #include <string.h>
53
54 #include <simgear/constants.h>
55 #include <simgear/debug/logstream.hxx>
56 #include <simgear/misc/sg_path.hxx>
57 #include <simgear/screen/screen-dump.hxx>
58
59 #include <Include/general.hxx>
60 #include <Aircraft/aircraft.hxx>
61 #include <Airports/simple.hxx>
62 #include <Autopilot/auto_gui.hxx>
63 #include <Autopilot/newauto.hxx>
64 #include <Cockpit/panel.hxx>
65 #include <Controls/controls.hxx>
66 #include <FDM/flight.hxx>
67 #include <Main/bfi.hxx>
68 #include <Main/fg_init.hxx>
69 #include <Main/fg_io.hxx>
70 #include <Main/globals.hxx>
71 #include <Main/fg_props.hxx>
72 #include <Main/options.hxx>
73
74 #ifdef FG_NETWORK_OLK
75 #include <NetworkOLK/network.h>
76 #endif
77    
78 #if defined( WIN32 ) && !defined( __CYGWIN__ )
79 #  include <simgear/screen/win32-printer.h>
80 #  include <simgear/screen/GlBitmaps.h>
81 #endif
82
83 #include "gui.h"
84 #include "gui_local.hxx"
85 #include "apt_dlg.hxx"
86 #include "net_dlg.hxx"
87 #include "sgVec3Slider.hxx"
88
89 SG_USING_STD(string);
90
91 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
92 SG_USING_STD(cout);
93 #endif
94
95 #ifdef  _MSC_VER
96 #define  snprintf    _snprintf
97 #endif   /* _MSC_VER */
98
99 // main.cxx hack, should come from an include someplace
100 extern void fgInitVisuals( void );
101 extern void fgReshape( int width, int height );
102 extern void fgRenderFrame( void );
103
104 puFont guiFnt = 0;
105 fntTexFont *guiFntHandle = 0;
106 int gui_menu_on = 0;
107 static puMenuBar    *mainMenuBar = 0;
108 //static puButton     *hideMenuButton = 0;
109
110 static puDialogBox  *dialogBox = 0;
111 static puFrame      *dialogFrame = 0;
112 static puText       *dialogBoxMessage = 0;
113 static puOneShot    *dialogBoxOkButton = 0;
114
115
116 static puDialogBox  *YNdialogBox = 0;
117 static puFrame      *YNdialogFrame = 0;
118 static puText       *YNdialogBoxMessage = 0;
119 static puOneShot    *YNdialogBoxOkButton = 0;
120 static puOneShot    *YNdialogBoxNoButton = 0;
121
122 static char msg_OK[]     = "OK";
123 static char msg_NO[]     = "NO";
124 static char msg_YES[]    = "YES";
125 static char msg_CANCEL[] = "Cancel";
126 static char msg_RESET[]  = "Reset";
127
128 char *gui_msg_OK;     // "OK"
129 char *gui_msg_NO;     // "NO"
130 char *gui_msg_YES;    // "YES"
131 char *gui_msg_CANCEL; // "CANCEL"
132 char *gui_msg_RESET;  // "RESET"
133
134 static char global_dialog_string[256];
135
136 // from cockpit.cxx
137 extern void fgLatLonFormatToggle( puObject *);
138
139
140 /* ================ General Purpose Functions ================ */
141
142 // Intercept the Escape Key
143 void ConfirmExitDialog(void)
144 {
145     FG_PUSH_PUI_DIALOG( YNdialogBox );
146 }
147
148 // General Purpose Message Box
149 void mkDialog (const char *txt)
150 {
151     strncpy(global_dialog_string, txt, 256);
152     dialogBoxMessage->setLabel(global_dialog_string);
153     FG_PUSH_PUI_DIALOG( dialogBox );
154 }
155
156 // Toggle the Menu and Mouse display state
157 void guiToggleMenu(void)
158 {
159     if( gui_menu_on ) {
160         // printf("Hiding Menu\n");
161         mainMenuBar->hide  ();
162 #if defined(WIN32_CURSOR_TWEAKS)
163         if( mouse_mode == MOUSE_POINTER )
164             TurnCursorOff();
165 #endif // #ifdef WIN32_CURSOR_TWEAKS
166     } else {
167         // printf("Showing Menu\n");
168         mainMenuBar->reveal();
169 #ifdef WIN32
170         TurnCursorOn();
171 #endif // #ifdef WIN32
172     }
173     gui_menu_on = ~gui_menu_on;
174 }
175     
176 /* -----------------------------------------------------------------------
177 the Gui callback functions 
178 ____________________________________________________________________*/
179
180
181 // Hier Neu :-) This is my newly added code
182 // Added by David Findlay <nedz@bigpond.com>
183 // on Sunday 3rd of December
184
185 // Start new Save Dialog Box
186 static puDialogBox     *SaveDialog = 0;
187 static puFrame         *SaveDialogFrame = 0;
188 static puText          *SaveDialogMessage = 0;
189 static puInput         *SaveDialogInput = 0;
190
191 static puOneShot       *SaveDialogOkButton = 0;
192 static puOneShot       *SaveDialogCancelButton = 0;
193 static puOneShot       *SaveDialogResetButton = 0;
194
195 // Default save filename
196 static char saveFile[256] = "fgfs.sav";
197
198 // Cancel Button
199 void SaveDialogCancel(puObject *) {
200     FG_POP_PUI_DIALOG( SaveDialog );
201 }
202
203 // If press OK do this
204 void SaveDialogOk(puObject*) {
205
206     FG_POP_PUI_DIALOG( SaveDialog );
207
208     char *s;
209     SaveDialogInput->getValue(&s);
210
211     ofstream output(s);
212     cout << saveFile << endl;
213     if (output.good() && fgSaveFlight(output)) {
214         output.close();
215         mkDialog("Saved flight");
216         SG_LOG(SG_INPUT, SG_INFO, "Saved flight");
217     } else {
218         mkDialog("Cannot save flight");
219         SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight");
220     }
221 }
222
223 // Create Dialog
224 static void saveFlight(puObject *cv) {
225     SaveDialog = new puDialogBox (150, 50);
226     {
227         SaveDialogFrame   = new puFrame           (0,0,350, 150);
228         SaveDialogMessage = new puText            (
229                         (150 - puGetStringWidth( puGetDefaultLabelFont(), "File Name:" ) / 2), 110);
230         SaveDialogMessage ->    setLabel          ("File Name:");
231
232         SaveDialogInput   = new puInput           (50, 70, 300, 100);
233         SaveDialogInput   ->    setValue          (saveFile);
234         SaveDialogInput   ->    acceptInput();
235
236         SaveDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
237         SaveDialogOkButton     ->     setLegend   (gui_msg_OK);
238         SaveDialogOkButton     ->     setCallback ( SaveDialogOk );
239         SaveDialogOkButton     ->     makeReturnDefault(TRUE);
240
241         SaveDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
242         SaveDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
243         SaveDialogCancelButton ->     setCallback ( SaveDialogCancel );
244     }
245     FG_FINALIZE_PUI_DIALOG( SaveDialog );
246    
247     SaveDialog -> reveal();
248 }
249
250 // Load Dialog Start
251 static puDialogBox     *LoadDialog = 0;
252 static puFrame         *LoadDialogFrame = 0;
253 static puText          *LoadDialogMessage = 0;
254 static puInput         *LoadDialogInput = 0;
255
256 static puOneShot       *LoadDialogOkButton = 0;
257 static puOneShot       *LoadDialogCancelButton = 0;
258 static puOneShot       *LoadDialogResetButton = 0;
259
260 // Default load filename
261 static char loadFile[256] = "fgfs.sav";
262
263 // Do this if the person click okay
264 void LoadDialogOk(puObject *) {
265
266     FG_POP_PUI_DIALOG( LoadDialog );
267
268     char *l;
269     LoadDialogInput->getValue(&l);
270
271     ifstream input(l);
272     if (input.good() && fgLoadFlight(input)) {
273         input.close();
274         mkDialog("Loaded flight");
275         SG_LOG(SG_INPUT, SG_INFO, "Restored flight");
276     } else {
277         mkDialog("Failed to load flight");
278         SG_LOG(SG_INPUT, SG_ALERT, "Cannot load flight");
279     }
280 }
281
282 // Do this is the person presses cancel
283 void LoadDialogCancel(puObject *) {
284     FG_POP_PUI_DIALOG( LoadDialog );
285 }
286
287 // Create Load Dialog
288 static void loadFlight(puObject *cb)
289 {
290     LoadDialog = new puDialogBox (150, 50);
291     {
292         LoadDialogFrame   = new puFrame           (0,0,350, 150);
293         LoadDialogMessage = new puText            (
294                         (150 - puGetStringWidth( puGetDefaultLabelFont(), "File Name:" ) / 2), 110);
295         LoadDialogMessage ->    setLabel          ("File Name:");
296
297         LoadDialogInput   = new puInput           (50, 70, 300, 100);
298         LoadDialogInput   ->    setValue          (loadFile);
299         LoadDialogInput   ->    acceptInput();
300
301         LoadDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
302         LoadDialogOkButton     ->     setLegend   (gui_msg_OK);
303         LoadDialogOkButton     ->     setCallback ( LoadDialogOk );
304         LoadDialogOkButton     ->     makeReturnDefault(TRUE);
305
306         LoadDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
307         LoadDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
308         LoadDialogCancelButton ->     setCallback ( LoadDialogCancel );
309     }
310     FG_FINALIZE_PUI_DIALOG( LoadDialog );
311    
312     LoadDialog -> reveal();
313 }
314
315 // This is the accessor function
316 void guiTogglePanel(puObject *cb)
317 {
318   if (fgGetBool("/sim/panel/visibility"))
319     fgSetBool("/sim/panel/visibility", false);
320   else
321     fgSetBool("/sim/panel/visibility", true);
322
323   fgReshape(fgGetInt("/sim/startup/xsize"),
324             fgGetInt("/sim/startup/ysize"));
325 }
326     
327 //void MenuHideMenuCb(puObject *cb)
328 void hideMenuCb (puObject *cb)
329 {
330     guiToggleMenu();
331 }
332
333 void goodBye(puObject *)
334 {
335     // SG_LOG( SG_INPUT, SG_ALERT,
336     //      "Program exiting normally at user request." );
337     cout << "Program exiting normally at user request." << endl;
338
339 #ifdef FG_NETWORK_OLK    
340     if ( fgGetBool("/sim/networking/network-olk") ) {
341         if ( net_is_registered == 0 ) fgd_send_com( "8", FGFS_host);
342     }
343 #endif
344
345     // close all external I/O connections
346     fgIOShutdownAll();
347
348     exit(0);
349 }
350
351
352 void goAwayCb (puObject *me)
353 {
354     FG_POP_PUI_DIALOG( dialogBox );
355 }
356
357 void mkDialogInit (void)
358 {
359     //  printf("mkDialogInit\n");
360     int x = (fgGetInt("/sim/startup/xsize")/2 - 400/2);
361     int y = (fgGetInt("/sim/startup/ysize")/2 - 100/2);
362     dialogBox = new puDialogBox (x, y); // 150, 50
363     {
364         dialogFrame = new puFrame (0,0,400,100);
365         dialogBoxMessage  =  new puText         (10, 70);
366         dialogBoxMessage  -> setLabel           ("");
367         dialogBoxOkButton =  new puOneShot      (180, 10, 240, 50);
368         dialogBoxOkButton -> setLegend          (gui_msg_OK);
369         dialogBoxOkButton -> makeReturnDefault  (TRUE );
370         dialogBoxOkButton -> setCallback        (goAwayCb);
371     }
372     FG_FINALIZE_PUI_DIALOG( dialogBox );
373 }
374
375 void MayBeGoodBye(puObject *)
376 {
377     ConfirmExitDialog(); 
378 }
379
380 void goAwayYesNoCb(puObject *me)
381 {
382     FG_POP_PUI_DIALOG( YNdialogBox);
383 }
384
385 void ConfirmExitDialogInit(void)
386 {
387     char msg[] = "Really Quit";
388     char *s;
389
390     //  printf("ConfirmExitDialogInit\n");
391     int len = 200 - puGetStringWidth( puGetDefaultLabelFont(), msg )/2;
392
393     int x = (fgGetInt("/sim/startup/xsize")/2 - 400/2);
394     int y = (fgGetInt("/sim/startup/ysize")/2 - 100/2);
395         
396     YNdialogBox = new puDialogBox (x, y); // 150, 50
397     //  YNdialogBox = new puDialogBox (150, 50);
398     {
399         YNdialogFrame = new puFrame (0,0,400, 100);
400         
401         YNdialogBoxMessage  =  new puText         (len, 70);
402         YNdialogBoxMessage  -> setDefaultValue    (msg);
403         YNdialogBoxMessage  -> getDefaultValue    (&s);
404         YNdialogBoxMessage  -> setLabel           (s);
405         
406         YNdialogBoxOkButton =  new puOneShot      (100, 10, 160, 50);
407         YNdialogBoxOkButton -> setLegend          (gui_msg_OK);
408         YNdialogBoxOkButton -> makeReturnDefault  (TRUE );
409         YNdialogBoxOkButton -> setCallback        (goodBye);
410         
411         YNdialogBoxNoButton =  new puOneShot      (240, 10, 300, 50);
412         YNdialogBoxNoButton -> setLegend          (gui_msg_NO);
413         YNdialogBoxNoButton -> setCallback        (goAwayYesNoCb);
414     }
415     FG_FINALIZE_PUI_DIALOG( YNdialogBox );
416 }
417
418 void notCb (puObject *)
419 {
420     mkDialog ("This function isn't implemented yet");
421 }
422
423 void helpCb (puObject *)
424 {
425     string command;
426         
427 #if defined(FX) && !defined(WIN32)
428 #  if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
429     if ( global_fullscreen ) {
430         global_fullscreen = false;
431         XMesaSetFXmode( XMESA_FX_WINDOW );
432     }
433 #  endif
434 #endif
435         
436 #if !defined(WIN32)
437     string url = "http://www.flightgear.org/Docs/InstallGuide/getstart.html";
438         
439     if ( system("xwininfo -name Netscape > /dev/null 2>&1") == 0 ) {
440         command = "netscape -remote \"openURL(" + url + ")\" &";
441     } else {
442         command = "netscape " + url + " &";
443     }
444 #else
445     command = "webrun.bat";
446 #endif
447         
448     system( command.c_str() );
449     //string text = "Help started in netscape window.";
450
451     //mkDialog (text.c_str());
452     mkDialog ("Help started in netscape window.");
453 }
454
455 #if defined( WIN32 ) && !defined( __CYGWIN__)
456
457 static void rotateView( double roll, double pitch, double yaw )
458 {
459         // rotate view
460 }
461
462 static GlBitmap *b1 = NULL;
463 extern FGInterface cur_view_fdm;
464 GLubyte *hiResScreenCapture( int multiplier )
465 {
466     float oldfov = fgGetDouble("/sim/field-of-view");
467     float fov = oldfov / multiplier;
468     FGViewer *v = globals->get_current_view();
469     fgSetDouble("/sim/field-of-view", fov);
470     fgInitVisuals();
471     int cur_width = fgGetInt("/sim/startup/xsize");
472     int cur_height = fgGetInt("/sim/startup/ysize");
473     if (b1) delete( b1 );
474     // New empty (mostly) bitmap
475     b1 = new GlBitmap( GL_RGB, 1, 1, (unsigned char *)"123" );
476     int x,y;
477     for ( y = 0; y < multiplier; y++ ) {
478         for ( x = 0; x < multiplier; x++ ) {
479             fgReshape( cur_width, cur_height );
480             // pan to tile
481             rotateView( 0, (y*fov)-((multiplier-1)*fov/2), (x*fov)-((multiplier-1)*fov/2) );
482             fgRenderFrame();
483             // restore view
484             GlBitmap b2;
485             b1->copyBitmap( &b2, cur_width*x, cur_height*y );
486         }
487     }
488     fgSetDouble("/sim/field-of-view", oldfov);
489     return b1->getBitmap();
490 }
491 #endif
492
493
494 #if defined( WIN32 ) && !defined( __CYGWIN__)
495 // win32 print screen function
496 void printScreen ( puObject *obj ) {
497     bool show_pu_cursor = false;
498     TurnCursorOff();
499     if ( !puCursorIsHidden() ) {
500         show_pu_cursor = true;
501         puHideCursor();
502     }
503     BusyCursor( 0 );
504     mainMenuBar->hide();
505
506     CGlPrinter p( CGlPrinter::PRINT_BITMAP );
507     int cur_width = fgGetInt("/sim/startup/xsize");
508     int cur_height = fgGetInt("/sim/startup/ysize");
509     p.Begin( "FlightGear", cur_width*3, cur_height*3 );
510         p.End( hiResScreenCapture(3) );
511
512     if( gui_menu_on ) {
513         mainMenuBar->reveal();
514     }
515     BusyCursor(1);
516     if ( show_pu_cursor ) {
517         puShowCursor();
518     }
519     TurnCursorOn();
520 }
521 #endif // #ifdef WIN32
522
523
524 void dumpSnapShot ( puObject *obj ) {
525     fgDumpSnapShot();
526 }
527
528
529 // do a screen snap shot
530 void fgDumpSnapShot () {
531     bool show_pu_cursor = false;
532     char *filename = new char [24];
533     string message;
534     static int count = 1;
535
536     int freeze = globals->get_freeze();
537     if(!freeze)
538         globals->set_freeze( true );
539
540     mainMenuBar->hide();
541     TurnCursorOff();
542     if ( !puCursorIsHidden() ) {
543         show_pu_cursor = true;
544         puHideCursor();
545     }
546
547     fgInitVisuals();
548     fgReshape( fgGetInt("/sim/startup/xsize"),
549                fgGetInt("/sim/startup/ysize") );
550
551     // we need two render frames here to clear the menu and cursor
552     // ... not sure why but doing an extra fgRenderFrame() shouldn't
553     // hurt anything
554     fgRenderFrame();
555     fgRenderFrame();
556
557     while (count < 1000) {
558         FILE *fp;
559         snprintf(filename, 24, "fgfs-screen-%03d.ppm", count++);
560         if ( (fp = fopen(filename, "r")) == NULL )
561             break;
562         fclose(fp);
563     }
564
565     if ( sg_glDumpWindow( filename,
566                           fgGetInt("/sim/startup/xsize"), 
567                           fgGetInt("/sim/startup/ysize")) ) {
568         message = "Snap shot saved to ";
569         message += filename;
570     } else {
571         message = "Failed to save to ";
572         message += filename;
573     }
574
575     mkDialog (message.c_str());
576
577     delete [] filename;
578
579     if ( show_pu_cursor ) {
580         puShowCursor();
581     }
582
583     TurnCursorOn();
584     if( gui_menu_on ) {
585         mainMenuBar->reveal();
586     }
587
588     if(!freeze)
589         globals->set_freeze( false );
590 }
591
592 #ifdef FG_NETWORK_OLK
593 static void net_display_toggle( puObject *cb)
594 {
595         net_hud_display = (net_hud_display) ? 0 : 1;
596         printf("Toggle net_hud_display : %d\n", net_hud_display);
597 }
598
599 static void net_register( puObject *cb)
600 {
601         fgd_send_com( "1", FGFS_host );
602         net_is_registered = 0;
603         printf("Registering to deamon\n");
604 }
605
606 static void net_unregister( puObject *cb)
607 {
608         fgd_send_com( "8", FGFS_host );
609         net_is_registered = -1;
610         printf("Unregistering from deamon\n");
611 }
612
613 extern void net_fgd_scan(puObject *cb);
614 #endif // #ifdef FG_NETWORK_OLK
615
616 /* -----------------------------------------------------------------------
617 The menu stuff 
618 ---------------------------------------------------------------------*/
619 char *fileSubmenu               [] = {
620     "Exit", /* "Close", "---------", */
621 #if defined( WIN32 ) && !defined( __CYGWIN__)
622     "Print",
623 #endif
624     "Snap Shot",
625     "---------", 
626     "Reset", 
627     "Load flight",
628     "Save flight",
629     NULL
630 };
631 puCallback fileSubmenuCb        [] = {
632     MayBeGoodBye, /* hideMenuCb, NULL, */
633 #if defined( WIN32 ) && !defined( __CYGWIN__)
634     printScreen, 
635 #endif
636     /* NULL, notCb, */
637     dumpSnapShot,
638     NULL,
639     reInit, 
640     loadFlight,
641     saveFlight,
642     NULL
643 };
644
645 /*
646 char *editSubmenu               [] = {
647     "Edit text", NULL
648 };
649 puCallback editSubmenuCb        [] = {
650     notCb, NULL
651 };
652 */
653
654 extern void fgHUDalphaAdjust( puObject * );
655 char *viewSubmenu               [] = {
656     "HUD Alpha",
657     "Pilot Offset",
658     /* "Cockpit View > ", "View >","------------", */
659     "Toggle Panel...", NULL
660 };
661 puCallback viewSubmenuCb        [] = {
662     fgHUDalphaAdjust,
663     PilotOffsetAdjust,
664     /* notCb, notCb, NULL, */
665     guiTogglePanel, NULL
666 };
667
668 //  "---------", 
669
670 char *autopilotSubmenu           [] = {
671     "Toggle HUD Format", "Adjust AP Settings",
672     "---------", 
673     "Clear Route", "Skip Current Waypoint", "Add Waypoint",
674     "---------", 
675     "Set Altitude", "Set Heading",
676     NULL
677 };
678
679 puCallback autopilotSubmenuCb    [] = {
680     fgLatLonFormatToggle, fgAPAdjust,
681     NULL,
682     ClearRoute, PopWayPoint, AddWayPoint,
683     NULL,
684     NewAltitude, NewHeading,
685     /* notCb, */ NULL
686 };
687
688 char *environmentSubmenu        [] = {
689     "Goto Airport", /* "Terrain", "Weather", */ NULL
690 };
691 puCallback environmentSubmenuCb [] = {
692     NewAirport, /* notCb, notCb, */ NULL
693 };
694
695 /*
696 char *optionsSubmenu            [] = {
697     "Preferences", "Realism & Reliablity...", NULL
698 };
699 puCallback optionsSubmenuCb     [] = {
700     notCb, notCb, NULL
701 };
702 */
703
704 #ifdef FG_NETWORK_OLK
705 char *networkSubmenu            [] = {
706     "Unregister from FGD ", /* "Send MSG to All", "Send MSG", "Show Pilots", */
707     "Register to FGD",
708     "Scan for Deamons", "Enter Callsign", /* "Display Netinfos", */
709     "Toggle Display", NULL
710 };
711 puCallback networkSubmenuCb     [] = {
712     /* notCb, notCb, notCb, notCb, */ 
713     net_unregister, 
714     net_register, 
715     net_fgd_scan, NewCallSign, 
716     net_display_toggle, NULL
717 };
718 #endif
719
720 char *helpSubmenu               [] = {
721     /* "About...", */ "Help", NULL
722 };
723 puCallback helpSubmenuCb        [] = {
724     /* notCb, */ helpCb, NULL
725 };
726
727
728 /* -------------------------------------------------------------------------
729 init the gui
730 _____________________________________________________________________*/
731
732
733 void guiInit()
734 {
735     char *mesa_win_state;
736
737     // Initialize PUI
738     puInit();
739     puSetDefaultStyle         ( PUSTYLE_SMALL_BEVELLED ); //PUSTYLE_DEFAULT
740     puSetDefaultColourScheme  (0.8, 0.8, 0.8, 0.4);
741
742     // Initialize our GLOBAL GUI STRINGS
743     gui_msg_OK     = msg_OK;     // "OK"
744     gui_msg_NO     = msg_NO;     // "NO"
745     gui_msg_YES    = msg_YES;    // "YES"
746     gui_msg_CANCEL = msg_CANCEL; // "CANCEL"
747     gui_msg_RESET  = msg_RESET;  // "RESET"
748
749     // Next check home directory
750     SGPath fntpath;
751     char* envp = ::getenv( "FG_FONTS" );
752     if ( envp != NULL ) {
753         fntpath.set( envp );
754     } else {
755         fntpath.set( globals->get_fg_root() );
756         fntpath.append( "Fonts" );
757     }
758
759     // Install our fast fonts
760     fntpath.append( "typewriter.txf" );
761     guiFntHandle = new fntTexFont ;
762     guiFntHandle -> load ( (char *)fntpath.c_str() ) ;
763     puFont GuiFont ( guiFntHandle, 15 ) ;
764     puSetDefaultFonts( GuiFont, GuiFont ) ;
765     guiFnt = puGetDefaultLabelFont();
766   
767     if (!fgHasValue("/sim/startup/mouse-pointer")) {
768         // no preference specified for mouse pointer, attempt to autodetect...
769         // Determine if we need to render the cursor, or if the windowing
770         // system will do it.  First test if we are rendering with glide.
771         if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
772             // Test for the MESA_GLX_FX env variable
773             if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
774                 // test if we are fullscreen mesa/glide
775                 if ( (mesa_win_state[0] == 'f') ||
776                      (mesa_win_state[0] == 'F') ) {
777                     puShowCursor ();
778                 }
779             }
780         }
781 //        mouse_active = ~mouse_active;
782     } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
783         // don't show pointer
784     } else {
785         // force showing pointer
786         puShowCursor();
787 //        mouse_active = ~mouse_active;
788     }
789         
790     // MOUSE_VIEW mode stuff
791         initMouseQuat();
792
793     // Set up our Dialog Boxes
794     ConfirmExitDialogInit();
795     NewAirportInit();
796 #ifdef FG_NETWORK_OLK
797     NewNetIdInit();
798     NewNetFGDInit();
799 #endif
800
801         mkDialogInit();
802     
803     // Make the menu bar
804     mainMenuBar = new puMenuBar ();
805     mainMenuBar -> add_submenu ("File", fileSubmenu, fileSubmenuCb);
806     // mainMenuBar -> add_submenu ("Edit", editSubmenu, editSubmenuCb);
807     mainMenuBar -> add_submenu ("View", viewSubmenu, viewSubmenuCb);
808     mainMenuBar -> add_submenu ("Environment", environmentSubmenu, environmentSubmenuCb);
809     mainMenuBar -> add_submenu ("Autopilot", autopilotSubmenu, autopilotSubmenuCb);
810     // mainMenuBar -> add_submenu ("Options", optionsSubmenu, optionsSubmenuCb);
811 #ifdef FG_NETWORK_OLK
812     if ( fgGetBool("/sim/networking/network-olk") ) {
813         mainMenuBar -> add_submenu ("Network", networkSubmenu, networkSubmenuCb);
814     }
815 #endif
816     mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
817     mainMenuBar-> close ();
818     // Set up menu bar toggle
819     gui_menu_on = ~0;
820 }
821