From 1fd2047cf53c6d506f405f9fe7de04f05663c4a7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 4 Jan 2007 21:28:16 +0000 Subject: [PATCH] Added Viewer::setKeySetsDone(int) to allow developers to specify which key should set done and cause the main loop to exit. --- include/osgViewer/Viewer | 11 +++++++++++ src/osgViewer/Viewer.cpp | 27 ++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) 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();