]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/keyboard.cxx
One more pass at a reorg.
[flightgear.git] / src / Main / keyboard.cxx
index 58b72be812caaf6f7c3b70433e6413cdd34774b3..dcf0a7057691bdce2bfc814e10f6613c87bbaee3 100644 (file)
@@ -1,8 +1,8 @@
-// GLUTkey.cxx -- handle GLUT keyboard events
+// keyboard.cxx -- handle GLUT keyboard events
 //
 // Written by Curtis Olson, started May 1997.
 //
-// Copyright (C) 1997  Curtis L. Olson  - curt@me.umn.edu
+// Copyright (C) 1997 - 1999  Curtis L. Olson  - curt@flightgear.org
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
@@ -30,7 +30,7 @@
 #endif
 
 #include <GL/glut.h>
-#include <XGL/xgl.h>
+#include <simgear/xgl/xgl.h>
 
 #if defined(FX) && defined(XMESA)
 #include <GL/xmesa.h>
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <Debug/logstream.hxx>
+#include <plib/pu.h>           // plib include
+
+#include <simgear/constants.h>
+#include <simgear/debug/logstream.hxx>
+#include <simgear/misc/fgpath.hxx>
+
 #include <Aircraft/aircraft.hxx>
 #include <Astro/solarsystem.hxx>
 #include <Astro/sky.hxx>
 #include <Autopilot/autopilot.hxx>
 #include <Cockpit/hud.hxx>
 #include <GUI/gui.h>
-#include <Include/fg_constants.h>
 #include <Scenery/tilemgr.hxx>
 #include <Objects/materialmgr.hxx>
-#include <plib/pu.h>
 #include <Time/fg_time.hxx>
 #include <Time/light.hxx>
-#include <Weather/weather.hxx>
 
-#include "GLUTkey.hxx"
+#ifndef FG_OLD_WEATHER
+#  include <WeatherCM/FGLocalWeatherDatabase.h>
+#else
+#  include <Weather/weather.hxx>
+#endif
+
+#include "keyboard.hxx"
 #include "options.hxx"
+#include "save.hxx"
 #include "views.hxx"
 
 extern void NewAltitude( puObject *cb );
@@ -75,14 +84,13 @@ void GLUTkey(unsigned char k, int x, int y) {
     FGInterface *f;
     FGTime *t;
     FGView *v;
-    FGWeather *w;
     float fov, tmp;
     static bool winding_ccw = true;
+    int speed;
 
     f = current_aircraft.fdm_state;
     t = FGTime::cur_time_params;
     v = &current_view;
-    w = &current_weather;
 
     FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
     if ( puKeyboard(k, PU_DOWN) ) {
@@ -113,6 +121,15 @@ void GLUTkey(unsigned char k, int x, int y) {
        case 20: // Ctrl-T key
            fgAPToggleTerrainFollow();
            return;
+       case 21: // Ctrl-U key
+           // add 1000' of emergency altitude.  Possibly good for 
+           // unflipping yourself :-)
+           {
+               double alt = cur_fdm_state->get_Altitude() + 1000;
+               fgFDMForceAltitude( current_options.get_flight_model(), 
+                                   alt * FEET_TO_METER );
+           }
+           return;
        case 49: // numeric keypad 1
            v->set_goal_view_offset( FG_PI * 0.75 );
            return;
@@ -137,6 +154,14 @@ void GLUTkey(unsigned char k, int x, int y) {
        case 57: // numeric keypad 9
            v->set_goal_view_offset( FG_PI * 1.75 );
            return;
+       case 65: // A key
+           speed = current_options.get_speed_up();
+           speed--;
+           if ( speed < 1 ) {
+               speed = 1;
+           }
+           current_options.set_speed_up( speed );
+           return;
        case 72: // H key
            // status = current_options.get_hud_status();
            // current_options.set_hud_status(!status);
@@ -176,9 +201,15 @@ void GLUTkey(unsigned char k, int x, int y) {
            v->force_update_fov_math();
            return;
        case 90: // Z key
-           tmp = w->get_visibility();   // in meters
+#ifndef FG_OLD_WEATHER
+           tmp = WeatherDatabase->getWeatherVisibility();
            tmp /= 1.10;
-           w->set_visibility( tmp );
+           WeatherDatabase->setWeatherVisibility( tmp );
+#else
+           tmp = current_weather.get_visibility();   // in meters
+           tmp /= 1.10;
+           current_weather.set_visibility( tmp );
+#endif
            return;
        }
     } else {
@@ -243,6 +274,21 @@ void GLUTkey(unsigned char k, int x, int y) {
                controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
            }
            return;
+       case 91: // [ key
+           controls.move_flaps(-0.34);
+           FG_LOG( FG_INPUT, FG_INFO,
+                   "Set flaps to " << controls.get_flaps() );
+           return;
+       case 93: // ] key
+           controls.move_flaps(0.34);
+           FG_LOG( FG_INPUT, FG_INFO,
+                   "Set flaps to " << controls.get_flaps() );
+           return;
+       case 97: // a key
+           speed = current_options.get_speed_up();
+           speed++;
+           current_options.set_speed_up( speed );
+           return;
        case 98: // b key
            int b_ret;
            double b_set;
@@ -262,21 +308,36 @@ void GLUTkey(unsigned char k, int x, int y) {
            return;
        case 112: // p key
            t->togglePauseMode();
-           // printf position and attitude information
-           FG_LOG( FG_INPUT, FG_INFO,
-                   "Lon = " << f->get_Longitude() * RAD_TO_DEG
-                   << "  Lat = " << f->get_Latitude() * RAD_TO_DEG
-                   << "  Altitude = " << f->get_Altitude() * FEET_TO_METER );
-           FG_LOG( FG_INPUT, FG_INFO,
-                   "Heading = " << f->get_Psi() * RAD_TO_DEG 
-                   << "  Roll = " << f->get_Phi() * RAD_TO_DEG
-                   << "  Pitch = " << f->get_Theta() * RAD_TO_DEG );
+
+           {
+               FGBucket p( f->get_Longitude() * RAD_TO_DEG,
+                           f->get_Latitude() * RAD_TO_DEG );
+               FGPath tile_path( current_options.get_fg_root() );
+               tile_path.append( "Scenery" );
+               tile_path.append( p.gen_base_path() );
+               tile_path.append( p.gen_index_str() );
+
+               // printf position and attitude information
+               FG_LOG( FG_INPUT, FG_INFO,
+                       "Lon = " << f->get_Longitude() * RAD_TO_DEG
+                       << "  Lat = " << f->get_Latitude() * RAD_TO_DEG
+                       << "  Altitude = " << f->get_Altitude() * FEET_TO_METER
+                       );
+               FG_LOG( FG_INPUT, FG_INFO,
+                       "Heading = " << f->get_Psi() * RAD_TO_DEG 
+                       << "  Roll = " << f->get_Phi() * RAD_TO_DEG
+                       << "  Pitch = " << f->get_Theta() * RAD_TO_DEG );
+               FG_LOG( FG_INPUT, FG_INFO, tile_path.c_str());
+           }
            return;
        case 116: // t key
            t->adjust_warp_delta (+30);
            local_update_sky_and_lighting_params();
            return;
-       case 120: // X key
+       case 118: // v key
+           current_options.cycle_view_mode();
+           return;
+       case 120: // x key
            fov = current_options.get_fov();
            fov /= 1.05;
            if ( fov < FG_FOV_MIN ) {
@@ -286,9 +347,15 @@ void GLUTkey(unsigned char k, int x, int y) {
            v->force_update_fov_math();
            return;
        case 122: // z key
-           tmp = w->get_visibility();   // in meters
+#ifndef FG_OLD_WEATHER
+           tmp = WeatherDatabase->getWeatherVisibility();
            tmp *= 1.10;
-           w->set_visibility( tmp );
+           WeatherDatabase->setWeatherVisibility( tmp );
+#else
+           tmp = current_weather.get_visibility();   // in meters
+           tmp *= 1.10;
+           current_weather.set_visibility( tmp );
+#endif
            return;
        case 27: // ESC
            // if( fg_DebugOutput ) {
@@ -318,6 +385,27 @@ void GLUTspecialkey(int k, int x, int y) {
     if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
        FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
        switch (k) {
+       case GLUT_KEY_F1: {
+           ifstream input("fgfs.sav");
+           if (input.good() && fgLoadFlight(input)) {
+               input.close();
+               FG_LOG(FG_INPUT, FG_INFO, "Restored flight from fgfs.sav");
+           } else {
+               FG_LOG(FG_INPUT, FG_ALERT, "Cannot load flight from fgfs.sav");
+           }
+           return;
+       }
+       case GLUT_KEY_F2: {
+           FG_LOG(FG_INPUT, FG_INFO, "Saving flight");
+           ofstream output("fgfs.sav");
+           if (output.good() && fgSaveFlight(output)) {
+               output.close();
+               FG_LOG(FG_INPUT, FG_INFO, "Saved flight to fgfs.sav");
+           } else {
+               FG_LOG(FG_INPUT, FG_ALERT, "Cannot save flight to fgfs.sav");
+           }
+           return;
+       }
        case GLUT_KEY_END: // numeric keypad 1
            v->set_goal_view_offset( FG_PI * 0.75 );
            return;
@@ -367,6 +455,12 @@ void GLUTspecialkey(int k, int x, int y) {
                    t->togglePauseMode();
                return;
            }
+       case GLUT_KEY_F3: // F3 Take a screen shot
+           fgDumpSnapShot();
+           return;
+        case GLUT_KEY_F6: // F6 toggles Autopilot target location
+           fgAPToggleWayPoint();
+           return;
        case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
            current_options.cycle_fog();
        
@@ -387,9 +481,13 @@ void GLUTspecialkey(int k, int x, int y) {
            return;
        case GLUT_KEY_F9: // F9 toggles textures on and off...
            if ( material_mgr.loaded() ) {
-               current_options.get_textures() ?
-                   current_options.set_textures(false) :
+               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" );
            } else {
                FG_LOG( FG_INPUT, FG_INFO,