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

Revision 9319, 2.3 kB (checked in by robert, 6 years ago)

Intoduce new osgWidget::PdfReader? and osgWidget::VncClient? front ends to osgWidget,
with new pdf plugin and updated vnc plugin that now support these front ends.

Updated osgpdf and osgvnc examples to new these new interfaces.

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