From 3c68f5f6fe8f5d1abf6fcafb6ceaa9d2c7811346 Mon Sep 17 00:00:00 2001 From: george82 Date: Tue, 5 Sep 2006 06:17:01 +0000 Subject: [PATCH] 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 --- win/vncviewer/DesktopWindow.cxx | 22 ++++++++++++++++++++++ win/vncviewer/DesktopWindow.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/win/vncviewer/DesktopWindow.cxx b/win/vncviewer/DesktopWindow.cxx index f96c7e44..babcd45b 100644 --- a/win/vncviewer/DesktopWindow.cxx +++ b/win/vncviewer/DesktopWindow.cxx @@ -946,6 +946,28 @@ void DesktopWindow::setDesktopScale(int scale) { 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(); diff --git a/win/vncviewer/DesktopWindow.h b/win/vncviewer/DesktopWindow.h index f471fccb..f0db4275 100644 --- a/win/vncviewer/DesktopWindow.h +++ b/win/vncviewer/DesktopWindow.h @@ -83,6 +83,7 @@ namespace rfb { void setSize(int w, int h); void setColour(int i, int r, int g, int b) {buffer->setColour(i, r, g, b);} void setDesktopScale(int scale); + void fitBufferToWindow(bool repaint = true); // - Set the cursor to render when the pointer is within the desktop buffer void setCursor(int w, int h, const Point& hotspot, void* data, void* mask); @@ -236,6 +237,7 @@ namespace rfb { // Local window state win32::ScaledDIBSectionBuffer* buffer; + double aspect_corr; bool has_focus; Rect window_size; Rect client_size; -- 2.39.5