mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +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"
|
"fmt"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sync"
|
"sync"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"golang.org/x/mobile/app"
|
"golang.org/x/mobile/app"
|
||||||
"golang.org/x/mobile/event/key"
|
"golang.org/x/mobile/event/key"
|
||||||
@ -151,6 +152,7 @@ func (u *UserInterface) appMain(a app.App) {
|
|||||||
|
|
||||||
for e := range a.Events() {
|
for e := range a.Events() {
|
||||||
var updateInput bool
|
var updateInput bool
|
||||||
|
var runes []rune
|
||||||
|
|
||||||
switch e := a.Filter(e).(type) {
|
switch e := a.Filter(e).(type) {
|
||||||
case lifecycle.Event:
|
case lifecycle.Event:
|
||||||
@ -204,14 +206,20 @@ func (u *UserInterface) appMain(a app.App) {
|
|||||||
updateInput = true
|
updateInput = true
|
||||||
case key.Event:
|
case key.Event:
|
||||||
k, ok := gbuildKeyToDriverKey[e.Code]
|
k, ok := gbuildKeyToDriverKey[e.Code]
|
||||||
if !ok {
|
if ok {
|
||||||
continue
|
switch e.Direction {
|
||||||
|
case key.DirPress, key.DirNone:
|
||||||
|
keys[k] = struct{}{}
|
||||||
|
case key.DirRelease:
|
||||||
|
delete(keys, k)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch e.Direction {
|
switch e.Direction {
|
||||||
case key.DirPress, key.DirNone:
|
case key.DirPress, key.DirNone:
|
||||||
keys[k] = struct{}{}
|
if e.Rune != -1 && unicode.IsPrint(e.Rune) {
|
||||||
case key.DirRelease:
|
runes = []rune{e.Rune}
|
||||||
delete(keys, k)
|
}
|
||||||
}
|
}
|
||||||
updateInput = true
|
updateInput = true
|
||||||
}
|
}
|
||||||
@ -221,7 +229,7 @@ func (u *UserInterface) appMain(a app.App) {
|
|||||||
for _, t := range touches {
|
for _, t := range touches {
|
||||||
ts = append(ts, t)
|
ts = append(ts, t)
|
||||||
}
|
}
|
||||||
u.input.update(keys, nil, ts)
|
u.input.update(keys, runes, ts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,10 @@
|
|||||||
|
|
||||||
package ebitenmobileview
|
package ebitenmobileview
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
func UpdateTouchesOnAndroid(action int, id int, x, y int) {
|
func UpdateTouchesOnAndroid(action int, id int, x, y int) {
|
||||||
switch action {
|
switch action {
|
||||||
case 0x00, 0x05, 0x02: // ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_MOVE
|
case 0x00, 0x05, 0x02: // ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_MOVE
|
||||||
@ -37,8 +41,8 @@ func OnKeyDownOnAndroid(keyCode int, unicodeChar int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
keys[key] = struct{}{}
|
keys[key] = struct{}{}
|
||||||
if unicodeChar != 0 {
|
if r := rune(unicodeChar); r != 0 && unicode.IsPrint(r) {
|
||||||
runes = []rune{rune(unicodeChar)}
|
runes = []rune{r}
|
||||||
}
|
}
|
||||||
updateInput()
|
updateInput()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user