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>
68 #ifndef FG_HAVE_NATIVE_SGI_COMPILERS
73 fntTexFont *guiFntHandle = 0;
75 static puMenuBar *mainMenuBar = 0;
76 //static puButton *hideMenuButton = 0;
78 static puDialogBox *dialogBox = 0;
79 static puFrame *dialogFrame = 0;
80 static puText *dialogBoxMessage = 0;
81 static puOneShot *dialogBoxOkButton = 0;
84 static puDialogBox *YNdialogBox = 0;
85 static puFrame *YNdialogFrame = 0;
86 static puText *YNdialogBoxMessage = 0;
87 static puOneShot *YNdialogBoxOkButton = 0;
88 static puOneShot *YNdialogBoxNoButton = 0;
90 static char msg_OK[] = "OK";
91 static char msg_NO[] = "NO";
92 static char msg_YES[] = "YES";
93 static char msg_CANCEL[] = "Cancel";
94 static char msg_RESET[] = "Reset";
96 char *gui_msg_OK; // "OK"
97 char *gui_msg_NO; // "NO"
98 char *gui_msg_YES; // "YES"
99 char *gui_msg_CANCEL; // "CANCEL"
100 char *gui_msg_RESET; // "RESET"
102 static char global_dialog_string[256];
104 extern void NewAltitude( puObject *cb );
105 extern void NewHeading( puObject *cb );
106 extern void fgAPAdjust( puObject * );
107 extern void fgLatLonFormatToggle( puObject *);
109 /* --------------------------------------------------------------------
111 ---------------------------------------------------------------------*/
115 static int last_buttons = 0 ;
116 static int mouse_active = 0;
117 static int menu_on = 0;
119 void guiMotionFunc ( int x, int y )
124 glutPostRedisplay () ;
127 void guiMouseFunc(int button, int updown, int x, int y)
131 if ( updown == PU_DOWN )
132 last_buttons |= ( 1 << button ) ;
134 last_buttons &= ~( 1 << button ) ;
135 puMouse (button, updown, x,y);
136 glutPostRedisplay ();
139 int guiGetMouseButton(void)
144 void guiGetMouse(int *x, int *y)
150 static inline void TurnCursorOn( void )
153 #if defined ( WIN32 ) || defined(__CYGWIN32__)
154 glutSetCursor(GLUT_CURSOR_INHERIT);
156 #if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
157 glutWarpPointer( glutGet(GLUT_SCREEN_WIDTH)/2, glutGet(GLUT_SCREEN_HEIGHT)/2);
161 static inline void TurnCursorOff( void )
164 #if defined ( WIN32 ) || defined(__CYGWIN32__)
165 glutSetCursor(GLUT_CURSOR_NONE);
166 #else // I guess this is what we want to do ??
167 #if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
168 glutWarpPointer( glutGet(GLUT_SCREEN_WIDTH), glutGet(GLUT_SCREEN_HEIGHT));
173 void maybeToggleMouse( void )
176 static int first_time = ~0;
177 static int mouse_changed = 0;
181 mouse_changed = ~mouse_changed;
185 if( mouse_changed ) {
186 mouse_changed = ~mouse_changed;
192 first_time = ~first_time;
193 #endif // #ifdef WIN32
196 // Call with FALSE to init and TRUE to restore
197 void BusyCursor( int restore )
199 static int cursor = 0;
201 glutSetCursor(cursor);
203 cursor = glutGet( GLUT_WINDOW_CURSOR );
207 glutSetCursor( GLUT_CURSOR_WAIT );
210 /* ================ General Purpose Functions ================ */
212 // Intercept the Escape Key
213 void ConfirmExitDialog(void)
215 FG_PUSH_PUI_DIALOG( YNdialogBox );
218 // General Purpose Message Box
219 void mkDialog (const char *txt)
221 strncpy(global_dialog_string, txt, 256);
222 dialogBoxMessage->setLabel(global_dialog_string);
223 FG_PUSH_PUI_DIALOG( dialogBox );
226 // Repair any damage done to the Panel by other Gui Items
227 void guiFixPanel( void )
231 if ( current_options.get_panel_status() ) {
232 FGView *v = ¤t_view;
233 FGTime *t = FGTime::cur_time_params;
235 if( (toggle_pause = !t->getPause()) )
236 t->togglePauseMode();
238 // this seems to be the only way to do this :-(
239 // problem is the viewport has been mucked with
240 xglViewport(0, 0 , (GLint)(v->winWidth), (GLint)(v->winHeight) );
241 FGPanel::OurPanel->ReInit(0, 0, 1024, 768);
244 t->togglePauseMode();
248 // Toggle the Menu and Mouse display state
249 void guiToggleMenu(void)
252 // printf("Hiding Menu\n");
253 mainMenuBar->hide ();
256 #endif // #ifdef WIN32
258 // printf("Showing Menu\n");
259 mainMenuBar->reveal();
262 #endif // #ifdef WIN32
267 /* -----------------------------------------------------------------------
268 the Gui callback functions
269 ____________________________________________________________________*/
271 void reInit(puObject *cb)
274 fgReInitSubsystems();
278 // This is the accessor function
279 void guiTogglePanel(puObject *cb)
281 current_options.toggle_panel();
284 //void MenuHideMenuCb(puObject *cb)
285 void hideMenuCb (puObject *cb)
290 void goodBye(puObject *)
292 // FG_LOG( FG_INPUT, FG_ALERT,
293 // "Program exiting normally at user request." );
294 cout << "Program exiting normally at user request." << endl;
303 void goAwayCb (puObject *me)
305 FG_POP_PUI_DIALOG( dialogBox );
308 void mkDialogInit (void)
310 // printf("mkDialogInit\n");
311 int x = (current_options.get_xsize()/2 - 400/2);
312 int y = (current_options.get_ysize()/2 - 100/2);
313 dialogBox = new puDialogBox (x, y); // 150, 50
315 dialogFrame = new puFrame (0,0,400,100);
316 dialogBoxMessage = new puText (10, 70);
317 dialogBoxMessage -> setLabel ("");
318 dialogBoxOkButton = new puOneShot (180, 10, 240, 50);
319 dialogBoxOkButton -> setLegend (gui_msg_OK);
320 dialogBoxOkButton -> makeReturnDefault (TRUE );
321 dialogBoxOkButton -> setCallback (goAwayCb);
323 FG_FINALIZE_PUI_DIALOG( dialogBox );
326 void MayBeGoodBye(puObject *)
331 void goAwayYesNoCb(puObject *me)
333 FG_POP_PUI_DIALOG( YNdialogBox);
336 void ConfirmExitDialogInit(void)
338 char msg[] = "Really Quit";
341 // printf("ConfirmExitDialogInit\n");
342 int len = 200 - puGetStringWidth( puGetDefaultLabelFont(), msg )/2;
344 int x = (current_options.get_xsize()/2 - 400/2);
345 int y = (current_options.get_ysize()/2 - 100/2);
347 YNdialogBox = new puDialogBox (x, y); // 150, 50
348 // YNdialogBox = new puDialogBox (150, 50);
350 YNdialogFrame = new puFrame (0,0,400, 100);
352 YNdialogBoxMessage = new puText (len, 70);
353 YNdialogBoxMessage -> setDefaultValue (msg);
354 YNdialogBoxMessage -> getDefaultValue (&s);
355 YNdialogBoxMessage -> setLabel (s);
357 YNdialogBoxOkButton = new puOneShot (100, 10, 160, 50);
358 YNdialogBoxOkButton -> setLegend (gui_msg_OK);
359 YNdialogBoxOkButton -> setCallback (goodBye);
361 YNdialogBoxNoButton = new puOneShot (240, 10, 300, 50);
362 YNdialogBoxNoButton -> setLegend (gui_msg_NO);
363 // YNdialogBoxNoButton -> makeReturnDefault (TRUE );
364 YNdialogBoxNoButton -> setCallback (goAwayYesNoCb);
366 FG_FINALIZE_PUI_DIALOG( YNdialogBox );
369 void notCb (puObject *)
371 mkDialog ("This function isn't implemented yet");
374 void helpCb (puObject *)
378 #if defined(FX) && !defined(WIN32)
379 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
380 if ( global_fullscreen ) {
381 global_fullscreen = false;
382 XMesaSetFXmode( XMESA_FX_WINDOW );
388 string url = "http://www.flightgear.org/Docs/InstallGuide/getstart.html";
390 if ( system("xwininfo -name Netscape > /dev/null 2>&1") == 0 ) {
391 command = "netscape -remote \"openURL(" + url + ")\" &";
393 command = "netscape " + url + " &";
396 command = "webrun.bat";
399 system( command.c_str() );
400 //string text = "Help started in netscape window.";
402 //mkDialog (text.c_str());
403 mkDialog ("Help started in netscape window.");
406 /// The beginnings of teleportation :-)
407 // Needs cleaning up but works
408 // These statics should disapear when this is a class
409 static puDialogBox *AptDialog = 0;
410 static puFrame *AptDialogFrame = 0;
411 static puText *AptDialogMessage = 0;
412 static puInput *AptDialogInput = 0;
414 static char NewAirportId[16];
415 static char NewAirportLabel[] = "Enter New Airport ID";
417 static puOneShot *AptDialogOkButton = 0;
418 static puOneShot *AptDialogCancelButton = 0;
419 static puOneShot *AptDialogResetButton = 0;
421 void AptDialog_Cancel(puObject *)
423 FG_POP_PUI_DIALOG( AptDialog );
426 void AptDialog_OK (puObject *)
430 FGTime *t = FGTime::cur_time_params;
431 int PauseMode = t->getPause();
433 t->togglePauseMode();
436 AptDialogInput->getValue(&s);
439 AptDialog_Cancel( NULL );
441 if ( AptId.length() ) {
442 // set initial position from airport id
446 FG_LOG( FG_GENERAL, FG_INFO,
447 "Attempting to set starting position from airport code "
450 airports.load("apt_simple");
451 if ( airports.search( AptId, &a ) )
453 current_options.set_airport_id( AptId.c_str() );
455 fgReInitSubsystems();
458 AptId += " not in database.";
459 mkDialog(AptId.c_str());
462 if( PauseMode != t->getPause() )
463 t->togglePauseMode();
466 void AptDialog_Reset(puObject *)
468 // strncpy( NewAirportId, current_options.get_airport_id().c_str(), 16 );
469 sprintf( NewAirportId, "%s", current_options.get_airport_id().c_str() );
470 AptDialogInput->setValue ( NewAirportId );
471 AptDialogInput->setCursor( 0 ) ;
474 void NewAirport(puObject *cb)
476 // strncpy( NewAirportId, current_options.get_airport_id().c_str(), 16 );
477 sprintf( NewAirportId, "%s", current_options.get_airport_id().c_str() );
478 AptDialogInput->setValue( NewAirportId );
480 FG_PUSH_PUI_DIALOG( AptDialog );
483 static void NewAirportInit(void)
485 sprintf( NewAirportId, "%s", current_options.get_airport_id().c_str() );
486 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
487 NewAirportLabel ) / 2;
489 AptDialog = new puDialogBox (150, 50);
491 AptDialogFrame = new puFrame (0,0,350, 150);
492 AptDialogMessage = new puText (len, 110);
493 AptDialogMessage -> setLabel (NewAirportLabel);
495 AptDialogInput = new puInput (50, 70, 300, 100);
496 AptDialogInput -> setValue (NewAirportId);
497 AptDialogInput -> acceptInput();
499 AptDialogOkButton = new puOneShot (50, 10, 110, 50);
500 AptDialogOkButton -> setLegend (gui_msg_OK);
501 AptDialogOkButton -> setCallback (AptDialog_OK);
502 AptDialogOkButton -> makeReturnDefault(TRUE);
504 AptDialogCancelButton = new puOneShot (140, 10, 210, 50);
505 AptDialogCancelButton -> setLegend (gui_msg_CANCEL);
506 AptDialogCancelButton -> setCallback (AptDialog_Cancel);
508 AptDialogResetButton = new puOneShot (240, 10, 300, 50);
509 AptDialogResetButton -> setLegend (gui_msg_RESET);
510 AptDialogResetButton -> setCallback (AptDialog_Reset);
512 FG_FINALIZE_PUI_DIALOG( AptDialog );
515 /// The beginnings of networking :-)
516 // Needs cleaning up but works
517 // These statics should disapear when this is a class
518 static puDialogBox *NetIdDialog = 0;
519 static puFrame *NetIdDialogFrame = 0;
520 static puText *NetIdDialogMessage = 0;
521 static puInput *NetIdDialogInput = 0;
523 static char NewNetId[16];
524 static char NewNetIdLabel[] = "Enter New Callsign";
526 static puOneShot *NetIdDialogOkButton = 0;
527 static puOneShot *NetIdDialogCancelButton = 0;
529 void NetIdDialog_Cancel(puObject *)
531 FG_POP_PUI_DIALOG( NetIdDialog );
534 void NetIdDialog_OK (puObject *)
538 FGTime *t = FGTime::cur_time_params;
539 int PauseMode = t->getPause();
541 t->togglePauseMode();
543 The following needs some cleanup because
544 "string options.NetId" and "char *net_callsign"
546 NetIdDialogInput->getValue(&net_callsign);
547 NetId = net_callsign;
549 NetIdDialog_Cancel( NULL );
550 current_options.set_net_id( NetId.c_str() );
551 /* Entering a callsign indicates : user wants Net HUD Info */
554 if( PauseMode != t->getPause() )
555 t->togglePauseMode();
558 void NewCallSign(puObject *cb)
560 sprintf( NewNetId, "%s", current_options.get_net_id().c_str() );
561 NetIdDialogInput->setValue( NewNetId );
563 FG_PUSH_PUI_DIALOG( NetIdDialog );
566 static void NewNetIdInit(void)
568 sprintf( NewNetId, "%s", current_options.get_net_id().c_str() );
569 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
572 NetIdDialog = new puDialogBox (150, 50);
574 NetIdDialogFrame = new puFrame (0,0,350, 150);
575 NetIdDialogMessage = new puText (len, 110);
576 NetIdDialogMessage -> setLabel (NewNetIdLabel);
578 NetIdDialogInput = new puInput (50, 70, 300, 100);
579 NetIdDialogInput -> setValue (NewNetId);
580 NetIdDialogInput -> acceptInput();
582 NetIdDialogOkButton = new puOneShot (50, 10, 110, 50);
583 NetIdDialogOkButton -> setLegend (gui_msg_OK);
584 NetIdDialogOkButton -> setCallback (NetIdDialog_OK);
585 NetIdDialogOkButton -> makeReturnDefault(TRUE);
587 NetIdDialogCancelButton = new puOneShot (240, 10, 300, 50);
588 NetIdDialogCancelButton -> setLegend (gui_msg_CANCEL);
589 NetIdDialogCancelButton -> setCallback (NetIdDialog_Cancel);
592 FG_FINALIZE_PUI_DIALOG( NetIdDialog );
595 static void net_display_toggle( puObject *cb)
597 net_hud_display = (net_hud_display) ? 0 : 1;
598 printf("Toggle net_hud_display : %d\n", net_hud_display);
601 static void net_blaster_toggle( puObject *cb)
603 net_blast_toggle = (net_blast_toggle) ? 0 : -1;
604 printf("Toggle net_blast : %d\n", net_blast_toggle);
607 /*************** End Networking **************/
611 /* -----------------------------------------------------------------------
613 ---------------------------------------------------------------------*/
614 char *fileSubmenu [] = {
615 "Exit", "Close", "---------", "Print", "---------", "Save", "Reset", NULL
617 puCallback fileSubmenuCb [] = {
618 MayBeGoodBye, hideMenuCb, NULL, notCb, NULL, notCb, reInit, NULL
621 char *editSubmenu [] = {
624 puCallback editSubmenuCb [] = {
628 char *viewSubmenu [] = {
629 "Cockpit View > ", "View >","------------", "Toggle Panel...", NULL
631 puCallback viewSubmenuCb [] = {
632 notCb, notCb, NULL, guiTogglePanel, NULL
635 char *aircraftSubmenu [] = {
636 "Autopilot", "Heading", "Altitude", "Navigation", "Communication", NULL
638 puCallback aircraftSubmenuCb [] = {
639 fgAPAdjust, NewHeading, NewAltitude, fgLatLonFormatToggle, notCb, NULL
642 char *environmentSubmenu [] = {
643 "Airport", "Terrain", "Weather", NULL
645 puCallback environmentSubmenuCb [] = {
646 NewAirport, notCb, notCb, NULL
649 char *optionsSubmenu [] = {
650 "Preferences", "Realism & Reliablity...", NULL
652 puCallback optionsSubmenuCb [] = {
656 #ifdef FG_NETWORK_OLK
657 char *networkSubmenu [] = {
658 "Unregister from FGD ", "Send MSG to All", "Send MSG", "Show Pilots", "Register to FGD",
659 "Scan for Deamons", "Enter Callsign", "Display Netinfos", "Toggle Display",
662 puCallback networkSubmenuCb [] = {
663 notCb, notCb, notCb, notCb, notCb, notCb, NewCallSign, notCb,
664 net_display_toggle, net_blaster_toggle, NULL
668 char *helpSubmenu [] = {
669 "About...", "Help", NULL
671 puCallback helpSubmenuCb [] = {
676 /* -------------------------------------------------------------------------
678 _____________________________________________________________________*/
683 char *mesa_win_state;
687 puSetDefaultStyle ( PUSTYLE_SMALL_BEVELLED ); //PUSTYLE_DEFAULT
688 puSetDefaultColourScheme (0.8, 0.8, 0.8, 0.4);
690 // Initialize our GLOBAL GUI STRINGS
691 gui_msg_OK = msg_OK; // "OK"
692 gui_msg_NO = msg_NO; // "NO"
693 gui_msg_YES = msg_YES; // "YES"
694 gui_msg_CANCEL = msg_CANCEL; // "CANCEL"
695 gui_msg_RESET = msg_RESET; // "RESET"
697 // Next check home directory
699 char* envp = ::getenv( "FG_FONTS" );
700 if ( envp != NULL ) {
703 fntpath.set( current_options.get_fg_root() );
704 fntpath.append( "Fonts" );
707 // Install our fast fonts
708 fntpath.append( "typewriter.txf" );
709 guiFntHandle = new fntTexFont ;
710 guiFntHandle -> load ( (char *)fntpath.c_str() ) ;
711 puFont GuiFont ( guiFntHandle, 15 ) ;
712 puSetDefaultFonts( GuiFont, GuiFont ) ;
713 guiFnt = puGetDefaultLabelFont();
715 if ( current_options.get_mouse_pointer() == 0 ) {
716 // no preference specified for mouse pointer, attempt to autodetect...
717 // Determine if we need to render the cursor, or if the windowing
718 // system will do it. First test if we are rendering with glide.
719 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
720 // Test for the MESA_GLX_FX env variable
721 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
722 // test if we are fullscreen mesa/glide
723 if ( (mesa_win_state[0] == 'f') ||
724 (mesa_win_state[0] == 'F') ) {
729 mouse_active = ~mouse_active;
730 } else if ( current_options.get_mouse_pointer() == 1 ) {
731 // don't show pointer
732 } else if ( current_options.get_mouse_pointer() == 2 ) {
733 // force showing pointer
735 mouse_active = ~mouse_active;
738 // Set up our Dialog Boxes
739 ConfirmExitDialogInit();
741 #ifdef FG_NETWORK_OLK
747 mainMenuBar = new puMenuBar ();
748 mainMenuBar -> add_submenu ("File", fileSubmenu, fileSubmenuCb);
749 mainMenuBar -> add_submenu ("Edit", editSubmenu, editSubmenuCb);
750 mainMenuBar -> add_submenu ("View", viewSubmenu, viewSubmenuCb);
751 mainMenuBar -> add_submenu ("Aircraft", aircraftSubmenu, aircraftSubmenuCb);
752 mainMenuBar -> add_submenu ("Environment", environmentSubmenu, environmentSubmenuCb);
753 mainMenuBar -> add_submenu ("Options", optionsSubmenu, optionsSubmenuCb);
754 #ifdef FG_NETWORK_OLK
755 mainMenuBar -> add_submenu ("Network", networkSubmenu, networkSubmenuCb);
757 mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
758 mainMenuBar-> close ();
759 // Set up menu bar toggle