/
mouse.go
151 lines (117 loc) · 3.82 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package allegro
// #include <allegro5/allegro.h>
import "C"
import "unsafe"
func InstallMouse() bool {
return bool(C.al_install_mouse())
}
func IsMouseInstalled() bool {
return bool(C.al_is_mouse_installed())
}
func UninstallMouse() {
C.al_uninstall_mouse()
}
func GetMouseNumAxes() uint32 {
return uint32(C.al_get_mouse_num_axes())
}
func GetMouseNumButtons() uint32 {
return uint32(C.al_get_mouse_num_buttons())
}
func GetMouseState() *MouseState {
ms := new(C.ALLEGRO_MOUSE_STATE)
C.al_get_mouse_state(ms)
return (*MouseState)(unsafe.Pointer(ms))
}
func (m *MouseState) GetAxis(axis int32) int32 {
return int32(C.al_get_mouse_state_axis((*C.ALLEGRO_MOUSE_STATE)(unsafe.Pointer(m)), C.int(axis)))
}
func (m *MouseState) ButtonDown(button int32) bool {
return bool(C.al_mouse_button_down((*C.ALLEGRO_MOUSE_STATE)(unsafe.Pointer(m)), C.int(button)))
}
func (d *Display) SetMouseXy(x, y int32) bool {
return bool(C.al_set_mouse_xy((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), C.int(x), C.int(y)))
}
func SetMouseZ(z int32) bool {
return bool(C.al_set_mouse_z(C.int(z)))
}
func SetMouseW(w int32) bool {
return bool(C.al_set_mouse_w(C.int(w)))
}
func SetMouseAxis(which, value int32) bool {
return bool(C.al_set_mouse_axis(C.int(which), C.int(value)))
}
func GetMouseEventSource() *EventSource {
return (*EventSource)(unsafe.Pointer(C.al_get_mouse_event_source()))
}
/*****************/
/* Mouse Cursors */
/*****************/
func CreateMouseCursor(bmp *Bitmap, xFocus, yFocus int32) *MouseCursor {
return (*MouseCursor)(unsafe.Pointer(C.al_create_mouse_cursor((*C.ALLEGRO_BITMAP)(unsafe.Pointer(bmp)), C.int(xFocus), C.int(yFocus))))
}
func (m *MouseCursor) Destroy() {
C.al_destroy_mouse_cursor((*C.ALLEGRO_MOUSE_CURSOR)(unsafe.Pointer(m)))
}
func (m *MouseCursor) Set(display *Display) bool {
return bool(C.al_set_mouse_cursor((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(display)), (*C.ALLEGRO_MOUSE_CURSOR)(unsafe.Pointer(m))))
}
func SetSystemMouseCursor(display *Display, cursorId uint32) bool {
return bool(C.al_set_system_mouse_cursor((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(display)), (C.ALLEGRO_SYSTEM_MOUSE_CURSOR)(cursorId)))
}
func GetMouseCursorPosition() (bool, int32, int32) {
var x, y C.int
r := bool(C.al_get_mouse_cursor_position(&x, &y))
return r, int32(x), int32(y)
}
func HideMouseCursor(display *Display) bool {
return bool(C.al_hide_mouse_cursor((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(display))))
}
func ShowMouseCursor(display *Display) bool {
return bool(C.al_show_mouse_cursor((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(display))))
}
func GrabMouse(display *Display) bool {
return bool(C.al_grab_mouse((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(display))))
}
func UngrabMouse() bool {
return bool(C.al_ungrab_mouse())
}
/**********************/
/* MouseState getters */
/**********************/
func (m *MouseState) X() int32 {
mc := (*C.ALLEGRO_MOUSE_STATE)(unsafe.Pointer(m))
return int32(mc.x)
}
func (m *MouseState) Y() int32 {
mc := (*C.ALLEGRO_MOUSE_STATE)(unsafe.Pointer(m))
return int32(mc.y)
}
func (m *MouseState) Z() int32 {
mc := (*C.ALLEGRO_MOUSE_STATE)(unsafe.Pointer(m))
return int32(mc.z)
}
func (m *MouseState) W() int32 {
mc := (*C.ALLEGRO_MOUSE_STATE)(unsafe.Pointer(m))
return int32(mc.w)
}
func (m *MouseState) MoreAxes() []int32 {
mc := (*C.ALLEGRO_MOUSE_STATE)(unsafe.Pointer(m))
length := int(C.ALLEGRO_MOUSE_MAX_EXTRA_AXES)
axes := make([]int32, length)
for i := 0; i < length; i++ {
axes[i] = int32(mc.more_axes[i])
}
return axes
}
func (m *MouseState) Buttons() int32 {
mc := (*C.ALLEGRO_MOUSE_STATE)(unsafe.Pointer(m))
return int32(mc.buttons)
}
func (m *MouseState) Pressure() float32 {
mc := (*C.ALLEGRO_MOUSE_STATE)(unsafe.Pointer(m))
return float32(mc.pressure)
}
func (m *MouseState) Display() *Display {
mc := (*C.ALLEGRO_MOUSE_STATE)(unsafe.Pointer(m))
return (*Display)(unsafe.Pointer(mc.display))
}