ISO keylayout on configs

This commit is contained in:
minjaesong
2024-09-12 13:07:19 +09:00
parent 35c330d253
commit ff16ca5b1a
7 changed files with 579 additions and 145 deletions

Binary file not shown.

View File

@@ -0,0 +1,256 @@
{"n":"Colemak Mod\u2013DH ISO","capslock":"back","l":"iso","t":[[""],[undefined],
[undefined],
["<HOME>"],
[undefined],
["<CALL>"],
["<ENDCALL>"],
["0",")","","”"],
["1","!","¡","¹"],
["2","@","º","²"],
["3","#","ª","³"],
["4","$","¢","£"],
["5","%","€","¥"],
["6","^","ħ","Ħ"],
["7","&","ð","Ð"],
["8","*","þ","Þ"],
["9","(","","“"],
["*"],
["#"],
["<UP>"],
["<DOWN>"],
["<LEFT>"],
["<RIGHT>"],
["<CENTER>"],
["<VOL_UP>"],
["<VOL_DOWN>"],
["<POWER>"],
["<CAMERA>"],
["<CLEAR>"],
["a","A","á","Á"],
["\\","|","¬","¦"],
["d","D","\u0308","°"],
["s","S","ß","ẞ"],
["f","F","ã","Ã"],
["t","T","\u0301","\u030B"],
["g","G","\u0328","¶"],
["m","M","\u0304","µ"],
["u","U","ú","Ú"],
["n","N","ñ","Ñ"],
["e","E","é","É"],
["i","I","í","Í"],
["h","H","\u030C","±"],
["k","K","\u030A","№"],
["y","Y","ü","Ü"],
[";",":","ö","Ö"],
["q","Q","ä","Ä"],
["p","P","ø","Ø"],
["r","R","\u0300","®"],
["b","B","\u0306","©"],
["l","L","ł","Ł"],
["v","V","œ","Œ"],
["w","W","å","Å"],
["c","C","ç","Ç"],
["j","J","đ","Đ"],
["x","X","\u0302","¤"],
[",","<","\u0327","·"],
[".",">","\u0307","…"],
["<ALT_L>"],
["<ALT_R>"],
["<SHIFT_L>"],
["<SHIFT_R>"],
["<TAB>"],
[" "," ","\u00A0","\u00A0"],
["<SYM>"],
["<EXPLORER>"],
["<ENVELOPE>"],
["\n"],
["\x08"],
["`","~","\u0300","\u0303"],
["-","_","","—"],
["=","+","×","÷"],
["[","{","«",""],
["]","}","»",""],
["#","~"],
["o","O","ó","Ó"],
["'",'"',"õ","Õ"],
["/","?","¿","§"],
["<AT>"],
["<NUM_LOCK>"],
["<HEADSETHOOK>"],
["<FOCUS>"],
["+"],
["<MENU>"],
["<NOTIFICATION>"],
["<SEARCH>"],
["<PLAY_PAUSE>"],
["<STOP>"],
["<NEXT>"],
["<PREV>"],
["<REW>"],
["<FFWD>"],
["<MUTE>"],
["<PAGE_UP>"],
["<PAGE_DOWN>"],
["<PICTSYMBOLS>"],
["<SWITCH_CHARSET>"],
["<:A:>"],
["<:B:>"],
["<:C:>"],
["<:X:>"],
["<:Y:>"],
["<:Z:>"],
["<:L1:>"],
["<:R1:>"],
["<:L2:>"],
["<:R2:>"],
["<:TL:>"],
["<:TR:>"],
["<:START:>"],
["<:SELECT:>"],
["<:MODE:>"],
["<ESC>"],
["<DEL>"],
[undefined],
[undefined],
["<CAPS_LOCK>"],
["<SCROLL_LOCK>"],
[undefined],
[undefined],
[undefined],
["<PRINT_SCREEN_SYS_RQ>"],
["<PAUSE_BREAK>"],
[undefined],
["<END>"],
["<INSERT>"],
[undefined],
[undefined],
[undefined],
[undefined],
["<CTRL_L>"],
["<CTRL_R>"],
["<F1>"],
["<F2>"],
["<F3>"],
["<F4>"],
["<F5>"],
["<F6>"],
["<F7>"],
["<F8>"],
["<F9>"],
["<F10>"],
["<F11>"],
["<F12>"],
["<NUM_LOCK>"],
["0"],
["1"],
["2"],
["3"],
["4"],
["5"],
["6"],
["7"],
["8"],
["9"],
["/"],
["*"],
["-"],
["+"],
["."],
["."],
["\n"],
["="],
["("],
[")"],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
["z","Z","æ","Æ"],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
[undefined],
["<:CIRCLE:>"]
]}

View File

@@ -1,4 +1,4 @@
{"n":"FR Bépo","capslock":"shift","t":[[""],[undefined], // NOTE: ISO key that's between LSHIFT and Z (called NUBS on QMK) is not recognised by GDX; NUHS is same as BACKSLASH
{"n":"FR Bépo","capslock":"shift","l":"iso","t":[[""],[undefined], // NOTE: ISO key that's between LSHIFT and Z (called NUBS on QMK) is not recognised by GDX; NUHS is same as BACKSLASH
[undefined],
["<HOME>"],
[undefined],

View File

@@ -15,9 +15,10 @@ typealias Keysymfun = Map<String, String>
data class TerrarumKeyLayout(
val name: String,
val capsMode: TerrarumKeyCapsMode,
val symbols: Keysyms
val name: String,
val capsMode: TerrarumKeyCapsMode,
val symbols: Keysyms,
val physicalLayout: String
)
enum class TerrarumKeyCapsMode {
@@ -25,24 +26,24 @@ enum class TerrarumKeyCapsMode {
}
data class TerrarumIME(
val name: String,
val config: TerrarumIMEConf,
// (headkey, shiftin, altgrin, lowLayerKeysym)
val acceptChar: (Int, Boolean, Boolean, String) -> Pair<IMECandidates, IMEOutput>,
val backspace: () -> IMECandidates,
val endCompose: () -> IMEOutput,
val reset: () -> Unit,
val composing: () -> Boolean
val name: String,
val config: TerrarumIMEConf,
// (headkey, shiftin, altgrin, lowLayerKeysym)
val acceptChar: (Int, Boolean, Boolean, String) -> Pair<IMECandidates, IMEOutput>,
val backspace: () -> IMECandidates,
val endCompose: () -> IMEOutput,
val reset: () -> Unit,
val composing: () -> Boolean
)
data class TerrarumIMEConf(
val name: String,
val copying: String,
val lang: String,
val candidates: TerrarumIMEViewCount,
val symbols: Keysyms?,
val symbolsfun: Keysymfun?,
val mode: TerrarumIMEMode
val name: String,
val copying: String,
val lang: String,
val candidates: TerrarumIMEViewCount,
val symbols: Keysyms?,
val symbolsfun: Keysymfun?,
val mode: TerrarumIMEMode
)
enum class TerrarumIMEViewCount {
@@ -177,6 +178,12 @@ object IME {
val jsval = context.eval("js", "'use strict';Object.freeze($src)")
val name = jsval.getMember("n").asString()
val capsmode = jsval.getMember("capslock").asString().toCapsMode()
val physicalLayout = try {
jsval.getMember("l").asString().lowercase()
}
catch (e: NullPointerException) {
"ansi"
}
val out = Array(256) { Array<String?>(4) { null } }
@@ -196,7 +203,7 @@ object IME {
// println("[IME] Test Keymap print for $name:"); for (keycode in 0 until 256) { print("$keycode:\t"); println(out[keycode].joinToString("\t")) }
return TerrarumKeyLayout(name, capsmode, out)
return TerrarumKeyLayout(name, capsmode, out, physicalLayout)
}
private fun String.toCanditates(): List<String> =

View File

@@ -2,17 +2,13 @@ package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.unicode.EMDASH
import net.torvald.terrarum.App
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.ControlPresets
import net.torvald.terrarum.gamecontroller.*
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.linearSearch
import net.torvald.terrarum.ui.*
/**
@@ -20,10 +16,6 @@ import net.torvald.terrarum.ui.*
*/
class UIIMEConfig(remoCon: UIRemoCon?) : UICanvas() {
init {
handler.allowESCtoClose = false
}
override var width = 480
override var height = 600
@@ -34,81 +26,176 @@ class UIIMEConfig(remoCon: UIRemoCon?) : UICanvas() {
internal val kbx = drawX + 1
internal val kby = drawY + 95
private val oneu = 28
private val onehalfu = 44
private val twou = 52
private val twohalfu = 68
private val threeu = 84
private val spaceu = 188
private val keycaps = hashMapOf(
Input.Keys.GRAVE to UIItemInputKeycap(this, 1, 1, Input.Keys.GRAVE, oneu),
Input.Keys.NUM_1 to UIItemInputKeycap(this, 33,1, Input.Keys.NUM_1, oneu),
Input.Keys.NUM_2 to UIItemInputKeycap(this, 65,1, Input.Keys.NUM_2, oneu),
Input.Keys.NUM_3 to UIItemInputKeycap(this, 97,1, Input.Keys.NUM_3, oneu),
Input.Keys.NUM_4 to UIItemInputKeycap(this, 129,1, Input.Keys.NUM_4, oneu),
Input.Keys.NUM_5 to UIItemInputKeycap(this, 161,1, Input.Keys.NUM_5, oneu),
Input.Keys.NUM_6 to UIItemInputKeycap(this, 193,1, Input.Keys.NUM_6, oneu),
Input.Keys.NUM_7 to UIItemInputKeycap(this, 225,1, Input.Keys.NUM_7, oneu),
Input.Keys.NUM_8 to UIItemInputKeycap(this, 257,1, Input.Keys.NUM_8, oneu),
Input.Keys.NUM_9 to UIItemInputKeycap(this, 289,1, Input.Keys.NUM_9, oneu),
Input.Keys.NUM_0 to UIItemInputKeycap(this, 321,1, Input.Keys.NUM_0, oneu),
Input.Keys.MINUS to UIItemInputKeycap(this, 353,1, Input.Keys.MINUS, oneu),
Input.Keys.EQUALS to UIItemInputKeycap(this, 385,1, Input.Keys.EQUALS, oneu),
Input.Keys.BACKSPACE to UIItemInputKeycap(this, 417,1, Input.Keys.BACKSPACE, 60),
companion object {
private val oneu = 28
private val onequartu = 36
private val onehalfu = 44
private val twou = 52
private val twoquartu = 60
private val twohalfu = 68
private val threeu = 84
private val spaceu = 188
Input.Keys.TAB to UIItemInputKeycap(this, 1,33, Input.Keys.TAB, onehalfu),
Input.Keys.Q to UIItemInputKeycap(this, 49,33, Input.Keys.Q, oneu),
Input.Keys.W to UIItemInputKeycap(this, 81,33, Input.Keys.W, oneu),
Input.Keys.E to UIItemInputKeycap(this, 113,33, Input.Keys.E, oneu),
Input.Keys.R to UIItemInputKeycap(this, 145,33, Input.Keys.R, oneu),
Input.Keys.T to UIItemInputKeycap(this, 177,33, Input.Keys.T, oneu),
Input.Keys.Y to UIItemInputKeycap(this, 209,33, Input.Keys.Y, oneu),
Input.Keys.U to UIItemInputKeycap(this, 241,33, Input.Keys.U, oneu),
Input.Keys.I to UIItemInputKeycap(this, 273,33, Input.Keys.I, oneu),
Input.Keys.O to UIItemInputKeycap(this, 305,33, Input.Keys.O, oneu),
Input.Keys.P to UIItemInputKeycap(this, 337,33, Input.Keys.P, oneu),
Input.Keys.LEFT_BRACKET to UIItemInputKeycap(this, 369,33, Input.Keys.LEFT_BRACKET, oneu),
Input.Keys.RIGHT_BRACKET to UIItemInputKeycap(this, 401,33, Input.Keys.RIGHT_BRACKET, oneu),
Input.Keys.BACKSLASH to UIItemInputKeycap(this, 433,33, Input.Keys.BACKSLASH, onehalfu),
private fun getKeycapsANSI(parent: UIIMEConfig) = hashMapOf(
Input.Keys.GRAVE to UIItemInputKeycap(parent, 1, 1, Input.Keys.GRAVE, oneu),
Input.Keys.NUM_1 to UIItemInputKeycap(parent, 33,1, Input.Keys.NUM_1, oneu),
Input.Keys.NUM_2 to UIItemInputKeycap(parent, 65,1, Input.Keys.NUM_2, oneu),
Input.Keys.NUM_3 to UIItemInputKeycap(parent, 97,1, Input.Keys.NUM_3, oneu),
Input.Keys.NUM_4 to UIItemInputKeycap(parent, 129,1, Input.Keys.NUM_4, oneu),
Input.Keys.NUM_5 to UIItemInputKeycap(parent, 161,1, Input.Keys.NUM_5, oneu),
Input.Keys.NUM_6 to UIItemInputKeycap(parent, 193,1, Input.Keys.NUM_6, oneu),
Input.Keys.NUM_7 to UIItemInputKeycap(parent, 225,1, Input.Keys.NUM_7, oneu),
Input.Keys.NUM_8 to UIItemInputKeycap(parent, 257,1, Input.Keys.NUM_8, oneu),
Input.Keys.NUM_9 to UIItemInputKeycap(parent, 289,1, Input.Keys.NUM_9, oneu),
Input.Keys.NUM_0 to UIItemInputKeycap(parent, 321,1, Input.Keys.NUM_0, oneu),
Input.Keys.MINUS to UIItemInputKeycap(parent, 353,1, Input.Keys.MINUS, oneu),
Input.Keys.EQUALS to UIItemInputKeycap(parent, 385,1, Input.Keys.EQUALS, oneu),
Input.Keys.BACKSPACE to UIItemInputKeycap(parent, 417,1, Input.Keys.BACKSPACE, twoquartu),
Input.Keys.CAPS_LOCK to UIItemInputKeycap(this, 1,65, Input.Keys.CAPS_LOCK, twou),
Input.Keys.A to UIItemInputKeycap(this, 57,65, Input.Keys.A, oneu),
Input.Keys.S to UIItemInputKeycap(this, 89,65, Input.Keys.S, oneu),
Input.Keys.D to UIItemInputKeycap(this, 121,65, Input.Keys.D, oneu),
Input.Keys.F to UIItemInputKeycap(this, 153,65, Input.Keys.F, oneu, true),
Input.Keys.G to UIItemInputKeycap(this, 185,65, Input.Keys.G, oneu),
Input.Keys.H to UIItemInputKeycap(this, 217,65, Input.Keys.H, oneu),
Input.Keys.J to UIItemInputKeycap(this, 249,65, Input.Keys.J, oneu, true),
Input.Keys.K to UIItemInputKeycap(this, 281,65, Input.Keys.K, oneu),
Input.Keys.L to UIItemInputKeycap(this, 313,65, Input.Keys.L, oneu),
Input.Keys.SEMICOLON to UIItemInputKeycap(this, 345,65, Input.Keys.SEMICOLON, oneu),
Input.Keys.APOSTROPHE to UIItemInputKeycap(this, 377,65, Input.Keys.APOSTROPHE, oneu),
Input.Keys.ENTER to UIItemInputKeycap(this, 409,65, Input.Keys.ENTER, twohalfu),
Input.Keys.TAB to UIItemInputKeycap(parent, 1,33, Input.Keys.TAB, onehalfu),
Input.Keys.Q to UIItemInputKeycap(parent, 49,33, Input.Keys.Q, oneu),
Input.Keys.W to UIItemInputKeycap(parent, 81,33, Input.Keys.W, oneu),
Input.Keys.E to UIItemInputKeycap(parent, 113,33, Input.Keys.E, oneu),
Input.Keys.R to UIItemInputKeycap(parent, 145,33, Input.Keys.R, oneu),
Input.Keys.T to UIItemInputKeycap(parent, 177,33, Input.Keys.T, oneu),
Input.Keys.Y to UIItemInputKeycap(parent, 209,33, Input.Keys.Y, oneu),
Input.Keys.U to UIItemInputKeycap(parent, 241,33, Input.Keys.U, oneu),
Input.Keys.I to UIItemInputKeycap(parent, 273,33, Input.Keys.I, oneu),
Input.Keys.O to UIItemInputKeycap(parent, 305,33, Input.Keys.O, oneu),
Input.Keys.P to UIItemInputKeycap(parent, 337,33, Input.Keys.P, oneu),
Input.Keys.LEFT_BRACKET to UIItemInputKeycap(parent, 369,33, Input.Keys.LEFT_BRACKET, oneu),
Input.Keys.RIGHT_BRACKET to UIItemInputKeycap(parent, 401,33, Input.Keys.RIGHT_BRACKET, oneu),
Input.Keys.BACKSLASH to UIItemInputKeycap(parent, 433,33, Input.Keys.BACKSLASH, onehalfu),
Input.Keys.SHIFT_LEFT to UIItemInputKeycap(this, 1,97, Input.Keys.SHIFT_LEFT, twohalfu),
Input.Keys.Z to UIItemInputKeycap(this, 73,97, Input.Keys.Z, oneu),
Input.Keys.X to UIItemInputKeycap(this, 105,97, Input.Keys.X, oneu),
Input.Keys.C to UIItemInputKeycap(this, 137,97, Input.Keys.C, oneu),
Input.Keys.V to UIItemInputKeycap(this, 169,97, Input.Keys.V, oneu),
Input.Keys.B to UIItemInputKeycap(this, 201,97, Input.Keys.B, oneu),
Input.Keys.N to UIItemInputKeycap(this, 233,97, Input.Keys.N, oneu),
Input.Keys.M to UIItemInputKeycap(this, 265,97, Input.Keys.M, oneu),
Input.Keys.COMMA to UIItemInputKeycap(this, 297,97, Input.Keys.COMMA, oneu),
Input.Keys.PERIOD to UIItemInputKeycap(this, 329,97, Input.Keys.PERIOD, oneu),
Input.Keys.SLASH to UIItemInputKeycap(this, 361,97, Input.Keys.SLASH, oneu),
Input.Keys.SHIFT_RIGHT to UIItemInputKeycap(this, 393,97, Input.Keys.SHIFT_RIGHT, threeu),
Input.Keys.CAPS_LOCK to UIItemInputKeycap(parent, 1,65, Input.Keys.CAPS_LOCK, twou),
Input.Keys.A to UIItemInputKeycap(parent, 57,65, Input.Keys.A, oneu),
Input.Keys.S to UIItemInputKeycap(parent, 89,65, Input.Keys.S, oneu),
Input.Keys.D to UIItemInputKeycap(parent, 121,65, Input.Keys.D, oneu),
Input.Keys.F to UIItemInputKeycap(parent, 153,65, Input.Keys.F, oneu, true),
Input.Keys.G to UIItemInputKeycap(parent, 185,65, Input.Keys.G, oneu),
Input.Keys.H to UIItemInputKeycap(parent, 217,65, Input.Keys.H, oneu),
Input.Keys.J to UIItemInputKeycap(parent, 249,65, Input.Keys.J, oneu, true),
Input.Keys.K to UIItemInputKeycap(parent, 281,65, Input.Keys.K, oneu),
Input.Keys.L to UIItemInputKeycap(parent, 313,65, Input.Keys.L, oneu),
Input.Keys.SEMICOLON to UIItemInputKeycap(parent, 345,65, Input.Keys.SEMICOLON, oneu),
Input.Keys.APOSTROPHE to UIItemInputKeycap(parent, 377,65, Input.Keys.APOSTROPHE, oneu),
Input.Keys.ENTER to UIItemInputKeycap(parent, 409,65, Input.Keys.ENTER, twohalfu),
Input.Keys.CONTROL_LEFT to UIItemInputKeycap(this, 1,129, Input.Keys.CONTROL_LEFT, onehalfu),
-2 to UIItemInputKeycap(this, 49,129, null, oneu),
Input.Keys.ALT_LEFT to UIItemInputKeycap(this, 81,129, Input.Keys.ALT_LEFT, onehalfu),
Input.Keys.SPACE to UIItemInputKeycap(this, 129,129, Input.Keys.SPACE, spaceu),
Input.Keys.ALT_RIGHT to UIItemInputKeycap(this, 321,129, Input.Keys.ALT_RIGHT, onehalfu),
-3 to UIItemInputKeycap(this, 369,129, null, oneu),
-4 to UIItemInputKeycap(this, 401,129, null, oneu),
Input.Keys.CONTROL_RIGHT to UIItemInputKeycap(this, 433,129, Input.Keys.CONTROL_RIGHT, onehalfu),
Input.Keys.SHIFT_LEFT to UIItemInputKeycap(parent, 1,97, Input.Keys.SHIFT_LEFT, twohalfu),
Input.Keys.Z to UIItemInputKeycap(parent, 73,97, Input.Keys.Z, oneu),
Input.Keys.X to UIItemInputKeycap(parent, 105,97, Input.Keys.X, oneu),
Input.Keys.C to UIItemInputKeycap(parent, 137,97, Input.Keys.C, oneu),
Input.Keys.V to UIItemInputKeycap(parent, 169,97, Input.Keys.V, oneu),
Input.Keys.B to UIItemInputKeycap(parent, 201,97, Input.Keys.B, oneu),
Input.Keys.N to UIItemInputKeycap(parent, 233,97, Input.Keys.N, oneu),
Input.Keys.M to UIItemInputKeycap(parent, 265,97, Input.Keys.M, oneu),
Input.Keys.COMMA to UIItemInputKeycap(parent, 297,97, Input.Keys.COMMA, oneu),
Input.Keys.PERIOD to UIItemInputKeycap(parent, 329,97, Input.Keys.PERIOD, oneu),
Input.Keys.SLASH to UIItemInputKeycap(parent, 361,97, Input.Keys.SLASH, oneu),
Input.Keys.SHIFT_RIGHT to UIItemInputKeycap(parent, 393,97, Input.Keys.SHIFT_RIGHT, threeu),
) // end of keycaps
Input.Keys.CONTROL_LEFT to UIItemInputKeycap(parent, 1,129, Input.Keys.CONTROL_LEFT, onehalfu),
-2 to UIItemInputKeycap(parent, 49,129, null, oneu),
Input.Keys.ALT_LEFT to UIItemInputKeycap(parent, 81,129, Input.Keys.ALT_LEFT, onehalfu),
Input.Keys.SPACE to UIItemInputKeycap(parent, 129,129, Input.Keys.SPACE, spaceu),
Input.Keys.ALT_RIGHT to UIItemInputKeycap(parent, 321,129, Input.Keys.ALT_RIGHT, onehalfu),
-3 to UIItemInputKeycap(parent, 369,129, null, oneu),
-4 to UIItemInputKeycap(parent, 401,129, null, oneu),
Input.Keys.CONTROL_RIGHT to UIItemInputKeycap(parent, 433,129, Input.Keys.CONTROL_RIGHT, onehalfu),
) // end of keycaps
private fun getKeycapsISO(parent: UIIMEConfig) = hashMapOf(
Input.Keys.GRAVE to UIItemInputKeycap(parent, 1, 1, Input.Keys.GRAVE, oneu),
Input.Keys.NUM_1 to UIItemInputKeycap(parent, 33,1, Input.Keys.NUM_1, oneu),
Input.Keys.NUM_2 to UIItemInputKeycap(parent, 65,1, Input.Keys.NUM_2, oneu),
Input.Keys.NUM_3 to UIItemInputKeycap(parent, 97,1, Input.Keys.NUM_3, oneu),
Input.Keys.NUM_4 to UIItemInputKeycap(parent, 129,1, Input.Keys.NUM_4, oneu),
Input.Keys.NUM_5 to UIItemInputKeycap(parent, 161,1, Input.Keys.NUM_5, oneu),
Input.Keys.NUM_6 to UIItemInputKeycap(parent, 193,1, Input.Keys.NUM_6, oneu),
Input.Keys.NUM_7 to UIItemInputKeycap(parent, 225,1, Input.Keys.NUM_7, oneu),
Input.Keys.NUM_8 to UIItemInputKeycap(parent, 257,1, Input.Keys.NUM_8, oneu),
Input.Keys.NUM_9 to UIItemInputKeycap(parent, 289,1, Input.Keys.NUM_9, oneu),
Input.Keys.NUM_0 to UIItemInputKeycap(parent, 321,1, Input.Keys.NUM_0, oneu),
Input.Keys.MINUS to UIItemInputKeycap(parent, 353,1, Input.Keys.MINUS, oneu),
Input.Keys.EQUALS to UIItemInputKeycap(parent, 385,1, Input.Keys.EQUALS, oneu),
Input.Keys.BACKSPACE to UIItemInputKeycap(parent, 417,1, Input.Keys.BACKSPACE, twoquartu),
Input.Keys.TAB to UIItemInputKeycap(parent, 1,33, Input.Keys.TAB, onehalfu),
Input.Keys.Q to UIItemInputKeycap(parent, 49,33, Input.Keys.Q, oneu),
Input.Keys.W to UIItemInputKeycap(parent, 81,33, Input.Keys.W, oneu),
Input.Keys.E to UIItemInputKeycap(parent, 113,33, Input.Keys.E, oneu),
Input.Keys.R to UIItemInputKeycap(parent, 145,33, Input.Keys.R, oneu),
Input.Keys.T to UIItemInputKeycap(parent, 177,33, Input.Keys.T, oneu),
Input.Keys.Y to UIItemInputKeycap(parent, 209,33, Input.Keys.Y, oneu),
Input.Keys.U to UIItemInputKeycap(parent, 241,33, Input.Keys.U, oneu),
Input.Keys.I to UIItemInputKeycap(parent, 273,33, Input.Keys.I, oneu),
Input.Keys.O to UIItemInputKeycap(parent, 305,33, Input.Keys.O, oneu),
Input.Keys.P to UIItemInputKeycap(parent, 337,33, Input.Keys.P, oneu),
Input.Keys.LEFT_BRACKET to UIItemInputKeycap(parent, 369,33, Input.Keys.LEFT_BRACKET, oneu),
Input.Keys.RIGHT_BRACKET to UIItemInputKeycap(parent, 401,33, Input.Keys.RIGHT_BRACKET, oneu),
Input.Keys.ENTER to UIItemInputKeycapTwoRowRight(parent, 433,33, Input.Keys.ENTER, onehalfu, onequartu),
Input.Keys.CAPS_LOCK to UIItemInputKeycap(parent, 1,65, Input.Keys.CAPS_LOCK, twou),
Input.Keys.A to UIItemInputKeycap(parent, 57,65, Input.Keys.A, oneu),
Input.Keys.S to UIItemInputKeycap(parent, 89,65, Input.Keys.S, oneu),
Input.Keys.D to UIItemInputKeycap(parent, 121,65, Input.Keys.D, oneu),
Input.Keys.F to UIItemInputKeycap(parent, 153,65, Input.Keys.F, oneu, true),
Input.Keys.G to UIItemInputKeycap(parent, 185,65, Input.Keys.G, oneu),
Input.Keys.H to UIItemInputKeycap(parent, 217,65, Input.Keys.H, oneu),
Input.Keys.J to UIItemInputKeycap(parent, 249,65, Input.Keys.J, oneu, true),
Input.Keys.K to UIItemInputKeycap(parent, 281,65, Input.Keys.K, oneu),
Input.Keys.L to UIItemInputKeycap(parent, 313,65, Input.Keys.L, oneu),
Input.Keys.SEMICOLON to UIItemInputKeycap(parent, 345,65, Input.Keys.SEMICOLON, oneu),
Input.Keys.APOSTROPHE to UIItemInputKeycap(parent, 377,65, Input.Keys.APOSTROPHE, oneu),
Input.Keys.BACKSLASH to UIItemInputKeycap(parent, 409,65, Input.Keys.BACKSLASH, oneu),
Input.Keys.SHIFT_LEFT to UIItemInputKeycap(parent, 1,97, Input.Keys.SHIFT_LEFT, onequartu),
Input.Keys.WORLD_1 to UIItemInputKeycap(parent, 41,97, Input.Keys.WORLD_1, oneu),
Input.Keys.Z to UIItemInputKeycap(parent, 73,97, Input.Keys.Z, oneu),
Input.Keys.X to UIItemInputKeycap(parent, 105,97, Input.Keys.X, oneu),
Input.Keys.C to UIItemInputKeycap(parent, 137,97, Input.Keys.C, oneu),
Input.Keys.V to UIItemInputKeycap(parent, 169,97, Input.Keys.V, oneu),
Input.Keys.B to UIItemInputKeycap(parent, 201,97, Input.Keys.B, oneu),
Input.Keys.N to UIItemInputKeycap(parent, 233,97, Input.Keys.N, oneu),
Input.Keys.M to UIItemInputKeycap(parent, 265,97, Input.Keys.M, oneu),
Input.Keys.COMMA to UIItemInputKeycap(parent, 297,97, Input.Keys.COMMA, oneu),
Input.Keys.PERIOD to UIItemInputKeycap(parent, 329,97, Input.Keys.PERIOD, oneu),
Input.Keys.SLASH to UIItemInputKeycap(parent, 361,97, Input.Keys.SLASH, oneu),
Input.Keys.SHIFT_RIGHT to UIItemInputKeycap(parent, 393,97, Input.Keys.SHIFT_RIGHT, threeu),
Input.Keys.CONTROL_LEFT to UIItemInputKeycap(parent, 1,129, Input.Keys.CONTROL_LEFT, onehalfu),
-2 to UIItemInputKeycap(parent, 49,129, null, oneu),
Input.Keys.ALT_LEFT to UIItemInputKeycap(parent, 81,129, Input.Keys.ALT_LEFT, onehalfu),
Input.Keys.SPACE to UIItemInputKeycap(parent, 129,129, Input.Keys.SPACE, spaceu),
Input.Keys.ALT_RIGHT to UIItemInputKeycap(parent, 321,129, Input.Keys.ALT_RIGHT, onehalfu),
-3 to UIItemInputKeycap(parent, 369,129, null, oneu),
-4 to UIItemInputKeycap(parent, 401,129, null, oneu),
Input.Keys.CONTROL_RIGHT to UIItemInputKeycap(parent, 433,129, Input.Keys.CONTROL_RIGHT, onehalfu),
) // end of keycaps
}
private lateinit var keycaps: HashMap<Int, UIItemInputKeycap>
init {
handler.allowESCtoClose = false
}
private fun refreshKeycaps(layout: String) {
if (::keycaps.isInitialized)
keycaps.values.forEach { removeUIitem(it) }
keycaps = when (layout) {
"ansi" -> getKeycapsANSI(this)
"iso" -> getKeycapsISO(this)
else -> throw IllegalArgumentException("Unknown physical layout: $layout")
}
keycaps.values.forEach { addUIitemAtHead(it) }
}
private val textSelWidth = 266
private val selectorWidth = 600
@@ -149,8 +236,10 @@ class UIIMEConfig(remoCon: UIRemoCon?) : UICanvas() {
)
private var oldPhysicalLayout = IME.getLowLayerByName(App.getConfigString("basekeyboardlayout")).physicalLayout
init {
keycaps.values.forEach { addUIitem(it) }
refreshKeycaps(oldPhysicalLayout)
keyboardLayoutSelection.selectionChangeListener = {
@@ -204,6 +293,16 @@ class UIIMEConfig(remoCon: UIRemoCon?) : UICanvas() {
altgrin = Gdx.input.isKeyPressed(Input.Keys.ALT_RIGHT) || (Gdx.input.isKeyPressed(Input.Keys.ALT_LEFT) && Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT))
lowlayer = IME.getLowLayerByName(App.getConfigString("basekeyboardlayout"))
highlayer = getIME()
detectLowLayerChange()
}
private fun detectLowLayerChange() {
val newPhysicalLayout = IME.getLowLayerByName(App.getConfigString("basekeyboardlayout")).physicalLayout
if (newPhysicalLayout != oldPhysicalLayout) {
oldPhysicalLayout = newPhysicalLayout
refreshKeycaps(newPhysicalLayout)
}
}
internal var shiftin = false; private set
@@ -232,7 +331,7 @@ class UIIMEConfig(remoCon: UIRemoCon?) : UICanvas() {
/**
* @param key LibGDX keycode. Set it to `null` to "disable" the key. Also see [com.badlogic.gdx.Input.Keys]
*/
private class UIItemInputKeycap(
open private class UIItemInputKeycap(
val parent: UIIMEConfig,
initialX: Int,
initialY: Int,
@@ -248,20 +347,20 @@ private class UIItemInputKeycap(
override val height = 28
private val labels = CommonResourcePool.getAsTextureRegionPack("inventory_category")
protected val labels = CommonResourcePool.getAsTextureRegionPack("inventory_category")
var selected = false
private val borderKeyForbidden = Color(0x000000C0)
private val borderKeyNormal = Toolkit.Theme.COL_INACTIVE
private val borderMouseUp = Toolkit.Theme.COL_MOUSE_UP
private val borderKeyPressed = Toolkit.Theme.COL_SELECTED
private val borderKeyPressedAndSelected = Color(0x33FF33FF.toInt())
protected val borderKeyForbidden = Color(0x000000C0)
protected val borderKeyNormal = Toolkit.Theme.COL_INACTIVE
protected val borderMouseUp = Toolkit.Theme.COL_MOUSE_UP
protected val borderKeyPressed = Toolkit.Theme.COL_SELECTED
protected val borderKeyPressedAndSelected = Color(0x33FF33FF.toInt())
private val keycapFill = Toolkit.Theme.COL_CELL_FILL
protected val keycapFill = Toolkit.Theme.COL_CELL_FILL
private val keylabelCol = Color(0xddddddff.toInt())
private val configuredKeyCol = Color.WHITE
protected val keylabelCol = Color(0xddddddff.toInt())
protected val configuredKeyCol = Color.WHITE
override fun update(delta: Float) {
super.update(delta)
@@ -271,58 +370,62 @@ private class UIItemInputKeycap(
c in 0x1DC0..0x1DFF || c in 0x20D0..0x20FF || c in 0xFE20..0xFE2F ||
c == 0xE31 || c in 0xE33..0xE3A || c in 0xE47..0xE4E
override fun render(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
super.render(frameDelta, batch, camera)
protected fun getBorderCol() = if (key == null)
borderKeyForbidden
else if (Gdx.input.isKeyPressed(key))
borderKeyPressed
else
borderKeyNormal
protected open fun drawKeycap(batch: SpriteBatch) {
// key background
batch.color = keycapFill
Toolkit.fillArea(batch, posX, posY, width, height)
batch.color = if (key == null)
borderKeyForbidden
else if (Gdx.input.isKeyPressed(key))
borderKeyPressed
else
borderKeyNormal
// key border
batch.color = getBorderCol()
Toolkit.drawBoxBorder(batch, posX, posY, width, height)
if (homerow) Toolkit.drawBoxBorder(batch, posX + 9, posY + 26, 10, 1)
}
if (homerow) {
Toolkit.drawBoxBorder(batch, posX + 9, posY + 26, 10, 1)
}
protected open fun getKeysymPos() = (posX + (width - 20) / 2).toFloat() to posY + 4f
override fun render(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
super.render(frameDelta, batch, camera)
drawKeycap(batch)
val (symx, symy) = getKeysymPos()
// keysym
if (key == Input.Keys.CONTROL_LEFT || key == Input.Keys.CONTROL_RIGHT)
batch.draw(labels.get(21,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(21,3), symx, symy)
else if (key == Input.Keys.ALT_LEFT)
batch.draw(labels.get(22,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(22,3), symx, symy)
else if (key == Input.Keys.ALT_RIGHT)
batch.draw(labels.get(23,2), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(23,2), symx, symy)
else if (key == Input.Keys.SHIFT_LEFT || key == Input.Keys.SHIFT_RIGHT)
batch.draw(labels.get(23,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(23,3), symx, symy)
else if (key == Input.Keys.TAB)
batch.draw(labels.get(23,5), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(23,5), symx, symy)
else if (key == Input.Keys.BACKSPACE)
batch.draw(labels.get(24,5), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(24,5), symx, symy)
else if (key == Input.Keys.CAPS_LOCK) {
if (parent.lowlayer.capsMode == TerrarumKeyCapsMode.CAPS)
batch.draw(labels.get(24,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(24,3), symx, symy)
else if (parent.lowlayer.capsMode == TerrarumKeyCapsMode.SHIFT)
batch.draw(labels.get(24,2), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(24,2), symx, symy)
else if (parent.lowlayer.capsMode == TerrarumKeyCapsMode.BACK)
batch.draw(labels.get(24,5), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(24,5), symx, symy)
}
else if (key == Input.Keys.ENTER)
batch.draw(labels.get(17,3), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(17,3), symx, symy)
else if (key != null) {
val keysymsLow = parent.lowlayer.symbols[key]
val keysymLow =
(if (parent.shiftin && parent.altgrin && keysymsLow[3]?.isNotEmpty() == true) keysymsLow[3]
else if (parent.altgrin && keysymsLow[2]?.isNotEmpty() == true) keysymsLow[2]
else if (parent.shiftin && keysymsLow[1]?.isNotEmpty() == true) keysymsLow[1]
else keysymsLow[0]) ?: ""
(if (parent.shiftin && parent.altgrin && keysymsLow[3]?.isNotEmpty() == true) keysymsLow[3]
else if (parent.altgrin && keysymsLow[2]?.isNotEmpty() == true) keysymsLow[2]
else if (parent.shiftin && keysymsLow[1]?.isNotEmpty() == true) keysymsLow[1]
else keysymsLow[0]) ?: ""
val keysym0: Array<String?> = if (KeyToggler.isOn(ControlPresets.getKey("control_key_toggleime"))) {
if (parent.highlayer == null) arrayOf(keysymLow,keysymLow,keysymLow,keysymLow)
@@ -343,17 +446,22 @@ private class UIItemInputKeycap(
parent.lowlayer.symbols[key]
var keysym =
(if (parent.shiftin && parent.altgrin && keysym0[3]?.isNotEmpty() == true) keysym0[3]
else if (parent.altgrin && keysym0[2]?.isNotEmpty() == true) keysym0[2]
else if (parent.shiftin && keysym0[1]?.isNotEmpty() == true) keysym0[1]
else keysym0[0]) ?: keysymLow
(if (parent.shiftin && parent.altgrin && keysym0[3]?.isNotEmpty() == true) keysym0[3]
else if (parent.altgrin && keysym0[2]?.isNotEmpty() == true) keysym0[2]
else if (parent.shiftin && keysym0[1]?.isNotEmpty() == true) keysym0[1]
else keysym0[0]) ?: keysymLow
if (keysym.isEmpty()) {
return
}
if (isDiacritic(keysym[0].code))
keysym = "\uDBBF\uDE01$keysym"
if (keysym[0].code == 0xA0)
batch.draw(labels.get(22, 2), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(22, 2), symx, symy)
else if (keysym[0].code == 0x20)
batch.draw(labels.get(21,2), (posX + (width - 20) / 2).toFloat(), posY + 4f)
batch.draw(labels.get(21,2), symx, symy)
else {
val keysymw = App.fontGame.getWidth(keysym)
App.fontGame.draw(batch, keysym, posX + (width - keysymw) / 2, posY + 2)
@@ -364,4 +472,58 @@ private class UIItemInputKeycap(
override fun dispose() {
}
}
}
private class UIItemInputKeycapTwoRowRight(
parent: UIIMEConfig,
initialX: Int,
initialY: Int,
key: Int?,
val widthUp: Int,
val widthDown: Int
) : UIItemInputKeycap(parent, initialX, initialY, key, maxOf(widthUp, widthDown), false) {
init {
this.posX = initialX + parent.kbx
this.posY = initialY + parent.kby
}
private val rowheight = 28
override val height = 60
private val heightUp = if (widthUp > widthDown) 28 else 32
private val heightDown = if (widthUp > widthDown) 32 else 28
private val posXgap = (widthUp - widthDown).abs()
override fun drawKeycap(batch: SpriteBatch) {
// key background
batch.color = keycapFill
Toolkit.fillArea(batch, posX, posY, widthUp, heightUp)
Toolkit.fillArea(batch, posX + posXgap - 1, posY + heightUp, widthDown + 1, 1)
Toolkit.fillArea(batch, posX + posXgap, posY + heightUp + 1, widthDown, heightDown - 1)
// key border
batch.color = getBorderCol()
val pack = CommonResourcePool.getAsTextureRegionPack("toolkit_box_border")
val tx = pack.tileW.toFloat()
val ty = pack.tileH.toFloat()
// top edge
batch.draw(pack.get(1, 0), posX.toFloat(), posY - ty, widthUp.toFloat(), ty)
// bottom edge L
batch.draw(pack.get(1, 2), posX.toFloat(), posY.toFloat() + heightUp, posXgap - 1f, ty)
// bottom edge R
batch.draw(pack.get(1, 2), posX.toFloat() + posXgap, posY.toFloat() + height, widthDown.toFloat(), ty)
// left edge U
batch.draw(pack.get(0, 1), posX.toFloat() - tx, posY.toFloat(), tx, heightUp.toFloat())
// left edge D
batch.draw(pack.get(0, 1), posX.toFloat() - tx + posXgap, posY + heightUp + 1f, tx, heightDown.toFloat())
// right edge
batch.draw(pack.get(2, 1), posX.toFloat() + width, posY.toFloat(), tx, height.toFloat())
if (homerow) Toolkit.drawBoxBorder(batch, posX + 9, posY + 26, 10, 1)
}
override fun getKeysymPos() = (posX + posXgap + (minOf(widthUp, widthDown) - 20) / 2).toFloat() to posY + 20f
}

View File

@@ -66,7 +66,7 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
Input.Keys.P to UIItemKeycap(this, 337,33, Input.Keys.P, oneu, "15,4"),
Input.Keys.LEFT_BRACKET to UIItemKeycap(this, 369,33, Input.Keys.LEFT_BRACKET, oneu, "12,3"),
Input.Keys.RIGHT_BRACKET to UIItemKeycap(this, 401,33, Input.Keys.RIGHT_BRACKET, oneu, "13,3"),
Input.Keys.BACKSLASH to UIItemKeycap(this, 433,33, Input.Keys.BACKSLASH, onehalfu, "20,3"),
Input.Keys.BACKSLASH to UIItemKeycap(this, 433,33, Input.Keys.BACKSLASH, onehalfu, "14,3"),
-5 to UIItemKeycap(this, 1,65, null, twou, "24,3"),
Input.Keys.A to UIItemKeycap(this, 57,65, Input.Keys.A, oneu, "0,4"),
@@ -82,7 +82,8 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() {
Input.Keys.APOSTROPHE to UIItemKeycap(this, 377,65, Input.Keys.APOSTROPHE, oneu, "16,3"),
Input.Keys.ENTER to UIItemKeycap(this, 409,65, Input.Keys.ENTER, twohalfu, "17,3"),
Input.Keys.SHIFT_LEFT to UIItemKeycap(this, 1,97, Input.Keys.SHIFT_LEFT, twohalfu, "23,3"),
Input.Keys.SHIFT_LEFT to UIItemKeycap(this, 1,97, Input.Keys.SHIFT_LEFT, 36, "23,3"),
Input.Keys.WORLD_1 to UIItemKeycap(this, 41,97, Input.Keys.WORLD_1, oneu, "1,5"),
Input.Keys.Z to UIItemKeycap(this, 73,97, Input.Keys.Z, oneu, "0,5"),
Input.Keys.X to UIItemKeycap(this, 105,97, Input.Keys.X, oneu, "23,4"),
Input.Keys.C to UIItemKeycap(this, 137,97, Input.Keys.C, oneu, "2,4"),

View File

@@ -198,6 +198,14 @@ abstract class UICanvas(
if (!uiItems.contains(uiItem)) uiItems.add(uiItem)
}
fun addUIitemAtHead(uiItem: UIItemisable) {
if (!uiItems.contains(uiItem)) uiItems.add(0, uiItem)
}
fun removeUIitem(uiItem: UIItemisable) {
uiItems.remove(uiItem)
}
fun mouseInScreen(x: Int, y: Int) = x in 0 until App.scr.windowW && y in 0 until App.scr.windowH
/**