]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/keyboard.cxx
Added a viewmgr system and made corresponding changes to support it.
[flightgear.git] / src / Main / keyboard.cxx
index dc52097a2a2cbef9cc746590b7875780760c1f7f..e28854cc8aacba9e4d46d8b0728b54f132ead8ce 100644 (file)
@@ -53,6 +53,8 @@
 #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/matlib.hxx>
 #include "bfi.hxx"
 #include "globals.hxx"
 #include "keyboard.hxx"
-#include "options.hxx"
 #include "save.hxx"
-#include "views.hxx"
+
+                               // From main.cxx
+extern void fgReshape( int width, int height );
 
 
 // Handle keyboard events
 void GLUTkey(unsigned char k, int x, int y) {
-    FGInterface *f;
-    SGTime *t;
-    FGView *v;
     float fov, tmp;
     static bool winding_ccw = true;
     int speed;
 
-    f = current_aircraft.fdm_state;
-    v = &current_view;
+    FGInterface *f = current_aircraft.fdm_state;
+    FGViewerRPH *v = (FGViewerRPH *)globals->get_current_view();
 
     FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
     if ( puKeyboard(k, PU_DOWN) ) {
@@ -147,45 +147,93 @@ 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( globals->get_options()->get_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 = current_options.get_speed_up();
+           speed = globals->get_options()->get_speed_up();
            speed--;
            if ( speed < 1 ) {
                speed = 1;
            }
-           current_options.set_speed_up( speed );
+           globals->get_options()->set_speed_up( speed );
            return;
        case 72: // H key
-           // status = current_options.get_hud_status();
-           // current_options.set_hud_status(!status);
+           // status = globals->get_options()->get_hud_status();
+           // globals->get_options()->set_hud_status(!status);
            HUD_brightkey( true );
            return;
        case 73: // I key
@@ -197,7 +245,7 @@ void GLUTkey(unsigned char k, int x, int y) {
            fgUpdateSkyAndLightingParams();
            return;
        case 80: // P key
-           current_options.toggle_panel();
+           globals->get_options()->toggle_panel();
            break;
        case 84: // T key
            globals->inc_warp_delta( -30 );
@@ -213,13 +261,13 @@ void GLUTkey(unsigned char k, int x, int y) {
 #endif
            return;
        case 88: // X key
-           fov = current_options.get_fov();
+           fov = globals->get_options()->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_options()->set_fov(fov);
+           // v->force_update_fov_math();
            return;
        case 90: // Z key
 #ifndef FG_OLD_WEATHER
@@ -306,9 +354,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 = globals->get_options()->get_speed_up();
            speed++;
-           current_options.set_speed_up( speed );
+           globals->get_options()->set_speed_up( speed );
            return;
        case 98: // b key
            int b_ret;
@@ -347,7 +395,7 @@ void GLUTkey(unsigned char k, int x, int y) {
            {
                FGBucket 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_options()->get_fg_root() );
                tile_path.append( "Scenery" );
                tile_path.append( p.gen_base_path() );
                tile_path.append( p.gen_index_str() );
@@ -370,16 +418,32 @@ void GLUTkey(unsigned char k, int x, int y) {
            fgUpdateSkyAndLightingParams();
            return;
        case 118: // v key
-           current_options.cycle_view_mode();
+//         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() );
            return;
        case 120: // x key
-           fov = current_options.get_fov();
+           fov = globals->get_options()->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_options()->set_fov(fov);
+           // v->force_update_fov_math();
            return;
        case 122: // z key
 #ifndef FG_OLD_WEATHER
@@ -397,7 +461,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;
        }
@@ -407,9 +471,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;
+    FGViewerRPH *v = (FGViewerRPH *)globals->get_current_view();
 
     FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
 
@@ -441,29 +503,125 @@ void GLUTspecialkey(int k, int x, int y) {
            }
            return;
        }
+       case GLUT_KEY_F3: {
+         string panel_path =
+           current_properties.getStringValue("/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);
+         delete current_panel;
+         current_panel = new_panel;
+         return;
+       }
+       case GLUT_KEY_F4: {
+         FGPath props_path(globals->get_options()->get_fg_root());
+         props_path.append("preferences.xml");
+         FG_LOG(FG_INPUT, FG_INFO, "Rereading global preferences");
+         if (!readPropertyList(props_path.str(), &current_properties)) {
+           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(globals->get_options()->get_xsize(),
+                   globals->get_options()->get_ysize());
+         return;
+       }
+       case GLUT_KEY_F6: {
+         current_panel->setYOffset(current_panel->getYOffset() + 5);
+         fgReshape(globals->get_options()->get_xsize(),
+                   globals->get_options()->get_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 );
+           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 {
@@ -499,23 +657,26 @@ void GLUTspecialkey(int k, int x, int y) {
                 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 );
            }
            return;
        case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
-           current_options.cycle_fog();
+           globals->get_options()->cycle_fog();
        
-           if ( current_options.get_fog() == fgOPTIONS::FG_FOG_DISABLED ) {
+           if ( globals->get_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 )
+           } 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 ( current_options.get_fog() ==
-                       fgOPTIONS::FG_FOG_NICEST )
+           } else if ( globals->get_options()->get_fog() ==
+                       FGOptions::FG_FOG_NICEST )
            {
                FG_LOG( FG_INPUT, FG_INFO,
                        "Fog enabled, hint set to nicest" );
@@ -524,11 +685,11 @@ void GLUTspecialkey(int k, int x, int y) {
            return;
        case GLUT_KEY_F9: // F9 toggles textures on and off...
            FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
-           if ( current_options.get_textures() ) {
-               current_options.set_textures( false );
+           if ( globals->get_options()->get_textures() ) {
+               globals->get_options()->set_textures( false );
                material_lib.set_step( 1 );
            } else {
-               current_options.set_textures( true );
+               globals->get_options()->set_textures( true );
                material_lib.set_step( 0 );
            }
            return;