mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
uidriver/mobile: Implement InputChars for gomobile-build
This change also fixes InputChars to return only printable Unicode chars on Android. Updates #237
This commit is contained in:
parent
de52eb75e4
commit
3af869732c
@ -21,6 +21,7 @@ import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
"unicode"
|
||||
|
||||
"golang.org/x/mobile/app"
|
||||
"golang.org/x/mobile/event/key"
|
||||
@ -151,6 +152,7 @@ func (u *UserInterface) appMain(a app.App) {
|
||||
|
||||
for e := range a.Events() {
|
||||
var updateInput bool
|
||||
var runes []rune
|
||||
|
||||
switch e := a.Filter(e).(type) {
|
||||
case lifecycle.Event:
|
||||
@ -204,15 +206,21 @@ func (u *UserInterface) appMain(a app.App) {
|
||||
updateInput = true
|
||||
case key.Event:
|
||||
k, ok := gbuildKeyToDriverKey[e.Code]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if ok {
|
||||
switch e.Direction {
|
||||
case key.DirPress, key.DirNone:
|
||||
keys[k] = struct{}{}
|
||||
case key.DirRelease:
|
||||
delete(keys, k)
|
||||
}
|
||||
}
|
||||
|
||||
switch e.Direction {
|
||||
case key.DirPress, key.DirNone:
|
||||
if e.Rune != -1 && unicode.IsPrint(e.Rune) {
|
||||
runes = []rune{e.Rune}
|
||||
}
|
||||
}
|
||||
updateInput = true
|
||||
}
|
||||
|
||||
@ -221,7 +229,7 @@ func (u *UserInterface) appMain(a app.App) {
|
||||
for _, t := range touches {
|
||||
ts = append(ts, t)
|
||||
}
|
||||
u.input.update(keys, nil, ts)
|
||||
u.input.update(keys, runes, ts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,10 @@
|
||||
|
||||
package ebitenmobileview
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func UpdateTouchesOnAndroid(action int, id int, x, y int) {
|
||||
switch action {
|
||||
case 0x00, 0x05, 0x02: // ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_MOVE
|
||||
@ -37,8 +41,8 @@ func OnKeyDownOnAndroid(keyCode int, unicodeChar int) {
|
||||
return
|
||||
}
|
||||
keys[key] = struct{}{}
|
||||
if unicodeChar != 0 {
|
||||
runes = []rune{rune(unicodeChar)}
|
||||
if r := rune(unicodeChar); r != 0 && unicode.IsPrint(r) {
|
||||
runes = []rune{r}
|
||||
}
|
||||
updateInput()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user