sdl2-bindings 0.0.9 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +129 -96
  3. data/LICENSE.txt +0 -0
  4. data/README.md +78 -55
  5. data/lib/sdl2.rb +131 -172
  6. data/lib/sdl2_audio.rb +261 -222
  7. data/lib/sdl2_blendmode.rb +72 -69
  8. data/lib/sdl2_clipboard.rb +56 -51
  9. data/lib/sdl2_cpuinfo.rb +129 -106
  10. data/lib/sdl2_error.rb +71 -64
  11. data/lib/sdl2_events.rb +564 -533
  12. data/lib/sdl2_filesystem.rb +52 -48
  13. data/lib/sdl2_framerate.rb +74 -67
  14. data/lib/sdl2_gamecontroller.rb +329 -274
  15. data/lib/sdl2_gesture.rb +61 -55
  16. data/lib/sdl2_gfxPrimitives.rb +283 -222
  17. data/lib/sdl2_haptic.rb +301 -269
  18. data/lib/sdl2_hidapi.rb +139 -118
  19. data/lib/sdl2_hints.rb +221 -198
  20. data/lib/sdl2_image.rb +232 -185
  21. data/lib/sdl2_imageFilter.rb +164 -132
  22. data/lib/sdl2_joystick.rb +294 -239
  23. data/lib/sdl2_keyboard.rb +125 -99
  24. data/lib/sdl2_keycode.rb +307 -305
  25. data/lib/sdl2_log.rb +131 -115
  26. data/lib/sdl2_main.rb +74 -67
  27. data/lib/sdl2_messagebox.rb +102 -98
  28. data/lib/sdl2_misc.rb +48 -45
  29. data/lib/sdl2_mixer.rb +392 -317
  30. data/lib/sdl2_mouse.rb +136 -117
  31. data/lib/sdl2_pixels.rb +240 -224
  32. data/lib/sdl2_platform.rb +48 -45
  33. data/lib/sdl2_power.rb +54 -51
  34. data/lib/sdl2_rect.rb +145 -102
  35. data/lib/sdl2_render.rb +408 -322
  36. data/lib/sdl2_rotozoom.rb +76 -66
  37. data/lib/sdl2_rwops.rb +242 -208
  38. data/lib/sdl2_scancode.rb +289 -287
  39. data/lib/sdl2_sensor.rb +115 -97
  40. data/lib/sdl2_shape.rb +83 -77
  41. data/lib/sdl2_sound.rb +154 -0
  42. data/lib/sdl2_stdinc.rb +556 -439
  43. data/lib/sdl2_surface.rb +229 -188
  44. data/lib/sdl2_syswm.rb +160 -157
  45. data/lib/sdl2_timer.rb +74 -65
  46. data/lib/sdl2_touch.rb +86 -75
  47. data/lib/sdl2_ttf.rb +358 -202
  48. data/lib/sdl2_version.rb +67 -62
  49. data/lib/sdl2_video.rb +540 -446
  50. data/lib/sdl2_vulkan.rb +72 -64
  51. metadata +18 -3
data/lib/sdl2.rb CHANGED
@@ -1,172 +1,131 @@
1
- # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby
2
- #
3
- # * https://github.com/vaiorabbit/sdl2-bindings
4
-
5
- require 'ffi'
6
- require_relative 'sdl2_main.rb'
7
- require_relative 'sdl2_audio.rb'
8
- require_relative 'sdl2_blendmode.rb'
9
- require_relative 'sdl2_clipboard.rb'
10
- require_relative 'sdl2_cpuinfo.rb'
11
- require_relative 'sdl2_error.rb'
12
- require_relative 'sdl2_events.rb'
13
- require_relative 'sdl2_filesystem.rb'
14
- require_relative 'sdl2_gamecontroller.rb'
15
- require_relative 'sdl2_gesture.rb'
16
- require_relative 'sdl2_haptic.rb'
17
- require_relative 'sdl2_hints.rb'
18
- require_relative 'sdl2_joystick.rb'
19
- require_relative 'sdl2_keyboard.rb'
20
- require_relative 'sdl2_keycode.rb'
21
- require_relative 'sdl2_log.rb'
22
- require_relative 'sdl2_messagebox.rb'
23
- require_relative 'sdl2_misc.rb'
24
- require_relative 'sdl2_mouse.rb'
25
- require_relative 'sdl2_pixels.rb'
26
- require_relative 'sdl2_platform.rb'
27
- require_relative 'sdl2_power.rb'
28
- require_relative 'sdl2_rect.rb'
29
- require_relative 'sdl2_render.rb'
30
- require_relative 'sdl2_rwops.rb'
31
- require_relative 'sdl2_scancode.rb'
32
- require_relative 'sdl2_sensor.rb'
33
- require_relative 'sdl2_shape.rb'
34
- require_relative 'sdl2_stdinc.rb'
35
- require_relative 'sdl2_surface.rb'
36
- require_relative 'sdl2_syswm.rb'
37
- require_relative 'sdl2_timer.rb'
38
- require_relative 'sdl2_touch.rb'
39
- require_relative 'sdl2_version.rb'
40
- require_relative 'sdl2_video.rb'
41
- require_relative 'sdl2_vulkan.rb'
42
-
43
- require_relative 'sdl2_framerate.rb'
44
- require_relative 'sdl2_gfxPrimitives.rb'
45
- require_relative 'sdl2_image.rb'
46
- require_relative 'sdl2_rotozoom.rb'
47
- require_relative 'sdl2_imageFilter.rb'
48
- require_relative 'sdl2_ttf.rb'
49
- require_relative 'sdl2_mixer.rb'
50
-
51
- module SDL2
52
- extend FFI::Library
53
-
54
- @@sdl2_import_done = false
55
- def self.load_lib(libpath, image_libpath: nil, ttf_libpath: nil, mixer_libpath: nil, gfx_libpath: nil)
56
-
57
- unless @@sdl2_import_done
58
- # Ref.: Using Multiple and Alternate Libraries
59
- # https://github.com/ffi/ffi/wiki/Using-Multiple-and-Alternate-Libraries
60
- begin
61
- lib_paths = [libpath, image_libpath, ttf_libpath, mixer_libpath, gfx_libpath].compact
62
-
63
- ffi_lib_flags :now, :global
64
- ffi_lib *lib_paths
65
- setup_symbols()
66
-
67
- if image_libpath != nil
68
- setup_image_symbols()
69
- end
70
-
71
- if ttf_libpath != nil
72
- setup_ttf_symbols()
73
- end
74
-
75
- if mixer_libpath != nil
76
- setup_mixer_symbols()
77
- end
78
-
79
- if gfx_libpath != nil
80
- setup_gfx_framerate_symbols()
81
- setup_gfx_primitives_symbols()
82
- setup_gfx_imagefilter_symbols()
83
- setup_gfx_rotozoom_symbols()
84
- end
85
- rescue => error
86
- puts error
87
- end
88
- end
89
-
90
- end
91
-
92
- def self.setup_symbols()
93
- setup_main_symbols()
94
- setup_audio_symbols()
95
- setup_blendmode_symbols()
96
- setup_clipboard_symbols()
97
- setup_cpuinfo_symbols()
98
- setup_error_symbols()
99
- setup_events_symbols()
100
- setup_filesystem_symbols()
101
- setup_gamecontroller_symbols()
102
- setup_gesture_symbols()
103
- setup_haptic_symbols()
104
- setup_hints_symbols()
105
- setup_joystick_symbols()
106
- setup_keyboard_symbols()
107
- setup_keycode_symbols()
108
- setup_log_symbols()
109
- setup_messagebox_symbols()
110
- setup_misc_symbols()
111
- setup_mouse_symbols()
112
- setup_pixels_symbols()
113
- setup_platform_symbols()
114
- setup_power_symbols()
115
- setup_rect_symbols()
116
- setup_render_symbols()
117
- setup_rwops_symbols()
118
- setup_scancode_symbols()
119
- setup_sensor_symbols()
120
- setup_shape_symbols()
121
- setup_surface_symbols()
122
- setup_syswm_symbols()
123
- setup_stdinc_symbols()
124
- setup_timer_symbols()
125
- setup_touch_symbols()
126
- setup_version_symbols()
127
- setup_video_symbols()
128
- setup_vulkan_symbols()
129
- end
130
-
131
- end
132
-
133
-
134
- if __FILE__ == $0
135
- SDL2.load_lib('libSDL2.dylib',
136
- gfx_libpath: '/usr/local/lib/libSDL2_gfx.dylib'
137
- )
138
-
139
- success = SDL2.SDL_Init(SDL2::SDL_INIT_EVERYTHING)
140
- exit if success < 0
141
-
142
- WINDOW_W = 320
143
- WINDOW_H = 240
144
- window = SDL2.SDL_CreateWindow("1st SDL Window via sdl2-bindings", 0, 0, WINDOW_W, WINDOW_H, 0)
145
-
146
- fpsdelay = 100;
147
-
148
- count = 0
149
- event = SDL2::SDL_Event.new
150
- done = false
151
- while not done
152
- while SDL2.SDL_PollEvent(event) != 0
153
- # 'type' and 'timestamp' are common members for all SDL Event structs.
154
- event_type = event[:common][:type]
155
- event_timestamp = event[:common][:timestamp]
156
- puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}"
157
-
158
- case event_type
159
- when SDL2::SDL_KEYDOWN
160
- if event[:key][:keysym][:sym] == SDL2::SDLK_SPACE
161
- puts "\tSPACE key pressed."
162
- end
163
- end
164
- end
165
-
166
- count += 1
167
- done = true if count >= 100
168
- SDL2.SDL_Delay(fpsdelay)
169
- end
170
-
171
- SDL2.SDL_Quit()
172
- end
1
+ # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby
2
+ #
3
+ # * https://github.com/vaiorabbit/sdl2-bindings
4
+
5
+ require 'ffi'
6
+ require_relative 'sdl2_main.rb'
7
+ require_relative 'sdl2_audio.rb'
8
+ require_relative 'sdl2_blendmode.rb'
9
+ require_relative 'sdl2_clipboard.rb'
10
+ require_relative 'sdl2_cpuinfo.rb'
11
+ require_relative 'sdl2_error.rb'
12
+ require_relative 'sdl2_events.rb'
13
+ require_relative 'sdl2_filesystem.rb'
14
+ require_relative 'sdl2_gamecontroller.rb'
15
+ require_relative 'sdl2_gesture.rb'
16
+ require_relative 'sdl2_haptic.rb'
17
+ require_relative 'sdl2_hints.rb'
18
+ require_relative 'sdl2_joystick.rb'
19
+ require_relative 'sdl2_keyboard.rb'
20
+ require_relative 'sdl2_keycode.rb'
21
+ require_relative 'sdl2_log.rb'
22
+ require_relative 'sdl2_messagebox.rb'
23
+ require_relative 'sdl2_misc.rb'
24
+ require_relative 'sdl2_mouse.rb'
25
+ require_relative 'sdl2_pixels.rb'
26
+ require_relative 'sdl2_platform.rb'
27
+ require_relative 'sdl2_power.rb'
28
+ require_relative 'sdl2_rect.rb'
29
+ require_relative 'sdl2_render.rb'
30
+ require_relative 'sdl2_rwops.rb'
31
+ require_relative 'sdl2_scancode.rb'
32
+ require_relative 'sdl2_sensor.rb'
33
+ require_relative 'sdl2_shape.rb'
34
+ require_relative 'sdl2_stdinc.rb'
35
+ require_relative 'sdl2_surface.rb'
36
+ require_relative 'sdl2_syswm.rb'
37
+ require_relative 'sdl2_timer.rb'
38
+ require_relative 'sdl2_touch.rb'
39
+ require_relative 'sdl2_version.rb'
40
+ require_relative 'sdl2_video.rb'
41
+ require_relative 'sdl2_vulkan.rb'
42
+
43
+ # SDL2_gfx
44
+ require_relative 'sdl2_framerate.rb'
45
+ require_relative 'sdl2_gfxPrimitives.rb'
46
+ require_relative 'sdl2_rotozoom.rb'
47
+ require_relative 'sdl2_imageFilter.rb'
48
+ # SDL_image
49
+ require_relative 'sdl2_image.rb'
50
+ # SDL_mixer
51
+ require_relative 'sdl2_mixer.rb'
52
+ # SDL_ttf
53
+ require_relative 'sdl2_ttf.rb'
54
+ # SDL_sound
55
+ require_relative 'sdl2_sound.rb'
56
+
57
+ module SDL
58
+ extend FFI::Library
59
+
60
+ @@sdl2_import_done = false
61
+ def self.load_lib(libpath, output_error = false, image_libpath: nil, ttf_libpath: nil, mixer_libpath: nil, gfx_libpath: nil, sound_libpath: nil)
62
+
63
+ unless @@sdl2_import_done
64
+ # Ref.: Using Multiple and Alternate Libraries
65
+ # https://github.com/ffi/ffi/wiki/Using-Multiple-and-Alternate-Libraries
66
+ begin
67
+ lib_paths = [libpath, image_libpath, ttf_libpath, mixer_libpath, gfx_libpath, sound_libpath].compact
68
+
69
+ ffi_lib_flags :now, :global
70
+ ffi_lib *lib_paths
71
+ setup_symbols(output_error)
72
+
73
+ setup_image_symbols(output_error) if image_libpath
74
+ setup_ttf_symbols(output_error) if ttf_libpath
75
+ setup_mixer_symbols(output_error) if mixer_libpath
76
+
77
+ if gfx_libpath != nil
78
+ setup_gfx_framerate_symbols(output_error)
79
+ setup_gfx_primitives_symbols(output_error)
80
+ setup_gfx_imagefilter_symbols(output_error)
81
+ setup_gfx_rotozoom_symbols(output_error)
82
+ end
83
+
84
+ setup_sound_symbols(output_error) if sound_libpath
85
+ rescue => error
86
+ $stderr.puts("[Warning] Failed to load libraries (#{error}).") if output_error
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ def self.setup_symbols(output_error = false)
93
+ setup_main_symbols(output_error)
94
+ setup_audio_symbols(output_error)
95
+ setup_blendmode_symbols(output_error)
96
+ setup_clipboard_symbols(output_error)
97
+ setup_cpuinfo_symbols(output_error)
98
+ setup_error_symbols(output_error)
99
+ setup_events_symbols(output_error)
100
+ setup_filesystem_symbols(output_error)
101
+ setup_gamecontroller_symbols(output_error)
102
+ setup_gesture_symbols(output_error)
103
+ setup_haptic_symbols(output_error)
104
+ setup_hints_symbols(output_error)
105
+ setup_joystick_symbols(output_error)
106
+ setup_keyboard_symbols(output_error)
107
+ setup_keycode_symbols(output_error)
108
+ setup_log_symbols(output_error)
109
+ setup_messagebox_symbols(output_error)
110
+ setup_misc_symbols(output_error)
111
+ setup_mouse_symbols(output_error)
112
+ setup_pixels_symbols(output_error)
113
+ setup_platform_symbols(output_error)
114
+ setup_power_symbols(output_error)
115
+ setup_rect_symbols(output_error)
116
+ setup_render_symbols(output_error)
117
+ setup_rwops_symbols(output_error)
118
+ setup_scancode_symbols(output_error)
119
+ setup_sensor_symbols(output_error)
120
+ setup_shape_symbols(output_error)
121
+ setup_surface_symbols(output_error)
122
+ setup_syswm_symbols(output_error)
123
+ setup_stdinc_symbols(output_error)
124
+ setup_timer_symbols(output_error)
125
+ setup_touch_symbols(output_error)
126
+ setup_version_symbols(output_error)
127
+ setup_video_symbols(output_error)
128
+ setup_vulkan_symbols(output_error)
129
+ end
130
+
131
+ end