Added DesktopWindow::fitBufferToWindow() method.
It's used to scale buffer to the vncviewer client window.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@643 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/win/vncviewer/DesktopWindow.cxx b/win/vncviewer/DesktopWindow.cxx
index f96c7e4..babcd45 100644
--- a/win/vncviewer/DesktopWindow.cxx
+++ b/win/vncviewer/DesktopWindow.cxx
@@ -946,6 +946,28 @@
calculateScrollBars();
}
+void DesktopWindow::fitBufferToWindow(bool repaint) {
+ double scale_ratio;
+ double resized_aspect_corr = double(client_size.width()) / client_size.height();
+ DWORD style = GetWindowLong(frameHandle, GWL_STYLE);
+ if (style & (WS_VSCROLL | WS_HSCROLL)) {
+ style &= ~(WS_VSCROLL | WS_HSCROLL);
+ SetWindowLong(frameHandle, GWL_STYLE, style);
+ SetWindowPos(frameHandle, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
+ // Update the cached client size
+ RECT r;
+ GetClientRect(frameHandle, &r);
+ client_size = Rect(r.left, r.top, r.right, r.bottom);
+ }
+ if (resized_aspect_corr > aspect_corr) {
+ scale_ratio = double(client_size.height()) / buffer->getSrcHeight();
+ } else {
+ scale_ratio = double(client_size.width()) / buffer->getSrcWidth();
+ }
+ buffer->setScaleRatio(scale_ratio);
+ if (repaint) InvalidateRect(frameHandle, 0, TRUE);
+}
+
void
DesktopWindow::setCursor(int w, int h, const Point& hotspot, void* data, void* mask) {
hideLocalCursor();