diff --git a/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java b/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java index c2340213a..09a2622a8 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java @@ -27,6 +27,7 @@ import com.watabou.glwrap.Attribute; import com.watabou.glwrap.Quad; import com.watabou.glwrap.Uniform; import com.watabou.glwrap.Vertexbuffer; +import com.watabou.utils.DeviceCompat; import java.nio.Buffer; import java.nio.FloatBuffer; @@ -166,8 +167,8 @@ public class NoosaScript extends Script { //This fixes pixel scaling issues on some hidpi displays (mainly on macOS) // because for some reason all other openGL operations work on virtual pixels // but glScissor operations work on real pixels - float xScale = (Gdx.graphics.getBackBufferWidth() / (float)Game.width ); - float yScale = ((Gdx.graphics.getBackBufferHeight()-Game.bottomInset) / (float)Game.height ); + float xScale = DeviceCompat.getRealPixelScaleX(); + float yScale = DeviceCompat.getRealPixelScaleY(); Gdx.gl20.glScissor( Math.round(camera.x * xScale), diff --git a/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java b/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java index b8c88647c..ecc8a0bb6 100644 --- a/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java +++ b/SPD-classes/src/main/java/com/watabou/utils/DeviceCompat.java @@ -67,4 +67,15 @@ public class DeviceCompat { return result; } + //some devices (macOS mainly) report virtual pixels to Shattered, but sometimes we want real pixel precision + //this returns the number of real pixels per virtual pixel in the X dimension... + public static float getRealPixelScaleX(){ + return (Gdx.graphics.getBackBufferWidth() / (float)Game.width ); + } + + //...and in the Y dimension + public static float getRealPixelScaleY(){ + return ((Gdx.graphics.getBackBufferHeight()-Game.bottomInset) / (float)Game.height ); + } + } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java index 2f7b06e78..46b6cfdb3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Badges; @@ -325,7 +324,7 @@ public class PixelScene extends Scene { public static RenderedTextBlock renderTextBlock(String text, int size ){ //some systems (macOS mainly) require this back buffer check to ensure // that we're working with real pixels, not logical ones - float scale = Game.width / (float)Gdx.graphics.getBackBufferWidth(); + float scale = DeviceCompat.getRealPixelScaleX(); RenderedTextBlock result = new RenderedTextBlock( text, size*Math.round(defaultZoom*scale)); result.zoom(1/(float)Math.round(defaultZoom*scale)); return result;