From 159c0271b715d4829c3dd90968471c9b704d27df Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 18 Feb 2021 16:08:25 +0000 Subject: [PATCH] Fixed osgWidget event handling --- src/osgWidget/WindowManager.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/osgWidget/WindowManager.cpp b/src/osgWidget/WindowManager.cpp index 7bccbd348..9267cefe0 100644 --- a/src/osgWidget/WindowManager.cpp +++ b/src/osgWidget/WindowManager.cpp @@ -317,7 +317,17 @@ bool WindowManager::pickAtXY(float x, float y, WidgetList& wl) // Iterate over every picked result and create a list of Widgets that belong // to that Window. for(Intersections::iterator i = intr.begin(); i != intr.end(); i++) { - Window* win = dynamic_cast(i->nodePath.back()->getParent(0)); + + Widget* widget = dynamic_cast(i->drawable.get()); + if(!widget) continue; + + Window* win = 0; + const osg::NodePath& nodePath = i->nodePath; + for(osg::NodePath::const_reverse_iterator np_itr = nodePath.rbegin(); np_itr != nodePath.rend(); ++np_itr) + { + win = dynamic_cast(*np_itr); + if (win) break; + } // Make sure that our window is valid, and that our pick is within the // "visible area" of the Window. @@ -335,9 +345,6 @@ bool WindowManager::pickAtXY(float x, float y, WidgetList& wl) // If we've found a new Widnow, break out! else if(activeWin != win) break; - Widget* widget = dynamic_cast(i->drawable.get()); - - if(!widget) continue; // We need to return a list of every Widget that was picked, so // that the handler can operate on it accordingly.