mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
driver: Add Input
This commit is contained in:
parent
bf165ae9d4
commit
de9f54fd9d
@ -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
|
||||
|
@ -25,7 +25,7 @@ type pos struct {
|
||||
Y int
|
||||
}
|
||||
|
||||
func Get() *Input {
|
||||
func Get() driver.Input {
|
||||
return theInput
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user