root/OpenSceneGraph/trunk/examples/osgvnc/osgvnc.cpp @ 12851

Revision 12851, 2.7 kB (checked in by robert, 3 years ago)

Added password support into osgvnc example and vnc plugin

  • Property svn:eol-style set to native
RevLine 
[9323]1#include <osgWidget/VncClient>
2
[12851]3#include <osgDB/Registry>
[9082]4#include <osgViewer/Viewer>
5#include <osgViewer/ViewerEventHandlers>
6
[9090]7class EscapeHandler : public osgGA::GUIEventHandler
[9083]8{
[9090]9    public:
[9083]10   
[9090]11        EscapeHandler() {}
[9083]12
[9090]13        bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
[9083]14        {
[9090]15            if (ea.getHandled()) return false;
[9083]16
[9090]17            switch(ea.getEventType())
[9083]18            {
[9090]19                case(osgGA::GUIEventAdapter::KEYUP):
[9083]20                {
[9090]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                    }
[9083]28                }
29
[9090]30                default:
31                    return false;
32            }
33            return false;
[9083]34        }
[9090]35};
[9083]36
[9090]37int main(int argc,char** argv)
38{
39    osg::ArgumentParser arguments(&argc, argv);
[9319]40    osgViewer::Viewer viewer(arguments);
[9082]41
[9324]42    osgWidget::GeometryHints hints(osg::Vec3(0.0f,0.0f,0.0f),
[9319]43                                   osg::Vec3(1.0f,0.0f,0.0f),
44                                   osg::Vec3(0.0f,0.0f,1.0f),
[9323]45                                   osg::Vec4(1.0f,1.0f,1.0f,1.0f),
[9319]46                                   osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO);
[9082]47
[9319]48    osg::ref_ptr<osg::Group> group = new osg::Group;
[9082]49
[12851]50    std::string password;
51    while(arguments.read("--password",password))
52    {
53    }
54
[9319]55    for(int i=1; i<arguments.argc(); ++i)
[9090]56    {
[9319]57        if (!arguments.isOption(i))
58        {
[12851]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
[9319]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        }
[9090]75    }
[9082]76
[9319]77    viewer.setSceneData(group.get());
78
[9082]79    viewer.addEventHandler(new osgViewer::StatsHandler);
[9319]80
[9090]81    // add a custom escape handler, but disable the standard viewer one to enable the vnc images to handle
82    // the escape without it getting caught by the viewer.
83    viewer.addEventHandler(new EscapeHandler);   
[9083]84    viewer.setKeyEventSetsDone(0);
[9082]85
86    return viewer.run();
87}
Note: See TracBrowser for help on using the browser.