hangul ime

This commit is contained in:
minjaesong
2021-10-22 17:51:13 +09:00
parent 1c370ac610
commit 9b3384255b
5 changed files with 41 additions and 26 deletions

View File

@@ -10,8 +10,8 @@ data class TerrarumKeyLayout(
data class TerrarumInputMethod(
val name: String,
// (keycodes, shiftin, altgrin)
val acceptChar: (IntArray, Boolean, Boolean) -> Pair<String, String>, // Pair<Display Char, Output Char if any>
// (headkey, shiftin, altgrin)
val acceptChar: (Int, Boolean, Boolean) -> Pair<String, String>, // Pair<Display Char, Output Char if any>
val endCompose: () -> String,
val reset: () -> Unit,
val composing: () -> Boolean
@@ -106,8 +106,8 @@ object IME {
val name = jsval.getMember("n").asString()
return TerrarumInputMethod(name, { it, shifted, alted ->
val a = jsval.invokeMember("accept", context.eval("js", "'${it.joinToString(",")}'.split(',')"), shifted, alted)
return TerrarumInputMethod(name, { headkey, shifted, alted ->
val a = jsval.invokeMember("accept", headkey, shifted, alted)
a.getArrayElement(0).asString() to a.getArrayElement(1).asString()
}, {
jsval.invokeMember("end").asString()

View File

@@ -276,7 +276,8 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
companion object {
data class TerrarumKeyboardEvent(
val type: Int,
val character: String?,
val character: String?, // representative key symbol
val headkey: Int, // representative keycode
val repeatCount: Int,
val keycodes: IntArray
)
@@ -318,11 +319,15 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
else if (shiftin && newKeysym0[1]?.isNotBlank() == true) newKeysym0[1]
else newKeysym0[0]
val headKeyCode = if (keyDiff.size < 1) keys[0] else keyDiff[0]
if (!keyChanged) {
callback(TerrarumKeyboardEvent(KEY_DOWN, keysym, repeatCount, keys))
// println("KEY_DOWN '$keysym' ($headKeyCode) $repeatCount; ${keys.joinToString()}")
callback(TerrarumKeyboardEvent(KEY_DOWN, keysym, headKeyCode, repeatCount, keys))
}
else if (newKeysym != null) {
callback(TerrarumKeyboardEvent(KEY_DOWN, newKeysym, repeatCount, keys))
// println("KEY_DOWC '$newKeysym' ($headKeyCode) $repeatCount; ${keys.joinToString()}")
callback(TerrarumKeyboardEvent(KEY_DOWN, newKeysym, headKeyCode, repeatCount, keys))
}
oldKeys = keys // don't put this outside of if-cascade
@@ -346,7 +351,7 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
private fun keysToStr(keymap: TerrarumKeyLayout, keys: IntArray): Array<String?>? {
if (keys.size == 0) return null
val headkey = keys[0]
return if (keymap.symbols!![headkey] == null) null else keymap.symbols!![headkey]
return keymap.symbols?.get(headkey)
}
private fun strobeKeys(): IntArray {

View File

@@ -165,7 +165,7 @@ class UIItemTextLineInput(
// process keypresses
if (isActive) {
IngameController.withKeyboardEvent { (_, char, _, keycodes) ->
IngameController.withKeyboardEvent { (_, char, headkey, _, keycodes) ->
fboUpdateLatch = true
forceLitCursor()
val ime = getIME()
@@ -195,7 +195,7 @@ class UIItemTextLineInput(
if (cursorX == 0 || (oldCode !in 0x115F..0x11FF && oldCode !in 0xD7B0..0xD7FF)) break
}
cursorDrawX = App.fontGame.getWidth(textbuf.subList(0, cursorX))
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
tryCursorForward()
}
}
@@ -203,13 +203,13 @@ class UIItemTextLineInput(
else if (cursorX > 0 && keycodes.contains(Input.Keys.LEFT)) {
// TODO IME endComposing()
cursorX -= 1
cursorDrawX = App.fontGame.getWidth(textbuf.subList(0, cursorX))
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
tryCursorForward()
}
else if (cursorX < textbuf.size && keycodes.contains(Input.Keys.RIGHT)) {
// TODO IME endComposing()
cursorX += 1
cursorDrawX = App.fontGame.getWidth(textbuf.subList(0, cursorX))
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
tryCursorBack()
}
// accept:
@@ -220,7 +220,7 @@ class UIItemTextLineInput(
val altgrin = keycodes.contains(Input.Keys.ALT_RIGHT)
val codepoints = if (ime != null) {
val newStatus = ime.acceptChar(keycodes, shiftin, altgrin)
val newStatus = ime.acceptChar(headkey, shiftin, altgrin)
composingView = CodepointSequence(newStatus.first.toCodePoints())
newStatus.second.toCodePoints()
@@ -233,7 +233,7 @@ class UIItemTextLineInput(
textbuf.addAll(cursorX, codepoints)
cursorX += codepoints.size
cursorDrawX = App.fontGame.getWidth(textbuf.subList(0, cursorX))
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
tryCursorBack()
}
@@ -302,7 +302,7 @@ class UIItemTextLineInput(
textbuf.addAll(cursorX, actuallyInserted)
cursorX += actuallyInserted.size
cursorDrawX = App.fontGame.getWidth(textbuf.subList(0, cursorX))
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
tryCursorBack()