mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Add centered flag to setMode, optionally centers the window (on by default, as before) (issue #463)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user