Added EventHandler to report key and mouse events for debugging purposes

This commit is contained in:
Robert Osfield 2018-04-04 13:40:06 +01:00
parent fdc7d225a0
commit 38534c453a

View File

@ -125,6 +125,42 @@ public:
};
class EventHandler : public osgGA::GUIEventHandler {
public:
EventHandler() {}
~EventHandler() {}
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
if (!view) return false;
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::KEYDOWN):
case(osgGA::GUIEventAdapter::KEYUP):
OSG_NOTICE<<"View "<<view<<", name="<<view->getName()<<" keyboard event "<<ea.getEventType()<<" key="<<ea.getKey()<<" ea.getX()="<<ea.getX()<<" ea.getY()="<<ea.getY()<<std::endl;
break;
case(osgGA::GUIEventAdapter::MOVE):
case(osgGA::GUIEventAdapter::DRAG):
case(osgGA::GUIEventAdapter::PUSH):
case(osgGA::GUIEventAdapter::RELEASE):
OSG_NOTICE<<"View "<<view<<", name="<<view->getName()<<" mouse event "<<ea.getEventType()<<" ea.getX()="<<ea.getX()<<" ea.getY()="<<ea.getY()<<std::endl;
break;
default:
// OSG_NOTICE<<"View "<<view<<", name="<<view->getName()<<" general event "<<ea.getEventType()<<std::endl;
break;
}
return false;
}
};
int main( int argc, char **argv )
{
@ -217,6 +253,8 @@ int main( int argc, char **argv )
statesetManipulator->setStateSet(view->getCamera()->getOrCreateStateSet());
view->addEventHandler( statesetManipulator.get() );
view->addEventHandler( new EventHandler());
}
// view two
@ -234,6 +272,8 @@ int main( int argc, char **argv )
// add the handler for doing the picking
view->addEventHandler(new PickHandler());
view->addEventHandler( new EventHandler());
}
}