]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/gui.cxx
Close all iochannel connections on exit.
[flightgear.git] / src / GUI / gui.cxx
index d183e766cdb882ce3fd62314c69723edee649aed..8fd6545d378b57f13a2789e4ed95260659702f05 100644 (file)
@@ -28,7 +28,7 @@
 #  include <config.h>
 #endif
 
-#include <Include/compiler.h>
+#include <simgear/compiler.h>
 
 #ifdef FG_MATH_EXCEPTION_CLASH
 #  include <math.h>
 #endif
 
 #include <GL/glut.h>
-#include <XGL/xgl.h>
+#include <simgear/xgl/xgl.h>
 
 #if defined(FX) && defined(XMESA)
 #  include <GL/xmesa.h>
 #endif
 
+#include STL_FSTREAM
 #include STL_STRING
 
 #include <stdlib.h>
 #include <string.h>
 
+#include <simgear/constants.h>
+#include <simgear/debug/logstream.hxx>
+#include <simgear/misc/fgpath.hxx>
+#include <simgear/screen/screen-dump.hxx>
+
 #include <Include/general.hxx>
-#include <Include/fg_constants.h>
-#include <Debug/logstream.hxx>
 #include <Aircraft/aircraft.hxx>
 #include <Airports/simple.hxx>
+#include <Autopilot/auto_gui.hxx>
+#include <Autopilot/newauto.hxx>
 #include <Cockpit/panel.hxx>
 #include <Controls/controls.hxx>
 #include <FDM/flight.hxx>
-#include <Main/options.hxx>
+#include <Main/bfi.hxx>
 #include <Main/fg_init.hxx>
+#include <Main/fg_io.hxx>
+#include <Main/globals.hxx>
+#include <Main/options.hxx>
 #include <Main/views.hxx>
-#include <Misc/fgpath.hxx>
+#include <Main/save.hxx>
 #ifdef FG_NETWORK_OLK
 #include <NetworkOLK/network.h>
 #endif
-#include <Screen/screen-dump.hxx>
-#include <Time/fg_time.hxx>
 
 #if defined( WIN32 ) && !defined( __CYGWIN__ )
-#  include <Screen/win32-printer.h>
-#  include <Screen/GlBitmaps.h>
+#  include <simgear/screen/win32-printer.h>
+#  include <simgear/screen/GlBitmaps.h>
 #endif
 
 /*
@@ -168,15 +175,15 @@ char *gui_msg_RESET;  // "RESET"
 static char global_dialog_string[256];
 
 // from autopilot.cxx
-extern void NewAltitude( puObject *cb );
-extern void NewHeading( puObject *cb );
-extern void fgAPAdjust( puObject * );
-extern void NewTgtAirport( puObject *cb );
-bool fgAPTerrainFollowEnabled( void );
-bool fgAPAltitudeEnabled( void );
-bool fgAPHeadingEnabled( void );
-bool fgAPWayPointEnabled( void );
-bool fgAPAutoThrottleEnabled( void );
+// extern void NewAltitude( puObject *cb );
+// extern void NewHeading( puObject *cb );
+// extern void fgAPAdjust( puObject * );
+// extern void NewTgtAirport( puObject *cb );
+// bool fgAPTerrainFollowEnabled( void );
+// bool fgAPAltitudeEnabled( void );
+// bool fgAPHeadingEnabled( void );
+// bool fgAPWayPointEnabled( void );
+// bool fgAPAutoThrottleEnabled( void );
 
 // from cockpit.cxx
 extern void fgLatLonFormatToggle( puObject *);
@@ -363,14 +370,6 @@ void guiMotionFunc ( int x, int y )
     int ww, wh, need_warp = 0;
     float W, H;
     double offset;
-//  FGTime *t = FGTime::cur_time_params;
-//  if( mouse_timed_out ) {
-//      if( t->get_cur_time() > mouse_off_time ) {
-//          moused_timed_out = 0;
-//          TurnCursorOn();
-//          glutPostRedisplay () ;
-//      }
-//  }
 
     if (mouse_mode == MOUSE_POINTER) {
         puMouse ( x, y ) ;
@@ -397,20 +396,20 @@ void guiMotionFunc ( int x, int y )
                         offset = (_mY - y) * throttle_sensitivity;
                         controls.move_throttle(FGControls::ALL_ENGINES, offset);
                     } else if ( right_button() ) {
-                        if( !fgAPHeadingEnabled() ) {
+                        if( ! current_autopilot->get_HeadingEnabled() ) {
                             offset = (x - _mX) * rudder_sensitivity;
                             controls.move_rudder(offset);
                         }
-                        if( !fgAPAltitudeEnabled() ) {
+                        if( ! current_autopilot->get_AltitudeEnabled() ) {
                             offset = (_mY - y) * trim_sensitivity;
                             controls.move_elevator_trim(offset);
                         }
                     } else {
-                        if( !fgAPHeadingEnabled() ) {
+                        if( ! current_autopilot->get_HeadingEnabled() ) {
                             offset = (x - _mX) * aileron_sensitivity;
                             controls.move_aileron(offset);
                         }
-                        if( !fgAPAltitudeEnabled() ) {
+                        if( ! current_autopilot->get_AltitudeEnabled() ) {
                             offset = (_mY - y) * elevator_sensitivity;
                             controls.move_elevator(offset);
                         }
@@ -640,7 +639,9 @@ void guiMouseFunc(int button, int updown, int x, int y)
     // If we're in pointer mode, let PUI
     // know what's going on.
     if (mouse_mode == MOUSE_POINTER) {
-        puMouse (button, updown, x,y);
+      if (!puMouse (button, updown, x,y)) {
+       current_panel->doMouseAction(button, updown, x, y);
+      }
     }
     
     // Register the new position (if it
@@ -667,28 +668,6 @@ void mkDialog (const char *txt)
     FG_PUSH_PUI_DIALOG( dialogBox );
 }
 
-// Repair any damage done to the Panel by other Gui Items
-void guiFixPanel( void )
-{
-    int toggle_pause;
-
-    if ( current_options.get_panel_status() ) {
-        FGView *v = &current_view;
-        FGTime *t = FGTime::cur_time_params;
-
-        if( (toggle_pause = !t->getPause()) )
-            t->togglePauseMode();
-
-        // this seems to be the only way to do this :-(
-        // problem is the viewport has been mucked with
-        xglViewport(0, 0 , (GLint)(v->winWidth), (GLint)(v->winHeight) );
-        FGPanel::OurPanel->ReInit(0, 0, 1024, 768);
-
-        if(toggle_pause)
-            t->togglePauseMode();
-    }
-}
-
 // Toggle the Menu and Mouse display state
 void guiToggleMenu(void)
 {
@@ -713,6 +692,36 @@ void guiToggleMenu(void)
 the Gui callback functions 
 ____________________________________________________________________*/
 
+static void saveFlight(puObject *cv)
+{
+    BusyCursor(0);
+    ofstream output("fgfs.sav");
+    if (output.good() && fgSaveFlight(output)) {
+      output.close();
+      mkDialog("Saved flight to ./fgfs.sav");
+      FG_LOG(FG_INPUT, FG_INFO, "Saved flight to fgfs.sav");
+    } else {
+      mkDialog("Cannot save flight to ./fgfs.sav");
+      FG_LOG(FG_INPUT, FG_ALERT, "Cannot save flight to fgfs.sav");
+    }
+    BusyCursor(1);
+}
+
+static void loadFlight(puObject *cb)
+{
+    BusyCursor(0);
+    ifstream input("fgfs.sav");
+    if (input.good() && fgLoadFlight(input)) {
+      input.close();
+      mkDialog("Loaded flight from fgfs.sav");
+      FG_LOG(FG_INPUT, FG_INFO, "Restored flight from ./fgfs.sav");
+    } else {
+      mkDialog("Failed to load flight from fgfs.sav");
+      FG_LOG(FG_INPUT, FG_ALERT, "Cannot load flight from ./fgfs.sav");
+    }
+    BusyCursor(1);
+}
+
 void reInit(puObject *cb)
 {
     BusyCursor(0);
@@ -721,6 +730,11 @@ void reInit(puObject *cb)
     fgReInitSubsystems();
     BusyCursor(1);
 }
+
+static void toggleClouds(puObject *cb)
+{
+    FGBFI::setClouds( !FGBFI::getClouds() );
+}
        
 // This is the accessor function
 void guiTogglePanel(puObject *cb)
@@ -741,13 +755,15 @@ void goodBye(puObject *)
     cout << "Program exiting normally at user request." << endl;
 
 #ifdef FG_NETWORK_OLK    
-    if ( net_is_registered == 0 ) fgd_send_com( "8", FGFS_host);
+    if ( current_options.get_network_olk() ) {
+       if ( net_is_registered == 0 ) fgd_send_com( "8", FGFS_host);
+    }
 #endif
 
-    //  if(gps_bug)
-    //      fclose(gps_bug);
+    // close all external I/O connections
+    fgIOShutdownAll();
 
-    exit(-1);
+    exit(0);
 }
 
 
@@ -807,11 +823,11 @@ void ConfirmExitDialogInit(void)
         
         YNdialogBoxOkButton =  new puOneShot      (100, 10, 160, 50);
         YNdialogBoxOkButton -> setLegend          (gui_msg_OK);
+        YNdialogBoxOkButton -> makeReturnDefault  (TRUE );
         YNdialogBoxOkButton -> setCallback        (goodBye);
         
         YNdialogBoxNoButton =  new puOneShot      (240, 10, 300, 50);
         YNdialogBoxNoButton -> setLegend          (gui_msg_NO);
-        //      YNdialogBoxNoButton -> makeReturnDefault  (TRUE );
         YNdialogBoxNoButton -> setCallback        (goAwayYesNoCb);
     }
     FG_FINALIZE_PUI_DIALOG( YNdialogBox );
@@ -861,7 +877,7 @@ static void rotateView( double roll, double pitch, double yaw )
        // rotate view
 }
 
-static GLBitmap *b1 = NULL;
+static GlBitmap *b1 = NULL;
 extern FGInterface cur_view_fdm;
 GLubyte *hiResScreenCapture( int multiplier )
 {
@@ -937,6 +953,10 @@ void dumpSnapShot ( puObject *obj ) {
 void fgDumpSnapShot () {
     bool show_pu_cursor = false;
 
+    int freeze = globals->get_freeze();
+    if(!freeze)
+        globals->set_freeze( true );
+
     mainMenuBar->hide();
     TurnCursorOff();
     if ( !puCursorIsHidden() ) {
@@ -945,7 +965,7 @@ void fgDumpSnapShot () {
     }
 
     fgInitVisuals();
-    fgReshape( current_options.get_xsize(), current_options.get_ysize() );
+    fgReshape( current_view.get_winWidth(), current_view.get_winHeight() );
 
     // we need two render frames here to clear the menu and cursor
     // ... not sure why but doing an extra fgFenderFrame() shoulnd't
@@ -968,6 +988,8 @@ void fgDumpSnapShot () {
        mainMenuBar->reveal();
     }
 
+    if(!freeze)
+        globals->set_freeze( false );
 }
 
 
@@ -993,13 +1015,16 @@ void AptDialog_Cancel(puObject *)
 
 void AptDialog_OK (puObject *)
 {
-       fgAIRPORTS airports;
-       fgAIRPORT a;
+    FGPath path( current_options.get_fg_root() );
+    path.append( "Airports" );
+    path.append( "simple.mk4" );
+    FGAirports airports( path.c_str() );
+
+    FGAirport a;
     
-    FGTime *t = FGTime::cur_time_params;
-    int PauseMode = t->getPause();
-    if(!PauseMode)
-        t->togglePauseMode();
+    int freeze = globals->get_freeze();
+    if(!freeze)
+        globals->set_freeze( true );
 
     char *s;
     AptDialogInput->getValue(&s);
@@ -1015,10 +1040,13 @@ void AptDialog_OK (puObject *)
                 "Attempting to set starting position from airport code "
                 << AptId );
 
-        airports.load("apt_simple");
         if ( airports.search( AptId, &a ) )
         {
             current_options.set_airport_id( AptId.c_str() );
+            current_options.set_altitude( -9999.0 );
+           // fgSetPosFromAirportID( AptId );
+           fgSetPosFromAirportIDandHdg( AptId, 
+                                        cur_fdm_state->get_Psi() * RAD_TO_DEG);
             BusyCursor(0);
             fgReInitSubsystems();
             BusyCursor(1);
@@ -1027,8 +1055,8 @@ void AptDialog_OK (puObject *)
             mkDialog(AptId.c_str());
         }
     }
-    if( PauseMode != t->getPause() )
-        t->togglePauseMode();
+    if(!freeze)
+        globals->set_freeze( false );
 }
 
 void AptDialog_Reset(puObject *)
@@ -1108,10 +1136,9 @@ void NetIdDialog_OK (puObject *)
 {
     string NetId;
     
-    FGTime *t = FGTime::cur_time_params;
-    int PauseMode = t->getPause();
-    if(!PauseMode)
-        t->togglePauseMode();
+    bool freeze = globals->get_freeze();
+    if(!freeze)
+        globals->set_freeze( true );
 /*  
    The following needs some cleanup because 
    "string options.NetId" and "char *net_callsign" 
@@ -1126,8 +1153,8 @@ void NetIdDialog_OK (puObject *)
 /* Entering a callsign indicates : user wants Net HUD Info */
     net_hud_display = 1;
 
-    if( PauseMode != t->getPause() )
-        t->togglePauseMode();
+    if(!freeze)
+        globals->set_freeze( false );
 }
 
 void NewCallSign(puObject *cb)
@@ -1227,16 +1254,16 @@ void NetFGDDialog_OK (puObject *)
 {
     char *NetFGD;    
 
-    FGTime *t = FGTime::cur_time_params;
-    int PauseMode = t->getPause();
-    if(!PauseMode) t->togglePauseMode();
+    bool freeze = globals->get_freeze();
+    if(!freeze)
+        globals->set_freeze( true );
     NetFGDHostDialogInput->getValue( &NetFGD );
     strcpy( fgd_host, NetFGD);
     NetFGDPortLoDialogInput->getValue( (int *) &base_port );
     NetFGDPortHiDialogInput->getValue( (int *) &end_port );
     NetFGDDialog_Cancel( NULL );
-    if( PauseMode != t->getPause() )
-        t->togglePauseMode();
+    if(!freeze)
+        globals->set_freeze( false );
 }
 
 void NetFGDDialog_SCAN (puObject *)
@@ -1244,9 +1271,9 @@ void NetFGDDialog_SCAN (puObject *)
     char *NetFGD;
     int fgd_port;
     
-    FGTime *t = FGTime::cur_time_params;
-    int PauseMode = t->getPause();
-    if(!PauseMode) t->togglePauseMode();
+    bool freeze = globals->get_freeze();
+    if(!freeze)
+        globals->set_freeze( true );
 //    printf("Vor getvalue %s\n");
     NetFGDHostDialogInput->getValue( &NetFGD );
 //    printf("Vor strcpy %s\n", (char *) NetFGD);
@@ -1257,7 +1284,8 @@ void NetFGDDialog_SCAN (puObject *)
                  base_port, end_port);
     net_resolv_fgd(fgd_host);
     printf("Resolve : %d\n", net_r);
-    if( PauseMode != t->getPause() )  t->togglePauseMode();
+    if(!freeze)
+        globals->set_freeze( false );
     if ( net_r == 0 ) {
       fgd_port = 10000;
       strcpy( fgd_name, "");
@@ -1358,8 +1386,11 @@ char *fileSubmenu               [] = {
     "Print",
 #endif
     "Snap Shot",
-    /* "---------", "Save", */ 
-    "Reset", NULL
+    "---------", 
+    "Reset", 
+    "Load flight",
+    "Save flight",
+    NULL
 };
 puCallback fileSubmenuCb        [] = {
     MayBeGoodBye, /* hideMenuCb, NULL, */
@@ -1368,7 +1399,11 @@ puCallback fileSubmenuCb        [] = {
 #endif
     /* NULL, notCb, */
     dumpSnapShot,
-    reInit, NULL
+    NULL,
+    reInit, 
+    loadFlight,
+    saveFlight,
+    NULL
 };
 
 /*
@@ -1380,11 +1415,16 @@ puCallback editSubmenuCb        [] = {
 };
 */
 
+extern void fgHUDalphaAdjust( puObject * );
 char *viewSubmenu               [] = {
-    /* "Cockpit View > ", "View >","------------", */ "Toggle Panel...", NULL
+    "HUD Alpha",
+    /* "Cockpit View > ", "View >","------------", */
+    "Toggle Panel...", NULL
 };
 puCallback viewSubmenuCb        [] = {
-    /* notCb, notCb, NULL, guiTogglePanel, */ NULL
+    fgHUDalphaAdjust,
+    /* notCb, notCb, NULL, */
+    guiTogglePanel, NULL
 };
 
 char *aircraftSubmenu           [] = {
@@ -1397,9 +1437,11 @@ puCallback aircraftSubmenuCb    [] = {
 };
 
 char *environmentSubmenu        [] = {
-    "Airport", /* "Terrain", "Weather", */ NULL
+    "Toggle Clouds",
+    "Goto Airport", /* "Terrain", "Weather", */ NULL
 };
 puCallback environmentSubmenuCb [] = {
+    toggleClouds,
     NewAirport, /* notCb, notCb, */ NULL
 };
 
@@ -1521,7 +1563,9 @@ void guiInit()
     mainMenuBar -> add_submenu ("Environment", environmentSubmenu, environmentSubmenuCb);
     // mainMenuBar -> add_submenu ("Options", optionsSubmenu, optionsSubmenuCb);
 #ifdef FG_NETWORK_OLK
-    mainMenuBar -> add_submenu ("Network", networkSubmenu, networkSubmenuCb);
+    if ( current_options.get_network_olk() ) {
+       mainMenuBar -> add_submenu ("Network", networkSubmenu, networkSubmenuCb);
+    }
 #endif
     mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
     mainMenuBar-> close ();