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();
544 NetIdDialogInput->getValue(&s);
547 NetIdDialog_Cancel( NULL );
548 current_options.set_net_id( NetId.c_str() );
551 if( PauseMode != t->getPause() )
552 t->togglePauseMode();
555 void NewCallSign(puObject *cb)
557 sprintf( NewNetId, "%s", current_options.get_net_id().c_str() );
558 NetIdDialogInput->setValue( NewNetId );
560 FG_PUSH_PUI_DIALOG( NetIdDialog );
563 static void NewNetIdInit(void)
565 sprintf( NewNetId, "%s", current_options.get_net_id().c_str() );
566 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
569 NetIdDialog = new puDialogBox (150, 50);
571 NetIdDialogFrame = new puFrame (0,0,350, 150);
572 NetIdDialogMessage = new puText (len, 110);
573 NetIdDialogMessage -> setLabel (NewNetIdLabel);
575 NetIdDialogInput = new puInput (50, 70, 300, 100);
576 NetIdDialogInput -> setValue (NewNetId);
577 NetIdDialogInput -> acceptInput();
579 NetIdDialogOkButton = new puOneShot (50, 10, 110, 50);
580 NetIdDialogOkButton -> setLegend (gui_msg_OK);
581 NetIdDialogOkButton -> setCallback (NetIdDialog_OK);
582 NetIdDialogOkButton -> makeReturnDefault(TRUE);
584 NetIdDialogCancelButton = new puOneShot (240, 10, 300, 50);
585 NetIdDialogCancelButton -> setLegend (gui_msg_CANCEL);
586 NetIdDialogCancelButton -> setCallback (NetIdDialog_Cancel);
589 FG_FINALIZE_PUI_DIALOG( NetIdDialog );
592 static void net_display_toggle( puObject *cb)
594 net_hud_display = (net_hud_display) ? 0 : 1;
597 /*************** End Networking **************/
601 /* -----------------------------------------------------------------------
603 ---------------------------------------------------------------------*/
604 char *fileSubmenu [] = {
605 "Exit", "Close", "---------", "Print", "---------", "Save", "Reset", NULL
607 puCallback fileSubmenuCb [] = {
608 MayBeGoodBye, hideMenuCb, NULL, notCb, NULL, notCb, reInit, NULL
611 char *editSubmenu [] = {
614 puCallback editSubmenuCb [] = {
618 char *viewSubmenu [] = {
619 "Cockpit View > ", "View >","------------", "Toggle Panel...", NULL
621 puCallback viewSubmenuCb [] = {
622 notCb, notCb, NULL, guiTogglePanel, NULL
625 char *aircraftSubmenu [] = {
626 "Autopilot", "Heading", "Altitude", "Navigation", "Communication", NULL
628 puCallback aircraftSubmenuCb [] = {
629 fgAPAdjust, NewHeading, NewAltitude, fgLatLonFormatToggle, notCb, NULL
632 char *environmentSubmenu [] = {
633 "Airport", "Terrain", "Weather", NULL
635 puCallback environmentSubmenuCb [] = {
636 NewAirport, notCb, notCb, NULL
639 char *optionsSubmenu [] = {
640 "Preferences", "Realism & Reliablity...", NULL
642 puCallback optionsSubmenuCb [] = {
646 #ifdef FG_NETWORK_OLK
647 char *networkSubmenu [] = {
648 "Unregister from FGD ", "Send MSG to All", "Send MSG", "Show Pilots", "Register to FGD",
649 "Scan for Deamons", "Enter Callsign", "Display Netinfos", "Toggle Display", NULL
651 puCallback networkSubmenuCb [] = {
652 notCb, notCb, notCb, notCb, notCb, notCb, NewCallSign, notCb,
653 net_display_toggle, NULL
657 char *helpSubmenu [] = {
658 "About...", "Help", NULL
660 puCallback helpSubmenuCb [] = {
665 /* -------------------------------------------------------------------------
667 _____________________________________________________________________*/
672 char *mesa_win_state;
676 puSetDefaultStyle ( PUSTYLE_SMALL_BEVELLED ); //PUSTYLE_DEFAULT
677 puSetDefaultColourScheme (0.8, 0.8, 0.8, 0.4);
679 // Initialize our GLOBAL GUI STRINGS
680 gui_msg_OK = msg_OK; // "OK"
681 gui_msg_NO = msg_NO; // "NO"
682 gui_msg_YES = msg_YES; // "YES"
683 gui_msg_CANCEL = msg_CANCEL; // "CANCEL"
684 gui_msg_RESET = msg_RESET; // "RESET"
686 // Next check home directory
688 char* envp = ::getenv( "FG_FONTS" );
689 if ( envp != NULL ) {
692 fntpath.set( current_options.get_fg_root() );
693 fntpath.append( "Fonts" );
696 // Install our fast fonts
697 fntpath.append( "typewriter.txf" );
698 guiFntHandle = new fntTexFont ;
699 guiFntHandle -> load ( (char *)fntpath.c_str() ) ;
700 puFont GuiFont ( guiFntHandle, 15 ) ;
701 puSetDefaultFonts( GuiFont, GuiFont ) ;
702 guiFnt = puGetDefaultLabelFont();
704 if ( current_options.get_mouse_pointer() == 0 ) {
705 // no preference specified for mouse pointer, attempt to autodetect...
706 // Determine if we need to render the cursor, or if the windowing
707 // system will do it. First test if we are rendering with glide.
708 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
709 // Test for the MESA_GLX_FX env variable
710 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
711 // test if we are fullscreen mesa/glide
712 if ( (mesa_win_state[0] == 'f') ||
713 (mesa_win_state[0] == 'F') ) {
718 mouse_active = ~mouse_active;
719 } else if ( current_options.get_mouse_pointer() == 1 ) {
720 // don't show pointer
721 } else if ( current_options.get_mouse_pointer() == 2 ) {
722 // force showing pointer
724 mouse_active = ~mouse_active;
727 // Set up our Dialog Boxes
728 ConfirmExitDialogInit();
730 #ifdef FG_NETWORK_OLK
736 mainMenuBar = new puMenuBar ();
737 mainMenuBar -> add_submenu ("File", fileSubmenu, fileSubmenuCb);
738 mainMenuBar -> add_submenu ("Edit", editSubmenu, editSubmenuCb);
739 mainMenuBar -> add_submenu ("View", viewSubmenu, viewSubmenuCb);
740 mainMenuBar -> add_submenu ("Aircraft", aircraftSubmenu, aircraftSubmenuCb);
741 mainMenuBar -> add_submenu ("Environment", environmentSubmenu, environmentSubmenuCb);
742 mainMenuBar -> add_submenu ("Options", optionsSubmenu, optionsSubmenuCb);
743 #ifdef FG_NETWORK_OLK
744 mainMenuBar -> add_submenu ("Network", networkSubmenu, networkSubmenuCb);
746 mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
747 mainMenuBar-> close ();
748 // Set up menu bar toggle