]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/input.cxx
Added a property output feature to ControlMap that allows arbitrary binding
[flightgear.git] / src / Input / input.cxx
index 51f0b7c8ba03eb1ae7465a1685cc764a14768bde..06122defdc0dd2380a1306ddd1e379d2740c3bca 100644 (file)
 #include <Cockpit/panel_io.hxx>
 #include <GUI/gui.h>
 
-#ifndef FG_OLD_WEATHER
-#  include <WeatherCM/FGLocalWeatherDatabase.h>
-#else
-#  include <Weather/weather.hxx>
-#endif
-
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
-#include <Main/options.hxx>
 
 #include "input.hxx"
 
@@ -92,16 +85,6 @@ FGBinding::FGBinding ()
 {
 }
 
-FGBinding::FGBinding (const FGBinding &binding)
-  : _command_name(binding._command_name),
-    _command(binding._command),
-    _arg(new SGPropertyNode),
-    _setting(0),
-    _command_state(0)
-{
-  copyProperties(binding._arg, _arg);
-}
-
 FGBinding::FGBinding (const SGPropertyNode * node)
   : _command(0),
     _arg(new SGPropertyNode),
@@ -113,13 +96,19 @@ FGBinding::FGBinding (const SGPropertyNode * node)
 
 FGBinding::~FGBinding ()
 {
-  delete _arg;                 // Delete the saved arguments
-  delete _command_state;       // Delete the saved command state
+//   delete _arg;                      // Delete the saved arguments
+//   delete _command_state;    // Delete the saved command state
 }
 
 void
 FGBinding::read (const SGPropertyNode * node)
 {
+  const SGPropertyNode * conditionNode = node->getChild("condition");
+  if (conditionNode != 0) {
+    cerr << "Adding condition to binding" << endl;
+    setCondition(fgReadCondition(conditionNode));
+  }
+
   _command_name = node->getStringValue("command", "");
   if (_command_name == "") {
     SG_LOG(SG_INPUT, SG_ALERT, "No command supplied for binding.");
@@ -143,22 +132,27 @@ FGBinding::read (const SGPropertyNode * node)
 void
 FGBinding::fire () const
 {
-  if (_command == 0) {
-    SG_LOG(SG_INPUT, SG_ALERT, "No command attached to binding");
-  } else if (!(*_command)(_arg, &_command_state)) {
-    SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command " << _command_name);
+  if (test()) {
+    if (_command == 0) {
+      SG_LOG(SG_INPUT, SG_ALERT, "No command attached to binding");
+    } else if (!(*_command)(_arg, &_command_state)) {
+      SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
+            << _command_name);
+    }
   }
 }
 
 void
 FGBinding::fire (double setting) const
 {
+  if (test()) {
                                // A value is automatically added to
                                // the args
-  if (_setting == 0)           // save the setting node for efficiency
-    _setting = _arg->getChild("setting", 0, true);
-  _setting->setDoubleValue(setting);
-  fire();
+    if (_setting == 0)         // save the setting node for efficiency
+      _setting = _arg->getChild("setting", 0, true);
+    _setting->setDoubleValue(setting);
+    fire();
+  }
 }
 
 
@@ -203,7 +197,7 @@ FGInput::unbind ()
 }
 
 void 
-FGInput::update ()
+FGInput::update (int dt)
 {
   _update_keyboard();
   _update_joystick();
@@ -212,8 +206,8 @@ FGInput::update ()
 void
 FGInput::doKey (int k, int modifiers, int x, int y)
 {
-  SG_LOG(SG_INPUT, SG_INFO, "User pressed key " << k
-        << " with modifiers " << modifiers);
+    // SG_LOG( SG_INPUT, SG_INFO, "User pressed key " << k
+    //                << " with modifiers " << modifiers );
 
                                // Sanity check.
   if (k < 0 || k >= MAX_KEYS) {
@@ -233,7 +227,7 @@ FGInput::doKey (int k, int modifiers, int x, int y)
       int max = bindings.size();
       if (max > 0) {
        for (int i = 0; i < max; i++)
-         bindings[i].fire();
+         bindings[i]->fire();
        return;
       }
     }
@@ -249,7 +243,7 @@ FGInput::doKey (int k, int modifiers, int x, int y)
       int max = bindings.size();
       if (max > 0) {
        for (int i = 0; i < max; i++)
-         bindings[i].fire();
+         bindings[i]->fire();
        return;
       }
     }
@@ -257,30 +251,15 @@ FGInput::doKey (int k, int modifiers, int x, int y)
 
 
                                // Use the old, default actions.
-  SG_LOG(SG_INPUT, SG_INFO, "(No user binding.)");
+  // SG_LOG( SG_INPUT, SG_INFO, "(No user binding.)" );
   if (modifiers&FG_MOD_UP)
     return;
 
-  // float fov, tmp;
-  static bool winding_ccw = true;
-  // int speed;
-  // FGInterface *f = current_aircraft.fdm_state;
-  // FGViewer *v = globals->get_current_view();
-  
   // everything after here will be removed sooner or later...
 
   if (modifiers & FG_MOD_SHIFT) {
 
        switch (k) {
-       case 18: // Ctrl-R key
-           // temporary
-           winding_ccw = !winding_ccw;
-           if ( winding_ccw ) {
-               glFrontFace ( GL_CCW );
-           } else {
-               glFrontFace ( GL_CW );
-           }
-           return;
        case 72: // H key
            HUD_brightkey( true );
            return;
@@ -288,25 +267,6 @@ FGInput::doKey (int k, int modifiers, int x, int y)
            // Minimal Hud
            fgHUDInit2(&current_aircraft);
            return;
-       case 87: // W key
-#if defined(FX) && !defined(WIN32)
-           global_fullscreen = ( !global_fullscreen );
-#  if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
-           XMesaSetFXmode( global_fullscreen ? 
-                           XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
-#  endif
-#endif
-           return;
-
-// START SPECIALS
-
-        case 256+GLUT_KEY_F10: {
-            fgToggleFDMdataLogging();
-            return;
-        }
-
-// END SPECIALS
-
        }
 
 
@@ -553,7 +513,7 @@ FGInput::_update_joystick ()
 //     SG_LOG(SG_INPUT, SG_INFO, "There are "
 //            << a.bindings[modifiers].size() << " bindings");
        for (unsigned int k = 0; k < a.bindings[modifiers].size(); k++)
-         a.bindings[modifiers][k].fire(axis_values[j]);
+         a.bindings[modifiers][k]->fire(axis_values[j]);
       }
      
                                // do we have to emulate axis buttons?
@@ -584,16 +544,16 @@ FGInput::_update_button (button &b, int modifiers, bool pressed)
   if (pressed) {
                                // The press event may be repeated.
     if (!b.last_state || b.is_repeatable) {
-      SG_LOG(SG_INPUT, SG_INFO, "Button has been pressed");
+      // SG_LOG( SG_INPUT, SG_INFO, "Button has been pressed" );
       for (unsigned int k = 0; k < b.bindings[modifiers].size(); k++)
-       b.bindings[modifiers][k].fire();
+       b.bindings[modifiers][k]->fire();
     }
   } else {
                                // The release event is never repeated.
     if (b.last_state) {
-      SG_LOG(SG_INPUT, SG_INFO, "Button has been released");
+      // SG_LOG( SG_INPUT, SG_INFO, "Button has been released" );
       for (unsigned int k = 0; k < b.bindings[modifiers|FG_MOD_UP].size(); k++)
-       b.bindings[modifiers|FG_MOD_UP][k].fire();
+       b.bindings[modifiers|FG_MOD_UP][k]->fire();
     }
   }
          
@@ -611,7 +571,7 @@ FGInput::_read_bindings (const SGPropertyNode * node,
   for (unsigned int i = 0; i < bindings.size(); i++) {
     SG_LOG(SG_INPUT, SG_INFO, "Reading binding "
           << bindings[i]->getStringValue("command"));
-    binding_list[modifiers].push_back(FGBinding(bindings[i]));
+    binding_list[modifiers].push_back(new FGBinding(bindings[i]));
   }
 
                                // Read nested bindings for modifiers
@@ -633,7 +593,7 @@ FGInput::_read_bindings (const SGPropertyNode * node,
 }
 
 
-const vector<FGBinding> &
+const vector<FGBinding *> &
 FGInput::_find_key_bindings (unsigned int k, int modifiers)
 {
   button &b = _key_bindings[k];
@@ -665,6 +625,70 @@ FGInput::_find_key_bindings (unsigned int k, int modifiers)
 }
 
 
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGInput::button.
+////////////////////////////////////////////////////////////////////////
+
+FGInput::button::button ()
+  : is_repeatable(false),
+    last_state(-1)
+{
+}
+
+FGInput::button::~button ()
+{
+                               // FIXME: memory leak
+//   for (int i = 0; i < FG_MOD_MAX; i++)
+//     for (int j = 0; i < bindings[i].size(); j++)
+//       delete bindings[i][j];
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGInput::axis.
+////////////////////////////////////////////////////////////////////////
+
+FGInput::axis::axis ()
+  : last_value(9999999),
+    tolerance(0.002),
+    low_threshold(-0.9),
+    high_threshold(0.9)
+{
+}
+
+FGInput::axis::~axis ()
+{
+//   for (int i = 0; i < FG_MOD_MAX; i++)
+//     for (int j = 0; i < bindings[i].size(); j++)
+//       delete bindings[i][j];
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGInput::joystick.
+////////////////////////////////////////////////////////////////////////
+
+FGInput::joystick::joystick ()
+{
+}
+
+FGInput::joystick::~joystick ()
+{
+//   delete js;
+//   delete[] axes;
+//   delete[] buttons;
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of GLUT callbacks.
+////////////////////////////////////////////////////////////////////////
+
+
 /**
  * Construct the modifiers.
  */