]> 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 e28854cc8aacba9e4d46d8b0728b54f132ead8ce..faf28ecdef80d1ccafca55f9b38c935ef4977d31 100644 (file)
@@ -70,8 +70,8 @@
 #include "bfi.hxx"
 #include "globals.hxx"
 #include "keyboard.hxx"
-#include "save.hxx"
-
+#include "fg_props.hxx"
+#include "options.hxx"
                                // From main.cxx
 extern void fgReshape( int width, int height );
 
@@ -83,7 +83,7 @@ void GLUTkey(unsigned char k, int x, int y) {
     int speed;
 
     FGInterface *f = current_aircraft.fdm_state;
-    FGViewerRPH *v = (FGViewerRPH *)globals->get_current_view();
+    FGViewer *v = globals->get_current_view();
 
     FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
     if ( puKeyboard(k, PU_DOWN) ) {
@@ -108,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()
                );
@@ -147,93 +147,43 @@ void GLUTkey(unsigned char k, int x, int y) {
            // unflipping yourself :-)
            {
                double alt = cur_fdm_state->get_Altitude() + 1000;
-               fgFDMForceAltitude( globals->get_options()->get_flight_model(), 
+               fgFDMForceAltitude( fgGetString("/sim/flight-model"), 
                                    alt * FEET_TO_METER );
            }
            return;
        case 49: // numeric keypad 1
            v->set_goal_view_offset( FG_PI * 0.75 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(-25.0, 25.0, 1.0);
-               v->set_view_offset( FG_PI * 0.75 );
-           }
            return;
        case 50: // numeric keypad 2
            v->set_goal_view_offset( FG_PI );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(-25.0, 0.0, 1.0);
-               v->set_view_offset( FG_PI );
-           }
            return;
        case 51: // numeric keypad 3
            v->set_goal_view_offset( FG_PI * 1.25 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(-25.0, -25.0, 1.0);
-               v->set_view_offset( FG_PI * 1.25 );
-           }
            return;
        case 52: // numeric keypad 4
            v->set_goal_view_offset( FG_PI * 0.50 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(0.0, 25.0, 1.0);
-               v->set_view_offset( FG_PI * 0.50 );
-           }
            return;
        case 54: // numeric keypad 6
            v->set_goal_view_offset( FG_PI * 1.50 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(0.0, -25.0, 1.0);
-               v->set_view_offset( FG_PI * 1.50 );
-           }
            return;
        case 55: // numeric keypad 7
            v->set_goal_view_offset( FG_PI * 0.25 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(25.0, 25.0, 1.0);
-               v->set_view_offset( FG_PI * 0.25 );
-           }
            return;
        case 56: // numeric keypad 8
            v->set_goal_view_offset( 0.00 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(25.0, 0.0, 1.0);
-               v->set_view_offset( 0.00 );
-           }
            return;
        case 57: // numeric keypad 9
            v->set_goal_view_offset( FG_PI * 1.75 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(25.0, -25.0, 1.0);
-               v->set_view_offset( FG_PI * 1.75 );
-           }
            return;
        case 65: // A key
-           speed = globals->get_options()->get_speed_up();
+           speed = fgGetInt("/sim/speed-up");
            speed--;
            if ( speed < 1 ) {
                speed = 1;
            }
-           globals->get_options()->set_speed_up( speed );
+           fgSetInt("/sim/speed-up", speed);
            return;
        case 72: // H key
-           // status = globals->get_options()->get_hud_status();
-           // globals->get_options()->set_hud_status(!status);
            HUD_brightkey( true );
            return;
        case 73: // I key
@@ -245,7 +195,12 @@ void GLUTkey(unsigned char k, int x, int y) {
            fgUpdateSkyAndLightingParams();
            return;
        case 80: // P key
-           globals->get_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
            globals->inc_warp_delta( -30 );
@@ -261,12 +216,12 @@ void GLUTkey(unsigned char k, int x, int y) {
 #endif
            return;
        case 88: // X key
-           fov = globals->get_options()->get_fov();
+           fov = globals->get_current_view()->get_fov();
            fov *= 1.05;
            if ( fov > FG_FOV_MAX ) {
                fov = FG_FOV_MAX;
            }
-           globals->get_options()->set_fov(fov);
+           globals->get_current_view()->set_fov(fov);
            // v->force_update_fov_math();
            return;
        case 90: // Z key
@@ -354,9 +309,9 @@ void GLUTkey(unsigned char k, int x, int y) {
                    "Set flaps to " << controls.get_flaps() );
            return;
        case 97: // a key
-           speed = globals->get_options()->get_speed_up();
+           speed = fgGetInt("/sim/speed-up");
            speed++;
-           globals->get_options()->set_speed_up( speed );
+           fgSetInt("/sim/speed-up", speed);
            return;
        case 98: // b key
            int b_ret;
@@ -393,9 +348,9 @@ void GLUTkey(unsigned char k, int x, int y) {
            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( globals->get_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() );
@@ -418,31 +373,19 @@ void GLUTkey(unsigned char k, int x, int y) {
            fgUpdateSkyAndLightingParams();
            return;
        case 118: // v key
-//         globals->get_options()->cycle_view_mode();
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_options()->set_view_mode(FGOptions::FG_VIEW_PILOT);
-               v->set_goal_view_offset( 0.0 );
-               v->set_view_offset( 0.0 );
-           } else if ( globals->get_options()->get_view_mode() ==
-                       FGOptions::FG_VIEW_PILOT )
-           {
-               globals->get_options()->set_view_mode( FGOptions::FG_VIEW_FOLLOW );
-               v->set_goal_view_offset( FG_PI * 1.75 );
-               v->set_view_offset( FG_PI * 1.75 );
-               globals->get_current_view()->set_pilot_offset(25.0, -25.0, 1.0);
-           }
-           fgReshape( globals->get_options()->get_xsize(),
-                      globals->get_options()->get_ysize() );
+           // 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 = globals->get_options()->get_fov();
+           fov = globals->get_current_view()->get_fov();
            fov /= 1.05;
            if ( fov < FG_FOV_MIN ) {
                fov = FG_FOV_MIN;
            }
-           globals->get_options()->set_fov(fov);
+           globals->get_current_view()->set_fov(fov);
            // v->force_update_fov_math();
            return;
        case 122: // z key
@@ -471,7 +414,7 @@ void GLUTkey(unsigned char k, int x, int y) {
 
 // Handle "special" keyboard events
 void GLUTspecialkey(int k, int x, int y) {
-    FGViewerRPH *v = (FGViewerRPH *)globals->get_current_view();
+    FGViewer *v = globals->get_current_view();
 
     FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
 
@@ -494,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");
@@ -505,8 +450,7 @@ void GLUTspecialkey(int k, int x, int y) {
        }
        case GLUT_KEY_F3: {
          string panel_path =
-           current_properties.getStringValue("/sim/panel/path",
-                                             "Panels/Default/default.xml");
+           fgGetString("/sim/panel/path", "Panels/Default/default.xml");
          FGPanel * new_panel = fgReadPanel(panel_path);
          if (new_panel == 0) {
            FG_LOG(FG_INPUT, FG_ALERT,
@@ -514,15 +458,16 @@ void GLUTspecialkey(int k, int x, int y) {
            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_options()->get_fg_root());
+         FGPath props_path(globals->get_fg_root());
          props_path.append("preferences.xml");
          FG_LOG(FG_INPUT, FG_INFO, "Rereading global preferences");
-         if (!readPropertyList(props_path.str(), &current_properties)) {
+         if (!readProperties(props_path.str(), globals->get_props())) {
            FG_LOG(FG_INPUT, FG_ALERT,
                   "Failed to reread global preferences from "
                   << props_path.str());
@@ -533,14 +478,14 @@ void GLUTspecialkey(int k, int x, int y) {
        }
        case GLUT_KEY_F5: {
          current_panel->setYOffset(current_panel->getYOffset() - 5);
-         fgReshape(globals->get_options()->get_xsize(),
-                   globals->get_options()->get_ysize());
+         fgReshape(fgGetInt("/sim/startup/xsize"),
+                   fgGetInt("/sim/startup/ysize"));
          return;
        }
        case GLUT_KEY_F6: {
          current_panel->setYOffset(current_panel->getYOffset() + 5);
-         fgReshape(globals->get_options()->get_xsize(),
-                   globals->get_options()->get_ysize());
+         fgReshape(fgGetInt("/sim/startup/xsize"),
+                   fgGetInt("/sim/startup/ysize"));
          return;
        }
        case GLUT_KEY_F7: {
@@ -553,75 +498,27 @@ void GLUTspecialkey(int k, int x, int y) {
        }
        case GLUT_KEY_END: // numeric keypad 1
            v->set_goal_view_offset( FG_PI * 0.75 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW)
-           {
-               globals->get_current_view()->set_pilot_offset(-25.0, 25.0, 1.0);
-               v->set_view_offset( FG_PI * 0.75 );
-           }
            return;
        case GLUT_KEY_DOWN: // numeric keypad 2
            v->set_goal_view_offset( FG_PI );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(-25.0, 0.0, 1.0);
-               v->set_view_offset( FG_PI );
-           }
            return;
        case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
            v->set_goal_view_offset( FG_PI * 1.25 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW)
-           {
-               globals->get_current_view()->set_pilot_offset(-25.0, -25.0, 1.0);
-               v->set_view_offset( FG_PI * 1.25 );
-           }
            return;
        case GLUT_KEY_LEFT: // numeric keypad 4
            v->set_goal_view_offset( FG_PI * 0.50 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(0.0, 25.0, 1.0);
-               v->set_view_offset( FG_PI * 0.50 );
-           }
            return;
        case GLUT_KEY_RIGHT: // numeric keypad 6
            v->set_goal_view_offset( FG_PI * 1.50 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(0.0, -25.0, 1.0);
-               v->set_view_offset( FG_PI * 1.50 );
-           }
            return;
        case GLUT_KEY_HOME: // numeric keypad 7
            v->set_goal_view_offset( FG_PI * 0.25 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(25.0, 25.0, 1.0);
-               v->set_view_offset( FG_PI * 0.25 );
-           }
            return;
        case GLUT_KEY_UP: // numeric keypad 8
            v->set_goal_view_offset( 0.00 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(25.0, 0.0, 1.0);
-               v->set_view_offset( 0.00 );
-           }
            return;
        case GLUT_KEY_PAGE_UP: // numeric keypad 9
            v->set_goal_view_offset( FG_PI * 1.75 );
-           if ( globals->get_options()->get_view_mode() ==
-                FGOptions::FG_VIEW_FOLLOW )
-           {
-               globals->get_current_view()->set_pilot_offset(25.0, -25.0, 1.0);
-               v->set_view_offset( FG_PI * 1.75 );
-           }
            return;
        }
     } else {
@@ -629,7 +526,7 @@ void GLUTspecialkey(int k, int x, int y) {
        switch (k) {
        case GLUT_KEY_F2: // F2 Reload Tile Cache...
            {
-               bool freeze;
+               bool freeze = globals->get_freeze();
                FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
                if ( !freeze ) 
                    globals->set_freeze( true );
@@ -652,6 +549,8 @@ void GLUTspecialkey(int k, int x, int y) {
        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 ) {
@@ -660,36 +559,34 @@ void GLUTspecialkey(int k, int x, int y) {
                current_autopilot->set_HeadingEnabled( true );
            } else {
                current_autopilot->set_HeadingMode(
-                   FGAutopilot::FG_HEADING_LOCK );
-           }
-           return;
-       case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
-           globals->get_options()->cycle_fog();
-       
-           if ( globals->get_options()->get_fog() ==
-                FGOptions::FG_FOG_DISABLED )
-           {
-               FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
-           } else if ( globals->get_options()->get_fog() == 
-                       FGOptions::FG_FOG_FASTEST )
-           {
-               FG_LOG( FG_INPUT, FG_INFO, 
-                       "Fog enabled, hint set to fastest" );
-           } else if ( globals->get_options()->get_fog() ==
-                       FGOptions::FG_FOG_NICEST )
-           {
-               FG_LOG( FG_INPUT, FG_INFO,
-                       "Fog enabled, hint set to nicest" );
+                   FGAutopilot::FG_DG_HEADING_LOCK );
+           }
+           return;
+       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...
            FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
-           if ( globals->get_options()->get_textures() ) {
-               globals->get_options()->set_textures( false );
+           if ( fgGetBool("/sim/rendering/textures")) {
+               fgSetBool("/sim/rendering/textures", false);
                material_lib.set_step( 1 );
            } else {
-               globals->get_options()->set_textures( true );
+               fgSetBool("/sim/rendering/textures", true);
                material_lib.set_step( 0 );
            }
            return;