diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index 5af75418f..c1db754cf 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -49,6 +49,15 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View /** Get the threading model the rendering traversals will use.*/ ThreadingModel getThreadingModel() const { return _threadingModel; } + /** Set the key value that the viewer checks on each frame to see if the viewer's done flag should be set to + * signal end of viewers main loop. + * Default value is Escape (osgGA::GUIEVentAdapter::KEY_Escape). + * Setting to 0 switches off the feature.*/ + void setKeySetsDone(int key) { _keySetsDone = key; } + + /** Set the key value that the viewer checks on each frame to see if the viewer's done flag.*/ + int getKeySetsDone() const { return _keySetsDone; } + /** Render a complete new frame. * Calls frameAdvance(), frameEventTraversal(), frameUpateTraversal(), frameRenderingTraversals(). */ virtual void frame(); @@ -86,7 +95,9 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View void checkWindowStatus(); bool _firstFrame; + bool _done; + int _keySetsDone; ThreadingModel _threadingModel; diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 80552dce6..3072fd746 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -25,6 +25,7 @@ using namespace osgViewer; Viewer::Viewer(): _firstFrame(true), _done(false), + _keySetsDone(osgGA::GUIEventAdapter::KEY_Escape), _threadingModel(ThreadPerContext), _numThreadsOnBarrier(0) { @@ -601,21 +602,25 @@ void Viewer::frameEventTraversal() #endif // osg::notify(osg::NOTICE)<<"Events "<get(); - switch(event->getEventType()) + for(osgGA::EventQueue::Events::iterator itr = events.begin(); + itr != events.end(); + ++itr) { - case(osgGA::GUIEventAdapter::KEYUP): - if (event->getKey()==osgGA::GUIEventAdapter::KEY_Escape) _done = true; - break; - default: - break; + osgGA::GUIEventAdapter* event = itr->get(); + switch(event->getEventType()) + { + case(osgGA::GUIEventAdapter::KEYUP): + if (event->getKey()==_keySetsDone) _done = true; + break; + default: + break; + } } } - + if (_done) return; for(osgGA::EventQueue::Events::iterator itr = events.begin();