Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)

This commit is contained in:
Bart van Strien
2013-03-10 23:00:31 +01:00
parent 63c57ba3f8
commit 7efe11b11f
7 changed files with 39 additions and 3 deletions
+10
View File
@@ -38,5 +38,15 @@ void Window::swapBuffers()
{
}
WindowFlags::WindowFlags()
: fullscreen(false)
, vsync(true)
, fsaa(0)
, resizable(false)
, borderless(false)
, centered(true)
{
}
} // window
} // love
+2
View File
@@ -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
+10 -3
View File
@@ -39,9 +39,6 @@ Window::Window()
: windowTitle("")
, created(false)
{
// Window should be centered.
SDL_putenv(const_cast<char *>("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<char *>("SDL_VIDEO_CENTERED=center"));
else
SDL_putenv(const_cast<char *>("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
+1
View File
@@ -74,6 +74,7 @@ private:
int fsaa;
bool resizable;
bool borderless;
bool centered;
} currentMode;
bool created;
}; // Window