From 82ca9cde8e86c826f0022b2014ca7a57da953864 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 | 9 ++++----- src/gui/GuiControl.hx | 2 +- 9 files changed, 15 insertions(+), 12 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 8433cd84..d20d52e6 100644 --- a/compile.hxml +++ b/compile.hxml @@ -4,5 +4,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 b0d3a4bb..471296b1 100644 --- a/src/ResourceLoader.hx +++ b/src/ResourceLoader.hx @@ -22,11 +22,11 @@ import src.Settings; class ResourceLoader { #if (hl && !android) - #if MACOS_BUNDLE + #if MACOS_BUNDLE public static var fileSystem:FileSystem = new TorqueFileSystem(Path.normalize(Path.join([Path.directory(Sys.programPath()), "..", "..", ".."])), null); - #else + #else public static var fileSystem:FileSystem = new TorqueFileSystem(".", null); - #end + #end #end #if (js || android) public static var fileSystem:FileSystem = null; @@ -316,8 +316,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 d6c83f64..e14de707 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -157,13 +157,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-MBP"]); - #else + #else public static var settingsDir = "."; - #end #end - + #end public static function applySettings() { #if hl Window.getInstance().resize(optionsSettings.screenWidth, optionsSettings.screenHeight); @@ -354,7 +353,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 7fa6499e..c732746f 100644 --- a/src/gui/GuiControl.hx +++ b/src/gui/GuiControl.hx @@ -131,7 +131,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