|
楼主 |
发表于 2012-10-19 08:45:34
|
显示全部楼层
这部分是接收的消息处理
- bool MYGUIHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
- {
- int width = ea.getWindowWidth(), height = ea.getWindowHeight();
- switch ( ea.getEventType() )
- {
- case osgGA::GUIEventAdapter::RESIZE:
- if ( _camera.valid() )
- {
- _camera->setProjectionMatrix( osg::Matrixd::ortho2D(0.0, width, 0.0, height) );
- _camera->setViewport( 0.0, 0.0, width, height );
- }
- break;
- default:
- break;
- }
- // As MyGUI handle all events within the OpenGL context, we have to record the event here
- // and process it later in the draw implementation
- if ( (ea.getEventType()!=osgGA::GUIEventAdapter::FRAME) && _manager )
- _manager->pushEvent( &ea );
- return _manager->_bHanlded;
- }
复制代码
这部分是Event队列处理
- void MYGUIManager::updateEvents() const
- {
- unsigned int size = _eventsToHandle.size();
- for ( unsigned int i=0; i<size; ++i )
- {
- const osgGA::GUIEventAdapter& ea = *(_eventsToHandle.front());
- int x = ea.getX(), y = ea.getY(), key = ea.getKey();
- if ( ea.getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS )
- y = ea.getWindowHeight() - y;
- switch ( ea.getEventType() )
- {
- case osgGA::GUIEventAdapter::PUSH:
- _bHanlded = MyGUI::InputManager::getInstance().injectMousePress( x, y, convertMouseButton(ea.getButton()));
- break;
- case osgGA::GUIEventAdapter::RELEASE:
- _bHanlded = MyGUI::InputManager::getInstance().injectMouseRelease( x, y, convertMouseButton(ea.getButton()) );
- break;
- case osgGA::GUIEventAdapter::DRAG:
- case osgGA::GUIEventAdapter::MOVE:
- _bHanlded = MyGUI::InputManager::getInstance().injectMouseMove( x, y, 0 );
- break;
- case osgGA::GUIEventAdapter::KEYDOWN:
- if ( key<127 )
- _bHanlded = MyGUI::InputManager::getInstance().injectKeyPress( convertKeyCode(key), (char)key );
- else
- _bHanlded = MyGUI::InputManager::getInstance().injectKeyPress( convertKeyCode(key) );
- break;
- case osgGA::GUIEventAdapter::IME:
- _bHanlded = MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::None, (MyGUI::Char)ea.getCode());
- break;
- case osgGA::GUIEventAdapter::KEYUP:
- _bHanlded = MyGUI::InputManager::getInstance().injectKeyRelease( convertKeyCode(key) );
- break;
- case osgGA::GUIEventAdapter::RESIZE:
- _platform->getRenderManagerPtr()->setViewSize( ea.getWindowWidth(), ea.getWindowHeight() );
- break;
- default:
- break;
- }
- const_cast<MYGUIManager*>(this)->_eventsToHandle.pop();
- }
- }
复制代码 |
|