uidriver/js: Refactoring

This commit is contained in:
Hajime Hoshi 2020-12-20 18:17:08 +09:00
parent d3fbf377ef
commit 2e2ee2595b
2 changed files with 13 additions and 13 deletions

View File

@ -275,7 +275,7 @@ func (i *Input) setMouseCursor(x, y int) {
i.cursorX, i.cursorY = x, y
}
func (i *Input) UpdateGamepads() {
func (i *Input) updateGamepads() {
nav := js.Global().Get("navigator")
if !nav.Truthy() {
return
@ -318,7 +318,7 @@ func (i *Input) UpdateGamepads() {
}
}
func (i *Input) Update(e js.Value) {
func (i *Input) updateFromEvent(e js.Value) {
// Avoid using js.Value.String() as String creates a Uint8Array via a TextEncoder and causes a heavy
// overhead (#1437).
switch t := e.Get("type"); {

View File

@ -181,7 +181,7 @@ func (u *UserInterface) update() error {
}
hooks.ResumeAudio()
u.input.UpdateGamepads()
u.input.updateGamepads()
u.updateSize()
if err := u.context.Update(); err != nil {
return err
@ -339,19 +339,19 @@ func setCanvasEventHandlers(v js.Value) {
e := args[0]
// Don't 'preventDefault' on keydown events or keypress events wouldn't work (#715).
theUI.input.Update(e)
theUI.input.updateFromEvent(e)
return nil
}))
v.Call("addEventListener", "keypress", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
e := args[0]
e.Call("preventDefault")
theUI.input.Update(e)
theUI.input.updateFromEvent(e)
return nil
}))
v.Call("addEventListener", "keyup", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
e := args[0]
e.Call("preventDefault")
theUI.input.Update(e)
theUI.input.updateFromEvent(e)
return nil
}))
@ -362,25 +362,25 @@ func setCanvasEventHandlers(v js.Value) {
e := args[0]
e.Call("preventDefault")
theUI.input.Update(e)
theUI.input.updateFromEvent(e)
return nil
}))
v.Call("addEventListener", "mouseup", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
e := args[0]
e.Call("preventDefault")
theUI.input.Update(e)
theUI.input.updateFromEvent(e)
return nil
}))
v.Call("addEventListener", "mousemove", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
e := args[0]
e.Call("preventDefault")
theUI.input.Update(e)
theUI.input.updateFromEvent(e)
return nil
}))
v.Call("addEventListener", "wheel", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
e := args[0]
e.Call("preventDefault")
theUI.input.Update(e)
theUI.input.updateFromEvent(e)
return nil
}))
@ -391,19 +391,19 @@ func setCanvasEventHandlers(v js.Value) {
e := args[0]
e.Call("preventDefault")
theUI.input.Update(e)
theUI.input.updateFromEvent(e)
return nil
}))
v.Call("addEventListener", "touchend", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
e := args[0]
e.Call("preventDefault")
theUI.input.Update(e)
theUI.input.updateFromEvent(e)
return nil
}))
v.Call("addEventListener", "touchmove", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
e := args[0]
e.Call("preventDefault")
theUI.input.Update(e)
theUI.input.updateFromEvent(e)
return nil
}))