mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
This commit is contained in:
@@ -38,5 +38,15 @@ void Window::swapBuffers()
|
||||
{
|
||||
}
|
||||
|
||||
WindowFlags::WindowFlags()
|
||||
: fullscreen(false)
|
||||
, vsync(true)
|
||||
, fsaa(0)
|
||||
, resizable(false)
|
||||
, borderless(false)
|
||||
, centered(true)
|
||||
{
|
||||
}
|
||||
|
||||
} // window
|
||||
} // love
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -74,6 +74,7 @@ private:
|
||||
int fsaa;
|
||||
bool resizable;
|
||||
bool borderless;
|
||||
bool centered;
|
||||
} currentMode;
|
||||
bool created;
|
||||
}; // Window
|
||||
|
||||
Reference in New Issue
Block a user