diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index d335cf58c..30e6d35db 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -94,6 +94,7 @@ int w_setMode(lua_State *L) flags.fsaa = luax_intflag(L, 3, "fsaa", 0); flags.resizable = luax_boolflag(L, 3, "resizable", false); flags.borderless = luax_boolflag(L, 3, "borderless", false); + flags.centered = luax_boolflag(L, 3, "centered", true); luax_pushboolean(L, instance->setMode(w, h, &flags)); return 1; @@ -124,6 +125,9 @@ int w_getMode(lua_State *L) luax_pushboolean(L, flags.borderless); lua_setfield(L, -2, "borderless"); + luax_pushboolean(L, flags.centered); + lua_setfield(L, -2, "centered"); + return 3; } diff --git a/src/modules/window/Window.cpp b/src/modules/window/Window.cpp index eec6253cf..aa6c8c609 100644 --- a/src/modules/window/Window.cpp +++ b/src/modules/window/Window.cpp @@ -38,5 +38,15 @@ void Window::swapBuffers() { } +WindowFlags::WindowFlags() + : fullscreen(false) + , vsync(true) + , fsaa(0) + , resizable(false) + , borderless(false) + , centered(true) +{ +} + } // window } // love diff --git a/src/modules/window/Window.h b/src/modules/window/Window.h index a4d8c90f8..d4d6aacc2 100644 --- a/src/modules/window/Window.h +++ b/src/modules/window/Window.h @@ -35,11 +35,13 @@ namespace window struct WindowFlags { + WindowFlags(); bool fullscreen; // = false bool vsync; // = true int fsaa; // = 0 bool resizable; // = false bool borderless; // = false + bool centered; // = true }; // WindowFlags class Window : public Module diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index c470f26b3..db97721c3 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -39,9 +39,6 @@ Window::Window() : windowTitle("") , created(false) { - // Window should be centered. - SDL_putenv(const_cast("SDL_VIDEO_CENTERED=center")); - if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) throw love::Exception(SDL_GetError()); } @@ -63,6 +60,7 @@ bool Window::setWindow(int width, int height, WindowFlags *flags) int fsaa = 0; bool resizable = false; bool borderless = false; + bool centered = true; if (flags) { @@ -71,6 +69,7 @@ bool Window::setWindow(int width, int height, WindowFlags *flags) fsaa = flags->fsaa; resizable = flags->resizable; borderless = flags->borderless; + centered = flags->centered; } bool mouseVisible = getMouseVisible(); @@ -91,6 +90,12 @@ bool Window::setWindow(int width, int height, WindowFlags *flags) // love.mouse.getX() < 800 when switching from 800x600 to a // higher resolution) SDL_QuitSubSystem(SDL_INIT_VIDEO); + + if (centered) // Window should be centered. + SDL_putenv(const_cast("SDL_VIDEO_CENTERED=center")); + else + SDL_putenv(const_cast("SDL_VIDEO_CENTERED=")); + if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { std::cout << "Could not init SDL_VIDEO: " << SDL_GetError() << std::endl; @@ -177,6 +182,7 @@ bool Window::setWindow(int width, int height, WindowFlags *flags) currentMode.vsync = (real_vsync != 0); currentMode.resizable = ((surface->flags & SDL_RESIZABLE) != 0); currentMode.borderless = ((surface->flags & SDL_NOFRAME) != 0); + currentMode.centered = centered; return true; } @@ -190,6 +196,7 @@ void Window::getWindow(int &width, int &height, WindowFlags &flags) const flags.fsaa = currentMode.fsaa; flags.resizable = currentMode.resizable; flags.borderless = currentMode.borderless; + flags.centered = currentMode.centered; } bool Window::checkWindowSize(int width, int height, bool fullscreen) const diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index b6857c48f..656a57111 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -74,6 +74,7 @@ private: int fsaa; bool resizable; bool borderless; + bool centered; } currentMode; bool created; }; // Window diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index 7be571740..927b6b00e 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -261,6 +261,9 @@ function love.init() fullscreen = false, vsync = true, fsaa = 0, + borderless = false, + resizable = false, + centered = true, }, modules = { event = true, @@ -345,6 +348,7 @@ function love.init() fsaa = c.screen.fsaa, resizable = c.screen.resizable, borderless = c.screen.borderless, + centered = c.screen.centered, }), "Could not set screen mode") else error("Could not set screen mode") diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index 177a33b5c..3644af3ee 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -450,6 +450,12 @@ const unsigned char boot_lua[] = 0x6c, 0x73, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x76, 0x73, 0x79, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x66, 0x73, 0x61, 0x61, 0x20, 0x3d, 0x20, 0x30, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x66, 0x61, + 0x6c, 0x73, 0x65, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, + 0x73, 0x65, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, + 0x2c, 0x0a, 0x09, 0x09, 0x7d, 0x2c, 0x0a, 0x09, 0x09, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, @@ -582,6 +588,8 @@ const unsigned char boot_lua[] = 0x09, 0x09, 0x09, 0x09, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x73, 0x63, 0x72, 0x65, 0x65, 0x6e, 0x2e, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x6c, 0x65, 0x73, 0x73, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x73, + 0x63, 0x72, 0x65, 0x65, 0x6e, 0x2e, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x64, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x7d, 0x29, 0x2c, 0x20, 0x22, 0x43, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x65, 0x74, 0x20, 0x73, 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x6d, 0x6f, 0x64, 0x65, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a,