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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME - make x,y available to the binding
|
SGPropertyNode_ptr params(new SGPropertyNode);
|
||||||
fireBindingList(_hover);
|
params->setDoubleValue("x", windowPos.x());
|
||||||
|
params->setDoubleValue("y", windowPos.y());
|
||||||
|
fireBindingList(_hover, params.ptr());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
@@ -439,8 +441,10 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME - make x,y available to the binding
|
SGPropertyNode_ptr params(new SGPropertyNode);
|
||||||
fireBindingList(_hover);
|
params->setDoubleValue("x", windowPos.x());
|
||||||
|
params->setDoubleValue("y", windowPos.y());
|
||||||
|
fireBindingList(_hover, params.ptr());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
#include "SGBinding.hxx"
|
#include "SGBinding.hxx"
|
||||||
|
|
||||||
|
#include <simgear/props/props_io.hxx>
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
|
|
||||||
SGBinding::SGBinding()
|
SGBinding::SGBinding()
|
||||||
@@ -64,25 +65,42 @@ SGBinding::read(const SGPropertyNode* node, SGPropertyNode* root)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SGBinding::fire () const
|
SGBinding::fire() const
|
||||||
{
|
{
|
||||||
if (test()) {
|
if (test()) {
|
||||||
if (_command == 0)
|
innerFire();
|
||||||
_command = SGCommandMgr::instance()->getCommand(_command_name);
|
}
|
||||||
if (_command == 0) {
|
}
|
||||||
SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding");
|
|
||||||
} else
|
void
|
||||||
{
|
SGBinding::innerFire () const
|
||||||
try {
|
{
|
||||||
if (!(*_command)(_arg)) {
|
if (_command == 0)
|
||||||
SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
|
_command = SGCommandMgr::instance()->getCommand(_command_name);
|
||||||
<< _command_name);
|
if (_command == 0) {
|
||||||
}
|
SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding:" << _command_name);
|
||||||
} catch (sg_exception& e) {
|
} else {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "command '" << _command_name << "' failed with exception\n"
|
try {
|
||||||
<< "\tmessage:" << e.getMessage() << " (from " << e.getOrigin() << ")");
|
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()) {
|
if (test()) {
|
||||||
_arg->setDoubleValue("offset", offset/max);
|
_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
|
if (_setting == 0) // save the setting node for efficiency
|
||||||
_setting = _arg->getChild("setting", 0, true);
|
_setting = _arg->getChild("setting", 0, true);
|
||||||
_setting->setDoubleValue(setting);
|
_setting->setDoubleValue(setting);
|
||||||
fire();
|
innerFire();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fireBindingList(const SGBindingList& aBindings)
|
void fireBindingList(const SGBindingList& aBindings, SGPropertyNode* params)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(SGBinding_ptr b, aBindings) {
|
BOOST_FOREACH(SGBinding_ptr b, aBindings) {
|
||||||
b->fire();
|
b->fire(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,8 +114,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
void fire (double setting) const;
|
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:
|
private:
|
||||||
|
void innerFire() const;
|
||||||
// just to be safe.
|
// just to be safe.
|
||||||
SGBinding (const SGBinding &binding);
|
SGBinding (const SGBinding &binding);
|
||||||
|
|
||||||
@@ -134,7 +141,7 @@ typedef std::map<unsigned,SGBindingList> SGBindingMap;
|
|||||||
* fire every binding in a list, in sequence
|
* 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
|
* fire every binding in a list with a setting value
|
||||||
|
|||||||
Reference in New Issue
Block a user