From e3a867eb771f3c820997d5b2c9660c535b9ff52b Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 20 Dec 2022 21:55:58 +0530 Subject: [PATCH] highdpi support test --- compile-c.hxml | 1 + compile-js-rel.hxml | 1 + compile-js.hxml | 1 + compile-macos.hxml | 1 + compile.hxml | 1 + src/CameraController.hx | 2 +- src/ResourceLoader.hx | 9 ++++----- src/Settings.hx | 12 +++++------- src/gui/GuiControl.hx | 2 +- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/compile-c.hxml b/compile-c.hxml index d032bc32..93c8ea05 100644 --- a/compile-c.hxml +++ b/compile-c.hxml @@ -1,5 +1,6 @@ -cp src -lib heaps -lib hlsdl +-D highDPI -hl native/marblegame.c --main Main \ No newline at end of file diff --git a/compile-js-rel.hxml b/compile-js-rel.hxml index 6baeb59c..33b4618d 100644 --- a/compile-js-rel.hxml +++ b/compile-js-rel.hxml @@ -6,5 +6,6 @@ --js marblegame.js -D windowSize=1280x720 -D js-es=6 +-D highDPI --dce full --main Main \ No newline at end of file diff --git a/compile-js.hxml b/compile-js.hxml index f188602e..341e6d74 100644 --- a/compile-js.hxml +++ b/compile-js.hxml @@ -6,5 +6,6 @@ -D windowSize=1280x720 -D js-es=6 -D keep-inline-positions +-D highDPI --main Main -debug \ No newline at end of file diff --git a/compile-macos.hxml b/compile-macos.hxml index 618e4117..90483087 100644 --- a/compile-macos.hxml +++ b/compile-macos.hxml @@ -1,6 +1,7 @@ -cp src -lib heaps -lib hlsdl +-D highDPI -hl native/marblegame.c -D MACOS_BUNDLE --main Main diff --git a/compile.hxml b/compile.hxml index 532a696f..040f0fd6 100644 --- a/compile.hxml +++ b/compile.hxml @@ -5,5 +5,6 @@ -hl marblegame.hl -D windowSize=1280x720 -D keep-inline-positions +-D highDPI --main Main -debug \ No newline at end of file diff --git a/src/CameraController.hx b/src/CameraController.hx index 34347e5f..e43e8564 100644 --- a/src/CameraController.hx +++ b/src/CameraController.hx @@ -115,7 +115,7 @@ class CameraController extends Object { _ignoreCursor = false; return; } - var scaleFactor = 1.0; + var scaleFactor = 1.0 / Window.getInstance().windowToPixelRatio; #if js scaleFactor = 1 / js.Browser.window.devicePixelRatio; #end diff --git a/src/ResourceLoader.hx b/src/ResourceLoader.hx index 7a7e47e9..bdbe7a93 100644 --- a/src/ResourceLoader.hx +++ b/src/ResourceLoader.hx @@ -20,11 +20,11 @@ import src.ResourceLoaderWorker; class ResourceLoader { #if (hl && !android) - #if MACOS_BUNDLE + #if MACOS_BUNDLE public static var fileSystem:FileSystem = new LocalFileSystem(Path.normalize(Path.join([Path.directory(Sys.programPath()), "..", "..", ".."])), null); - #else + #else public static var fileSystem:FileSystem = new LocalFileSystem(".", null); - #end + #end #end #if (js || android) public static var fileSystem:FileSystem = null; @@ -271,8 +271,7 @@ class ResourceLoader { texObj.flags.set(MipMapped); } var tex = img.toTexture(); - tex.mipMap = Linear; - tex.filter = Linear; + tex.mipMap = Nearest; // tex.filter = Nearest; var textureresource = new Resource(tex, path, textureCache, tex -> tex.dispose()); textureCache.set(path, textureresource); diff --git a/src/Settings.hx b/src/Settings.hx index 1442e969..f6ba3fea 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -117,13 +117,12 @@ class Settings { public static var isTouch:Option = Option.None; #if hl - #if MACOS_BUNDLE + #if MACOS_BUNDLE public static var settingsDir = Path.join([Sys.getEnv("HOME"), "Library", "Application Support", "MBHaxe-MBG"]); - #else + #else public static var settingsDir = "."; - #end #end - + #end public static function applySettings() { #if hl Window.getInstance().resize(optionsSettings.screenWidth, optionsSettings.screenHeight); @@ -208,8 +207,7 @@ class Settings { if (settingsExists) { #if hl - var json = - Json.parse(File.getContent(Path.join([settingsDir, "settings.json"]))); + var json = Json.parse(File.getContent(Path.join([settingsDir, "settings.json"]))); #end #if js var json = Json.parse(localStorage.getItem("MBHaxeSettings")); @@ -247,7 +245,7 @@ class Settings { // @:privateAccess Window.getInstance().window.center(); Window.getInstance().addResizeEvent(() -> { var wnd = Window.getInstance(); - var zoomRatio = 1.0; + var zoomRatio = Window.getInstance().windowToPixelRatio; #if js var zoomRatio = Util.isTouchDevice() ? js.Browser.window.screen.height * js.Browser.window.devicePixelRatio / 600 : js.Browser.window.devicePixelRatio; // 768 / js.Browser.window.innerHeight; // js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio / 768; Settings.zoomRatio = zoomRatio; diff --git a/src/gui/GuiControl.hx b/src/gui/GuiControl.hx index 49fe4a9f..20bad208 100644 --- a/src/gui/GuiControl.hx +++ b/src/gui/GuiControl.hx @@ -119,7 +119,7 @@ class GuiControl { rect.position = parentRect.position.add(this.position.multiply(uiScaleFactor)); } - var scaleFactor = 1.0; + var scaleFactor = 1.0 / Window.getInstance().windowToPixelRatio; #if (js || android) scaleFactor = 1 / Settings.zoomRatio; // 768 / js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio; // 0.5; // 768 / js.Browser.window.innerHeight; // js.Browser.window.innerHeight * js.Browser.window.devicePixelRatio / 768; #end