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