2020-01-25 23:28:21 -05:00
|
|
|
package d2input
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-02-09 14:12:04 -05:00
|
|
|
ErrHasReg = errors.New("input system already has provided handler")
|
|
|
|
ErrNotReg = errors.New("input system does not have provided handler")
|
2020-01-25 23:28:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Priority int
|
|
|
|
|
|
|
|
const (
|
|
|
|
PriorityLow Priority = iota
|
|
|
|
PriorityDefault
|
|
|
|
PriorityHigh
|
|
|
|
)
|
|
|
|
|
|
|
|
type HandlerEvent struct {
|
|
|
|
KeyMod KeyMod
|
|
|
|
ButtonMod MouseButtonMod
|
|
|
|
X int
|
|
|
|
Y int
|
|
|
|
}
|
|
|
|
|
|
|
|
type KeyEvent struct {
|
|
|
|
HandlerEvent
|
|
|
|
Key Key
|
2020-06-23 18:12:08 -04:00
|
|
|
// Duration represents the number of frames this key has been pressed for
|
|
|
|
Duration int
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type KeyCharsEvent struct {
|
|
|
|
HandlerEvent
|
|
|
|
Chars []rune
|
|
|
|
}
|
|
|
|
|
|
|
|
type MouseEvent struct {
|
|
|
|
HandlerEvent
|
|
|
|
Button MouseButton
|
|
|
|
}
|
|
|
|
|
|
|
|
type MouseMoveEvent struct {
|
|
|
|
HandlerEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
type Handler interface{}
|
|
|
|
|
|
|
|
type KeyDownHandler interface {
|
|
|
|
OnKeyDown(event KeyEvent) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type KeyRepeatHandler interface {
|
|
|
|
OnKeyRepeat(event KeyEvent) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type KeyUpHandler interface {
|
|
|
|
OnKeyUp(event KeyEvent) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type KeyCharsHandler interface {
|
|
|
|
OnKeyChars(event KeyCharsEvent) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type MouseButtonDownHandler interface {
|
|
|
|
OnMouseButtonDown(event MouseEvent) bool
|
|
|
|
}
|
|
|
|
|
2020-06-22 15:55:32 -04:00
|
|
|
type MouseButtonRepeatHandler interface {
|
|
|
|
OnMouseButtonRepeat(event MouseEvent) bool
|
|
|
|
}
|
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
type MouseButtonUpHandler interface {
|
|
|
|
OnMouseButtonUp(event MouseEvent) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type MouseMoveHandler interface {
|
|
|
|
OnMouseMove(event MouseMoveEvent) bool
|
|
|
|
}
|
|
|
|
|
2020-02-09 14:12:04 -05:00
|
|
|
var singleton inputManager
|
2020-01-25 23:28:21 -05:00
|
|
|
|
2020-06-23 18:12:08 -04:00
|
|
|
func Initialize(inputService InputService) {
|
|
|
|
singleton = inputManager{
|
|
|
|
inputService: inputService,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
func Advance(elapsed float64) error {
|
|
|
|
return singleton.advance(elapsed)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BindHandlerWithPriority(handler Handler, priority Priority) error {
|
|
|
|
return singleton.bindHandler(handler, priority)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BindHandler(handler Handler) error {
|
|
|
|
return BindHandlerWithPriority(handler, PriorityDefault)
|
|
|
|
}
|
|
|
|
|
|
|
|
func UnbindHandler(handler Handler) error {
|
|
|
|
return singleton.unbindHandler(handler)
|
|
|
|
}
|