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

Revision 9324, 2.2 kB (checked in by robert, 5 years ago)

Cleaned up osgWidget::VncClient? and osgWidget::Browser so that their implementations are all more consitent with the osgWidget::PdfReader?.

Line 
1#include <osgWidget/VncClient>
2
3#include <osgViewer/Viewer>
4#include <osgViewer/ViewerEventHandlers>
5
6class EscapeHandler : public osgGA::GUIEventHandler
7{
8    public:
9   
10        EscapeHandler() {}
11
12        bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
13        {
14            if (ea.getHandled()) return false;
15
16            switch(ea.getEventType())
17            {
18                case(osgGA::GUIEventAdapter::KEYUP):
19                {
20                    if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Escape)
21                    {
22                        osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
23                        if (view) view->getViewerBase()->setDone(true);
24                       
25                        return true;
26                    }
27                }
28
29                default:
30                    return false;
31            }
32            return false;
33        }
34};
35
36int main(int argc,char** argv)
37{
38    osg::ArgumentParser arguments(&argc, argv);
39    osgViewer::Viewer viewer(arguments);
40
41    osgWidget::GeometryHints hints(osg::Vec3(0.0f,0.0f,0.0f),
42                                   osg::Vec3(1.0f,0.0f,0.0f),
43                                   osg::Vec3(0.0f,0.0f,1.0f),
44                                   osg::Vec4(1.0f,1.0f,1.0f,1.0f),
45                                   osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO);
46
47    osg::ref_ptr<osg::Group> group = new osg::Group;
48
49    for(int i=1; i<arguments.argc(); ++i)
50    {
51        if (!arguments.isOption(i))
52        {
53            osg::ref_ptr<osgWidget::VncClient> vncClient = new osgWidget::VncClient;
54            if (vncClient->connect(arguments[i], hints))
55            {           
56                group->addChild(vncClient.get());
57               
58                hints.position.x() += 1.1f;
59            }
60        }
61    }
62
63    viewer.setSceneData(group.get());
64
65    viewer.addEventHandler(new osgViewer::StatsHandler);
66
67    // add a custom escape handler, but disable the standard viewer one to enable the vnc images to handle
68    // the escape without it getting caught by the viewer.
69    viewer.addEventHandler(new EscapeHandler);   
70    viewer.setKeyEventSetsDone(0);
71
72    return viewer.run();
73}
Note: See TracBrowser for help on using the browser.