osgUI.HandleCallback是OpenSceneGraph中的一个回调类,用于处理UI事件,如鼠标、键盘等操作。
HandleCallback();
默认构造函数。
void addCallback(Callback* cb);
添加附加的回调(Callback对象)。
void removeCallback(Callback* cb);
移除附加的回调(Callback对象)。
bool run(osgGA::GUIEventAdapter* ea, osgGA::GUIActionAdapter* aa, osg::Object* obj, osg::NodeVisitor* nv);
重载运行函数,用于处理UI事件和执行附加回调。
参数:
返回值:
osg::ref_ptr<osg::Group> uiGroup = new osg::Group();
osg::ref_ptr<osgText::Text> label = new osgText::Text();
label->setPosition(osg::Vec3(100,50,0));
label->setCharacterSize(24);
label->setFont("fonts/arial.ttf");
label->setColor(osg::Vec4(0,1,0,1));
label->setText("Hello, OSGUI");
osgUI::Label* uiLabel = new osgUI::Label(label);
uiLabel->setPosition(50,50);
uiLabel->setFont("fonts/arial.ttf");
uiLabel->setFontSize(24);
uiGroup->addChild(uiLabel);
osgViewer::Viewer viewer;
viewer.setSceneData(root.get());
viewer.addEventHandler(new osgUI::MouseHandler);
viewer.addEventHandler(new osgUI::KeyboardHandler);
viewer.addEventHandler(new osgUI::HandleCallback(uiGroup.get()));
viewer.realize();