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