From e5e8028b3fc296cc4364b61d6711bba99057e058 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 26 Jun 2023 19:07:25 +0900 Subject: [PATCH] fix: clickOnceListener would not fired if screen is magnified --- src/net/torvald/terrarum/App.java | 13 +++++-------- src/net/torvald/terrarum/TerrarumScreenSize.kt | 12 +++++++----- .../modulebasegame/ui/UIGraphicsControlPanel.kt | 8 ++++++++ src/net/torvald/terrarum/ui/UICanvas.kt | 2 +- src/net/torvald/terrarum/ui/UIItem.kt | 2 ++ src/net/torvald/terrarum/ui/UIItemToggleButton.kt | 1 + 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/net/torvald/terrarum/App.java b/src/net/torvald/terrarum/App.java index fbebc56d6..1e17dbb63 100644 --- a/src/net/torvald/terrarum/App.java +++ b/src/net/torvald/terrarum/App.java @@ -383,8 +383,8 @@ public class App implements ApplicationListener { ShaderProgram.pedantic = false; scr = new TerrarumScreenSize(getConfigInt("screenwidth"), getConfigInt("screenheight")); - int width = (int) Math.round(scr.getWidth() * scr.getMagn()); - int height = (int) Math.round(scr.getHeight() * scr.getMagn()); + int width = scr.getWindowW(); + int height = scr.getWindowH(); Lwjgl3ApplicationConfiguration appConfig = new Lwjgl3ApplicationConfiguration(); //appConfig.useGL30 = false; // https://stackoverflow.com/questions/46753218/libgdx-should-i-use-gl30 @@ -776,12 +776,9 @@ public class App implements ApplicationListener { @Override public void resize(int w0, int h0) { - int w = (w0%2==0)?w0:w0+1; - int h = (h0%2==0)?h0:h0+1; - float magn = (float) getConfigDouble("screenmagnifying"); - int width = Math.round(w / magn); - int height = Math.round(h / magn); + int width = Math.round(w0 / magn); + int height = Math.round(h0 / magn); printdbg(this, "Resize called: "+width+","+height); @@ -791,7 +788,7 @@ public class App implements ApplicationListener { //initViewPort(width, height); - scr.setDimension(width, height, magn, w, h); + scr.setDimension(width, height, magn); if (currentScreen != null) currentScreen.resize(scr.getWidth(), scr.getHeight()); TerrarumPostProcessor.INSTANCE.resize(scr.getWidth(), scr.getHeight()); diff --git a/src/net/torvald/terrarum/TerrarumScreenSize.kt b/src/net/torvald/terrarum/TerrarumScreenSize.kt index 7c2bcd0e2..8eeebc1e4 100644 --- a/src/net/torvald/terrarum/TerrarumScreenSize.kt +++ b/src/net/torvald/terrarum/TerrarumScreenSize.kt @@ -33,14 +33,16 @@ class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) { val tvSafeActionWidth: Int; get() = Math.round(width * TV_SAFE_ACTION) val tvSafeActionHeight: Int; get() = Math.round(height * TV_SAFE_ACTION) + /** Apparent window size. `roundToEven(width * magn)` */ var windowW: Int = 0; private set + /** Apparent window size. `roundToEven(height * magn)` */ var windowH: Int = 0; private set init { - setDimension(maxOf(minimumW, scrw), maxOf(minimumH, scrh), App.getConfigDouble("screenmagnifying").toFloat(), maxOf(minimumW, scrw), maxOf(minimumH, scrh)) + setDimension(maxOf(minimumW, scrw), maxOf(minimumH, scrh), App.getConfigDouble("screenmagnifying").toFloat()) } - fun setDimension(scrw: Int, scrh: Int, magn: Float, ww: Int, wh: Int) { + fun setDimension(scrw: Int, scrh: Int, magn: Float,) { width = scrw and 0x7FFFFFFE height = scrh and 0x7FFFFFFE wf = scrw.toFloat() @@ -54,11 +56,11 @@ class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) { this.magn = magn - windowW = ww - windowH = wh + windowW = (scrw * magn).roundToInt() and 0x7FFFFFFE + windowH = (scrh * magn).roundToInt() and 0x7FFFFFFE - printdbg(this, "Window dim: $ww x $wh, called by:") + printdbg(this, "Window dim: $windowW x $windowH, called by:") printStackTrace(this) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt index 221175b0c..ffe698df0 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt @@ -223,6 +223,14 @@ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() { } } + override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + return super.touchDown(screenX, screenY, pointer, button) + } + + override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + return super.touchUp(screenX, screenY, pointer, button) + } + override fun dispose() { } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index 34c5b5f9e..d7fe2279d 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -190,7 +190,7 @@ abstract class UICanvas( if (!uiItems.contains(uiItem)) uiItems.add(uiItem) } - fun mouseInScreen(x: Int, y: Int) = x in 0 until App.scr.width && y in 0 until App.scr.height + fun mouseInScreen(x: Int, y: Int) = x in 0 until App.scr.windowW && y in 0 until App.scr.windowH /** * Called by the screen's InputProcessor diff --git a/src/net/torvald/terrarum/ui/UIItem.kt b/src/net/torvald/terrarum/ui/UIItem.kt index f0b441510..c6880f968 100644 --- a/src/net/torvald/terrarum/ui/UIItem.kt +++ b/src/net/torvald/terrarum/ui/UIItem.kt @@ -215,6 +215,8 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I return false } open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + // FIXME does not work with magnified screen + var actionDone = false if (parentUI.isVisible && isActive) { diff --git a/src/net/torvald/terrarum/ui/UIItemToggleButton.kt b/src/net/torvald/terrarum/ui/UIItemToggleButton.kt index 5b506c6c6..a2a7fdf8d 100644 --- a/src/net/torvald/terrarum/ui/UIItemToggleButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemToggleButton.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.App import net.torvald.terrarum.CommonResourcePool import net.torvald.terrarum.blendNormalStraightAlpha import net.torvald.terrarum.toInt