]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/input.cxx
Added static port system and a new altimeter model connected to it.
[flightgear.git] / src / Input / input.cxx
index 41edac95a8e8cdb515e2b6ea86960678781dcfc7..93cad1dbadd33cdc0675bbe208d27b01402ce390 100644 (file)
@@ -197,11 +197,9 @@ FGInput::init ()
   glutKeyboardUpFunc(GLUTkeyup);
   glutSpecialFunc(GLUTspecialkey);
   glutSpecialUpFunc(GLUTspecialkeyup);
-#ifndef FG_OLD_MOUSE
   glutMouseFunc (GLUTmouse);
   glutMotionFunc (GLUTmotion);
   glutPassiveMotionFunc (GLUTmotion);
-#endif
 }
 
 void
@@ -217,7 +215,7 @@ FGInput::unbind ()
 }
 
 void 
-FGInput::update (int dt)
+FGInput::update (double dt)
 {
   _update_keyboard();
   _update_joystick();
@@ -405,12 +403,12 @@ FGInput::doMouseMotion (int x, int y)
                                // so we can play with it.
   if (x != m.x) {
     int delta = x - m.x;
-    for (int i = 0; i < mode.x_bindings[modifiers].size(); i++)
+    for (unsigned int i = 0; i < mode.x_bindings[modifiers].size(); i++)
       mode.x_bindings[modifiers][i]->fire(double(delta), double(xsize));
   }
   if (y != m.y) {
     int delta = y - m.y;
-    for (int i = 0; i < mode.y_bindings[modifiers].size(); i++)
+    for (unsigned int i = 0; i < mode.y_bindings[modifiers].size(); i++)
       mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize));
   }
 
@@ -451,7 +449,7 @@ FGInput::_init_keyboard ()
     key_nodes = fgGetNode("/input/keyboard", true);
   }
   
-  vector<SGPropertyNode *> keys = key_nodes->getChildren("key");
+  vector<SGPropertyNode_ptr> keys = key_nodes->getChildren("key");
   for (unsigned int i = 0; i < keys.size(); i++) {
     int index = keys[i]->getIndex();
     SG_LOG(SG_INPUT, SG_DEBUG, "Binding key " << index);
@@ -473,7 +471,7 @@ FGInput::_init_joystick ()
   }
 
   for (int i = 0; i < MAX_JOYSTICKS; i++) {
-    SGPropertyNode * js_node = js_nodes->getChild("js", i);
+    SGPropertyNode_ptr js_node = js_nodes->getChild("js", i);
     if (js_node == 0) {
       SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for joystick " << i);
       js_node = js_nodes->getChild("js", i, true);
@@ -485,8 +483,27 @@ FGInput::_init_joystick ()
       continue;
     } else {
 #ifdef FG_PLIB_JOYSTICK_GETNAME
-      SG_LOG(SG_INPUT, SG_INFO, "");
-      SG_LOG(SG_INPUT, SG_INFO, "Found joystick " << js->getName());
+      bool found_js = false;
+      const char * name = js->getName();
+      SG_LOG(SG_INPUT, SG_INFO, "Looking for bindings for joystick \""
+            << name << '"');
+      vector<SGPropertyNode_ptr> nodes = js_nodes->getChildren("js-named");
+      for (unsigned int i = 0; i < nodes.size(); i++) {
+       SGPropertyNode_ptr node = nodes[i];
+        vector<SGPropertyNode_ptr> name_nodes = node->getChildren("name");
+        for (unsigned int j = 0; j < name_nodes.size(); j++) {
+            const char * js_name = name_nodes[j]->getStringValue();
+            SG_LOG(SG_INPUT, SG_INFO, "  Trying \"" << js_name << '"');
+            if (!strcmp(js_name, name)) {
+                SG_LOG(SG_INPUT, SG_INFO, "  Found bindings");
+                js_node = node;
+                found_js = true;
+                break;
+            }
+        }
+        if (found_js)
+            break;
+      }
 #endif
     }
 #ifdef WIN32
@@ -810,7 +827,7 @@ FGInput::_read_bindings (const SGPropertyNode * node,
                         int modifiers)
 {
   SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
-  vector<const SGPropertyNode *> bindings = node->getChildren("binding");
+  vector<SGPropertyNode_ptr> bindings = node->getChildren("binding");
   for (unsigned int i = 0; i < bindings.size(); i++) {
     SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding "
           << bindings[i]->getStringValue("command"));
@@ -959,10 +976,10 @@ FGInput::mouse_mode::~mouse_mode ()
 ////////////////////////////////////////////////////////////////////////
 
 FGInput::mouse::mouse ()
-  : nModes(1),
-    current_mode(0),
-    x(-1),
+  : x(-1),
     y(-1),
+    nModes(1),
+    current_mode(0),
     modes(0)
 {
 }