From: Pierre Ossman Date: Wed, 1 Jun 2011 09:31:53 +0000 (+0000) Subject: Allow resize of the viewport widget. X-Git-Tag: v1.1.90~319 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e00f0aa62b8631456dce54a82211cd779f99ae68;p=tigervnc.git Allow resize of the viewport widget. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4459 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index 3dd53e2f..e574903c 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -196,6 +196,48 @@ void Viewport::draw() } +void Viewport::resize(int x, int y, int w, int h) +{ + rfb::ManagedPixelBuffer* newBuffer; + rfb::Rect rect; + + // FIXME: Resize should probably be a feature of ManagedPixelBuffer + + if ((w == frameBuffer->width()) && (h == frameBuffer->height())) + goto end; + + newBuffer = new ManagedPixelBuffer(frameBuffer->getPF(), w, h); + assert(newBuffer); + + rect.setXYWH(0, 0, + __rfbmin(newBuffer->width(), frameBuffer->width()), + __rfbmin(newBuffer->height(), frameBuffer->height())); + newBuffer->imageRect(rect, frameBuffer->data, frameBuffer->getStride()); + + // Black out any new areas + + if (newBuffer->width() > frameBuffer->width()) { + rect.setXYWH(frameBuffer->width(), 0, + newBuffer->width() - frameBuffer->width(), + newBuffer->height()); + newBuffer->fillRect(rect, 0); + } + + if (newBuffer->height() > frameBuffer->height()) { + rect.setXYWH(0, frameBuffer->height(), + newBuffer->width(), + newBuffer->height() - frameBuffer->height()); + newBuffer->fillRect(rect, 0); + } + + delete frameBuffer; + frameBuffer = newBuffer; + +end: + Fl_Widget::resize(x, y, w, h); +} + + int Viewport::handle(int event) { char *buffer; diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h index f3f60be9..293eb93b 100644 --- a/vncviewer/Viewport.h +++ b/vncviewer/Viewport.h @@ -79,7 +79,11 @@ public: } // Fl_Widget callback methods + void draw(); + + void resize(int x, int y, int w, int h); + int handle(int event); private: