-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmouse.go
82 lines (68 loc) · 1.42 KB
/
mouse.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package gogre3d
/*
#cgo LDFLAGS: -lllcoi
#cgo CFLAGS: -I./llcoihdr
#include "ois_interface.h"
*/
import "C"
type Mouse struct {
cptr C.MouseInputHandle
}
type Axis struct {
Abs, Rel int
AbsOnly bool
}
type MouseState struct {
X, Y, Z Axis
buttons MouseButtonId
}
type MouseButtonId uint8
const (
_ = iota // skip 0
MB_Left MouseButtonId = iota
MB_Right
MB_Middle
MB_3
MB_4
MB_5
MB_6
MB_7
)
func (ms *MouseState) ButtonPressed(b MouseButtonId) bool {
return ms.buttons & b == b
}
func goMouseState(s *C.MouseState) MouseState {
return MouseState{
X: goAxis(&s.X),
Y: goAxis(&s.Y),
Z: goAxis(&s.Z),
buttons: MouseButtonId(s.buttons),
}
}
func goAxis(a *C.Axis) Axis {
return Axis{
Abs: int(a.abs),
Rel: int(a.rel),
AbsOnly: gobool(a.absOnly),
}
}
func (m *Mouse) State() MouseState {
cms := C.mouse_get_state(m.cptr)
return goMouseState(&cms)
}
func (m *Mouse) DisplayArea (width, height int) {
C.mouse_set_display_area(m.cptr, C.int(width), C.int(height))
}
func (m *Mouse) Capture() {
C.mouse_capture(m.cptr)
}
func (m *Mouse) Buffered(b bool) {
C.mouse_set_buffered(m.cptr, cbool(b))
}
/*
type MouseMovedEventHandler func(e MouseState, userdata interface{})bool
type MousePressedEventHandler func(e MouseState, b MouseButtonId, userdata interface{})bool
type MouseReleasedEventHandler func(e MouseState, b MouseButtonId, userdata interface{})bool
*/
// TODO: set mouse event
// TODO: remove mouse event