From ffc14a60cfd1ad93dc54fab586ee20ca14b548b9 Mon Sep 17 00:00:00 2001 From: george82 Date: Tue, 5 Sep 2006 06:51:41 +0000 Subject: [PATCH] Added the autoScaling mode implementation to the vncviewer. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@645 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- win/vncviewer/CConn.cxx | 9 +++++++-- win/vncviewer/DesktopWindow.cxx | 23 ++++++++++++++++------- win/vncviewer/DesktopWindow.h | 6 ++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/win/vncviewer/CConn.cxx b/win/vncviewer/CConn.cxx index 9f597ed0..2fb8d2d3 100644 --- a/win/vncviewer/CConn.cxx +++ b/win/vncviewer/CConn.cxx @@ -150,7 +150,12 @@ CConn::applyOptions(CConnOptions& opt) { window->setMenuKey(options.menuKey); window->setDisableWinKeys(options.disableWinKeys); window->setShowToolbar(options.showToolbar); - window->setDesktopScale(options.scale); + if (options.autoScaling) { + window->setAutoScaling(true); + } else { + window->setAutoScaling(false); + window->setDesktopScale(options.scale); + } if (!options.useLocalCursor) window->setCursor(0, 0, Point(), 0, 0); } @@ -611,9 +616,9 @@ void CConn::serverInit() { // Show the window window = new DesktopWindow(this); - applyOptions(options); window->setName(cp.name()); window->setSize(cp.width, cp.height); + applyOptions(options); // Save the server's current format serverDefaultPF = cp.pf(); diff --git a/win/vncviewer/DesktopWindow.cxx b/win/vncviewer/DesktopWindow.cxx index babcd45b..00f4c10f 100644 --- a/win/vncviewer/DesktopWindow.cxx +++ b/win/vncviewer/DesktopWindow.cxx @@ -181,7 +181,7 @@ FrameClass frameClass; DesktopWindow::DesktopWindow(Callback* cb) : buffer(0), - showToolbar(false), + showToolbar(false), autoScaling(false), client_size(0, 0, 16, 16), window_size(0, 0, 32, 32), cursorVisible(false), cursorAvailable(false), cursorInBuffer(false), systemCursorVisible(true), trackingMouseLeave(false), @@ -406,7 +406,7 @@ DesktopWindow::processMessage(UINT msg, WPARAM wParam, LPARAM lParam) { case WM_WINDOWPOSCHANGING: { WINDOWPOS* wpos = (WINDOWPOS*)lParam; - if (wpos->flags & SWP_NOSIZE) + if ((wpos->flags & SWP_NOSIZE) || isAutoScaling()) break; // Work out how big the window should ideally be @@ -469,11 +469,16 @@ DesktopWindow::processMessage(UINT msg, WPARAM wParam, LPARAM lParam) { GetClientRect(frameHandle, &r); client_size = Rect(r.left, r.top, r.right, r.bottom); - // Determine whether scrollbars are required - calculateScrollBars(); + // Perform the AutoScaling operation + if (isAutoScaling()) { + fitBufferToWindow(false); + } else { + // Determine whether scrollbars are required + calculateScrollBars(); + } // Redraw if required - if ((!old_offset.equals(desktopToClient(Point(0, 0))))) + if ((!old_offset.equals(desktopToClient(Point(0, 0)))) || isAutoScaling()) InvalidateRect(frameHandle, 0, TRUE); } break; @@ -791,8 +796,8 @@ DesktopWindow::processFrameMessage(UINT msg, WPARAM wParam, LPARAM lParam) { // Send a pointer event to the server oldpos = p; if (buffer->isScaling()) { - p.x /= double(buffer->getScale()) / 100.0; - p.y /= double(buffer->getScale()) / 100.0; + p.x /= buffer->getScaleRatio(); + p.y /= buffer->getScaleRatio(); } ptr.pointerEvent(callback, p, mask); #ifdef WM_MOUSEWHEEL @@ -917,6 +922,10 @@ DesktopWindow::setSize(int w, int h) { // Resize the backing buffer buffer->setSize(w, h); + // Calculate the pixel buffer aspect correlation. It's used + // for the autoScaling operation. + aspect_corr = (double)w / h; + // If the window is not maximised or full-screen then resize it if (!(GetWindowLong(handle, GWL_STYLE) & WS_MAXIMIZE) && !fullscreenActive) { // Resize the window to the required size diff --git a/win/vncviewer/DesktopWindow.h b/win/vncviewer/DesktopWindow.h index f0db4275..c24b0ced 100644 --- a/win/vncviewer/DesktopWindow.h +++ b/win/vncviewer/DesktopWindow.h @@ -82,6 +82,11 @@ namespace rfb { PixelFormat getPF() const { return buffer->getPF(); } void setSize(int w, int h); void setColour(int i, int r, int g, int b) {buffer->setColour(i, r, g, b);} + void setAutoScaling(bool as) { + autoScaling = as; + if (as) fitBufferToWindow(); + } + bool isAutoScaling() const { return autoScaling; } void setDesktopScale(int scale); void fitBufferToWindow(bool repaint = true); @@ -239,6 +244,7 @@ namespace rfb { win32::ScaledDIBSectionBuffer* buffer; double aspect_corr; bool has_focus; + bool autoScaling; Rect window_size; Rect client_size; Point scrolloffset; -- 2.39.5