From Daniel, changed setEventHandler to addEventHandler.

This commit is contained in:
Robert Osfield
2002-09-20 14:48:41 +00:00
parent ce51fb1841
commit fd3bef5158
2 changed files with 83 additions and 39 deletions

View File

@@ -13,6 +13,7 @@
#include <osgGA/GUIEventAdapter>
#include <osgGA/CameraManipulator>
#include <osgGA/GUIEventHandler>
#include <osgUtil/SceneView>
@@ -81,7 +82,7 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter
void selectCameraManipulator(unsigned int pos,
unsigned int viewport = 0);
void setEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport = 0);
void addEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport = 0);
// derived from osgGA::GUIActionAdapter
virtual void requestRedraw() {} // redraw always by idle callback done.
@@ -96,6 +97,7 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter
const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
typedef std::vector<osg::ref_ptr<osgGA::CameraManipulator> > CameraManipList;
typedef std::vector<osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlerList;
protected:
@@ -124,8 +126,7 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter
osg::ref_ptr<osgGA::CameraManipulator> _cameraManipulator;
CameraManipList _cameraManipList;
osg::ref_ptr<osgGA::GUIEventHandler> _eventHandler;
EventHandlerList _eventHandlerList;
};
typedef std::vector<ViewportDef> ViewportList;

View File

@@ -317,10 +317,10 @@ unsigned int Viewer::registerCameraManipulator(osgGA::CameraManipulator* cm,
return pos;
}
void Viewer::setEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport)
void Viewer::addEventHandler(osgGA::GUIEventHandler* handler,unsigned int viewport)
{
ViewportDef &viewp = _viewportList[viewport];
viewp._eventHandler = handler;
viewp._eventHandlerList.push_back( handler );
}
void Viewer::setFocusedViewport(unsigned int pos)
@@ -369,13 +369,18 @@ float Viewer::app(unsigned int viewport)
osg::ref_ptr<GLUTEventAdapter> ea = osgNew GLUTEventAdapter;
ea->adaptFrame(_frameStamp->getReferenceTime());
if (_viewportList[viewport]._eventHandler.valid() && _viewportList[viewport]._eventHandler->handle(*ea,*this))
{
// event handler handle this call.
bool handled = false;
for ( EventHandlerList::iterator eh =
_viewportList[viewport]._eventHandlerList.begin();
eh != _viewportList[viewport]._eventHandlerList.end(); eh++ ) {
if ( eh->valid() ) {
if ( (*eh)->handle(*ea,*this) ) {
handled = true;
}
}
}
else if (_viewportList[viewport]._cameraManipulator->handle(*ea,*this))
{
// osg::notify(osg::INFO) << "Handled update frame"<< std::endl;
if ( !handled ) {
_viewportList[viewport]._cameraManipulator->handle(*ea,*this);
}
@@ -744,9 +749,13 @@ void Viewer::reshape(GLint w, GLint h)
{
// osg::notify(osg::INFO) << "Handled reshape "<< std::endl;
}
if (itr->_eventHandler.valid() && itr->_eventHandler->handle(*ea,*this))
{
// event handler handle this call.
for ( EventHandlerList::iterator eh = itr->_eventHandlerList.begin();
eh != itr->_eventHandlerList.end(); eh++ ) {
if ( eh->valid() ) {
if ( (*eh)->handle(*ea,*this) ) {
// event handler handle this call.
}
}
}
}
@@ -758,13 +767,22 @@ void Viewer::mouseMotion(int x, int y)
osg::ref_ptr<GLUTEventAdapter> ea = osgNew GLUTEventAdapter;
ea->adaptMouseMotion(clockSeconds(),x,y);
if (_viewportList[_focusedViewport]._eventHandler.valid() && _viewportList[_focusedViewport]._eventHandler->handle(*ea,*this))
{
// event handler handle this call.
bool handled = false;
for ( EventHandlerList::iterator eh =
_viewportList[_focusedViewport]._eventHandlerList.begin();
eh != _viewportList[_focusedViewport]._eventHandlerList.end();
eh++ ) {
if ( eh->valid() ) {
if ( (*eh)->handle(*ea,*this) ) {
handled = true;
}
}
}
else if (_viewportList[_focusedViewport]._cameraManipulator->handle(*ea,*this))
{
// osg::notify(osg::INFO) << "Handled mouseMotion "<<ea->_buttonMask<<" x="<<ea->_mx<<" y="<<ea->_my<< std::endl;
if ( !handled ) {
if ( _viewportList[_focusedViewport]._cameraManipulator->handle(
*ea,*this) ) {
// osg::notify(osg::INFO) << "Handled mouseMotion "<<ea->_buttonMask<<" x="<<ea->_mx<<" y="<<ea->_my<< std::endl;
}
}
_mx = x;
@@ -786,13 +804,22 @@ void Viewer::mousePassiveMotion(int x, int y)
setFocusedViewport(focus);
}
if (_viewportList[_focusedViewport]._eventHandler.valid() && _viewportList[_focusedViewport]._eventHandler->handle(*ea,*this))
{
// event handler handle this call.
bool handled = false;
for ( EventHandlerList::iterator eh =
_viewportList[_focusedViewport]._eventHandlerList.begin();
eh != _viewportList[_focusedViewport]._eventHandlerList.end();
eh++ ) {
if ( eh->valid() ) {
if ( (*eh)->handle(*ea,*this) ) {
handled = true;
}
}
}
else if (_viewportList[_focusedViewport]._cameraManipulator->handle(*ea,*this))
{
// osg::notify(osg::INFO) << "Handled mousePassiveMotion "<<ea->_buttonMask<<" x="<<ea->_mx<<" y="<<ea->_my<< std::endl;
if ( !handled ) {
if ( _viewportList[_focusedViewport]._cameraManipulator->handle(
*ea,*this) ) {
// osg::notify(osg::INFO) << "Handled mousePassiveMotion "<<ea->_buttonMask<<" x="<<ea->_mx<<" y="<<ea->_my<< std::endl;
}
}
}
@@ -814,13 +841,22 @@ void Viewer::mouse(int button, int state, int x, int y)
setFocusedViewport(focus);
}
if (_viewportList[_focusedViewport]._eventHandler.valid() && _viewportList[_focusedViewport]._eventHandler->handle(*ea,*this))
{
// event handler handle this call.
bool handled = false;
for ( EventHandlerList::iterator eh =
_viewportList[_focusedViewport]._eventHandlerList.begin();
eh != _viewportList[_focusedViewport]._eventHandlerList.end();
eh++ ) {
if ( eh->valid() ) {
if ( (*eh)->handle(*ea,*this) ) {
handled = true;
}
}
}
else if (_viewportList[_focusedViewport]._cameraManipulator->handle(*ea,*this))
{
if ( !handled ) {
if ( _viewportList[_focusedViewport]._cameraManipulator->handle(
*ea,*this) ) {
// osg::notify(osg::INFO) << "Handled mouse "<<ea->_buttonMask<<" x="<<ea->_mx<<" y="<<ea->_my<< std::endl;
}
}
}
@@ -832,17 +868,24 @@ void Viewer::keyboard(unsigned char key, int x, int y)
osg::ref_ptr<GLUTEventAdapter> ea = osgNew GLUTEventAdapter;
ea->adaptKeyboard(clockSeconds(),key,x,y);
if (_viewportList[_focusedViewport]._eventHandler.valid() && _viewportList[_focusedViewport]._eventHandler->handle(*ea,*this))
{
return;
bool handled = false;
for ( EventHandlerList::iterator eh =
_viewportList[_focusedViewport]._eventHandlerList.begin();
eh != _viewportList[_focusedViewport]._eventHandlerList.end();
eh++ ) {
if ( eh->valid() ) {
if ( (*eh)->handle(*ea,*this) ) {
return;
}
}
}
else if (_viewportList[_focusedViewport]._cameraManipulator->handle(*ea,*this))
{
return;
if ( !handled ) {
if ( _viewportList[_focusedViewport]._cameraManipulator->handle(
*ea,*this) ) {
return;
}
}
if (key>='1' && key<='3')
{
int pos = key-'1';