sdl2_ffi 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -59
  3. data/lib/sdl2.rb +52 -15
  4. data/lib/sdl2/application.rb +71 -0
  5. data/lib/sdl2/audio.rb +72 -24
  6. data/lib/sdl2/clipboard.rb +9 -3
  7. data/lib/sdl2/color.rb +8 -3
  8. data/lib/sdl2/cpuinfo.rb +30 -10
  9. data/lib/sdl2/engine.rb +52 -0
  10. data/lib/sdl2/engine/block_engine.rb +27 -0
  11. data/lib/sdl2/engine/engines.rb +46 -0
  12. data/lib/sdl2/error.rb +9 -3
  13. data/lib/sdl2/events.rb +68 -6
  14. data/lib/sdl2/gamecontroller.rb +60 -20
  15. data/lib/sdl2/gem_version.rb +1 -1
  16. data/lib/sdl2/gesture.rb +12 -4
  17. data/lib/sdl2/haptic.rb +90 -30
  18. data/lib/sdl2/hints.rb +12 -4
  19. data/lib/sdl2/image.rb +85 -3
  20. data/lib/sdl2/init.rb +15 -5
  21. data/lib/sdl2/joystick.rb +63 -21
  22. data/lib/sdl2/keyboard.rb +101 -17
  23. data/lib/sdl2/keycode.rb +72 -72
  24. data/lib/sdl2/library.rb +7 -0
  25. data/lib/sdl2/log.rb +78 -21
  26. data/lib/sdl2/mixer.rb +651 -0
  27. data/lib/sdl2/mixer/chunk.rb +47 -0
  28. data/lib/sdl2/mixer/lib_paths.rb +8 -0
  29. data/lib/sdl2/mouse.rb +39 -13
  30. data/lib/sdl2/pixels.rb +39 -13
  31. data/lib/sdl2/point.rb +29 -0
  32. data/lib/sdl2/power.rb +3 -1
  33. data/lib/sdl2/rect.rb +94 -19
  34. data/lib/sdl2/render.rb +156 -52
  35. data/lib/sdl2/rwops.rb +60 -20
  36. data/lib/sdl2/surface.rb +85 -28
  37. data/lib/sdl2/syswm.rb +3 -1
  38. data/lib/sdl2/timer.rb +18 -6
  39. data/lib/sdl2/touch.rb +12 -4
  40. data/lib/sdl2/ttf.rb +153 -59
  41. data/lib/sdl2/ttf/font.rb +21 -5
  42. data/lib/sdl2/version.rb +9 -3
  43. data/lib/sdl2/video.rb +210 -70
  44. data/lib/sdl2/window.rb +9 -3
  45. data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/draws_the_message_to_the_screen.approved.png +0 -0
  46. data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/writes_a_message_to_a_surface.approved.png +0 -0
  47. data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/defaults_to_mouse_out.approved.png +0 -0
  48. data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/has_a_button_sheet.approved.png +0 -0
  49. data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_down.approved.png +0 -0
  50. data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_in.approved.png +0 -0
  51. data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_out.approved.png +0 -0
  52. data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_up.approved.png +0 -0
  53. data/spec/fixtures/images/button_sheet.png +0 -0
  54. data/spec/functional/lazy_foo_tutorial/lazy_foo_01_hello_world_spec.rb +9 -2
  55. data/spec/functional/lazy_foo_tutorial/lazy_foo_03_extension_libraries_spec.rb +1 -0
  56. data/spec/functional/lazy_foo_tutorial/lazy_foo_04_event_driven_programming_spec.rb +4 -3
  57. data/spec/functional/lazy_foo_tutorial/lazy_foo_05_color_keying_spec.rb +1 -1
  58. data/spec/functional/lazy_foo_tutorial/lazy_foo_06_clip_blitting_and_sprite_sheets_spec.rb +4 -3
  59. data/spec/functional/lazy_foo_tutorial/lazy_foo_07_true_type_fonts_spec.rb +4 -2
  60. data/spec/functional/lazy_foo_tutorial/lazy_foo_08_key_presses_spec.rb +10 -22
  61. data/spec/functional/lazy_foo_tutorial/lazy_foo_09_mouse_events_spec.rb +121 -0
  62. data/spec/functional/lazy_foo_tutorial/lazy_foo_10_key_states_spec.rb +30 -0
  63. data/spec/functional/lazy_foo_tutorial/lazy_foo_11_playing_sounds_spec.rb +116 -0
  64. data/spec/functional/lazy_foo_tutorial/lazy_foo_12_timing_spec.rb +57 -0
  65. data/spec/spec_helper.rb +3 -1
  66. metadata +31 -2
@@ -1,4 +1,4 @@
1
1
 
2
2
  module SDL2
3
- GEM_VERSION = "0.0.5"
3
+ GEM_VERSION = "0.0.6"
4
4
  end
data/lib/sdl2/gesture.rb CHANGED
@@ -7,9 +7,17 @@ module SDL2
7
7
 
8
8
  typedef :int64, :gesture_id
9
9
 
10
- api :SDL_RecordGesture, [:touch_id], :int
11
- api :SDL_SaveAllDollarTemplates, [RWops.by_ref], :int
12
- api :SDL_SaveDollarTemplate, [:gesture_id, RWops.by_ref], :int
13
- api :SDL_LoadDollarTemplates, [:touch_id, RWops.by_ref], :int
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
- api :SDL_NumHaptics, [], :int
440
- api :SDL_HapticName, [:int], :string
441
- api :SDL_HapticOpen, [:int], Haptic.auto_ptr
442
- api :SDL_HapticOpened, [:int], :int
443
- api :SDL_HapticIndex, [Haptic.by_ref], :int
444
- api :SDL_MouseIsHaptic, [], :int
445
- api :SDL_HapticOpenFromMouse, [], Haptic.auto_ptr
446
- api :SDL_JoystickIsHaptic, [Joystick.by_ref], :int
447
- api :SDL_HapticOpenFromJoystick, [Joystick.by_ref], Haptic.auto_ptr
448
- api :SDL_HapticClose, [Haptic.by_ref], :void
449
- api :SDL_HapticNumEffects, [Haptic.by_ref], :int
450
- api :SDL_HapticNumEffectsPlaying, [Haptic.by_ref], :int
451
- api :SDL_HapticQuery, [Haptic.by_ref], :int
452
- api :SDL_HapticNumAxes, [Haptic.by_ref], :int
453
- api :SDL_HapticEffectSupported, [Haptic.by_ref, Haptic::Effect.by_ref], :int
454
- api :SDL_HapticNewEffect, [Haptic.by_ref, Haptic::Effect.by_ref], :int
455
- api :SDL_HapticUpdateEffect, [Haptic.by_ref, :int, Haptic::Effect.by_ref], :int
456
- api :SDL_HapticRunEffect, [Haptic.by_ref, :int, :uint32], :int
457
- api :SDL_HapticStopEffect, [Haptic.by_ref, :int], :int
458
- api :SDL_HapticDestroyEffect, [Haptic.by_ref, :int], :int
459
- api :SDL_HapticGetEffectStatus, [Haptic.by_ref, :int], :int
460
- api :SDL_HapticSetGain, [Haptic.by_ref, :int], :int
461
- api :SDL_HapticSetAutocenter, [Haptic.by_ref, :int], :int
462
- api :SDL_HapticPause, [Haptic.by_ref], :int
463
- api :SDL_HapticUnpause, [Haptic.by_ref], :int
464
- api :SDL_HapticStopAll, [Haptic.by_ref], :int
465
- api :SDL_HapticRumbleSupported, [Haptic.by_ref], :int
466
- api :SDL_HapticRumbleInit, [Haptic.by_ref], :int
467
- api :SDL_HapticRumblePlay, [Haptic.by_ref], :int
468
- api :SDL_HapticRumbleStop, [Haptic.by_ref], :int
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
- api :SDL_ClearHints, [], :void
55
- api :SDL_GetHint, [:string], :string
56
- api :SDL_SetHint, [:string, :string], :bool, {error: true}
57
- api :SDL_SetHintWithPriority, [:string, :string, :hint_priority], :bool
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
- enum :init_flags, [:JPG, :PNG, :TIF, :WEBP]
15
-
16
- api :IMG_Init, [:init_flags], :int
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
- api :SDL_Init, [:init_flag], :int, {error: true}
25
+ ##
26
+ #
27
+ api :SDL_Init, [:init_flag], :int, {error: true}
26
28
 
27
29
 
28
- api :SDL_InitSubSystem, [:init_flag], :int, {error: true}
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
- api :SDL_WasInit, [:init_flag], :uint32
41
+ ##
42
+ #
43
+ api :SDL_WasInit, [:init_flag], :uint32
38
44
 
39
45
  boolean? :was_init, TRUE_WHEN_NOT_ZERO
40
46
 
41
- api :SDL_Quit, [], :void
47
+ ##
48
+ #
49
+ api :SDL_Quit, [], :void
42
50
 
43
- api :SDL_QuitSubSystem, [:init_flag], :void
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
- api :SDL_NumJoysticks, [], :int
26
- api :SDL_JoystickNameForIndex, [:int], :string
27
- api :SDL_JoystickOpen, [:int], Joystick.auto_ptr
28
- api :SDL_JoystickName, [Joystick.by_ref], :string
29
- api :SDL_JoystickGetDeviceGUID, [:int], JoystickGUID
30
- api :SDL_JoystickGetGUID, [Joystick.by_ref], JoystickGUID
31
- api :SDL_JoystickGetGUIDString, [JoystickGUID.by_value, :pointer, :int], :void
32
- api :SDL_JoystickGetGUIDFromString, [:string], JoystickGUID
33
- api :SDL_JoystickGetAttached, [Joystick.by_ref], :bool
34
- api :SDL_JoystickInstanceID, [Joystick.by_ref], :joystick_id
35
- api :SDL_JoystickNumAxes, [Joystick.by_ref], :int
36
- api :SDL_JoystickNumBalls, [Joystick.by_ref], :int
37
- api :SDL_JoystickNumHats, [Joystick.by_ref], :int
38
- api :SDL_JoystickNumButtons, [Joystick.by_ref], :int
39
- api :SDL_JoystickUpdate, [], :void
40
- api :SDL_JoystickEventState, [:int], :int
41
- api :SDL_JoystickGetAxis, [Joystick.by_ref, :int], :int16
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
- api :SDL_JoystickGetHat, [Joystick.by_ref, :int], :uint8
58
- api :SDL_JoystickGetBall, [Joystick.by_ref, :int, IntStruct.by_ref, IntStruct.by_ref], :int
59
- api :SDL_JoystickGetButton, [Joystick.by_ref, :int], :uint8
60
- api :SDL_JoystickClose, [Joystick.by_ref], :void
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
- api :SDL_GetKeyboardFocus, [], Window.by_ref
22
- api :SDL_GetKeyboardState, [:count], UInt8Struct.by_ref
23
- api :SDL_GetModState, [], :keymod
24
- api :SDL_SetModState, [:keymod], :void
25
- api :SDL_GetKeyFromScancode, [:scancode], :keycode
26
- api :SDL_GetScancodeFromKey, [:keycode], :scancode
27
- api :SDL_GetScancodeName, [:scancode], :string
28
- api :SDL_GetScancodeFromName, [:string], :scancode
29
- api :SDL_GetKeyName, [:keycode], :string
30
- api :SDL_GetKeyFromName, [:string], :keycode
31
- api :SDL_StartTextInput, [], :void
32
- api :SDL_IsTextInputActive, [], :bool
33
- api :SDL_StopTextInput, [], :void
34
- api :SDL_SetTextInputRect, [Rect.by_ref], :void
35
- api :SDL_HasScreenKeyboardSupport, [], :bool
36
- api :SDL_IsScreenKeyboardShown, [], :bool
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