Added Viewer::setKeySetsDone(int) to allow developers to specify which

key should set done and cause the main loop to exit.
This commit is contained in:
Robert Osfield 2007-01-04 21:28:16 +00:00
parent abdb1741a4
commit 1fd2047cf5
2 changed files with 27 additions and 11 deletions

View File

@ -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;

View File

@ -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 "<<events.size()<<std::endl;
for(osgGA::EventQueue::Events::iterator itr = events.begin();
itr != events.end();
++itr)
if (_keySetsDone!=0)
{
osgGA::GUIEventAdapter* event = itr->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();