root/OpenSceneGraph/trunk/src/osgWidget/VncClient.cpp @ 13041

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

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgDB/ReadFile>
15#include <osgViewer/ViewerEventHandlers>
16#include <osgWidget/VncClient>
17
18using namespace osgWidget;
19
20VncClient::VncClient(const std::string& hostname, const GeometryHints& hints)
21{
22    connect(hostname, hints);
23}
24
25bool VncClient::assign(VncImage* vncImage, const GeometryHints& hints)
26{
27    if (!vncImage) return false;
28
29    _vncImage = vncImage;
30
31    bool flip = _vncImage->getOrigin()==osg::Image::TOP_LEFT;
32
33    float aspectRatio = (_vncImage->t()>0 && _vncImage->s()>0) ? float(_vncImage->t()) / float(_vncImage->s()) : 1.0;
34
35    osg::Vec3 widthVec(hints.widthVec);
36    osg::Vec3 heightVec(hints.heightVec);
37
38    switch(hints.aspectRatioPolicy)
39    {
40        case(GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO):
41            heightVec *= aspectRatio;
42            break;
43        case(GeometryHints::RESIZE_WIDTH_TO_MAINTAINCE_ASPECT_RATIO):
44            widthVec /= aspectRatio;
45            break;
46        default:
47            // no need to adjust aspect ratio
48            break;
49    }
50
51    osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(hints.position, widthVec, heightVec,
52                                       0.0f, flip ? 1.0f : 0.0f , 1.0f, flip ? 0.0f : 1.0f);
53
54    osg::Texture2D* texture = new osg::Texture2D(_vncImage.get());
55    texture->setResizeNonPowerOfTwoHint(false);
56    texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
57    texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
58    texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
59
60    pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0,
61                texture,
62                osg::StateAttribute::ON);
63
64    pictureQuad->setEventCallback(new osgViewer::InteractiveImageHandler(_vncImage.get()));
65
66    addDrawable(pictureQuad);
67
68    return true;
69}
70
71bool VncClient::connect(const std::string& hostname, const GeometryHints& hints)
72{
73    osg::ref_ptr<osg::Image> image = osgDB::readImageFile(hostname+".vnc");
74    return assign(dynamic_cast<VncImage*>(image.get()), hints);
75}
76
77void VncClient::close()
78{
79    if (!_vncImage) return;
80
81    _vncImage->close();
82}
Note: See TracBrowser for help on using the browser.