| 1 | #include <osgWidget/VncClient> |
|---|
| 2 | |
|---|
| 3 | #include <osgDB/Registry> |
|---|
| 4 | #include <osgViewer/Viewer> |
|---|
| 5 | #include <osgViewer/ViewerEventHandlers> |
|---|
| 6 | |
|---|
| 7 | class EscapeHandler : public osgGA::GUIEventHandler |
|---|
| 8 | { |
|---|
| 9 | public: |
|---|
| 10 | |
|---|
| 11 | EscapeHandler() {} |
|---|
| 12 | |
|---|
| 13 | bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) |
|---|
| 14 | { |
|---|
| 15 | if (ea.getHandled()) return false; |
|---|
| 16 | |
|---|
| 17 | switch(ea.getEventType()) |
|---|
| 18 | { |
|---|
| 19 | case(osgGA::GUIEventAdapter::KEYUP): |
|---|
| 20 | { |
|---|
| 21 | if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Escape) |
|---|
| 22 | { |
|---|
| 23 | osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa); |
|---|
| 24 | if (view) view->getViewerBase()->setDone(true); |
|---|
| 25 | |
|---|
| 26 | return true; |
|---|
| 27 | } |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | default: |
|---|
| 31 | return false; |
|---|
| 32 | } |
|---|
| 33 | return false; |
|---|
| 34 | } |
|---|
| 35 | }; |
|---|
| 36 | |
|---|
| 37 | int main(int argc,char** argv) |
|---|
| 38 | { |
|---|
| 39 | osg::ArgumentParser arguments(&argc, argv); |
|---|
| 40 | osgViewer::Viewer viewer(arguments); |
|---|
| 41 | |
|---|
| 42 | osgWidget::GeometryHints hints(osg::Vec3(0.0f,0.0f,0.0f), |
|---|
| 43 | osg::Vec3(1.0f,0.0f,0.0f), |
|---|
| 44 | osg::Vec3(0.0f,0.0f,1.0f), |
|---|
| 45 | osg::Vec4(1.0f,1.0f,1.0f,1.0f), |
|---|
| 46 | osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO); |
|---|
| 47 | |
|---|
| 48 | osg::ref_ptr<osg::Group> group = new osg::Group; |
|---|
| 49 | |
|---|
| 50 | std::string password; |
|---|
| 51 | while(arguments.read("--password",password)) |
|---|
| 52 | { |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | for(int i=1; i<arguments.argc(); ++i) |
|---|
| 56 | { |
|---|
| 57 | if (!arguments.isOption(i)) |
|---|
| 58 | { |
|---|
| 59 | std::string hostname = arguments[i]; |
|---|
| 60 | |
|---|
| 61 | if (!password.empty()) |
|---|
| 62 | { |
|---|
| 63 | if (!osgDB::Registry::instance()->getAuthenticationMap()) osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap); |
|---|
| 64 | osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails(hostname, new osgDB::AuthenticationDetails("", password)); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | osg::ref_ptr<osgWidget::VncClient> vncClient = new osgWidget::VncClient; |
|---|
| 68 | if (vncClient->connect(arguments[i], hints)) |
|---|
| 69 | { |
|---|
| 70 | group->addChild(vncClient.get()); |
|---|
| 71 | |
|---|
| 72 | hints.position.x() += 1.1f; |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | viewer.setSceneData(group.get()); |
|---|
| 78 | |
|---|
| 79 | viewer.addEventHandler(new osgViewer::StatsHandler); |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | viewer.addEventHandler(new EscapeHandler); |
|---|
| 84 | viewer.setKeyEventSetsDone(0); |
|---|
| 85 | |
|---|
| 86 | return viewer.run(); |
|---|
| 87 | } |
|---|