Skip to content

Commit

Permalink
Added EventHandler to report key and mouse events for debugging purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Apr 4, 2018
1 parent fdc7d22 commit 38534c4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/osgcompositeviewer/osgcompositeviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,42 @@ class PickHandler : public osgGA::GUIEventHandler {

};

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 )
{
Expand Down Expand Up @@ -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
Expand All @@ -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());
}
}

Expand Down

0 comments on commit 38534c4

Please sign in to comment.