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.
This commit is contained in:
@@ -16,32 +16,30 @@
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/Registry>
|
||||
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include <osgWidget/VncClient>
|
||||
|
||||
extern "C" {
|
||||
#include <rfb/rfbclient.h>
|
||||
}
|
||||
|
||||
class VncImage : public osg::Image
|
||||
class LibVncImage : public osgWidget::VncImage
|
||||
{
|
||||
public:
|
||||
|
||||
VncImage();
|
||||
LibVncImage();
|
||||
|
||||
bool connect(int* argc, char** argv);
|
||||
|
||||
bool connect(const std::string& hostname, const osgDB::ReaderWriter::Options* options);
|
||||
bool connect(const std::string& hostname);
|
||||
|
||||
void close();
|
||||
|
||||
virtual void sendPointerEvent(int x, int y, int buttonMask);
|
||||
virtual bool sendPointerEvent(int x, int y, int buttonMask);
|
||||
|
||||
double getTimeOfLastUpdate() const { return _timeOfLastUpdate; }
|
||||
double getTimeOfLastRender() const { return _timeOfLastRender; }
|
||||
|
||||
double time() const { return osg::Timer::instance()->time_s(); }
|
||||
|
||||
virtual void sendKeyEvent(int key, bool keyDown);
|
||||
virtual bool sendKeyEvent(int key, bool keyDown);
|
||||
|
||||
virtual void setFrameLastRendered(const osg::FrameStamp* frameStamp);
|
||||
|
||||
@@ -59,13 +57,13 @@ class VncImage : public osg::Image
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~VncImage();
|
||||
virtual ~LibVncImage();
|
||||
|
||||
class RfbThread : public osg::Referenced, public OpenThreads::Thread
|
||||
{
|
||||
public:
|
||||
|
||||
RfbThread(rfbClient* client, VncImage* image):
|
||||
RfbThread(rfbClient* client, LibVncImage* image):
|
||||
_client(client),
|
||||
_image(image),
|
||||
_done(false) {}
|
||||
@@ -119,9 +117,9 @@ class VncImage : public osg::Image
|
||||
} while (!_done && !testCancel());
|
||||
}
|
||||
|
||||
rfbClient* _client;
|
||||
osg::observer_ptr<VncImage> _image;
|
||||
bool _done;
|
||||
rfbClient* _client;
|
||||
osg::observer_ptr<LibVncImage> _image;
|
||||
bool _done;
|
||||
|
||||
};
|
||||
|
||||
@@ -133,7 +131,7 @@ class VncImage : public osg::Image
|
||||
|
||||
};
|
||||
|
||||
VncImage::VncImage():
|
||||
LibVncImage::LibVncImage():
|
||||
_client(0)
|
||||
{
|
||||
// setPixelBufferObject(new osg::PixelBufferObject(this);
|
||||
@@ -142,40 +140,11 @@ VncImage::VncImage():
|
||||
|
||||
}
|
||||
|
||||
VncImage::~VncImage()
|
||||
LibVncImage::~LibVncImage()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
bool VncImage::connect(int* argc, char** argv)
|
||||
{
|
||||
if (_client) close();
|
||||
|
||||
|
||||
_client = rfbGetClient(8,3,4);
|
||||
_client->canHandleNewFBSize = TRUE;
|
||||
_client->MallocFrameBuffer = resizeImage;
|
||||
_client->GotFrameBufferUpdate = updateImage;
|
||||
_client->HandleKeyboardLedState = 0;
|
||||
_client->HandleTextChat = 0;
|
||||
|
||||
rfbClientSetClientData(_client, 0, this);
|
||||
|
||||
if (rfbInitClient(_client,argc,argv))
|
||||
{
|
||||
_rfbThread = new RfbThread(_client, this);
|
||||
_rfbThread->startThread();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
close();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static rfbBool rfbInitConnection(rfbClient* client)
|
||||
{
|
||||
/* Unless we accepted an incoming connection, make a TCP connection to the
|
||||
@@ -229,7 +198,7 @@ static rfbBool rfbInitConnection(rfbClient* client)
|
||||
}
|
||||
|
||||
|
||||
bool VncImage::connect(const std::string& hostname, const osgDB::ReaderWriter::Options* options)
|
||||
bool LibVncImage::connect(const std::string& hostname)
|
||||
{
|
||||
if (hostname.empty()) return false;
|
||||
|
||||
@@ -268,7 +237,7 @@ bool VncImage::connect(const std::string& hostname, const osgDB::ReaderWriter::O
|
||||
}
|
||||
|
||||
|
||||
void VncImage::close()
|
||||
void LibVncImage::close()
|
||||
{
|
||||
if (_rfbThread.valid())
|
||||
{
|
||||
@@ -287,7 +256,7 @@ void VncImage::close()
|
||||
}
|
||||
|
||||
|
||||
rfbBool VncImage::resizeImage(rfbClient* client)
|
||||
rfbBool LibVncImage::resizeImage(rfbClient* client)
|
||||
{
|
||||
osg::Image* image = (osg::Image*)(rfbClientGetClientData(client, 0));
|
||||
|
||||
@@ -304,30 +273,32 @@ rfbBool VncImage::resizeImage(rfbClient* client)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void VncImage::updateImage(rfbClient* client,int x,int y,int w,int h)
|
||||
void LibVncImage::updateImage(rfbClient* client,int x,int y,int w,int h)
|
||||
{
|
||||
osg::Image* image = (osg::Image*)(rfbClientGetClientData(client, 0));
|
||||
image->dirty();
|
||||
}
|
||||
|
||||
void VncImage::sendPointerEvent(int x, int y, int buttonMask)
|
||||
bool LibVncImage::sendPointerEvent(int x, int y, int buttonMask)
|
||||
{
|
||||
if (_client)
|
||||
{
|
||||
SendPointerEvent(_client ,x, y, buttonMask);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void VncImage::sendKeyEvent(int key, bool keyDown)
|
||||
bool LibVncImage::sendKeyEvent(int key, bool keyDown)
|
||||
{
|
||||
if (_client)
|
||||
{
|
||||
SendKeyEvent(_client, key, keyDown ? TRUE : FALSE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VncImage::setFrameLastRendered(const osg::FrameStamp*)
|
||||
void LibVncImage::setFrameLastRendered(const osg::FrameStamp*)
|
||||
{
|
||||
_timeOfLastRender = time();
|
||||
|
||||
@@ -335,7 +306,7 @@ void VncImage::setFrameLastRendered(const osg::FrameStamp*)
|
||||
_active = true;
|
||||
}
|
||||
|
||||
void VncImage::updated()
|
||||
void LibVncImage::updated()
|
||||
{
|
||||
_timeOfLastUpdate = time();
|
||||
}
|
||||
@@ -367,12 +338,12 @@ class ReaderWriterVNC : public osgDB::ReaderWriter
|
||||
|
||||
osg::notify(osg::NOTICE)<<"Hostname = "<<hostname<<std::endl;
|
||||
|
||||
osg::ref_ptr<VncImage> image = new VncImage;
|
||||
osg::ref_ptr<LibVncImage> image = new LibVncImage;
|
||||
image->setDataVariance(osg::Object::DYNAMIC);
|
||||
|
||||
image->setOrigin(osg::Image::TOP_LEFT);
|
||||
|
||||
if (!image->connect(hostname, options))
|
||||
if (!image->connect(hostname))
|
||||
{
|
||||
return "Could not connect to "+hostname;
|
||||
}
|
||||
@@ -385,38 +356,16 @@ class ReaderWriterVNC : public osgDB::ReaderWriter
|
||||
osgDB::ReaderWriter::ReadResult result = readImage(fileName, options);
|
||||
if (!result.validImage()) return result;
|
||||
|
||||
osg::Image* image = result.getImage();
|
||||
|
||||
bool xyPlane = false;
|
||||
bool flip = image->getOrigin()==osg::Image::TOP_LEFT;
|
||||
osg::Vec3 origin = osg::Vec3(0.0f,0.0f,0.0f);
|
||||
float width = 1.0;
|
||||
float height = float(image->t())/float(image->s());
|
||||
osg::Vec3 widthAxis = osg::Vec3(width,0.0f,0.0f);
|
||||
osg::Vec3 heightAxis = xyPlane ? osg::Vec3(0.0f,height,0.0f) : osg::Vec3(0.0f,0.0f,height);
|
||||
|
||||
osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(origin, widthAxis, heightAxis,
|
||||
0.0f, flip ? 1.0f : 0.0f , 1.0f, flip ? 0.0f : 1.0f);
|
||||
|
||||
osg::Texture2D* texture = new osg::Texture2D(image);
|
||||
texture->setResizeNonPowerOfTwoHint(false);
|
||||
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
||||
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
||||
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
||||
|
||||
pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0,
|
||||
texture,
|
||||
osg::StateAttribute::ON);
|
||||
|
||||
osg::ref_ptr<osgViewer::InteractiveImageHandler> callback = new osgViewer::InteractiveImageHandler(image);
|
||||
|
||||
pictureQuad->setEventCallback(callback.get());
|
||||
pictureQuad->setCullCallback(callback.get());
|
||||
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addDrawable(pictureQuad);
|
||||
|
||||
return geode;
|
||||
osg::ref_ptr<osgWidget::VncClient> vncClient = new osgWidget::VncClient();
|
||||
if (vncClient->assign(dynamic_cast<osgWidget::VncImage*>(result.getImage())))
|
||||
{
|
||||
return vncClient.release();
|
||||
}
|
||||
else
|
||||
{
|
||||
return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user