]> git.mxchange.org Git - simgear.git/commitdiff
Support arbitrary parameters to bindings.
authorJames Turner <zakalawe@mac.com>
Sun, 10 Feb 2013 15:07:55 +0000 (15:07 +0000)
committerJames Turner <zakalawe@mac.com>
Sun, 10 Feb 2013 15:07:55 +0000 (15:07 +0000)
Use this to supply window X/Y to hover bindings.

simgear/scene/model/SGPickAnimation.cxx
simgear/structure/SGBinding.cxx
simgear/structure/SGBinding.hxx

index 34516539e9e178655f3499d2742ff05e2fa98c74..f5642c6fef8211c080ffc424b18a759c9f9ec091 100644 (file)
@@ -100,8 +100,10 @@ static void readOptionalBindingList(const SGPropertyNode* aNode, SGPropertyNode*
            return false;
        }
        
-       // FIXME - make x,y available to the binding 
-       fireBindingList(_hover);
+       SGPropertyNode_ptr params(new SGPropertyNode);
+       params->setDoubleValue("x", windowPos.x());
+       params->setDoubleValue("y", windowPos.y());
+       fireBindingList(_hover, params.ptr());
        return true;
    }
  private:
@@ -439,8 +441,10 @@ public:
             return false;
         }
        
-        // FIXME - make x,y available to the binding 
-        fireBindingList(_hover);
+        SGPropertyNode_ptr params(new SGPropertyNode);
+        params->setDoubleValue("x", windowPos.x());
+        params->setDoubleValue("y", windowPos.y());
+        fireBindingList(_hover, params.ptr());
         return true;
     }
 private:
index 43f55baf20b042beb23b8d054793c0a5a7ca0101..a96307cc9f6cced777102024674b1e665f947c3c 100644 (file)
@@ -15,6 +15,7 @@
 #include <simgear/compiler.h>
 #include "SGBinding.hxx"
 
+#include <simgear/props/props_io.hxx>
 #include <simgear/structure/exception.hxx>
 
 SGBinding::SGBinding()
@@ -64,25 +65,42 @@ SGBinding::read(const SGPropertyNode* node, SGPropertyNode* root)
 }
 
 void
-SGBinding::fire () const
+SGBinding::fire() const
 {
   if (test()) {
-    if (_command == 0)
-      _command = SGCommandMgr::instance()->getCommand(_command_name);
-    if (_command == 0) {
-      SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding");
-    } else
-    {
-        try {
-            if (!(*_command)(_arg)) {
-                  SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
-                         << _command_name);
-            }
-        } catch (sg_exception& e) {
-          SG_LOG(SG_GENERAL, SG_ALERT, "command '" << _command_name << "' failed with exception\n"
-            << "\tmessage:" << e.getMessage() << " (from " << e.getOrigin() << ")");
-        }
+    innerFire();
+  }
+}
+
+void
+SGBinding::innerFire () const
+{
+  if (_command == 0)
+    _command = SGCommandMgr::instance()->getCommand(_command_name);
+  if (_command == 0) {
+    SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding:" << _command_name);
+  } else {
+      try {
+          if (!(*_command)(_arg)) {
+                SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
+                       << _command_name);
+          }
+      } catch (sg_exception& e) {
+        SG_LOG(SG_GENERAL, SG_ALERT, "command '" << _command_name << "' failed with exception\n"
+          << "\tmessage:" << e.getMessage() << " (from " << e.getOrigin() << ")");
+      }
+  }
+}
+
+void
+SGBinding::fire (SGPropertyNode* params) const
+{
+  if (test()) {
+    if (params != NULL) {
+      copyProperties(params, _arg);
     }
+    
+    innerFire();
   }
 }
 
@@ -91,7 +109,7 @@ SGBinding::fire (double offset, double max) const
 {
   if (test()) {
     _arg->setDoubleValue("offset", offset/max);
-    fire();
+    innerFire();
   }
 }
 
@@ -104,14 +122,14 @@ SGBinding::fire (double setting) const
     if (_setting == 0)          // save the setting node for efficiency
       _setting = _arg->getChild("setting", 0, true);
     _setting->setDoubleValue(setting);
-    fire();
+    innerFire();
   }
 }
 
-void fireBindingList(const SGBindingList& aBindings)
+void fireBindingList(const SGBindingList& aBindings, SGPropertyNode* params)
 {
     BOOST_FOREACH(SGBinding_ptr b, aBindings) {
-        b->fire();
+        b->fire(params);
     }
 }
 
index eb12f3d235b3c8b6052d2451cce4110ad3572347..23e921c461d75989e9579b121c121b789d4dd6db 100644 (file)
@@ -114,8 +114,15 @@ public:
    */
   void fire (double setting) const;
 
-
+  /**
+   * Fire a binding with a number of additional parameters
+   * 
+   * The children of params will be merged with the fixed arguments.
+   */
+  void fire (SGPropertyNode* params) const;
+  
 private:
+  void innerFire() const;
                                 // just to be safe.
   SGBinding (const SGBinding &binding);
 
@@ -134,7 +141,7 @@ typedef std::map<unsigned,SGBindingList> SGBindingMap;
  * fire every binding in a list, in sequence
  
  */
-void fireBindingList(const SGBindingList& aBindings);
+void fireBindingList(const SGBindingList& aBindings, SGPropertyNode* params = NULL);
 
 /**
  * fire every binding in a list with a setting value