From 4cf73d4c8721e3b605fb9e3a638ed5173a65ece7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 30 Sep 2007 19:15:32 +0000 Subject: [PATCH] Changed HelpHandler so it supports use with CompositeViewer and Viewer --- examples/osgcompositeviewer/osgcompositeviewer.cpp | 5 +++-- include/osgViewer/ViewerEventHandlers | 4 ++-- src/osgViewer/HelpHandler.cpp | 9 ++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/osgcompositeviewer/osgcompositeviewer.cpp b/examples/osgcompositeviewer/osgcompositeviewer.cpp index cbb3e31b7..fc0203c49 100644 --- a/examples/osgcompositeviewer/osgcompositeviewer.cpp +++ b/examples/osgcompositeviewer/osgcompositeviewer.cpp @@ -249,8 +249,8 @@ int main( int argc, char **argv ) view->addEventHandler( statesetManipulator.get() ); - osg::ref_ptr statsHandler = new osgViewer::StatsHandler; - view->addEventHandler( statsHandler.get() ); + view->addEventHandler( new osgViewer::StatsHandler ); + view->addEventHandler( new osgViewer::HelpHandler ); } // view two @@ -282,6 +282,7 @@ int main( int argc, char **argv ) } } + while (arguments.read("-s")) { viewer.setThreadingModel(osgViewer::CompositeViewer::SingleThreaded); } while (arguments.read("-g")) { viewer.setThreadingModel(osgViewer::CompositeViewer::ThreadPerContext); } diff --git a/include/osgViewer/ViewerEventHandlers b/include/osgViewer/ViewerEventHandlers index 37663b373..f8ebbd5cd 100644 --- a/include/osgViewer/ViewerEventHandlers +++ b/include/osgViewer/ViewerEventHandlers @@ -50,9 +50,9 @@ class OSGVIEWER_EXPORT HelpHandler : public osgGA::GUIEventHandler protected: - void setUpHUDCamera(osgViewer::Viewer* viewer); + void setUpHUDCamera(osgViewer::ViewerBase* viewer); - void setUpScene(osgViewer::Viewer* viewer); + void setUpScene(osgViewer::ViewerBase* viewer); osg::ref_ptr _applicationUsage; diff --git a/src/osgViewer/HelpHandler.cpp b/src/osgViewer/HelpHandler.cpp index 59a710a18..5a5cb40b9 100644 --- a/src/osgViewer/HelpHandler.cpp +++ b/src/osgViewer/HelpHandler.cpp @@ -40,7 +40,10 @@ void HelpHandler::reset() bool HelpHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { - osgViewer::Viewer* viewer = dynamic_cast(&aa); + osgViewer::View* view = dynamic_cast(&aa); + if (!view) return false; + + osgViewer::ViewerBase* viewer = view->getViewerBase(); if (!viewer) return false; if (ea.getHandled()) return false; @@ -77,7 +80,7 @@ bool HelpHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapt } -void HelpHandler::setUpHUDCamera(osgViewer::Viewer* viewer) +void HelpHandler::setUpHUDCamera(osgViewer::ViewerBase* viewer) { osgViewer::GraphicsWindow* window = dynamic_cast(_camera->getGraphicsContext()); @@ -106,7 +109,7 @@ void HelpHandler::setUpHUDCamera(osgViewer::Viewer* viewer) _initialized = true; } -void HelpHandler::setUpScene(osgViewer::Viewer* viewer) +void HelpHandler::setUpScene(osgViewer::ViewerBase* viewer) { _switch = new osg::Switch;