diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index fcc5a680c..0bc3c843e 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -122,9 +122,9 @@ void Window::setGLContextAttributes(const ContextAttribs &attribs) int contextflags = 0; if (attribs.gles) - profilemask |= SDL_GL_CONTEXT_PROFILE_ES; + profilemask = SDL_GL_CONTEXT_PROFILE_ES; else if (attribs.debug) - profilemask |= SDL_GL_CONTEXT_PROFILE_COMPATIBILITY; + profilemask = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY; if (attribs.debug) contextflags |= SDL_GL_CONTEXT_DEBUG_FLAG; @@ -471,7 +471,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) return false; // Make sure the window keeps any previously set icon. - setIcon(curMode.icon.get()); + setIcon(icon.get()); // Make sure the mouse keeps its previous grab setting. setMouseGrab(mouseGrabbed); @@ -490,7 +490,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) auto gfx = Module::getInstance(Module::M_GRAPHICS); if (gfx != nullptr) - gfx->setMode(curMode.pixelwidth, curMode.pixelheight); + gfx->setMode(pixelWidth, pixelHeight); #ifdef LOVE_ANDROID love::android::setImmersive(f.fullscreen); @@ -504,14 +504,14 @@ bool Window::onSizeChanged(int width, int height) if (!window) return false; - curMode.width = width; - curMode.height = height; + windowWidth = width; + windowHeight = height; - SDL_GL_GetDrawableSize(window, &curMode.pixelwidth, &curMode.pixelheight); + SDL_GL_GetDrawableSize(window, &pixelWidth, &pixelHeight); auto gfx = Module::getInstance(Module::M_GRAPHICS); if (gfx != nullptr) - gfx->setViewportSize(curMode.pixelwidth, curMode.pixelheight); + gfx->setViewportSize(pixelWidth, pixelHeight); return true; } @@ -521,23 +521,23 @@ void Window::updateSettings(const WindowSettings &newsettings) Uint32 wflags = SDL_GetWindowFlags(window); // Set the new display mode as the current display mode. - SDL_GetWindowSize(window, &curMode.width, &curMode.height); - SDL_GL_GetDrawableSize(window, &curMode.pixelwidth, &curMode.pixelheight); + SDL_GetWindowSize(window, &windowWidth, &windowHeight); + SDL_GL_GetDrawableSize(window, &pixelWidth, &pixelHeight); if ((wflags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) { - curMode.settings.fullscreen = true; - curMode.settings.fstype = FULLSCREEN_DESKTOP; + settings.fullscreen = true; + settings.fstype = FULLSCREEN_DESKTOP; } else if ((wflags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN) { - curMode.settings.fullscreen = true; - curMode.settings.fstype = FULLSCREEN_EXCLUSIVE; + settings.fullscreen = true; + settings.fstype = FULLSCREEN_EXCLUSIVE; } else { - curMode.settings.fullscreen = false; - curMode.settings.fstype = newsettings.fstype; + settings.fullscreen = false; + settings.fstype = newsettings.fstype; } #ifdef LOVE_ANDROID @@ -545,20 +545,19 @@ void Window::updateSettings(const WindowSettings &newsettings) #endif // SDL_GetWindowMinimumSize gives back 0,0 sometimes... - curMode.settings.minwidth = newsettings.minwidth; - curMode.settings.minheight = newsettings.minheight; + settings.minwidth = newsettings.minwidth; + settings.minheight = newsettings.minheight; - curMode.settings.resizable = (wflags & SDL_WINDOW_RESIZABLE) != 0; - curMode.settings.borderless = (wflags & SDL_WINDOW_BORDERLESS) != 0; - curMode.settings.centered = newsettings.centered; + settings.resizable = (wflags & SDL_WINDOW_RESIZABLE) != 0; + settings.borderless = (wflags & SDL_WINDOW_BORDERLESS) != 0; + settings.centered = newsettings.centered; - getPosition(curMode.settings.x, curMode.settings.y, curMode.settings.display); + getPosition(settings.x, settings.y, settings.display); - curMode.settings.highdpi = (wflags & SDL_WINDOW_ALLOW_HIGHDPI) != 0; + settings.highdpi = (wflags & SDL_WINDOW_ALLOW_HIGHDPI) != 0; - // Only minimize on focus loss if the window is in exclusive-fullscreen - // mode. - if (curMode.settings.fullscreen && curMode.settings.fstype == FULLSCREEN_EXCLUSIVE) + // Only minimize on focus loss if the window is in exclusive-fullscreen mode + if (settings.fullscreen && settings.fstype == FULLSCREEN_EXCLUSIVE) SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "1"); else SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); @@ -569,25 +568,25 @@ void Window::updateSettings(const WindowSettings &newsettings) SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buffers); SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &samples); - curMode.settings.msaa = (buffers > 0 ? samples : 0); - curMode.settings.vsync = SDL_GL_GetSwapInterval() != 0; + settings.msaa = (buffers > 0 ? samples : 0); + settings.vsync = SDL_GL_GetSwapInterval() != 0; SDL_DisplayMode dmode = {}; - SDL_GetCurrentDisplayMode(curMode.settings.display, &dmode); + SDL_GetCurrentDisplayMode(settings.display, &dmode); // May be 0 if the refresh rate can't be determined. - curMode.settings.refreshrate = (double) dmode.refresh_rate; + settings.refreshrate = (double) dmode.refresh_rate; } -void Window::getWindow(int &width, int &height, WindowSettings &settings) +void Window::getWindow(int &width, int &height, WindowSettings &newsettings) { // The window might have been modified (moved, resized, etc.) by the user. if (window) - updateSettings(curMode.settings); + updateSettings(settings); - width = curMode.width; - height = curMode.height; - settings = curMode.settings; + width = windowWidth; + height = windowHeight; + newsettings = settings; } void Window::close() @@ -620,7 +619,7 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype) if (!window) return false; - WindowSettings newsettings = curMode.settings; + WindowSettings newsettings = settings; newsettings.fullscreen = fullscreen; newsettings.fstype = fstype; @@ -635,8 +634,8 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype) sdlflags = SDL_WINDOW_FULLSCREEN; SDL_DisplayMode mode = {}; - mode.w = curMode.width; - mode.h = curMode.height; + mode.w = windowWidth; + mode.h = windowHeight; SDL_GetClosestDisplayMode(SDL_GetWindowDisplayIndex(window), &mode, &mode); SDL_SetWindowDisplayMode(window, &mode); @@ -654,12 +653,12 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype) // Apparently this gets un-set when we exit fullscreen (at least in OS X). if (!fullscreen) - SDL_SetWindowMinimumSize(window, curMode.settings.minwidth, curMode.settings.minheight); + SDL_SetWindowMinimumSize(window, settings.minwidth, settings.minheight); // Update the viewport size now instead of waiting for event polling. auto gfx = Module::getInstance(Module::M_GRAPHICS); if (gfx != nullptr) - gfx->setViewportSize(curMode.pixelwidth, curMode.pixelheight); + gfx->setViewportSize(pixelWidth, pixelHeight); return true; } @@ -669,7 +668,7 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype) bool Window::setFullscreen(bool fullscreen) { - return setFullscreen(fullscreen, curMode.settings.fstype); + return setFullscreen(fullscreen, settings.fstype); } int Window::getDisplayCount() const @@ -741,7 +740,7 @@ void Window::setPosition(int x, int y, int displayindex) SDL_SetWindowPosition(window, x, y); - curMode.settings.useposition = true; + settings.useposition = true; } void Window::getPosition(int &x, int &y, int &displayindex) @@ -793,7 +792,7 @@ bool Window::setIcon(love::image::ImageData *imgd) if (!imgd) return false; - curMode.icon.set(imgd); + icon.set(imgd); if (!window) return false; @@ -834,7 +833,7 @@ bool Window::setIcon(love::image::ImageData *imgd) love::image::ImageData *Window::getIcon() { - return curMode.icon.get(); + return icon.get(); } void Window::setDisplaySleepEnabled(bool enable) @@ -909,24 +908,24 @@ bool Window::isMouseGrabbed() const void Window::getPixelDimensions(int &w, int &h) const { - w = curMode.pixelwidth; - h = curMode.pixelheight; + w = pixelWidth; + h = pixelHeight; } void Window::windowToPixelCoords(double *x, double *y) const { if (x != nullptr) - *x = (*x) * ((double) curMode.pixelwidth / (double) curMode.width); + *x = (*x) * ((double) pixelWidth / (double) windowWidth); if (y != nullptr) - *y = (*y) * ((double) curMode.pixelheight / (double) curMode.height); + *y = (*y) * ((double) pixelHeight / (double) windowHeight); } void Window::pixelToWindowCoords(double *x, double *y) const { if (x != nullptr) - *x = (*x) * ((double) curMode.width / (double) curMode.pixelwidth); + *x = (*x) * ((double) windowWidth / (double) pixelWidth); if (y != nullptr) - *y = (*y) * ((double) curMode.height / (double) curMode.pixelheight); + *y = (*y) * ((double) windowHeight / (double) pixelHeight); } double Window::getPixelScale() const @@ -934,7 +933,7 @@ double Window::getPixelScale() const #ifdef LOVE_ANDROID return love::android::getScreenScale(); #else - return (double) curMode.pixelheight / (double) curMode.height; + return (double) pixelHeight / (double) windowHeight; #endif } diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index 6eaf2a758..7a720a83f 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -131,16 +131,12 @@ private: std::string title; - struct _currentMode - { - int width = 800; - int height = 600; - int pixelwidth = 800; - int pixelheight = 600; - WindowSettings settings; - StrongRef icon; - - } curMode; + int windowWidth = 800; + int windowHeight = 600; + int pixelWidth = 800; + int pixelHeight = 600; + WindowSettings settings; + StrongRef icon; bool open;