|
今天做了个osgGA::GUIEventHandler 的小例子,尽然发觉KEYDOWN事件执行2次,对应的KEYUP事件执行1次,怪了
-
- class TestHandler : public osgGA::GUIEventHandler
- {
- public:
- TestHandler(){}
- ~TestHandler(){}
- bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
- {
- osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
- //if (!viewer) return false;
- switch(ea.getEventType())
- {
- case(osgGA::GUIEventAdapter::KEYUP):
- {
- osg::notify(osg::NOTICE)<<"KEYUP"<<std::endl;
- return false;
- }
- case(osgGA::GUIEventAdapter::KEYDOWN):
- {
- osg::notify(osg::NOTICE)<<"KEYDOWN"<<std::endl;
- }
- case(osgGA::GUIEventAdapter::PUSH):
- case(osgGA::GUIEventAdapter::MOVE):
- {
- return false;
- }
- case(osgGA::GUIEventAdapter::RELEASE):
- {
- return true;
- }
- default:
- return false;
- }
- }
- };
- //main函数中
- osg::ref_ptr<osgViewer::View> view1=new osgViewer::View;
- view1->addEventHandler( new TestHandler());
-
- osgViewer::CompositeViewer *viewer
- //将视口添加到复合视图
- viewer->addView(view1);
复制代码
难道是复合视图的原因? |
|