sdl2_ffi 0.0.2

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 (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +33 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +83 -0
  9. data/Rakefile +7 -0
  10. data/bin/coderay +16 -0
  11. data/bin/guard +16 -0
  12. data/bin/pry +16 -0
  13. data/bin/rake +16 -0
  14. data/bin/thor +16 -0
  15. data/lib/sdl2/assert.rb +7 -0
  16. data/lib/sdl2/audio.rb +139 -0
  17. data/lib/sdl2/clipboard.rb +27 -0
  18. data/lib/sdl2/color.rb +12 -0
  19. data/lib/sdl2/cpuinfo.rb +18 -0
  20. data/lib/sdl2/display/mode.rb +53 -0
  21. data/lib/sdl2/display/modes.rb +36 -0
  22. data/lib/sdl2/display.rb +74 -0
  23. data/lib/sdl2/error.rb +9 -0
  24. data/lib/sdl2/events.rb +358 -0
  25. data/lib/sdl2/gamecontroller.rb +62 -0
  26. data/lib/sdl2/gem_version.rb +4 -0
  27. data/lib/sdl2/gesture.rb +15 -0
  28. data/lib/sdl2/haptic.rb +159 -0
  29. data/lib/sdl2/hints.rb +47 -0
  30. data/lib/sdl2/init.rb +54 -0
  31. data/lib/sdl2/joystick.rb +58 -0
  32. data/lib/sdl2/keyboard.rb +34 -0
  33. data/lib/sdl2/keycode.rb +294 -0
  34. data/lib/sdl2/log.rb +70 -0
  35. data/lib/sdl2/mouse.rb +54 -0
  36. data/lib/sdl2/palette.rb +15 -0
  37. data/lib/sdl2/pixel_format.rb +28 -0
  38. data/lib/sdl2/pixels.rb +35 -0
  39. data/lib/sdl2/point.rb +7 -0
  40. data/lib/sdl2/power.rb +9 -0
  41. data/lib/sdl2/rect.rb +38 -0
  42. data/lib/sdl2/render.rb +77 -0
  43. data/lib/sdl2/renderer.rb +34 -0
  44. data/lib/sdl2/renderer_info.rb +13 -0
  45. data/lib/sdl2/rwops.rb +127 -0
  46. data/lib/sdl2/scancode.rb +275 -0
  47. data/lib/sdl2/sdl_module.rb +8 -0
  48. data/lib/sdl2/surface.rb +83 -0
  49. data/lib/sdl2/syswm/info.rb +49 -0
  50. data/lib/sdl2/syswm/msg.rb +46 -0
  51. data/lib/sdl2/syswm.rb +20 -0
  52. data/lib/sdl2/texture.rb +9 -0
  53. data/lib/sdl2/timer.rb +17 -0
  54. data/lib/sdl2/touch.rb +24 -0
  55. data/lib/sdl2/version.rb +30 -0
  56. data/lib/sdl2/video.rb +154 -0
  57. data/lib/sdl2/window.rb +259 -0
  58. data/lib/sdl2.rb +99 -0
  59. data/lib/sdl2_ffi.rb +6 -0
  60. data/sdl2_ffi.gemspec +31 -0
  61. data/test/test_helper.rb +2 -0
  62. data/test/unit/sdl2/test_assert.rb +10 -0
  63. data/test/unit/sdl2/test_audio.rb +9 -0
  64. data/test/unit/sdl2/test_clipboard.rb +13 -0
  65. data/test/unit/sdl2/test_cpuinfo.rb +11 -0
  66. data/test/unit/sdl2/test_error.rb +20 -0
  67. data/test/unit/sdl2/test_events.rb +31 -0
  68. data/test/unit/sdl2/test_haptic.rb +10 -0
  69. data/test/unit/sdl2/test_hints.rb +50 -0
  70. data/test/unit/sdl2/test_init.rb +29 -0
  71. data/test/unit/sdl2/test_keyboard.rb +9 -0
  72. data/test/unit/sdl2/test_log.rb +80 -0
  73. data/test/unit/sdl2/test_pixels.rb +24 -0
  74. data/test/unit/sdl2/test_power.rb +11 -0
  75. data/test/unit/sdl2/test_rect.rb +19 -0
  76. data/test/unit/sdl2/test_render.rb +58 -0
  77. data/test/unit/sdl2/test_surface.rb +45 -0
  78. data/test/unit/sdl2/test_syswm.rb +11 -0
  79. data/test/unit/sdl2/test_timer.rb +9 -0
  80. data/test/unit/sdl2/test_version.rb +16 -0
  81. data/test/unit/sdl2/test_video.rb +170 -0
  82. data/test/unit/sdl2/test_window.rb +158 -0
  83. data/test/unit/test_sdl2.rb +16 -0
  84. metadata +280 -0
@@ -0,0 +1,58 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+
5
+ class Joystick < Struct
6
+
7
+ # TODO: Review if the Joystick layout should be hidden.
8
+ layout :hidden, :uint8
9
+
10
+ def self.release(pointer)
11
+ SDL2.joystick_close(pointer)
12
+ end
13
+
14
+ end
15
+
16
+ class JoystickGUID < Struct
17
+ layout :data, [:uint8, 16] #line 69
18
+ end
19
+
20
+ typedef :int32, :joystick_id
21
+ typedef :int32, :joystick_index # Dunno
22
+
23
+ api :SDL_NumJoysticks, [], :int
24
+ api :SDL_JoystickNameForIndex, [:int], :string
25
+ api :SDL_JoystickOpen, [:int], Joystick.auto_ptr
26
+ api :SDL_JoystickName, [Joystick.by_ref], :string
27
+ api :SDL_JoystickGetDeviceGUID, [:int], JoystickGUID
28
+ api :SDL_JoystickGetGUID, [Joystick.by_ref], JoystickGUID
29
+ api :SDL_JoystickGetGUIDString, [JoystickGUID, :pointer, :int], :void
30
+ api :SDL_JoystickGetGUIDFromString, [:string], JoystickGUID
31
+ api :SDL_JoystickGetAttached, [Joystick.by_ref], :bool
32
+ api :SDL_JoystickInstanceID, [Joystick.by_ref], :joystick_id
33
+ api :SDL_JoystickNumAxes, [Joystick.by_ref], :int
34
+ api :SDL_JoystickNumBalls, [Joystick.by_ref], :int
35
+ api :SDL_JoystickNumHats, [Joystick.by_ref], :int
36
+ api :SDL_JoystickNumButtons, [Joystick.by_ref], :int
37
+ api :SDL_JoystickUpdate, [], :void
38
+ api :SDL_JoystickEventState, [:int], :int
39
+ api :SDL_JoystickGetAxis, [Joystick.by_ref, :int], :int16
40
+
41
+ HAT_HASH = {
42
+ :CENTERED => 0x00,
43
+ :UP => 0x01,
44
+ :RIGHT => 0x02,
45
+ :DOWN => 0x04,
46
+ :LEFT => 0x08
47
+ }
48
+ HAT_HASH[:RIGHTUP]=(HAT_HASH[:RIGHT]|HAT_HASH[:UP])
49
+ HAT_HASH[:RIGHTDOWN]= (HAT_HASH[:RIGHT]|HAT_HASH[:DOWN])
50
+ HAT_HASH[:LEFTUP]= (HAT_HASH[:LEFT]|HAT_HASH[:UP])
51
+ HAT_HASH[:LEFTDOWN]= (HAT_HASH[:LEFT]|HAT_HASH[:DOWN])
52
+ Hat = Enum.new(:JOYSTICK_HAT, HAT_HASH)
53
+
54
+ api :SDL_JoystickGetHat, [Joystick.by_ref, :int], :uint8
55
+ api :SDL_JoystickGetBall, [Joystick.by_ref, :int, IntStruct.by_ref, IntStruct.by_ref], :int
56
+ api :SDL_JoystickGetButton, [Joystick.by_ref, :int], :uint8
57
+ api :SDL_JoystickClose, [Joystick.by_ref], :void
58
+ end
@@ -0,0 +1,34 @@
1
+ require 'sdl2'
2
+ require 'sdl2/error'
3
+ require 'sdl2/keycode'
4
+ require 'sdl2/video'
5
+
6
+ module SDL2
7
+
8
+ typedef :int16, :keymod
9
+
10
+
11
+ class Keysym < Struct
12
+ layout :scancode, :int32,
13
+ :sym, :keycode,
14
+ :mod, :uint16,
15
+ :unused, :uint32
16
+ end
17
+
18
+ api :SDL_GetKeyboardFocus, [], Window.by_ref
19
+ api :SDL_GetKeyboardState, [:count], UInt8Struct.by_ref
20
+ api :SDL_GetModState, [], :keymod
21
+ api :SDL_SetModState, [:keymod], :void
22
+ api :SDL_GetKeyFromScancode, [:scancode], :keycode
23
+ api :SDL_GetScancodeFromKey, [:keycode], :scancode
24
+ api :SDL_GetScancodeName, [:scancode], :string
25
+ api :SDL_GetScancodeFromName, [:string], :scancode
26
+ api :SDL_GetKeyName, [:keycode], :string
27
+ api :SDL_GetKeyFromName, [:string], :keycode
28
+ api :SDL_StartTextInput, [], :void
29
+ api :SDL_IsTextInputActive, [], :bool
30
+ api :SDL_StopTextInput, [], :void
31
+ api :SDL_SetTextInputRect, [Rect.by_ref], :void
32
+ api :SDL_HasScreenKeyboardSupport, [], :bool
33
+ api :SDL_IsScreenKeyboardShown, [], :bool
34
+ end
@@ -0,0 +1,294 @@
1
+ require 'sdl2'
2
+ require 'sdl2/scancode'
3
+ require 'yinum'
4
+
5
+ module SDL2
6
+
7
+ typedef :int32, :keycode
8
+ typedef :int32, :scancode
9
+
10
+ # TODO: Review if I translated lines 44~45 right.
11
+ SCANCODE_MASK = 1<<30
12
+
13
+ def self.scancode_to_keycode(scancode)
14
+ scancode | SCANCODE_MASK
15
+ end
16
+
17
+ Keycode = Enum.new(:KEYCODE, {
18
+ :UNKNOWN => 0,
19
+
20
+ :RETURN => '\r',
21
+ :ESCAPE => '\033',
22
+ :BACKSPACE => '\b',
23
+ :TAB => '\t',
24
+ :SPACE => ' ',
25
+ :EXCLAIM => '!',
26
+ :QUOTEDBL => '"',
27
+ :HASH => '#',
28
+ :PERCENT => '%',
29
+ :DOLLAR => '$',
30
+ :AMPERSAND => '&',
31
+ :QUOTE => '\'',
32
+ :LEFTPAREN => '(',
33
+ :RIGHTPAREN => ')',
34
+ :ASTERISK => '*',
35
+ :PLUS => '+',
36
+ :COMMA => ',',
37
+ :MINUS => '-',
38
+ :PERIOD => '.',
39
+ :SLASH => '/',
40
+ :'0' => '0',
41
+ :'1' => '1',
42
+ :'2' => '2',
43
+ :'3' => '3',
44
+ :'4' => '4',
45
+ :'5' => '5',
46
+ :'6' => '6',
47
+ :'7' => '7',
48
+ :'8' => '8',
49
+ :'9' => '9',
50
+ :COLON => ':',
51
+ :SEMICOLON => ';',
52
+ :LESS => '<',
53
+ :EQUALS => '=',
54
+ :GREATER => '>',
55
+ :QUESTION => '?',
56
+ :AT => '@',
57
+
58
+ :LEFTBRACKET => '[',
59
+ :BACKSLASH => '\\',
60
+ :RIGHTBRACKET => ']',
61
+ :CARET => '^',
62
+ :UNDERSCORE => '_',
63
+ :BACKQUOTE => '`',
64
+ :a => 'a',
65
+ :b => 'b',
66
+ :c => 'c',
67
+ :d => 'd',
68
+ :e => 'e',
69
+ :f => 'f',
70
+ :g => 'g',
71
+ :h => 'h',
72
+ :i => 'i',
73
+ :j => 'j',
74
+ :k => 'k',
75
+ :l => 'l',
76
+ :m => 'm',
77
+ :n => 'n',
78
+ :o => 'o',
79
+ :p => 'p',
80
+ :q => 'q',
81
+ :r => 'r',
82
+ :s => 's',
83
+ :t => 't',
84
+ :u => 'u',
85
+ :v => 'v',
86
+ :w => 'w',
87
+ :x => 'x',
88
+ :y => 'y',
89
+ :z => 'z',
90
+
91
+ :CAPSLOCK => scancode_to_keycode(Scancode.CAPSLOCK),
92
+
93
+ :F1 => scancode_to_keycode(Scancode.F1),
94
+ :F2 => scancode_to_keycode(Scancode.F2),
95
+ :F3 => scancode_to_keycode(Scancode.F3),
96
+ :F4 => scancode_to_keycode(Scancode.F4),
97
+ :F5 => scancode_to_keycode(Scancode.F5),
98
+ :F6 => scancode_to_keycode(Scancode.F6),
99
+ :F7 => scancode_to_keycode(Scancode.F7),
100
+ :F8 => scancode_to_keycode(Scancode.F8),
101
+ :F9 => scancode_to_keycode(Scancode.F9),
102
+ :F10 => scancode_to_keycode(Scancode.F10),
103
+ :F11 => scancode_to_keycode(Scancode.F11),
104
+ :F12 => scancode_to_keycode(Scancode.F12),
105
+
106
+ :PRINTSCREEN => scancode_to_keycode(Scancode.PRINTSCREEN),
107
+ :SCROLLLOCK => scancode_to_keycode(Scancode.SCROLLLOCK),
108
+ :PAUSE => scancode_to_keycode(Scancode.PAUSE),
109
+ :INSERT => scancode_to_keycode(Scancode.INSERT),
110
+ :HOME => scancode_to_keycode(Scancode.HOME),
111
+ :PAGEUP => scancode_to_keycode(Scancode.PAGEUP),
112
+ :DELETE => '\177',
113
+ :END => scancode_to_keycode(Scancode.END),
114
+ :PAGEDOWN => scancode_to_keycode(Scancode.PAGEDOWN),
115
+ :RIGHT => scancode_to_keycode(Scancode.RIGHT),
116
+ :LEFT => scancode_to_keycode(Scancode.LEFT),
117
+ :DOWN => scancode_to_keycode(Scancode.DOWN),
118
+ :UP => scancode_to_keycode(Scancode.UP),
119
+
120
+ :NUMLOCKCLEAR => scancode_to_keycode(Scancode.NUMLOCKCLEAR),
121
+ :KP_DIVIDE => scancode_to_keycode(Scancode.KP_DIVIDE),
122
+ :KP_MULTIPLY => scancode_to_keycode(Scancode.KP_MULTIPLY),
123
+ :KP_MINUS => scancode_to_keycode(Scancode.KP_MINUS),
124
+ :KP_PLUS => scancode_to_keycode(Scancode.KP_PLUS),
125
+ :KP_ENTER => scancode_to_keycode(Scancode.KP_ENTER),
126
+ :KP_1 => scancode_to_keycode(Scancode.KP_1),
127
+ :KP_2 => scancode_to_keycode(Scancode.KP_2),
128
+ :KP_3 => scancode_to_keycode(Scancode.KP_3),
129
+ :KP_4 => scancode_to_keycode(Scancode.KP_4),
130
+ :KP_5 => scancode_to_keycode(Scancode.KP_5),
131
+ :KP_6 => scancode_to_keycode(Scancode.KP_6),
132
+ :KP_7 => scancode_to_keycode(Scancode.KP_7),
133
+ :KP_8 => scancode_to_keycode(Scancode.KP_8),
134
+ :KP_9 => scancode_to_keycode(Scancode.KP_9),
135
+ :KP_0 => scancode_to_keycode(Scancode.KP_0),
136
+ :KP_PERIOD => scancode_to_keycode(Scancode.KP_PERIOD),
137
+
138
+ :APPLICATION => scancode_to_keycode(Scancode.APPLICATION),
139
+ :POWER => scancode_to_keycode(Scancode.POWER),
140
+ :KP_EQUALS => scancode_to_keycode(Scancode.KP_EQUALS),
141
+ :F13 => scancode_to_keycode(Scancode.F13),
142
+ :F14 => scancode_to_keycode(Scancode.F14),
143
+ :F15 => scancode_to_keycode(Scancode.F15),
144
+ :F16 => scancode_to_keycode(Scancode.F16),
145
+ :F17 => scancode_to_keycode(Scancode.F17),
146
+ :F18 => scancode_to_keycode(Scancode.F18),
147
+ :F19 => scancode_to_keycode(Scancode.F19),
148
+ :F20 => scancode_to_keycode(Scancode.F20),
149
+ :F21 => scancode_to_keycode(Scancode.F21),
150
+ :F22 => scancode_to_keycode(Scancode.F22),
151
+ :F23 => scancode_to_keycode(Scancode.F23),
152
+ :F24 => scancode_to_keycode(Scancode.F24),
153
+ :EXECUTE => scancode_to_keycode(Scancode.EXECUTE),
154
+ :HELP => scancode_to_keycode(Scancode.HELP),
155
+ :MENU => scancode_to_keycode(Scancode.MENU),
156
+ :SELECT => scancode_to_keycode(Scancode.SELECT),
157
+ :STOP => scancode_to_keycode(Scancode.STOP),
158
+ :AGAIN => scancode_to_keycode(Scancode.AGAIN),
159
+ :UNDO => scancode_to_keycode(Scancode.UNDO),
160
+ :CUT => scancode_to_keycode(Scancode.CUT),
161
+ :COPY => scancode_to_keycode(Scancode.COPY),
162
+ :PASTE => scancode_to_keycode(Scancode.PASTE),
163
+ :FIND => scancode_to_keycode(Scancode.FIND),
164
+ :MUTE => scancode_to_keycode(Scancode.MUTE),
165
+ :VOLUMEUP => scancode_to_keycode(Scancode.VOLUMEUP),
166
+ :VOLUMEDOWN => scancode_to_keycode(Scancode.VOLUMEDOWN),
167
+ :KP_COMMA => scancode_to_keycode(Scancode.KP_COMMA),
168
+ :KP_EQUALSAS400 => scancode_to_keycode(Scancode.KP_EQUALSAS400),
169
+
170
+ :ALTERASE => scancode_to_keycode(Scancode.ALTERASE),
171
+ :SYSREQ => scancode_to_keycode(Scancode.SYSREQ),
172
+ :CANCEL => scancode_to_keycode(Scancode.CANCEL),
173
+ :CLEAR => scancode_to_keycode(Scancode.CLEAR),
174
+ :PRIOR => scancode_to_keycode(Scancode.PRIOR),
175
+ :RETURN2 => scancode_to_keycode(Scancode.RETURN2),
176
+ :SEPARATOR => scancode_to_keycode(Scancode.SEPARATOR),
177
+ :OUT => scancode_to_keycode(Scancode.OUT),
178
+ :OPER => scancode_to_keycode(Scancode.OPER),
179
+ :CLEARAGAIN => scancode_to_keycode(Scancode.CLEARAGAIN),
180
+ :CRSEL => scancode_to_keycode(Scancode.CRSEL),
181
+ :EXSEL => scancode_to_keycode(Scancode.EXSEL),
182
+
183
+ :KP_00 => scancode_to_keycode(Scancode.KP_00),
184
+ :KP_000 => scancode_to_keycode(Scancode.KP_000),
185
+ :THOUSANDSSEPARATOR => scancode_to_keycode(Scancode.THOUSANDSSEPARATOR),
186
+ :DECIMALSEPARATOR => scancode_to_keycode(Scancode.DECIMALSEPARATOR),
187
+ :CURRENCYUNIT => scancode_to_keycode(Scancode.CURRENCYUNIT),
188
+ :CURRENCYSUBUNIT => scancode_to_keycode(Scancode.CURRENCYSUBUNIT),
189
+ :KP_LEFTPAREN => scancode_to_keycode(Scancode.KP_LEFTPAREN),
190
+ :KP_RIGHTPAREN => scancode_to_keycode(Scancode.KP_RIGHTPAREN),
191
+ :KP_LEFTBRACE => scancode_to_keycode(Scancode.KP_LEFTBRACE),
192
+ :KP_RIGHTBRACE => scancode_to_keycode(Scancode.KP_RIGHTBRACE),
193
+ :KP_TAB => scancode_to_keycode(Scancode.KP_TAB),
194
+ :KP_BACKSPACE => scancode_to_keycode(Scancode.KP_BACKSPACE),
195
+ :KP_A => scancode_to_keycode(Scancode.KP_A),
196
+ :KP_B => scancode_to_keycode(Scancode.KP_B),
197
+ :KP_C => scancode_to_keycode(Scancode.KP_C),
198
+ :KP_D => scancode_to_keycode(Scancode.KP_D),
199
+ :KP_E => scancode_to_keycode(Scancode.KP_E),
200
+ :KP_F => scancode_to_keycode(Scancode.KP_F),
201
+ :KP_XOR => scancode_to_keycode(Scancode.KP_XOR),
202
+ :KP_POWER => scancode_to_keycode(Scancode.KP_POWER),
203
+ :KP_PERCENT => scancode_to_keycode(Scancode.KP_PERCENT),
204
+ :KP_LESS => scancode_to_keycode(Scancode.KP_LESS),
205
+ :KP_GREATER => scancode_to_keycode(Scancode.KP_GREATER),
206
+ :KP_AMPERSAND => scancode_to_keycode(Scancode.KP_AMPERSAND),
207
+ :KP_DBLAMPERSAND => scancode_to_keycode(Scancode.KP_DBLAMPERSAND),
208
+ :KP_VERTICALBAR => scancode_to_keycode(Scancode.KP_VERTICALBAR),
209
+ :KP_DBLVERTICALBAR => scancode_to_keycode(Scancode.KP_DBLVERTICALBAR),
210
+ :KP_COLON => scancode_to_keycode(Scancode.KP_COLON),
211
+ :KP_HASH => scancode_to_keycode(Scancode.KP_HASH),
212
+ :KP_SPACE => scancode_to_keycode(Scancode.KP_SPACE),
213
+ :KP_AT => scancode_to_keycode(Scancode.KP_AT),
214
+ :KP_EXCLAM => scancode_to_keycode(Scancode.KP_EXCLAM),
215
+ :KP_MEMSTORE => scancode_to_keycode(Scancode.KP_MEMSTORE),
216
+ :KP_MEMRECALL => scancode_to_keycode(Scancode.KP_MEMRECALL),
217
+ :KP_MEMCLEAR => scancode_to_keycode(Scancode.KP_MEMCLEAR),
218
+ :KP_MEMADD => scancode_to_keycode(Scancode.KP_MEMADD),
219
+ :KP_MEMSUBTRACT => scancode_to_keycode(Scancode.KP_MEMSUBTRACT),
220
+ :KP_MEMMULTIPLY => scancode_to_keycode(Scancode.KP_MEMMULTIPLY),
221
+ :KP_MEMDIVIDE => scancode_to_keycode(Scancode.KP_MEMDIVIDE),
222
+ :KP_PLUSMINUS => scancode_to_keycode(Scancode.KP_PLUSMINUS),
223
+ :KP_CLEAR => scancode_to_keycode(Scancode.KP_CLEAR),
224
+ :KP_CLEARENTRY => scancode_to_keycode(Scancode.KP_CLEARENTRY),
225
+ :KP_BINARY => scancode_to_keycode(Scancode.KP_BINARY),
226
+ :KP_OCTAL => scancode_to_keycode(Scancode.KP_OCTAL),
227
+ :KP_DECIMAL => scancode_to_keycode(Scancode.KP_DECIMAL),
228
+ :KP_HEXADECIMAL => scancode_to_keycode(Scancode.KP_HEXADECIMAL),
229
+
230
+ :LCTRL => scancode_to_keycode(Scancode.LCTRL),
231
+ :LSHIFT => scancode_to_keycode(Scancode.LSHIFT),
232
+ :LALT => scancode_to_keycode(Scancode.LALT),
233
+ :LGUI => scancode_to_keycode(Scancode.LGUI),
234
+ :RCTRL => scancode_to_keycode(Scancode.RCTRL),
235
+ :RSHIFT => scancode_to_keycode(Scancode.RSHIFT),
236
+ :RALT => scancode_to_keycode(Scancode.RALT),
237
+ :RGUI => scancode_to_keycode(Scancode.RGUI),
238
+
239
+ :MODE => scancode_to_keycode(Scancode.MODE),
240
+
241
+ :AUDIONEXT => scancode_to_keycode(Scancode.AUDIONEXT),
242
+ :AUDIOPREV => scancode_to_keycode(Scancode.AUDIOPREV),
243
+ :AUDIOSTOP => scancode_to_keycode(Scancode.AUDIOSTOP),
244
+ :AUDIOPLAY => scancode_to_keycode(Scancode.AUDIOPLAY),
245
+ :AUDIOMUTE => scancode_to_keycode(Scancode.AUDIOMUTE),
246
+ :MEDIASELECT => scancode_to_keycode(Scancode.MEDIASELECT),
247
+ :WWW => scancode_to_keycode(Scancode.WWW),
248
+ :MAIL => scancode_to_keycode(Scancode.MAIL),
249
+ :CALCULATOR => scancode_to_keycode(Scancode.CALCULATOR),
250
+ :COMPUTER => scancode_to_keycode(Scancode.COMPUTER),
251
+ :AC_SEARCH => scancode_to_keycode(Scancode.AC_SEARCH),
252
+ :AC_HOME => scancode_to_keycode(Scancode.AC_HOME),
253
+ :AC_BACK => scancode_to_keycode(Scancode.AC_BACK),
254
+ :AC_FORWARD => scancode_to_keycode(Scancode.AC_FORWARD),
255
+ :AC_STOP => scancode_to_keycode(Scancode.AC_STOP),
256
+ :AC_REFRESH => scancode_to_keycode(Scancode.AC_REFRESH),
257
+ :AC_BOOKMARKS => scancode_to_keycode(Scancode.AC_BOOKMARKS),
258
+
259
+ :BRIGHTNESSDOWN => scancode_to_keycode(Scancode.BRIGHTNESSDOWN),
260
+ :BRIGHTNESSUP => scancode_to_keycode(Scancode.BRIGHTNESSUP),
261
+ :DISPLAYSWITCH => scancode_to_keycode(Scancode.DISPLAYSWITCH),
262
+ :KBDILLUMTOGGLE => scancode_to_keycode(Scancode.KBDILLUMTOGGLE),
263
+ :KBDILLUMDOWN => scancode_to_keycode(Scancode.KBDILLUMDOWN),
264
+ :KBDILLUMUP => scancode_to_keycode(Scancode.KBDILLUMUP),
265
+ :EJECT => scancode_to_keycode(Scancode.EJECT),
266
+ :SLEEP => scancode_to_keycode(Scancode.SLEEP)
267
+ })
268
+
269
+ enum :keycode, Keycode.by_name
270
+
271
+ KEYMOD_HASH = {
272
+ :NONE => 0x0000,
273
+ :LSHIFT => 0x0001,
274
+ :RSHIFT => 0x0002,
275
+ :LCTRL => 0x0040,
276
+ :RCTRL => 0x0080,
277
+ :LALT => 0x0100,
278
+ :RALT => 0x0200,
279
+ :LGUI => 0x0400,
280
+ :RGUI => 0x0800,
281
+ :NUM => 0x1000,
282
+ :CAPS => 0x2000,
283
+ :MODE => 0x4000,
284
+ :RESERVED => 0x8000
285
+ }
286
+ KEYMOD_HASH[:CTRL] = KEYMOD_HASH[:LCTRL]|KEYMOD_HASH[:RCTRL]
287
+ KEYMOD_HASH[:SHIFT] = KEYMOD_HASH[:LSHIFT]|KEYMOD_HASH[:RSHIFT]
288
+ KEYMOD_HASH[:ALT] = KEYMOD_HASH[:LALT]|KEYMOD_HASH[:RALT]
289
+ KEYMOD_HASH[:GUI] = KEYMOD_HASH[:LGUI]|KEYMOD_HASH[:RGUI]
290
+
291
+ Keymod = Enum.new( :KEYMOD, KEYMOD_HASH)
292
+
293
+
294
+ end
data/lib/sdl2/log.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+
5
+ class Log
6
+ private_class_method :new # Disable creation
7
+
8
+ def self.<<(msg, *args)
9
+ SDL2.log(msg, *args)
10
+ end
11
+
12
+ def self.critical(category, msg, *args)
13
+ SDL2.log_critical(category, msg, *args)
14
+ end
15
+
16
+ def self.debug(category, msg, *args)
17
+ SDL2.log_debug(category, msg, *args)
18
+ end
19
+
20
+ def self.error(category, msg, *args)
21
+ SDL2.log_error(category, msg, *args)
22
+ end
23
+
24
+ def self.warn(category, msg, *args)
25
+ SDL2.log_warn(category, msg, *args)
26
+ end
27
+
28
+ def self.verbose(category, msg, *args)
29
+ SDL2.log_verbose(category, msg, *args)
30
+ end
31
+
32
+ def self.set_priority(category, priority)
33
+ SDL2.log_set_priority(category, priority)
34
+ end
35
+
36
+ def self.get_priority(category)
37
+ SDL2.log_get_priority(category)
38
+ end
39
+ end
40
+
41
+ enum :log_priority, [:verbose, 1, :debug, :info, :warn, :error, :critical]
42
+
43
+ enum :log_category, [
44
+ :application, :error, :assert, :system, :audio, :video, :render, :input, :test,
45
+ :reserved1,:reserved2,:reserved3,:reserved4,:reserved5,
46
+ :reserved6,:reserved7,:reserved8,:reserved9,:reserved10,
47
+ :custom
48
+ ]
49
+
50
+
51
+
52
+ callback :log_output_function, [:pointer, :log_category, :log_priority, :string], :void
53
+
54
+ api :SDL_Log, [:string, :varargs], :void
55
+ api :SDL_LogCritical, [:log_category, :string, :varargs], :void
56
+ api :SDL_LogDebug, [:log_category, :string, :varargs], :void
57
+ api :SDL_LogError, [:log_category, :string, :varargs], :void
58
+ api :SDL_LogInfo, [:log_category, :string, :varargs], :void
59
+ api :SDL_LogVerbose, [:log_category, :string, :varargs], :void
60
+ api :SDL_LogWarn, [:log_category, :string, :varargs], :void
61
+ api :SDL_LogMessage, [:log_category, :log_priority, :string, :varargs], :void
62
+ api :SDL_LogMessageV, [:log_category, :log_priority, :string, :varargs], :void
63
+ api :SDL_LogResetPriorities, [], :void
64
+ api :SDL_LogSetAllPriority, [:log_priority], :void
65
+ api :SDL_LogGetOutputFunction, [:log_output_function, :pointer], :void
66
+ api :SDL_LogSetOutputFunction, [:log_output_function, :pointer], :void
67
+ api :SDL_LogSetPriority, [:log_category, :log_priority], :void
68
+ api :SDL_LogGetPriority, [:log_category], :log_priority
69
+
70
+ end
data/lib/sdl2/mouse.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'sdl2'
2
+ require 'yinum'
3
+
4
+ module SDL2
5
+
6
+ class Cursor < Struct
7
+
8
+ def self.release(pointer)
9
+ SDL2.free_cursor(pointer)
10
+ end
11
+ end
12
+
13
+ enum :system_cursor, [:ARROW,:IBEAM,:WAIT,:CROSSHAIR,:WAITARROW,:SIZENWSE,:SIZENESW,:SIZEWE,
14
+ :SIZENS,:SIZEALL,:NO,:HAND]
15
+
16
+ api :SDL_GetMouseFocus, [], Window.by_ref
17
+ api :SDL_GetMouseState, [IntStruct.by_ref, IntStruct.by_ref], :uint32
18
+ api :SDL_GetRelativeMouseState, [IntStruct.by_ref, IntStruct.by_ref], :uint32
19
+ api :SDL_WarpMouseInWindow, [Window.by_ref, :int, :int], :void
20
+ api :SDL_SetRelativeMouseMode, [:bool], :int
21
+ api :SDL_GetRelativeMouseMode, [], :bool
22
+ api :SDL_CreateCursor, [:pointer, :pointer, :int, :int, :int, :int], Cursor.auto_ptr
23
+ api :SDL_CreateColorCursor, [Surface.by_ref, :int, :int], Cursor.auto_ptr
24
+ api :SDL_CreateSystemCursor, [:system_cursor], Cursor.auto_ptr
25
+ api :SDL_GetCursor, [], Cursor.by_ref
26
+ api :SDL_GetDefaultCursor, [], Cursor.by_ref
27
+ api :SDL_FreeCursor, [Cursor.by_ref], :void
28
+ api :SDL_ShowCursor, [:int], :int
29
+
30
+ module Mouse
31
+
32
+ def self.button(num)
33
+ 1 << (num-1)
34
+ end
35
+
36
+ Button = Enum.new(:MOUSE_BUTTONS, {
37
+ :LEFT => 1,
38
+ :MIDDLE => 2,
39
+ :RIGHT => 3,
40
+ :X1 => 4,
41
+ :X2 => 5
42
+ })
43
+
44
+ ButtonMask = Enum.new(:MOUSE_BUTTON_MASK, {
45
+ :LEFT => button(Button.LEFT),
46
+ :MIDDLE => button(Button.MIDDLE),
47
+ :RIGHT => button(Button.RIGHT),
48
+ :X1 => button(Button.X1),
49
+ :X2 => button(Button.X2)
50
+ })
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,15 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+ #SDL_pixels.h:261~267
5
+ class Palette < FFI::Struct
6
+ layout :ncolors, :int,
7
+ :colors, :pointer,
8
+ :version, :uint32,
9
+ :refcount, :int
10
+
11
+ def self.release(pointer)
12
+ SDL2.free_palette(pointer)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ require 'sdl2'
2
+ require 'sdl2/palette'
3
+
4
+ module SDL2
5
+ #SDL_pixels.h:272~293
6
+ class PixelFormat < FFI::Struct
7
+ layout :format, :pixel_format,
8
+ :palette, Palette.by_ref,
9
+ :bits_per_pixel, :uint8,
10
+ :bytes_per_pixel, :uint8,
11
+ :padding, [:uint8, 2],
12
+ :r_mask, :uint32,
13
+ :g_mask, :uint32,
14
+ :b_mask, :uint32,
15
+ :a_mask, :uint32,
16
+ :r_loss, :uint8,
17
+ :g_loss, :uint8,
18
+ :b_loss, :uint8,
19
+ :a_loss, :uint8,
20
+ :refcount, :int,
21
+ :next, PixelFormat.by_ref
22
+
23
+ def self.release(pointer)
24
+ SDL2.free_format(pointer)
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,35 @@
1
+ require 'sdl2'
2
+ require 'sdl2/color'
3
+ require 'sdl2/pixel_format'
4
+
5
+ module SDL2
6
+
7
+ ALPHA_OPAQUE = 255
8
+ ALPHA_TRANSPARENT = 0
9
+
10
+ enum :pixeltype, [:unknown, :index1, :index4, :index8,
11
+ :packed8, :packed16, :packed32,
12
+ :arrayU8, :arrayU16, :arrayU32,
13
+ :arrayF16, :arrayF32
14
+ ]
15
+ enum :bitmaporder, [:none, :_4321, :_1234]
16
+ enum :packedorder, [:none, :xrgb, :rgbx, :argb, :rgba, :xbgr, :bgrx, :abgr, :bgra]
17
+ enum :arrayorder, [:none, :rgb, :rgba, :argb, :bgr, :bgra, :abgr]
18
+ enum :packedlayout, [:none, :_332, :_4444, :_1555, :_5551, :_565, :_8888, :_2101010, :_1010102]
19
+
20
+ api :SDL_GetPixelFormatName, [:pixel_format], :string
21
+ api :SDL_PixelFormatEnumToMasks, [:pixel_format, IntStruct.by_ref, UInt32Struct.by_ref, UInt32Struct.by_ref,UInt32Struct.by_ref,UInt32Struct.by_ref,], :bool
22
+ api :SDL_MasksToPixelFormatEnum, [:int, :uint32, :uint32, :uint32, :uint32], :pixel_format
23
+ api :SDL_AllocFormat, [:pixel_format], PixelFormat.auto_ptr
24
+ api :SDL_FreeFormat, [PixelFormat.by_ref], :void
25
+ api :SDL_AllocPalette, [:count], Palette.auto_ptr
26
+ api :SDL_SetPixelFormatPalette, [PixelFormat.by_ref, Palette.by_ref], :int
27
+ api :SDL_SetPaletteColors, [Palette.by_ref, Color.by_ref, :int, :count], :int
28
+ api :SDL_FreePalette, [Palette.by_ref], :void
29
+ api :SDL_MapRGB, [PixelFormat.by_ref, :uint8, :uint8, :uint8], :uint32
30
+ api :SDL_MapRGBA, [PixelFormat.by_ref, :uint8, :uint8, :uint8, :uint8], :uint32
31
+ api :SDL_GetRGB, [:uint32, PixelFormat.by_ref, UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref], :void
32
+ api :SDL_GetRGBA, [:uint32, PixelFormat.by_ref, UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref], :void
33
+
34
+
35
+ end
data/lib/sdl2/point.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+ class Point < FFI::Struct
5
+ layout :x, :int, :y, :int
6
+ end
7
+ end
data/lib/sdl2/power.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+
5
+ Powerstate = enum :powerstate, [:UNKOWN, :ON_BATTERY, :NO_BATTERY, :CHARGING, :CHARGED]
6
+
7
+ api :SDL_GetPowerInfo, [IntStruct.by_ref, IntStruct.by_ref], :powerstate
8
+
9
+ end
data/lib/sdl2/rect.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'sdl2'
2
+
3
+ # Because SDL_rect.h defines the point struct too, include it here
4
+ require 'sdl2/point'
5
+
6
+ module SDL2
7
+
8
+ class Rect < FFI::Struct
9
+ layout :x, :int, :y, :int, :w, :int, :h, :int
10
+
11
+ def empty
12
+ return ((!self.null?) || (self[:w] <= 0) || (self[:h] <= 0)) ? :true : :false
13
+ end
14
+
15
+ def empty?
16
+ empty == :true
17
+ end
18
+
19
+ def equals(other)
20
+ if self.null or other.null?
21
+ return (self.null? and other.null?) ? :true : :false
22
+ else
23
+ [:x, :y, :w, :h].each do |field|
24
+ return :false unless self[field] == other[field]
25
+ end
26
+ end
27
+ return true # if we made it this far
28
+ end
29
+
30
+ end
31
+
32
+ api :SDL_HasIntersection, [Rect.by_ref, Rect.by_ref], :bool
33
+ api :SDL_IntersectRect, [Rect.by_ref, Rect.by_ref, Rect.by_ref], :bool
34
+ api :SDL_UnionRect, [Rect.by_ref, Rect.by_ref, Rect.by_ref], :void
35
+ api :SDL_EnclosePoints, [Point.by_ref, :count, Rect.by_ref, Rect.by_ref], :bool
36
+ api :SDL_IntersectRectAndLine, [Rect.by_ref, :int, :int, :int, :int], :bool
37
+
38
+ end