Replace highdpi window flag with t.highdpi in love.conf

This commit is contained in:
Alex Szpakowski
2020-11-01 21:36:15 -04:00
parent f0838a4eb7
commit 905e5baf06
9 changed files with 71 additions and 16 deletions
+16
View File
@@ -65,6 +65,11 @@
# include "graphics/Graphics.h"
#endif
// For love::window::setHighDPIAllowed
#ifdef LOVE_ENABLE_WINDOW
# include "window/Window.h"
#endif
// For love::audio::Audio::setMixWithSystem.
#ifdef LOVE_ENABLE_AUDIO
# include "audio/Audio.h"
@@ -318,6 +323,14 @@ static int w__setGammaCorrect(lua_State *L)
return 0;
}
static int w__setHighDPIAllowed(lua_State *L)
{
#ifdef LOVE_ENABLE_WINDOW
love::window::setHighDPIAllowed((bool) lua_toboolean(L, 1));
#endif
return 0;
}
static int w__setAudioMixWithSystem(lua_State *L)
{
bool success = false;
@@ -395,6 +408,9 @@ int luaopen_love(lua_State *L)
lua_pushcfunction(L, w__setGammaCorrect);
lua_setfield(L, -2, "_setGammaCorrect");
lua_pushcfunction(L, w__setHighDPIAllowed);
lua_setfield(L, -2, "_setHighDPIAllowed");
// Exposed here because we need to be able to call it before the audio
// module is initialized.
lua_pushcfunction(L, w__setAudioMixWithSystem);
+12
View File
@@ -26,6 +26,18 @@ namespace love
namespace window
{
static bool highDPIAllowed = false;
void setHighDPIAllowed(bool enable)
{
highDPIAllowed = enable;
}
bool isHighDPIAllowed()
{
return highDPIAllowed;
}
Window::~Window()
{
}
+5 -2
View File
@@ -43,6 +43,10 @@ class Graphics;
namespace window
{
// Applied when the window is first created.
void setHighDPIAllowed(bool enable);
bool isHighDPIAllowed();
// Forward-declared so it can be used in the class methods. We can't define the
// whole thing here because it uses the Window::Type enum.
struct WindowSettings;
@@ -66,7 +70,7 @@ public:
SETTING_BORDERLESS,
SETTING_CENTERED,
SETTING_DISPLAY,
SETTING_HIGHDPI,
SETTING_HIGHDPI, // Deprecated
SETTING_USE_DPISCALE,
SETTING_REFRESHRATE,
SETTING_X,
@@ -261,7 +265,6 @@ struct WindowSettings
bool borderless = false;
bool centered = true;
int display = 0;
bool highdpi = false;
bool usedpiscale = true;
double refreshrate = 0.0;
bool useposition = false;
+3 -2
View File
@@ -477,7 +477,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
if (f.borderless)
sdlflags |= SDL_WINDOW_BORDERLESS;
if (f.highdpi)
if (isHighDPIAllowed())
sdlflags |= SDL_WINDOW_ALLOW_HIGHDPI;
int x = f.x;
@@ -596,7 +596,8 @@ void Window::updateSettings(const WindowSettings &newsettings, bool updateGraphi
getPosition(settings.x, settings.y, settings.display);
settings.highdpi = (wflags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
setHighDPIAllowed((wflags & SDL_WINDOW_ALLOW_HIGHDPI) != 0);
settings.usedpiscale = newsettings.usedpiscale;
// Only minimize on focus loss if the window is in exclusive-fullscreen mode
+18 -4
View File
@@ -75,9 +75,19 @@ static int readWindowSettings(lua_State *L, int idx, WindowSettings &settings)
settings.borderless = luax_boolflag(L, idx, settingName(Window::SETTING_BORDERLESS), settings.borderless);
settings.centered = luax_boolflag(L, idx, settingName(Window::SETTING_CENTERED), settings.centered);
settings.display = luax_intflag(L, idx, settingName(Window::SETTING_DISPLAY), settings.display+1) - 1;
settings.highdpi = luax_boolflag(L, idx, settingName(Window::SETTING_HIGHDPI), settings.highdpi);
settings.usedpiscale = luax_boolflag(L, idx, settingName(Window::SETTING_USE_DPISCALE), settings.usedpiscale);
lua_getfield(L, idx, settingName(Window::SETTING_HIGHDPI));
if (!lua_isnoneornil(L, -1))
{
luax_markdeprecated(L, "window.highdpi", API_FIELD, DEPRECATED_REPLACED, "t.highdpi in love.conf");
bool highdpi = luax_checkboolean(L, -1);
if (!instance()->isOpen())
setHighDPIAllowed(highdpi);
}
lua_pop(L, 1);
lua_getfield(L, idx, settingName(Window::SETTING_VSYNC));
if (lua_isnumber(L, -1))
settings.vsync = (int) lua_tointeger(L, -1);
@@ -201,9 +211,6 @@ int w_getMode(lua_State *L)
lua_pushinteger(L, settings.display + 1);
lua_setfield(L, -2, settingName(Window::SETTING_DISPLAY));
luax_pushboolean(L, settings.highdpi);
lua_setfield(L, -2, settingName(Window::SETTING_HIGHDPI));
luax_pushboolean(L, settings.usedpiscale);
lua_setfield(L, -2, settingName(Window::SETTING_USE_DPISCALE));
@@ -219,6 +226,12 @@ int w_getMode(lua_State *L)
return 3;
}
int w_isHighDPIAllowed(lua_State *L)
{
luax_pushboolean(L, isHighDPIAllowed());
return 1;
}
int w_getDisplayOrientation(lua_State *L)
{
int displayindex = 0;
@@ -618,6 +631,7 @@ static const luaL_Reg functions[] =
{ "setMode", w_setMode },
{ "updateMode", w_updateMode },
{ "getMode", w_getMode },
{ "isHighDPIAllowed", w_isHighDPIAllowed },
{ "getDisplayOrientation", w_getDisplayOrientation },
{ "getFullscreenModes", w_getFullscreenModes },
{ "setFullscreen", w_setFullscreen },