From 1fa1e26cf9c91f6eb41f967e76799323541080ff Mon Sep 17 00:00:00 2001 From: Braden Obrzut Date: Fri, 17 Apr 2015 00:24:33 -0400 Subject: [PATCH] - 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;