From: James Turner Date: Sun, 31 Jul 2016 21:13:19 +0000 (+0100) Subject: Improve pick-callback enabled testing. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=43963e67ef5c222c98afc273fe5a43c6d9747be5;p=simgear.git Improve pick-callback enabled testing. --- diff --git a/simgear/scene/model/SGPickAnimation.cxx b/simgear/scene/model/SGPickAnimation.cxx index 3c6a2da0..f4ba22f5 100644 --- a/simgear/scene/model/SGPickAnimation.cxx +++ b/simgear/scene/model/SGPickAnimation.cxx @@ -107,7 +107,11 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter& ea) if (_buttons.find(button) == _buttons.end()) { return false; } - + + if (!anyBindingEnabled(_bindingsDown)) { + return false; + } + fireBindingList(_bindingsDown); _repeatTime = -_repeatInterval; // anti-bobble: delay start of repeat return true; @@ -136,7 +140,7 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter& ea) virtual bool hover( const osg::Vec2d& windowPos, const Info& ) { - if (_hover.empty()) { + if (!anyBindingEnabled(_hover)) { return false; } diff --git a/simgear/structure/SGBinding.cxx b/simgear/structure/SGBinding.cxx index 28e6f816..86420be1 100644 --- a/simgear/structure/SGBinding.cxx +++ b/simgear/structure/SGBinding.cxx @@ -165,3 +165,18 @@ void clearBindingList(const SGBindingList& aBindings) } } +bool anyBindingEnabled(const SGBindingList& aBindings) +{ + if (aBindings.empty()) { + return false; + } + + BOOST_FOREACH(SGBinding_ptr b, aBindings) { + if (!b->test()) { + return false; + } + } + + return true; +} + diff --git a/simgear/structure/SGBinding.hxx b/simgear/structure/SGBinding.hxx index ef573a01..6ec2bc68 100644 --- a/simgear/structure/SGBinding.hxx +++ b/simgear/structure/SGBinding.hxx @@ -171,4 +171,10 @@ SGBindingList readBindingList(const simgear::PropertyList& aNodes, SGPropertyNod */ void clearBindingList(const SGBindingList& aBindings); +/** + * check if at least one binding in the list is enabled. Returns false if bindings + * list is empty, or all bindings are conditinally disabled. + */ +bool anyBindingEnabled(const SGBindingList& bindings); + #endif