Support arbitrary parameters to bindings.
Use this to supply window X/Y to hover bindings.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user