forked from drhodes/go-sfml
/
win-mouse.go
59 lines (51 loc) · 1.95 KB
/
win-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
package sfml
//#include <SFML/Window/Export.h>
//#include <SFML/Window/Types.h>
//#include <SFML/Window/Mouse.h>
//#include <SFML/System/Vector2.h>
import "C"
type MouseButton uint
const (
MouseLeft = iota // The left mouse button
MouseRight // The right mouse button
MouseMiddle // The middle (wheel) mouse button
MouseXButton1 // The first extra mouse button
MouseXButton2 // The second extra mouse button
MouseButtonCount // Keep last -- the total number of mouse buttons
)
// Mouse buttons
// Check if a mouse button is pressed
// \param button Button to check
// \return sfTrue if the button is pressed, sfFalse otherwise
// sfBool sfMouse_isButtonPressed(sfMouseButton button);
func (self MouseButton) IsButtonPressed() bool {
return C.sfMouse_isButtonPressed(C.sfMouseButton(self)) == 1
}
// Get the current position of the mouse
// This function returns the current position of the mouse
// cursor relative to the given window, or desktop if NULL is passed.
// \param relativeTo Reference window
// \return Position of the mouse cursor, relative to the given window
// sfVector2i sfMouse_getPosition(const sfWindow* relativeTo);
func MousePositionAbsolute() (int, int) {
v := C.sfMouse_getPosition(nil)
return int(v.x), int(v.y)
}
func MousePosition(win Window) (int, int) {
v := C.sfMouse_getPosition(win.Cref)
return int(v.x), int(v.y)
}
// Set the current position of the mouse
// This function sets the current position of the mouse
// cursor relative to the given window, or desktop if NULL is passed.
// \param position New position of the mouse
// \param relativeTo Reference window
// void sfMouse_setPosition(sfVector2i position, const sfWindow* relativeTo);
func SetMousePositionAbsolute(x, y int) {
v := C.sfVector2i{C.int(x), C.int(y)}
C.sfMouse_setPosition(v, nil)
}
func SetMousePosition(x, y int, win Window) {
v := C.sfVector2i{C.int(x), C.int(y)}
C.sfMouse_setPosition(v, win.Cref)
}