ソースを参照

Add 'usedpiscale' boolean (true by default) to love.window.setMode's settings table and love.conf's t.window table. Add love.window.getNativeDPIScale.

When usedpiscale=false, love will no longer automatically scale coordinates by the screen's DPI scale factor (so all coordinates will be in pixels), even when highdpi=true. love.window.getDPIScale will return 1, love.graphics.newCanvas will default to a dpi scale of 1 instead of the screen's dpi scale, etc.

love.window.getNativeDPIScale() will return the screen's DPI scale as reported by the OS no matter what usedpiscale is set to.
Alex Szpakowski 6 年 前
コミット
37472d6f5e

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

@@ -104,6 +104,7 @@ StringMap<Window::Setting, Window::SETTING_MAX_ENUM>::Entry Window::settingEntri
 	{"centered", SETTING_CENTERED},
 	{"display", SETTING_DISPLAY},
 	{"highdpi", SETTING_HIGHDPI},
+	{"usedpiscale", SETTING_USE_DPISCALE},
 	{"refreshrate", SETTING_REFRESHRATE},
 	{"x", SETTING_X},
 	{"y", SETTING_Y},

+ 4 - 0
src/modules/window/Window.h

@@ -25,6 +25,7 @@
 #include "common/Module.h"
 #include "common/StringMap.h"
 #include "common/math.h"
+#include "common/Optional.h"
 #include "image/ImageData.h"
 
 // C++
@@ -66,6 +67,7 @@ public:
 		SETTING_CENTERED,
 		SETTING_DISPLAY,
 		SETTING_HIGHDPI,
+		SETTING_USE_DPISCALE,
 		SETTING_REFRESHRATE,
 		SETTING_X,
 		SETTING_Y,
@@ -200,6 +202,7 @@ public:
 	virtual void DPIToWindowCoords(double *x, double *y) const = 0;
 
 	virtual double getDPIScale() const = 0;
+	virtual double getNativeDPIScale() const = 0;
 
 	virtual double toPixels(double x) const = 0;
 	virtual void toPixels(double wx, double wy, double &px, double &py) const = 0;
@@ -259,6 +262,7 @@ struct WindowSettings
 	bool centered = true;
 	int display = 0;
 	bool highdpi = false;
+	bool usedpiscale = true;
 	double refreshrate = 0.0;
 	bool useposition = false;
 	int x = 0;

+ 6 - 0
src/modules/window/sdl/Window.cpp

@@ -593,6 +593,7 @@ void Window::updateSettings(const WindowSettings &newsettings, bool updateGraphi
 	getPosition(settings.x, settings.y, settings.display);
 
 	settings.highdpi = (wflags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
+	settings.usedpiscale = newsettings.usedpiscale;
 
 	// Only minimize on focus loss if the window is in exclusive-fullscreen mode
 	if (settings.fullscreen && settings.fstype == FULLSCREEN_EXCLUSIVE)
@@ -1114,6 +1115,11 @@ void Window::DPIToWindowCoords(double *x, double *y) const
 }
 
 double Window::getDPIScale() const
+{
+	return settings.usedpiscale ? getNativeDPIScale() : 1.0;
+}
+
+double Window::getNativeDPIScale() const
 {
 #ifdef LOVE_ANDROID
 	return love::android::getScreenScale();

+ 1 - 0
src/modules/window/sdl/Window.h

@@ -111,6 +111,7 @@ public:
 	void DPIToWindowCoords(double *x, double *y) const override;
 
 	double getDPIScale() const override;
+	double getNativeDPIScale() const override;
 
 	double toPixels(double x) const override;
 	void toPixels(double wx, double wy, double &px, double &py) const override;

+ 11 - 0
src/modules/window/wrap_Window.cpp

@@ -76,6 +76,7 @@ static int readWindowSettings(lua_State *L, int idx, WindowSettings &settings)
 	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_VSYNC));
 	if (lua_isnumber(L, -1))
@@ -203,6 +204,9 @@ int w_getMode(lua_State *L)
 	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));
+
 	lua_pushnumber(L, settings.refreshrate);
 	lua_setfield(L, -2, settingName(Window::SETTING_REFRESHRATE));
 
@@ -457,6 +461,12 @@ int w_getDPIScale(lua_State *L)
 	return 1;
 }
 
+int w_getNativeDPIScale(lua_State *L)
+{
+	lua_pushnumber(L, instance()->getNativeDPIScale());
+	return 1;
+}
+
 int w_toPixels(lua_State *L)
 {
 	double wx = luaL_checknumber(L, 1);
@@ -630,6 +640,7 @@ static const luaL_Reg functions[] =
 	{ "hasMouseFocus", w_hasMouseFocus },
 	{ "isVisible", w_isVisible },
 	{ "getDPIScale", w_getDPIScale },
+	{ "nativeDPIScale", w_getNativeDPIScale },
 	{ "toPixels", w_toPixels },
 	{ "fromPixels", w_fromPixels },
 	{ "minimize", w_minimize },

+ 2 - 0
src/scripts/boot.lua

@@ -401,6 +401,7 @@ function love.init()
 			resizable = false,
 			centered = true,
 			highdpi = false,
+			usedpiscale = true,
 		},
 		modules = {
 			data = true,
@@ -539,6 +540,7 @@ function love.init()
 			centered = c.window.centered,
 			display = c.window.display,
 			highdpi = c.window.highdpi,
+			usedpiscale = c.window.usedpiscale,
 			x = c.window.x,
 			y = c.window.y,
 		}), "Could not set window mode")

+ 5 - 0
src/scripts/boot.lua.h

@@ -810,6 +810,8 @@ const unsigned char boot_lua[] =
 	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, 
+	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, 0x64, 0x61, 0x74, 0x61, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a,
@@ -1070,6 +1072,9 @@ const unsigned char boot_lua[] =
 	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, 
 	0x64, 0x6f, 0x77, 0x2e, 0x68, 0x69, 0x67, 0x68, 0x64, 0x70, 0x69, 0x2c, 0x0a,
+	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, 
+	0x65, 0x2c, 0x0a,
 	0x09, 0x09, 0x09, 0x78, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x78, 0x2c, 0x0a,
 	0x09, 0x09, 0x09, 0x79, 0x20, 0x3d, 0x20, 0x63, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x79, 0x2c, 0x0a,
 	0x09, 0x09, 0x7d, 0x29, 0x2c, 0x20, 0x22, 0x43, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73,