uidriver/js: Implement touches on go2cpp

This commit is contained in:
Hajime Hoshi 2020-12-20 20:25:18 +09:00
parent 2a2866bf65
commit b20f611058
2 changed files with 21 additions and 0 deletions

View File

@ -395,3 +395,23 @@ func (i *Input) updateTouchesFromEvent(e js.Value) {
}
i.touches = ts
}
func (i *Input) updateForGo2Cpp() {
if !go2cpp.Truthy() {
return
}
i.touches = map[driver.TouchID]pos{}
maxID := go2cpp.Get("maxTouchId").Int()
for id := 0; id < maxID; id++ {
x := go2cpp.Call("getTouchPositionX", id)
y := go2cpp.Call("getTouchPositionY", id)
if x.Type() != js.TypeNumber || y.Type() != js.TypeNumber {
continue
}
i.touches[driver.TouchID(id)] = pos{
X: x.Int(),
Y: y.Int(),
}
}
}

View File

@ -182,6 +182,7 @@ func (u *UserInterface) update() error {
hooks.ResumeAudio()
u.input.updateGamepads()
u.input.updateForGo2Cpp()
u.updateSize()
if err := u.context.Update(); err != nil {
return err