本文整理汇总了C++中osg::NodeVisitor::asEventVisitor方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeVisitor::asEventVisitor方法的具体用法?C++ NodeVisitor::asEventVisitor怎么用?C++ NodeVisitor::asEventVisitor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::NodeVisitor
的用法示例。
在下文中一共展示了NodeVisitor::asEventVisitor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: traverseImplementation
void Widget::traverseImplementation(osg::NodeVisitor& nv)
{
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
osgGA::EventVisitor* ev = nv.asEventVisitor();
if (ev)
{
updateFocus(nv);
if (getHasEventFocus())
{
// signify that event has been taken by widget with focus
ev->setEventHandled(true);
osgGA::EventQueue::Events& events = ev->getEvents();
for(osgGA::EventQueue::Events::iterator itr = events.begin();
itr != events.end();
++itr)
{
if (handle(ev, itr->get()))
{
(*itr)->setHandled(true);
}
}
}
}
else
{
osg::Group::traverse(nv);
}
}
示例2: traverse
void Dragger::traverse(osg::NodeVisitor& nv)
{
if (_handleEvents && nv.getVisitorType()==osg::NodeVisitor::EVENT_VISITOR)
{
osgGA::EventVisitor* ev = nv.asEventVisitor();
if (ev)
{
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
itr != ev->getEvents().end();
++itr)
{
osgGA::GUIEventAdapter* ea = (*itr)->asGUIEventAdapter();
if (ea && handle(*ea, *(ev->getActionAdapter()))) ea->setHandled(true);
}
}
return;
}
MatrixTransform::traverse(nv);
}
示例3: updateFocus
void Widget::updateFocus(osg::NodeVisitor& nv)
{
osgGA::EventVisitor* ev = nv.asEventVisitor();
osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0;
if (ev && aa)
{
osgGA::EventQueue::Events& events = ev->getEvents();
for(osgGA::EventQueue::Events::iterator itr = events.begin();
itr != events.end();
++itr)
{
osgGA::GUIEventAdapter* ea = (*itr)->asGUIEventAdapter();
if (ea)
{
bool previousFocus = _hasEventFocus;
if (_focusBehaviour==CLICK_TO_FOCUS)
{
if (ea->getEventType()==osgGA::GUIEventAdapter::PUSH)
{
int numButtonsPressed = 0;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) ++numButtonsPressed;
if (numButtonsPressed==1)
{
osgUtil::LineSegmentIntersector::Intersections intersections;
bool withinWidget = aa->computeIntersections(*ea, nv.getNodePath(), intersections);
if (withinWidget) _hasEventFocus = true;
else _hasEventFocus = false;
}
}
}
else if (_focusBehaviour==FOCUS_FOLLOWS_POINTER)
{
bool checkWithinWidget = false;
if (!_hasEventFocus)
{
checkWithinWidget = (ea->getEventType()!=osgGA::GUIEventAdapter::FRAME) && ea->getButtonMask()==0;
}
else
{
// if mouse move or mouse release check to see if mouse still within widget to retain focus
if (ea->getEventType()==osgGA::GUIEventAdapter::MOVE)
{
checkWithinWidget = true;
}
else if (ea->getEventType()==osgGA::GUIEventAdapter::RELEASE)
{
// if no buttons pressed then check
if (ea->getButtonMask()==0) checkWithinWidget = true;
}
}
if (checkWithinWidget)
{
osgUtil::LineSegmentIntersector::Intersections intersections;
bool withinWidget = aa->computeIntersections(*ea, nv.getNodePath(), intersections);
_hasEventFocus = withinWidget;
}
}
if (previousFocus != _hasEventFocus)
{
if (_hasEventFocus)
{
enter();
#if 0
if (view->getCameraManipulator())
{
view->getCameraManipulator()->finishAnimation();
view->requestContinuousUpdate( false );
}
#endif
}
else
{
leave();
}
}
}
}
}
}
示例4: updateFocus
void Widget::updateFocus(osg::NodeVisitor& nv)
{
osgGA::EventVisitor* ev = nv.asEventVisitor();
osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0;
if (ev && aa)
{
// OSG_NOTICE<<"updateFocus"<<std::endl;
osgGA::EventQueue::Events& events = ev->getEvents();
for(osgGA::EventQueue::Events::iterator itr = events.begin();
itr != events.end();
++itr)
{
osgGA::GUIEventAdapter* ea = (*itr)->asGUIEventAdapter();
if (ea)
{
int numButtonsPressed = 0;
if (ea->getEventType()==osgGA::GUIEventAdapter::PUSH)
{
if (ea->getButtonMask()&osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON) ++numButtonsPressed;
if (ea->getButtonMask()&osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) ++numButtonsPressed;
}
bool previousFocus = _hasEventFocus;
if (_focusBehaviour==CLICK_TO_FOCUS)
{
if (ea->getEventType()==osgGA::GUIEventAdapter::PUSH)
{
if (numButtonsPressed==1)
{
osg::Vec3d intersection;
bool withinWidget = computeExtentsPositionInLocalCoordinates(ev, ea, intersection);
if (withinWidget) _hasEventFocus = true;
else _hasEventFocus = false;
}
}
}
else if (_focusBehaviour==FOCUS_FOLLOWS_POINTER)
{
bool checkWithinWidget = false;
if (!_hasEventFocus)
{
checkWithinWidget = (ea->getEventType()!=osgGA::GUIEventAdapter::FRAME) && ea->getButtonMask()==0;
}
else
{
// if mouse move or mouse release check to see if mouse still within widget to retain focus
if (ea->getEventType()==osgGA::GUIEventAdapter::MOVE)
{
checkWithinWidget = true;
}
else if (ea->getEventType()==osgGA::GUIEventAdapter::RELEASE)
{
// if no buttons pressed then check
if (ea->getButtonMask()==0) checkWithinWidget = true;
}
}
if (checkWithinWidget)
{
osg::Vec3d intersection;
bool withinWidget = computeExtentsPositionInLocalCoordinates(ev, ea, intersection);
_hasEventFocus = withinWidget;
}
}
if (_hasEventFocus && (ea->getEventType()==osgGA::GUIEventAdapter::PUSH || ea->getEventType()==osgGA::GUIEventAdapter::SCROLL) )
{
osgViewer::View* view = dynamic_cast<osgViewer::View*>(aa);
if (view && view->getCameraManipulator())
{
view->getCameraManipulator()->finishAnimation();
view->requestContinuousUpdate( false );
}
}
if (previousFocus != _hasEventFocus)
{
if (_hasEventFocus)
{
enter();
}
else
{
leave();
}
}
}
}
}
}
示例5: traverseImplementation
void Widget::traverseImplementation(osg::NodeVisitor& nv)
{
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
osgGA::EventVisitor* ev = nv.asEventVisitor();
if (ev)
{
if (_visible && _enabled)
{
updateFocus(nv);
// OSG_NOTICE<<"EventTraversal getHasEventFocus()="<<getHasEventFocus()<<std::endl;
// signify that event has been taken by widget with focus
bool widgetsWithFocusSetHandled = getHasEventFocus();
osgGA::EventQueue::Events& events = ev->getEvents();
for(osgGA::EventQueue::Events::iterator itr = events.begin();
itr != events.end();
++itr)
{
if (handle(ev, itr->get()) || widgetsWithFocusSetHandled)
{
(*itr)->setHandled(true);
ev->setEventHandled(true);
}
}
GraphicsSubgraphMap::iterator itr = _graphicsSubgraphMap.begin();
while(itr!= _graphicsSubgraphMap.end() && itr->first<=0)
{
itr->second->accept(nv);
++itr;
}
osg::Group::traverse(nv);
while(itr!= _graphicsSubgraphMap.end())
{
itr->second->accept(nv);
++itr;
}
}
}
else if (_visible ||
(nv.getVisitorType()!=osg::NodeVisitor::UPDATE_VISITOR && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR && nv.getVisitorType()!=osg::NodeVisitor::INTERSECTION_VISITOR) )
{
osgUtil::CullVisitor* cv = (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) ? nv.asCullVisitor() : 0;
if (cv && _widgetStateSet.valid()) cv->pushStateSet(_widgetStateSet.get());
GraphicsSubgraphMap::iterator itr = _graphicsSubgraphMap.begin();
while(itr!= _graphicsSubgraphMap.end() && itr->first<=0)
{
itr->second->accept(nv);
++itr;
}
Group::traverse(nv);
while(itr!= _graphicsSubgraphMap.end())
{
itr->second->accept(nv);
++itr;
}
if (cv && _widgetStateSet.valid()) cv->popStateSet();
}
}