From 9b6756114b89c37d607705713bd7705cf08c8a20 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 16 Apr 2015 17:39:45 -0500 Subject: [PATCH] Scale mouse coordinates based on window size - Fixed: If you enlarged the game window (in windowed mode) so that the window is bigger than the selected resolution, the menu would still take its inputs from the portion in the upper left that matched the resolution. --- src/v_video.h | 4 ++-- src/win32/fb_d3d9.cpp | 22 ++++++++++++++++++++++ src/win32/fb_ddraw.cpp | 13 +++++++++++++ src/win32/i_input.cpp | 8 ++++---- src/win32/win32iface.h | 5 ++--- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/v_video.h b/src/v_video.h index 69741c7f80..5250cdaa97 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -398,8 +398,8 @@ public: virtual void WipeEndScreen(); virtual bool WipeDo(int ticks); virtual void WipeCleanup(); - virtual int GetPixelDoubling() const { return 0; } - virtual int GetTrueHeight() { return GetHeight(); } + + virtual void ScaleCoordsFromWindow(SWORD &x, SWORD &y) {} uint32 GetLastFPS() const { return LastCount; } diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index e232757344..9fd1854318 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -1028,6 +1028,28 @@ bool D3DFB::IsFullscreen () return !Windowed; } +//========================================================================== +// +// D3DFB :: ScaleCoordsFromWindow +// +// Given coordinates in window space, return coordinates in what the game +// thinks screen space is. +// +//========================================================================== + +void D3DFB::ScaleCoordsFromWindow(SWORD &x, SWORD &y) +{ + RECT rect; + + if (GetClientRect(Window, &rect)) + { + x = SWORD(x * Width / (rect.right - rect.left)); + y = SWORD(y * TrueHeight / (rect.bottom - rect.top)); + } + // Subtract letterboxing borders + y -= (TrueHeight - Height) / 2; +} + //========================================================================== // // D3DFB :: Lock diff --git a/src/win32/fb_ddraw.cpp b/src/win32/fb_ddraw.cpp index 2aa694f3b4..ecf570ff88 100644 --- a/src/win32/fb_ddraw.cpp +++ b/src/win32/fb_ddraw.cpp @@ -806,6 +806,19 @@ bool DDrawFB::Is8BitMode() return vid_displaybits == 8; } +void DDrawFB::ScaleCoordsFromWindow(SWORD &x, SWORD &y) +{ + RECT rect; + + if (GetClientRect(Window, &rect)) + { + x = SWORD(x * Width / (rect.right - rect.left)); + y = SWORD(y * TrueHeight / (rect.bottom - rect.top)); + } + // Subtract letterboxing borders + y -= (TrueHeight - Height) / 2; +} + bool DDrawFB::IsValid () { return PrimarySurf != NULL; diff --git a/src/win32/i_input.cpp b/src/win32/i_input.cpp index ed7c81cf17..a26ff320e6 100644 --- a/src/win32/i_input.cpp +++ b/src/win32/i_input.cpp @@ -323,11 +323,11 @@ bool GUIWndProcHook(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESU if (BlockMouseMove > 0) return true; } + ev.data1 = LOWORD(lParam); + ev.data2 = HIWORD(lParam); + if (screen != NULL) { - int shift = screen? screen->GetPixelDoubling() : 0; - ev.data1 = LOWORD(lParam) >> shift; - ev.data2 = HIWORD(lParam) >> shift; - if (screen) ev.data2 -= (screen->GetTrueHeight() - screen->GetHeight())/2; + screen->ScaleCoordsFromWindow(ev.data1, ev.data2); } if (wParam & MK_SHIFT) ev.data3 |= GKM_SHIFT; diff --git a/src/win32/win32iface.h b/src/win32/win32iface.h index 2704de0fa4..9699157cd9 100644 --- a/src/win32/win32iface.h +++ b/src/win32/win32iface.h @@ -164,8 +164,8 @@ public: void SetVSync (bool vsync); void NewRefreshRate(); HRESULT GetHR (); - virtual int GetTrueHeight() { return TrueHeight; } bool Is8BitMode(); + void ScaleCoordsFromWindow(SWORD &x, SWORD &y); void Blank (); bool PaintToWindow (); @@ -269,8 +269,8 @@ public: bool WipeDo(int ticks); void WipeCleanup(); HRESULT GetHR (); - virtual int GetTrueHeight() { return TrueHeight; } bool Is8BitMode() { return false; } + void ScaleCoordsFromWindow(SWORD &x, SWORD &y); private: friend class D3DTex; @@ -380,7 +380,6 @@ private: void EndLineBatch(); void EndBatch(); void CopyNextFrontBuffer(); - int GetPixelDoubling() const { return PixelDoubling; } D3DCAPS9 DeviceCaps;