sdl2_ffi 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -59
- data/lib/sdl2.rb +52 -15
- data/lib/sdl2/application.rb +71 -0
- data/lib/sdl2/audio.rb +72 -24
- data/lib/sdl2/clipboard.rb +9 -3
- data/lib/sdl2/color.rb +8 -3
- data/lib/sdl2/cpuinfo.rb +30 -10
- data/lib/sdl2/engine.rb +52 -0
- data/lib/sdl2/engine/block_engine.rb +27 -0
- data/lib/sdl2/engine/engines.rb +46 -0
- data/lib/sdl2/error.rb +9 -3
- data/lib/sdl2/events.rb +68 -6
- data/lib/sdl2/gamecontroller.rb +60 -20
- data/lib/sdl2/gem_version.rb +1 -1
- data/lib/sdl2/gesture.rb +12 -4
- data/lib/sdl2/haptic.rb +90 -30
- data/lib/sdl2/hints.rb +12 -4
- data/lib/sdl2/image.rb +85 -3
- data/lib/sdl2/init.rb +15 -5
- data/lib/sdl2/joystick.rb +63 -21
- data/lib/sdl2/keyboard.rb +101 -17
- data/lib/sdl2/keycode.rb +72 -72
- data/lib/sdl2/library.rb +7 -0
- data/lib/sdl2/log.rb +78 -21
- data/lib/sdl2/mixer.rb +651 -0
- data/lib/sdl2/mixer/chunk.rb +47 -0
- data/lib/sdl2/mixer/lib_paths.rb +8 -0
- data/lib/sdl2/mouse.rb +39 -13
- data/lib/sdl2/pixels.rb +39 -13
- data/lib/sdl2/point.rb +29 -0
- data/lib/sdl2/power.rb +3 -1
- data/lib/sdl2/rect.rb +94 -19
- data/lib/sdl2/render.rb +156 -52
- data/lib/sdl2/rwops.rb +60 -20
- data/lib/sdl2/surface.rb +85 -28
- data/lib/sdl2/syswm.rb +3 -1
- data/lib/sdl2/timer.rb +18 -6
- data/lib/sdl2/touch.rb +12 -4
- data/lib/sdl2/ttf.rb +153 -59
- data/lib/sdl2/ttf/font.rb +21 -5
- data/lib/sdl2/version.rb +9 -3
- data/lib/sdl2/video.rb +210 -70
- data/lib/sdl2/window.rb +9 -3
- data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/draws_the_message_to_the_screen.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/writes_a_message_to_a_surface.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/defaults_to_mouse_out.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/has_a_button_sheet.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_down.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_in.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_out.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_up.approved.png +0 -0
- data/spec/fixtures/images/button_sheet.png +0 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_01_hello_world_spec.rb +9 -2
- data/spec/functional/lazy_foo_tutorial/lazy_foo_03_extension_libraries_spec.rb +1 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_04_event_driven_programming_spec.rb +4 -3
- data/spec/functional/lazy_foo_tutorial/lazy_foo_05_color_keying_spec.rb +1 -1
- data/spec/functional/lazy_foo_tutorial/lazy_foo_06_clip_blitting_and_sprite_sheets_spec.rb +4 -3
- data/spec/functional/lazy_foo_tutorial/lazy_foo_07_true_type_fonts_spec.rb +4 -2
- data/spec/functional/lazy_foo_tutorial/lazy_foo_08_key_presses_spec.rb +10 -22
- data/spec/functional/lazy_foo_tutorial/lazy_foo_09_mouse_events_spec.rb +121 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_10_key_states_spec.rb +30 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_11_playing_sounds_spec.rb +116 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_12_timing_spec.rb +57 -0
- data/spec/spec_helper.rb +3 -1
- metadata +31 -2
data/lib/sdl2/gem_version.rb
CHANGED
data/lib/sdl2/gesture.rb
CHANGED
@@ -7,9 +7,17 @@ module SDL2
|
|
7
7
|
|
8
8
|
typedef :int64, :gesture_id
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
##
|
11
|
+
#
|
12
|
+
api :SDL_RecordGesture, [:touch_id], :int
|
13
|
+
##
|
14
|
+
#
|
15
|
+
api :SDL_SaveAllDollarTemplates, [RWops.by_ref], :int
|
16
|
+
##
|
17
|
+
#
|
18
|
+
api :SDL_SaveDollarTemplate, [:gesture_id, RWops.by_ref], :int
|
19
|
+
##
|
20
|
+
#
|
21
|
+
api :SDL_LoadDollarTemplates, [:touch_id, RWops.by_ref], :int
|
14
22
|
|
15
23
|
end
|
data/lib/sdl2/haptic.rb
CHANGED
@@ -436,35 +436,95 @@ module SDL2
|
|
436
436
|
|
437
437
|
##
|
438
438
|
# Get the number of haptics?
|
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
|
-
|
439
|
+
##
|
440
|
+
#
|
441
|
+
api :SDL_NumHaptics, [], :int
|
442
|
+
##
|
443
|
+
#
|
444
|
+
api :SDL_HapticName, [:int], :string
|
445
|
+
##
|
446
|
+
#
|
447
|
+
api :SDL_HapticOpen, [:int], Haptic.auto_ptr
|
448
|
+
##
|
449
|
+
#
|
450
|
+
api :SDL_HapticOpened, [:int], :int
|
451
|
+
##
|
452
|
+
#
|
453
|
+
api :SDL_HapticIndex, [Haptic.by_ref], :int
|
454
|
+
##
|
455
|
+
#
|
456
|
+
api :SDL_MouseIsHaptic, [], :int
|
457
|
+
##
|
458
|
+
#
|
459
|
+
api :SDL_HapticOpenFromMouse, [], Haptic.auto_ptr
|
460
|
+
##
|
461
|
+
#
|
462
|
+
api :SDL_JoystickIsHaptic, [Joystick.by_ref], :int
|
463
|
+
##
|
464
|
+
#
|
465
|
+
api :SDL_HapticOpenFromJoystick, [Joystick.by_ref], Haptic.auto_ptr
|
466
|
+
##
|
467
|
+
#
|
468
|
+
api :SDL_HapticClose, [Haptic.by_ref], :void
|
469
|
+
##
|
470
|
+
#
|
471
|
+
api :SDL_HapticNumEffects, [Haptic.by_ref], :int
|
472
|
+
##
|
473
|
+
#
|
474
|
+
api :SDL_HapticNumEffectsPlaying, [Haptic.by_ref], :int
|
475
|
+
##
|
476
|
+
#
|
477
|
+
api :SDL_HapticQuery, [Haptic.by_ref], :int
|
478
|
+
##
|
479
|
+
#
|
480
|
+
api :SDL_HapticNumAxes, [Haptic.by_ref], :int
|
481
|
+
##
|
482
|
+
#
|
483
|
+
api :SDL_HapticEffectSupported, [Haptic.by_ref, Haptic::Effect.by_ref], :int
|
484
|
+
##
|
485
|
+
#
|
486
|
+
api :SDL_HapticNewEffect, [Haptic.by_ref, Haptic::Effect.by_ref], :int
|
487
|
+
##
|
488
|
+
#
|
489
|
+
api :SDL_HapticUpdateEffect, [Haptic.by_ref, :int, Haptic::Effect.by_ref], :int
|
490
|
+
##
|
491
|
+
#
|
492
|
+
api :SDL_HapticRunEffect, [Haptic.by_ref, :int, :uint32], :int
|
493
|
+
##
|
494
|
+
#
|
495
|
+
api :SDL_HapticStopEffect, [Haptic.by_ref, :int], :int
|
496
|
+
##
|
497
|
+
#
|
498
|
+
api :SDL_HapticDestroyEffect, [Haptic.by_ref, :int], :int
|
499
|
+
##
|
500
|
+
#
|
501
|
+
api :SDL_HapticGetEffectStatus, [Haptic.by_ref, :int], :int
|
502
|
+
##
|
503
|
+
#
|
504
|
+
api :SDL_HapticSetGain, [Haptic.by_ref, :int], :int
|
505
|
+
##
|
506
|
+
#
|
507
|
+
api :SDL_HapticSetAutocenter, [Haptic.by_ref, :int], :int
|
508
|
+
##
|
509
|
+
#
|
510
|
+
api :SDL_HapticPause, [Haptic.by_ref], :int
|
511
|
+
##
|
512
|
+
#
|
513
|
+
api :SDL_HapticUnpause, [Haptic.by_ref], :int
|
514
|
+
##
|
515
|
+
#
|
516
|
+
api :SDL_HapticStopAll, [Haptic.by_ref], :int
|
517
|
+
##
|
518
|
+
#
|
519
|
+
api :SDL_HapticRumbleSupported, [Haptic.by_ref], :int
|
520
|
+
##
|
521
|
+
#
|
522
|
+
api :SDL_HapticRumbleInit, [Haptic.by_ref], :int
|
523
|
+
##
|
524
|
+
#
|
525
|
+
api :SDL_HapticRumblePlay, [Haptic.by_ref], :int
|
526
|
+
##
|
527
|
+
#
|
528
|
+
api :SDL_HapticRumbleStop, [Haptic.by_ref], :int
|
469
529
|
|
470
530
|
end
|
data/lib/sdl2/hints.rb
CHANGED
@@ -51,9 +51,17 @@ module SDL2
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
##
|
55
|
+
#
|
56
|
+
api :SDL_ClearHints, [], :void
|
57
|
+
##
|
58
|
+
#
|
59
|
+
api :SDL_GetHint, [:string], :string
|
60
|
+
##
|
61
|
+
#
|
62
|
+
api :SDL_SetHint, [:string, :string], :bool, {error: true}
|
63
|
+
##
|
64
|
+
#
|
65
|
+
api :SDL_SetHintWithPriority, [:string, :string, :hint_priority], :bool
|
58
66
|
|
59
67
|
end
|
data/lib/sdl2/image.rb
CHANGED
@@ -10,49 +10,131 @@ module SDL2
|
|
10
10
|
extend Library
|
11
11
|
ffi_lib SDL_IMAGE_MODULE
|
12
12
|
|
13
|
+
module INIT
|
14
|
+
include EnumerableConstants
|
15
|
+
JPG = next_const_value
|
16
|
+
PNG = next_const_value
|
17
|
+
TIF = next_const_value
|
18
|
+
WEBP = next_const_value
|
19
|
+
end
|
20
|
+
enum :init_flags, INIT.flatten_consts
|
13
21
|
|
14
|
-
|
15
|
-
|
16
|
-
|
22
|
+
##
|
23
|
+
# Loads dynamic libraries and prepares them for use. Flags should be
|
24
|
+
# one or more flags from IMG_InitFlags OR'd together.
|
25
|
+
# It returns the flags successfully initialized, or 0 on failure.
|
26
|
+
api :IMG_Init, [:init_flags], :int, {error: true, filter: TRUE_WHEN_NOT_ZERO}
|
27
|
+
##
|
28
|
+
#
|
17
29
|
api :IMG_Quit, [], :void
|
30
|
+
##
|
31
|
+
#
|
18
32
|
api :IMG_LoadTyped_RW, [RWops.by_ref, :int, :string], Surface.auto_ptr
|
33
|
+
##
|
34
|
+
#
|
19
35
|
api :IMG_Load, [:string], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL }
|
36
|
+
##
|
37
|
+
#
|
20
38
|
api :IMG_Load_RW, [RWops.by_ref, :int], Surface.auto_ptr
|
21
39
|
|
40
|
+
##
|
41
|
+
#
|
22
42
|
api :IMG_isICO, [RWops.by_ref], :int
|
43
|
+
##
|
44
|
+
#
|
23
45
|
api :IMG_isCUR, [RWops.by_ref], :int
|
46
|
+
##
|
47
|
+
#
|
24
48
|
api :IMG_isBMP, [RWops.by_ref], :int
|
49
|
+
##
|
50
|
+
#
|
25
51
|
api :IMG_isGIF, [RWops.by_ref], :int
|
52
|
+
##
|
53
|
+
#
|
26
54
|
api :IMG_isJPG, [RWops.by_ref], :int
|
55
|
+
##
|
56
|
+
#
|
27
57
|
api :IMG_isLBM, [RWops.by_ref], :int
|
58
|
+
##
|
59
|
+
#
|
28
60
|
api :IMG_isPCX, [RWops.by_ref], :int
|
61
|
+
##
|
62
|
+
#
|
29
63
|
api :IMG_isPNG, [RWops.by_ref], :int
|
64
|
+
##
|
65
|
+
#
|
30
66
|
api :IMG_isPNM, [RWops.by_ref], :int
|
67
|
+
##
|
68
|
+
#
|
31
69
|
api :IMG_isTIF, [RWops.by_ref], :int
|
70
|
+
##
|
71
|
+
#
|
32
72
|
api :IMG_isXCF, [RWops.by_ref], :int
|
73
|
+
##
|
74
|
+
#
|
33
75
|
api :IMG_isXPM, [RWops.by_ref], :int
|
76
|
+
##
|
77
|
+
#
|
34
78
|
api :IMG_isXV, [RWops.by_ref], :int
|
79
|
+
##
|
80
|
+
#
|
35
81
|
api :IMG_isWEBP, [RWops.by_ref], :int
|
36
82
|
|
83
|
+
##
|
84
|
+
#
|
37
85
|
api :IMG_LoadICO_RW, [RWops.by_ref], Surface.auto_ptr
|
86
|
+
##
|
87
|
+
#
|
38
88
|
api :IMG_LoadCUR_RW, [RWops.by_ref], Surface.auto_ptr
|
89
|
+
##
|
90
|
+
#
|
39
91
|
api :IMG_LoadBMP_RW, [RWops.by_ref], Surface.auto_ptr
|
92
|
+
##
|
93
|
+
#
|
40
94
|
api :IMG_LoadGIF_RW, [RWops.by_ref], Surface.auto_ptr
|
95
|
+
##
|
96
|
+
#
|
41
97
|
api :IMG_LoadJPG_RW, [RWops.by_ref], Surface.auto_ptr
|
98
|
+
##
|
99
|
+
#
|
42
100
|
api :IMG_LoadLBM_RW, [RWops.by_ref], Surface.auto_ptr
|
101
|
+
##
|
102
|
+
#
|
43
103
|
api :IMG_LoadPCX_RW, [RWops.by_ref], Surface.auto_ptr
|
104
|
+
##
|
105
|
+
#
|
44
106
|
api :IMG_LoadPNG_RW, [RWops.by_ref], Surface.auto_ptr
|
107
|
+
##
|
108
|
+
#
|
45
109
|
api :IMG_LoadPNM_RW, [RWops.by_ref], Surface.auto_ptr
|
110
|
+
##
|
111
|
+
#
|
46
112
|
api :IMG_LoadTGA_RW, [RWops.by_ref], Surface.auto_ptr
|
113
|
+
##
|
114
|
+
#
|
47
115
|
api :IMG_LoadTIF_RW, [RWops.by_ref], Surface.auto_ptr
|
116
|
+
##
|
117
|
+
#
|
48
118
|
api :IMG_LoadXCF_RW, [RWops.by_ref], Surface.auto_ptr
|
119
|
+
##
|
120
|
+
#
|
49
121
|
api :IMG_LoadXPM_RW, [RWops.by_ref], Surface.auto_ptr
|
122
|
+
##
|
123
|
+
#
|
50
124
|
api :IMG_LoadXV_RW, [RWops.by_ref], Surface.auto_ptr
|
125
|
+
##
|
126
|
+
#
|
51
127
|
api :IMG_LoadWEBP_RW, [RWops.by_ref], Surface.auto_ptr
|
52
128
|
|
129
|
+
##
|
130
|
+
#
|
53
131
|
api :IMG_ReadXPMFromArray, [:pointer], Surface.auto_ptr
|
54
132
|
|
133
|
+
##
|
134
|
+
#
|
55
135
|
api :IMG_SavePNG, [Surface.by_ref, :string], :int
|
136
|
+
##
|
137
|
+
#
|
56
138
|
api :IMG_SavePNG_RW, [Surface.by_ref, RWops.by_ref, :int], :int
|
57
139
|
|
58
140
|
end
|
data/lib/sdl2/init.rb
CHANGED
@@ -22,10 +22,14 @@ module SDL2
|
|
22
22
|
enum :init_flag, INIT.flatten_consts
|
23
23
|
|
24
24
|
|
25
|
-
|
25
|
+
##
|
26
|
+
#
|
27
|
+
api :SDL_Init, [:init_flag], :int, {error: true}
|
26
28
|
|
27
29
|
|
28
|
-
|
30
|
+
##
|
31
|
+
#
|
32
|
+
api :SDL_InitSubSystem, [:init_flag], :int, {error: true}
|
29
33
|
|
30
34
|
def init_sub_system!(flags)
|
31
35
|
error_code = init_sub_system(flags)
|
@@ -34,11 +38,17 @@ module SDL2
|
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
37
|
-
|
41
|
+
##
|
42
|
+
#
|
43
|
+
api :SDL_WasInit, [:init_flag], :uint32
|
38
44
|
|
39
45
|
boolean? :was_init, TRUE_WHEN_NOT_ZERO
|
40
46
|
|
41
|
-
|
47
|
+
##
|
48
|
+
#
|
49
|
+
api :SDL_Quit, [], :void
|
42
50
|
|
43
|
-
|
51
|
+
##
|
52
|
+
#
|
53
|
+
api :SDL_QuitSubSystem, [:init_flag], :void
|
44
54
|
end
|
data/lib/sdl2/joystick.rb
CHANGED
@@ -22,23 +22,57 @@ module SDL2
|
|
22
22
|
typedef :int32, :joystick_id
|
23
23
|
typedef :int32, :joystick_index # Dunno
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
25
|
+
##
|
26
|
+
#
|
27
|
+
api :SDL_NumJoysticks, [], :int
|
28
|
+
##
|
29
|
+
#
|
30
|
+
api :SDL_JoystickNameForIndex, [:int], :string
|
31
|
+
##
|
32
|
+
#
|
33
|
+
api :SDL_JoystickOpen, [:int], Joystick.auto_ptr
|
34
|
+
##
|
35
|
+
#
|
36
|
+
api :SDL_JoystickName, [Joystick.by_ref], :string
|
37
|
+
##
|
38
|
+
#
|
39
|
+
api :SDL_JoystickGetDeviceGUID, [:int], JoystickGUID
|
40
|
+
##
|
41
|
+
#
|
42
|
+
api :SDL_JoystickGetGUID, [Joystick.by_ref], JoystickGUID
|
43
|
+
##
|
44
|
+
#
|
45
|
+
api :SDL_JoystickGetGUIDString, [JoystickGUID.by_value, :pointer, :int], :void
|
46
|
+
##
|
47
|
+
#
|
48
|
+
api :SDL_JoystickGetGUIDFromString, [:string], JoystickGUID
|
49
|
+
##
|
50
|
+
#
|
51
|
+
api :SDL_JoystickGetAttached, [Joystick.by_ref], :bool
|
52
|
+
##
|
53
|
+
#
|
54
|
+
api :SDL_JoystickInstanceID, [Joystick.by_ref], :joystick_id
|
55
|
+
##
|
56
|
+
#
|
57
|
+
api :SDL_JoystickNumAxes, [Joystick.by_ref], :int
|
58
|
+
##
|
59
|
+
#
|
60
|
+
api :SDL_JoystickNumBalls, [Joystick.by_ref], :int
|
61
|
+
##
|
62
|
+
#
|
63
|
+
api :SDL_JoystickNumHats, [Joystick.by_ref], :int
|
64
|
+
##
|
65
|
+
#
|
66
|
+
api :SDL_JoystickNumButtons, [Joystick.by_ref], :int
|
67
|
+
##
|
68
|
+
#
|
69
|
+
api :SDL_JoystickUpdate, [], :void
|
70
|
+
##
|
71
|
+
#
|
72
|
+
api :SDL_JoystickEventState, [:int], :int
|
73
|
+
##
|
74
|
+
#
|
75
|
+
api :SDL_JoystickGetAxis, [Joystick.by_ref, :int], :int16
|
42
76
|
|
43
77
|
# Hat positions
|
44
78
|
module HAT
|
@@ -54,8 +88,16 @@ module SDL2
|
|
54
88
|
LEFTDOWN = LEFT | DOWN
|
55
89
|
end
|
56
90
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
91
|
+
##
|
92
|
+
#
|
93
|
+
api :SDL_JoystickGetHat, [Joystick.by_ref, :int], :uint8
|
94
|
+
##
|
95
|
+
#
|
96
|
+
api :SDL_JoystickGetBall, [Joystick.by_ref, :int, IntStruct.by_ref, IntStruct.by_ref], :int
|
97
|
+
##
|
98
|
+
#
|
99
|
+
api :SDL_JoystickGetButton, [Joystick.by_ref, :int], :uint8
|
100
|
+
##
|
101
|
+
#
|
102
|
+
api :SDL_JoystickClose, [Joystick.by_ref], :void
|
61
103
|
end
|
data/lib/sdl2/keyboard.rb
CHANGED
@@ -7,7 +7,9 @@ module SDL2
|
|
7
7
|
|
8
8
|
typedef :int16, :keymod
|
9
9
|
|
10
|
-
|
10
|
+
# The SDL keysym structure, used in key events.
|
11
|
+
#
|
12
|
+
# @note: If you are looking for translated character input, see the TextInputEvent.
|
11
13
|
class Keysym < Struct
|
12
14
|
layout :scancode, :int32,
|
13
15
|
:sym, :keycode,
|
@@ -18,20 +20,102 @@ module SDL2
|
|
18
20
|
member_writers *members
|
19
21
|
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
##
|
24
|
+
# Get the window which currently has keyboard focus.
|
25
|
+
# :call-seq:
|
26
|
+
# get_keyboard_focus()
|
27
|
+
# get_keyboard_focus!
|
28
|
+
api :SDL_GetKeyboardFocus, [], Window.by_ref
|
29
|
+
|
30
|
+
##
|
31
|
+
# brief Get a snapshot of the current state of the keyboard.
|
32
|
+
#
|
33
|
+
# @param numkeys if non-NULL, receives the length of the returned array.
|
34
|
+
#
|
35
|
+
# @return An array of key states.
|
36
|
+
# Indexes into this array are obtained by using ::SDL_Scancode values.
|
37
|
+
#
|
38
|
+
#
|
39
|
+
# Example: See Keyboard::get_state()
|
40
|
+
# @code
|
41
|
+
# count = FFI::MemoryPointer.new :int, 1
|
42
|
+
# state = FFI::Pointer.new :uint8, SDL2::get_keyboard_state(count)
|
43
|
+
# if state[SDL2::SCANCODE::RETURN]
|
44
|
+
# puts("<RETURN> is pressed.\n");
|
45
|
+
# end
|
46
|
+
api :SDL_GetKeyboardState, [:pointer], :pointer
|
47
|
+
|
48
|
+
|
49
|
+
##
|
50
|
+
#
|
51
|
+
api :SDL_GetModState, [], :keymod
|
52
|
+
##
|
53
|
+
#
|
54
|
+
api :SDL_SetModState, [:keymod], :void
|
55
|
+
##
|
56
|
+
#
|
57
|
+
api :SDL_GetKeyFromScancode, [:scancode], :keycode
|
58
|
+
##
|
59
|
+
#
|
60
|
+
api :SDL_GetScancodeFromKey, [:keycode], :scancode
|
61
|
+
##
|
62
|
+
#
|
63
|
+
api :SDL_GetScancodeName, [:scancode], :string
|
64
|
+
##
|
65
|
+
#
|
66
|
+
api :SDL_GetScancodeFromName, [:string], :scancode
|
67
|
+
##
|
68
|
+
#
|
69
|
+
api :SDL_GetKeyName, [:keycode], :string
|
70
|
+
##
|
71
|
+
#
|
72
|
+
api :SDL_GetKeyFromName, [:string], :keycode
|
73
|
+
##
|
74
|
+
#
|
75
|
+
api :SDL_StartTextInput, [], :void
|
76
|
+
##
|
77
|
+
#
|
78
|
+
api :SDL_IsTextInputActive, [], :bool
|
79
|
+
##
|
80
|
+
#
|
81
|
+
api :SDL_StopTextInput, [], :void
|
82
|
+
##
|
83
|
+
#
|
84
|
+
api :SDL_SetTextInputRect, [Rect.by_ref], :void
|
85
|
+
##
|
86
|
+
#
|
87
|
+
api :SDL_HasScreenKeyboardSupport, [], :bool
|
88
|
+
##
|
89
|
+
#
|
90
|
+
api :SDL_IsScreenKeyboardShown, [], :bool
|
91
|
+
|
92
|
+
module Keyboard
|
93
|
+
# Get the window which currently has keyboard focus
|
94
|
+
def self.get_focus()
|
95
|
+
SDL2::get_keyboard_focus()
|
96
|
+
end
|
97
|
+
|
98
|
+
# Get a snapshot of the current state of the keyboard.
|
99
|
+
def self.get_state()
|
100
|
+
count = FFI::MemoryPointer.new :int, 1
|
101
|
+
state = FFI::Pointer.new :uint8, SDL2::get_keyboard_state(count)
|
102
|
+
result = state.get_array_of_int(0, count.get_int(0))
|
103
|
+
count.free
|
104
|
+
state.free
|
105
|
+
return result
|
106
|
+
end
|
107
|
+
|
108
|
+
# Get the current key modifier state for the keyboard.
|
109
|
+
def self.get_mod()
|
110
|
+
SDL2::get_mod_state()
|
111
|
+
end
|
112
|
+
|
113
|
+
# Set the current key modifire state for the keyboard.
|
114
|
+
# @note This does not change the keyboard state, only the key modifier flags.
|
115
|
+
def self.set_mod(modstate)
|
116
|
+
SDL2::set_mod_state(modstate)
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
end
|
37
121
|
end
|