-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdl_events.go
176 lines (152 loc) · 2.66 KB
/
sdl_events.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package sdl
import (
"github.com/veandco/go-sdl2/sdl"
)
const (
NUM_SCANCODES = sdl.NUM_SCANCODES
PRESSED = sdl.PRESSED
SCANCODE_SPACE = sdl.SCANCODE_SPACE
KMOD_LSHIFT = sdl.KMOD_LSHIFT
KMOD_RSHIFT = sdl.KMOD_RSHIFT
KMOD_RALT = sdl.KMOD_RALT
)
type FingerID int32
type Keymod int32
type Scancode int32
func PollEvent(e *Event) int32 {
ev := sdl.PollEvent()
if ev == nil {
return 0
}
//log.Printf("sdl.PollEvent: %T", ev)
switch ev := ev.(type) {
case *sdl.WindowEvent:
*e = Event{
Type: int32(ev.Type),
Window: WindowEvent{
Event: ev.Event,
},
}
case *sdl.TextEditingEvent:
*e = Event{
Type: int32(ev.Type),
}
copy(e.Edit.Text[:], ev.Text[:])
case *sdl.TextInputEvent:
*e = Event{
Type: int32(ev.Type),
}
copy(e.Text.Text[:], ev.Text[:])
case *sdl.KeyboardEvent:
*e = Event{
Type: int32(ev.Type),
Key: KeyboardEvent{
Keysym: Keysym{
Scancode: Scancode(ev.Keysym.Scancode),
},
State: ev.State,
},
}
case *sdl.MouseButtonEvent:
*e = Event{
Type: int32(ev.Type),
Button: MouseButtonEvent{
Button: ev.Button,
State: ev.State,
X: ev.X,
Y: ev.Y,
},
}
case *sdl.MouseMotionEvent:
*e = Event{
Type: int32(ev.Type),
Motion: MouseMotionEvent{
X: ev.X,
Y: ev.Y,
Xrel: ev.XRel,
Yrel: ev.YRel,
},
}
case *sdl.MouseWheelEvent:
*e = Event{
Type: int32(ev.Type),
Wheel: MouseWheelEvent{
X: ev.X,
Y: ev.Y,
},
}
default:
return 0 // TODO
}
return 1
}
type Event struct {
Type int32
Edit TextEditingEvent
Text TextInputEvent
Key KeyboardEvent
Button MouseButtonEvent
Motion MouseMotionEvent
Wheel MouseWheelEvent
Window WindowEvent
}
type WindowEvent struct {
Event uint8
}
type TextInputEvent struct {
Text [32]byte
}
type TextEditingEvent struct {
Text [32]byte
}
type MouseWheelEvent struct {
X int32
Y int32
}
type MouseMotionEvent struct {
X int32
Y int32
Xrel int32
Yrel int32
}
type MouseButtonEvent struct {
Button uint8
State uint8
X int32
Y int32
}
type KeyboardEvent struct {
Keysym Keysym
State uint8
}
type Keysym struct {
Scancode Scancode
}
func StartTextInput() {
sdl.StartTextInput()
}
func StopTextInput() {
sdl.StopTextInput()
}
func GetModState() Keymod {
return Keymod(sdl.GetModState())
}
func SetRelativeMouseMode(enabled bool) int32 {
if noMouseGrab {
return 0
}
return int32(sdl.SetRelativeMouseMode(enabled))
}
func GetEventState(ev uint32) uint8 {
return sdl.GetEventState(ev)
}
func GetGlobalMouseState(x, y *int32) uint32 {
cx, cy, state := sdl.GetGlobalMouseState()
if x != nil {
*x = cx
}
if y != nil {
*y = cy
}
return state
}