sdl2-bindings 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +12 -0
  3. data/README.md +39 -26
  4. data/lib/sdl2.rb +54 -99
  5. data/lib/sdl2_audio.rb +59 -20
  6. data/lib/sdl2_blendmode.rb +28 -25
  7. data/lib/sdl2_clipboard.rb +9 -4
  8. data/lib/sdl2_cpuinfo.rb +28 -5
  9. data/lib/sdl2_error.rb +17 -10
  10. data/lib/sdl2_events.rb +150 -131
  11. data/lib/sdl2_filesystem.rb +8 -4
  12. data/lib/sdl2_framerate.rb +11 -4
  13. data/lib/sdl2_gamecontroller.rb +112 -57
  14. data/lib/sdl2_gesture.rb +10 -4
  15. data/lib/sdl2_gfxPrimitives.rb +65 -4
  16. data/lib/sdl2_haptic.rb +76 -44
  17. data/lib/sdl2_hidapi.rb +26 -5
  18. data/lib/sdl2_hints.rb +146 -137
  19. data/lib/sdl2_image.rb +54 -7
  20. data/lib/sdl2_imageFilter.rb +36 -4
  21. data/lib/sdl2_joystick.rb +93 -38
  22. data/lib/sdl2_keyboard.rb +23 -5
  23. data/lib/sdl2_keycode.rb +6 -4
  24. data/lib/sdl2_log.rb +48 -32
  25. data/lib/sdl2_main.rb +21 -14
  26. data/lib/sdl2_messagebox.rb +26 -22
  27. data/lib/sdl2_misc.rb +7 -4
  28. data/lib/sdl2_mixer.rb +86 -11
  29. data/lib/sdl2_mouse.rb +44 -25
  30. data/lib/sdl2_pixels.rb +115 -99
  31. data/lib/sdl2_platform.rb +7 -4
  32. data/lib/sdl2_power.rb +12 -9
  33. data/lib/sdl2_rect.rb +18 -11
  34. data/lib/sdl2_render.rb +107 -25
  35. data/lib/sdl2_rotozoom.rb +14 -4
  36. data/lib/sdl2_rwops.rb +58 -28
  37. data/lib/sdl2_scancode.rb +250 -248
  38. data/lib/sdl2_sensor.rb +27 -9
  39. data/lib/sdl2_shape.rb +17 -11
  40. data/lib/sdl2_stdinc.rb +135 -10
  41. data/lib/sdl2_surface.rb +56 -15
  42. data/lib/sdl2_syswm.rb +47 -44
  43. data/lib/sdl2_timer.rb +13 -4
  44. data/lib/sdl2_touch.rb +18 -11
  45. data/lib/sdl2_ttf.rb +180 -25
  46. data/lib/sdl2_version.rb +13 -8
  47. data/lib/sdl2_video.rb +204 -110
  48. data/lib/sdl2_vulkan.rb +12 -4
  49. metadata +17 -3
data/lib/sdl2_mixer.rb CHANGED
@@ -6,21 +6,18 @@
6
6
 
7
7
  require 'ffi'
8
8
 
9
- module SDL2
9
+ module SDL
10
10
  extend FFI::Library
11
11
  # Define/Macro
12
12
 
13
- SDL_MIXER_MAJOR_VERSION = 2
14
- SDL_MIXER_MINOR_VERSION = 0
15
- SDL_MIXER_PATCHLEVEL = 4
16
- MIX_MAJOR_VERSION = SDL_MIXER_MAJOR_VERSION
17
- MIX_MINOR_VERSION = SDL_MIXER_MINOR_VERSION
18
- MIX_PATCHLEVEL = SDL_MIXER_PATCHLEVEL
13
+ MIXER_MAJOR_VERSION = 2
14
+ MIXER_MINOR_VERSION = 0
15
+ MIXER_PATCHLEVEL = 4
19
16
  MIX_CHANNELS = 8
20
17
  MIX_DEFAULT_FREQUENCY = 22050
21
18
  MIX_DEFAULT_FORMAT = AUDIO_S16LSB
22
19
  MIX_DEFAULT_CHANNELS = 2
23
- MIX_MAX_VOLUME = SDL_MIX_MAXVOLUME
20
+ MIX_MAX_VOLUME = MIX_MAXVOLUME
24
21
  MIX_CHANNEL_POST = -2
25
22
  MIX_EFFECTSMAXSPEED = "MIX_EFFECTSMAXSPEED"
26
23
 
@@ -69,7 +66,7 @@ module SDL2
69
66
 
70
67
  # Function
71
68
 
72
- def self.setup_mixer_symbols()
69
+ def self.setup_mixer_symbols(output_error = false)
73
70
  symbols = [
74
71
  :Mix_Linked_Version,
75
72
  :Mix_Init,
@@ -148,6 +145,84 @@ module SDL2
148
145
  :Mix_GetChunk,
149
146
  :Mix_CloseAudio,
150
147
  ]
148
+ apis = {
149
+ :Mix_Linked_Version => :Mix_Linked_Version,
150
+ :Mix_Init => :Mix_Init,
151
+ :Mix_Quit => :Mix_Quit,
152
+ :Mix_OpenAudio => :Mix_OpenAudio,
153
+ :Mix_OpenAudioDevice => :Mix_OpenAudioDevice,
154
+ :Mix_AllocateChannels => :Mix_AllocateChannels,
155
+ :Mix_QuerySpec => :Mix_QuerySpec,
156
+ :Mix_LoadWAV_RW => :Mix_LoadWAV_RW,
157
+ :Mix_LoadMUS => :Mix_LoadMUS,
158
+ :Mix_LoadMUS_RW => :Mix_LoadMUS_RW,
159
+ :Mix_LoadMUSType_RW => :Mix_LoadMUSType_RW,
160
+ :Mix_QuickLoad_WAV => :Mix_QuickLoad_WAV,
161
+ :Mix_QuickLoad_RAW => :Mix_QuickLoad_RAW,
162
+ :Mix_FreeChunk => :Mix_FreeChunk,
163
+ :Mix_FreeMusic => :Mix_FreeMusic,
164
+ :Mix_GetNumChunkDecoders => :Mix_GetNumChunkDecoders,
165
+ :Mix_GetChunkDecoder => :Mix_GetChunkDecoder,
166
+ :Mix_HasChunkDecoder => :Mix_HasChunkDecoder,
167
+ :Mix_GetNumMusicDecoders => :Mix_GetNumMusicDecoders,
168
+ :Mix_GetMusicDecoder => :Mix_GetMusicDecoder,
169
+ :Mix_HasMusicDecoder => :Mix_HasMusicDecoder,
170
+ :Mix_GetMusicType => :Mix_GetMusicType,
171
+ :Mix_SetPostMix => :Mix_SetPostMix,
172
+ :Mix_HookMusic => :Mix_HookMusic,
173
+ :Mix_HookMusicFinished => :Mix_HookMusicFinished,
174
+ :Mix_GetMusicHookData => :Mix_GetMusicHookData,
175
+ :Mix_ChannelFinished => :Mix_ChannelFinished,
176
+ :Mix_RegisterEffect => :Mix_RegisterEffect,
177
+ :Mix_UnregisterEffect => :Mix_UnregisterEffect,
178
+ :Mix_UnregisterAllEffects => :Mix_UnregisterAllEffects,
179
+ :Mix_SetPanning => :Mix_SetPanning,
180
+ :Mix_SetPosition => :Mix_SetPosition,
181
+ :Mix_SetDistance => :Mix_SetDistance,
182
+ :Mix_SetReverseStereo => :Mix_SetReverseStereo,
183
+ :Mix_ReserveChannels => :Mix_ReserveChannels,
184
+ :Mix_GroupChannel => :Mix_GroupChannel,
185
+ :Mix_GroupChannels => :Mix_GroupChannels,
186
+ :Mix_GroupAvailable => :Mix_GroupAvailable,
187
+ :Mix_GroupCount => :Mix_GroupCount,
188
+ :Mix_GroupOldest => :Mix_GroupOldest,
189
+ :Mix_GroupNewer => :Mix_GroupNewer,
190
+ :Mix_PlayChannelTimed => :Mix_PlayChannelTimed,
191
+ :Mix_PlayMusic => :Mix_PlayMusic,
192
+ :Mix_FadeInMusic => :Mix_FadeInMusic,
193
+ :Mix_FadeInMusicPos => :Mix_FadeInMusicPos,
194
+ :Mix_FadeInChannelTimed => :Mix_FadeInChannelTimed,
195
+ :Mix_Volume => :Mix_Volume,
196
+ :Mix_VolumeChunk => :Mix_VolumeChunk,
197
+ :Mix_VolumeMusic => :Mix_VolumeMusic,
198
+ :Mix_HaltChannel => :Mix_HaltChannel,
199
+ :Mix_HaltGroup => :Mix_HaltGroup,
200
+ :Mix_HaltMusic => :Mix_HaltMusic,
201
+ :Mix_ExpireChannel => :Mix_ExpireChannel,
202
+ :Mix_FadeOutChannel => :Mix_FadeOutChannel,
203
+ :Mix_FadeOutGroup => :Mix_FadeOutGroup,
204
+ :Mix_FadeOutMusic => :Mix_FadeOutMusic,
205
+ :Mix_FadingMusic => :Mix_FadingMusic,
206
+ :Mix_FadingChannel => :Mix_FadingChannel,
207
+ :Mix_Pause => :Mix_Pause,
208
+ :Mix_Resume => :Mix_Resume,
209
+ :Mix_Paused => :Mix_Paused,
210
+ :Mix_PauseMusic => :Mix_PauseMusic,
211
+ :Mix_ResumeMusic => :Mix_ResumeMusic,
212
+ :Mix_RewindMusic => :Mix_RewindMusic,
213
+ :Mix_PausedMusic => :Mix_PausedMusic,
214
+ :Mix_SetMusicPosition => :Mix_SetMusicPosition,
215
+ :Mix_Playing => :Mix_Playing,
216
+ :Mix_PlayingMusic => :Mix_PlayingMusic,
217
+ :Mix_SetMusicCMD => :Mix_SetMusicCMD,
218
+ :Mix_SetSynchroValue => :Mix_SetSynchroValue,
219
+ :Mix_GetSynchroValue => :Mix_GetSynchroValue,
220
+ :Mix_SetSoundFonts => :Mix_SetSoundFonts,
221
+ :Mix_GetSoundFonts => :Mix_GetSoundFonts,
222
+ :Mix_EachSoundFont => :Mix_EachSoundFont,
223
+ :Mix_GetChunk => :Mix_GetChunk,
224
+ :Mix_CloseAudio => :Mix_CloseAudio,
225
+ }
151
226
  args = {
152
227
  :Mix_Linked_Version => [],
153
228
  :Mix_Init => [:int],
@@ -306,9 +381,9 @@ module SDL2
306
381
  }
307
382
  symbols.each do |sym|
308
383
  begin
309
- attach_function sym, args[sym], retvals[sym]
384
+ attach_function apis[sym], sym, args[sym], retvals[sym]
310
385
  rescue FFI::NotFoundError => error
311
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
386
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
312
387
  end
313
388
  end
314
389
  end
data/lib/sdl2_mouse.rb CHANGED
@@ -6,33 +6,33 @@
6
6
 
7
7
  require 'ffi'
8
8
 
9
- module SDL2
9
+ module SDL
10
10
  extend FFI::Library
11
11
  # Define/Macro
12
12
 
13
- SDL_BUTTON_LEFT = 1
14
- SDL_BUTTON_MIDDLE = 2
15
- SDL_BUTTON_RIGHT = 3
16
- SDL_BUTTON_X1 = 4
17
- SDL_BUTTON_X2 = 5
13
+ BUTTON_LEFT = 1
14
+ BUTTON_MIDDLE = 2
15
+ BUTTON_RIGHT = 3
16
+ BUTTON_X1 = 4
17
+ BUTTON_X2 = 5
18
18
 
19
19
  # Enum
20
20
 
21
- SDL_SYSTEM_CURSOR_ARROW = 0
22
- SDL_SYSTEM_CURSOR_IBEAM = 1
23
- SDL_SYSTEM_CURSOR_WAIT = 2
24
- SDL_SYSTEM_CURSOR_CROSSHAIR = 3
25
- SDL_SYSTEM_CURSOR_WAITARROW = 4
26
- SDL_SYSTEM_CURSOR_SIZENWSE = 5
27
- SDL_SYSTEM_CURSOR_SIZENESW = 6
28
- SDL_SYSTEM_CURSOR_SIZEWE = 7
29
- SDL_SYSTEM_CURSOR_SIZENS = 8
30
- SDL_SYSTEM_CURSOR_SIZEALL = 9
31
- SDL_SYSTEM_CURSOR_NO = 10
32
- SDL_SYSTEM_CURSOR_HAND = 11
33
- SDL_NUM_SYSTEM_CURSORS = 12
34
- SDL_MOUSEWHEEL_NORMAL = 0
35
- SDL_MOUSEWHEEL_FLIPPED = 1
21
+ SYSTEM_CURSOR_ARROW = 0
22
+ SYSTEM_CURSOR_IBEAM = 1
23
+ SYSTEM_CURSOR_WAIT = 2
24
+ SYSTEM_CURSOR_CROSSHAIR = 3
25
+ SYSTEM_CURSOR_WAITARROW = 4
26
+ SYSTEM_CURSOR_SIZENWSE = 5
27
+ SYSTEM_CURSOR_SIZENESW = 6
28
+ SYSTEM_CURSOR_SIZEWE = 7
29
+ SYSTEM_CURSOR_SIZENS = 8
30
+ SYSTEM_CURSOR_SIZEALL = 9
31
+ SYSTEM_CURSOR_NO = 10
32
+ SYSTEM_CURSOR_HAND = 11
33
+ NUM_SYSTEM_CURSORS = 12
34
+ MOUSEWHEEL_NORMAL = 0
35
+ MOUSEWHEEL_FLIPPED = 1
36
36
 
37
37
  # Typedef
38
38
 
@@ -44,7 +44,7 @@ module SDL2
44
44
 
45
45
  # Function
46
46
 
47
- def self.setup_mouse_symbols()
47
+ def self.setup_mouse_symbols(output_error = false)
48
48
  symbols = [
49
49
  :SDL_GetMouseFocus,
50
50
  :SDL_GetMouseState,
@@ -64,6 +64,25 @@ module SDL2
64
64
  :SDL_FreeCursor,
65
65
  :SDL_ShowCursor,
66
66
  ]
67
+ apis = {
68
+ :SDL_GetMouseFocus => :GetMouseFocus,
69
+ :SDL_GetMouseState => :GetMouseState,
70
+ :SDL_GetGlobalMouseState => :GetGlobalMouseState,
71
+ :SDL_GetRelativeMouseState => :GetRelativeMouseState,
72
+ :SDL_WarpMouseInWindow => :WarpMouseInWindow,
73
+ :SDL_WarpMouseGlobal => :WarpMouseGlobal,
74
+ :SDL_SetRelativeMouseMode => :SetRelativeMouseMode,
75
+ :SDL_CaptureMouse => :CaptureMouse,
76
+ :SDL_GetRelativeMouseMode => :GetRelativeMouseMode,
77
+ :SDL_CreateCursor => :CreateCursor,
78
+ :SDL_CreateColorCursor => :CreateColorCursor,
79
+ :SDL_CreateSystemCursor => :CreateSystemCursor,
80
+ :SDL_SetCursor => :SetCursor,
81
+ :SDL_GetCursor => :GetCursor,
82
+ :SDL_GetDefaultCursor => :GetDefaultCursor,
83
+ :SDL_FreeCursor => :FreeCursor,
84
+ :SDL_ShowCursor => :ShowCursor,
85
+ }
67
86
  args = {
68
87
  :SDL_GetMouseFocus => [],
69
88
  :SDL_GetMouseState => [:pointer, :pointer],
@@ -104,14 +123,14 @@ module SDL2
104
123
  }
105
124
  symbols.each do |sym|
106
125
  begin
107
- attach_function sym, args[sym], retvals[sym]
126
+ attach_function apis[sym], sym, args[sym], retvals[sym]
108
127
  rescue FFI::NotFoundError => error
109
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
128
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
110
129
  end
111
130
  end
112
131
  end
113
132
 
114
133
  end
115
134
 
116
- # TODO : def SDL_BUTTON(X); (1 << ((X)-1)); end;
135
+ # TODO : def self.BUTTON(X); (1 << ((X)-1)); end;
117
136
 
data/lib/sdl2_pixels.rb CHANGED
@@ -6,105 +6,105 @@
6
6
 
7
7
  require 'ffi'
8
8
 
9
- module SDL2
9
+ module SDL
10
10
  extend FFI::Library
11
11
  # Define/Macro
12
12
 
13
- SDL_ALPHA_OPAQUE = 255
14
- SDL_ALPHA_TRANSPARENT = 0
13
+ ALPHA_OPAQUE = 255
14
+ ALPHA_TRANSPARENT = 0
15
15
 
16
16
  # Enum
17
17
 
18
- SDL_PIXELTYPE_UNKNOWN = 0
19
- SDL_PIXELTYPE_INDEX1 = 1
20
- SDL_PIXELTYPE_INDEX4 = 2
21
- SDL_PIXELTYPE_INDEX8 = 3
22
- SDL_PIXELTYPE_PACKED8 = 4
23
- SDL_PIXELTYPE_PACKED16 = 5
24
- SDL_PIXELTYPE_PACKED32 = 6
25
- SDL_PIXELTYPE_ARRAYU8 = 7
26
- SDL_PIXELTYPE_ARRAYU16 = 8
27
- SDL_PIXELTYPE_ARRAYU32 = 9
28
- SDL_PIXELTYPE_ARRAYF16 = 10
29
- SDL_PIXELTYPE_ARRAYF32 = 11
30
- SDL_BITMAPORDER_NONE = 0
31
- SDL_BITMAPORDER_4321 = 1
32
- SDL_BITMAPORDER_1234 = 2
33
- SDL_PACKEDORDER_NONE = 0
34
- SDL_PACKEDORDER_XRGB = 1
35
- SDL_PACKEDORDER_RGBX = 2
36
- SDL_PACKEDORDER_ARGB = 3
37
- SDL_PACKEDORDER_RGBA = 4
38
- SDL_PACKEDORDER_XBGR = 5
39
- SDL_PACKEDORDER_BGRX = 6
40
- SDL_PACKEDORDER_ABGR = 7
41
- SDL_PACKEDORDER_BGRA = 8
42
- SDL_ARRAYORDER_NONE = 0
43
- SDL_ARRAYORDER_RGB = 1
44
- SDL_ARRAYORDER_RGBA = 2
45
- SDL_ARRAYORDER_ARGB = 3
46
- SDL_ARRAYORDER_BGR = 4
47
- SDL_ARRAYORDER_BGRA = 5
48
- SDL_ARRAYORDER_ABGR = 6
49
- SDL_PACKEDLAYOUT_NONE = 0
50
- SDL_PACKEDLAYOUT_332 = 1
51
- SDL_PACKEDLAYOUT_4444 = 2
52
- SDL_PACKEDLAYOUT_1555 = 3
53
- SDL_PACKEDLAYOUT_5551 = 4
54
- SDL_PACKEDLAYOUT_565 = 5
55
- SDL_PACKEDLAYOUT_8888 = 6
56
- SDL_PACKEDLAYOUT_2101010 = 7
57
- SDL_PACKEDLAYOUT_1010102 = 8
58
- SDL_PIXELFORMAT_UNKNOWN = 0
59
- SDL_PIXELFORMAT_INDEX1LSB = 286261504
60
- SDL_PIXELFORMAT_INDEX1MSB = 287310080
61
- SDL_PIXELFORMAT_INDEX4LSB = 303039488
62
- SDL_PIXELFORMAT_INDEX4MSB = 304088064
63
- SDL_PIXELFORMAT_INDEX8 = 318769153
64
- SDL_PIXELFORMAT_RGB332 = 336660481
65
- SDL_PIXELFORMAT_XRGB4444 = 353504258
66
- SDL_PIXELFORMAT_RGB444 = 353504258
67
- SDL_PIXELFORMAT_XBGR4444 = 357698562
68
- SDL_PIXELFORMAT_BGR444 = 357698562
69
- SDL_PIXELFORMAT_XRGB1555 = 353570562
70
- SDL_PIXELFORMAT_RGB555 = 353570562
71
- SDL_PIXELFORMAT_XBGR1555 = 357764866
72
- SDL_PIXELFORMAT_BGR555 = 357764866
73
- SDL_PIXELFORMAT_ARGB4444 = 355602434
74
- SDL_PIXELFORMAT_RGBA4444 = 356651010
75
- SDL_PIXELFORMAT_ABGR4444 = 359796738
76
- SDL_PIXELFORMAT_BGRA4444 = 360845314
77
- SDL_PIXELFORMAT_ARGB1555 = 355667970
78
- SDL_PIXELFORMAT_RGBA5551 = 356782082
79
- SDL_PIXELFORMAT_ABGR1555 = 359862274
80
- SDL_PIXELFORMAT_BGRA5551 = 360976386
81
- SDL_PIXELFORMAT_RGB565 = 353701890
82
- SDL_PIXELFORMAT_BGR565 = 357896194
83
- SDL_PIXELFORMAT_RGB24 = 386930691
84
- SDL_PIXELFORMAT_BGR24 = 390076419
85
- SDL_PIXELFORMAT_XRGB8888 = 370546692
86
- SDL_PIXELFORMAT_RGB888 = 370546692
87
- SDL_PIXELFORMAT_RGBX8888 = 371595268
88
- SDL_PIXELFORMAT_XBGR8888 = 374740996
89
- SDL_PIXELFORMAT_BGR888 = 374740996
90
- SDL_PIXELFORMAT_BGRX8888 = 375789572
91
- SDL_PIXELFORMAT_ARGB8888 = 372645892
92
- SDL_PIXELFORMAT_RGBA8888 = 373694468
93
- SDL_PIXELFORMAT_ABGR8888 = 376840196
94
- SDL_PIXELFORMAT_BGRA8888 = 377888772
95
- SDL_PIXELFORMAT_ARGB2101010 = 372711428
96
- SDL_PIXELFORMAT_RGBA32 = 376840196
97
- SDL_PIXELFORMAT_ARGB32 = 377888772
98
- SDL_PIXELFORMAT_BGRA32 = 372645892
99
- SDL_PIXELFORMAT_ABGR32 = 373694468
100
- SDL_PIXELFORMAT_YV12 = 842094169
101
- SDL_PIXELFORMAT_IYUV = 1448433993
102
- SDL_PIXELFORMAT_YUY2 = 844715353
103
- SDL_PIXELFORMAT_UYVY = 1498831189
104
- SDL_PIXELFORMAT_YVYU = 1431918169
105
- SDL_PIXELFORMAT_NV12 = 842094158
106
- SDL_PIXELFORMAT_NV21 = 825382478
107
- SDL_PIXELFORMAT_EXTERNAL_OES = 542328143
18
+ PIXELTYPE_UNKNOWN = 0
19
+ PIXELTYPE_INDEX1 = 1
20
+ PIXELTYPE_INDEX4 = 2
21
+ PIXELTYPE_INDEX8 = 3
22
+ PIXELTYPE_PACKED8 = 4
23
+ PIXELTYPE_PACKED16 = 5
24
+ PIXELTYPE_PACKED32 = 6
25
+ PIXELTYPE_ARRAYU8 = 7
26
+ PIXELTYPE_ARRAYU16 = 8
27
+ PIXELTYPE_ARRAYU32 = 9
28
+ PIXELTYPE_ARRAYF16 = 10
29
+ PIXELTYPE_ARRAYF32 = 11
30
+ BITMAPORDER_NONE = 0
31
+ BITMAPORDER_4321 = 1
32
+ BITMAPORDER_1234 = 2
33
+ PACKEDORDER_NONE = 0
34
+ PACKEDORDER_XRGB = 1
35
+ PACKEDORDER_RGBX = 2
36
+ PACKEDORDER_ARGB = 3
37
+ PACKEDORDER_RGBA = 4
38
+ PACKEDORDER_XBGR = 5
39
+ PACKEDORDER_BGRX = 6
40
+ PACKEDORDER_ABGR = 7
41
+ PACKEDORDER_BGRA = 8
42
+ ARRAYORDER_NONE = 0
43
+ ARRAYORDER_RGB = 1
44
+ ARRAYORDER_RGBA = 2
45
+ ARRAYORDER_ARGB = 3
46
+ ARRAYORDER_BGR = 4
47
+ ARRAYORDER_BGRA = 5
48
+ ARRAYORDER_ABGR = 6
49
+ PACKEDLAYOUT_NONE = 0
50
+ PACKEDLAYOUT_332 = 1
51
+ PACKEDLAYOUT_4444 = 2
52
+ PACKEDLAYOUT_1555 = 3
53
+ PACKEDLAYOUT_5551 = 4
54
+ PACKEDLAYOUT_565 = 5
55
+ PACKEDLAYOUT_8888 = 6
56
+ PACKEDLAYOUT_2101010 = 7
57
+ PACKEDLAYOUT_1010102 = 8
58
+ PIXELFORMAT_UNKNOWN = 0
59
+ PIXELFORMAT_INDEX1LSB = 286261504
60
+ PIXELFORMAT_INDEX1MSB = 287310080
61
+ PIXELFORMAT_INDEX4LSB = 303039488
62
+ PIXELFORMAT_INDEX4MSB = 304088064
63
+ PIXELFORMAT_INDEX8 = 318769153
64
+ PIXELFORMAT_RGB332 = 336660481
65
+ PIXELFORMAT_XRGB4444 = 353504258
66
+ PIXELFORMAT_RGB444 = 353504258
67
+ PIXELFORMAT_XBGR4444 = 357698562
68
+ PIXELFORMAT_BGR444 = 357698562
69
+ PIXELFORMAT_XRGB1555 = 353570562
70
+ PIXELFORMAT_RGB555 = 353570562
71
+ PIXELFORMAT_XBGR1555 = 357764866
72
+ PIXELFORMAT_BGR555 = 357764866
73
+ PIXELFORMAT_ARGB4444 = 355602434
74
+ PIXELFORMAT_RGBA4444 = 356651010
75
+ PIXELFORMAT_ABGR4444 = 359796738
76
+ PIXELFORMAT_BGRA4444 = 360845314
77
+ PIXELFORMAT_ARGB1555 = 355667970
78
+ PIXELFORMAT_RGBA5551 = 356782082
79
+ PIXELFORMAT_ABGR1555 = 359862274
80
+ PIXELFORMAT_BGRA5551 = 360976386
81
+ PIXELFORMAT_RGB565 = 353701890
82
+ PIXELFORMAT_BGR565 = 357896194
83
+ PIXELFORMAT_RGB24 = 386930691
84
+ PIXELFORMAT_BGR24 = 390076419
85
+ PIXELFORMAT_XRGB8888 = 370546692
86
+ PIXELFORMAT_RGB888 = 370546692
87
+ PIXELFORMAT_RGBX8888 = 371595268
88
+ PIXELFORMAT_XBGR8888 = 374740996
89
+ PIXELFORMAT_BGR888 = 374740996
90
+ PIXELFORMAT_BGRX8888 = 375789572
91
+ PIXELFORMAT_ARGB8888 = 372645892
92
+ PIXELFORMAT_RGBA8888 = 373694468
93
+ PIXELFORMAT_ABGR8888 = 376840196
94
+ PIXELFORMAT_BGRA8888 = 377888772
95
+ PIXELFORMAT_ARGB2101010 = 372711428
96
+ PIXELFORMAT_RGBA32 = 376840196
97
+ PIXELFORMAT_ARGB32 = 377888772
98
+ PIXELFORMAT_BGRA32 = 372645892
99
+ PIXELFORMAT_ABGR32 = 373694468
100
+ PIXELFORMAT_YV12 = 842094169
101
+ PIXELFORMAT_IYUV = 1448433993
102
+ PIXELFORMAT_YUY2 = 844715353
103
+ PIXELFORMAT_UYVY = 1498831189
104
+ PIXELFORMAT_YVYU = 1431918169
105
+ PIXELFORMAT_NV12 = 842094158
106
+ PIXELFORMAT_NV21 = 825382478
107
+ PIXELFORMAT_EXTERNAL_OES = 542328143
108
108
 
109
109
  # Typedef
110
110
 
@@ -117,7 +117,7 @@ module SDL2
117
117
 
118
118
  # Struct
119
119
 
120
- class SDL_Color < FFI::Struct
120
+ class Color < FFI::Struct
121
121
  layout(
122
122
  :r, :uchar,
123
123
  :g, :uchar,
@@ -126,7 +126,7 @@ module SDL2
126
126
  )
127
127
  end
128
128
 
129
- class SDL_Palette < FFI::Struct
129
+ class Palette < FFI::Struct
130
130
  layout(
131
131
  :ncolors, :int,
132
132
  :colors, :pointer,
@@ -135,7 +135,7 @@ module SDL2
135
135
  )
136
136
  end
137
137
 
138
- class SDL_PixelFormat < FFI::Struct
138
+ class PixelFormat < FFI::Struct
139
139
  layout(
140
140
  :format, :uint,
141
141
  :palette, :pointer,
@@ -162,7 +162,7 @@ module SDL2
162
162
 
163
163
  # Function
164
164
 
165
- def self.setup_pixels_symbols()
165
+ def self.setup_pixels_symbols(output_error = false)
166
166
  symbols = [
167
167
  :SDL_GetPixelFormatName,
168
168
  :SDL_PixelFormatEnumToMasks,
@@ -179,6 +179,22 @@ module SDL2
179
179
  :SDL_GetRGBA,
180
180
  :SDL_CalculateGammaRamp,
181
181
  ]
182
+ apis = {
183
+ :SDL_GetPixelFormatName => :GetPixelFormatName,
184
+ :SDL_PixelFormatEnumToMasks => :PixelFormatEnumToMasks,
185
+ :SDL_MasksToPixelFormatEnum => :MasksToPixelFormatEnum,
186
+ :SDL_AllocFormat => :AllocFormat,
187
+ :SDL_FreeFormat => :FreeFormat,
188
+ :SDL_AllocPalette => :AllocPalette,
189
+ :SDL_SetPixelFormatPalette => :SetPixelFormatPalette,
190
+ :SDL_SetPaletteColors => :SetPaletteColors,
191
+ :SDL_FreePalette => :FreePalette,
192
+ :SDL_MapRGB => :MapRGB,
193
+ :SDL_MapRGBA => :MapRGBA,
194
+ :SDL_GetRGB => :GetRGB,
195
+ :SDL_GetRGBA => :GetRGBA,
196
+ :SDL_CalculateGammaRamp => :CalculateGammaRamp,
197
+ }
182
198
  args = {
183
199
  :SDL_GetPixelFormatName => [:uint],
184
200
  :SDL_PixelFormatEnumToMasks => [:uint, :pointer, :pointer, :pointer, :pointer, :pointer],
@@ -213,9 +229,9 @@ module SDL2
213
229
  }
214
230
  symbols.each do |sym|
215
231
  begin
216
- attach_function sym, args[sym], retvals[sym]
232
+ attach_function apis[sym], sym, args[sym], retvals[sym]
217
233
  rescue FFI::NotFoundError => error
218
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
234
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
219
235
  end
220
236
  end
221
237
  end
data/lib/sdl2_platform.rb CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  require 'ffi'
8
8
 
9
- module SDL2
9
+ module SDL
10
10
  extend FFI::Library
11
11
  # Define/Macro
12
12
 
@@ -22,10 +22,13 @@ module SDL2
22
22
 
23
23
  # Function
24
24
 
25
- def self.setup_platform_symbols()
25
+ def self.setup_platform_symbols(output_error = false)
26
26
  symbols = [
27
27
  :SDL_GetPlatform,
28
28
  ]
29
+ apis = {
30
+ :SDL_GetPlatform => :GetPlatform,
31
+ }
29
32
  args = {
30
33
  :SDL_GetPlatform => [],
31
34
  }
@@ -34,9 +37,9 @@ module SDL2
34
37
  }
35
38
  symbols.each do |sym|
36
39
  begin
37
- attach_function sym, args[sym], retvals[sym]
40
+ attach_function apis[sym], sym, args[sym], retvals[sym]
38
41
  rescue FFI::NotFoundError => error
39
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
42
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
40
43
  end
41
44
  end
42
45
  end
data/lib/sdl2_power.rb CHANGED
@@ -6,18 +6,18 @@
6
6
 
7
7
  require 'ffi'
8
8
 
9
- module SDL2
9
+ module SDL
10
10
  extend FFI::Library
11
11
  # Define/Macro
12
12
 
13
13
 
14
14
  # Enum
15
15
 
16
- SDL_POWERSTATE_UNKNOWN = 0
17
- SDL_POWERSTATE_ON_BATTERY = 1
18
- SDL_POWERSTATE_NO_BATTERY = 2
19
- SDL_POWERSTATE_CHARGING = 3
20
- SDL_POWERSTATE_CHARGED = 4
16
+ POWERSTATE_UNKNOWN = 0
17
+ POWERSTATE_ON_BATTERY = 1
18
+ POWERSTATE_NO_BATTERY = 2
19
+ POWERSTATE_CHARGING = 3
20
+ POWERSTATE_CHARGED = 4
21
21
 
22
22
  # Typedef
23
23
 
@@ -28,10 +28,13 @@ module SDL2
28
28
 
29
29
  # Function
30
30
 
31
- def self.setup_power_symbols()
31
+ def self.setup_power_symbols(output_error = false)
32
32
  symbols = [
33
33
  :SDL_GetPowerInfo,
34
34
  ]
35
+ apis = {
36
+ :SDL_GetPowerInfo => :GetPowerInfo,
37
+ }
35
38
  args = {
36
39
  :SDL_GetPowerInfo => [:pointer, :pointer],
37
40
  }
@@ -40,9 +43,9 @@ module SDL2
40
43
  }
41
44
  symbols.each do |sym|
42
45
  begin
43
- attach_function sym, args[sym], retvals[sym]
46
+ attach_function apis[sym], sym, args[sym], retvals[sym]
44
47
  rescue FFI::NotFoundError => error
45
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
48
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
46
49
  end
47
50
  end
48
51
  end
data/lib/sdl2_rect.rb CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  require 'ffi'
8
8
 
9
- module SDL2
9
+ module SDL
10
10
  extend FFI::Library
11
11
  # Define/Macro
12
12
 
@@ -17,36 +17,36 @@ module SDL2
17
17
  # Typedef
18
18
 
19
19
 
20
- def SDL_PointInRect(p, r)
20
+ def self.PointInRect(p, r)
21
21
  return ( (p.x >= r.x) && (p.x < (r.x + r.w)) && (p.y >= r.y) && (p.y < (r.y + r.h)) ) ? 1 : 0;
22
22
  end
23
23
 
24
- def SDL_RectEmpty(r)
24
+ def self.RectEmpty(r)
25
25
  return (!r.null? || (r.w <= 0) || (r.h <= 0)) ? 1 : 0
26
26
  end
27
27
 
28
- def SDL_RectEquals(a, b)
28
+ def self.RectEquals(a, b)
29
29
  return (!a.null? && !b.null? && (a.x == b.x) && (a.y == b.y) && (a.w == b.w) && (a.h == b.h)) ? 1 : 0
30
30
  end
31
31
 
32
32
 
33
33
  # Struct
34
34
 
35
- class SDL_Point < FFI::Struct
35
+ class Point < FFI::Struct
36
36
  layout(
37
37
  :x, :int,
38
38
  :y, :int,
39
39
  )
40
40
  end
41
41
 
42
- class SDL_FPoint < FFI::Struct
42
+ class FPoint < FFI::Struct
43
43
  layout(
44
44
  :x, :float,
45
45
  :y, :float,
46
46
  )
47
47
  end
48
48
 
49
- class SDL_Rect < FFI::Struct
49
+ class Rect < FFI::Struct
50
50
  layout(
51
51
  :x, :int,
52
52
  :y, :int,
@@ -55,7 +55,7 @@ module SDL2
55
55
  )
56
56
  end
57
57
 
58
- class SDL_FRect < FFI::Struct
58
+ class FRect < FFI::Struct
59
59
  layout(
60
60
  :x, :float,
61
61
  :y, :float,
@@ -67,7 +67,7 @@ module SDL2
67
67
 
68
68
  # Function
69
69
 
70
- def self.setup_rect_symbols()
70
+ def self.setup_rect_symbols(output_error = false)
71
71
  symbols = [
72
72
  :SDL_HasIntersection,
73
73
  :SDL_IntersectRect,
@@ -75,6 +75,13 @@ module SDL2
75
75
  :SDL_EnclosePoints,
76
76
  :SDL_IntersectRectAndLine,
77
77
  ]
78
+ apis = {
79
+ :SDL_HasIntersection => :HasIntersection,
80
+ :SDL_IntersectRect => :IntersectRect,
81
+ :SDL_UnionRect => :UnionRect,
82
+ :SDL_EnclosePoints => :EnclosePoints,
83
+ :SDL_IntersectRectAndLine => :IntersectRectAndLine,
84
+ }
78
85
  args = {
79
86
  :SDL_HasIntersection => [:pointer, :pointer],
80
87
  :SDL_IntersectRect => [:pointer, :pointer, :pointer],
@@ -91,9 +98,9 @@ module SDL2
91
98
  }
92
99
  symbols.each do |sym|
93
100
  begin
94
- attach_function sym, args[sym], retvals[sym]
101
+ attach_function apis[sym], sym, args[sym], retvals[sym]
95
102
  rescue FFI::NotFoundError => error
96
- $stderr.puts("[Warning] Failed to import #{sym} (#{error}).")
103
+ $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error
97
104
  end
98
105
  end
99
106
  end