]> git.mxchange.org Git - flightgear.git/blob - src/GUI/gui.cxx
ee2e226cccb00d51d7659a8f1e8ce9b545937e7f
[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
87 FG_USING_STD(string);
88
89 #ifndef FG_HAVE_NATIVE_SGI_COMPILERS
90 FG_USING_STD(cout);
91 #endif
92
93 #if defined(WIN32) || defined(__CYGWIN32__)
94 #define WIN32_CURSOR_TWEAKS
95 #elif (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
96 #define X_CURSOR_TWEAKS
97 #endif
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         FG_LOG(FG_INPUT, FG_INFO, "Saved flight");
217     } else {
218         mkDialog("Cannot save flight");
219         FG_LOG(FG_INPUT, FG_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         FG_LOG(FG_INPUT, FG_INFO, "Restored flight");
276     } else {
277         mkDialog("Failed to load flight");
278         FG_LOG(FG_INPUT, FG_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/visiblity", false);
320   else
321     fgSetBool("/sim/panel/visibility", true);
322 }
323     
324 //void MenuHideMenuCb(puObject *cb)
325 void hideMenuCb (puObject *cb)
326 {
327     guiToggleMenu();
328 }
329
330 void goodBye(puObject *)
331 {
332     // FG_LOG( FG_INPUT, FG_ALERT,
333     //      "Program exiting normally at user request." );
334     cout << "Program exiting normally at user request." << endl;
335
336 #ifdef FG_NETWORK_OLK    
337     if ( fgGetBool("/sim/networking/network-olk") ) {
338         if ( net_is_registered == 0 ) fgd_send_com( "8", FGFS_host);
339     }
340 #endif
341
342     // close all external I/O connections
343     fgIOShutdownAll();
344
345     exit(0);
346 }
347
348
349 void goAwayCb (puObject *me)
350 {
351     FG_POP_PUI_DIALOG( dialogBox );
352 }
353
354 void mkDialogInit (void)
355 {
356     //  printf("mkDialogInit\n");
357     int x = (fgGetInt("/sim/startup/xsize")/2 - 400/2);
358     int y = (fgGetInt("/sim/startup/ysize")/2 - 100/2);
359     dialogBox = new puDialogBox (x, y); // 150, 50
360     {
361         dialogFrame = new puFrame (0,0,400,100);
362         dialogBoxMessage  =  new puText         (10, 70);
363         dialogBoxMessage  -> setLabel           ("");
364         dialogBoxOkButton =  new puOneShot      (180, 10, 240, 50);
365         dialogBoxOkButton -> setLegend          (gui_msg_OK);
366         dialogBoxOkButton -> makeReturnDefault  (TRUE );
367         dialogBoxOkButton -> setCallback        (goAwayCb);
368     }
369     FG_FINALIZE_PUI_DIALOG( dialogBox );
370 }
371
372 void MayBeGoodBye(puObject *)
373 {
374     ConfirmExitDialog(); 
375 }
376
377 void goAwayYesNoCb(puObject *me)
378 {
379     FG_POP_PUI_DIALOG( YNdialogBox);
380 }
381
382 void ConfirmExitDialogInit(void)
383 {
384     char msg[] = "Really Quit";
385     char *s;
386
387     //  printf("ConfirmExitDialogInit\n");
388     int len = 200 - puGetStringWidth( puGetDefaultLabelFont(), msg )/2;
389
390     int x = (fgGetInt("/sim/startup/xsize")/2 - 400/2);
391     int y = (fgGetInt("/sim/startup/ysize")/2 - 100/2);
392         
393     YNdialogBox = new puDialogBox (x, y); // 150, 50
394     //  YNdialogBox = new puDialogBox (150, 50);
395     {
396         YNdialogFrame = new puFrame (0,0,400, 100);
397         
398         YNdialogBoxMessage  =  new puText         (len, 70);
399         YNdialogBoxMessage  -> setDefaultValue    (msg);
400         YNdialogBoxMessage  -> getDefaultValue    (&s);
401         YNdialogBoxMessage  -> setLabel           (s);
402         
403         YNdialogBoxOkButton =  new puOneShot      (100, 10, 160, 50);
404         YNdialogBoxOkButton -> setLegend          (gui_msg_OK);
405         YNdialogBoxOkButton -> makeReturnDefault  (TRUE );
406         YNdialogBoxOkButton -> setCallback        (goodBye);
407         
408         YNdialogBoxNoButton =  new puOneShot      (240, 10, 300, 50);
409         YNdialogBoxNoButton -> setLegend          (gui_msg_NO);
410         YNdialogBoxNoButton -> setCallback        (goAwayYesNoCb);
411     }
412     FG_FINALIZE_PUI_DIALOG( YNdialogBox );
413 }
414
415 void notCb (puObject *)
416 {
417     mkDialog ("This function isn't implemented yet");
418 }
419
420 void helpCb (puObject *)
421 {
422     string command;
423         
424 #if defined(FX) && !defined(WIN32)
425 #  if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
426     if ( global_fullscreen ) {
427         global_fullscreen = false;
428         XMesaSetFXmode( XMESA_FX_WINDOW );
429     }
430 #  endif
431 #endif
432         
433 #if !defined(WIN32)
434     string url = "http://www.flightgear.org/Docs/InstallGuide/getstart.html";
435         
436     if ( system("xwininfo -name Netscape > /dev/null 2>&1") == 0 ) {
437         command = "netscape -remote \"openURL(" + url + ")\" &";
438     } else {
439         command = "netscape " + url + " &";
440     }
441 #else
442     command = "webrun.bat";
443 #endif
444         
445     system( command.c_str() );
446     //string text = "Help started in netscape window.";
447
448     //mkDialog (text.c_str());
449     mkDialog ("Help started in netscape window.");
450 }
451
452 #if defined( WIN32 ) && !defined( __CYGWIN__)
453
454 static void rotateView( double roll, double pitch, double yaw )
455 {
456         // rotate view
457 }
458
459 static GlBitmap *b1 = NULL;
460 extern FGInterface cur_view_fdm;
461 GLubyte *hiResScreenCapture( int multiplier )
462 {
463     float oldfov = fgGetDouble("/sim/field-of-view");
464     float fov = oldfov / multiplier;
465     FGViewer *v = globals->get_current_view();
466     fgSetDouble("/sim/field-of-view", fov);
467     fgInitVisuals();
468     int cur_width = fgGetInt("/sim/startup/xsize");
469     int cur_height = fgGetInt("/sim/startup/ysize");
470     if (b1) delete( b1 );
471     // New empty (mostly) bitmap
472     b1 = new GlBitmap( GL_RGB, 1, 1, (unsigned char *)"123" );
473     int x,y;
474     for ( y = 0; y < multiplier; y++ ) {
475         for ( x = 0; x < multiplier; x++ ) {
476             fgReshape( cur_width, cur_height );
477             // pan to tile
478             rotateView( 0, (y*fov)-((multiplier-1)*fov/2), (x*fov)-((multiplier-1)*fov/2) );
479             fgRenderFrame();
480             // restore view
481             GlBitmap b2;
482             b1->copyBitmap( &b2, cur_width*x, cur_height*y );
483         }
484     }
485     fgSetDouble("/sim/field-of-view", oldfov);
486     return b1->getBitmap();
487 }
488 #endif
489
490
491 #if defined( WIN32 ) && !defined( __CYGWIN__)
492 // win32 print screen function
493 void printScreen ( puObject *obj ) {
494     bool show_pu_cursor = false;
495     TurnCursorOff();
496     if ( !puCursorIsHidden() ) {
497         show_pu_cursor = true;
498         puHideCursor();
499     }
500     BusyCursor( 0 );
501     mainMenuBar->hide();
502
503     CGlPrinter p( CGlPrinter::PRINT_BITMAP );
504     int cur_width = fgGetInt("/sim/startup/xsize");
505     int cur_height = fgGetInt("/sim/startup/ysize");
506     p.Begin( "FlightGear", cur_width*3, cur_height*3 );
507         p.End( hiResScreenCapture(3) );
508
509     if( gui_menu_on ) {
510         mainMenuBar->reveal();
511     }
512     BusyCursor(1);
513     if ( show_pu_cursor ) {
514         puShowCursor();
515     }
516     TurnCursorOn();
517 }
518 #endif // #ifdef WIN32
519
520
521 void dumpSnapShot ( puObject *obj ) {
522     fgDumpSnapShot();
523 }
524
525
526 // do a screen snap shot
527 void fgDumpSnapShot () {
528     bool show_pu_cursor = false;
529
530     int freeze = globals->get_freeze();
531     if(!freeze)
532         globals->set_freeze( true );
533
534     mainMenuBar->hide();
535     TurnCursorOff();
536     if ( !puCursorIsHidden() ) {
537         show_pu_cursor = true;
538         puHideCursor();
539     }
540
541     fgInitVisuals();
542     fgReshape( fgGetInt("/sim/startup/xsize"),
543                fgGetInt("/sim/startup/ysize") );
544
545     // we need two render frames here to clear the menu and cursor
546     // ... not sure why but doing an extra fgFenderFrame() shoulnd't
547     // hurt anything
548     fgRenderFrame();
549     fgRenderFrame();
550
551     my_glDumpWindow( "fgfs-screen.ppm", 
552                      fgGetInt("/sim/startup/xsize"), 
553                      fgGetInt("/sim/startup/ysize") );
554     
555     mkDialog ("Snap shot saved to fgfs-screen.ppm");
556
557     if ( show_pu_cursor ) {
558         puShowCursor();
559     }
560
561     TurnCursorOn();
562     if( gui_menu_on ) {
563         mainMenuBar->reveal();
564     }
565
566     if(!freeze)
567         globals->set_freeze( false );
568 }
569
570 #ifdef FG_NETWORK_OLK
571 static void net_display_toggle( puObject *cb)
572 {
573         net_hud_display = (net_hud_display) ? 0 : 1;
574         printf("Toggle net_hud_display : %d\n", net_hud_display);
575 }
576
577 static void net_register( puObject *cb)
578 {
579         fgd_send_com( "1", FGFS_host );
580         net_is_registered = 0;
581         printf("Registering to deamon\n");
582 }
583
584 static void net_unregister( puObject *cb)
585 {
586         fgd_send_com( "8", FGFS_host );
587         net_is_registered = -1;
588         printf("Unregistering from deamon\n");
589 }
590
591 extern void net_fgd_scan(puObject *cb);
592 #endif // #ifdef FG_NETWORK_OLK
593
594 /* -----------------------------------------------------------------------
595 The menu stuff 
596 ---------------------------------------------------------------------*/
597 char *fileSubmenu               [] = {
598     "Exit", /* "Close", "---------", */
599 #if defined( WIN32 ) && !defined( __CYGWIN__)
600     "Print",
601 #endif
602     "Snap Shot",
603     "---------", 
604     "Reset", 
605     "Load flight",
606     "Save flight",
607     NULL
608 };
609 puCallback fileSubmenuCb        [] = {
610     MayBeGoodBye, /* hideMenuCb, NULL, */
611 #if defined( WIN32 ) && !defined( __CYGWIN__)
612     printScreen, 
613 #endif
614     /* NULL, notCb, */
615     dumpSnapShot,
616     NULL,
617     reInit, 
618     loadFlight,
619     saveFlight,
620     NULL
621 };
622
623 /*
624 char *editSubmenu               [] = {
625     "Edit text", NULL
626 };
627 puCallback editSubmenuCb        [] = {
628     notCb, NULL
629 };
630 */
631
632 extern void fgHUDalphaAdjust( puObject * );
633 char *viewSubmenu               [] = {
634     "HUD Alpha",
635     /* "Cockpit View > ", "View >","------------", */
636     "Toggle Panel...", NULL
637 };
638 puCallback viewSubmenuCb        [] = {
639     fgHUDalphaAdjust,
640     /* notCb, notCb, NULL, */
641     guiTogglePanel, NULL
642 };
643
644 //  "---------", 
645
646 char *autopilotSubmenu           [] = {
647     "Toggle HUD Format", "Adjust AP Settings",
648     "---------", 
649     "Clear Route", "Skip Current Waypoint", "Add Waypoint",
650     "---------", 
651     "Set Altitude", "Set Heading",
652     NULL
653 };
654
655 puCallback autopilotSubmenuCb    [] = {
656     fgLatLonFormatToggle, fgAPAdjust,
657     NULL,
658     ClearRoute, PopWayPoint, AddWayPoint,
659     NULL,
660     NewAltitude, NewHeading,
661     /* notCb, */ NULL
662 };
663
664 char *environmentSubmenu        [] = {
665     "Goto Airport", /* "Terrain", "Weather", */ NULL
666 };
667 puCallback environmentSubmenuCb [] = {
668     NewAirport, /* notCb, notCb, */ NULL
669 };
670
671 /*
672 char *optionsSubmenu            [] = {
673     "Preferences", "Realism & Reliablity...", NULL
674 };
675 puCallback optionsSubmenuCb     [] = {
676     notCb, notCb, NULL
677 };
678 */
679
680 #ifdef FG_NETWORK_OLK
681 char *networkSubmenu            [] = {
682     "Unregister from FGD ", /* "Send MSG to All", "Send MSG", "Show Pilots", */
683     "Register to FGD",
684     "Scan for Deamons", "Enter Callsign", /* "Display Netinfos", */
685     "Toggle Display", NULL
686 };
687 puCallback networkSubmenuCb     [] = {
688     /* notCb, notCb, notCb, notCb, */ 
689     net_unregister, 
690     net_register, 
691     net_fgd_scan, NewCallSign, 
692     net_display_toggle, NULL
693 };
694 #endif
695
696 char *helpSubmenu               [] = {
697     /* "About...", */ "Help", NULL
698 };
699 puCallback helpSubmenuCb        [] = {
700     /* notCb, */ helpCb, NULL
701 };
702
703
704 /* -------------------------------------------------------------------------
705 init the gui
706 _____________________________________________________________________*/
707
708
709 void guiInit()
710 {
711     char *mesa_win_state;
712
713     // Initialize PUI
714     puInit();
715     puSetDefaultStyle         ( PUSTYLE_SMALL_BEVELLED ); //PUSTYLE_DEFAULT
716     puSetDefaultColourScheme  (0.8, 0.8, 0.8, 0.4);
717
718     // Initialize our GLOBAL GUI STRINGS
719     gui_msg_OK     = msg_OK;     // "OK"
720     gui_msg_NO     = msg_NO;     // "NO"
721     gui_msg_YES    = msg_YES;    // "YES"
722     gui_msg_CANCEL = msg_CANCEL; // "CANCEL"
723     gui_msg_RESET  = msg_RESET;  // "RESET"
724
725     // Next check home directory
726     FGPath fntpath;
727     char* envp = ::getenv( "FG_FONTS" );
728     if ( envp != NULL ) {
729         fntpath.set( envp );
730     } else {
731         fntpath.set( globals->get_fg_root() );
732         fntpath.append( "Fonts" );
733     }
734
735     // Install our fast fonts
736     fntpath.append( "typewriter.txf" );
737     guiFntHandle = new fntTexFont ;
738     guiFntHandle -> load ( (char *)fntpath.c_str() ) ;
739     puFont GuiFont ( guiFntHandle, 15 ) ;
740     puSetDefaultFonts( GuiFont, GuiFont ) ;
741     guiFnt = puGetDefaultLabelFont();
742   
743     if (!fgHasValue("/sim/startup/mouse-pointer")) {
744         // no preference specified for mouse pointer, attempt to autodetect...
745         // Determine if we need to render the cursor, or if the windowing
746         // system will do it.  First test if we are rendering with glide.
747         if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
748             // Test for the MESA_GLX_FX env variable
749             if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
750                 // test if we are fullscreen mesa/glide
751                 if ( (mesa_win_state[0] == 'f') ||
752                      (mesa_win_state[0] == 'F') ) {
753                     puShowCursor ();
754                 }
755             }
756         }
757 //        mouse_active = ~mouse_active;
758     } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
759         // don't show pointer
760     } else {
761         // force showing pointer
762         puShowCursor();
763 //        mouse_active = ~mouse_active;
764     }
765         
766     // MOUSE_VIEW mode stuff
767         initMouseQuat();
768
769     // Set up our Dialog Boxes
770     ConfirmExitDialogInit();
771     NewAirportInit();
772 #ifdef FG_NETWORK_OLK
773     NewNetIdInit();
774     NewNetFGDInit();
775 #endif
776
777         mkDialogInit();
778     
779     // Make the menu bar
780     mainMenuBar = new puMenuBar ();
781     mainMenuBar -> add_submenu ("File", fileSubmenu, fileSubmenuCb);
782     // mainMenuBar -> add_submenu ("Edit", editSubmenu, editSubmenuCb);
783     mainMenuBar -> add_submenu ("View", viewSubmenu, viewSubmenuCb);
784     mainMenuBar -> add_submenu ("Environment", environmentSubmenu, environmentSubmenuCb);
785     mainMenuBar -> add_submenu ("Autopilot", autopilotSubmenu, autopilotSubmenuCb);
786     // mainMenuBar -> add_submenu ("Options", optionsSubmenu, optionsSubmenuCb);
787 #ifdef FG_NETWORK_OLK
788     if ( fgGetBool("/sim/networking/network-olk") ) {
789         mainMenuBar -> add_submenu ("Network", networkSubmenu, networkSubmenuCb);
790     }
791 #endif
792     mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
793     mainMenuBar-> close ();
794     // Set up menu bar toggle
795     gui_menu_on = ~0;
796 }
797