add Window.Repeat

This commit is contained in:
faiface 2017-05-10 23:54:06 +02:00
parent 9062f1eae9
commit be2434cfa8
2 changed files with 11 additions and 0 deletions

View File

@ -21,6 +21,13 @@ func (w *Window) JustReleased(button Button) bool {
return !w.currInp.buttons[button] && w.prevInp.buttons[button] return !w.currInp.buttons[button] && w.prevInp.buttons[button]
} }
// Repeated returns whether a repeat event has been triggered on button.
//
// Repeat event occurs repeatedly when a button is held down for some time.
func (w *Window) Repeated(button Button) bool {
return w.currInp.repeat[button]
}
// MousePosition returns the current mouse position in the Window's Bounds. // MousePosition returns the current mouse position in the Window's Bounds.
func (w *Window) MousePosition() pixel.Vec { func (w *Window) MousePosition() pixel.Vec {
return w.currInp.mouse return w.currInp.mouse
@ -342,6 +349,8 @@ func (w *Window) initInput() {
w.tempInp.buttons[Button(key)] = true w.tempInp.buttons[Button(key)] = true
case glfw.Release: case glfw.Release:
w.tempInp.buttons[Button(key)] = false w.tempInp.buttons[Button(key)] = false
case glfw.Repeat:
w.tempInp.repeat[Button(key)] = true
} }
}) })
@ -370,6 +379,7 @@ func (w *Window) updateInput() {
w.prevInp = w.currInp w.prevInp = w.currInp
w.currInp = w.tempInp w.currInp = w.tempInp
w.tempInp.repeat = [KeyLast + 1]bool{}
w.tempInp.scroll = 0 w.tempInp.scroll = 0
w.tempInp.typed = "" w.tempInp.typed = ""
} }

View File

@ -68,6 +68,7 @@ type Window struct {
prevInp, currInp, tempInp struct { prevInp, currInp, tempInp struct {
mouse pixel.Vec mouse pixel.Vec
buttons [KeyLast + 1]bool buttons [KeyLast + 1]bool
repeat [KeyLast + 1]bool
scroll pixel.Vec scroll pixel.Vec
typed string typed string
} }