mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-13 22:47:26 +01:00
uidriver/js: Refactoring
This commit is contained in:
parent
d3fbf377ef
commit
2e2ee2595b
@ -275,7 +275,7 @@ func (i *Input) setMouseCursor(x, y int) {
|
|||||||
i.cursorX, i.cursorY = x, y
|
i.cursorX, i.cursorY = x, y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Input) UpdateGamepads() {
|
func (i *Input) updateGamepads() {
|
||||||
nav := js.Global().Get("navigator")
|
nav := js.Global().Get("navigator")
|
||||||
if !nav.Truthy() {
|
if !nav.Truthy() {
|
||||||
return
|
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
|
// Avoid using js.Value.String() as String creates a Uint8Array via a TextEncoder and causes a heavy
|
||||||
// overhead (#1437).
|
// overhead (#1437).
|
||||||
switch t := e.Get("type"); {
|
switch t := e.Get("type"); {
|
||||||
|
@ -181,7 +181,7 @@ func (u *UserInterface) update() error {
|
|||||||
}
|
}
|
||||||
hooks.ResumeAudio()
|
hooks.ResumeAudio()
|
||||||
|
|
||||||
u.input.UpdateGamepads()
|
u.input.updateGamepads()
|
||||||
u.updateSize()
|
u.updateSize()
|
||||||
if err := u.context.Update(); err != nil {
|
if err := u.context.Update(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -339,19 +339,19 @@ func setCanvasEventHandlers(v js.Value) {
|
|||||||
|
|
||||||
e := args[0]
|
e := args[0]
|
||||||
// Don't 'preventDefault' on keydown events or keypress events wouldn't work (#715).
|
// Don't 'preventDefault' on keydown events or keypress events wouldn't work (#715).
|
||||||
theUI.input.Update(e)
|
theUI.input.updateFromEvent(e)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
v.Call("addEventListener", "keypress", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
v.Call("addEventListener", "keypress", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
e := args[0]
|
e := args[0]
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theUI.input.Update(e)
|
theUI.input.updateFromEvent(e)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
v.Call("addEventListener", "keyup", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
v.Call("addEventListener", "keyup", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
e := args[0]
|
e := args[0]
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theUI.input.Update(e)
|
theUI.input.updateFromEvent(e)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@ -362,25 +362,25 @@ func setCanvasEventHandlers(v js.Value) {
|
|||||||
|
|
||||||
e := args[0]
|
e := args[0]
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theUI.input.Update(e)
|
theUI.input.updateFromEvent(e)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
v.Call("addEventListener", "mouseup", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
v.Call("addEventListener", "mouseup", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
e := args[0]
|
e := args[0]
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theUI.input.Update(e)
|
theUI.input.updateFromEvent(e)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
v.Call("addEventListener", "mousemove", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
v.Call("addEventListener", "mousemove", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
e := args[0]
|
e := args[0]
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theUI.input.Update(e)
|
theUI.input.updateFromEvent(e)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
v.Call("addEventListener", "wheel", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
v.Call("addEventListener", "wheel", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
e := args[0]
|
e := args[0]
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theUI.input.Update(e)
|
theUI.input.updateFromEvent(e)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@ -391,19 +391,19 @@ func setCanvasEventHandlers(v js.Value) {
|
|||||||
|
|
||||||
e := args[0]
|
e := args[0]
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theUI.input.Update(e)
|
theUI.input.updateFromEvent(e)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
v.Call("addEventListener", "touchend", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
v.Call("addEventListener", "touchend", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
e := args[0]
|
e := args[0]
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theUI.input.Update(e)
|
theUI.input.updateFromEvent(e)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
v.Call("addEventListener", "touchmove", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
v.Call("addEventListener", "touchmove", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
e := args[0]
|
e := args[0]
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theUI.input.Update(e)
|
theUI.input.updateFromEvent(e)
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user