1 /**************************************************************************
4 * Written 1998 by Durk Talsma, started Juni, 1998. For the flight gear
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 **************************************************************************/
29 #include <Include/compiler.h>
31 #ifdef FG_MATH_EXCEPTION_CLASH
42 #if defined(FX) && defined(XMESA)
43 # include <GL/xmesa.h>
51 #include <Include/general.hxx>
52 #include <Debug/logstream.hxx>
53 #include <Aircraft/aircraft.hxx>
54 #include <Airports/simple.hxx>
55 #include <Cockpit/panel.hxx>
56 #include <FDM/flight.hxx>
57 #include <Main/options.hxx>
58 #include <Main/fg_init.hxx>
59 #include <Main/views.hxx>
60 #include <Misc/fgpath.hxx>
61 #include <Network/network.h>
62 #include <Time/fg_time.hxx>
69 fntTexFont *guiFntHandle = 0;
71 static puMenuBar *mainMenuBar = 0;
72 //static puButton *hideMenuButton = 0;
74 static puDialogBox *dialogBox = 0;
75 static puFrame *dialogFrame = 0;
76 static puText *dialogBoxMessage = 0;
77 static puOneShot *dialogBoxOkButton = 0;
80 static puDialogBox *YNdialogBox = 0;
81 static puFrame *YNdialogFrame = 0;
82 static puText *YNdialogBoxMessage = 0;
83 static puOneShot *YNdialogBoxOkButton = 0;
84 static puOneShot *YNdialogBoxNoButton = 0;
86 static char msg_OK[] = "OK";
87 static char msg_NO[] = "NO";
88 static char msg_YES[] = "YES";
89 static char msg_CANCEL[] = "Cancel";
90 static char msg_RESET[] = "Reset";
92 char *gui_msg_OK; // "OK"
93 char *gui_msg_NO; // "NO"
94 char *gui_msg_YES; // "YES"
95 char *gui_msg_CANCEL; // "CANCEL"
96 char *gui_msg_RESET; // "RESET"
98 static char global_dialog_string[256];
100 extern void NewAltitude( puObject *cb );
101 extern void NewHeading( puObject *cb );
102 extern void fgAPAdjust( puObject * );
103 extern void fgLatLonFormatToggle( puObject *);
105 /* --------------------------------------------------------------------
107 ---------------------------------------------------------------------*/
111 static int last_buttons = 0 ;
112 static int mouse_active = 0;
113 static int menu_on = 0;
115 void guiMotionFunc ( int x, int y )
120 glutPostRedisplay () ;
123 void guiMouseFunc(int button, int updown, int x, int y)
127 if ( updown == PU_DOWN )
128 last_buttons |= ( 1 << button ) ;
130 last_buttons &= ~( 1 << button ) ;
131 puMouse (button, updown, x,y);
132 glutPostRedisplay ();
135 int guiGetMouseButton(void)
140 void guiGetMouse(int *x, int *y)
146 static inline void TurnCursorOn( void )
149 #if defined ( WIN32 ) || defined(__CYGWIN32__)
150 glutSetCursor(GLUT_CURSOR_INHERIT);
152 #if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
153 glutWarpPointer( glutGet(GLUT_SCREEN_WIDTH)/2, glutGet(GLUT_SCREEN_HEIGHT)/2);
157 static inline void TurnCursorOff( void )
160 #if defined ( WIN32 ) || defined(__CYGWIN32__)
161 glutSetCursor(GLUT_CURSOR_NONE);
162 #else // I guess this is what we want to do ??
163 #if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
164 glutWarpPointer( glutGet(GLUT_SCREEN_WIDTH), glutGet(GLUT_SCREEN_HEIGHT));
169 void maybeToggleMouse( void )
172 static int first_time = ~0;
173 static int mouse_changed = 0;
177 mouse_changed = ~mouse_changed;
181 if( mouse_changed ) {
182 mouse_changed = ~mouse_changed;
188 first_time = ~first_time;
189 #endif // #ifdef WIN32
192 // Call with FALSE to init and TRUE to restore
193 void BusyCursor( int restore )
195 static int cursor = 0;
197 glutSetCursor(cursor);
199 cursor = glutGet( GLUT_WINDOW_CURSOR );
203 glutSetCursor( GLUT_CURSOR_WAIT );
206 /* ================ General Purpose Functions ================ */
208 // Intercept the Escape Key
209 void ConfirmExitDialog(void)
211 FG_PUSH_PUI_DIALOG( YNdialogBox );
214 // General Purpose Message Box
215 void mkDialog (const char *txt)
217 strncpy(global_dialog_string, txt, 256);
218 dialogBoxMessage->setLabel(global_dialog_string);
219 FG_PUSH_PUI_DIALOG( dialogBox );
222 // Repair any damage done to the Panel by other Gui Items
223 void guiFixPanel( void )
227 if ( current_options.get_panel_status() ) {
228 FGView *v = ¤t_view;
229 FGTime *t = FGTime::cur_time_params;
231 if( (toggle_pause = !t->getPause()) )
232 t->togglePauseMode();
234 // this seems to be the only way to do this :-(
235 // problem is the viewport has been mucked with
236 xglViewport(0, 0 , (GLint)(v->winWidth), (GLint)(v->winHeight) );
237 FGPanel::OurPanel->ReInit(0, 0, 1024, 768);
240 t->togglePauseMode();
244 // Toggle the Menu and Mouse display state
245 void guiToggleMenu(void)
248 // printf("Hiding Menu\n");
249 mainMenuBar->hide ();
252 #endif // #ifdef WIN32
254 // printf("Showing Menu\n");
255 mainMenuBar->reveal();
258 #endif // #ifdef WIN32
263 /* -----------------------------------------------------------------------
264 the Gui callback functions
265 ____________________________________________________________________*/
267 void reInit(puObject *cb)
270 fgReInitSubsystems();
274 // This is the accessor function
275 void guiTogglePanel(puObject *cb)
277 current_options.toggle_panel();
280 //void MenuHideMenuCb(puObject *cb)
281 void hideMenuCb (puObject *cb)
286 void goodBye(puObject *)
288 // FG_LOG( FG_INPUT, FG_ALERT,
289 // "Program exiting normally at user request." );
290 cout << "Program exiting normally at user request." << endl;
299 void goAwayCb (puObject *me)
301 FG_POP_PUI_DIALOG( dialogBox );
304 void mkDialogInit (void)
306 // printf("mkDialogInit\n");
307 int x = (current_options.get_xsize()/2 - 400/2);
308 int y = (current_options.get_ysize()/2 - 100/2);
309 dialogBox = new puDialogBox (x, y); // 150, 50
311 dialogFrame = new puFrame (0,0,400,100);
312 dialogBoxMessage = new puText (10, 70);
313 dialogBoxMessage -> setLabel ("");
314 dialogBoxOkButton = new puOneShot (180, 10, 240, 50);
315 dialogBoxOkButton -> setLegend (gui_msg_OK);
316 dialogBoxOkButton -> makeReturnDefault (TRUE );
317 dialogBoxOkButton -> setCallback (goAwayCb);
319 FG_FINALIZE_PUI_DIALOG( dialogBox );
322 void MayBeGoodBye(puObject *)
327 void goAwayYesNoCb(puObject *me)
329 FG_POP_PUI_DIALOG( YNdialogBox);
332 void ConfirmExitDialogInit(void)
334 char msg[] = "Really Quit";
337 // printf("ConfirmExitDialogInit\n");
338 int len = 200 - puGetStringWidth( puGetDefaultLabelFont(), msg )/2;
340 int x = (current_options.get_xsize()/2 - 400/2);
341 int y = (current_options.get_ysize()/2 - 100/2);
343 YNdialogBox = new puDialogBox (x, y); // 150, 50
344 // YNdialogBox = new puDialogBox (150, 50);
346 YNdialogFrame = new puFrame (0,0,400, 100);
348 YNdialogBoxMessage = new puText (len, 70);
349 YNdialogBoxMessage -> setDefaultValue (msg);
350 YNdialogBoxMessage -> getDefaultValue (&s);
351 YNdialogBoxMessage -> setLabel (s);
353 YNdialogBoxOkButton = new puOneShot (100, 10, 160, 50);
354 YNdialogBoxOkButton -> setLegend (gui_msg_OK);
355 YNdialogBoxOkButton -> setCallback (goodBye);
357 YNdialogBoxNoButton = new puOneShot (240, 10, 300, 50);
358 YNdialogBoxNoButton -> setLegend (gui_msg_NO);
359 // YNdialogBoxNoButton -> makeReturnDefault (TRUE );
360 YNdialogBoxNoButton -> setCallback (goAwayYesNoCb);
362 FG_FINALIZE_PUI_DIALOG( YNdialogBox );
365 void notCb (puObject *)
367 mkDialog ("This function isn't implemented yet");
370 void helpCb (puObject *)
374 #if defined(FX) && !defined(WIN32)
375 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
376 if ( global_fullscreen ) {
377 global_fullscreen = false;
378 XMesaSetFXmode( XMESA_FX_WINDOW );
384 string url = "http://www.flightgear.org/Docs/InstallGuide/getstart.html";
386 if ( system("xwininfo -name Netscape > /dev/null 2>&1") == 0 ) {
387 command = "netscape -remote \"openURL(" + url + ")\" &";
389 command = "netscape " + url + " &";
392 command = "webrun.bat";
395 system( command.c_str() );
396 //string text = "Help started in netscape window.";
398 //mkDialog (text.c_str());
399 mkDialog ("Help started in netscape window.");
402 /// The beginnings of teleportation :-)
403 // Needs cleaning up but works
404 // These statics should disapear when this is a class
405 static puDialogBox *AptDialog = 0;
406 static puFrame *AptDialogFrame = 0;
407 static puText *AptDialogMessage = 0;
408 static puInput *AptDialogInput = 0;
410 static char NewAirportId[16];
411 static char NewAirportLabel[] = "Enter New Airport ID";
413 static puOneShot *AptDialogOkButton = 0;
414 static puOneShot *AptDialogCancelButton = 0;
415 static puOneShot *AptDialogResetButton = 0;
417 void AptDialog_Cancel(puObject *)
419 FG_POP_PUI_DIALOG( AptDialog );
422 void AptDialog_OK (puObject *)
426 FGTime *t = FGTime::cur_time_params;
427 int PauseMode = t->getPause();
429 t->togglePauseMode();
432 AptDialogInput->getValue(&s);
435 AptDialog_Cancel( NULL );
437 if ( AptId.length() ) {
438 // set initial position from airport id
442 FG_LOG( FG_GENERAL, FG_INFO,
443 "Attempting to set starting position from airport code "
446 airports.load("apt_simple");
447 if ( airports.search( AptId, &a ) )
449 current_options.set_airport_id( AptId.c_str() );
451 fgReInitSubsystems();
454 AptId += " not in database.";
455 mkDialog(AptId.c_str());
458 if( PauseMode != t->getPause() )
459 t->togglePauseMode();
462 void AptDialog_Reset(puObject *)
464 // strncpy( NewAirportId, current_options.get_airport_id().c_str(), 16 );
465 sprintf( NewAirportId, "%s", current_options.get_airport_id().c_str() );
466 AptDialogInput->setValue ( NewAirportId );
467 AptDialogInput->setCursor( 0 ) ;
470 void NewAirport(puObject *cb)
472 // strncpy( NewAirportId, current_options.get_airport_id().c_str(), 16 );
473 sprintf( NewAirportId, "%s", current_options.get_airport_id().c_str() );
474 AptDialogInput->setValue( NewAirportId );
476 FG_PUSH_PUI_DIALOG( AptDialog );
479 static void NewAirportInit(void)
481 sprintf( NewAirportId, "%s", current_options.get_airport_id().c_str() );
482 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
483 NewAirportLabel ) / 2;
485 AptDialog = new puDialogBox (150, 50);
487 AptDialogFrame = new puFrame (0,0,350, 150);
488 AptDialogMessage = new puText (len, 110);
489 AptDialogMessage -> setLabel (NewAirportLabel);
491 AptDialogInput = new puInput (50, 70, 300, 100);
492 AptDialogInput -> setValue (NewAirportId);
493 AptDialogInput -> acceptInput();
495 AptDialogOkButton = new puOneShot (50, 10, 110, 50);
496 AptDialogOkButton -> setLegend (gui_msg_OK);
497 AptDialogOkButton -> setCallback (AptDialog_OK);
498 AptDialogOkButton -> makeReturnDefault(TRUE);
500 AptDialogCancelButton = new puOneShot (140, 10, 210, 50);
501 AptDialogCancelButton -> setLegend (gui_msg_CANCEL);
502 AptDialogCancelButton -> setCallback (AptDialog_Cancel);
504 AptDialogResetButton = new puOneShot (240, 10, 300, 50);
505 AptDialogResetButton -> setLegend (gui_msg_RESET);
506 AptDialogResetButton -> setCallback (AptDialog_Reset);
508 FG_FINALIZE_PUI_DIALOG( AptDialog );
511 /// The beginnings of networking :-)
512 // Needs cleaning up but works
513 // These statics should disapear when this is a class
514 static puDialogBox *NetIdDialog = 0;
515 static puFrame *NetIdDialogFrame = 0;
516 static puText *NetIdDialogMessage = 0;
517 static puInput *NetIdDialogInput = 0;
519 static char NewNetId[16];
520 static char NewNetIdLabel[] = "Enter New Callsign";
522 static puOneShot *NetIdDialogOkButton = 0;
523 static puOneShot *NetIdDialogCancelButton = 0;
525 void NetIdDialog_Cancel(puObject *)
527 FG_POP_PUI_DIALOG( NetIdDialog );
530 void NetIdDialog_OK (puObject *)
534 FGTime *t = FGTime::cur_time_params;
535 int PauseMode = t->getPause();
537 t->togglePauseMode();
540 NetIdDialogInput->getValue(&s);
543 NetIdDialog_Cancel( NULL );
544 current_options.set_net_id( NetId.c_str() );
547 if( PauseMode != t->getPause() )
548 t->togglePauseMode();
551 void NewCallSign(puObject *cb)
553 sprintf( NewNetId, "%s", current_options.get_net_id().c_str() );
554 NetIdDialogInput->setValue( NewNetId );
556 FG_PUSH_PUI_DIALOG( NetIdDialog );
559 static void NewNetIdInit(void)
561 sprintf( NewNetId, "%s", current_options.get_net_id().c_str() );
562 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
565 NetIdDialog = new puDialogBox (150, 50);
567 NetIdDialogFrame = new puFrame (0,0,350, 150);
568 NetIdDialogMessage = new puText (len, 110);
569 NetIdDialogMessage -> setLabel (NewNetIdLabel);
571 NetIdDialogInput = new puInput (50, 70, 300, 100);
572 NetIdDialogInput -> setValue (NewNetId);
573 NetIdDialogInput -> acceptInput();
575 NetIdDialogOkButton = new puOneShot (50, 10, 110, 50);
576 NetIdDialogOkButton -> setLegend (gui_msg_OK);
577 NetIdDialogOkButton -> setCallback (NetIdDialog_OK);
578 NetIdDialogOkButton -> makeReturnDefault(TRUE);
580 NetIdDialogCancelButton = new puOneShot (240, 10, 300, 50);
581 NetIdDialogCancelButton -> setLegend (gui_msg_CANCEL);
582 NetIdDialogCancelButton -> setCallback (NetIdDialog_Cancel);
585 FG_FINALIZE_PUI_DIALOG( NetIdDialog );
588 static void net_display_toggle( puObject *cb)
590 net_hud_display = (net_hud_display) ? 0 : 1;
593 /*************** End Networking **************/
597 /* -----------------------------------------------------------------------
599 ---------------------------------------------------------------------*/
600 char *fileSubmenu [] = {
601 "Exit", "Close", "---------", "Print", "---------", "Save", "Reset", NULL
603 puCallback fileSubmenuCb [] = {
604 MayBeGoodBye, hideMenuCb, NULL, notCb, NULL, notCb, reInit, NULL
607 char *editSubmenu [] = {
610 puCallback editSubmenuCb [] = {
614 char *viewSubmenu [] = {
615 "Cockpit View > ", "View >","------------", "Toggle Panel...", NULL
617 puCallback viewSubmenuCb [] = {
618 notCb, notCb, NULL, guiTogglePanel, NULL
621 char *aircraftSubmenu [] = {
622 "Autopilot", "Heading", "Altitude", "Navigation", "Communication", NULL
624 puCallback aircraftSubmenuCb [] = {
625 fgAPAdjust, NewHeading, NewAltitude, fgLatLonFormatToggle, notCb, NULL
628 char *environmentSubmenu [] = {
629 "Airport", "Terrain", "Weather", NULL
631 puCallback environmentSubmenuCb [] = {
632 NewAirport, notCb, notCb, NULL
635 char *optionsSubmenu [] = {
636 "Preferences", "Realism & Reliablity...", NULL
638 puCallback optionsSubmenuCb [] = {
642 #ifdef FG_NETWORK_OLK
643 char *networkSubmenu [] = {
644 "Unregister from FGD ", "Send MSG to All", "Send MSG", "Show Pilots", "Register to FGD",
645 "Scan for Deamons", "Enter Callsign", "Display Netinfos", "Toggle Display", NULL
647 puCallback networkSubmenuCb [] = {
648 notCb, notCb, notCb, notCb, notCb, notCb, NewCallSign, notCb,
649 net_display_toggle, NULL
653 char *helpSubmenu [] = {
654 "About...", "Help", NULL
656 puCallback helpSubmenuCb [] = {
661 /* -------------------------------------------------------------------------
663 _____________________________________________________________________*/
668 char *mesa_win_state;
672 puSetDefaultStyle ( PUSTYLE_SMALL_BEVELLED ); //PUSTYLE_DEFAULT
673 puSetDefaultColourScheme (0.8, 0.8, 0.8, 0.4);
675 // Initialize our GLOBAL GUI STRINGS
676 gui_msg_OK = msg_OK; // "OK"
677 gui_msg_NO = msg_NO; // "NO"
678 gui_msg_YES = msg_YES; // "YES"
679 gui_msg_CANCEL = msg_CANCEL; // "CANCEL"
680 gui_msg_RESET = msg_RESET; // "RESET"
682 // Next check home directory
684 char* envp = ::getenv( "FG_FONTS" );
685 if ( envp != NULL ) {
688 fntpath.set( current_options.get_fg_root() );
689 fntpath.append( "Fonts" );
692 // Install our fast fonts
693 fntpath.append( "typewriter.txf" );
694 guiFntHandle = new fntTexFont ;
695 guiFntHandle -> load ( fntpath.c_str() ) ;
696 puFont GuiFont ( guiFntHandle, 15 ) ;
697 puSetDefaultFonts( GuiFont, GuiFont ) ;
698 guiFnt = puGetDefaultLabelFont();
700 if ( current_options.get_mouse_pointer() == 0 ) {
701 // no preference specified for mouse pointer, attempt to autodetect...
702 // Determine if we need to render the cursor, or if the windowing
703 // system will do it. First test if we are rendering with glide.
704 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
705 // Test for the MESA_GLX_FX env variable
706 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
707 // test if we are fullscreen mesa/glide
708 if ( (mesa_win_state[0] == 'f') ||
709 (mesa_win_state[0] == 'F') ) {
714 mouse_active = ~mouse_active;
715 } else if ( current_options.get_mouse_pointer() == 1 ) {
716 // don't show pointer
717 } else if ( current_options.get_mouse_pointer() == 2 ) {
718 // force showing pointer
720 mouse_active = ~mouse_active;
723 // Set up our Dialog Boxes
724 ConfirmExitDialogInit();
726 #ifdef FG_NETWORK_OLK
732 mainMenuBar = new puMenuBar ();
733 mainMenuBar -> add_submenu ("File", fileSubmenu, fileSubmenuCb);
734 mainMenuBar -> add_submenu ("Edit", editSubmenu, editSubmenuCb);
735 mainMenuBar -> add_submenu ("View", viewSubmenu, viewSubmenuCb);
736 mainMenuBar -> add_submenu ("Aircraft", aircraftSubmenu, aircraftSubmenuCb);
737 mainMenuBar -> add_submenu ("Environment", environmentSubmenu, environmentSubmenuCb);
738 mainMenuBar -> add_submenu ("Options", optionsSubmenu, optionsSubmenuCb);
739 #ifdef FG_NETWORK_OLK
740 mainMenuBar -> add_submenu ("Network", networkSubmenu, networkSubmenuCb);
742 mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
743 mainMenuBar-> close ();
744 // Set up menu bar toggle