-
Notifications
You must be signed in to change notification settings - Fork 84
/
event.go
45 lines (39 loc) · 1.2 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package mouse
import (
"github.com/oakmound/oak/alg/floatgeom"
"github.com/oakmound/oak/collision"
)
var (
// LastEvent is the last triggered mouse event,
// tracked for continuous mouse responsiveness on events
// that don't take in a mouse event
LastEvent = NewZeroEvent(0, 0)
// LastPress is the last triggered mouse event,
// where the mouse event was a press.
// If TrackMouseClicks is set to false then this will not be tracked
LastPress = NewZeroEvent(0, 0)
)
// An Event is passed in through all Mouse related event bindings to
// indicate what type of mouse event was triggered, where it was triggered,
// and which mouse button it concerns.
type Event struct {
floatgeom.Point2
Button string
Event string
}
// NewEvent creates and returns an Event
func NewEvent(x, y float64, button, event string) Event {
return Event{
Point2: floatgeom.Point2{x, y},
Button: button,
Event: event,
}
}
// NewZeroEvent creates an event with no button or event string.
func NewZeroEvent(x, y float64) Event {
return NewEvent(x, y, "", "")
}
// ToSpace converts a mouse event into a collision space
func (e Event) ToSpace() *collision.Space {
return collision.NewUnassignedSpace(e.X(), e.Y(), 0.1, 0.1)
}