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