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:
parent
abdb1741a4
commit
1fd2047cf5
@ -49,6 +49,15 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
|
|||||||
/** Get the threading model the rendering traversals will use.*/
|
/** Get the threading model the rendering traversals will use.*/
|
||||||
ThreadingModel getThreadingModel() const { return _threadingModel; }
|
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.
|
/** Render a complete new frame.
|
||||||
* Calls frameAdvance(), frameEventTraversal(), frameUpateTraversal(), frameRenderingTraversals(). */
|
* Calls frameAdvance(), frameEventTraversal(), frameUpateTraversal(), frameRenderingTraversals(). */
|
||||||
virtual void frame();
|
virtual void frame();
|
||||||
@ -86,7 +95,9 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
|
|||||||
void checkWindowStatus();
|
void checkWindowStatus();
|
||||||
|
|
||||||
bool _firstFrame;
|
bool _firstFrame;
|
||||||
|
|
||||||
bool _done;
|
bool _done;
|
||||||
|
int _keySetsDone;
|
||||||
|
|
||||||
ThreadingModel _threadingModel;
|
ThreadingModel _threadingModel;
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ using namespace osgViewer;
|
|||||||
Viewer::Viewer():
|
Viewer::Viewer():
|
||||||
_firstFrame(true),
|
_firstFrame(true),
|
||||||
_done(false),
|
_done(false),
|
||||||
|
_keySetsDone(osgGA::GUIEventAdapter::KEY_Escape),
|
||||||
_threadingModel(ThreadPerContext),
|
_threadingModel(ThreadPerContext),
|
||||||
_numThreadsOnBarrier(0)
|
_numThreadsOnBarrier(0)
|
||||||
{
|
{
|
||||||
@ -601,21 +602,25 @@ void Viewer::frameEventTraversal()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// osg::notify(osg::NOTICE)<<"Events "<<events.size()<<std::endl;
|
// osg::notify(osg::NOTICE)<<"Events "<<events.size()<<std::endl;
|
||||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
|
||||||
itr != events.end();
|
if (_keySetsDone!=0)
|
||||||
++itr)
|
|
||||||
{
|
{
|
||||||
osgGA::GUIEventAdapter* event = itr->get();
|
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||||
switch(event->getEventType())
|
itr != events.end();
|
||||||
|
++itr)
|
||||||
{
|
{
|
||||||
case(osgGA::GUIEventAdapter::KEYUP):
|
osgGA::GUIEventAdapter* event = itr->get();
|
||||||
if (event->getKey()==osgGA::GUIEventAdapter::KEY_Escape) _done = true;
|
switch(event->getEventType())
|
||||||
break;
|
{
|
||||||
default:
|
case(osgGA::GUIEventAdapter::KEYUP):
|
||||||
break;
|
if (event->getKey()==_keySetsDone) _done = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_done) return;
|
if (_done) return;
|
||||||
|
|
||||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||||
|
Loading…
Reference in New Issue
Block a user