2018-06-17 02:59:23 +00:00
|
|
|
package events
|
|
|
|
|
2018-06-17 14:56:51 +00:00
|
|
|
// BoolTick holds boolean state between this frame and the previous.
|
|
|
|
type BoolTick struct {
|
2018-06-17 02:59:23 +00:00
|
|
|
Now bool
|
|
|
|
Last bool
|
|
|
|
}
|
|
|
|
|
2018-06-17 14:56:51 +00:00
|
|
|
// Int32Tick manages int32 state between this frame and the previous.
|
|
|
|
type Int32Tick struct {
|
2018-06-17 02:59:23 +00:00
|
|
|
Now int32
|
|
|
|
Last int32
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push a bool state, copying the current Now value to Last.
|
2018-06-17 14:56:51 +00:00
|
|
|
func (bs *BoolTick) Push(v bool) {
|
2018-06-17 02:59:23 +00:00
|
|
|
bs.Last = bs.Now
|
|
|
|
bs.Now = v
|
|
|
|
}
|
|
|
|
|
2018-06-17 14:56:51 +00:00
|
|
|
// Pressed returns true if the button was pressed THIS tick.
|
|
|
|
func (bs *BoolTick) Pressed() bool {
|
|
|
|
return bs.Now && !bs.Last
|
|
|
|
}
|
|
|
|
|
2018-06-17 02:59:23 +00:00
|
|
|
// Push an int32 state, copying the current Now value to Last.
|
2018-06-17 14:56:51 +00:00
|
|
|
func (is *Int32Tick) Push(v int32) {
|
2018-06-17 02:59:23 +00:00
|
|
|
is.Last = is.Now
|
|
|
|
is.Now = v
|
|
|
|
}
|