/
xel-mouse.go
86 lines (61 loc) · 1.71 KB
/
xel-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
package xel
import (
"github.com/amortaza/go-glfw"
//"fmt"
"fmt"
"github.com/amortaza/go-hal"
)
var gUserOnMouseMove func(x, y int)
var gUserOnMouseButton func(button hal.MouseButton, action hal.ButtonAction)
func SetMouseCursor(cursor hal.MouseCursor) {
if cursor == hal.Mouse_Cursor_Arrow {
g_window.SetCursor(glfw.ArrowCursor)
} else if cursor == hal.Mouse_Cursor_Horiz_Resize {
g_window.SetCursor(glfw.HResizeCursor)
} else if cursor == hal.Mouse_Cursor_Vert_Resize {
g_window.SetCursor(glfw.VResizeCursor)
} else if cursor == hal.Mouse_Cursor_IBeam {
g_window.SetCursor(glfw.IBeamCursor)
} else if cursor == hal.Mouse_Cursor_Hand {
g_window.SetCursor(glfw.HandCursor)
} else if cursor == hal.Mouse_Cursor_CrossHair {
g_window.SetCursor(glfw.CrossHairCursor)
} else {
fmt.Println("Did not recognize the Mouse cursor in xel2.SetMouseCursor")
}
}
func glfw_onMouseMove(
window *glfw.Window,
x, y float64) {
MouseX, MouseY = int(x), int(y)
if gUserOnMouseMove != nil {
gUserOnMouseMove(int(x), int(y))
}
}
func glfw_onMouseButton(
window *glfw.Window,
button glfw.MouseButton,
action glfw.Action,
mods glfw.ModifierKey) {
var _button hal.MouseButton
var _action hal.ButtonAction
if button == glfw.MouseButtonLeft {
_button = hal.Mouse_Button_Left
} else if button == glfw.MouseButtonRight {
_button = hal.Mouse_Button_Right
} else {
fmt.Println("Unrecognized mouse button %i", button)
return
}
if action == glfw.Press {
_action = hal.Button_Action_Down
} else if action == glfw.Release {
_action = hal.Button_Action_Up
} else {
fmt.Println("Unrecognized action %i", action)
return
}
if gUserOnMouseButton != nil {
gUserOnMouseButton(_button, _action)
}
}