mobile/ebitenmobileview: Implement InputChars on Android / ebitenmobile

Updates #237
This commit is contained in:
Hajime Hoshi 2020-02-23 00:42:52 +09:00
parent 0ea5e65c92
commit de52eb75e4
6 changed files with 18 additions and 10 deletions

View File

@ -383,7 +383,7 @@ public class EbitenView extends ViewGroup {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Ebitenmobileview.onKeyDownOnAndroid(keyCode);
Ebitenmobileview.onKeyDownOnAndroid(keyCode, event.getUnicodeChar());
return true;
}

File diff suppressed because one or more lines are too long

View File

@ -29,6 +29,7 @@ type Input struct {
cursorX int
cursorY int
keys map[driver.Key]struct{}
runes []rune
touches map[int]pos
ui *UserInterface
}
@ -95,7 +96,7 @@ func (i *Input) TouchPosition(id int) (x, y int) {
}
func (i *Input) RuneBuffer() []rune {
return nil
return i.runes
}
func (i *Input) IsKeyPressed(key driver.Key) bool {
@ -117,7 +118,7 @@ func (i *Input) IsMouseButtonPressed(key driver.MouseButton) bool {
return false
}
func (i *Input) update(keys map[driver.Key]struct{}, touches []*Touch) {
func (i *Input) update(keys map[driver.Key]struct{}, runes []rune, touches []*Touch) {
i.ui.m.Lock()
defer i.ui.m.Unlock()
@ -126,6 +127,9 @@ func (i *Input) update(keys map[driver.Key]struct{}, touches []*Touch) {
i.keys[k] = struct{}{}
}
i.runes = make([]rune, len(runes))
copy(i.runes, runes)
i.touches = map[int]pos{}
for _, t := range touches {
i.touches[t.ID] = pos{
@ -136,5 +140,5 @@ func (i *Input) update(keys map[driver.Key]struct{}, touches []*Touch) {
}
func (i *Input) ResetForFrame() {
// Do nothing
i.runes = nil
}

View File

@ -221,7 +221,7 @@ func (u *UserInterface) appMain(a app.App) {
for _, t := range touches {
ts = append(ts, t)
}
u.input.update(keys, ts)
u.input.update(keys, nil, ts)
}
}
}
@ -443,6 +443,6 @@ type Touch struct {
Y int
}
func (u *UserInterface) UpdateInput(keys map[driver.Key]struct{}, touches []*Touch) {
u.input.update(keys, touches)
func (u *UserInterface) UpdateInput(keys map[driver.Key]struct{}, runes []rune, touches []*Touch) {
u.input.update(keys, runes, touches)
}

View File

@ -28,6 +28,7 @@ type position struct {
var (
keys = map[driver.Key]struct{}{}
runes []rune
touches = map[int]position{}
)
@ -40,5 +41,5 @@ func updateInput() {
Y: position.y,
})
}
mobile.Get().UpdateInput(keys, ts)
mobile.Get().UpdateInput(keys, runes, ts)
}

View File

@ -31,12 +31,15 @@ func UpdateTouchesOnIOS(phase int, ptr int64, x, y int) {
panic("ebitenmobileview: updateTouchesOnIOSImpl must not be called on Android")
}
func OnKeyDownOnAndroid(keyCode int) {
func OnKeyDownOnAndroid(keyCode int, unicodeChar int) {
key, ok := androidKeyToDriverKey[keyCode]
if !ok {
return
}
keys[key] = struct{}{}
if unicodeChar != 0 {
runes = []rune{rune(unicodeChar)}
}
updateInput()
}