diff --git a/simgear/scene/model/SGPickAnimation.cxx b/simgear/scene/model/SGPickAnimation.cxx index 3fa643d6..ae99eb29 100644 --- a/simgear/scene/model/SGPickAnimation.cxx +++ b/simgear/scene/model/SGPickAnimation.cxx @@ -74,10 +74,12 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter& ea) class SGPickAnimation::PickCallback : public SGPickCallback { public: PickCallback(const SGPropertyNode* configNode, - SGPropertyNode* modelRoot) : + SGPropertyNode* modelRoot, + SGSharedPtr condition) : SGPickCallback(PriorityPanel), _repeatable(configNode->getBoolValue("repeatable", false)), - _repeatInterval(configNode->getDoubleValue("interval-sec", 0.1)) + _repeatInterval(configNode->getDoubleValue("interval-sec", 0.1)), + _condition(condition) { std::vector bindings; @@ -98,63 +100,76 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter& ea) void addHoverBindings(const SGPropertyNode* hoverNode, SGPropertyNode* modelRoot) { - _hover = readBindingList(hoverNode->getChildren("binding"), modelRoot); + if (!_condition || _condition->test()) { + _hover = readBindingList(hoverNode->getChildren("binding"), modelRoot); + } } virtual bool buttonPressed( int button, const osgGA::GUIEventAdapter&, const Info& ) { - if (_buttons.find(button) == _buttons.end()) { - return false; - } + if (!_condition || _condition->test()) { + if (_buttons.find(button) == _buttons.end()) { + return false; + } - if (!anyBindingEnabled(_bindingsDown)) { - return false; - } + if (!anyBindingEnabled(_bindingsDown)) { + return false; + } - fireBindingList(_bindingsDown); - _repeatTime = -_repeatInterval; // anti-bobble: delay start of repeat - return true; + fireBindingList(_bindingsDown); + _repeatTime = -_repeatInterval; // anti-bobble: delay start of repeat + return true; + } + return false; } virtual void buttonReleased( int keyModState, const osgGA::GUIEventAdapter&, const Info* ) { - SG_UNUSED(keyModState); - fireBindingList(_bindingsUp); + if (!_condition || _condition->test()) { + SG_UNUSED(keyModState); + fireBindingList(_bindingsUp); + } } virtual void update(double dt, int keyModState) { - SG_UNUSED(keyModState); - if (!_repeatable) - return; + if (!_condition || _condition->test()) { + SG_UNUSED(keyModState); + if (!_repeatable) + return; - _repeatTime += dt; - while (_repeatInterval < _repeatTime) { - _repeatTime -= _repeatInterval; - fireBindingList(_bindingsDown); - } + _repeatTime += dt; + while (_repeatInterval < _repeatTime) { + _repeatTime -= _repeatInterval; + fireBindingList(_bindingsDown); + } + } } virtual bool hover( const osg::Vec2d& windowPos, const Info& ) { - if (!anyBindingEnabled(_hover)) { - return false; + if (!_condition || _condition->test()) { + if (!anyBindingEnabled(_hover)) { + return false; + } + + SGPropertyNode_ptr params(new SGPropertyNode); + params->setDoubleValue("x", windowPos.x()); + params->setDoubleValue("y", windowPos.y()); + fireBindingList(_hover, params.ptr()); + return true; } - - SGPropertyNode_ptr params(new SGPropertyNode); - params->setDoubleValue("x", windowPos.x()); - params->setDoubleValue("y", windowPos.y()); - fireBindingList(_hover, params.ptr()); - return true; + return false; } std::string getCursor() const { return _cursorName; } private: + SGSharedPtr _condition; SGBindingList _bindingsDown; SGBindingList _bindingsUp; SGBindingList _hover; @@ -247,8 +262,9 @@ class SGPickAnimation::VncCallback : public SGPickCallback { public: VncCallback(const SGPropertyNode* configNode, SGPropertyNode* modelRoot, - osg::Group *node) - : _node(node) + osg::Group *node, + SGSharedPtr condition) + : _node(node), _condition(condition) { SG_LOG(SG_INPUT, SG_DEBUG, "Configuring VNC callback"); const char *cornernames[3] = {"top-left", "top-right", "bottom-left"}; @@ -270,29 +286,35 @@ public: const osgGA::GUIEventAdapter&, const Info& info ) { - SGVec3d loc(info.local); - SG_LOG(SG_INPUT, SG_DEBUG, "VNC pressed " << button << ": " << loc); - loc -= _topLeft; - _x = dot(loc, _toRight) / _squaredRight; - _y = dot(loc, _toDown) / _squaredDown; - if (_x<0) _x = 0; else if (_x > 1) _x = 1; - if (_y<0) _y = 0; else if (_y > 1) _y = 1; - VncVisitor vv(_x, _y, 1 << button); - _node->accept(vv); - return vv.wasSuccessful(); - + if (!_condition || _condition->test()) { + SGVec3d loc(info.local); + SG_LOG(SG_INPUT, SG_DEBUG, "VNC pressed " << button << ": " << loc); + loc -= _topLeft; + _x = dot(loc, _toRight) / _squaredRight; + _y = dot(loc, _toDown) / _squaredDown; + if (_x < 0) _x = 0; else if (_x > 1) _x = 1; + if (_y < 0) _y = 0; else if (_y > 1) _y = 1; + VncVisitor vv(_x, _y, 1 << button); + _node->accept(vv); + return vv.wasSuccessful(); + } + return false; } virtual void buttonReleased( int keyModState, const osgGA::GUIEventAdapter&, const Info* ) { - SG_UNUSED(keyModState); - SG_LOG(SG_INPUT, SG_DEBUG, "VNC release"); - VncVisitor vv(_x, _y, 0); - _node->accept(vv); + if (!_condition || _condition->test()) { + SG_UNUSED(keyModState); + SG_LOG(SG_INPUT, SG_DEBUG, "VNC release"); + VncVisitor vv(_x, _y, 0); + _node->accept(vv); + } } private: + SGSharedPtr _condition; + double _x, _y; osg::ref_ptr _node; SGVec3d _topLeft, _toRight, _toDown; @@ -304,6 +326,8 @@ private: SGPickAnimation::SGPickAnimation(simgear::SGTransientModelData &modelData) : SGAnimation(modelData) { + _condition = getCondition(); + std::vector names = modelData.getConfigNode()->getChildren("proxy-name"); for (unsigned i = 0; i < names.size(); ++i) { _proxyNames.push_back(names[i]->getStringValue()); @@ -451,7 +475,7 @@ SGPickAnimation::setupCallbacks(SGSceneUserData* ud, osg::Group* parent) std::vector actions; actions = getConfig()->getChildren("action"); for (unsigned int i = 0; i < actions.size(); ++i) { - pickCb = new PickCallback(actions[i], getModelRoot()); + pickCb = new PickCallback(actions[i], getModelRoot(), _condition); ud->addPickCallback(pickCb); } @@ -459,7 +483,7 @@ SGPickAnimation::setupCallbacks(SGSceneUserData* ud, osg::Group* parent) if (!pickCb) { // make a trivial PickCallback to hang the hovered off of SGPropertyNode_ptr dummyNode(new SGPropertyNode); - pickCb = new PickCallback(dummyNode.ptr(), getModelRoot()); + pickCb = new PickCallback(dummyNode.ptr(), getModelRoot(), _condition); ud->addPickCallback(pickCb); } @@ -469,7 +493,7 @@ SGPickAnimation::setupCallbacks(SGSceneUserData* ud, osg::Group* parent) // Look for the VNC sessions that want raw mouse input actions = getConfig()->getChildren("vncaction"); for (unsigned int i = 0; i < actions.size(); ++i) { - ud->addPickCallback(new VncCallback(actions[i], getModelRoot(), parent)); + ud->addPickCallback(new VncCallback(actions[i], getModelRoot(), parent, _condition)); } } diff --git a/simgear/scene/model/SGPickAnimation.hxx b/simgear/scene/model/SGPickAnimation.hxx index 00695467..63fc4999 100644 --- a/simgear/scene/model/SGPickAnimation.hxx +++ b/simgear/scene/model/SGPickAnimation.hxx @@ -45,7 +45,8 @@ protected: virtual osg::Group* createMainGroup(osg::Group* pr); - + SGSharedPtr _condition; + virtual void setupCallbacks(SGSceneUserData* ud, osg::Group* parent); private: class PickCallback;