Mercurial > love-experiments
diff src/modules/window/sdl/Window.cpp @ 1111:9a6a533ac832 minor
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Example setMode invocation: love.graphics.setMode(800, 600, {fullscreen = false, vsync = true, borderless = true})
t.screen.resizable and t.screen.borderless are available in love.conf
And love.resize(w, h) gets called if it exists on a resize event.
NOTE: love.handlers.resize(w, h) does the required setMode, but that does mean a visual reload
| author | Bart van Strien <bart.bes+projects@gmail.com> |
|---|---|
| date | Mon, 23 Jul 2012 11:53:13 +0200 |
| parents | 86a44f2bc38f |
| children | 730ed5f01ab0 |
line wrap: on
line diff
--- a/src/modules/window/sdl/Window.cpp Mon Jul 23 10:54:23 2012 +0200 +++ b/src/modules/window/sdl/Window.cpp Mon Jul 23 11:53:13 2012 +0200 @@ -60,8 +60,23 @@ { } -bool Window::setWindow(int width, int height, bool fullscreen, bool vsync, int fsaa) +bool Window::setWindow(int width, int height, WindowFlags *flags) { + bool fullscreen = false; + bool vsync = true; + int fsaa = 0; + bool resizable = false; + bool borderless = false; + + if (flags) + { + fullscreen = flags->fullscreen; + vsync = flags->vsync; + fsaa = flags->fsaa; + resizable = flags->resizable; + borderless = flags->borderless; + } + bool mouseVisible = getMouseVisible(); // We need to restart the subsystem for two reasons: @@ -104,23 +119,30 @@ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa); } - // Fullscreen? - Uint32 sdlflags = fullscreen ? (SDL_OPENGL | SDL_FULLSCREEN) : SDL_OPENGL; + Uint32 sdlflags = SDL_OPENGL; + // Flags + if (fullscreen) + sdlflags |= SDL_FULLSCREEN; + if (resizable) + sdlflags |= SDL_RESIZABLE; + if (borderless) + sdlflags |= SDL_NOFRAME; // Have SDL set the video mode. - if (SDL_SetVideoMode(width, height, 32, sdlflags) == 0) + SDL_Surface *surface; + if ((surface = SDL_SetVideoMode(width, height, 32, sdlflags)) == 0) { bool failed = true; if (fsaa > 0) { // FSAA might have failed, disable it and try again SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); - failed = SDL_SetVideoMode(width, height, 32, sdlflags) == 0; + failed = (surface = SDL_SetVideoMode(width, height, 32, sdlflags)) == 0; if (failed) { // There might be no FSAA at all SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); - failed = SDL_SetVideoMode(width, height, 32, sdlflags) == 0; + failed = (surface = SDL_SetVideoMode(width, height, 32, sdlflags)) == 0; } } if (failed) @@ -165,17 +187,21 @@ currentMode.fsaa = fsaa; currentMode.fullscreen = fullscreen; currentMode.vsync = (real_vsync != 0); + currentMode.resizable = ((surface->flags & SDL_RESIZABLE) != 0); + currentMode.borderless = ((surface->flags & SDL_NOFRAME) != 0); return true; } -void Window::getWindow(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa) +void Window::getWindow(int &width, int &height, WindowFlags &flags) { width = currentMode.width; height = currentMode.height; - fullscreen = currentMode.fullscreen; - vsync = currentMode.vsync; - fsaa = currentMode.fsaa; + flags.fullscreen = currentMode.fullscreen; + flags.vsync = currentMode.vsync; + flags.fsaa = currentMode.fsaa; + flags.resizable = currentMode.resizable; + flags.borderless = currentMode.borderless; } bool Window::checkWindowSize(int width, int height, bool fullscreen)
