diff --git a/examples/osghud/osghud.cpp b/examples/osghud/osghud.cpp index f1c98a397..46535d21e 100644 --- a/examples/osghud/osghud.cpp +++ b/examples/osghud/osghud.cpp @@ -227,6 +227,8 @@ struct SnapImage : public osg::Camera::DrawCallback mutable osg::ref_ptr _image; }; + + struct SnapeImageHandler : public osgGA::GUIEventHandler { @@ -234,7 +236,7 @@ struct SnapeImageHandler : public osgGA::GUIEventHandler _key(key), _snapImage(si) {} - bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&) + bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { if (ea.getHandled()) return false; @@ -242,6 +244,18 @@ struct SnapeImageHandler : public osgGA::GUIEventHandler { case(osgGA::GUIEventAdapter::KEYUP): { + if (ea.getKey() == 'o' ) + { + osgViewer::View* view = dynamic_cast(&aa); + osg::Node* node = view ? view->getSceneData() : 0; + if (node) + { + osgDB::writeNodeFile(*node, "hud.osgt"); + osgDB::writeNodeFile(*node, "hud.osgb"); + } + return true; + } + if (ea.getKey() == _key) { osg::notify(osg::NOTICE)<<"event handler"<setFinalDrawCallback(finalDrawCallback); viewer.addEventHandler(new SnapeImageHandler('f',finalDrawCallback)); - osg::ref_ptr group = new osg::Group; + osg::ref_ptr group = new osg::Group; // add the HUD subgraph. if (scene.valid()) group->addChild(scene.get());