-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
events.go
1633 lines (1430 loc) · 55.3 KB
/
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
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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package sdl
/*
#include "sdl_wrapper.h"
#include "events.h"
// Used by Go functions like SDL_SensorEvent from SDL2 2.26.0 to enable backward compatibility when building with older SDL2
typedef struct SensorEvent {
Uint32 type;
Uint32 timestamp;
Sint32 which;
float data[6];
Uint64 timestamp_us;
} SensorEvent;
typedef struct ControllerSensorEvent {
Uint32 type;
Uint32 timestamp;
SDL_JoystickID which;
Sint32 sensor;
float data[3];
Uint64 timestamp_us;
} ControllerSensorEvent;
typedef struct MouseWheelEvent
{
Uint32 type; // ::SDL_MOUSEWHEEL
Uint32 timestamp; // In milliseconds, populated using SDL_GetTicks()
Uint32 windowID; // The window with mouse focus, if any
Uint32 which; // The mouse instance id, or SDL_TOUCH_MOUSEID
Sint32 x; // The amount scrolled horizontally, positive to the right and negative to the left
Sint32 y; // The amount scrolled vertically, positive away from the user and negative toward the user
Uint32 direction; // Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back
float preciseX; // The amount scrolled horizontally, positive to the right and negative to the left, with float precision (added in 2.0.18)
float preciseY; // The amount scrolled vertically, positive away from the user and negative toward the user, with float precision (added in 2.0.18)
Sint32 mouseX; // X coordinate, relative to window (added in 2.26.0)
Sint32 mouseY; // Y coordinate, relative to window (added in 2.26.0)
} MouseWheelEvent;
#if !SDL_VERSION_ATLEAST(2,0,9)
#if defined(WARN_OUTDATED)
#pragma message("SDL_DISPLAYEVENT is not supported before SDL 2.0.9")
#pragma message("SDL_DisplayEvent is not supported before SDL 2.0.9")
#endif
#define SDL_DISPLAYEVENT (0x150)
typedef struct SDL_DisplayEvent
{
Uint32 type; // ::SDL_DISPLAYEVENT
Uint32 timestamp; // In milliseconds, populated using SDL_GetTicks()
Uint32 display; // The associated display index
Uint8 event; // ::SDL_DisplayEventID
Uint8 padding1;
Uint8 padding2;
Uint8 padding3;
Sint32 data1; // event dependent data
} SDL_DisplayEvent;
#endif
#if !SDL_VERSION_ATLEAST(2,0,2)
#if defined(WARN_OUTDATED)
#pragma message("SDL_RENDER_TARGETS_RESET is not supported before SDL 2.0.2")
#endif
#define SDL_RENDER_TARGETS_RESET (0x2000)
#endif
#if !SDL_VERSION_ATLEAST(2,0,4)
#if defined(WARN_OUTDATED)
#pragma message("SDL_KEYMAPCHANGED is not supported before SDL 2.0.4")
#pragma message("SDL_AUDIODEVICEADDED is not supported before SDL 2.0.4")
#pragma message("SDL_AUDIODEVICEREMOVED is not supported before SDL 2.0.4")
#pragma message("SDL_RENDER_DEVICE_RESET is not supported before SDL 2.0.4")
#pragma message("SDL_AudioDeviceEvent is not supported before SDL 2.0.4")
#endif
#define SDL_KEYMAPCHANGED (0x304)
#define SDL_AUDIODEVICEADDED (0x1100)
#define SDL_AUDIODEVICEREMOVED (0x1101)
#define SDL_RENDER_DEVICE_RESET (0x2001)
typedef struct SDL_AudioDeviceEvent
{
Uint32 type;
Uint32 timestamp;
Uint32 which;
Uint8 iscapture;
Uint8 padding1;
Uint8 padding2;
Uint8 padding3;
} SDL_AudioDeviceEvent;
#endif
#if !SDL_VERSION_ATLEAST(2,0,5)
#if defined(WARN_OUTDATED)
#pragma message("SDL_DROPTEXT is not supported before SDL 2.0.5")
#pragma message("SDL_DROPBEGIN is not supported before SDL 2.0.5")
#pragma message("SDL_DROPCOMPLETE is not supported before SDL 2.0.5")
#endif
#define SDL_DROPTEXT (0x1001)
#define SDL_DROPBEGIN (0x1002)
#define SDL_DROPCOMPLETE (0x1003)
#endif
#if !SDL_VERSION_ATLEAST(2,0,9)
#define SDL_SENSORUPDATE (0x1200)
#endif
#if !SDL_VERSION_ATLEAST(2,0,22)
#if defined(WARN_OUTDATED)
#pragma message("SDL_TEXTEDITING_EXT is not supported before SDL 2.0.22")
#endif
#if !SDL_VERSION_ATLEAST(2,0,14)
#define SDL_CONTROLLERTOUCHPADDOWN (0x656)
#define SDL_CONTROLLERTOUCHPADMOTION (0x657)
#define SDL_CONTROLLERTOUCHPADUP (0x658)
#define SDL_CONTROLLERSENSORUPDATE (0x659)
#endif
#define SDL_TEXTEDITING_EXT (0x305)
#endif
// NOTE: To prevent build from failing when using older SDL2, we create a
// structure definiton that directly maps to the SDL2 struct definition if
// using the latest SDL2. Otherwise, we copy the latest definition and paste
// it here.
#if SDL_VERSION_ATLEAST(2,0,22)
typedef SDL_MouseButtonEvent MouseButtonEvent;
typedef SDL_TouchFingerEvent TouchFingerEvent;
typedef SDL_DropEvent DropEvent;
#else
typedef struct MouseButtonEvent
{
Uint32 type; // ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP
Uint32 timestamp;
Uint32 windowID; // The window with mouse focus, if any
Uint32 which; // The mouse instance id, or SDL_TOUCH_MOUSEID
Uint8 button; // The mouse button index
Uint8 state; // ::SDL_PRESSED or ::SDL_RELEASED
Uint8 clicks; // 1 for single-click, 2 for double-click, etc.
Uint8 padding1;
Sint32 x; // X coordinate, relative to window
Sint32 y; // Y coordinate, relative to window
} MouseButtonEvent;
typedef struct TouchFingerEvent
{
Uint32 type; // ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP
Uint32 timestamp; // In milliseconds, populated using SDL_GetTicks()
SDL_TouchID touchId; // The touch device id
SDL_FingerID fingerId; //
float x; // Normalized in the range 0...1
float y; // Normalized in the range 0...1
float dx; // Normalized in the range -1...1
float dy; // Normalized in the range -1...1
float pressure; // Normalized in the range 0...1
Uint32 windowID; // The window underneath the finger, if any
} TouchFingerEvent;
typedef struct DropEvent
{
Uint32 type; // ::SDL_DROPBEGIN or ::SDL_DROPFILE or ::SDL_DROPTEXT or ::SDL_DROPCOMPLETE
Uint32 timestamp; // In milliseconds, populated using SDL_GetTicks()
char *file; // The file name, which should be freed with SDL_free(), is NULL on begin/complete
Uint32 windowID; // The window that was dropped on, if any
} DropEvent;
#endif
#if !SDL_VERSION_ATLEAST(2,24,0)
#if defined(WARN_OUTDATED)
#pragma message("SDL_JOYBATTEYUPDATED is not supported before SDL 2.24.0")
#endif
#define SDL_JOYBATTERYUPDATED (1543)
#if !SDL_VERSION_ATLEAST(2,0,4)
typedef enum
{
SDL_JOYSTICK_POWER_UNKNOWN = -1,
SDL_JOYSTICK_POWER_EMPTY,
SDL_JOYSTICK_POWER_LOW,
SDL_JOYSTICK_POWER_MEDIUM,
SDL_JOYSTICK_POWER_FULL,
SDL_JOYSTICK_POWER_WIRED,
SDL_JOYSTICK_POWER_MAX
} SDL_JoystickPowerLevel;
#endif
typedef struct SDL_JoyBatteryEvent
{
Uint32 type;
Uint32 timestamp;
SDL_JoystickID which;
SDL_JoystickPowerLevel level;
} SDL_JoyBatteryEvent;
#endif
*/
import "C"
import (
"reflect"
"sync"
"unsafe"
)
var (
eventFilterCache EventFilter
eventWatches = make(map[EventWatchHandle]*eventFilterCallbackContext)
lastEventWatchHandleMutex sync.Mutex
lastEventWatchHandle EventWatchHandle
cevent C.SDL_Event
)
// Enumeration of the types of events that can be delivered.
// (https://wiki.libsdl.org/SDL_EventType)
type EventType uint32
const (
FIRSTEVENT EventType = C.SDL_FIRSTEVENT // do not remove (unused)
// Application events
QUIT EventType = C.SDL_QUIT // user-requested quit
// Android, iOS and WinRT events
APP_TERMINATING EventType = C.SDL_APP_TERMINATING // OS is terminating the application
APP_LOWMEMORY EventType = C.SDL_APP_LOWMEMORY // OS is low on memory; free some
APP_WILLENTERBACKGROUND EventType = C.SDL_APP_WILLENTERBACKGROUND // application is entering background
APP_DIDENTERBACKGROUND EventType = C.SDL_APP_DIDENTERBACKGROUND //application entered background
APP_WILLENTERFOREGROUND EventType = C.SDL_APP_WILLENTERFOREGROUND // application is entering foreground
APP_DIDENTERFOREGROUND EventType = C.SDL_APP_DIDENTERFOREGROUND // application entered foreground
// Display events
DISPLAYEVENT EventType = C.SDL_DISPLAYEVENT // Display state change
// Window events
WINDOWEVENT EventType = C.SDL_WINDOWEVENT // window state change
SYSWMEVENT EventType = C.SDL_SYSWMEVENT // system specific event
// Keyboard events
KEYDOWN EventType = C.SDL_KEYDOWN // key pressed
KEYUP EventType = C.SDL_KEYUP // key released
TEXTEDITING EventType = C.SDL_TEXTEDITING // keyboard text editing (composition)
TEXTINPUT EventType = C.SDL_TEXTINPUT // keyboard text input
TEXTEDITING_EXT EventType = C.SDL_TEXTEDITING_EXT // keyboard text editing (composition)
KEYMAPCHANGED EventType = C.SDL_KEYMAPCHANGED // keymap changed due to a system event such as an input language or keyboard layout change (>= SDL 2.0.4)
// Mouse events
MOUSEMOTION EventType = C.SDL_MOUSEMOTION // mouse moved
MOUSEBUTTONDOWN EventType = C.SDL_MOUSEBUTTONDOWN // mouse button pressed
MOUSEBUTTONUP EventType = C.SDL_MOUSEBUTTONUP // mouse button released
MOUSEWHEEL EventType = C.SDL_MOUSEWHEEL // mouse wheel motion
// Joystick events
JOYAXISMOTION EventType = C.SDL_JOYAXISMOTION // joystick axis motion
JOYBALLMOTION EventType = C.SDL_JOYBALLMOTION // joystick trackball motion
JOYHATMOTION EventType = C.SDL_JOYHATMOTION // joystick hat position change
JOYBUTTONDOWN EventType = C.SDL_JOYBUTTONDOWN // joystick button pressed
JOYBUTTONUP EventType = C.SDL_JOYBUTTONUP // joystick button released
JOYDEVICEADDED EventType = C.SDL_JOYDEVICEADDED // joystick connected
JOYDEVICEREMOVED EventType = C.SDL_JOYDEVICEREMOVED // joystick disconnected
JOYBATTERYUPDATED EventType = C.SDL_JOYBATTERYUPDATED // joystick battery level change
// Game controller events
CONTROLLERAXISMOTION EventType = C.SDL_CONTROLLERAXISMOTION // controller axis motion
CONTROLLERBUTTONDOWN EventType = C.SDL_CONTROLLERBUTTONDOWN // controller button pressed
CONTROLLERBUTTONUP EventType = C.SDL_CONTROLLERBUTTONUP // controller button released
CONTROLLERDEVICEADDED EventType = C.SDL_CONTROLLERDEVICEADDED // controller connected
CONTROLLERDEVICEREMOVED EventType = C.SDL_CONTROLLERDEVICEREMOVED // controller disconnected
CONTROLLERDEVICEREMAPPED EventType = C.SDL_CONTROLLERDEVICEREMAPPED // controller mapping updated
CONTROLLERTOUCHPADDOWN EventType = C.SDL_CONTROLLERTOUCHPADDOWN // Game controller touchpad was touched
CONTROLLERTOUCHPADMOTION EventType = C.SDL_CONTROLLERTOUCHPADMOTION // Game controller touchpad finger was moved
CONTROLLERTOUCHPADUP EventType = C.SDL_CONTROLLERTOUCHPADUP // Game controller touchpad finger was lifted
CONTROLLERSENSORUPDATE EventType = C.SDL_CONTROLLERSENSORUPDATE // Game controller sensor was updated
// Touch events
FINGERDOWN EventType = C.SDL_FINGERDOWN // user has touched input device
FINGERUP EventType = C.SDL_FINGERUP // user stopped touching input device
FINGERMOTION EventType = C.SDL_FINGERMOTION // user is dragging finger on input device
// Gesture events
DOLLARGESTURE EventType = C.SDL_DOLLARGESTURE
DOLLARRECORD EventType = C.SDL_DOLLARRECORD
MULTIGESTURE EventType = C.SDL_MULTIGESTURE
// Clipboard events
CLIPBOARDUPDATE EventType = C.SDL_CLIPBOARDUPDATE // the clipboard changed
// Drag and drop events
DROPFILE EventType = C.SDL_DROPFILE // the system requests a file open
DROPTEXT EventType = C.SDL_DROPTEXT // text/plain drag-and-drop event
DROPBEGIN EventType = C.SDL_DROPBEGIN // a new set of drops is beginning (NULL filename)
DROPCOMPLETE EventType = C.SDL_DROPCOMPLETE // current set of drops is now complete (NULL filename)
// Audio hotplug events
AUDIODEVICEADDED EventType = C.SDL_AUDIODEVICEADDED // a new audio device is available (>= SDL 2.0.4)
AUDIODEVICEREMOVED EventType = C.SDL_AUDIODEVICEREMOVED // an audio device has been removed (>= SDL 2.0.4)
// Sensor events
SENSORUPDATE EventType = C.SDL_SENSORUPDATE // a sensor was updated
// Render events
RENDER_TARGETS_RESET EventType = C.SDL_RENDER_TARGETS_RESET // the render targets have been reset and their contents need to be updated (>= SDL 2.0.2)
RENDER_DEVICE_RESET EventType = C.SDL_RENDER_DEVICE_RESET // the device has been reset and all textures need to be recreated (>= SDL 2.0.4)
// These are for your use, and should be allocated with RegisterEvents()
USEREVENT EventType = C.SDL_USEREVENT // a user-specified event
LASTEVENT EventType = C.SDL_LASTEVENT // (only for bounding internal arrays)
)
// Actions for PeepEvents().
// (https://wiki.libsdl.org/SDL_PeepEvents)
type EventAction C.SDL_eventaction
const (
ADDEVENT EventAction = C.SDL_ADDEVENT // up to numevents events will be added to the back of the event queue
PEEKEVENT EventAction = C.SDL_PEEKEVENT // up to numevents events at the front of the event queue, within the specified minimum and maximum type, will be returned and will not be removed from the queue
GETEVENT EventAction = C.SDL_GETEVENT // up to numevents events at the front of the event queue, within the specified minimum and maximum type, will be returned and will be removed from the queue
)
// Toggles for different event state functions.
// (https://wiki.libsdl.org/SDL_EventState)
type EventStateConstant int
const (
QUERY EventStateConstant = C.SDL_QUERY
IGNORE EventStateConstant = C.SDL_IGNORE
DISABLE EventStateConstant = C.SDL_DISABLE
ENABLE EventStateConstant = C.SDL_ENABLE
)
// Event is a union of all event structures used in SDL.
// (https://wiki.libsdl.org/SDL_Event)
type Event interface {
GetType() EventType // GetType returns the event type
GetTimestamp() uint32 // GetTimestamp returns the timestamp of the event
}
// CEvent is a union of all event structures used in SDL.
// (https://wiki.libsdl.org/SDL_Event)
type CEvent struct {
Type EventType
_ [52]byte // padding
}
// CommonEvent contains common event data.
// (https://wiki.libsdl.org/SDL_Event)
type CommonEvent struct {
Type EventType // the event type
Timestamp uint32 // timestamp of the event
}
type cCommonEvent C.SDL_CommonEvent
// GetType returns the event type.
func (e CommonEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e CommonEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// DisplayEvent contains common event data.
// (https://wiki.libsdl.org/SDL_Event)
type DisplayEvent struct {
Type EventType // the event type
Timestamp uint32 // timestamp of the event
Display uint32 // the associated display index
Event uint8 // TODO: (https://wiki.libsdl.org/SDL_DisplayEventID)
Data1 int32 // event dependent data
}
type cDisplayEvent C.SDL_DisplayEvent
// GetType returns the event type.
func (e DisplayEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e DisplayEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// WindowEvent contains window state change event data.
// (https://wiki.libsdl.org/SDL_WindowEvent)
type WindowEvent struct {
Type EventType // WINDOWEVENT
Timestamp uint32 // timestamp of the event
WindowID uint32 // the associated window
Event WindowEventID // (https://wiki.libsdl.org/SDL_WindowEventID)
Data1 int32 // event dependent data
Data2 int32 // event dependent data
}
type cWindowEvent C.SDL_WindowEvent
// GetType returns the event type.
func (e WindowEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e WindowEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// KeyboardEvent contains keyboard key down event information.
// (https://wiki.libsdl.org/SDL_KeyboardEvent)
type KeyboardEvent struct {
Type EventType // KEYDOWN, KEYUP
Timestamp uint32 // timestamp of the event
WindowID uint32 // the window with keyboard focus, if any
State ButtonState // PRESSED, RELEASED
Repeat uint8 // non-zero if this is a key repeat
Keysym Keysym // Keysym representing the key that was pressed or released
}
type cKeyboardEvent C.SDL_KeyboardEvent
// GetType returns the event type.
func (e KeyboardEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e KeyboardEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// TextEditingEvent contains keyboard text editing event information.
// (https://wiki.libsdl.org/SDL_TextEditingEvent)
type TextEditingEvent struct {
Type EventType // TEXTEDITING
Timestamp uint32 // timestamp of the event
WindowID uint32 // the window with keyboard focus, if any
Text string // the null-terminated editing text in UTF-8 encoding
Start int32 // the location to begin editing from
Length int32 // the number of characters to edit from the start point
}
type cTextEditingEvent C.SDL_TextEditingEvent
// GetType returns the event type.
func (e TextEditingEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e TextEditingEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// GetText returns the text as string
func (e TextEditingEvent) GetText() string {
return e.Text
}
// TextInputEvent contains keyboard text input event information.
// (https://wiki.libsdl.org/SDL_TextInputEvent)
type TextInputEvent struct {
Type EventType // TEXTINPUT
Timestamp uint32 // timestamp of the event
WindowID uint32 // the window with keyboard focus, if any
Text string // the null-terminated input text in UTF-8 encoding
}
type cTextInputEvent C.SDL_TextInputEvent
// GetType returns the event type.
func (e TextInputEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e TextInputEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// GetText returns the text as string
func (e TextInputEvent) GetText() string {
return e.Text
}
// MouseMotionEvent contains mouse motion event information.
// (https://wiki.libsdl.org/SDL_MouseMotionEvent)
type MouseMotionEvent struct {
Type EventType // MOUSEMOTION
Timestamp uint32 // timestamp of the event
WindowID uint32 // the window with mouse focus, if any
Which uint32 // the mouse instance id, or TOUCH_MOUSEID
State ButtonMask // masks for BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT, BUTTON_X1, BUTTON_X2
X int32 // X coordinate, relative to window
Y int32 // Y coordinate, relative to window
XRel int32 // relative motion in the X direction
YRel int32 // relative motion in the Y direction
}
type cMouseMotionEvent C.SDL_MouseMotionEvent
// GetType returns the event type.
func (e MouseMotionEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e MouseMotionEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// MouseButtonEvent contains mouse button event information.
// (https://wiki.libsdl.org/SDL_MouseButtonEvent)
type MouseButtonEvent struct {
Type EventType // MOUSEBUTTONDOWN, MOUSEBUTTONUP
Timestamp uint32 // timestamp of the event
WindowID uint32 // the window with mouse focus, if any
Which uint32 // the mouse instance id, or TOUCH_MOUSEID
Button Button // BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT, BUTTON_X1, BUTTON_X2
State ButtonState // PRESSED, RELEASED
Clicks uint8 // 1 for single-click, 2 for double-click, etc. (>= SDL 2.0.2)
X int32 // X coordinate, relative to window
Y int32 // Y coordinate, relative to window
}
type cMouseButtonEvent C.MouseButtonEvent
// GetType returns the event type.
func (e MouseButtonEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e MouseButtonEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// MouseWheelEvent contains mouse wheel event information.
// (https://wiki.libsdl.org/SDL_MouseWheelEvent)
type MouseWheelEvent struct {
Type EventType // MOUSEWHEEL
Timestamp uint32 // timestamp of the event
WindowID uint32 // the window with mouse focus, if any
Which uint32 // the mouse instance id, or TOUCH_MOUSEID
X int32 // the amount scrolled horizontally, positive to the right and negative to the left
Y int32 // the amount scrolled vertically, positive away from the user and negative toward the user
Direction uint32 // MOUSEWHEEL_NORMAL, MOUSEWHEEL_FLIPPED (>= SDL 2.0.4)
PreciseX float32 // The amount scrolled horizontally, positive to the right and negative to the left, with float precision (added in 2.0.18)
PreciseY float32 // The amount scrolled vertically, positive away from the user and negative toward the user, with float precision (added in 2.0.18)
MouseX int32 // X coordinate, relative to window (added in 2.26.0)
MouseY int32 // Y coordinate, relative to window (added in 2.26.0)
}
type cMouseWheelEvent C.MouseWheelEvent
// GetType returns the event type.
func (e MouseWheelEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e MouseWheelEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// JoyAxisEvent contains joystick axis motion event information.
// (https://wiki.libsdl.org/SDL_JoyAxisEvent)
type JoyAxisEvent struct {
Type EventType // JOYAXISMOTION
Timestamp uint32 // timestamp of the event
Which JoystickID // the instance id of the joystick that reported the event
Axis uint8 // the index of the axis that changed
Value int16 // the current position of the axis (range: -32768 to 32767)
}
type cJoyAxisEvent C.SDL_JoyAxisEvent
// GetType returns the event type.
func (e JoyAxisEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e JoyAxisEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// JoyBallEvent contains joystick trackball motion event information.
// (https://wiki.libsdl.org/SDL_JoyBallEvent)
type JoyBallEvent struct {
Type EventType // JOYBALLMOTION
Timestamp uint32 // timestamp of the event
Which JoystickID // the instance id of the joystick that reported the event
Ball uint8 // the index of the trackball that changed
XRel int16 // the relative motion in the X direction
YRel int16 // the relative motion in the Y direction
}
type cJoyBallEvent C.SDL_JoyBallEvent
// GetType returns the event type.
func (e JoyBallEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e JoyBallEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// JoyHatEvent contains joystick hat position change event information.
// (https://wiki.libsdl.org/SDL_JoyHatEvent)
type JoyHatEvent struct {
Type EventType // JOYHATMOTION
Timestamp uint32 // timestamp of the event
Which JoystickID // the instance id of the joystick that reported the event
Hat uint8 // the index of the hat that changed
Value JoystickHat // HAT_LEFTUP, HAT_UP, HAT_RIGHTUP, HAT_LEFT, HAT_CENTERED, HAT_RIGHT, HAT_LEFTDOWN, HAT_DOWN, HAT_RIGHTDOWN
}
type cJoyHatEvent C.SDL_JoyHatEvent
// GetType returns the event type.
func (e JoyHatEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e JoyHatEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// JoyButtonEvent contains joystick button event information.
// (https://wiki.libsdl.org/SDL_JoyButtonEvent)
type JoyButtonEvent struct {
Type EventType // JOYBUTTONDOWN, JOYBUTTONUP
Timestamp uint32 // timestamp of the event
Which JoystickID // the instance id of the joystick that reported the event
Button uint8 // the index of the button that changed
State ButtonState // PRESSED, RELEASED
}
type cJoyButtonEvent C.SDL_JoyButtonEvent
// GetType returns the event type.
func (e JoyButtonEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e JoyButtonEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// JoyDeviceAddedEvent contains joystick device event information.
// (https://wiki.libsdl.org/SDL_JoyDeviceEvent)
type JoyDeviceAddedEvent struct {
Type EventType // JOYDEVICEADDED
Timestamp uint32 // the timestamp of the event
Which JoystickID // the joystick device index
}
type cJoyDeviceEvent C.SDL_JoyDeviceEvent
// GetType returns the event type.
func (e JoyDeviceAddedEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e JoyDeviceAddedEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// JoyDeviceRemovedEvent contains joystick device event information.
// (https://wiki.libsdl.org/SDL_JoyDeviceEvent)
type JoyDeviceRemovedEvent struct {
Type EventType // JOYDEVICEREMOVED
Timestamp uint32 // the timestamp of the event
Which JoystickID // the instance id
}
// GetType returns the event type.
func (e JoyDeviceRemovedEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e JoyDeviceRemovedEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// JoyBatteryEvent contains joystick button event information.
// (https://wiki.libsdl.org/SDL_JoyBatteryEvent)
type JoyBatteryEvent struct {
Type EventType // JOYBATTERYUPDATED
Timestamp uint32 // timestamp of the event
Which JoystickID // the instance id of the joystick that reported the event
Level JoystickPowerLevel // the joystick battery level
}
type cJoyBatteryEvent C.SDL_JoyBatteryEvent
// GetType returns the event type.
func (e JoyBatteryEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e JoyBatteryEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// ControllerAxisEvent contains game controller axis motion event information.
// (https://wiki.libsdl.org/SDL_ControllerAxisEvent)
type ControllerAxisEvent struct {
Type EventType // CONTROLLERAXISMOTION
Timestamp uint32 // the timestamp of the event
Which JoystickID // the joystick instance id
Axis GameControllerAxis // the controller axis (https://wiki.libsdl.org/SDL_GameControllerAxis)
Value int16 // the axis value (range: -32768 to 32767)
}
type cControllerAxisEvent C.SDL_ControllerAxisEvent
// GetType returns the event type.
func (e ControllerAxisEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e ControllerAxisEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// ControllerButtonEvent contains game controller button event information.
// (https://wiki.libsdl.org/SDL_ControllerButtonEvent)
type ControllerButtonEvent struct {
Type EventType // CONTROLLERBUTTONDOWN, CONTROLLERBUTTONUP
Timestamp uint32 // the timestamp of the event
Which JoystickID // the joystick instance id
Button GameControllerButton // the controller button (https://wiki.libsdl.org/SDL_GameControllerButton)
State ButtonState // PRESSED, RELEASED
}
type cControllerButtonEvent C.SDL_ControllerButtonEvent
// GetType returns the event type.
func (e ControllerButtonEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e ControllerButtonEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// ControllerDeviceEvent contains controller device event information.
// (https://wiki.libsdl.org/SDL_ControllerDeviceEvent)
type ControllerDeviceEvent struct {
Type EventType // CONTROLLERDEVICEADDED, CONTROLLERDEVICEREMOVED, SDL_CONTROLLERDEVICEREMAPPED
Timestamp uint32 // the timestamp of the event
Which JoystickID // the joystick device index for the CONTROLLERDEVICEADDED event or instance id for the CONTROLLERDEVICEREMOVED or CONTROLLERDEVICEREMAPPED event
}
type cControllerDeviceEvent C.SDL_ControllerDeviceEvent
// GetType returns the event type.
func (e ControllerDeviceEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e ControllerDeviceEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// ControllerSensorEvent contains data from sensors such as accelerometer and gyroscope
// (TODO: https://wiki.libsdl.org/SDL_ControllerSensorEvent)
type ControllerSensorEvent struct {
Type EventType // SDL_CONTROLLERSENSORUPDATE
Timestamp uint32 // In milliseconds, populated using SDL_GetTicks()
Which JoystickID // The joystick instance id
Sensor int32 // The type of the sensor, one of the values of SensorType
Data [3]float32 // Up to 3 values from the sensor - additional values can be queried using SDL_SensorGetData()
TimestampUs uint64 // The timestamp of the sensor reading in microseconds, if the hardware provides this information.
}
type cControllerSensorEvent C.ControllerSensorEvent
// GetType returns the event type.
func (e ControllerSensorEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e ControllerSensorEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// AudioDeviceEvent contains audio device event information.
// (https://wiki.libsdl.org/SDL_AudioDeviceEvent)
type AudioDeviceEvent struct {
Type EventType // AUDIODEVICEADDED, AUDIODEVICEREMOVED
Timestamp uint32 // the timestamp of the event
Which uint32 // the audio device index for the AUDIODEVICEADDED event (valid until next GetNumAudioDevices() call), AudioDeviceID for the AUDIODEVICEREMOVED event
IsCapture uint8 // zero if an audio output device, non-zero if an audio capture device
}
type cAudioDeviceEvent C.SDL_AudioDeviceEvent
// GetType returns the event type.
func (e AudioDeviceEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e AudioDeviceEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// TouchFingerEvent contains finger touch event information.
// (https://wiki.libsdl.org/SDL_TouchFingerEvent)
type TouchFingerEvent struct {
Type EventType // FINGERMOTION, FINGERDOWN, FINGERUP
Timestamp uint32 // timestamp of the event
TouchID TouchID // the touch device id
FingerID FingerID // the finger id
X float32 // the x-axis location of the touch event, normalized (0...1)
Y float32 // the y-axis location of the touch event, normalized (0...1)
DX float32 // the distance moved in the x-axis, normalized (-1...1)
DY float32 // the distance moved in the y-axis, normalized (-1...1)
Pressure float32 // the quantity of pressure applied, normalized (0...1)
WindowID uint32 // the window underneath the finger, if any
}
type cTouchFingerEvent C.TouchFingerEvent
// GetType returns the event type.
func (e TouchFingerEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e TouchFingerEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// MultiGestureEvent contains multiple finger gesture event information.
// (https://wiki.libsdl.org/SDL_MultiGestureEvent)
type MultiGestureEvent struct {
Type EventType // MULTIGESTURE
Timestamp uint32 // timestamp of the event
TouchID TouchID // the touch device id
DTheta float32 // the amount that the fingers rotated during this motion
DDist float32 // the amount that the fingers pinched during this motion
X float32 // the normalized center of gesture
Y float32 // the normalized center of gesture
NumFingers uint16 // the number of fingers used in the gesture
}
type cMultiGestureEvent C.SDL_MultiGestureEvent
// GetType returns the event type.
func (e MultiGestureEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e MultiGestureEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// DollarGestureEvent contains complex gesture event information.
// (https://wiki.libsdl.org/SDL_DollarGestureEvent)
type DollarGestureEvent struct {
Type EventType // DOLLARGESTURE, DOLLARRECORD
Timestamp uint32 // timestamp of the event
TouchID TouchID // the touch device id
GestureID GestureID // the unique id of the closest gesture to the performed stroke
NumFingers uint32 // the number of fingers used to draw the stroke
Error float32 // the difference between the gesture template and the actual performed gesture (lower error is a better match)
X float32 // the normalized center of gesture
Y float32 // the normalized center of gesture
}
type cDollarGestureEvent C.SDL_DollarGestureEvent
// GetType returns the event type.
func (e DollarGestureEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e DollarGestureEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// DropEvent contains an event used to request a file open by the system.
// (https://wiki.libsdl.org/SDL_DropEvent)
type DropEvent struct {
Type EventType // DROPFILE, DROPTEXT, DROPBEGIN, DROPCOMPLETE
Timestamp uint32 // timestamp of the event
File string // the file name
WindowID uint32 // the window that was dropped on, if any
}
type cDropEvent C.DropEvent
// GetType returns the event type.
func (e DropEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e DropEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// SensorEvent contains data from sensors such as accelerometer and gyroscope
// (https://wiki.libsdl.org/SDL_SensorEvent)
type SensorEvent struct {
Type EventType // SDL_SENSORUPDATE
Timestamp uint32 // In milliseconds, populated using SDL_GetTicks()
Which int32 // The instance ID of the sensor
Data [6]float32 // Up to 6 values from the sensor - additional values can be queried using SDL_SensorGetData()
TimestampUs uint64 // The timestamp of the sensor reading in microseconds, if the hardware provides this information.
}
type cSensorEvent C.SensorEvent
// GetType returns the event type.
func (e SensorEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e SensorEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// RenderEvent contains render event information.
// (https://wiki.libsdl.org/SDL_EventType)
type RenderEvent struct {
Type EventType // the event type
Timestamp uint32 // timestamp of the event
}
// GetType returns the event type.
func (e RenderEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e RenderEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// QuitEvent contains the "quit requested" event.
// (https://wiki.libsdl.org/SDL_QuitEvent)
type QuitEvent struct {
Type EventType // QUIT
Timestamp uint32 // timestamp of the event
}
// GetType returns the event type.
func (e QuitEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e QuitEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// OSEvent contains OS specific event information.
type OSEvent struct {
Type EventType // the event type
Timestamp uint32 // timestamp of the event
}
// GetType returns the event type.
func (e OSEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e OSEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// ClipboardEvent contains clipboard event information.
// (https://wiki.libsdl.org/SDL_EventType)
type ClipboardEvent struct {
Type EventType // CLIPBOARDUPDATE
Timestamp uint32 // timestamp of the event
}
// GetType returns the event type.
func (e ClipboardEvent) GetType() EventType {
return e.Type
}
// GetTimestamp returns the timestamp of the event.
func (e ClipboardEvent) GetTimestamp() uint32 {
return e.Timestamp
}
// UserEvent contains an application-defined event type.
// (https://wiki.libsdl.org/SDL_UserEvent)
type UserEvent struct {
Type EventType // value obtained from RegisterEvents()
Timestamp uint32 // timestamp of the event
WindowID uint32 // the associated window, if any