Browse Source

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

Alex Szpakowski 4 years ago
parent
commit
905e5baf06

+ 16 - 0
src/modules/love/love.cpp

@@ -65,6 +65,11 @@
 #	include "graphics/Graphics.h"
 #	include "graphics/Graphics.h"
 #endif
 #endif
 
 
+// For love::window::setHighDPIAllowed
+#ifdef LOVE_ENABLE_WINDOW
+#	include "window/Window.h"
+#endif
+
 // For love::audio::Audio::setMixWithSystem.
 // For love::audio::Audio::setMixWithSystem.
 #ifdef LOVE_ENABLE_AUDIO
 #ifdef LOVE_ENABLE_AUDIO
 #	include "audio/Audio.h"
 #	include "audio/Audio.h"
@@ -318,6 +323,14 @@ static int w__setGammaCorrect(lua_State *L)
 	return 0;
 	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)
 static int w__setAudioMixWithSystem(lua_State *L)
 {
 {
 	bool success = false;
 	bool success = false;
@@ -395,6 +408,9 @@ int luaopen_love(lua_State *L)
 	lua_pushcfunction(L, w__setGammaCorrect);
 	lua_pushcfunction(L, w__setGammaCorrect);
 	lua_setfield(L, -2, "_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
 	// Exposed here because we need to be able to call it before the audio
 	// module is initialized.
 	// module is initialized.
 	lua_pushcfunction(L, w__setAudioMixWithSystem);
 	lua_pushcfunction(L, w__setAudioMixWithSystem);

+ 12 - 0
src/modules/window/Window.cpp

@@ -26,6 +26,18 @@ namespace love
 namespace window
 namespace window
 {
 {
 
 
+static bool highDPIAllowed = false;
+
+void setHighDPIAllowed(bool enable)
+{
+	highDPIAllowed = enable;
+}
+
+bool isHighDPIAllowed()
+{
+	return highDPIAllowed;
+}
+
 Window::~Window()
 Window::~Window()
 {
 {
 }
 }

+ 5 - 2
src/modules/window/Window.h

@@ -43,6 +43,10 @@ class Graphics;
 namespace window
 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
 // 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.
 // whole thing here because it uses the Window::Type enum.
 struct WindowSettings;
 struct WindowSettings;
@@ -66,7 +70,7 @@ public:
 		SETTING_BORDERLESS,
 		SETTING_BORDERLESS,
 		SETTING_CENTERED,
 		SETTING_CENTERED,
 		SETTING_DISPLAY,
 		SETTING_DISPLAY,
-		SETTING_HIGHDPI,
+		SETTING_HIGHDPI, // Deprecated
 		SETTING_USE_DPISCALE,
 		SETTING_USE_DPISCALE,
 		SETTING_REFRESHRATE,
 		SETTING_REFRESHRATE,
 		SETTING_X,
 		SETTING_X,
@@ -261,7 +265,6 @@ struct WindowSettings
 	bool borderless = false;
 	bool borderless = false;
 	bool centered = true;
 	bool centered = true;
 	int display = 0;
 	int display = 0;
-	bool highdpi = false;
 	bool usedpiscale = true;
 	bool usedpiscale = true;
 	double refreshrate = 0.0;
 	double refreshrate = 0.0;
 	bool useposition = false;
 	bool useposition = false;

+ 3 - 2
src/modules/window/sdl/Window.cpp

@@ -477,7 +477,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
 	if (f.borderless)
 	if (f.borderless)
 		sdlflags |= SDL_WINDOW_BORDERLESS;
 		sdlflags |= SDL_WINDOW_BORDERLESS;
 
 
-	if (f.highdpi)
+	if (isHighDPIAllowed())
 		sdlflags |= SDL_WINDOW_ALLOW_HIGHDPI;
 		sdlflags |= SDL_WINDOW_ALLOW_HIGHDPI;
 
 
 	int x = f.x;
 	int x = f.x;
@@ -596,7 +596,8 @@ void Window::updateSettings(const WindowSettings &newsettings, bool updateGraphi
 
 
 	getPosition(settings.x, settings.y, settings.display);
 	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;
 	settings.usedpiscale = newsettings.usedpiscale;
 
 
 	// Only minimize on focus loss if the window is in exclusive-fullscreen mode
 	// Only minimize on focus loss if the window is in exclusive-fullscreen mode

+ 18 - 4
src/modules/window/wrap_Window.cpp

@@ -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.borderless = luax_boolflag(L, idx, settingName(Window::SETTING_BORDERLESS), settings.borderless);
 	settings.centered = luax_boolflag(L, idx, settingName(Window::SETTING_CENTERED), settings.centered);
 	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.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);
 	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));
 	lua_getfield(L, idx, settingName(Window::SETTING_VSYNC));
 	if (lua_isnumber(L, -1))
 	if (lua_isnumber(L, -1))
 		settings.vsync = (int) lua_tointeger(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_pushinteger(L, settings.display + 1);
 	lua_setfield(L, -2, settingName(Window::SETTING_DISPLAY));
 	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);
 	luax_pushboolean(L, settings.usedpiscale);
 	lua_setfield(L, -2, settingName(Window::SETTING_USE_DPISCALE));
 	lua_setfield(L, -2, settingName(Window::SETTING_USE_DPISCALE));
 
 
@@ -219,6 +226,12 @@ int w_getMode(lua_State *L)
 	return 3;
 	return 3;
 }
 }
 
 
+int w_isHighDPIAllowed(lua_State *L)
+{
+	luax_pushboolean(L, isHighDPIAllowed());
+	return 1;
+}
+
 int w_getDisplayOrientation(lua_State *L)
 int w_getDisplayOrientation(lua_State *L)
 {
 {
 	int displayindex = 0;
 	int displayindex = 0;
@@ -618,6 +631,7 @@ static const luaL_Reg functions[] =
 	{ "setMode", w_setMode },
 	{ "setMode", w_setMode },
 	{ "updateMode", w_updateMode },
 	{ "updateMode", w_updateMode },
 	{ "getMode", w_getMode },
 	{ "getMode", w_getMode },
+	{ "isHighDPIAllowed", w_isHighDPIAllowed },
 	{ "getDisplayOrientation", w_getDisplayOrientation },
 	{ "getDisplayOrientation", w_getDisplayOrientation },
 	{ "getFullscreenModes", w_getFullscreenModes },
 	{ "getFullscreenModes", w_getFullscreenModes },
 	{ "setFullscreen", w_setFullscreen },
 	{ "setFullscreen", w_setFullscreen },

+ 6 - 2
src/scripts/boot.lua

@@ -400,7 +400,6 @@ function love.init()
 			borderless = false,
 			borderless = false,
 			resizable = false,
 			resizable = false,
 			centered = true,
 			centered = true,
-			highdpi = false,
 			usedpiscale = true,
 			usedpiscale = true,
 		},
 		},
 		modules = {
 		modules = {
@@ -433,6 +432,7 @@ function love.init()
 		externalstorage = false, -- Only relevant for Android.
 		externalstorage = false, -- Only relevant for Android.
 		accelerometerjoystick = true, -- Only relevant for Android / iOS.
 		accelerometerjoystick = true, -- Only relevant for Android / iOS.
 		gammacorrect = false,
 		gammacorrect = false,
+		highdpi = false,
 	}
 	}
 
 
 	-- Console hack, part 1.
 	-- Console hack, part 1.
@@ -470,6 +470,10 @@ function love.init()
 		love._setGammaCorrect(c.gammacorrect)
 		love._setGammaCorrect(c.gammacorrect)
 	end
 	end
 
 
+	if love._setHighDPIAllowed then
+		love._setHighDPIAllowed(c.highdpi)
+	end
+
 	if love._setAudioMixWithSystem then
 	if love._setAudioMixWithSystem then
 		if c.audio and c.audio.mixwithsystem ~= nil then
 		if c.audio and c.audio.mixwithsystem ~= nil then
 			love._setAudioMixWithSystem(c.audio.mixwithsystem)
 			love._setAudioMixWithSystem(c.audio.mixwithsystem)
@@ -547,7 +551,7 @@ function love.init()
 			borderless = c.window.borderless,
 			borderless = c.window.borderless,
 			centered = c.window.centered,
 			centered = c.window.centered,
 			display = c.window.display,
 			display = c.window.display,
-			highdpi = c.window.highdpi,
+			highdpi = c.window.highdpi, -- deprecated
 			usedpiscale = c.window.usedpiscale,
 			usedpiscale = c.window.usedpiscale,
 			x = c.window.x,
 			x = c.window.x,
 			y = c.window.y,
 			y = c.window.y,

+ 9 - 3
src/scripts/boot.lua.h

@@ -808,8 +808,6 @@ const unsigned char boot_lua[] =
 	0x73, 0x65, 0x2c, 0x0a,
 	0x73, 0x65, 0x2c, 0x0a,
 	0x09, 0x09, 0x09, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 
 	0x09, 0x09, 0x09, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 
 	0x2c, 0x0a,
 	0x2c, 0x0a,
-	0x09, 0x09, 0x09, 0x68, 0x69, 0x67, 0x68, 0x64, 0x70, 0x69, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 
-	0x2c, 0x0a,
 	0x09, 0x09, 0x09, 0x75, 0x73, 0x65, 0x64, 0x70, 0x69, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x74, 
 	0x09, 0x09, 0x09, 0x75, 0x73, 0x65, 0x64, 0x70, 0x69, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x74, 
 	0x72, 0x75, 0x65, 0x2c, 0x0a,
 	0x72, 0x75, 0x65, 0x2c, 0x0a,
 	0x09, 0x09, 0x7d, 0x2c, 0x0a,
 	0x09, 0x09, 0x7d, 0x2c, 0x0a,
@@ -862,6 +860,7 @@ const unsigned char boot_lua[] =
 	0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x20, 0x2f, 0x20, 0x69, 0x4f, 0x53, 0x2e, 0x0a,
 	0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x20, 0x2f, 0x20, 0x69, 0x4f, 0x53, 0x2e, 0x0a,
 	0x09, 0x09, 0x67, 0x61, 0x6d, 0x6d, 0x61, 0x63, 0x6f, 0x72, 0x72, 0x65, 0x63, 0x74, 0x20, 0x3d, 0x20, 0x66, 
 	0x09, 0x09, 0x67, 0x61, 0x6d, 0x6d, 0x61, 0x63, 0x6f, 0x72, 0x72, 0x65, 0x63, 0x74, 0x20, 0x3d, 0x20, 0x66, 
 	0x61, 0x6c, 0x73, 0x65, 0x2c, 0x0a,
 	0x61, 0x6c, 0x73, 0x65, 0x2c, 0x0a,
+	0x09, 0x09, 0x68, 0x69, 0x67, 0x68, 0x64, 0x70, 0x69, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x0a,
 	0x09, 0x7d, 0x0a,
 	0x09, 0x7d, 0x0a,
 	0x0a,
 	0x0a,
 	0x09, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x20, 0x68, 0x61, 0x63, 0x6b, 0x2c, 0x20, 
 	0x09, 0x2d, 0x2d, 0x20, 0x43, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x20, 0x68, 0x61, 0x63, 0x6b, 0x2c, 0x20, 
@@ -946,6 +945,12 @@ const unsigned char boot_lua[] =
 	0x63, 0x74, 0x29, 0x0a,
 	0x63, 0x74, 0x29, 0x0a,
 	0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x0a,
 	0x0a,
+	0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x73, 0x65, 0x74, 0x48, 0x69, 0x67, 0x68, 0x44, 
+	0x50, 0x49, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x73, 0x65, 0x74, 0x48, 0x69, 0x67, 0x68, 0x44, 0x50, 0x49, 
+	0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x28, 0x63, 0x2e, 0x68, 0x69, 0x67, 0x68, 0x64, 0x70, 0x69, 0x29, 0x0a,
+	0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x0a,
 	0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x73, 0x65, 0x74, 0x41, 0x75, 0x64, 0x69, 0x6f, 
 	0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x73, 0x65, 0x74, 0x41, 0x75, 0x64, 0x69, 0x6f, 
 	0x4d, 0x69, 0x78, 0x57, 0x69, 0x74, 0x68, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
 	0x4d, 0x69, 0x78, 0x57, 0x69, 0x74, 0x68, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
 	0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x2e, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 
 	0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x2e, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63, 
@@ -1089,7 +1094,8 @@ const unsigned char boot_lua[] =
 	0x09, 0x09, 0x09, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 
 	0x09, 0x09, 0x09, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 
 	0x64, 0x6f, 0x77, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x2c, 0x0a,
 	0x64, 0x6f, 0x77, 0x2e, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x2c, 0x0a,
 	0x09, 0x09, 0x09, 0x68, 0x69, 0x67, 0x68, 0x64, 0x70, 0x69, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 
 	0x09, 0x09, 0x09, 0x68, 0x69, 0x67, 0x68, 0x64, 0x70, 0x69, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 
-	0x64, 0x6f, 0x77, 0x2e, 0x68, 0x69, 0x67, 0x68, 0x64, 0x70, 0x69, 0x2c, 0x0a,
+	0x64, 0x6f, 0x77, 0x2e, 0x68, 0x69, 0x67, 0x68, 0x64, 0x70, 0x69, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x64, 0x65, 
+	0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x0a,
 	0x09, 0x09, 0x09, 0x75, 0x73, 0x65, 0x64, 0x70, 0x69, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x63, 
 	0x09, 0x09, 0x09, 0x75, 0x73, 0x65, 0x64, 0x70, 0x69, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x63, 
 	0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x75, 0x73, 0x65, 0x64, 0x70, 0x69, 0x73, 0x63, 0x61, 0x6c, 
 	0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x75, 0x73, 0x65, 0x64, 0x70, 0x69, 0x73, 0x63, 0x61, 0x6c, 
 	0x65, 0x2c, 0x0a,
 	0x65, 0x2c, 0x0a,

+ 1 - 1
src/scripts/nogame.lua

@@ -3274,7 +3274,7 @@ function love.nogame()
 		t.modules.sound = false
 		t.modules.sound = false
 		t.modules.joystick = false
 		t.modules.joystick = false
 		t.window.resizable = true
 		t.window.resizable = true
-		t.window.highdpi = true
+		t.highdpi = true
 
 
 		if love._os == "iOS" then
 		if love._os == "iOS" then
 			t.window.borderless = true
 			t.window.borderless = true

+ 1 - 2
src/scripts/nogame.lua.h

@@ -12115,8 +12115,7 @@ const unsigned char nogame_lua[] =
 	0x63, 0x6b, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a,
 	0x63, 0x6b, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a,
 	0x09, 0x09, 0x74, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x61, 0x62, 
 	0x09, 0x09, 0x74, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x61, 0x62, 
 	0x6c, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a,
 	0x6c, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a,
-	0x09, 0x09, 0x74, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x68, 0x69, 0x67, 0x68, 0x64, 0x70, 0x69, 
-	0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a,
+	0x09, 0x09, 0x74, 0x2e, 0x68, 0x69, 0x67, 0x68, 0x64, 0x70, 0x69, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a,
 	0x0a,
 	0x0a,
 	0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x6f, 0x73, 0x20, 0x3d, 0x3d, 0x20, 0x22, 
 	0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x6f, 0x73, 0x20, 0x3d, 0x3d, 0x20, 0x22, 
 	0x69, 0x4f, 0x53, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
 	0x69, 0x4f, 0x53, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,