/
gamecontroller.go
603 lines (491 loc) · 22.2 KB
/
gamecontroller.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
package sdl
/*
#include "sdl_wrapper.h"
#if !(SDL_VERSION_ATLEAST(2,0,4))
#if defined(WARN_OUTDATED)
#pragma message("SDL_GameControllerFromInstanceID is not supported before SDL 2.0.4")
#endif
static SDL_GameController* SDL_GameControllerFromInstanceID(SDL_JoystickID joyid)
{
return NULL;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,6))
#if defined(WARN_OUTDATED)
#pragma message("SDL_GameControllerGetVendor is not supported before SDL 2.0.6")
#pragma message("SDL_GameControllerGetProduct is not supported before SDL 2.0.6")
#pragma message("SDL_GameControllerGetProductVersion is not supported before SDL 2.0.6")
#pragma message("SDL_GameControllerNumMappings is not supported before SDL 2.0.6")
#pragma message("SDL_GameControllerMappingForIndex is not supported before SDL 2.0.6")
#endif
static Uint16 SDL_GameControllerGetVendor(SDL_GameController* gamecontroller)
{
return 0;
}
static Uint16 SDL_GameControllerGetProduct(SDL_GameController* gamecontroller)
{
return 0;
}
static Uint16 SDL_GameControllerGetProductVersion(SDL_GameController* gamecontroller)
{
return 0;
}
static int SDL_GameControllerNumMappings(void)
{
return 0;
}
static char* SDL_GameControllerMappingForIndex(int mapping_index)
{
return NULL;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,9))
#if defined(WARN_OUTDATED)
#pragma message("SDL_GameControllerGetPlayerIndex is not supported before SDL 2.0.9")
#pragma message("SDL_GameControllerRumble is not supported before SDL 2.0.9")
#pragma message("SDL_GameControllerMappingForDeviceIndex is not supported before SDL 2.0.9")
#endif
static int SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller)
{
return -1;
}
static int SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
{
return -1;
}
static char *SDL_GameControllerMappingForDeviceIndex(int joystick_index)
{
return NULL;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,12))
typedef enum
{
SDL_CONTROLLER_TYPE_UNKNOWN = 0,
SDL_CONTROLLER_TYPE_XBOX360,
SDL_CONTROLLER_TYPE_XBOXONE,
SDL_CONTROLLER_TYPE_PS3,
SDL_CONTROLLER_TYPE_PS4,
SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO
} SDL_GameControllerType;
#if defined(WARN_OUTDATED)
#pragma message("SDL_GameControllerTypeForIndex is not supported before SDL 2.0.12")
#pragma message("SDL_GameControllerGetType is not supported before SDL 2.0.12")
#pragma message("SDL_GameControllerFromPlayerIndex is not supported before SDL 2.0.12")
#pragma message("SDL_GameControllerSetPlayerIndex is not supported before SDL 2.0.12")
#endif
static SDL_GameControllerType SDL_GameControllerTypeForIndex(int joystick_index)
{
return SDL_CONTROLLER_TYPE_UNKNOWN;
}
static SDL_GameControllerType SDL_GameControllerGetType(SDL_GameController *gamecontroller)
{
return SDL_CONTROLLER_TYPE_UNKNOWN;
}
static SDL_GameController * SDL_GameControllerFromPlayerIndex(int player_index)
{
return NULL;
}
static void SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index)
{
// do nothing
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,14))
#define SDL_CONTROLLER_TYPE_VIRTUAL (6)
#define SDL_CONTROLLER_TYPE_PS5 (7)
#if defined(WARN_OUTDATED)
#pragma message("SDL_GameControllerGetSerial is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerHasAxis is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerHasButton is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerGetNumTouchpads is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerGetNumTouchpadFingers is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerGetTouchpadFinger is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerHasSensor is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerSetSensorEnabled is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerIsSensorEnabled is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerGetSensorData is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerRumbleTriggers is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerHasLED is not supported before SDL 2.0.14")
#pragma message("SDL_GameControllerSetLED is not supported before SDL 2.0.14")
#endif
static const char * SDLCALL SDL_GameControllerGetSerial(SDL_GameController *gamecontroller)
{
return NULL;
}
static SDL_bool SDL_GameControllerHasAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
{
return SDL_FALSE;
}
static SDL_bool SDLCALL SDL_GameControllerHasButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button)
{
return SDL_FALSE;
}
static int SDLCALL SDL_GameControllerGetNumTouchpads(SDL_GameController *gamecontroller)
{
return 0;
}
static int SDL_GameControllerGetNumTouchpadFingers(SDL_GameController *gamecontroller, int touchpad)
{
return 0;
}
static int SDL_GameControllerGetTouchpadFinger(SDL_GameController *gamecontroller, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure)
{
return -1;
}
static SDL_bool SDL_GameControllerHasSensor(SDL_GameController *gamecontroller, SDL_SensorType type)
{
return SDL_FALSE;
}
static int SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type, SDL_bool enabled)
{
return -1;
}
static SDL_bool SDL_GameControllerIsSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type)
{
return SDL_FALSE;
}
static int SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values)
{
return -1;
}
static int SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
{
return -1;
}
static SDL_bool SDL_GameControllerHasLED(SDL_GameController *gamecontroller)
{
return SDL_FALSE;
}
static int SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue)
{
return -1;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,16))
#if defined(WARN_OUTDATED)
#pragma message("SDL_GameControllerSendEffect is not supported before SDL 2.0.16")
#pragma message("SDL_GameControllerGetSensorDataRate is not supported before SDL 2.0.16")
#endif
static int SDL_GameControllerSendEffect(SDL_GameController *gamecontroller, const void *data, int size)
{
return -1;
}
static float SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SDL_SensorType type)
{
return 0.0f;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,18))
#if defined(WARN_OUTDATED)
#pragma message("SDL_GameControllerHasRumble is not supported before SDL 2.0.18")
#pragma message("SDL_GameControllerHasRumbleTriggers is not supported before SDL 2.0.18")
#pragma message("SDL_GameControllerGetAppleSFSymbolsNameForButton is not supported before SDL 2.0.18")
#pragma message("SDL_GameControllerGetAppleSFSymbolsNameForAxis is not supported before SDL 2.0.18")
#endif
static SDL_bool SDL_GameControllerHasRumble(SDL_GameController *gamecontroller)
{
return SDL_FALSE;
}
static SDL_bool SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller)
{
return SDL_FALSE;
}
static const char* SDL_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button)
{
return NULL;
}
static const char* SDL_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
{
return NULL;
}
#endif
*/
import "C"
import (
"encoding/binary"
"unsafe"
)
// Types of game controller inputs.
const (
CONTROLLER_BINDTYPE_NONE = C.SDL_CONTROLLER_BINDTYPE_NONE
CONTROLLER_BINDTYPE_BUTTON = C.SDL_CONTROLLER_BINDTYPE_BUTTON
CONTROLLER_BINDTYPE_AXIS = C.SDL_CONTROLLER_BINDTYPE_AXIS
CONTROLLER_BINDTYPE_HAT = C.SDL_CONTROLLER_BINDTYPE_HAT
)
// An enumeration of axes available from a controller.
// (https://wiki.libsdl.org/SDL_GameControllerAxis)
const (
CONTROLLER_AXIS_INVALID = C.SDL_CONTROLLER_AXIS_INVALID
CONTROLLER_AXIS_LEFTX = C.SDL_CONTROLLER_AXIS_LEFTX
CONTROLLER_AXIS_LEFTY = C.SDL_CONTROLLER_AXIS_LEFTY
CONTROLLER_AXIS_RIGHTX = C.SDL_CONTROLLER_AXIS_RIGHTX
CONTROLLER_AXIS_RIGHTY = C.SDL_CONTROLLER_AXIS_RIGHTY
CONTROLLER_AXIS_TRIGGERLEFT = C.SDL_CONTROLLER_AXIS_TRIGGERLEFT
CONTROLLER_AXIS_TRIGGERRIGHT = C.SDL_CONTROLLER_AXIS_TRIGGERRIGHT
CONTROLLER_AXIS_MAX = C.SDL_CONTROLLER_AXIS_MAX
)
// An enumeration of buttons available from a controller.
// (https://wiki.libsdl.org/SDL_GameControllerButton)
const (
CONTROLLER_BUTTON_INVALID = C.SDL_CONTROLLER_BUTTON_INVALID
CONTROLLER_BUTTON_A = C.SDL_CONTROLLER_BUTTON_A
CONTROLLER_BUTTON_B = C.SDL_CONTROLLER_BUTTON_B
CONTROLLER_BUTTON_X = C.SDL_CONTROLLER_BUTTON_X
CONTROLLER_BUTTON_Y = C.SDL_CONTROLLER_BUTTON_Y
CONTROLLER_BUTTON_BACK = C.SDL_CONTROLLER_BUTTON_BACK
CONTROLLER_BUTTON_GUIDE = C.SDL_CONTROLLER_BUTTON_GUIDE
CONTROLLER_BUTTON_START = C.SDL_CONTROLLER_BUTTON_START
CONTROLLER_BUTTON_LEFTSTICK = C.SDL_CONTROLLER_BUTTON_LEFTSTICK
CONTROLLER_BUTTON_RIGHTSTICK = C.SDL_CONTROLLER_BUTTON_RIGHTSTICK
CONTROLLER_BUTTON_LEFTSHOULDER = C.SDL_CONTROLLER_BUTTON_LEFTSHOULDER
CONTROLLER_BUTTON_RIGHTSHOULDER = C.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
CONTROLLER_BUTTON_DPAD_UP = C.SDL_CONTROLLER_BUTTON_DPAD_UP
CONTROLLER_BUTTON_DPAD_DOWN = C.SDL_CONTROLLER_BUTTON_DPAD_DOWN
CONTROLLER_BUTTON_DPAD_LEFT = C.SDL_CONTROLLER_BUTTON_DPAD_LEFT
CONTROLLER_BUTTON_DPAD_RIGHT = C.SDL_CONTROLLER_BUTTON_DPAD_RIGHT
CONTROLLER_BUTTON_MAX = C.SDL_CONTROLLER_BUTTON_MAX
)
// GameControllerBindType is a type of game controller input.
type GameControllerBindType C.SDL_GameControllerBindType
// GameControllerAxis is an axis on a game controller.
// (https://wiki.libsdl.org/SDL_GameControllerAxis)
type GameControllerAxis C.SDL_GameControllerAxis
// GameControllerButton is a button on a game controller.
// (https://wiki.libsdl.org/SDL_GameControllerButton)
type GameControllerButton C.SDL_GameControllerButton
// GameController used to identify an SDL game controller.
type GameController C.SDL_GameController
// GameControllerButtonBind SDL joystick layer binding for controller button/axis mapping.
type GameControllerButtonBind C.SDL_GameControllerButtonBind
func (ctrl *GameController) cptr() *C.SDL_GameController {
return (*C.SDL_GameController)(unsafe.Pointer(ctrl))
}
func (axis GameControllerAxis) c() C.SDL_GameControllerAxis {
return C.SDL_GameControllerAxis(axis)
}
func (btn GameControllerButton) c() C.SDL_GameControllerButton {
return C.SDL_GameControllerButton(btn)
}
// GameControllerAddMapping adds support for controllers that SDL is unaware of or to cause an existing controller to have a different binding.
// (https://wiki.libsdl.org/SDL_GameControllerAddMapping)
func GameControllerAddMapping(mappingString string) int {
_mappingString := C.CString(mappingString)
defer C.free(unsafe.Pointer(_mappingString))
return int(C.SDL_GameControllerAddMapping(_mappingString))
}
// GameControllerNumMappings returns the number of mappings installed.
func GameControllerNumMappings() int {
return int(C.SDL_GameControllerNumMappings())
}
// GameControllerMappingForIndex returns the game controller mapping string at a particular index.
func GameControllerMappingForIndex(index int) string {
mappingString := C.SDL_GameControllerMappingForIndex(C.int(index))
defer C.free(unsafe.Pointer(mappingString))
return C.GoString(mappingString)
}
// GameControllerMappingForGUID returns the game controller mapping string for a given GUID.
// (https://wiki.libsdl.org/SDL_GameControllerMappingForGUID)
func GameControllerMappingForGUID(guid JoystickGUID) string {
mappingString := C.SDL_GameControllerMappingForGUID(guid.c())
defer C.free(unsafe.Pointer(mappingString))
return C.GoString(mappingString)
}
// IsGameController reports whether the given joystick is supported by the game controller interface.
// (https://wiki.libsdl.org/SDL_IsGameController)
func IsGameController(index int) bool {
return C.SDL_IsGameController(C.int(index)) == C.SDL_TRUE
}
// GameControllerNameForIndex returns the implementation dependent name for the game controller.
// (https://wiki.libsdl.org/SDL_GameControllerNameForIndex)
func GameControllerNameForIndex(index int) string {
return C.GoString(C.SDL_GameControllerNameForIndex(C.int(index)))
}
// GameControllerMappingForDeviceIndex returns the game controller mapping string at a particular index.
func GameControllerMappingForDeviceIndex(index int) string {
mappingString := C.SDL_GameControllerMappingForDeviceIndex(C.int(index))
defer C.free(unsafe.Pointer(mappingString))
return C.GoString(mappingString)
}
// GameControllerOpen opens a gamecontroller for use.
// (https://wiki.libsdl.org/SDL_GameControllerOpen)
func GameControllerOpen(index int) *GameController {
return (*GameController)(C.SDL_GameControllerOpen(C.int(index)))
}
// GameControllerFromInstanceID returns the GameController associated with an instance id.
// (https://wiki.libsdl.org/SDL_GameControllerFromInstanceID)
func GameControllerFromInstanceID(joyid JoystickID) *GameController {
return (*GameController)(C.SDL_GameControllerFromInstanceID(joyid.c()))
}
// Name returns the implementation dependent name for an opened game controller.
// (https://wiki.libsdl.org/SDL_GameControllerName)
func (ctrl *GameController) Name() string {
return C.GoString(C.SDL_GameControllerName(ctrl.cptr()))
}
// PlayerIndex the player index of an opened game controller, or -1 if it's not available.
// TODO: (https://wiki.libsdl.org/SDL_GameControllerGetPlayerIndex)
func (ctrl *GameController) PlayerIndex() int {
return int(C.SDL_GameControllerGetPlayerIndex(ctrl.cptr()))
}
// Vendor returns the USB vendor ID of an opened controller, if available, 0 otherwise.
func (ctrl *GameController) Vendor() int {
return int(C.SDL_GameControllerGetVendor(ctrl.cptr()))
}
// Product returns the USB product ID of an opened controller, if available, 0 otherwise.
func (ctrl *GameController) Product() int {
return int(C.SDL_GameControllerGetProduct(ctrl.cptr()))
}
// ProductVersion returns the product version of an opened controller, if available, 0 otherwise.
func (ctrl *GameController) ProductVersion() int {
return int(C.SDL_GameControllerGetProductVersion(ctrl.cptr()))
}
// Attached reports whether a controller has been opened and is currently connected.
// (https://wiki.libsdl.org/SDL_GameControllerGetAttached)
func (ctrl *GameController) Attached() bool {
return C.SDL_GameControllerGetAttached(ctrl.cptr()) == C.SDL_TRUE
}
// Mapping returns the current mapping of a Game Controller.
// (https://wiki.libsdl.org/SDL_GameControllerMapping)
func (ctrl *GameController) Mapping() string {
mappingString := C.SDL_GameControllerMapping(ctrl.cptr())
defer C.free(unsafe.Pointer(mappingString))
return C.GoString(mappingString)
}
// Joystick returns the Joystick ID from a Game Controller. The game controller builds on the Joystick API, but to be able to use the Joystick's functions with a gamepad, you need to use this first to get the joystick object.
// (https://wiki.libsdl.org/SDL_GameControllerGetJoystick)
func (ctrl *GameController) Joystick() *Joystick {
return (*Joystick)(unsafe.Pointer(C.SDL_GameControllerGetJoystick(ctrl.cptr())))
}
// GameControllerEventState returns the current state of, enable, or disable events dealing with Game Controllers. This will not disable Joystick events, which can also be fired by a controller (see https://wiki.libsdl.org/SDL_JoystickEventState).
// (https://wiki.libsdl.org/SDL_GameControllerEventState)
func GameControllerEventState(state int) int {
return int(C.SDL_GameControllerEventState(C.int(state)))
}
// GameControllerUpdate manually pumps game controller updates if not using the loop.
// (https://wiki.libsdl.org/SDL_GameControllerUpdate)
func GameControllerUpdate() {
C.SDL_GameControllerUpdate()
}
// GameControllerGetAxisFromString converts a string into an enum representation for a GameControllerAxis.
// (https://wiki.libsdl.org/SDL_GameControllerGetAxisFromString)
func GameControllerGetAxisFromString(pchString string) GameControllerAxis {
_pchString := C.CString(pchString)
defer C.free(unsafe.Pointer(_pchString))
return GameControllerAxis(C.SDL_GameControllerGetAxisFromString(_pchString))
}
// GameControllerGetStringForAxis converts from an axis enum to a string.
// (https://wiki.libsdl.org/SDL_GameControllerGetStringForAxis)
func GameControllerGetStringForAxis(axis GameControllerAxis) string {
return C.GoString(C.SDL_GameControllerGetStringForAxis(axis.c()))
}
// BindForAxis returns the SDL joystick layer binding for a controller button mapping.
// (https://wiki.libsdl.org/SDL_GameControllerGetBindForAxis)
func (ctrl *GameController) BindForAxis(axis GameControllerAxis) GameControllerButtonBind {
return GameControllerButtonBind(C.SDL_GameControllerGetBindForAxis(ctrl.cptr(), axis.c()))
}
// Axis returns the current state of an axis control on a game controller.
// (https://wiki.libsdl.org/SDL_GameControllerGetAxis)
func (ctrl *GameController) Axis(axis GameControllerAxis) int16 {
return int16(C.SDL_GameControllerGetAxis(ctrl.cptr(), axis.c()))
}
// GameControllerGetButtonFromString turns a string into a button mapping.
// (https://wiki.libsdl.org/SDL_GameControllerGetButtonFromString)
func GameControllerGetButtonFromString(pchString string) GameControllerButton {
_pchString := C.CString(pchString)
defer C.free(unsafe.Pointer(_pchString))
return GameControllerButton(C.SDL_GameControllerGetButtonFromString(_pchString))
}
// GameControllerGetStringForButton turns a button enum into a string mapping.
// (https://wiki.libsdl.org/SDL_GameControllerGetStringForButton)
func GameControllerGetStringForButton(btn GameControllerButton) string {
return C.GoString(C.SDL_GameControllerGetStringForButton(btn.c()))
}
// BindForButton returns the SDL joystick layer binding for this controller button mapping.
// (https://wiki.libsdl.org/SDL_GameControllerGetBindForButton)
func (ctrl *GameController) BindForButton(btn GameControllerButton) GameControllerButtonBind {
return GameControllerButtonBind(C.SDL_GameControllerGetBindForButton(ctrl.cptr(), btn.c()))
}
// Rumble triggers a rumble effect
// Each call to this function cancels any previous rumble effect, and calling it with 0 intensity stops any rumbling.
//
// lowFrequencyRumble - The intensity of the low frequency (left) rumble motor, from 0 to 0xFFFF
// highFrequencyRumble - The intensity of the high frequency (right) rumble motor, from 0 to 0xFFFF
// durationMS - The duration of the rumble effect, in milliseconds
//
// Returns error if rumble isn't supported on this joystick.
//
// TODO: (https://wiki.libsdl.org/SDL_GameControllerRumble)
func (ctrl *GameController) Rumble(lowFrequencyRumble, highFrequencyRumble uint16, durationMS uint32) error {
return errorFromInt(int(C.SDL_GameControllerRumble(ctrl.cptr(), C.Uint16(lowFrequencyRumble), C.Uint16(highFrequencyRumble), C.Uint32(durationMS))))
}
// Button returns the current state of a button on a game controller.
// (https://wiki.libsdl.org/SDL_GameControllerGetButton)
func (ctrl *GameController) Button(btn GameControllerButton) byte {
return byte(C.SDL_GameControllerGetButton(ctrl.cptr(), btn.c()))
}
// Close closes a game controller previously opened with GameControllerOpen().
// (https://wiki.libsdl.org/SDL_GameControllerClose)
func (ctrl *GameController) Close() {
C.SDL_GameControllerClose(ctrl.cptr())
}
// Type returns the type of game controller input for this SDL joystick layer binding.
func (bind *GameControllerButtonBind) Type() int {
return int(bind.bindType)
}
// Button returns button mapped for this SDL joystick layer binding.
func (bind *GameControllerButtonBind) Button() int {
val, _ := binary.Varint(bind.value[:4])
return int(val)
}
// Axis returns axis mapped for this SDL joystick layer binding.
func (bind *GameControllerButtonBind) Axis() int {
val, _ := binary.Varint(bind.value[:4])
return int(val)
}
// Hat returns hat mapped for this SDL joystick layer binding.
func (bind *GameControllerButtonBind) Hat() int {
val, _ := binary.Varint(bind.value[:4])
return int(val)
}
// HatMask returns hat mask for this SDL joystick layer binding.
func (bind *GameControllerButtonBind) HatMask() int {
val, _ := binary.Varint(bind.value[4:8])
return int(val)
}
// SendEffect sends a controller specific effect packet.
// (https://wiki.libsdl.org/SDL_GameControllerSendEffect)
func (ctrl *GameController) SendEffect(data []byte) (err error) {
_size := C.int(len(data))
return errorFromInt(int(C.SDL_GameControllerSendEffect(ctrl.cptr(), unsafe.Pointer(&data[0]), _size)))
}
// GetSensorDataRate gets the data rate (number of events per second) of a game controller sensor.
// (https://wiki.libsdl.org/SDL_GameControllerGetSensorDataRate)
func (ctrl *GameController) SensorDataRate(typ SensorType) (rate float32) {
return float32(C.SDL_GameControllerGetSensorDataRate(ctrl.cptr(), C.SDL_SensorType(typ)))
}
// HasRumble queries whether a game controller has rumble support.
// (https://wiki.libsdl.org/SDL_GameControllerHasRumble)
func (ctrl *GameController) HasRumble() bool {
return C.SDL_GameControllerHasRumble(ctrl.cptr()) == C.SDL_TRUE
}
// HasRumbleTriggers queries whether a game controller has rumble support on triggers.
// (https://wiki.libsdl.org/SDL_GameControllerHasRumbleTriggers)
func (ctrl *GameController) HasRumbleTriggers() bool {
return C.SDL_GameControllerHasRumbleTriggers(ctrl.cptr()) == C.SDL_TRUE
}
// GetAppleSFSymbolsNameForButton returns the sfSymbolsName for a given button on a game controller on Apple platforms.
// (https://wiki.libsdl.org/SDL_GameControllerGetAppleSFSymbolsNameForButton)
func (ctrl *GameController) GetAppleSFSymbolsNameForButton(button GameControllerButton) (sfSymbolsName string) {
_button := C.SDL_GameControllerButton(button)
_sfSymbolsName := C.SDL_GameControllerGetAppleSFSymbolsNameForButton(ctrl.cptr(), _button)
sfSymbolsName = C.GoString(_sfSymbolsName)
return
}
// GetAppleSFSymbolsNameForAxis returns the sfSymbolsName for a given axis on a game controller on Apple platforms.
// (https://wiki.libsdl.org/SDL_GameControllerGetAppleSFSymbolsNameForAxis)
func (ctrl *GameController) SDL_GameControllerGetAppleSFSymbolsNameForAxis(axis GameControllerAxis) (sfSymbolsName string) {
_axis := C.SDL_GameControllerAxis(axis)
_sfSymbolsName := C.SDL_GameControllerGetAppleSFSymbolsNameForAxis(ctrl.cptr(), _axis)
sfSymbolsName = C.GoString(_sfSymbolsName)
return
}