mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
input: Refactoring
This commit is contained in:
parent
80dcec865d
commit
f5c68d2a61
@ -100,24 +100,32 @@ var glfwMouseButtonToMouseButton = map[glfw.MouseButton]driver.MouseButton{
|
|||||||
glfw.MouseButtonMiddle: driver.MouseButtonMiddle,
|
glfw.MouseButtonMiddle: driver.MouseButtonMiddle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Input) appendRuneBuffer(char rune) {
|
||||||
|
if !unicode.IsPrint(char) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
i.m.Lock()
|
||||||
|
i.runeBuffer = append(i.runeBuffer, char)
|
||||||
|
i.m.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Input) setWheel(xoff, yoff float64) {
|
||||||
|
i.m.Lock()
|
||||||
|
i.scrollX = xoff
|
||||||
|
i.scrollY = yoff
|
||||||
|
i.m.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Input) Update(window *glfw.Window, scale float64) {
|
func (i *Input) Update(window *glfw.Window, scale float64) {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
|
|
||||||
if !i.callbacksInitialized {
|
if !i.callbacksInitialized {
|
||||||
i.runeBuffer = make([]rune, 0, 1024)
|
|
||||||
window.SetCharModsCallback(func(w *glfw.Window, char rune, mods glfw.ModifierKey) {
|
window.SetCharModsCallback(func(w *glfw.Window, char rune, mods glfw.ModifierKey) {
|
||||||
if unicode.IsPrint(char) {
|
i.appendRuneBuffer(char)
|
||||||
i.m.Lock()
|
|
||||||
i.runeBuffer = append(i.runeBuffer, char)
|
|
||||||
i.m.Unlock()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
window.SetScrollCallback(func(w *glfw.Window, xoff float64, yoff float64) {
|
window.SetScrollCallback(func(w *glfw.Window, xoff float64, yoff float64) {
|
||||||
i.m.Lock()
|
i.setWheel(xoff, yoff)
|
||||||
i.scrollX = xoff
|
|
||||||
i.scrollY = yoff
|
|
||||||
i.m.Unlock()
|
|
||||||
})
|
})
|
||||||
i.callbacksInitialized = true
|
i.callbacksInitialized = true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user