1 /**************************************************************************
4 * Written 1998 by Durk Talsma, started Juni, 1998. For the flight gear
7 * Additional mouse supported added by David Megginson, 1999.
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.
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.
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.
24 **************************************************************************/
31 #include <simgear/compiler.h>
33 #ifdef SG_MATH_EXCEPTION_CLASH
42 #include <simgear/xgl/xgl.h>
44 #if defined(FX) && defined(XMESA)
45 # include <GL/xmesa.h>
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>
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>
75 #include <NetworkOLK/network.h>
78 #if defined( WIN32 ) && !defined( __CYGWIN__ )
79 # include <simgear/screen/win32-printer.h>
80 # include <simgear/screen/GlBitmaps.h>
84 #include "gui_local.hxx"
85 #include "apt_dlg.hxx"
86 #include "net_dlg.hxx"
87 #include "sgVec3Slider.hxx"
91 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
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 );
101 fntTexFont *guiFntHandle = 0;
103 static puMenuBar *mainMenuBar = 0;
104 //static puButton *hideMenuButton = 0;
106 static puDialogBox *dialogBox = 0;
107 static puFrame *dialogFrame = 0;
108 static puText *dialogBoxMessage = 0;
109 static puOneShot *dialogBoxOkButton = 0;
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;
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";
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"
130 static char global_dialog_string[256];
133 extern void fgLatLonFormatToggle( puObject *);
136 /* ================ General Purpose Functions ================ */
138 // Intercept the Escape Key
139 void ConfirmExitDialog(void)
141 FG_PUSH_PUI_DIALOG( YNdialogBox );
144 // General Purpose Message Box
145 void mkDialog (const char *txt)
147 strncpy(global_dialog_string, txt, 256);
148 dialogBoxMessage->setLabel(global_dialog_string);
149 FG_PUSH_PUI_DIALOG( dialogBox );
152 // Toggle the Menu and Mouse display state
153 void guiToggleMenu(void)
156 // printf("Hiding Menu\n");
157 mainMenuBar->hide ();
158 #if defined(WIN32_CURSOR_TWEAKS)
159 if( mouse_mode == MOUSE_POINTER )
161 #endif // #ifdef WIN32_CURSOR_TWEAKS
163 // printf("Showing Menu\n");
164 mainMenuBar->reveal();
167 #endif // #ifdef WIN32
169 gui_menu_on = ~gui_menu_on;
172 /* -----------------------------------------------------------------------
173 the Gui callback functions
174 ____________________________________________________________________*/
177 // Hier Neu :-) This is my newly added code
178 // Added by David Findlay <nedz@bigpond.com>
179 // on Sunday 3rd of December
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;
187 static puOneShot *SaveDialogOkButton = 0;
188 static puOneShot *SaveDialogCancelButton = 0;
189 static puOneShot *SaveDialogResetButton = 0;
191 // Default save filename
192 static char saveFile[256] = "fgfs.sav";
195 void SaveDialogCancel(puObject *) {
196 FG_POP_PUI_DIALOG( SaveDialog );
199 // If press OK do this
200 void SaveDialogOk(puObject*) {
202 FG_POP_PUI_DIALOG( SaveDialog );
205 SaveDialogInput->getValue(&s);
208 cout << saveFile << endl;
209 if (output.good() && fgSaveFlight(output)) {
211 mkDialog("Saved flight");
212 SG_LOG(SG_INPUT, SG_INFO, "Saved flight");
214 mkDialog("Cannot save flight");
215 SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight");
220 static void saveFlight(puObject *cv) {
221 SaveDialog = new puDialogBox (150, 50);
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:");
228 SaveDialogInput = new puInput (50, 70, 300, 100);
229 SaveDialogInput -> setValue (saveFile);
230 SaveDialogInput -> acceptInput();
232 SaveDialogOkButton = new puOneShot (50, 10, 110, 50);
233 SaveDialogOkButton -> setLegend (gui_msg_OK);
234 SaveDialogOkButton -> setCallback ( SaveDialogOk );
235 SaveDialogOkButton -> makeReturnDefault(TRUE);
237 SaveDialogCancelButton = new puOneShot (140, 10, 210, 50);
238 SaveDialogCancelButton -> setLegend (gui_msg_CANCEL);
239 SaveDialogCancelButton -> setCallback ( SaveDialogCancel );
241 FG_FINALIZE_PUI_DIALOG( SaveDialog );
243 SaveDialog -> reveal();
247 static puDialogBox *LoadDialog = 0;
248 static puFrame *LoadDialogFrame = 0;
249 static puText *LoadDialogMessage = 0;
250 static puInput *LoadDialogInput = 0;
252 static puOneShot *LoadDialogOkButton = 0;
253 static puOneShot *LoadDialogCancelButton = 0;
254 static puOneShot *LoadDialogResetButton = 0;
256 // Default load filename
257 static char loadFile[256] = "fgfs.sav";
259 // Do this if the person click okay
260 void LoadDialogOk(puObject *) {
262 FG_POP_PUI_DIALOG( LoadDialog );
265 LoadDialogInput->getValue(&l);
268 if (input.good() && fgLoadFlight(input)) {
270 mkDialog("Loaded flight");
271 SG_LOG(SG_INPUT, SG_INFO, "Restored flight");
273 mkDialog("Failed to load flight");
274 SG_LOG(SG_INPUT, SG_ALERT, "Cannot load flight");
278 // Do this is the person presses cancel
279 void LoadDialogCancel(puObject *) {
280 FG_POP_PUI_DIALOG( LoadDialog );
283 // Create Load Dialog
284 static void loadFlight(puObject *cb)
286 LoadDialog = new puDialogBox (150, 50);
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:");
293 LoadDialogInput = new puInput (50, 70, 300, 100);
294 LoadDialogInput -> setValue (loadFile);
295 LoadDialogInput -> acceptInput();
297 LoadDialogOkButton = new puOneShot (50, 10, 110, 50);
298 LoadDialogOkButton -> setLegend (gui_msg_OK);
299 LoadDialogOkButton -> setCallback ( LoadDialogOk );
300 LoadDialogOkButton -> makeReturnDefault(TRUE);
302 LoadDialogCancelButton = new puOneShot (140, 10, 210, 50);
303 LoadDialogCancelButton -> setLegend (gui_msg_CANCEL);
304 LoadDialogCancelButton -> setCallback ( LoadDialogCancel );
306 FG_FINALIZE_PUI_DIALOG( LoadDialog );
308 LoadDialog -> reveal();
311 // This is the accessor function
312 void guiTogglePanel(puObject *cb)
314 if (fgGetBool("/sim/panel/visibility"))
315 fgSetBool("/sim/panel/visibility", false);
317 fgSetBool("/sim/panel/visibility", true);
319 fgReshape(fgGetInt("/sim/startup/xsize"),
320 fgGetInt("/sim/startup/ysize"));
323 //void MenuHideMenuCb(puObject *cb)
324 void hideMenuCb (puObject *cb)
329 void goodBye(puObject *)
331 // SG_LOG( SG_INPUT, SG_ALERT,
332 // "Program exiting normally at user request." );
333 cout << "Program exiting normally at user request." << endl;
335 #ifdef FG_NETWORK_OLK
336 if ( fgGetBool("/sim/networking/network-olk") ) {
337 if ( net_is_registered == 0 ) fgd_send_com( "8", FGFS_host);
341 // close all external I/O connections
348 void goAwayCb (puObject *me)
350 FG_POP_PUI_DIALOG( dialogBox );
353 void mkDialogInit (void)
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
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);
368 FG_FINALIZE_PUI_DIALOG( dialogBox );
371 void MayBeGoodBye(puObject *)
376 void goAwayYesNoCb(puObject *me)
378 FG_POP_PUI_DIALOG( YNdialogBox);
381 void ConfirmExitDialogInit(void)
383 char msg[] = "Really Quit";
386 // printf("ConfirmExitDialogInit\n");
387 int len = 200 - puGetStringWidth( puGetDefaultLabelFont(), msg )/2;
389 int x = (fgGetInt("/sim/startup/xsize")/2 - 400/2);
390 int y = (fgGetInt("/sim/startup/ysize")/2 - 100/2);
392 YNdialogBox = new puDialogBox (x, y); // 150, 50
393 // YNdialogBox = new puDialogBox (150, 50);
395 YNdialogFrame = new puFrame (0,0,400, 100);
397 YNdialogBoxMessage = new puText (len, 70);
398 YNdialogBoxMessage -> setDefaultValue (msg);
399 YNdialogBoxMessage -> getDefaultValue (&s);
400 YNdialogBoxMessage -> setLabel (s);
402 YNdialogBoxOkButton = new puOneShot (100, 10, 160, 50);
403 YNdialogBoxOkButton -> setLegend (gui_msg_OK);
404 YNdialogBoxOkButton -> makeReturnDefault (TRUE );
405 YNdialogBoxOkButton -> setCallback (goodBye);
407 YNdialogBoxNoButton = new puOneShot (240, 10, 300, 50);
408 YNdialogBoxNoButton -> setLegend (gui_msg_NO);
409 YNdialogBoxNoButton -> setCallback (goAwayYesNoCb);
411 FG_FINALIZE_PUI_DIALOG( YNdialogBox );
414 void notCb (puObject *)
416 mkDialog ("This function isn't implemented yet");
419 void helpCb (puObject *)
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 );
433 string url = "http://www.flightgear.org/Docs/InstallGuide/getstart.html";
435 if ( system("xwininfo -name Netscape > /dev/null 2>&1") == 0 ) {
436 command = "netscape -remote \"openURL(" + url + ")\" &";
438 command = "netscape " + url + " &";
441 command = "webrun.bat";
444 system( command.c_str() );
445 //string text = "Help started in netscape window.";
447 //mkDialog (text.c_str());
448 mkDialog ("Help started in netscape window.");
451 #if defined( WIN32 ) && !defined( __CYGWIN__)
453 static void rotateView( double roll, double pitch, double yaw )
458 static GlBitmap *b1 = NULL;
459 extern FGInterface cur_view_fdm;
460 GLubyte *hiResScreenCapture( int multiplier )
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);
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" );
473 for ( y = 0; y < multiplier; y++ ) {
474 for ( x = 0; x < multiplier; x++ ) {
475 fgReshape( cur_width, cur_height );
477 rotateView( 0, (y*fov)-((multiplier-1)*fov/2), (x*fov)-((multiplier-1)*fov/2) );
481 b1->copyBitmap( &b2, cur_width*x, cur_height*y );
484 fgSetDouble("/sim/field-of-view", oldfov);
485 return b1->getBitmap();
490 #if defined( WIN32 ) && !defined( __CYGWIN__)
491 // win32 print screen function
492 void printScreen ( puObject *obj ) {
493 bool show_pu_cursor = false;
495 if ( !puCursorIsHidden() ) {
496 show_pu_cursor = true;
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) );
509 mainMenuBar->reveal();
512 if ( show_pu_cursor ) {
517 #endif // #ifdef WIN32
520 void dumpSnapShot ( puObject *obj ) {
525 // do a screen snap shot
526 void fgDumpSnapShot () {
527 bool show_pu_cursor = false;
529 int freeze = globals->get_freeze();
531 globals->set_freeze( true );
535 if ( !puCursorIsHidden() ) {
536 show_pu_cursor = true;
541 fgReshape( fgGetInt("/sim/startup/xsize"),
542 fgGetInt("/sim/startup/ysize") );
544 // we need two render frames here to clear the menu and cursor
545 // ... not sure why but doing an extra fgFenderFrame() shoulnd't
550 my_glDumpWindow( "fgfs-screen.ppm",
551 fgGetInt("/sim/startup/xsize"),
552 fgGetInt("/sim/startup/ysize") );
554 mkDialog ("Snap shot saved to fgfs-screen.ppm");
556 if ( show_pu_cursor ) {
562 mainMenuBar->reveal();
566 globals->set_freeze( false );
569 #ifdef FG_NETWORK_OLK
570 static void net_display_toggle( puObject *cb)
572 net_hud_display = (net_hud_display) ? 0 : 1;
573 printf("Toggle net_hud_display : %d\n", net_hud_display);
576 static void net_register( puObject *cb)
578 fgd_send_com( "1", FGFS_host );
579 net_is_registered = 0;
580 printf("Registering to deamon\n");
583 static void net_unregister( puObject *cb)
585 fgd_send_com( "8", FGFS_host );
586 net_is_registered = -1;
587 printf("Unregistering from deamon\n");
590 extern void net_fgd_scan(puObject *cb);
591 #endif // #ifdef FG_NETWORK_OLK
593 /* -----------------------------------------------------------------------
595 ---------------------------------------------------------------------*/
596 char *fileSubmenu [] = {
597 "Exit", /* "Close", "---------", */
598 #if defined( WIN32 ) && !defined( __CYGWIN__)
608 puCallback fileSubmenuCb [] = {
609 MayBeGoodBye, /* hideMenuCb, NULL, */
610 #if defined( WIN32 ) && !defined( __CYGWIN__)
623 char *editSubmenu [] = {
626 puCallback editSubmenuCb [] = {
631 extern void fgHUDalphaAdjust( puObject * );
632 char *viewSubmenu [] = {
635 /* "Cockpit View > ", "View >","------------", */
636 "Toggle Panel...", NULL
638 puCallback viewSubmenuCb [] = {
641 /* notCb, notCb, NULL, */
647 char *autopilotSubmenu [] = {
648 "Toggle HUD Format", "Adjust AP Settings",
650 "Clear Route", "Skip Current Waypoint", "Add Waypoint",
652 "Set Altitude", "Set Heading",
656 puCallback autopilotSubmenuCb [] = {
657 fgLatLonFormatToggle, fgAPAdjust,
659 ClearRoute, PopWayPoint, AddWayPoint,
661 NewAltitude, NewHeading,
665 char *environmentSubmenu [] = {
666 "Goto Airport", /* "Terrain", "Weather", */ NULL
668 puCallback environmentSubmenuCb [] = {
669 NewAirport, /* notCb, notCb, */ NULL
673 char *optionsSubmenu [] = {
674 "Preferences", "Realism & Reliablity...", NULL
676 puCallback optionsSubmenuCb [] = {
681 #ifdef FG_NETWORK_OLK
682 char *networkSubmenu [] = {
683 "Unregister from FGD ", /* "Send MSG to All", "Send MSG", "Show Pilots", */
685 "Scan for Deamons", "Enter Callsign", /* "Display Netinfos", */
686 "Toggle Display", NULL
688 puCallback networkSubmenuCb [] = {
689 /* notCb, notCb, notCb, notCb, */
692 net_fgd_scan, NewCallSign,
693 net_display_toggle, NULL
697 char *helpSubmenu [] = {
698 /* "About...", */ "Help", NULL
700 puCallback helpSubmenuCb [] = {
701 /* notCb, */ helpCb, NULL
705 /* -------------------------------------------------------------------------
707 _____________________________________________________________________*/
712 char *mesa_win_state;
716 puSetDefaultStyle ( PUSTYLE_SMALL_BEVELLED ); //PUSTYLE_DEFAULT
717 puSetDefaultColourScheme (0.8, 0.8, 0.8, 0.4);
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"
726 // Next check home directory
728 char* envp = ::getenv( "FG_FONTS" );
729 if ( envp != NULL ) {
732 fntpath.set( globals->get_fg_root() );
733 fntpath.append( "Fonts" );
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();
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') ) {
758 // mouse_active = ~mouse_active;
759 } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
760 // don't show pointer
762 // force showing pointer
764 // mouse_active = ~mouse_active;
767 // MOUSE_VIEW mode stuff
770 // Set up our Dialog Boxes
771 ConfirmExitDialogInit();
773 #ifdef FG_NETWORK_OLK
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);
793 mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
794 mainMenuBar-> close ();
795 // Set up menu bar toggle