mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +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,
|
||||
}
|
||||
|
||||
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) {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
|
||||
if !i.callbacksInitialized {
|
||||
i.runeBuffer = make([]rune, 0, 1024)
|
||||
window.SetCharModsCallback(func(w *glfw.Window, char rune, mods glfw.ModifierKey) {
|
||||
if unicode.IsPrint(char) {
|
||||
i.m.Lock()
|
||||
i.runeBuffer = append(i.runeBuffer, char)
|
||||
i.m.Unlock()
|
||||
}
|
||||
i.appendRuneBuffer(char)
|
||||
})
|
||||
window.SetScrollCallback(func(w *glfw.Window, xoff float64, yoff float64) {
|
||||
i.m.Lock()
|
||||
i.scrollX = xoff
|
||||
i.scrollY = yoff
|
||||
i.m.Unlock()
|
||||
i.setWheel(xoff, yoff)
|
||||
})
|
||||
i.callbacksInitialized = true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user