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

Revision 9323, 2.4 kB (checked in by robert, 9 years ago)

Added support for setting background colour of Pdf document.

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