]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/keyboard.cxx
Fixed a problem with autodetecting if we need to draw our own mouse cursor
[flightgear.git] / src / Main / keyboard.cxx
index f76b50f3ca9eaa2f839e7d96f4ce822701d365cc..faf28ecdef80d1ccafca55f9b38c935ef4977d31 100644 (file)
 #include <Autopilot/auto_gui.hxx>
 #include <Autopilot/newauto.hxx>
 #include <Cockpit/hud.hxx>
+#include <Cockpit/panel.hxx>
+#include <Cockpit/panel_io.hxx>
 #include <GUI/gui.h>
 #include <Scenery/tilemgr.hxx>
-#include <Objects/materialmgr.hxx>
-#include <Time/fg_time.hxx>
+#include <Objects/matlib.hxx>
 #include <Time/light.hxx>
+#include <Time/tmp.hxx>
 
 #ifndef FG_OLD_WEATHER
 #  include <WeatherCM/FGLocalWeatherDatabase.h>
 #endif
 
 #include "bfi.hxx"
+#include "globals.hxx"
 #include "keyboard.hxx"
+#include "fg_props.hxx"
 #include "options.hxx"
-#include "save.hxx"
-#include "views.hxx"
-
-
-// Force an update of the sky and lighting parameters
-static void local_update_sky_and_lighting_params( void ) {
-    FGTime::cur_time_params->updateLocal();
-    cur_light_params.Update();
-}
+                               // From main.cxx
+extern void fgReshape( int width, int height );
 
 
 // Handle keyboard events
 void GLUTkey(unsigned char k, int x, int y) {
-    FGInterface *f;
-    FGTime *t;
-    FGView *v;
     float fov, tmp;
     static bool winding_ccw = true;
     int speed;
 
-    f = current_aircraft.fdm_state;
-    t = FGTime::cur_time_params;
-    v = &current_view;
+    FGInterface *f = current_aircraft.fdm_state;
+    FGViewer *v = globals->get_current_view();
 
     FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
     if ( puKeyboard(k, PU_DOWN) ) {
@@ -115,8 +108,8 @@ void GLUTkey(unsigned char k, int x, int y) {
                );
            return;
        case 8: // Ctrl-H key
-           current_autopilot->set_HeadingMode( 
-                  FGAutopilot::FG_HEADING_LOCK );
+           current_autopilot->set_HeadingMode(
+                 FGAutopilot::FG_DG_HEADING_LOCK );
            current_autopilot->set_HeadingEnabled(
                  ! current_autopilot->get_HeadingEnabled()
                );
@@ -154,7 +147,7 @@ void GLUTkey(unsigned char k, int x, int y) {
            // unflipping yourself :-)
            {
                double alt = cur_fdm_state->get_Altitude() + 1000;
-               fgFDMForceAltitude( current_options.get_flight_model(), 
+               fgFDMForceAltitude( fgGetString("/sim/flight-model"), 
                                    alt * FEET_TO_METER );
            }
            return;
@@ -183,16 +176,14 @@ void GLUTkey(unsigned char k, int x, int y) {
            v->set_goal_view_offset( FG_PI * 1.75 );
            return;
        case 65: // A key
-           speed = current_options.get_speed_up();
+           speed = fgGetInt("/sim/speed-up");
            speed--;
            if ( speed < 1 ) {
                speed = 1;
            }
-           current_options.set_speed_up( speed );
+           fgSetInt("/sim/speed-up", speed);
            return;
        case 72: // H key
-           // status = current_options.get_hud_status();
-           // current_options.set_hud_status(!status);
            HUD_brightkey( true );
            return;
        case 73: // I key
@@ -200,15 +191,20 @@ void GLUTkey(unsigned char k, int x, int y) {
            fgHUDInit2(&current_aircraft);
            return;
        case 77: // M key
-           t->adjust_warp(-60);
-           local_update_sky_and_lighting_params();
+           globals->inc_warp( -60 );
+           fgUpdateSkyAndLightingParams();
            return;
        case 80: // P key
-           current_options.toggle_panel();
+           if (fgGetBool("/sim/panel/visibility"))
+             fgSetBool("/sim/panel/visibility", false);
+           else
+             fgSetBool("/sim/panel/visibility", true);
+           fgReshape(fgGetInt("/sim/startup/xsize"),
+                     fgGetInt("/sim/startup/ysize"));
            break;
        case 84: // T key
-           t->adjust_warp_delta(-30);
-           local_update_sky_and_lighting_params();
+           globals->inc_warp_delta( -30 );
+           fgUpdateSkyAndLightingParams();
            return;
        case 87: // W key
 #if defined(FX) && !defined(WIN32)
@@ -220,13 +216,13 @@ void GLUTkey(unsigned char k, int x, int y) {
 #endif
            return;
        case 88: // X key
-           fov = current_options.get_fov();
+           fov = globals->get_current_view()->get_fov();
            fov *= 1.05;
            if ( fov > FG_FOV_MAX ) {
                fov = FG_FOV_MAX;
            }
-           current_options.set_fov(fov);
-           v->force_update_fov_math();
+           globals->get_current_view()->set_fov(fov);
+           // v->force_update_fov_math();
            return;
        case 90: // Z key
 #ifndef FG_OLD_WEATHER
@@ -313,9 +309,9 @@ void GLUTkey(unsigned char k, int x, int y) {
                    "Set flaps to " << controls.get_flaps() );
            return;
        case 97: // a key
-           speed = current_options.get_speed_up();
+           speed = fgGetInt("/sim/speed-up");
            speed++;
-           current_options.set_speed_up( speed );
+           fgSetInt("/sim/speed-up", speed);
            return;
        case 98: // b key
            int b_ret;
@@ -324,6 +320,20 @@ void GLUTkey(unsigned char k, int x, int y) {
            b_set = double(!b_ret);
            controls.set_brake( FGControls::ALL_WHEELS, b_set);
            return;
+       case 44: // , key
+           if (controls.get_brake(0) > 0.0) {
+               controls.set_brake(0, 0.0);
+           } else {
+               controls.set_brake(0, 1.0);
+           }
+           return;
+       case 46: // . key
+           if (controls.get_brake(1) > 0.0) {
+               controls.set_brake(1, 0.0);
+           } else {
+               controls.set_brake(1, 1.0);
+           }
+           return;
        case 104: // h key
            HUD_masterswitch( true );
            return;
@@ -331,16 +341,16 @@ void GLUTkey(unsigned char k, int x, int y) {
            fgHUDInit(&current_aircraft);  // normal HUD
            return;
        case 109: // m key
-           t->adjust_warp (+60);
-           local_update_sky_and_lighting_params();
+           globals->inc_warp( 60 );
+           fgUpdateSkyAndLightingParams();
            return;
        case 112: // p key
-           t->togglePauseMode();
+           globals->set_freeze( ! globals->get_freeze() );
 
            {
-               FGBucket p( f->get_Longitude() * RAD_TO_DEG,
+               SGBucket p( f->get_Longitude() * RAD_TO_DEG,
                            f->get_Latitude() * RAD_TO_DEG );
-               FGPath tile_path( current_options.get_fg_root() );
+               FGPath tile_path( globals->get_fg_root() );
                tile_path.append( "Scenery" );
                tile_path.append( p.gen_base_path() );
                tile_path.append( p.gen_index_str() );
@@ -359,20 +369,24 @@ void GLUTkey(unsigned char k, int x, int y) {
            }
            return;
        case 116: // t key
-           t->adjust_warp_delta (+30);
-           local_update_sky_and_lighting_params();
+           globals->inc_warp_delta( 30 );
+           fgUpdateSkyAndLightingParams();
            return;
        case 118: // v key
-           current_options.cycle_view_mode();
+           // handles GUI state as well as Viewer LookAt Direction
+           CenterView();
+           globals->set_current_view( globals->get_viewmgr()->next_view() );
+           fgReshape( fgGetInt("/sim/startup/xsize"),
+                      fgGetInt("/sim/startup/ysize") );
            return;
        case 120: // x key
-           fov = current_options.get_fov();
+           fov = globals->get_current_view()->get_fov();
            fov /= 1.05;
            if ( fov < FG_FOV_MIN ) {
                fov = FG_FOV_MIN;
            }
-           current_options.set_fov(fov);
-           v->force_update_fov_math();
+           globals->get_current_view()->set_fov(fov);
+           // v->force_update_fov_math();
            return;
        case 122: // z key
 #ifndef FG_OLD_WEATHER
@@ -390,7 +404,7 @@ void GLUTkey(unsigned char k, int x, int y) {
            //   fclose( fg_DebugOutput );
            // }
            FG_LOG( FG_INPUT, FG_ALERT, 
-                   "Program exiting normally at user request." );
+                   "Program exit requested." );
            ConfirmExitDialog();
            return;
        }
@@ -400,9 +414,7 @@ void GLUTkey(unsigned char k, int x, int y) {
 
 // Handle "special" keyboard events
 void GLUTspecialkey(int k, int x, int y) {
-    FGView *v;
-
-    v = &current_view;
+    FGViewer *v = globals->get_current_view();
 
     FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
 
@@ -425,7 +437,9 @@ void GLUTspecialkey(int k, int x, int y) {
        }
        case GLUT_KEY_F2: {
            FG_LOG(FG_INPUT, FG_INFO, "Saving flight");
+           cerr << "Opening output stream" << endl;
            ofstream output("fgfs.sav");
+           cerr << "output stream opened" << endl;
            if (output.good() && fgSaveFlight(output)) {
                output.close();
                FG_LOG(FG_INPUT, FG_INFO, "Saved flight to fgfs.sav");
@@ -434,6 +448,54 @@ void GLUTspecialkey(int k, int x, int y) {
            }
            return;
        }
+       case GLUT_KEY_F3: {
+         string panel_path =
+           fgGetString("/sim/panel/path", "Panels/Default/default.xml");
+         FGPanel * new_panel = fgReadPanel(panel_path);
+         if (new_panel == 0) {
+           FG_LOG(FG_INPUT, FG_ALERT,
+                  "Error reading new panel from " << panel_path);
+           return;
+         }
+         FG_LOG(FG_INPUT, FG_INFO, "Loaded new panel from " << panel_path);
+         current_panel->unbind();
+         delete current_panel;
+         current_panel = new_panel;
+         return;
+       }
+       case GLUT_KEY_F4: {
+         FGPath props_path(globals->get_fg_root());
+         props_path.append("preferences.xml");
+         FG_LOG(FG_INPUT, FG_INFO, "Rereading global preferences");
+         if (!readProperties(props_path.str(), globals->get_props())) {
+           FG_LOG(FG_INPUT, FG_ALERT,
+                  "Failed to reread global preferences from "
+                  << props_path.str());
+         } else {
+           FG_LOG(FG_INPUT, FG_INFO, "Finished Reading global preferences");
+         }
+         return;
+       }
+       case GLUT_KEY_F5: {
+         current_panel->setYOffset(current_panel->getYOffset() - 5);
+         fgReshape(fgGetInt("/sim/startup/xsize"),
+                   fgGetInt("/sim/startup/ysize"));
+         return;
+       }
+       case GLUT_KEY_F6: {
+         current_panel->setYOffset(current_panel->getYOffset() + 5);
+         fgReshape(fgGetInt("/sim/startup/xsize"),
+                   fgGetInt("/sim/startup/ysize"));
+         return;
+       }
+       case GLUT_KEY_F7: {
+         current_panel->setXOffset(current_panel->getXOffset() - 5);
+         return;
+       }
+       case GLUT_KEY_F8: {
+         current_panel->setXOffset(current_panel->getXOffset() + 5);
+         return;
+       }
        case GLUT_KEY_END: // numeric keypad 1
            v->set_goal_view_offset( FG_PI * 0.75 );
            return;
@@ -464,69 +526,68 @@ void GLUTspecialkey(int k, int x, int y) {
        switch (k) {
        case GLUT_KEY_F2: // F2 Reload Tile Cache...
            {
-               int toggle_pause;
+               bool freeze = globals->get_freeze();
                FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
-               FGTime *t = FGTime::cur_time_params;
-               if( (toggle_pause = !t->getPause()) )
-                   t->togglePauseMode();
+               if ( !freeze ) 
+                   globals->set_freeze( true );
                BusyCursor(0);
-               if( global_tile_mgr.init() ) {
+               if ( global_tile_mgr.init() ) {
                    // Load the local scenery data
-                   global_tile_mgr.update();
+                   global_tile_mgr.update( 
+                       cur_fdm_state->get_Longitude() * RAD_TO_DEG,
+                       cur_fdm_state->get_Latitude() * RAD_TO_DEG );
                } else {
                    FG_LOG( FG_GENERAL, FG_ALERT, 
                            "Error in Tile Manager initialization!" );
                    exit(-1);
                }
                BusyCursor(1);
-               if(toggle_pause)
-                   t->togglePauseMode();
+               if ( !freeze )
+                  globals->set_freeze( false );
                return;
            }
        case GLUT_KEY_F3: // F3 Take a screen shot
            fgDumpSnapShot();
            return;
+        case GLUT_KEY_F4: // F4 Update lighting manually
+           fgUpdateSkyAndLightingParams();
         case GLUT_KEY_F6: // F6 toggles Autopilot target location
            if ( current_autopilot->get_HeadingMode() !=
                 FGAutopilot::FG_HEADING_WAYPOINT ) {
                current_autopilot->set_HeadingMode(
                    FGAutopilot::FG_HEADING_WAYPOINT );
+               current_autopilot->set_HeadingEnabled( true );
            } else {
                current_autopilot->set_HeadingMode(
-                   FGAutopilot::FG_HEADING_LOCK );
+                   FGAutopilot::FG_DG_HEADING_LOCK );
            }
            return;
-       case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
-           current_options.cycle_fog();
-       
-           if ( current_options.get_fog() == fgOPTIONS::FG_FOG_DISABLED ) {
-               FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
-           } else if ( current_options.get_fog() == 
-                       fgOPTIONS::FG_FOG_FASTEST )
-           {
-               FG_LOG( FG_INPUT, FG_INFO, 
-                       "Fog enabled, hint set to fastest" );
-           } else if ( current_options.get_fog() ==
-                       fgOPTIONS::FG_FOG_NICEST )
-           {
-               FG_LOG( FG_INPUT, FG_INFO,
-                       "Fog enabled, hint set to nicest" );
+       case GLUT_KEY_F8: {// F8 toggles fog ... off fastest nicest...
+           const string &fog = fgGetString("/sim/rendering/fog");
+           if (fog == "disabled") {
+             fgSetString("/sim/rendering/fog", "fastest");
+             FG_LOG(FG_INPUT, FG_INFO, "Fog enabled, hint=fastest");
+           } else if (fog == "fastest") {
+             fgSetString("/sim/rendering/fog", "nicest");
+             FG_LOG(FG_INPUT, FG_INFO, "Fog enabled, hint=nicest");
+           } else if (fog == "nicest") {
+             fgSetString("/sim/rendering/fog", "disabled");
+             FG_LOG(FG_INPUT, FG_INFO, "Fog disabled");
+           } else {
+             fgSetString("/sim/rendering/fog", "disabled");
+             FG_LOG(FG_INPUT, FG_ALERT, "Unrecognized fog type "
+                    << fog << ", changed to 'disabled'");
            }
-
            return;
+       }
        case GLUT_KEY_F9: // F9 toggles textures on and off...
-           if ( material_mgr.loaded() ) {
-               if (current_options.get_textures()) {
-                   current_options.set_textures(false);
-                   material_mgr.set_step(1);
-               } else {
-                   current_options.set_textures(true);
-                   material_mgr.set_step(0);
-               }
-               FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
+           FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
+           if ( fgGetBool("/sim/rendering/textures")) {
+               fgSetBool("/sim/rendering/textures", false);
+               material_lib.set_step( 1 );
            } else {
-               FG_LOG( FG_INPUT, FG_INFO, 
-                       "No textures loaded, cannot toggle" );
+               fgSetBool("/sim/rendering/textures", true);
+               material_lib.set_step( 0 );
            }
            return;
        case GLUT_KEY_F10: // F10 toggles menu on and off...