screen magnifying for hidpi WIP

This commit is contained in:
minjaesong
2022-06-13 13:19:10 +09:00
parent 27509a7291
commit 828a485395
7 changed files with 58 additions and 27 deletions

View File

@@ -351,8 +351,8 @@ public class App implements ApplicationListener {
ShaderProgram.pedantic = false; ShaderProgram.pedantic = false;
scr = new TerrarumScreenSize(getConfigInt("screenwidth"), getConfigInt("screenheight")); scr = new TerrarumScreenSize(getConfigInt("screenwidth"), getConfigInt("screenheight"));
int width = scr.getWidth(); int width = (int) Math.round(scr.getWidth() * scr.getMagn());
int height = scr.getHeight(); int height = (int) Math.round(scr.getHeight() * scr.getMagn());
Lwjgl3ApplicationConfiguration appConfig = new Lwjgl3ApplicationConfiguration(); Lwjgl3ApplicationConfiguration appConfig = new Lwjgl3ApplicationConfiguration();
//appConfig.useGL30 = false; // https://stackoverflow.com/questions/46753218/libgdx-should-i-use-gl30 //appConfig.useGL30 = false; // https://stackoverflow.com/questions/46753218/libgdx-should-i-use-gl30
@@ -719,7 +719,13 @@ public class App implements ApplicationListener {
} }
@Override @Override
public void resize(int width, int height) { public void resize(int w, int h) {
double magn = getConfigDouble("screenmagnifying");
int width = (int) Math.round(w / magn);
int height = (int) Math.round(h / magn);
printdbg(this, "Resize called: "+width+","+height); printdbg(this, "Resize called: "+width+","+height);
printStackTrace(this); printStackTrace(this);
@@ -1223,6 +1229,20 @@ public class App implements ApplicationListener {
return ((int) cfg); return ((int) cfg);
} }
/**
* Return config from config set. If the config does not exist, default value will be returned.
* @param key
* *
* @return Config from config set or default config if it does not exist.
* *
* @throws NullPointerException if the specified config simply does not exist.
*/
public static double getConfigDouble(String key) {
Object cfg = getConfigMaster(key);
return (cfg instanceof Integer) ? (((Integer) cfg) * 1.0) : ((double) (cfg));
}
/** /**
* Return config from config set. If the config does not exist, default value will be returned. * Return config from config set. If the config does not exist, default value will be returned.
* @param key * @param key

View File

@@ -105,7 +105,9 @@ object DefaultConfig {
//"fx_3dlut" to false, //"fx_3dlut" to false,
"basekeyboardlayout" to "en_intl_qwerty", "basekeyboardlayout" to "en_intl_qwerty",
"inputmethod" to "none" "inputmethod" to "none",
"screenmagnifying" to 1.0
// settings regarding debugger // settings regarding debugger

View File

@@ -220,16 +220,16 @@ object Terrarum : Disposable {
/** Position of the cursor in the world, rounded */ /** Position of the cursor in the world, rounded */
val mouseX: Double val mouseX: Double
get() = (WorldCamera.zoomedX + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble()).fmod(WorldCamera.worldWidth.toDouble()) get() = (WorldCamera.zoomedX + Gdx.input.x / (ingame?.screenZoom ?: 1f).times(scr.magn)).fmod(WorldCamera.worldWidth.toDouble())
/** Position of the cursor in the world */ /** Position of the cursor in the world */
val mouseY: Double val mouseY: Double
get() = (WorldCamera.zoomedY + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble()) get() = (WorldCamera.zoomedY + Gdx.input.y / (ingame?.screenZoom ?: 1f).times(scr.magn))
/** Position of the cursor in the world, rounded */ /** Position of the cursor in the world, rounded */
val oldMouseX: Double val oldMouseX: Double
get() = (WorldCamera.zoomedX + (Gdx.input.x - Gdx.input.deltaX) / (ingame?.screenZoom ?: 1f).toDouble()).fmod(WorldCamera.worldWidth.toDouble()) get() = (WorldCamera.zoomedX + (Gdx.input.x - Gdx.input.deltaX) / (ingame?.screenZoom ?: 1f).times(scr.magn)).fmod(WorldCamera.worldWidth.toDouble())
/** Position of the cursor in the world */ /** Position of the cursor in the world */
val oldMouseY: Double val oldMouseY: Double
get() = WorldCamera.zoomedY + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).toDouble() get() = WorldCamera.zoomedY + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).times(scr.magn)
/** Position of the cursor in the world, rounded */ /** Position of the cursor in the world, rounded */
@JvmStatic val mouseTileX: Int @JvmStatic val mouseTileX: Int
get() = (mouseX / TILE_SIZE).floorInt() get() = (mouseX / TILE_SIZE).floorInt()
@@ -243,13 +243,13 @@ object Terrarum : Disposable {
@JvmStatic val oldMouseTileY: Int @JvmStatic val oldMouseTileY: Int
get() = (oldMouseY / TILE_SIZE).floorInt() get() = (oldMouseY / TILE_SIZE).floorInt()
inline val mouseScreenX: Int inline val mouseScreenX: Int
get() = Gdx.input.x get() = Gdx.input.x.div(scr.magn).roundToInt()
inline val mouseScreenY: Int inline val mouseScreenY: Int
get() = Gdx.input.y get() = Gdx.input.y.div(scr.magn).roundToInt()
inline val mouseDeltaX: Int inline val mouseDeltaX: Int
get() = Gdx.input.deltaX get() = Gdx.input.deltaX.div(scr.magn).roundToInt()
inline val mouseDeltaY: Int inline val mouseDeltaY: Int
get() = Gdx.input.deltaY get() = Gdx.input.deltaY.div(scr.magn).roundToInt()
/** Delta converted as it it was a FPS */ /** Delta converted as it it was a FPS */
inline val updateRate: Double inline val updateRate: Double
get() = 1.0 / Gdx.graphics.deltaTime get() = 1.0 / Gdx.graphics.deltaTime

View File

@@ -25,6 +25,7 @@ class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) {
var aspectRatio: Float = 0f; private set var aspectRatio: Float = 0f; private set
var chatWidth: Int = 0; private set var chatWidth: Int = 0; private set
var magn: Double = 0.0; private set // this value is stored here so that the initial instance would stay, forcing the players to require restart to apply the screen magnifying
val tvSafeGraphicsWidth: Int; get() = Math.round(width * TV_SAFE_GRAPHICS) val tvSafeGraphicsWidth: Int; get() = Math.round(width * TV_SAFE_GRAPHICS)
val tvSafeGraphicsHeight: Int; get() = Math.round(height * TV_SAFE_GRAPHICS) val tvSafeGraphicsHeight: Int; get() = Math.round(height * TV_SAFE_GRAPHICS)
@@ -46,6 +47,8 @@ class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) {
halfhf = hf / 2f halfhf = hf / 2f
aspectRatio = wf / hf aspectRatio = wf / hf
chatWidth = (width - (width * 0.84375).roundToInt()) and 0x7FFFFFFE chatWidth = (width - (width * 0.84375).roundToInt()) and 0x7FFFFFFE
magn = App.getConfigDouble("screenmagnifying")
} }
} }

View File

@@ -511,7 +511,7 @@ object IngameRenderer : Disposable {
} }
// NOTE TO SELF: this works. // NOTE TO SELF: this works.
} }

View File

@@ -3,11 +3,11 @@ package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.unicode.TIMES
import net.torvald.terrarum.App import net.torvald.terrarum.App
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELL_COL import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELL_COL
import net.torvald.terrarum.ui.* import net.torvald.terrarum.ui.*
import net.torvald.unicode.TIMES
/** /**
* Created by minjaesong on 2021-10-06. * Created by minjaesong on 2021-10-06.
@@ -31,7 +31,8 @@ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() {
arrayOf("fx_backgroundblur", { Lang["MENU_OPTIONS_BLUR"] }, "toggle"), arrayOf("fx_backgroundblur", { Lang["MENU_OPTIONS_BLUR"] }, "toggle"),
arrayOf("fx_streamerslayout", { Lang["MENU_OPTION_STREAMERS_LAYOUT"] }, "toggle"), arrayOf("fx_streamerslayout", { Lang["MENU_OPTION_STREAMERS_LAYOUT"] }, "toggle"),
arrayOf("usevsync", { Lang["MENU_OPTIONS_VSYNC"]+"*" }, "toggle"), arrayOf("usevsync", { Lang["MENU_OPTIONS_VSYNC"]+"*" }, "toggle"),
arrayOf("maxparticles", { Lang["MENU_OPTIONS_PARTICLES"] }, "spinner,256,1024,256") arrayOf("screenmagnifying", { Lang["MENU_OPTIONS_RESOLUTION"]+"*" }, "spinnerd,1.0,2.0,0.25"),
arrayOf("maxparticles", { Lang["MENU_OPTIONS_PARTICLES"] }, "spinner,256,1024,256"),
) )
private fun makeButton(args: String, x: Int, y: Int, optionName: String): UIItem { private fun makeButton(args: String, x: Int, y: Int, optionName: String): UIItem {
@@ -40,7 +41,11 @@ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() {
} }
else if (args.startsWith("spinner,")) { else if (args.startsWith("spinner,")) {
val arg = args.split(',') val arg = args.split(',')
UIItemSpinner(this, x - spinnerWidth, y, App.getConfigInt(optionName), arg[1].toInt(), arg[2].toInt(), arg[3].toInt(), spinnerWidth) UIItemSpinner(this, x - spinnerWidth, y, App.getConfigInt(optionName), arg[1].toInt(), arg[2].toInt(), arg[3].toInt(), spinnerWidth, numberToTextFunction = { "${it.toLong()}" })
}
else if (args.startsWith("spinnerd,")) {
val arg = args.split(',')
UIItemSpinner(this, x - spinnerWidth, y, App.getConfigDouble(optionName), arg[1].toDouble(), arg[2].toDouble(), arg[3].toDouble(), spinnerWidth, numberToTextFunction = { "${it}x" })
} }
else throw IllegalArgumentException(args) else throw IllegalArgumentException(args)
} }

View File

@@ -15,12 +15,13 @@ import net.torvald.terrarum.*
class UIItemSpinner( class UIItemSpinner(
parentUI: UICanvas, parentUI: UICanvas,
initialX: Int, initialY: Int, initialX: Int, initialY: Int,
initialValue: Int, initialValue: Number,
val min: Int, val min: Number,
val max: Int, val max: Number,
val step: Int, val step: Number,
override val width: Int, override val width: Int,
private val drawBorder: Boolean = true private val drawBorder: Boolean = true,
private val numberToTextFunction: (Number) -> String = { "$it" }
) : UIItem(parentUI, initialX, initialY) { ) : UIItem(parentUI, initialX, initialY) {
init { init {
@@ -33,12 +34,12 @@ class UIItemSpinner(
private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, false) private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, false)
var value = initialValue.coerceIn(min, max) var value = initialValue.toDouble().coerceIn(min.toDouble(), max.toDouble()) as Number
var fboUpdateLatch = true var fboUpdateLatch = true
private var mouseOnButton = 0 // 0: nothing, 1: left, 2: right private var mouseOnButton = 0 // 0: nothing, 1: left, 2: right
var selectionChangeListener: (Int) -> Unit = {} var selectionChangeListener: (Number) -> Unit = {}
override fun update(delta: Float) { override fun update(delta: Float) {
super.update(delta) super.update(delta)
@@ -55,7 +56,7 @@ class UIItemSpinner(
if (!mouseLatched && Terrarum.mouseDown && mouseOnButton in 1..2) { if (!mouseLatched && Terrarum.mouseDown && mouseOnButton in 1..2) {
mouseLatched = true mouseLatched = true
value = (value + step * ((mouseOnButton * 2) - 3)).coerceIn(min, max) value = (value.toDouble() + step.toDouble() * ((mouseOnButton * 2) - 3)).coerceIn(min.toDouble(), max.toDouble())
fboUpdateLatch = true fboUpdateLatch = true
selectionChangeListener(value) selectionChangeListener(value)
} }
@@ -72,7 +73,7 @@ class UIItemSpinner(
gdxClearAndSetBlend(0f, 0f, 0f, 0f) gdxClearAndSetBlend(0f, 0f, 0f, 0f)
it.color = Color.WHITE it.color = Color.WHITE
val t = "$value" val t = numberToTextFunction(value)
val tw = App.fontGame.getWidth(t) val tw = App.fontGame.getWidth(t)
App.fontGameFBO.draw(it, t, (fbo.width - tw) / 2, 0) App.fontGameFBO.draw(it, t, (fbo.width - tw) / 2, 0)
} } } }
@@ -133,9 +134,9 @@ class UIItemSpinner(
override fun scrolled(amountX: Float, amountY: Float): Boolean { override fun scrolled(amountX: Float, amountY: Float): Boolean {
if (mouseUp) { if (mouseUp) {
if (amountX <= -1 || amountY <= -1) if (amountX <= -1 || amountY <= -1)
value = (value - step).coerceIn(min, max) value = (value.toDouble() - step.toDouble()).coerceIn(min.toDouble(), max.toDouble())
else if (amountX >= 1 || amountY >= 1) else if (amountX >= 1 || amountY >= 1)
value = (value + step).coerceIn(min, max) value = (value.toDouble() + step.toDouble()).coerceIn(min.toDouble(), max.toDouble())
selectionChangeListener(value) selectionChangeListener(value)
fboUpdateLatch = true fboUpdateLatch = true