From 9b6756114b89c37d607705713bd7705cf08c8a20 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 16 Apr 2015 17:39:45 -0500 Subject: [PATCH 1/3] 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 69741c7f8..5250cdaa9 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 e23275734..9fd185431 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 2aa694f3b..ecf570ff8 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 ed7c81cf1..a26ff320e 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 2704de0fa..9699157cd 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; From 1fa1e26cf9c91f6eb41f967e76799323541080ff Mon Sep 17 00:00:00 2001 From: Braden Obrzut Date: Fri, 17 Apr 2015 00:24:33 -0400 Subject: [PATCH 2/3] - SDL backend could use the new ScaleCoordsFromWindow since it does similarly for fullscreen. --- src/posix/sdl/i_input.cpp | 32 +++----------------------------- src/posix/sdl/sdlvideo.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/posix/sdl/i_input.cpp b/src/posix/sdl/i_input.cpp index 6fff2d2a9..372b23446 100644 --- a/src/posix/sdl/i_input.cpp +++ b/src/posix/sdl/i_input.cpp @@ -18,8 +18,6 @@ #include "templates.h" #include "s_sound.h" -void ScaleWithAspect (int &w, int &h, int Width, int Height); - static void I_CheckGUICapture (); static void I_CheckNativeMouse (); @@ -320,35 +318,11 @@ void MessagePump (const SDL_Event &sev) int x, y; SDL_GetMouseState (&x, &y); - // Detect if we're doing scaling in the Window and adjust the mouse - // coordinates accordingly. This could be more efficent, but I - // don't think performance is an issue in the menus. - SDL_Window *focus; - if (screen->IsFullscreen() && (focus = SDL_GetMouseFocus ())) - { - int w, h; - SDL_GetWindowSize (focus, &w, &h); - int realw = w, realh = h; - ScaleWithAspect (realw, realh, SCREENWIDTH, SCREENHEIGHT); - if (realw != SCREENWIDTH || realh != SCREENHEIGHT) - { - double xratio = (double)SCREENWIDTH/realw; - double yratio = (double)SCREENHEIGHT/realh; - if (realw < w) - { - x = (x - (w - realw)/2)*xratio; - y *= yratio; - } - else - { - y = (y - (h - realh)/2)*yratio; - x *= xratio; - } - } - } - event.data1 = x; event.data2 = y; + + screen->ScaleCoordsFromWindow(event.data1, event.data2); + event.type = EV_GUI_Event; if(sev.type == SDL_MOUSEMOTION) event.subtype = EV_GUI_MouseMove; diff --git a/src/posix/sdl/sdlvideo.cpp b/src/posix/sdl/sdlvideo.cpp index 309002456..c24fd797a 100644 --- a/src/posix/sdl/sdlvideo.cpp +++ b/src/posix/sdl/sdlvideo.cpp @@ -50,6 +50,7 @@ public: friend class SDLVideo; virtual void SetVSync (bool vsync); + virtual void ScaleCoordsFromWindow(SWORD &x, SWORD &y); private: PalEntry SourcePalette[256]; @@ -723,6 +724,35 @@ void SDLFB::SetVSync (bool vsync) #endif // __APPLE__ } +void SDLFB::ScaleCoordsFromWindow(SWORD &x, SWORD &y) +{ + // Detect if we're doing scaling in the Window and adjust the mouse + // coordinates accordingly. This could be more efficent, but I + // don't think performance is an issue in the menus. + if(IsFullscreen()) + { + int w, h; + SDL_GetWindowSize (Screen, &w, &h); + int realw = w, realh = h; + ScaleWithAspect (realw, realh, SCREENWIDTH, SCREENHEIGHT); + if (realw != SCREENWIDTH || realh != SCREENHEIGHT) + { + double xratio = (double)SCREENWIDTH/realw; + double yratio = (double)SCREENHEIGHT/realh; + if (realw < w) + { + x = (x - (w - realw)/2)*xratio; + y *= yratio; + } + else + { + y = (y - (h - realh)/2)*yratio; + x *= xratio; + } + } + } +} + ADD_STAT (blit) { FString out; From 6e28963141cf02da2ca108b0104b65fc90b649ff Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2015 19:40:45 +0200 Subject: [PATCH 3/3] - added a sanity check to GL nodes loader for a potential crash. --- src/p_glnodes.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 1b34e8bbc..547cecace 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -338,7 +338,14 @@ static bool LoadGLSegs(FileReader * lump) ml->side=LittleShort(ml->side); segs[i].sidedef = ldef->sidedef[ml->side]; - segs[i].frontsector = ldef->sidedef[ml->side]->sector; + if (ldef->sidedef[ml->side] != NULL) + { + segs[i].frontsector = ldef->sidedef[ml->side]->sector; + } + else + { + segs[i].frontsector = NULL; + } if (ldef->flags & ML_TWOSIDED && ldef->sidedef[ml->side^1] != NULL) { segs[i].backsector = ldef->sidedef[ml->side^1]->sector; @@ -346,7 +353,7 @@ static bool LoadGLSegs(FileReader * lump) else { ldef->flags &= ~ML_TWOSIDED; - segs[i].backsector = 0; + segs[i].backsector = NULL; } } @@ -385,7 +392,14 @@ static bool LoadGLSegs(FileReader * lump) ml->side=LittleShort(ml->side); segs[i].sidedef = ldef->sidedef[ml->side]; - segs[i].frontsector = ldef->sidedef[ml->side]->sector; + if (ldef->sidedef[ml->side] != NULL) + { + segs[i].frontsector = ldef->sidedef[ml->side]->sector; + } + else + { + segs[i].frontsector = NULL; + } if (ldef->flags & ML_TWOSIDED && ldef->sidedef[ml->side^1] != NULL) { segs[i].backsector = ldef->sidedef[ml->side^1]->sector; @@ -393,7 +407,7 @@ static bool LoadGLSegs(FileReader * lump) else { ldef->flags &= ~ML_TWOSIDED; - segs[i].backsector = 0; + segs[i].backsector = NULL; } }