-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse_event.go
59 lines (48 loc) · 1.1 KB
/
mouse_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package bus
import (
"golang.org/x/mobile/event/mouse"
)
func NewMouseEvent(event mouse.Event) MouseEvent {
return &mouseState{event}
}
type mouseState struct {
mouse.Event
}
type MouseEventListener interface {
OnMouseEvent(mouseChannel <-chan MouseEvent)
}
type MouseEvent interface {
GetCursorPoint() CursorPoint
IsWheel() bool
IsReleased(button mouse.Button) bool
IsPressed(button mouse.Button) bool
}
func (m *mouseState) IsWheel() bool {
return m.Button.IsWheel()
}
func (m *mouseState) IsReleased(button mouse.Button) bool {
return m.Button == button && m.Direction == mouse.DirRelease
}
func (m *mouseState) IsPressed(button mouse.Button) bool {
return m.Button == button && m.Direction == mouse.DirPress
}
func (evt *mouseState) GetCursorPoint() CursorPoint {
return &cursorPoint{int32(evt.X), int32(evt.Y)}
}
type CursorPoint interface {
GetX() int32
GetY() int32
To() (int32, int32)
}
type cursorPoint struct {
x, y int32
}
func (p *cursorPoint) GetX() int32 {
return p.x
}
func (p *cursorPoint) GetY() int32 {
return p.y
}
func (p *cursorPoint) To() (int32, int32) {
return p.x, p.y
}