From 4016aed62d4b769af94e9cdecdfbb7791e03fe73 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 6 Feb 2014 17:32:41 +0000 Subject: [PATCH] Moved experimental Widget class to osgGA Add computeIntersections() to the osgGA::GUIActionAdapter base class to enable intersection tests without needing to directly link to osgViewer. --- examples/osgtransferfunction/CMakeLists.txt | 1 - .../TransferFunctionWidget.h | 4 ++-- include/osgGA/GUIActionAdapter | 8 +++++++ .../Widget.h => include/osgGA/Widget | 2 +- src/osgGA/CMakeLists.txt | 4 +++- .../osgGA}/Widget.cpp | 21 +++++++++---------- 6 files changed, 24 insertions(+), 16 deletions(-) rename examples/osgtransferfunction/Widget.h => include/osgGA/Widget (99%) rename {examples/osgtransferfunction => src/osgGA}/Widget.cpp (91%) diff --git a/examples/osgtransferfunction/CMakeLists.txt b/examples/osgtransferfunction/CMakeLists.txt index e5cbd4cc7..645cb1fcc 100644 --- a/examples/osgtransferfunction/CMakeLists.txt +++ b/examples/osgtransferfunction/CMakeLists.txt @@ -1,5 +1,4 @@ SET(TARGET_SRC - Widget.cpp TransferFunctionWidget.cpp osgtransferfunction.cpp ) diff --git a/examples/osgtransferfunction/TransferFunctionWidget.h b/examples/osgtransferfunction/TransferFunctionWidget.h index 78e173709..e9d16a54f 100644 --- a/examples/osgtransferfunction/TransferFunctionWidget.h +++ b/examples/osgtransferfunction/TransferFunctionWidget.h @@ -17,14 +17,14 @@ #include #include -#include "Widget.h" +#include #define OSGUI_EXPORT namespace osgUI { -class OSGUI_EXPORT TransferFunctionWidget : public osgUI::Widget +class OSGUI_EXPORT TransferFunctionWidget : public osgGA::Widget { public: TransferFunctionWidget(osg::TransferFunction1D* tf=0); diff --git a/include/osgGA/GUIActionAdapter b/include/osgGA/GUIActionAdapter index 07ddce4fb..06854631b 100644 --- a/include/osgGA/GUIActionAdapter +++ b/include/osgGA/GUIActionAdapter @@ -16,6 +16,7 @@ #include #include +#include namespace osgGA{ @@ -83,6 +84,13 @@ public: */ virtual void requestWarpPointer(float x,float y) = 0; + + /** Compute intersections of a ray, starting the current mouse position, through the specified camera. */ + virtual bool computeIntersections(const osgGA::GUIEventAdapter& /*ea*/, osgUtil::LineSegmentIntersector::Intersections& /*intersections*/,osg::Node::NodeMask /*traversalMask*/ = 0xffffffff) { return false; } + + /** Compute intersections of a ray, starting the current mouse position, through the specified master camera's window/eye coordinates and a specified nodePath's subgraph. */ + virtual bool computeIntersections(const osgGA::GUIEventAdapter& /*ea*/, const osg::NodePath& /*nodePath*/, osgUtil::LineSegmentIntersector::Intersections& /*intersections*/,osg::Node::NodeMask /*traversalMask*/ = 0xffffffff) { return false; } + }; } diff --git a/examples/osgtransferfunction/Widget.h b/include/osgGA/Widget similarity index 99% rename from examples/osgtransferfunction/Widget.h rename to include/osgGA/Widget index f78d3354a..3ef2ebc9f 100644 --- a/examples/osgtransferfunction/Widget.h +++ b/include/osgGA/Widget @@ -21,7 +21,7 @@ #define OSGUI_EXPORT -namespace osgUI +namespace osgGA { class OSGUI_EXPORT Widget : public osg::Group diff --git a/src/osgGA/CMakeLists.txt b/src/osgGA/CMakeLists.txt index b3fe5baec..49b0aca73 100644 --- a/src/osgGA/CMakeLists.txt +++ b/src/osgGA/CMakeLists.txt @@ -9,6 +9,7 @@ SET(LIB_NAME osgGA) SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME}) SET(TARGET_H ${HEADER_PATH}/AnimationPathManipulator + ${HEADER_PATH}/CameraViewSwitchManipulator ${HEADER_PATH}/DriveManipulator ${HEADER_PATH}/Device ${HEADER_PATH}/Event @@ -32,8 +33,8 @@ SET(TARGET_H ${HEADER_PATH}/TerrainManipulator ${HEADER_PATH}/TrackballManipulator ${HEADER_PATH}/UFOManipulator + ${HEADER_PATH}/Widget ${HEADER_PATH}/Version - ${HEADER_PATH}/CameraViewSwitchManipulator ) SET(TARGET_SRC @@ -59,6 +60,7 @@ SET(TARGET_SRC TerrainManipulator.cpp TrackballManipulator.cpp UFOManipulator.cpp + Widget.cpp Version.cpp CameraViewSwitchManipulator.cpp ${OPENSCENEGRAPH_VERSIONINFO_RC} diff --git a/examples/osgtransferfunction/Widget.cpp b/src/osgGA/Widget.cpp similarity index 91% rename from examples/osgtransferfunction/Widget.cpp rename to src/osgGA/Widget.cpp index 0ff94c79d..e4debd34a 100644 --- a/examples/osgtransferfunction/Widget.cpp +++ b/src/osgGA/Widget.cpp @@ -11,7 +11,6 @@ * OpenSceneGraph Public License for more details. */ -#include "Widget.h" #include #include @@ -19,10 +18,11 @@ #include #include +#include #include -#include +#include -using namespace osgUI; +using namespace osgGA; Widget::Widget(): _focusBehaviour(FOCUS_FOLLOWS_POINTER), @@ -50,8 +50,8 @@ void Widget::setExtents(const osg::BoundingBox& bb) void Widget::updateFocus(osg::NodeVisitor& nv) { osgGA::EventVisitor* ev = dynamic_cast(&nv); - osgViewer::View* view = ev ? dynamic_cast(ev->getActionAdapter()) : 0; - if (ev && view) + osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0; + if (ev && aa) { osgGA::EventQueue::Events& events = ev->getEvents(); for(osgGA::EventQueue::Events::iterator itr = events.begin(); @@ -74,7 +74,7 @@ void Widget::updateFocus(osg::NodeVisitor& nv) if (numButtonsPressed==1) { osgUtil::LineSegmentIntersector::Intersections intersections; - bool withinWidget = view->computeIntersections(*ea, nv.getNodePath(), intersections); + bool withinWidget = aa->computeIntersections(*ea, nv.getNodePath(), intersections); if (withinWidget) _hasEventFocus = true; else _hasEventFocus = false; } @@ -104,7 +104,7 @@ void Widget::updateFocus(osg::NodeVisitor& nv) if (checkWithinWidget) { osgUtil::LineSegmentIntersector::Intersections intersections; - bool withinWidget = view->computeIntersections(*ea, nv.getNodePath(), intersections); + bool withinWidget = aa->computeIntersections(*ea, nv.getNodePath(), intersections); _hasEventFocus = withinWidget; } @@ -205,8 +205,7 @@ void Widget::traverseImplementation(osg::NodeVisitor& nv) if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics(); osgGA::EventVisitor* ev = dynamic_cast(&nv); - osgViewer::View* view = ev ? dynamic_cast(ev->getActionAdapter()) : 0; - if (ev && view) + if (ev) { updateFocus(nv); @@ -263,9 +262,9 @@ bool Widget::handleImplementation(osgGA::EventVisitor* /*ev*/, osgGA::Event* /*e bool Widget::computePositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, osg::Vec3& localPosition) const { - osgViewer::View* view = ev ? dynamic_cast(ev->getActionAdapter()) : 0; + osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0; osgUtil::LineSegmentIntersector::Intersections intersections; - if (view && view->computeIntersections(*event, ev->getNodePath(), intersections)) + if (aa && aa->computeIntersections(*event, ev->getNodePath(), intersections)) { localPosition = intersections.begin()->getLocalIntersectPoint();