sdl2-bindings 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +83 -79
  3. data/LICENSE.txt +1 -1
  4. data/README.md +49 -49
  5. data/lib/sdl2.rb +170 -170
  6. data/lib/sdl2_audio.rb +219 -201
  7. data/lib/sdl2_blendmode.rb +69 -69
  8. data/lib/sdl2_clipboard.rb +51 -51
  9. data/lib/sdl2_cpuinfo.rb +106 -106
  10. data/lib/sdl2_error.rb +64 -64
  11. data/lib/sdl2_events.rb +530 -530
  12. data/lib/sdl2_filesystem.rb +48 -48
  13. data/lib/sdl2_framerate.rb +67 -67
  14. data/lib/sdl2_gamecontroller.rb +254 -254
  15. data/lib/sdl2_gesture.rb +55 -55
  16. data/lib/sdl2_gfxPrimitives.rb +222 -222
  17. data/lib/sdl2_haptic.rb +269 -269
  18. data/lib/sdl2_hints.rb +174 -174
  19. data/lib/sdl2_image.rb +185 -185
  20. data/lib/sdl2_imageFilter.rb +132 -132
  21. data/lib/sdl2_joystick.rb +230 -230
  22. data/lib/sdl2_keyboard.rb +99 -99
  23. data/lib/sdl2_keycode.rb +304 -304
  24. data/lib/sdl2_log.rb +115 -115
  25. data/lib/sdl2_main.rb +67 -67
  26. data/lib/sdl2_messagebox.rb +98 -98
  27. data/lib/sdl2_mixer.rb +317 -307
  28. data/lib/sdl2_mouse.rb +117 -117
  29. data/lib/sdl2_pixels.rb +224 -224
  30. data/lib/sdl2_platform.rb +45 -45
  31. data/lib/sdl2_power.rb +51 -51
  32. data/lib/sdl2_rect.rb +102 -102
  33. data/lib/sdl2_render.rb +290 -290
  34. data/lib/sdl2_rotozoom.rb +66 -66
  35. data/lib/sdl2_rwops.rb +208 -208
  36. data/lib/sdl2_scancode.rb +287 -287
  37. data/lib/sdl2_shape.rb +77 -77
  38. data/lib/sdl2_stdinc.rb +393 -393
  39. data/lib/sdl2_surface.rb +182 -182
  40. data/lib/sdl2_syswm.rb +154 -154
  41. data/lib/sdl2_timer.rb +62 -62
  42. data/lib/sdl2_touch.rb +73 -73
  43. data/lib/sdl2_ttf.rb +202 -190
  44. data/lib/sdl2_version.rb +62 -62
  45. data/lib/sdl2_video.rb +411 -411
  46. data/lib/sdl2_vulkan.rb +64 -64
  47. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 812b4dccbd8dbe9b1ba6574d29e9fe22cae02183fcc5aa406a279fed5fc74a89
4
- data.tar.gz: 27388b5c68685717b4ae8a555bf7d70ace3b4b8b514fb7b5f82433473dc9a5d9
3
+ metadata.gz: 533feab6661f4f13ec028b62c73801f5b8c44d3b204dcfd6acd4986c60297edf
4
+ data.tar.gz: 1b0a21d7edb08c3faf2cb9fb6863376fefa15086ccd2dfcaa75ed83a6fc3dc1e
5
5
  SHA512:
6
- metadata.gz: e3ba162ed6fd7ff9e4d54954c3128e843ec37b90dde546df4f88cde6a9d1e3e2e49f583b1f5d7afe0db1d2a6f418b9222c47f95e42577fd7251960aa885635bc
7
- data.tar.gz: e3595270bfa5fc5f56ea3bec23207b39ff45a8ef6e0ce5490230de72ef372734affbc7251503f5e3ae53322815e1a714dc02c3ada43cabd24fc2e06835901dc8
6
+ metadata.gz: 52d620b288f5f36afb018356f0788fd833cdaacd17bf20e79625ed1716cffbde8f5502b1e6d2e62b062dfc7546f763abf0b2c59b6c8e93a77b3de3718898bc50
7
+ data.tar.gz: 9ebe4273355e338e24deff7b35850a15dcb47c30e1ee11c2b7ca48dbacea21509f946c9b3beda3309560a5bcf3de05c3e4f1964fa6bc41526008ba62767298c5
data/ChangeLog CHANGED
@@ -1,79 +1,83 @@
1
- 2020-12-27 vaiorabbit <http://twitter.com/vaiorabbit>
2
-
3
- * Added SDL 2.0.14 features.
4
- * third_party/sdl2_build_dll.sh: Added to build x64 DLL for Windows
5
- * test/util.rb: Added
6
-
7
- 2020-12-20 vaiorabbit <http://twitter.com/vaiorabbit>
8
-
9
- * third_party/sdl2_build_dylib.sh: Added to build x86_64|arm64 Universal Binary
10
-
11
- 2020-06-08 vaiorabbit <http://twitter.com/vaiorabbit>
12
-
13
- * lib/sdl2_syswm.rb: Added
14
- * lib/sdl2_hints.rb: Added hint string symboles
15
-
16
- 2020-03-22 vaiorabbit <http://twitter.com/vaiorabbit>
17
-
18
- * Added SDL 2.0.12 features.
19
- * Generate callback types correctly.
20
-
21
- 2019-10-27 vaiorabbit <http://twitter.com/vaiorabbit>
22
-
23
- * lib/sdl2_stdinc.rb: Added.
24
-
25
- 2019-08-31 vaiorabbit <http://twitter.com/vaiorabbit>
26
-
27
- * Refactoring + Cleanup
28
- * Some tests are usable again
29
-
30
- 2019-08-28 vaiorabbit <http://twitter.com/vaiorabbit>
31
-
32
- * Exception-safety
33
-
34
- 2019-08-27 vaiorabbit <http://twitter.com/vaiorabbit>
35
-
36
- * lib/sdl2_mixer.rb: Added (experimental)
37
-
38
- 2019-08-24 vaiorabbit <http://twitter.com/vaiorabbit>
39
-
40
- * Added SDL 2.0.10 features.
41
- * Added generator. Binding codes are generated semi-automatically.
42
- * Now depends on Ruby/FFI. Note that some codes in 'test' directory are still not usable.
43
-
44
- 2016-04-03 vaiorabbit <http://twitter.com/vaiorabbit>
45
-
46
- * lib/sdl2_gfx.rb, test/test_gfx.rb: Added.
47
-
48
- 2016-04-02 vaiorabbit <http://twitter.com/vaiorabbit>
49
-
50
- * Added SDL 2.0.4 features.
51
- * lib/version.rb: Added SDL_MAJOR_VERSION, etc.
52
-
53
- 2015-09-29 vaiorabbit <http://twitter.com/vaiorabbit>
54
-
55
- * lib/sdl2_ttf.rb: Added.
56
-
57
- 2015-09-28 vaiorabbit <http://twitter.com/vaiorabbit>
58
-
59
- * lib/sdl2_image.rb: Added.
60
- * lib/sdl2_mixer.rb: Added.
61
-
62
- 2015-09-22 vaiorabbit <http://twitter.com/vaiorabbit>
63
-
64
- * lib/pixels.rb, lib/gamecontroller.rb, lib/joystick.rb: Added.
65
- * lib/rwops.rb, lib/syswm.rb, lib/surface.rb, lib/render.rb: Added.
66
- * lib/cpuinfo.rb, lib/gesture.rb, lib/touch.rb, lib/audio.rb: Added.
67
-
68
- 2015-09-21 vaiorabbit <http://twitter.com/vaiorabbit>
69
-
70
- * lib/events.rb, lib/timer.rb, lib/video.rb: Added.
71
- * lib/keyboard.rb, lib/keycode.rb, lib/scancode.rb: Added.
72
- * lib/error.rb: Added.
73
- * lib/blendmode.rb, lib/clipboard.rb, lib/filesystem.rb, lib/version.rb: Added.
74
- * lib/platform.rb, lib/rect.rb, lib/mouse.rb: Added.
75
- * lib/messagebox.rb, lib/pixels.rb: Added.
76
-
77
- 2015-09-19 vaiorabbit <http://twitter.com/vaiorabbit>
78
-
79
- * Project started.
1
+ 2021-02-21 vaiorabbit <http://twitter.com/vaiorabbit>
2
+
3
+ * Added defines from Audio, Mixer and TTF
4
+
5
+ 2020-12-27 vaiorabbit <http://twitter.com/vaiorabbit>
6
+
7
+ * Added SDL 2.0.14 features.
8
+ * third_party/sdl2_build_dll.sh: Added to build x64 DLL for Windows
9
+ * test/util.rb: Added
10
+
11
+ 2020-12-20 vaiorabbit <http://twitter.com/vaiorabbit>
12
+
13
+ * third_party/sdl2_build_dylib.sh: Added to build x86_64|arm64 Universal Binary
14
+
15
+ 2020-06-08 vaiorabbit <http://twitter.com/vaiorabbit>
16
+
17
+ * lib/sdl2_syswm.rb: Added
18
+ * lib/sdl2_hints.rb: Added hint string symboles
19
+
20
+ 2020-03-22 vaiorabbit <http://twitter.com/vaiorabbit>
21
+
22
+ * Added SDL 2.0.12 features.
23
+ * Generate callback types correctly.
24
+
25
+ 2019-10-27 vaiorabbit <http://twitter.com/vaiorabbit>
26
+
27
+ * lib/sdl2_stdinc.rb: Added.
28
+
29
+ 2019-08-31 vaiorabbit <http://twitter.com/vaiorabbit>
30
+
31
+ * Refactoring + Cleanup
32
+ * Some tests are usable again
33
+
34
+ 2019-08-28 vaiorabbit <http://twitter.com/vaiorabbit>
35
+
36
+ * Exception-safety
37
+
38
+ 2019-08-27 vaiorabbit <http://twitter.com/vaiorabbit>
39
+
40
+ * lib/sdl2_mixer.rb: Added (experimental)
41
+
42
+ 2019-08-24 vaiorabbit <http://twitter.com/vaiorabbit>
43
+
44
+ * Added SDL 2.0.10 features.
45
+ * Added generator. Binding codes are generated semi-automatically.
46
+ * Now depends on Ruby/FFI. Note that some codes in 'test' directory are still not usable.
47
+
48
+ 2016-04-03 vaiorabbit <http://twitter.com/vaiorabbit>
49
+
50
+ * lib/sdl2_gfx.rb, test/test_gfx.rb: Added.
51
+
52
+ 2016-04-02 vaiorabbit <http://twitter.com/vaiorabbit>
53
+
54
+ * Added SDL 2.0.4 features.
55
+ * lib/version.rb: Added SDL_MAJOR_VERSION, etc.
56
+
57
+ 2015-09-29 vaiorabbit <http://twitter.com/vaiorabbit>
58
+
59
+ * lib/sdl2_ttf.rb: Added.
60
+
61
+ 2015-09-28 vaiorabbit <http://twitter.com/vaiorabbit>
62
+
63
+ * lib/sdl2_image.rb: Added.
64
+ * lib/sdl2_mixer.rb: Added.
65
+
66
+ 2015-09-22 vaiorabbit <http://twitter.com/vaiorabbit>
67
+
68
+ * lib/pixels.rb, lib/gamecontroller.rb, lib/joystick.rb: Added.
69
+ * lib/rwops.rb, lib/syswm.rb, lib/surface.rb, lib/render.rb: Added.
70
+ * lib/cpuinfo.rb, lib/gesture.rb, lib/touch.rb, lib/audio.rb: Added.
71
+
72
+ 2015-09-21 vaiorabbit <http://twitter.com/vaiorabbit>
73
+
74
+ * lib/events.rb, lib/timer.rb, lib/video.rb: Added.
75
+ * lib/keyboard.rb, lib/keycode.rb, lib/scancode.rb: Added.
76
+ * lib/error.rb: Added.
77
+ * lib/blendmode.rb, lib/clipboard.rb, lib/filesystem.rb, lib/version.rb: Added.
78
+ * lib/platform.rb, lib/rect.rb, lib/mouse.rb: Added.
79
+ * lib/messagebox.rb, lib/pixels.rb: Added.
80
+
81
+ 2015-09-19 vaiorabbit <http://twitter.com/vaiorabbit>
82
+
83
+ * Project started.
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  sdl2-bindings : Yet another SDL2 wrapper for Ruby
2
- Copyright (c) 2015-2020 vaiorabbit <http://twitter.com/vaiorabbit>
2
+ Copyright (c) 2015-2021 vaiorabbit <http://twitter.com/vaiorabbit>
3
3
 
4
4
  This software is provided 'as-is', without any express or implied
5
5
  warranty. In no event will the authors be held liable for any damages
data/README.md CHANGED
@@ -1,49 +1,49 @@
1
- <!-- -*- mode:markdown; coding:utf-8; -*- -->
2
-
3
- # sdl2-bindings : Yet another SDL2 wrapper for Ruby #
4
-
5
- [Notice] Experimental project.
6
-
7
- * Created : 2015-09-19
8
- * Last modified : 2020-12-27
9
-
10
- ## Features ##
11
-
12
- * Generated semi-automatically
13
- * Based on Ruby/FFI
14
- * No need to build C extension library
15
-
16
-
17
- ## Limitations ##
18
-
19
- * Some APIs provided by pre-processor cannot be imported.
20
-
21
- ## Tested Environment ##
22
-
23
- * [2015-09-19] SDL 2.0.3 (Installed via Homebrew)
24
- * Mac OS X 10.10.5, ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
25
- * [2016-04-03] SDL 2.0.4 (Installed via Homebrew)
26
- * Mac OS X 10.11.4, ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
27
- * sdl2_gfx : 1.0.1
28
- * sdl2_image : 2.0.1
29
- * sdl2_mixer : 2.0.1
30
- * sdl2_ttf : 2.0.13
31
- * [2019-08-31] SDL 2.0.10 (Installed via Homebrew)
32
- * [2020-03-22] SDL 2.0.12 (Installed via Homebrew)
33
- * [2020-12-27] SDL 2.0.14 (Installed via Homebrew)
34
- * macOS Big Sur (11.0.1), ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm64-darwin20]
35
-
36
- ## License ##
37
-
38
- The zlib/libpng License ( http://opensource.org/licenses/Zlib ).
39
-
40
- sdl2-bindings : Yet another SDL2 wrapper for Ruby
41
- Copyright (c) 2015-2020 vaiorabbit <http://twitter.com/vaiorabbit>
42
-
43
- This software is provided 'as-is', without any express or implied
44
- warranty. In no event will the authors be held liable for any damages
45
- arising from the use of this software.
46
-
47
- Permission is granted to anyone to use this software for any purpose,
48
- including commercial applications, and to alter it and redistribute it
49
- freely, subject to the following restrictions:
1
+ <!-- -*- mode:markdown; coding:utf-8; -*- -->
2
+
3
+ # sdl2-bindings : Yet another SDL2 wrapper for Ruby #
4
+
5
+ [Notice] Experimental project.
6
+
7
+ * Created : 2015-09-19
8
+ * Last modified : 2021-02-21
9
+
10
+ ## Features ##
11
+
12
+ * Generated semi-automatically
13
+ * Based on Ruby/FFI
14
+ * No need to build C extension library
15
+
16
+
17
+ ## Limitations ##
18
+
19
+ * Some APIs provided by pre-processor cannot be imported.
20
+
21
+ ## Tested Environment ##
22
+
23
+ * [2015-09-19] SDL 2.0.3 (Installed via Homebrew)
24
+ * Mac OS X 10.10.5, ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
25
+ * [2016-04-03] SDL 2.0.4 (Installed via Homebrew)
26
+ * Mac OS X 10.11.4, ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
27
+ * sdl2_gfx : 1.0.1
28
+ * sdl2_image : 2.0.1
29
+ * sdl2_mixer : 2.0.1
30
+ * sdl2_ttf : 2.0.13
31
+ * [2019-08-31] SDL 2.0.10 (Installed via Homebrew)
32
+ * [2020-03-22] SDL 2.0.12 (Installed via Homebrew)
33
+ * [2020-12-27] SDL 2.0.14 (Installed via Homebrew)
34
+ * macOS Big Sur (11.0.1), ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm64-darwin20]
35
+
36
+ ## License ##
37
+
38
+ The zlib/libpng License ( http://opensource.org/licenses/Zlib ).
39
+
40
+ sdl2-bindings : Yet another SDL2 wrapper for Ruby
41
+ Copyright (c) 2015-2021 vaiorabbit <http://twitter.com/vaiorabbit>
42
+
43
+ This software is provided 'as-is', without any express or implied
44
+ warranty. In no event will the authors be held liable for any damages
45
+ arising from the use of this software.
46
+
47
+ Permission is granted to anyone to use this software for any purpose,
48
+ including commercial applications, and to alter it and redistribute it
49
+ freely, subject to the following restrictions:
data/lib/sdl2.rb CHANGED
@@ -1,170 +1,170 @@
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_mouse.rb'
24
- require_relative 'sdl2_pixels.rb'
25
- require_relative 'sdl2_platform.rb'
26
- require_relative 'sdl2_power.rb'
27
- require_relative 'sdl2_rect.rb'
28
- require_relative 'sdl2_render.rb'
29
- require_relative 'sdl2_rwops.rb'
30
- require_relative 'sdl2_scancode.rb'
31
- require_relative 'sdl2_shape.rb'
32
- require_relative 'sdl2_stdinc.rb'
33
- require_relative 'sdl2_surface.rb'
34
- require_relative 'sdl2_syswm.rb'
35
- require_relative 'sdl2_timer.rb'
36
- require_relative 'sdl2_touch.rb'
37
- require_relative 'sdl2_version.rb'
38
- require_relative 'sdl2_video.rb'
39
- require_relative 'sdl2_vulkan.rb'
40
-
41
- require_relative 'sdl2_framerate.rb'
42
- require_relative 'sdl2_gfxPrimitives.rb'
43
- require_relative 'sdl2_image.rb'
44
- require_relative 'sdl2_rotozoom.rb'
45
- require_relative 'sdl2_imageFilter.rb'
46
- require_relative 'sdl2_ttf.rb'
47
- require_relative 'sdl2_mixer.rb'
48
-
49
- module SDL2
50
- extend FFI::Library
51
-
52
- @@sdl2_import_done = false
53
- def self.load_lib(libpath, image_libpath: nil, ttf_libpath: nil, mixer_libpath: nil, gfx_libpath: nil)
54
-
55
- unless @@sdl2_import_done
56
- # Ref.: Using Multiple and Alternate Libraries
57
- # https://github.com/ffi/ffi/wiki/Using-Multiple-and-Alternate-Libraries
58
- begin
59
- lib_paths = [libpath, image_libpath, ttf_libpath, mixer_libpath, gfx_libpath].compact
60
-
61
- ffi_lib_flags :now, :global
62
- ffi_lib *lib_paths
63
- setup_symbols()
64
-
65
- if image_libpath != nil
66
- setup_image_symbols()
67
- end
68
-
69
- if ttf_libpath != nil
70
- setup_ttf_symbols()
71
- end
72
-
73
- if mixer_libpath != nil
74
- setup_mixer_symbols()
75
- end
76
-
77
- if gfx_libpath != nil
78
- setup_gfx_framerate_symbols()
79
- setup_gfx_primitives_symbols()
80
- setup_gfx_imagefilter_symbols()
81
- setup_gfx_rotozoom_symbols()
82
- end
83
- rescue => error
84
- puts error
85
- end
86
- end
87
-
88
- end
89
-
90
- def self.setup_symbols()
91
- setup_main_symbols()
92
- setup_audio_symbols()
93
- setup_blendmode_symbols()
94
- setup_clipboard_symbols()
95
- setup_cpuinfo_symbols()
96
- setup_error_symbols()
97
- setup_events_symbols()
98
- setup_filesystem_symbols()
99
- setup_gamecontroller_symbols()
100
- setup_gesture_symbols()
101
- setup_haptic_symbols()
102
- setup_hints_symbols()
103
- setup_joystick_symbols()
104
- setup_keyboard_symbols()
105
- setup_keycode_symbols()
106
- setup_log_symbols()
107
- setup_messagebox_symbols()
108
- setup_mouse_symbols()
109
- setup_pixels_symbols()
110
- setup_platform_symbols()
111
- setup_power_symbols()
112
- setup_rect_symbols()
113
- setup_render_symbols()
114
- setup_rwops_symbols()
115
- setup_scancode_symbols()
116
- setup_shape_symbols()
117
- setup_surface_symbols()
118
- setup_syswm_symbols()
119
- setup_stdinc_symbols()
120
- setup_timer_symbols()
121
- setup_touch_symbols()
122
- setup_version_symbols()
123
- setup_video_symbols()
124
- setup_vulkan_symbols()
125
- end
126
-
127
- end
128
-
129
-
130
- if __FILE__ == $0
131
- # SDL2.load_lib('libSDL2.dylib')
132
- # p SDL2.SDL_Init(SDL2::SDL_INIT_EVERYTHING)
133
- SDL2.load_lib('libSDL2.dylib',
134
- gfx_libpath: '/usr/local/lib/libSDL2_gfx.dylib'
135
- )
136
- #SDL2.SDL_SetMainReady()
137
- success = SDL2.SDL_Init(SDL2::SDL_INIT_EVERYTHING)
138
- exit if success < 0
139
-
140
- WINDOW_W = 320
141
- WINDOW_H = 240
142
- window = SDL2.SDL_CreateWindow("1st SDL Window via sdl2-bindings", 0, 0, WINDOW_W, WINDOW_H, 0)
143
-
144
- fpsdelay = 100;
145
-
146
- count = 0
147
- event = SDL2::SDL_Event.new
148
- done = false
149
- while not done
150
- while SDL2.SDL_PollEvent(event) != 0
151
- # 'type' and 'timestamp' are common members for all SDL Event structs.
152
- event_type = event[:common][:type]
153
- event_timestamp = event[:common][:timestamp]
154
- puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}"
155
-
156
- case event_type
157
- when SDL2::SDL_KEYDOWN
158
- if event[:key][:keysym][:sym] == SDL2::SDLK_SPACE
159
- puts "\tSPACE key pressed."
160
- end
161
- end
162
- end
163
-
164
- count += 1
165
- done = true if count >= 100
166
- SDL2.SDL_Delay(fpsdelay)
167
- end
168
-
169
- SDL2.SDL_Quit()
170
- 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_mouse.rb'
24
+ require_relative 'sdl2_pixels.rb'
25
+ require_relative 'sdl2_platform.rb'
26
+ require_relative 'sdl2_power.rb'
27
+ require_relative 'sdl2_rect.rb'
28
+ require_relative 'sdl2_render.rb'
29
+ require_relative 'sdl2_rwops.rb'
30
+ require_relative 'sdl2_scancode.rb'
31
+ require_relative 'sdl2_shape.rb'
32
+ require_relative 'sdl2_stdinc.rb'
33
+ require_relative 'sdl2_surface.rb'
34
+ require_relative 'sdl2_syswm.rb'
35
+ require_relative 'sdl2_timer.rb'
36
+ require_relative 'sdl2_touch.rb'
37
+ require_relative 'sdl2_version.rb'
38
+ require_relative 'sdl2_video.rb'
39
+ require_relative 'sdl2_vulkan.rb'
40
+
41
+ require_relative 'sdl2_framerate.rb'
42
+ require_relative 'sdl2_gfxPrimitives.rb'
43
+ require_relative 'sdl2_image.rb'
44
+ require_relative 'sdl2_rotozoom.rb'
45
+ require_relative 'sdl2_imageFilter.rb'
46
+ require_relative 'sdl2_ttf.rb'
47
+ require_relative 'sdl2_mixer.rb'
48
+
49
+ module SDL2
50
+ extend FFI::Library
51
+
52
+ @@sdl2_import_done = false
53
+ def self.load_lib(libpath, image_libpath: nil, ttf_libpath: nil, mixer_libpath: nil, gfx_libpath: nil)
54
+
55
+ unless @@sdl2_import_done
56
+ # Ref.: Using Multiple and Alternate Libraries
57
+ # https://github.com/ffi/ffi/wiki/Using-Multiple-and-Alternate-Libraries
58
+ begin
59
+ lib_paths = [libpath, image_libpath, ttf_libpath, mixer_libpath, gfx_libpath].compact
60
+
61
+ ffi_lib_flags :now, :global
62
+ ffi_lib *lib_paths
63
+ setup_symbols()
64
+
65
+ if image_libpath != nil
66
+ setup_image_symbols()
67
+ end
68
+
69
+ if ttf_libpath != nil
70
+ setup_ttf_symbols()
71
+ end
72
+
73
+ if mixer_libpath != nil
74
+ setup_mixer_symbols()
75
+ end
76
+
77
+ if gfx_libpath != nil
78
+ setup_gfx_framerate_symbols()
79
+ setup_gfx_primitives_symbols()
80
+ setup_gfx_imagefilter_symbols()
81
+ setup_gfx_rotozoom_symbols()
82
+ end
83
+ rescue => error
84
+ puts error
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ def self.setup_symbols()
91
+ setup_main_symbols()
92
+ setup_audio_symbols()
93
+ setup_blendmode_symbols()
94
+ setup_clipboard_symbols()
95
+ setup_cpuinfo_symbols()
96
+ setup_error_symbols()
97
+ setup_events_symbols()
98
+ setup_filesystem_symbols()
99
+ setup_gamecontroller_symbols()
100
+ setup_gesture_symbols()
101
+ setup_haptic_symbols()
102
+ setup_hints_symbols()
103
+ setup_joystick_symbols()
104
+ setup_keyboard_symbols()
105
+ setup_keycode_symbols()
106
+ setup_log_symbols()
107
+ setup_messagebox_symbols()
108
+ setup_mouse_symbols()
109
+ setup_pixels_symbols()
110
+ setup_platform_symbols()
111
+ setup_power_symbols()
112
+ setup_rect_symbols()
113
+ setup_render_symbols()
114
+ setup_rwops_symbols()
115
+ setup_scancode_symbols()
116
+ setup_shape_symbols()
117
+ setup_surface_symbols()
118
+ setup_syswm_symbols()
119
+ setup_stdinc_symbols()
120
+ setup_timer_symbols()
121
+ setup_touch_symbols()
122
+ setup_version_symbols()
123
+ setup_video_symbols()
124
+ setup_vulkan_symbols()
125
+ end
126
+
127
+ end
128
+
129
+
130
+ if __FILE__ == $0
131
+ # SDL2.load_lib('libSDL2.dylib')
132
+ # p SDL2.SDL_Init(SDL2::SDL_INIT_EVERYTHING)
133
+ SDL2.load_lib('libSDL2.dylib',
134
+ gfx_libpath: '/usr/local/lib/libSDL2_gfx.dylib'
135
+ )
136
+ #SDL2.SDL_SetMainReady()
137
+ success = SDL2.SDL_Init(SDL2::SDL_INIT_EVERYTHING)
138
+ exit if success < 0
139
+
140
+ WINDOW_W = 320
141
+ WINDOW_H = 240
142
+ window = SDL2.SDL_CreateWindow("1st SDL Window via sdl2-bindings", 0, 0, WINDOW_W, WINDOW_H, 0)
143
+
144
+ fpsdelay = 100;
145
+
146
+ count = 0
147
+ event = SDL2::SDL_Event.new
148
+ done = false
149
+ while not done
150
+ while SDL2.SDL_PollEvent(event) != 0
151
+ # 'type' and 'timestamp' are common members for all SDL Event structs.
152
+ event_type = event[:common][:type]
153
+ event_timestamp = event[:common][:timestamp]
154
+ puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}"
155
+
156
+ case event_type
157
+ when SDL2::SDL_KEYDOWN
158
+ if event[:key][:keysym][:sym] == SDL2::SDLK_SPACE
159
+ puts "\tSPACE key pressed."
160
+ end
161
+ end
162
+ end
163
+
164
+ count += 1
165
+ done = true if count >= 100
166
+ SDL2.SDL_Delay(fpsdelay)
167
+ end
168
+
169
+ SDL2.SDL_Quit()
170
+ end