diff --git a/internal/driver/input.go b/internal/driver/input.go index ebf066692..b79fc0aa2 100644 --- a/internal/driver/input.go +++ b/internal/driver/input.go @@ -14,6 +14,22 @@ package driver +type Input interface { + CursorPosition() (x, y int) + GamepadAxis(id int, axis int) float64 + GamepadAxisNum(id int) int + GamepadButtonNum(id int) int + GamepadIDs() []int + IsGamepadButtonPressed(id int, button GamepadButton) bool + IsKeyPressed(key Key) bool + IsMouseButtonPressed(button MouseButton) bool + ResetForFrame() + RuneBuffer() []rune + TouchIDs() []int + TouchPosition(id int) (x, y int) + Wheel() (xoff, yoff float64) +} + // TODO: Remove this for API simplicity. type Touch struct { ID int diff --git a/internal/input/input.go b/internal/input/input.go index 022ad77ac..470bfc887 100644 --- a/internal/input/input.go +++ b/internal/input/input.go @@ -25,7 +25,7 @@ type pos struct { Y int } -func Get() *Input { +func Get() driver.Input { return theInput } diff --git a/internal/input/input_js.go b/internal/input/input_js.go index 1cb623c6f..2b7d72a75 100644 --- a/internal/input/input_js.go +++ b/internal/input/input_js.go @@ -147,7 +147,7 @@ func (i *Input) setMouseCursor(x, y int) { i.cursorX, i.cursorY = x, y } -func (i *Input) UpdateGamepads() { +func (i *Input) Update() { nav := js.Global().Get("navigator") if nav.Get("getGamepads") == js.Undefined() { return diff --git a/internal/input/input_mobile.go b/internal/input/input_mobile.go index 9694cfa1e..1c966ebfa 100644 --- a/internal/input/input_mobile.go +++ b/internal/input/input_mobile.go @@ -46,7 +46,7 @@ func (i *Input) IsMouseButtonPressed(key driver.MouseButton) bool { return false } -func (i *Input) SetTouches(touches []*driver.Touch) { +func (i *Input) Update(touches []*driver.Touch) { i.m.Lock() i.touches = map[int]pos{} for _, t := range touches { diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 8eaf0bd34..b84ed1442 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -761,7 +761,12 @@ func (u *userInterface) update(g GraphicsContext) error { _ = mainthread.Run(func() error { glfw.PollEvents() - input.Get().Update(u.window, u.getScale()*glfwScale()) + + type updater interface { + Update(window *glfw.Window, scale float64) + } + + input.Get().(updater).Update(u.window, u.getScale()*glfwScale()) defer hooks.ResumeAudio() diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 018ffdcfb..51ee88d37 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -203,7 +203,11 @@ func (u *userInterface) update(g GraphicsContext) error { } hooks.ResumeAudio() - input.Get().UpdateGamepads() + type updater interface { + Update() + } + + input.Get().(updater).Update() u.updateGraphicsContext(g) if err := g.Update(func() { u.updateGraphicsContext(g) diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index 6de054a5a..b2f0e4d01 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -140,7 +140,10 @@ func appMain(a app.App) { for _, t := range touches { ts = append(ts, t) } - input.Get().SetTouches(ts) + type updater interface { + Update(touches []*driver.Touch) + } + input.Get().(updater).Update(ts) } } } diff --git a/mobile/touches_mobile.go b/mobile/touches_mobile.go index 6651b9bae..10ee7a1e9 100644 --- a/mobile/touches_mobile.go +++ b/mobile/touches_mobile.go @@ -39,5 +39,8 @@ func updateTouches() { Y: position.y, }) } - input.Get().SetTouches(ts) + type updater interface { + Update(touches []*driver.Touch) + } + input.Get().(updater).Update(ts) }