├── .gitignore ├── ChangeLog ├── LICENSE.txt ├── README.md ├── generator ├── README.md ├── SDL2 │ └── .gitkeep ├── batch_generate.sh ├── generate_SDL.py ├── generate_SDL2_framerate.py ├── generate_SDL2_gfxPrimitives.py ├── generate_SDL2_imageFilter.py ├── generate_SDL2_rotozoom.py ├── generate_SDL_audio.py ├── generate_SDL_blendmode.py ├── generate_SDL_clipboard.py ├── generate_SDL_cpuinfo.py ├── generate_SDL_error.py ├── generate_SDL_events.py ├── generate_SDL_filesystem.py ├── generate_SDL_gamecontroller.py ├── generate_SDL_gesture.py ├── generate_SDL_guid.py ├── generate_SDL_haptic.py ├── generate_SDL_hidapi.py ├── generate_SDL_hints.py ├── generate_SDL_image.py ├── generate_SDL_joystick.py ├── generate_SDL_keyboard.py ├── generate_SDL_keycode.py ├── generate_SDL_log.py ├── generate_SDL_messagebox.py ├── generate_SDL_misc.py ├── generate_SDL_mixer.py ├── generate_SDL_mouse.py ├── generate_SDL_pixels.py ├── generate_SDL_platform.py ├── generate_SDL_power.py ├── generate_SDL_rect.py ├── generate_SDL_render.py ├── generate_SDL_rwops.py ├── generate_SDL_scancode.py ├── generate_SDL_sensor.py ├── generate_SDL_shape.py ├── generate_SDL_sound.py ├── generate_SDL_stdinc.py ├── generate_SDL_surface.py ├── generate_SDL_syswm.py ├── generate_SDL_timer.py ├── generate_SDL_touch.py ├── generate_SDL_ttf.py ├── generate_SDL_version.py ├── generate_SDL_video.py ├── generate_SDL_vulkan.py ├── generate_initial_cindex_mapping.py ├── generate_initial_define_mapping.py ├── generate_initial_mapping.sh ├── sdl2_cindex_mapping.json ├── sdl2_define_mapping.json ├── sdl2_generator.py ├── sdl2_headers_list.json └── sdl2_parser.py ├── lib ├── sdl2.rb ├── sdl2_audio.rb ├── sdl2_blendmode.rb ├── sdl2_clipboard.rb ├── sdl2_cpuinfo.rb ├── sdl2_error.rb ├── sdl2_events.rb ├── sdl2_filesystem.rb ├── sdl2_framerate.rb ├── sdl2_gamecontroller.rb ├── sdl2_gesture.rb ├── sdl2_gfxPrimitives.rb ├── sdl2_guid.rb ├── sdl2_haptic.rb ├── sdl2_hidapi.rb ├── sdl2_hints.rb ├── sdl2_image.rb ├── sdl2_imageFilter.rb ├── sdl2_joystick.rb ├── sdl2_keyboard.rb ├── sdl2_keycode.rb ├── sdl2_log.rb ├── sdl2_main.rb ├── sdl2_messagebox.rb ├── sdl2_misc.rb ├── sdl2_mixer.rb ├── sdl2_mouse.rb ├── sdl2_pixels.rb ├── sdl2_platform.rb ├── sdl2_power.rb ├── sdl2_rect.rb ├── sdl2_render.rb ├── sdl2_rotozoom.rb ├── sdl2_rwops.rb ├── sdl2_scancode.rb ├── sdl2_sensor.rb ├── sdl2_shape.rb ├── sdl2_sound.rb ├── sdl2_stdinc.rb ├── sdl2_surface.rb ├── sdl2_syswm.rb ├── sdl2_timer.rb ├── sdl2_touch.rb ├── sdl2_ttf.rb ├── sdl2_version.rb ├── sdl2_video.rb └── sdl2_vulkan.rb ├── sdl2-bindings.gemspec ├── test ├── 256px-Globe.svg.png ├── GenShinGothic-Normal.ttf ├── Globe.bmp ├── README_GenShin.txt ├── SIL_Open_Font_License_1.1.txt ├── test_audioinfo.rb ├── test_draw.rb ├── test_dropfile.rb ├── test_event.rb ├── test_gfx.rb ├── test_image.rb ├── test_ime.rb ├── test_import.rb ├── test_joystick.rb ├── test_messagebox.rb ├── test_mixer.rb ├── test_opengl.rb ├── test_sound.rb ├── test_sprite.rb ├── test_timer.rb ├── test_ttf.rb ├── test_window.rb └── util.rb └── third_party ├── sdl2_build_dll.cmd ├── sdl2_build_dylib.sh ├── sdl2_mixer_build_dylib.sh └── sdl2_sound_build_dylib.sh /.gitignore: -------------------------------------------------------------------------------- 1 | generator/*SDL2/SDL* 2 | generator/*SDL2/*h 3 | third_party/SDL2-* 4 | third_party/SDL2_* 5 | third_party/SDL_* -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2024-02-03 vaiorabbit 2 | 3 | * SDL 2.30.0 4 | 5 | 2024-01-28 vaiorabbit 6 | 7 | * SDL_mixer 2.8.0 and SDL_ttf 2.22.0 8 | 9 | 2024-01-20 vaiorabbit 10 | 11 | * SDL 2.29.1, etc. 12 | 13 | 2023-12-09 vaiorabbit 14 | 15 | * SDL_image 2.8.0 ( https://github.com/libsdl-org/SDL_image/releases/tag/release-2.8.0 ) 16 | 17 | 2023-08-10 vaiorabbit 18 | 19 | * SDL 2.28.2 ( https://github.com/libsdl-org/SDL/releases/tag/release-2.28.2 ) 20 | 21 | 2023-06-25 vaiorabbit 22 | 23 | * SDL 2.28.0 ( https://github.com/libsdl-org/SDL/releases/tag/release-2.28.0 ) 24 | 25 | 2023-04-16 vaiorabbit 26 | 27 | * Fix parser bug 28 | 29 | 2023-02-05 vaiorabbit 30 | 31 | * lib/sdl2_syswm.rb: Added X11 support 32 | * Added Linux (on WSL) as a tested environment 33 | 34 | 2022-11-23 vaiorabbit 35 | 36 | * SDL 2.26.0 ( https://github.com/libsdl-org/SDL/releases/tag/release-2.26.0 ) 37 | 38 | 2022-10-09 vaiorabbit 39 | 40 | * SDL 2.24.1 ( https://github.com/libsdl-org/SDL/releases/tag/release-2.24.1 ) 41 | * Fixed wrong value definitions 42 | 43 | 2022-08-20 vaiorabbit 44 | 45 | * SDL 2.24.0 ( https://github.com/libsdl-org/SDL/releases/tag/release-2.24.0 ) 46 | * Generated for SDL_image 2.6.2, SDL_mixer 2.6.2 and SDL_ttf 2.20.1 47 | * SDL::JoystickGUID is now defined as an alias of SDL::GUID ( https://github.com/libsdl-org/SDL/commit/3a20274ddff20d9c3ea4895353b23ff252954b87 ) 48 | 49 | 2022-07-31 vaiorabbit 50 | 51 | * Regenerated bindings to fix bugs (size_t interpretation) 52 | * Regenerated bindings for SDL_image 2.6.0, SDL_mixer 2.6.0 and SDL_ttf 2.20.0 53 | 54 | 2022-05-01 vaiorabbit 55 | 56 | * lib/sdl2_rwops.rb: Added RW_SEEK_SET, RW_SEEK_CUR and RW_SEEK_END 57 | 58 | 2022-04-29 vaiorabbit 59 | 60 | * Added SDL 2.0.22 features ( https://github.com/libsdl-org/SDL/releases/tag/release-2.0.22 ) 61 | * third_party/sdl2_build_dll.cmd: Updated to refer 2.0.22 62 | 63 | 2022-03-28 vaiorabbit 64 | 65 | * lib/sdl2_sound.rb: Added 66 | 67 | 2022-02-13 vaiorabbit 68 | 69 | * Removed unavailable inline functions (SDL_memset4, SDL_memcpy4) 70 | 71 | 2022-02-12 vaiorabbit 72 | 73 | * Some tests are now available on Windows 74 | 75 | 2022-01-26 vaiorabbit 76 | 77 | * test/test*.rb: Changed namespace 78 | * load_lib: Now accepts argument 'output_error' 79 | 80 | 2022-01-22 vaiorabbit 81 | 82 | * lib/sdl2_ttf.rb: Generated for version 2.0.18 83 | * generator: Fixed wrong 'by_value' handling 84 | * .gitignore: Added 85 | * test/test_opengl.rb: Use opengl-bindings2 86 | 87 | 2022-01-11 vaiorabbit 88 | 89 | * Added SDL 2.0.20 features ( https://github.com/libsdl-org/SDL/releases/tag/release-2.0.20 ) 90 | 91 | 2021-12-02 vaiorabbit 92 | 93 | * Added SDL 2.0.18 features ( https://github.com/libsdl-org/SDL/releases/tag/release-2.0.18 ) 94 | 95 | 2021-08-12 vaiorabbit 96 | 97 | * Added SDL 2.0.14 features (SDL_misc). 98 | * Added SDL 2.0.16 features (SDL_sensor). 99 | 100 | 2021-02-21 vaiorabbit 101 | 102 | * Added defines from Audio, Mixer and TTF 103 | 104 | 2020-12-27 vaiorabbit 105 | 106 | * Added SDL 2.0.14 features. 107 | * third_party/sdl2_build_dll.sh: Added to build x64 DLL for Windows 108 | * test/util.rb: Added 109 | 110 | 2020-12-20 vaiorabbit 111 | 112 | * third_party/sdl2_build_dylib.sh: Added to build x86_64|arm64 Universal Binary 113 | 114 | 2020-06-08 vaiorabbit 115 | 116 | * lib/sdl2_syswm.rb: Added 117 | * lib/sdl2_hints.rb: Added hint string symboles 118 | 119 | 2020-03-22 vaiorabbit 120 | 121 | * Added SDL 2.0.12 features. 122 | * Generate callback types correctly. 123 | 124 | 2019-10-27 vaiorabbit 125 | 126 | * lib/sdl2_stdinc.rb: Added. 127 | 128 | 2019-08-31 vaiorabbit 129 | 130 | * Refactoring + Cleanup 131 | * Some tests are usable again 132 | 133 | 2019-08-28 vaiorabbit 134 | 135 | * Exception-safety 136 | 137 | 2019-08-27 vaiorabbit 138 | 139 | * lib/sdl2_mixer.rb: Added (experimental) 140 | 141 | 2019-08-24 vaiorabbit 142 | 143 | * Added SDL 2.0.10 features. 144 | * Added generator. Binding codes are generated semi-automatically. 145 | * Now depends on Ruby/FFI. Note that some codes in 'test' directory are still not usable. 146 | 147 | 2016-04-03 vaiorabbit 148 | 149 | * lib/sdl2_gfx.rb, test/test_gfx.rb: Added. 150 | 151 | 2016-04-02 vaiorabbit 152 | 153 | * Added SDL 2.0.4 features. 154 | * lib/version.rb: Added SDL_MAJOR_VERSION, etc. 155 | 156 | 2015-09-29 vaiorabbit 157 | 158 | * lib/sdl2_ttf.rb: Added. 159 | 160 | 2015-09-28 vaiorabbit 161 | 162 | * lib/sdl2_image.rb: Added. 163 | * lib/sdl2_mixer.rb: Added. 164 | 165 | 2015-09-22 vaiorabbit 166 | 167 | * lib/pixels.rb, lib/gamecontroller.rb, lib/joystick.rb: Added. 168 | * lib/rwops.rb, lib/syswm.rb, lib/surface.rb, lib/render.rb: Added. 169 | * lib/cpuinfo.rb, lib/gesture.rb, lib/touch.rb, lib/audio.rb: Added. 170 | 171 | 2015-09-21 vaiorabbit 172 | 173 | * lib/events.rb, lib/timer.rb, lib/video.rb: Added. 174 | * lib/keyboard.rb, lib/keycode.rb, lib/scancode.rb: Added. 175 | * lib/error.rb: Added. 176 | * lib/blendmode.rb, lib/clipboard.rb, lib/filesystem.rb, lib/version.rb: Added. 177 | * lib/platform.rb, lib/rect.rb, lib/mouse.rb: Added. 178 | * lib/messagebox.rb, lib/pixels.rb: Added. 179 | 180 | 2015-09-19 vaiorabbit 181 | 182 | * Project started. 183 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | sdl2-bindings : Yet another SDL2 wrapper for Ruby 2 | Copyright (c) 2015-2024 vaiorabbit 3 | 4 | This software is provided 'as-is', without any express or implied 5 | warranty. In no event will the authors be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this software must not be misrepresented; you must not 13 | claim that you wrote the original software. If you use this software 14 | in a product, an acknowledgment in the product documentation would be 15 | appreciated but is not required. 16 | 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 20 | 3. This notice may not be removed or altered from any source 21 | distribution. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # sdl2-bindings : Yet another SDL2 wrapper for Ruby # 4 | 5 | * Created : 2015-09-19 6 | * Last modified : 2024-02-03 7 | 8 | ## Features ## 9 | 10 | * Generated semi-automatically 11 | * Based on Ruby/FFI 12 | * No need to build C extension library 13 | 14 | See the project below to learn how to use this library: 15 | 16 | * Whac-a-Mole! : Ruby SDL2 bindings demo 17 | * 18 | * [![](http://img.youtube.com/vi/HroP-_EWcg8/mqdefault.jpg)](https://www.youtube.com/watch?v=HroP-_EWcg8) 19 | 20 | ## Limitations ## 21 | 22 | * Several original APIs originally defined with pre-processor macro are unavailable in this library (e.g. `SDL_LoadBMP`) 23 | 24 | ## Target version ## 25 | 26 | * [2024-02-03] 27 | * SDL : 2.30.0~ 28 | * SDL_image : 2.8.2 29 | * SDL_mixer : 2.8.0 30 | * SDL_ttf : 2.22.0 31 | * SDL2_gfx : 1.0.4 32 | * SDL_sound : 2.0.2 33 | 34 |
35 | Older versions 36 | 37 | * [2015-09-19] SDL 2.0.3 38 | * [2016-04-03] SDL 2.0.4 39 | * [2019-08-31] SDL 2.0.10 40 | * [2020-03-22] SDL 2.0.12 41 | * [2020-12-27] SDL 2.0.14 42 | * [2021-08-12] SDL 2.0.16 43 | * [2021-12-02] SDL 2.0.18 44 | * [2022-03-28] 45 | * SDL : 2.0.20 46 | * SDL_image : 2.0.5 47 | * SDL_mixer : 2.0.4 48 | * SDL_ttf : 2.0.18 49 | * SDL2_gfx : 1.0.4 50 | * SDL_sound : 2.0.1 51 | * [2022-04-29] 52 | * SDL : 2.0.22 53 | * SDL_image : 2.0.5 54 | * SDL_mixer : 2.0.4 55 | * SDL_ttf : 2.0.18 56 | * SDL2_gfx : 1.0.4 57 | * SDL_sound : 2.0.1 58 | * [2022-07-31] 59 | * SDL : 2.0.22 60 | * SDL_image : 2.6.0 61 | * SDL_mixer : 2.6.0 62 | * SDL_ttf : 2.20.0 63 | * SDL2_gfx : 1.0.4 64 | * SDL_sound : 2.0.1 65 | * [2022-08-20] 66 | * SDL : 2.24.0 67 | * SDL_image : 2.6.2 68 | * SDL_mixer : 2.6.2 69 | * SDL_ttf : 2.20.1 70 | * SDL2_gfx : 1.0.4 71 | * SDL_sound : 2.0.1 72 | * [2022-10-09] 73 | * SDL : 2.24.1 74 | * SDL_image : 2.6.2 75 | * SDL_mixer : 2.6.2 76 | * SDL_ttf : 2.20.1 77 | * SDL2_gfx : 1.0.4 78 | * SDL_sound : 2.0.1 79 | * [2022-11-03] 80 | * SDL : 2.24.2 81 | * SDL_image : 2.6.2 82 | * SDL_mixer : 2.6.2 83 | * SDL_ttf : 2.20.1 84 | * SDL2_gfx : 1.0.4 85 | * SDL_sound : 2.0.1 86 | * [2022-11-23] 87 | * SDL : 2.26.0 - 2.26.2 88 | * SDL_image : 2.6.2 89 | * SDL_mixer : 2.6.2 90 | * SDL_ttf : 2.20.1 91 | * SDL2_gfx : 1.0.4 92 | * SDL_sound : 2.0.1 93 | * [2023-04-16] 94 | * SDL : 2.26.x 95 | * SDL_image : 2.6.3 96 | * SDL_mixer : 2.6.3 97 | * SDL_ttf : 2.20.2 98 | * SDL2_gfx : 1.0.4 99 | * SDL_sound : 2.0.1 100 | * [2023-06-25] 101 | * SDL : 2.28.x 102 | * SDL_image : 2.6.3 103 | * SDL_mixer : 2.6.3 104 | * SDL_ttf : 2.20.2 105 | * SDL2_gfx : 1.0.4 106 | * SDL_sound : 2.0.1 107 | * [2023-08-10] 108 | * SDL : 2.28.2~ 109 | * SDL_image : 2.6.3 110 | * SDL_mixer : 2.6.3 111 | * SDL_ttf : 2.20.2 112 | * SDL2_gfx : 1.0.4 113 | * SDL_sound : 2.0.1 114 | * [2024-01-28] 115 | * SDL : 2.29.1~ 116 | * SDL_image : 2.8.2 117 | * SDL_mixer : 2.8.0 118 | * SDL_ttf : 2.22.0 119 | * SDL2_gfx : 1.0.4 120 | * SDL_sound : 2.0.2 121 | 122 | 123 |
124 | 125 | ## Supported Environments ## 126 | 127 | * [2023-12-09] macOS Sonoma (14.2.1) ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23] 128 | * [2023-01-07] Windows 11 (22H2), ruby 3.2.0 (2022-12-25 revision a528908271) [x64-mingw-ucrt] 129 | * [2022-10-09] Debian 11 (bullseye) on ASUS Chromebook Detachable CZ1, ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [aarch64-linux] 130 | * [2023-02-05] Ubuntu Linux 22.04 LTS (jammy) on WSL/Windows 11, ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-linux] 131 | 132 |
133 | Older Environments 134 | 135 | * [2023-12-09] macOS Sonoma (14.0) ruby 3.2.1 (2023-02-08 revision 31819e82c8) [arm64-darwin22] 136 | * [2023-01-07] macOS Ventura (13.2.1) ruby 3.2.1 (2023-02-08 revision 31819e82c8) [arm64-darwin22] 137 | * [2022-04-29] Windows 10 (21H1), ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x64-mingw-ucrt] 138 | * [2022-10-09] macOS Monterey (12.5.1), ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21] 139 | * [2022-07-31] macOS Monterey (12.4), ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [arm64-darwin21] 140 | * [2022-02-12] Windows 10 (21H1), ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x64-mingw-ucrt] 141 | * [2022-01-11] macOS Monterey (12.1), ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [arm64-darwin20] 142 | * [2021-12-02] macOS Big Sur (11.6), ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin20] 143 | * [2021-08-12] macOS Big Sur (11.5), ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [arm64-darwin20] 144 | * [2020-12-27] macOS Big Sur (11.0.1), ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm64-darwin20] 145 | * [2016-04-03] Mac OS X 10.11.4, ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] 146 | * [2015-09-19] Mac OS X 10.10.5, ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14] 147 | 148 |
149 | 150 | ## License ## 151 | 152 | The zlib/libpng License ( http://opensource.org/licenses/Zlib ). 153 | 154 | sdl2-bindings : Yet another SDL2 wrapper for Ruby 155 | Copyright (c) 2015-2024 vaiorabbit 156 | 157 | This software is provided 'as-is', without any express or implied 158 | warranty. In no event will the authors be held liable for any damages 159 | arising from the use of this software. 160 | 161 | Permission is granted to anyone to use this software for any purpose, 162 | including commercial applications, and to alter it and redistribute it 163 | freely, subject to the following restrictions: 164 | -------------------------------------------------------------------------------- /generator/README.md: -------------------------------------------------------------------------------- 1 | # Usage # 2 | 3 | These instructions are tested only on macOS environment. 4 | 5 | * Copy SDL2 headers into ./SDL2 6 | * You can also put these headers to make bindings: 7 | * SDL_gfx(SDL2_rotozoom.h, SDL2_imageFilter.h, SDL2_gfxPrimitives.h, SDL2_framerate.h) 8 | * SDL_image (SDL_image.h) 9 | * SDL_mixer (SDL_mixer.h) 10 | * SDL_ttf (SDL_ttf.h) 11 | * SDL_sound (SDL_sound.h) 12 | 13 | * Patch 2 header files manually: 14 | * SDL2/SDL_config_macosx.h : comment out these lines 15 | * '#define HAVE_INTTYPES_H 1' and '#define HAVE_STDINT_H 1' 16 | * SDL2/SDL_stdinc.h : put these typedefs by hand: 17 | 18 | #if defined(HAVE_INTTYPES_H) 19 | # include 20 | #elif defined(HAVE_STDINT_H) 21 | # include 22 | #else // ↓↓↓ 23 | typedef char int8_t; 24 | typedef short int16_t; 25 | typedef int int32_t; 26 | typedef long long int64_t; 27 | typedef unsigned char uint8_t; 28 | typedef unsigned short uint16_t; 29 | typedef unsigned int uint32_t; 30 | typedef unsigned long long uint64_t; 31 | #endif // ↑↑↑ 32 | 33 | * By including 'inttypes.h' or 'stdint.h', all SDL integer types (Sint8, etc.) are interpreted as 'TypeKind.INT'. Since macOS Catalina and CIndex of LLVM 9.0.0, my script cannot resolve integer types into CIndex type kinds (e.g. TypeKind.SCHAR) correctly. 34 | 35 | * Generate mapping tables with ./generate_initial_mapping.sh to get 36 | * sdl2_cindex_mapping.json 37 | * sdl2_define_mapping.json 38 | 39 | * Edit sdl2_define_mapping.json 40 | * This mapping table contains '#define' macros collected from headers in ./SDL2/ folder. 41 | * Each lines represent key-value pair that will be used for generated Python codes. 42 | * ex.) The line collected from './SDL2/SDL.h": 43 | "SDL_INIT_TIMER" : "0x00000001" 44 | will be appeared in sdl2.py: 45 | SDL_INIT_TIMER = 0x00000001 46 | * So if you find value that is inappropreate for Python syntax, 47 | you should fix it or make it 'null'. The 'null'ed marcros will not 48 | appear in the generated Python codes. 49 | 50 | * Run batch_generate.sh 51 | -------------------------------------------------------------------------------- /generator/SDL2/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/sdl2-bindings/61df5ed6d6d870815defa5a6fda2b0d7523e6826/generator/SDL2/.gitkeep -------------------------------------------------------------------------------- /generator/batch_generate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/zsh 2 | export PYTHONPATH=/opt/homebrew/opt/llvm/lib/python3.12/site-packages 3 | /opt/homebrew/bin/python3 generate_SDL.py > ../lib/sdl2_main.rb 4 | /opt/homebrew/bin/python3 generate_SDL_audio.py > ../lib/sdl2_audio.rb 5 | /opt/homebrew/bin/python3 generate_SDL_blendmode.py > ../lib/sdl2_blendmode.rb 6 | /opt/homebrew/bin/python3 generate_SDL_clipboard.py > ../lib/sdl2_clipboard.rb 7 | /opt/homebrew/bin/python3 generate_SDL_cpuinfo.py > ../lib/sdl2_cpuinfo.rb 8 | /opt/homebrew/bin/python3 generate_SDL_error.py > ../lib/sdl2_error.rb 9 | /opt/homebrew/bin/python3 generate_SDL_events.py > ../lib/sdl2_events.rb 10 | /opt/homebrew/bin/python3 generate_SDL_filesystem.py > ../lib/sdl2_filesystem.rb 11 | /opt/homebrew/bin/python3 generate_SDL_gamecontroller.py > ../lib/sdl2_gamecontroller.rb 12 | /opt/homebrew/bin/python3 generate_SDL_gesture.py > ../lib/sdl2_gesture.rb 13 | /opt/homebrew/bin/python3 generate_SDL_guid.py > ../lib/sdl2_guid.rb 14 | /opt/homebrew/bin/python3 generate_SDL_haptic.py > ../lib/sdl2_haptic.rb 15 | /opt/homebrew/bin/python3 generate_SDL_hints.py > ../lib/sdl2_hints.rb 16 | /opt/homebrew/bin/python3 generate_SDL_hidapi.py > ../lib/sdl2_hidapi.rb 17 | /opt/homebrew/bin/python3 generate_SDL_joystick.py > ../lib/sdl2_joystick.rb 18 | /opt/homebrew/bin/python3 generate_SDL_keyboard.py > ../lib/sdl2_keyboard.rb 19 | /opt/homebrew/bin/python3 generate_SDL_keycode.py > ../lib/sdl2_keycode.rb 20 | /opt/homebrew/bin/python3 generate_SDL_log.py > ../lib/sdl2_log.rb 21 | /opt/homebrew/bin/python3 generate_SDL_messagebox.py > ../lib/sdl2_messagebox.rb 22 | /opt/homebrew/bin/python3 generate_SDL_misc.py > ../lib/sdl2_misc.rb 23 | /opt/homebrew/bin/python3 generate_SDL_mouse.py > ../lib/sdl2_mouse.rb 24 | /opt/homebrew/bin/python3 generate_SDL_pixels.py > ../lib/sdl2_pixels.rb 25 | /opt/homebrew/bin/python3 generate_SDL_platform.py > ../lib/sdl2_platform.rb 26 | /opt/homebrew/bin/python3 generate_SDL_power.py > ../lib/sdl2_power.rb 27 | /opt/homebrew/bin/python3 generate_SDL_rect.py > ../lib/sdl2_rect.rb 28 | /opt/homebrew/bin/python3 generate_SDL_render.py > ../lib/sdl2_render.rb 29 | /opt/homebrew/bin/python3 generate_SDL_rwops.py > ../lib/sdl2_rwops.rb 30 | /opt/homebrew/bin/python3 generate_SDL_scancode.py > ../lib/sdl2_scancode.rb 31 | /opt/homebrew/bin/python3 generate_SDL_sensor.py > ../lib/sdl2_sensor.rb 32 | /opt/homebrew/bin/python3 generate_SDL_shape.py > ../lib/sdl2_shape.rb 33 | /opt/homebrew/bin/python3 generate_SDL_surface.py > ../lib/sdl2_surface.rb 34 | /opt/homebrew/bin/python3 generate_SDL_stdinc.py > ../lib/sdl2_stdinc.rb 35 | /opt/homebrew/bin/python3 generate_SDL_syswm.py > ../lib/sdl2_syswm.rb 36 | /opt/homebrew/bin/python3 generate_SDL_timer.py > ../lib/sdl2_timer.rb 37 | /opt/homebrew/bin/python3 generate_SDL_touch.py > ../lib/sdl2_touch.rb 38 | /opt/homebrew/bin/python3 generate_SDL_version.py > ../lib/sdl2_version.rb 39 | /opt/homebrew/bin/python3 generate_SDL_video.py > ../lib/sdl2_video.rb 40 | /opt/homebrew/bin/python3 generate_SDL_vulkan.py > ../lib/sdl2_vulkan.rb 41 | 42 | /opt/homebrew/bin/python3 generate_SDL_ttf.py > ../lib/sdl2_ttf.rb 43 | /opt/homebrew/bin/python3 generate_SDL_image.py > ../lib/sdl2_image.rb 44 | /opt/homebrew/bin/python3 generate_SDL_mixer.py > ../lib/sdl2_mixer.rb 45 | /opt/homebrew/bin/python3 generate_SDL2_gfxPrimitives.py > ../lib/sdl2_gfxPrimitives.rb 46 | /opt/homebrew/bin/python3 generate_SDL2_rotozoom.py > ../lib/sdl2_rotozoom.rb 47 | /opt/homebrew/bin/python3 generate_SDL2_imageFilter.py > ../lib/sdl2_imageFilter.rb 48 | /opt/homebrew/bin/python3 generate_SDL2_framerate.py > ../lib/sdl2_framerate.rb 49 | /opt/homebrew/bin/python3 generate_SDL_sound.py > ../lib/sdl2_sound.rb 50 | 51 | -------------------------------------------------------------------------------- /generator/generate_SDL.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'main') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL2_framerate.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL2_framerate.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, 10 | setup_method_name = 'gfx_framerate') 11 | -------------------------------------------------------------------------------- /generator/generate_SDL2_gfxPrimitives.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL2_gfxPrimitives.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, 10 | setup_method_name = 'gfx_primitives') 11 | -------------------------------------------------------------------------------- /generator/generate_SDL2_imageFilter.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL2_imageFilter.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, 10 | setup_method_name = 'gfx_imagefilter') 11 | -------------------------------------------------------------------------------- /generator/generate_SDL2_rotozoom.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL2_rotozoom.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, 10 | setup_method_name = 'gfx_rotozoom') 11 | -------------------------------------------------------------------------------- /generator/generate_SDL_audio.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | POSTFIX_AUDIO = """ 4 | # TODO : def SDL_LoadWAV 5 | """ 6 | 7 | if __name__ == "__main__": 8 | 9 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_audio.h') 10 | sdl2_parser.execute(ctx) 11 | 12 | sdl2_generator.sanitize(ctx) 13 | sdl2_generator.generate(ctx, postfix = sdl2_generator.POSTFIX + POSTFIX_AUDIO, 14 | setup_method_name = 'audio', 15 | ) 16 | -------------------------------------------------------------------------------- /generator/generate_SDL_blendmode.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_blendmode.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'blendmode') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_clipboard.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_clipboard.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'clipboard') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_cpuinfo.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_cpuinfo.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'cpuinfo') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_error.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_error.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'error') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_events.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_events.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, 10 | prefix = sdl2_generator.PREFIX + "require_relative 'sdl2_keyboard'\n", 11 | setup_method_name = 'events' 12 | ) 13 | -------------------------------------------------------------------------------- /generator/generate_SDL_filesystem.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_filesystem.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'filesystem') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_gamecontroller.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | TYPEDEF_PREFIX_GAMECONTROLLER = """ 4 | class GameControllerButtonBind_value_hat < FFI::Struct 5 | layout( 6 | :hat, :int, 7 | :hat_mask, :int, 8 | ) 9 | end 10 | 11 | class GameControllerButtonBind_value < FFI::Struct 12 | layout( 13 | :button, :int, 14 | :axis, :int, 15 | :hat, GameControllerButtonBind_value_hat, 16 | ) 17 | end 18 | 19 | class GameControllerButtonBind < FFI::Struct 20 | layout( 21 | :bindType, :int, 22 | :value, GameControllerButtonBind_value, 23 | ) 24 | end 25 | """ 26 | 27 | if __name__ == "__main__": 28 | 29 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_gamecontroller.h') 30 | sdl2_parser.execute(ctx) 31 | 32 | # TODO : Merge anonymous structs into one union (e.g. SDL_RWops) 33 | # 34 | # SDL_GameControllerButtonBind is a bit complicated so I unfortunately have to 35 | # substitute the parsed definition with my handwritten one. 36 | ctx.decl_structs['SDL_GameControllerButtonBind'] = None 37 | 38 | sdl2_generator.sanitize(ctx) 39 | sdl2_generator.generate(ctx, 40 | prefix = sdl2_generator.PREFIX + "require_relative 'sdl2_joystick'\n", 41 | typedef_prefix = TYPEDEF_PREFIX_GAMECONTROLLER, 42 | setup_method_name = 'gamecontroller' 43 | ) 44 | -------------------------------------------------------------------------------- /generator/generate_SDL_gesture.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_gesture.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'gesture') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_guid.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_guid.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'guid') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_haptic.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_haptic.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'haptic') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_hidapi.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_hidapi.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'hidapi') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_hints.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_hints.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'hints') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_image.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_image.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, 10 | setup_method_name = 'image' 11 | ) 12 | -------------------------------------------------------------------------------- /generator/generate_SDL_joystick.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | TYPEDEF_PREFIX_JOYSTICK = """ 4 | JoystickGUID = SDL::GUID 5 | """ 6 | 7 | if __name__ == "__main__": 8 | 9 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_joystick.h') 10 | sdl2_parser.execute(ctx) 11 | 12 | ctx.decl_structs['JoystickGUID'] = None 13 | 14 | sdl2_generator.sanitize(ctx) 15 | sdl2_generator.generate(ctx, 16 | prefix = sdl2_generator.PREFIX + "require_relative 'sdl2_guid'\n", 17 | typedef_prefix = TYPEDEF_PREFIX_JOYSTICK, 18 | setup_method_name = 'joystick') 19 | -------------------------------------------------------------------------------- /generator/generate_SDL_keyboard.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_keyboard.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'keyboard') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_keycode.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | POSTFIX_KEYCODE = """ 4 | # TODO #define KMOD_CTRL, #define KMOD_SHIFT, #define KMOD_ALT and #define KMOD_GUI 5 | """ 6 | 7 | if __name__ == "__main__": 8 | 9 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_keycode.h') 10 | sdl2_parser.execute(ctx) 11 | 12 | sdl2_generator.sanitize(ctx) 13 | sdl2_generator.generate(ctx, postfix = sdl2_generator.POSTFIX + POSTFIX_KEYCODE, 14 | setup_method_name = 'keycode') 15 | -------------------------------------------------------------------------------- /generator/generate_SDL_log.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_log.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | ctx.decl_functions['SDL_LogMessageV'] = None 9 | 10 | sdl2_generator.sanitize(ctx) 11 | sdl2_generator.generate(ctx, setup_method_name = 'log') 12 | -------------------------------------------------------------------------------- /generator/generate_SDL_messagebox.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_messagebox.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'messagebox') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_misc.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_misc.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'misc') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_mixer.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_mixer.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, 10 | setup_method_name = 'mixer' 11 | ) 12 | -------------------------------------------------------------------------------- /generator/generate_SDL_mouse.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | POSTFIX_MOUSE = """ 4 | # TODO : def self.BUTTON(X); (1 << ((X)-1)); end; 5 | """ 6 | 7 | if __name__ == "__main__": 8 | 9 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_mouse.h') 10 | sdl2_parser.execute(ctx) 11 | 12 | sdl2_generator.sanitize(ctx) 13 | sdl2_generator.generate(ctx, postfix = sdl2_generator.POSTFIX + POSTFIX_MOUSE, 14 | setup_method_name = 'mouse') 15 | -------------------------------------------------------------------------------- /generator/generate_SDL_pixels.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_pixels.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'pixels') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_platform.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_platform.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'platform') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_power.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_power.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'power') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_rect.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | TYPEDEF_PREFIX_RECT = """ 4 | def self.PointInRect(p, r) 5 | return ( (p.x >= r.x) && (p.x < (r.x + r.w)) && (p.y >= r.y) && (p.y < (r.y + r.h)) ) ? 1 : 0; 6 | end 7 | 8 | def self.RectEmpty(r) 9 | return (!r.null? || (r.w <= 0) || (r.h <= 0)) ? 1 : 0 10 | end 11 | 12 | def self.RectEquals(a, b) 13 | return (!a.null? && !b.null? && (a.x == b.x) && (a.y == b.y) && (a.w == b.w) && (a.h == b.h)) ? 1 : 0 14 | end 15 | """ 16 | 17 | if __name__ == "__main__": 18 | 19 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_rect.h') 20 | sdl2_parser.execute(ctx) 21 | 22 | ctx.decl_functions['SDL_PointInRect'] = None 23 | ctx.decl_functions['SDL_RectEmpty'] = None 24 | ctx.decl_functions['SDL_RectEquals'] = None 25 | 26 | sdl2_generator.sanitize(ctx) 27 | sdl2_generator.generate(ctx, 28 | typedef_prefix = TYPEDEF_PREFIX_RECT, 29 | setup_method_name = 'rect') 30 | -------------------------------------------------------------------------------- /generator/generate_SDL_render.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_render.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'render') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_rwops.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | TYPEDEF_PREFIX_RWOPS = """ 4 | RW_SEEK_SET = 0 5 | RW_SEEK_CUR = 1 6 | RW_SEEK_END = 2 7 | 8 | class RWops_mem < FFI::Struct 9 | layout( 10 | :base, :pointer, 11 | :here, :pointer, 12 | :stop, :pointer, 13 | ) 14 | end 15 | 16 | class RWops_unknown < FFI::Struct 17 | layout( 18 | :data1, :pointer, 19 | :data2, :pointer, 20 | ) 21 | end 22 | class RWops_windowsio_buffer < FFI::Struct 23 | layout( 24 | :data, :pointer, 25 | :size, :size_t, 26 | :left, :size_t, 27 | ) 28 | end 29 | 30 | class RWops_windowsio < FFI::Struct 31 | layout( 32 | :append, :int, 33 | :h, :pointer, 34 | :buffer, RWops_windowsio_buffer, 35 | ) 36 | end 37 | 38 | class Default_RWops_hidden < FFI::Union 39 | layout( 40 | :mem, RWops_mem, 41 | :unknown, RWops_unknown, 42 | ) 43 | end 44 | 45 | class Win32_RWops_hidden < FFI::Union 46 | layout( 47 | :mem, RWops_mem, 48 | :unknown, RWops_unknown, 49 | :windowsio, RWops_windowsio, 50 | ) 51 | end 52 | 53 | class Default_RWops < FFI::Struct 54 | layout( 55 | :size, :pointer, 56 | :seek, :pointer, 57 | :read, :pointer, 58 | :write, :pointer, 59 | :close, :pointer, 60 | :type, :uint, 61 | :hidden, Default_RWops_hidden, 62 | ) 63 | end 64 | 65 | class Win32_RWops < FFI::Struct 66 | layout( 67 | :size, :pointer, 68 | :seek, :pointer, 69 | :read, :pointer, 70 | :write, :pointer, 71 | :close, :pointer, 72 | :type, :uint, 73 | :hidden, Win32_RWops_hidden 74 | ) 75 | end 76 | 77 | if RUBY_PLATFORM =~ /mswin|msys|mingw|cygwin/ 78 | RWops = Win32_RWops 79 | else 80 | RWops = Default_RWops 81 | end 82 | """ 83 | 84 | if __name__ == "__main__": 85 | 86 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_rwops.h') 87 | sdl2_parser.execute(ctx) 88 | 89 | # TODO : Merge anonymous structs into one union (e.g. SDL_RWops) 90 | # 91 | # SDL_RWops is a bit complicated so I unfortunately have to 92 | # substitute the parsed definition with my handwritten one. 93 | ctx.decl_structs['SDL_RWops'] = None 94 | 95 | sdl2_generator.sanitize(ctx) 96 | sdl2_generator.generate(ctx, 97 | typedef_prefix = TYPEDEF_PREFIX_RWOPS, 98 | setup_method_name = 'rwops' 99 | ) 100 | -------------------------------------------------------------------------------- /generator/generate_SDL_scancode.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_scancode.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'scancode') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_sensor.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_sensor.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'sensor') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_shape.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_shape.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, 10 | prefix = sdl2_generator.PREFIX + "require_relative 'sdl2_pixels'\n", 11 | setup_method_name = 'shape' 12 | ) 13 | -------------------------------------------------------------------------------- /generator/generate_SDL_sound.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_sound.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'sound') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_stdinc.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_stdinc.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | ctx.decl_functions['SDL_memset4'] = None 9 | ctx.decl_functions['SDL_memcpy4'] = None 10 | ctx.decl_functions['SDL_size_mul_overflow'] = None 11 | ctx.decl_functions['SDL_size_add_overflow'] = None 12 | ctx.decl_functions['_SDL_size_mul_overflow_builtin'] = None 13 | ctx.decl_functions['_SDL_size_add_overflow_builtin'] = None 14 | ctx.decl_typedefs['SDL_compile_time_assert_uint8'] = None 15 | ctx.decl_typedefs['SDL_compile_time_assert_sint8'] = None 16 | ctx.decl_typedefs['SDL_compile_time_assert_uint16'] = None 17 | ctx.decl_typedefs['SDL_compile_time_assert_sint16'] = None 18 | ctx.decl_typedefs['SDL_compile_time_assert_uint32'] = None 19 | ctx.decl_typedefs['SDL_compile_time_assert_sint32'] = None 20 | ctx.decl_typedefs['SDL_compile_time_assert_uint64'] = None 21 | ctx.decl_typedefs['SDL_compile_time_assert_sint64'] = None 22 | ctx.decl_typedefs['SDL_DUMMY_ENUM'] = None 23 | ctx.decl_typedefs['SDL_compile_time_assert_enum'] = None 24 | 25 | ctx.decl_enums = {k:v for k, v in ctx.decl_enums.items() if v[0][0] != 'DUMMY_ENUM_VALUE'} # Omit 'DUMMY_ENUM_VALUE' from enum declarations 26 | 27 | sdl2_generator.sanitize(ctx) 28 | sdl2_generator.generate(ctx, setup_method_name = 'stdinc') 29 | -------------------------------------------------------------------------------- /generator/generate_SDL_surface.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_surface.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, 10 | prefix = sdl2_generator.PREFIX + "require_relative 'sdl2_rect'\n", 11 | setup_method_name = 'surface' 12 | ) 13 | -------------------------------------------------------------------------------- /generator/generate_SDL_syswm.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | TYPEDEF_POSTFIX_SYSWM = """ 4 | class SysWMmsg_def_win < FFI::Struct 5 | layout( 6 | :hwnd, :pointer, 7 | :msg, :uint32, 8 | :wParam, :uint64, 9 | :lParam, :int64 10 | ) 11 | end 12 | 13 | class SysWMmsg_value_win < FFI::Union 14 | layout( 15 | :win, SysWMmsg_def_win.by_value, 16 | :dummy, :int 17 | ) 18 | end 19 | 20 | class SysWMmsg_win < FFI::Struct 21 | layout( 22 | :version, Version.by_value, 23 | :subsystem, :int, 24 | :msg, SysWMmsg_value_win.by_value 25 | ) 26 | end 27 | 28 | 29 | class SysWMmsg_def_cocoa < FFI::Struct 30 | layout( 31 | :dummy, :int 32 | ) 33 | end 34 | 35 | class SysWMmsg_value_cocoa < FFI::Union 36 | layout( 37 | :cocoa, SysWMmsg_def_cocoa.by_value, 38 | :dummy, :int 39 | ) 40 | end 41 | 42 | class SysWMmsg_cocoa < FFI::Struct 43 | layout( 44 | :version, Version.by_value, 45 | :subsystem, :int, 46 | :msg, SysWMmsg_value_cocoa.by_value 47 | ) 48 | end 49 | 50 | 51 | class SysWMmsg_def_x11 < FFI::Struct 52 | layout( 53 | :event, [:long, 24] # /usr/include/X11/Xlib.h 54 | ) 55 | end 56 | 57 | class SysWMmsg_value_x11 < FFI::Union 58 | layout( 59 | :x11, SysWMmsg_def_x11.by_value, 60 | :dummy, :int 61 | ) 62 | end 63 | 64 | class SysWMmsg_x11 < FFI::Struct 65 | layout( 66 | :version, Version.by_value, 67 | :subsystem, :int, 68 | :msg, SysWMmsg_value_x11.by_value 69 | ) 70 | end 71 | 72 | ################################################################################ 73 | 74 | class SysWMinfo_def_win < FFI::Struct 75 | layout( 76 | :window, :pointer, 77 | :hdc, :pointer, 78 | :hinstance, :pointer 79 | ) 80 | end 81 | 82 | class SysWMinfo_value_win < FFI::Union 83 | layout( 84 | :win, SysWMinfo_def_win.by_value, 85 | :dummy, [:uint8, 64] 86 | ) 87 | end 88 | 89 | class SysWMinfo_win < FFI::Struct 90 | layout( 91 | :version, Version.by_value, 92 | :subsystem, :int, 93 | :info, SysWMinfo_value_win.by_value 94 | ) 95 | end 96 | 97 | 98 | class SysWMinfo_def_cocoa < FFI::Struct 99 | layout( 100 | :window, :pointer 101 | ) 102 | end 103 | 104 | class SysWMinfo_value_cocoa < FFI::Union 105 | layout( 106 | :cocoa, SysWMinfo_def_cocoa.by_value, 107 | :dummy, [:uint8, 64] 108 | ) 109 | end 110 | 111 | class SysWMinfo_cocoa < FFI::Struct 112 | layout( 113 | :version, Version.by_value, 114 | :subsystem, :int, 115 | :info, SysWMinfo_value_cocoa.by_value 116 | ) 117 | end 118 | 119 | 120 | class SysWMinfo_def_x11 < FFI::Struct 121 | layout( 122 | :display, :pointer, 123 | :window, :ulong # /usr/include/X11/X.h 124 | ) 125 | end 126 | 127 | class SysWMinfo_value_x11 < FFI::Union 128 | layout( 129 | :x11, SysWMinfo_def_x11.by_value, 130 | :dummy, [:uint8, 64] 131 | ) 132 | end 133 | 134 | class SysWMinfo_x11 < FFI::Struct 135 | layout( 136 | :version, Version.by_value, 137 | :subsystem, :int, 138 | :info, SysWMinfo_value_x11.by_value 139 | ) 140 | end 141 | 142 | 143 | class SysWMinfo_def_wl < FFI::Struct 144 | layout( 145 | :display, :pointer, 146 | :surface, :pointer, 147 | :shell_surface, :pointer, 148 | :egl_window, :pointer, 149 | :xdg_surface, :pointer, 150 | :xdg_toplevel, :pointer, 151 | :xdg_popup, :pointer, 152 | :xdg_positioner, :pointer 153 | ) 154 | end 155 | 156 | class SysWMinfo_value_wl < FFI::Union 157 | layout( 158 | :wl, SysWMinfo_def_wl.by_value, 159 | :dummy, [:uint8, 64] 160 | ) 161 | end 162 | 163 | class SysWMinfo_wl < FFI::Struct 164 | layout( 165 | :version, Version.by_value, 166 | :subsystem, :int, 167 | :info, SysWMinfo_value_wl.by_value 168 | ) 169 | end 170 | """ 171 | 172 | if __name__ == "__main__": 173 | 174 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_syswm.h') 175 | sdl2_parser.execute(ctx) 176 | 177 | # TODO : generate union automatically 178 | ctx.decl_structs['SDL_SysWMmsg'] = None 179 | ctx.decl_structs['SDL_SysWMinfo'] = None 180 | 181 | sdl2_generator.sanitize(ctx) 182 | sdl2_generator.generate(ctx, 183 | prefix = sdl2_generator.PREFIX + "require_relative 'sdl2_version'\n", 184 | typedef_postfix = TYPEDEF_POSTFIX_SYSWM, 185 | setup_method_name = 'syswm') 186 | -------------------------------------------------------------------------------- /generator/generate_SDL_timer.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_timer.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'timer') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_touch.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_touch.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'touch') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_ttf.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_ttf.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, 10 | prefix = sdl2_generator.PREFIX + 11 | "require_relative 'sdl2_pixels'\n", 12 | setup_method_name = 'ttf' 13 | ) 14 | -------------------------------------------------------------------------------- /generator/generate_SDL_version.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_version.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'version') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_video.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_video.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'video') 10 | -------------------------------------------------------------------------------- /generator/generate_SDL_vulkan.py: -------------------------------------------------------------------------------- 1 | import sdl2_parser, sdl2_generator 2 | 3 | if __name__ == "__main__": 4 | 5 | ctx = sdl2_parser.ParseContext('./SDL2/SDL_vulkan.h') 6 | sdl2_parser.execute(ctx) 7 | 8 | sdl2_generator.sanitize(ctx) 9 | sdl2_generator.generate(ctx, setup_method_name = 'vulkan') 10 | -------------------------------------------------------------------------------- /generator/generate_initial_cindex_mapping.py: -------------------------------------------------------------------------------- 1 | # PYTHONPATH=/usr/local/Cellar/llvm/7.0.0/lib/python2.7/site-packages python generate_initial_cindex_mapping.py > sdl2_cindex_mapping.json 2 | 3 | import sdl2_parser, sdl2_generator 4 | 5 | if __name__ == "__main__": 6 | sdl2_parser.generate_type_mapping() 7 | -------------------------------------------------------------------------------- /generator/generate_initial_define_mapping.py: -------------------------------------------------------------------------------- 1 | # PYTHONPATH=/usr/local/Cellar/llvm/6.0.0/lib/python2.7/site-packages python generate_initial_define_mapping.py > sdl2_define_mapping.json 2 | 3 | import sdl2_parser, sdl2_generator 4 | 5 | if __name__ == "__main__": 6 | sdl2_parser.generate_define_list() 7 | -------------------------------------------------------------------------------- /generator/generate_initial_mapping.sh: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/zsh 2 | export PYTHONPATH=/opt/homebrew/opt/llvm/lib/python3.12/site-packages 3 | /opt/homebrew/bin/python3 generate_initial_cindex_mapping.py > sdl2_cindex_mapping.json 4 | /opt/homebrew/bin/python3 generate_initial_define_mapping.py > sdl2_define_mapping.json 5 | -------------------------------------------------------------------------------- /generator/sdl2_headers_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | "SDL.h", 3 | "SDL_assert.h", 4 | "SDL_atomic.h", 5 | "SDL_audio.h", 6 | "SDL_bits.h", 7 | "SDL_blendmode.h", 8 | "SDL_clipboard.h", 9 | "SDL_cpuinfo.h", 10 | "SDL_endian.h", 11 | "SDL_error.h", 12 | "SDL_events.h", 13 | "SDL_filesystem.h", 14 | "SDL_gamecontroller.h", 15 | "SDL_gesture.h", 16 | "SDL_guid.h", 17 | "SDL_haptic.h", 18 | "SDL_hints.h", 19 | "SDL_joystick.h", 20 | "SDL_keyboard.h", 21 | "SDL_keycode.h", 22 | "SDL_loadso.h", 23 | "SDL_log.h", 24 | "SDL_main.h", 25 | "SDL_messagebox.h", 26 | "SDL_mouse.h", 27 | "SDL_mutex.h", 28 | "SDL_name.h", 29 | "SDL_pixels.h", 30 | "SDL_platform.h", 31 | "SDL_power.h", 32 | "SDL_quit.h", 33 | "SDL_rect.h", 34 | "SDL_render.h", 35 | "SDL_revision.h", 36 | "SDL_rwops.h", 37 | "SDL_scancode.h", 38 | "SDL_sensor.h", 39 | "SDL_shape.h", 40 | "SDL_stdinc.h", 41 | "SDL_surface.h", 42 | "SDL_system.h", 43 | "SDL_syswm.h", 44 | "SDL_thread.h", 45 | "SDL_timer.h", 46 | "SDL_touch.h", 47 | "SDL_version.h", 48 | "SDL_video.h", 49 | "SDL_vulkan.h", 50 | 51 | "SDL_ttf.h", 52 | "SDL_image.h", 53 | "SDL_mixer.h", 54 | "SDL2_framerate.h", 55 | "SDL2_gfxPrimitives.h", 56 | "SDL2_imageFilter.h", 57 | "SDL2_rotozoom.h", 58 | "SDL_sound.h" 59 | ] 60 | -------------------------------------------------------------------------------- /lib/sdl2.rb: -------------------------------------------------------------------------------- 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 132 | -------------------------------------------------------------------------------- /lib/sdl2_blendmode.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | BLENDMODE_NONE = 0 17 | BLENDMODE_BLEND = 1 18 | BLENDMODE_ADD = 2 19 | BLENDMODE_MOD = 4 20 | BLENDMODE_MUL = 8 21 | BLENDMODE_INVALID = 2147483647 22 | BLENDOPERATION_ADD = 1 23 | BLENDOPERATION_SUBTRACT = 2 24 | BLENDOPERATION_REV_SUBTRACT = 3 25 | BLENDOPERATION_MINIMUM = 4 26 | BLENDOPERATION_MAXIMUM = 5 27 | BLENDFACTOR_ZERO = 1 28 | BLENDFACTOR_ONE = 2 29 | BLENDFACTOR_SRC_COLOR = 3 30 | BLENDFACTOR_ONE_MINUS_SRC_COLOR = 4 31 | BLENDFACTOR_SRC_ALPHA = 5 32 | BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 6 33 | BLENDFACTOR_DST_COLOR = 7 34 | BLENDFACTOR_ONE_MINUS_DST_COLOR = 8 35 | BLENDFACTOR_DST_ALPHA = 9 36 | BLENDFACTOR_ONE_MINUS_DST_ALPHA = 10 37 | 38 | # Typedef 39 | 40 | typedef :int, :SDL_BlendMode 41 | typedef :int, :SDL_BlendOperation 42 | typedef :int, :SDL_BlendFactor 43 | 44 | # Struct 45 | 46 | 47 | # Function 48 | 49 | def self.setup_blendmode_symbols(output_error = false) 50 | symbols = [ 51 | :SDL_ComposeCustomBlendMode, 52 | ] 53 | apis = { 54 | :SDL_ComposeCustomBlendMode => :ComposeCustomBlendMode, 55 | } 56 | args = { 57 | :SDL_ComposeCustomBlendMode => [:int, :int, :int, :int, :int, :int], 58 | } 59 | retvals = { 60 | :SDL_ComposeCustomBlendMode => :int, 61 | } 62 | symbols.each do |sym| 63 | begin 64 | attach_function apis[sym], sym, args[sym], retvals[sym] 65 | rescue FFI::NotFoundError => error 66 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 67 | end 68 | end 69 | end 70 | 71 | end 72 | 73 | -------------------------------------------------------------------------------- /lib/sdl2_clipboard.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | # Struct 21 | 22 | 23 | # Function 24 | 25 | def self.setup_clipboard_symbols(output_error = false) 26 | symbols = [ 27 | :SDL_SetClipboardText, 28 | :SDL_GetClipboardText, 29 | :SDL_HasClipboardText, 30 | :SDL_SetPrimarySelectionText, 31 | :SDL_GetPrimarySelectionText, 32 | :SDL_HasPrimarySelectionText, 33 | ] 34 | apis = { 35 | :SDL_SetClipboardText => :SetClipboardText, 36 | :SDL_GetClipboardText => :GetClipboardText, 37 | :SDL_HasClipboardText => :HasClipboardText, 38 | :SDL_SetPrimarySelectionText => :SetPrimarySelectionText, 39 | :SDL_GetPrimarySelectionText => :GetPrimarySelectionText, 40 | :SDL_HasPrimarySelectionText => :HasPrimarySelectionText, 41 | } 42 | args = { 43 | :SDL_SetClipboardText => [:pointer], 44 | :SDL_GetClipboardText => [], 45 | :SDL_HasClipboardText => [], 46 | :SDL_SetPrimarySelectionText => [:pointer], 47 | :SDL_GetPrimarySelectionText => [], 48 | :SDL_HasPrimarySelectionText => [], 49 | } 50 | retvals = { 51 | :SDL_SetClipboardText => :int, 52 | :SDL_GetClipboardText => :pointer, 53 | :SDL_HasClipboardText => :int, 54 | :SDL_SetPrimarySelectionText => :int, 55 | :SDL_GetPrimarySelectionText => :pointer, 56 | :SDL_HasPrimarySelectionText => :int, 57 | } 58 | symbols.each do |sym| 59 | begin 60 | attach_function apis[sym], sym, args[sym], retvals[sym] 61 | rescue FFI::NotFoundError => error 62 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 63 | end 64 | end 65 | end 66 | 67 | end 68 | 69 | -------------------------------------------------------------------------------- /lib/sdl2_cpuinfo.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | CACHELINE_SIZE = 128 14 | 15 | # Enum 16 | 17 | 18 | # Typedef 19 | 20 | 21 | # Struct 22 | 23 | 24 | # Function 25 | 26 | def self.setup_cpuinfo_symbols(output_error = false) 27 | symbols = [ 28 | :SDL_GetCPUCount, 29 | :SDL_GetCPUCacheLineSize, 30 | :SDL_HasRDTSC, 31 | :SDL_HasAltiVec, 32 | :SDL_HasMMX, 33 | :SDL_Has3DNow, 34 | :SDL_HasSSE, 35 | :SDL_HasSSE2, 36 | :SDL_HasSSE3, 37 | :SDL_HasSSE41, 38 | :SDL_HasSSE42, 39 | :SDL_HasAVX, 40 | :SDL_HasAVX2, 41 | :SDL_HasAVX512F, 42 | :SDL_HasARMSIMD, 43 | :SDL_HasNEON, 44 | :SDL_HasLSX, 45 | :SDL_HasLASX, 46 | :SDL_GetSystemRAM, 47 | :SDL_SIMDGetAlignment, 48 | :SDL_SIMDAlloc, 49 | :SDL_SIMDRealloc, 50 | :SDL_SIMDFree, 51 | ] 52 | apis = { 53 | :SDL_GetCPUCount => :GetCPUCount, 54 | :SDL_GetCPUCacheLineSize => :GetCPUCacheLineSize, 55 | :SDL_HasRDTSC => :HasRDTSC, 56 | :SDL_HasAltiVec => :HasAltiVec, 57 | :SDL_HasMMX => :HasMMX, 58 | :SDL_Has3DNow => :Has3DNow, 59 | :SDL_HasSSE => :HasSSE, 60 | :SDL_HasSSE2 => :HasSSE2, 61 | :SDL_HasSSE3 => :HasSSE3, 62 | :SDL_HasSSE41 => :HasSSE41, 63 | :SDL_HasSSE42 => :HasSSE42, 64 | :SDL_HasAVX => :HasAVX, 65 | :SDL_HasAVX2 => :HasAVX2, 66 | :SDL_HasAVX512F => :HasAVX512F, 67 | :SDL_HasARMSIMD => :HasARMSIMD, 68 | :SDL_HasNEON => :HasNEON, 69 | :SDL_HasLSX => :HasLSX, 70 | :SDL_HasLASX => :HasLASX, 71 | :SDL_GetSystemRAM => :GetSystemRAM, 72 | :SDL_SIMDGetAlignment => :SIMDGetAlignment, 73 | :SDL_SIMDAlloc => :SIMDAlloc, 74 | :SDL_SIMDRealloc => :SIMDRealloc, 75 | :SDL_SIMDFree => :SIMDFree, 76 | } 77 | args = { 78 | :SDL_GetCPUCount => [], 79 | :SDL_GetCPUCacheLineSize => [], 80 | :SDL_HasRDTSC => [], 81 | :SDL_HasAltiVec => [], 82 | :SDL_HasMMX => [], 83 | :SDL_Has3DNow => [], 84 | :SDL_HasSSE => [], 85 | :SDL_HasSSE2 => [], 86 | :SDL_HasSSE3 => [], 87 | :SDL_HasSSE41 => [], 88 | :SDL_HasSSE42 => [], 89 | :SDL_HasAVX => [], 90 | :SDL_HasAVX2 => [], 91 | :SDL_HasAVX512F => [], 92 | :SDL_HasARMSIMD => [], 93 | :SDL_HasNEON => [], 94 | :SDL_HasLSX => [], 95 | :SDL_HasLASX => [], 96 | :SDL_GetSystemRAM => [], 97 | :SDL_SIMDGetAlignment => [], 98 | :SDL_SIMDAlloc => [:ulong], 99 | :SDL_SIMDRealloc => [:pointer, :ulong], 100 | :SDL_SIMDFree => [:pointer], 101 | } 102 | retvals = { 103 | :SDL_GetCPUCount => :int, 104 | :SDL_GetCPUCacheLineSize => :int, 105 | :SDL_HasRDTSC => :int, 106 | :SDL_HasAltiVec => :int, 107 | :SDL_HasMMX => :int, 108 | :SDL_Has3DNow => :int, 109 | :SDL_HasSSE => :int, 110 | :SDL_HasSSE2 => :int, 111 | :SDL_HasSSE3 => :int, 112 | :SDL_HasSSE41 => :int, 113 | :SDL_HasSSE42 => :int, 114 | :SDL_HasAVX => :int, 115 | :SDL_HasAVX2 => :int, 116 | :SDL_HasAVX512F => :int, 117 | :SDL_HasARMSIMD => :int, 118 | :SDL_HasNEON => :int, 119 | :SDL_HasLSX => :int, 120 | :SDL_HasLASX => :int, 121 | :SDL_GetSystemRAM => :int, 122 | :SDL_SIMDGetAlignment => :ulong, 123 | :SDL_SIMDAlloc => :pointer, 124 | :SDL_SIMDRealloc => :pointer, 125 | :SDL_SIMDFree => :void, 126 | } 127 | symbols.each do |sym| 128 | begin 129 | attach_function apis[sym], sym, args[sym], retvals[sym] 130 | rescue FFI::NotFoundError => error 131 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 132 | end 133 | end 134 | end 135 | 136 | end 137 | 138 | -------------------------------------------------------------------------------- /lib/sdl2_error.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | ENOMEM = 0 17 | EFREAD = 1 18 | EFWRITE = 2 19 | EFSEEK = 3 20 | UNSUPPORTED = 4 21 | LASTERROR = 5 22 | 23 | # Typedef 24 | 25 | typedef :int, :SDL_errorcode 26 | 27 | # Struct 28 | 29 | 30 | # Function 31 | 32 | def self.setup_error_symbols(output_error = false) 33 | symbols = [ 34 | :SDL_SetError, 35 | :SDL_GetError, 36 | :SDL_GetErrorMsg, 37 | :SDL_ClearError, 38 | :SDL_Error, 39 | ] 40 | apis = { 41 | :SDL_SetError => :SetError, 42 | :SDL_GetError => :GetError, 43 | :SDL_GetErrorMsg => :GetErrorMsg, 44 | :SDL_ClearError => :ClearError, 45 | :SDL_Error => :Error, 46 | } 47 | args = { 48 | :SDL_SetError => [:pointer], 49 | :SDL_GetError => [], 50 | :SDL_GetErrorMsg => [:pointer, :int], 51 | :SDL_ClearError => [], 52 | :SDL_Error => [:int], 53 | } 54 | retvals = { 55 | :SDL_SetError => :int, 56 | :SDL_GetError => :pointer, 57 | :SDL_GetErrorMsg => :pointer, 58 | :SDL_ClearError => :void, 59 | :SDL_Error => :int, 60 | } 61 | symbols.each do |sym| 62 | begin 63 | attach_function apis[sym], sym, args[sym], retvals[sym] 64 | rescue FFI::NotFoundError => error 65 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 66 | end 67 | end 68 | end 69 | 70 | end 71 | 72 | -------------------------------------------------------------------------------- /lib/sdl2_filesystem.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | # Struct 21 | 22 | 23 | # Function 24 | 25 | def self.setup_filesystem_symbols(output_error = false) 26 | symbols = [ 27 | :SDL_GetBasePath, 28 | :SDL_GetPrefPath, 29 | ] 30 | apis = { 31 | :SDL_GetBasePath => :GetBasePath, 32 | :SDL_GetPrefPath => :GetPrefPath, 33 | } 34 | args = { 35 | :SDL_GetBasePath => [], 36 | :SDL_GetPrefPath => [:pointer, :pointer], 37 | } 38 | retvals = { 39 | :SDL_GetBasePath => :pointer, 40 | :SDL_GetPrefPath => :pointer, 41 | } 42 | symbols.each do |sym| 43 | begin 44 | attach_function apis[sym], sym, args[sym], retvals[sym] 45 | rescue FFI::NotFoundError => error 46 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 47 | end 48 | end 49 | end 50 | 51 | end 52 | 53 | -------------------------------------------------------------------------------- /lib/sdl2_framerate.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | # Struct 21 | 22 | class FPSmanager < FFI::Struct 23 | layout( 24 | :framecount, :uint, 25 | :rateticks, :float, 26 | :baseticks, :uint, 27 | :lastticks, :uint, 28 | :rate, :uint, 29 | ) 30 | end 31 | 32 | 33 | # Function 34 | 35 | def self.setup_gfx_framerate_symbols(output_error = false) 36 | symbols = [ 37 | :SDL_initFramerate, 38 | :SDL_setFramerate, 39 | :SDL_getFramerate, 40 | :SDL_getFramecount, 41 | :SDL_framerateDelay, 42 | ] 43 | apis = { 44 | :SDL_initFramerate => :initFramerate, 45 | :SDL_setFramerate => :setFramerate, 46 | :SDL_getFramerate => :getFramerate, 47 | :SDL_getFramecount => :getFramecount, 48 | :SDL_framerateDelay => :framerateDelay, 49 | } 50 | args = { 51 | :SDL_initFramerate => [:pointer], 52 | :SDL_setFramerate => [:pointer, :uint], 53 | :SDL_getFramerate => [:pointer], 54 | :SDL_getFramecount => [:pointer], 55 | :SDL_framerateDelay => [:pointer], 56 | } 57 | retvals = { 58 | :SDL_initFramerate => :void, 59 | :SDL_setFramerate => :int, 60 | :SDL_getFramerate => :int, 61 | :SDL_getFramecount => :int, 62 | :SDL_framerateDelay => :uint, 63 | } 64 | symbols.each do |sym| 65 | begin 66 | attach_function apis[sym], sym, args[sym], retvals[sym] 67 | rescue FFI::NotFoundError => error 68 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 69 | end 70 | end 71 | end 72 | 73 | end 74 | 75 | -------------------------------------------------------------------------------- /lib/sdl2_gesture.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | typedef :long_long, :SDL_GestureID 20 | 21 | # Struct 22 | 23 | 24 | # Function 25 | 26 | def self.setup_gesture_symbols(output_error = false) 27 | symbols = [ 28 | :SDL_RecordGesture, 29 | :SDL_SaveAllDollarTemplates, 30 | :SDL_SaveDollarTemplate, 31 | :SDL_LoadDollarTemplates, 32 | ] 33 | apis = { 34 | :SDL_RecordGesture => :RecordGesture, 35 | :SDL_SaveAllDollarTemplates => :SaveAllDollarTemplates, 36 | :SDL_SaveDollarTemplate => :SaveDollarTemplate, 37 | :SDL_LoadDollarTemplates => :LoadDollarTemplates, 38 | } 39 | args = { 40 | :SDL_RecordGesture => [:long_long], 41 | :SDL_SaveAllDollarTemplates => [:pointer], 42 | :SDL_SaveDollarTemplate => [:long_long, :pointer], 43 | :SDL_LoadDollarTemplates => [:long_long, :pointer], 44 | } 45 | retvals = { 46 | :SDL_RecordGesture => :int, 47 | :SDL_SaveAllDollarTemplates => :int, 48 | :SDL_SaveDollarTemplate => :int, 49 | :SDL_LoadDollarTemplates => :int, 50 | } 51 | symbols.each do |sym| 52 | begin 53 | attach_function apis[sym], sym, args[sym], retvals[sym] 54 | rescue FFI::NotFoundError => error 55 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 56 | end 57 | end 58 | end 59 | 60 | end 61 | 62 | -------------------------------------------------------------------------------- /lib/sdl2_guid.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | # Struct 21 | 22 | class GUID < FFI::Struct 23 | layout( 24 | :data, [:uchar, 16], 25 | ) 26 | end 27 | 28 | 29 | # Function 30 | 31 | def self.setup_guid_symbols(output_error = false) 32 | symbols = [ 33 | :SDL_GUIDToString, 34 | :SDL_GUIDFromString, 35 | ] 36 | apis = { 37 | :SDL_GUIDToString => :GUIDToString, 38 | :SDL_GUIDFromString => :GUIDFromString, 39 | } 40 | args = { 41 | :SDL_GUIDToString => [GUID.by_value, :pointer, :int], 42 | :SDL_GUIDFromString => [:pointer], 43 | } 44 | retvals = { 45 | :SDL_GUIDToString => :void, 46 | :SDL_GUIDFromString => GUID.by_value, 47 | } 48 | symbols.each do |sym| 49 | begin 50 | attach_function apis[sym], sym, args[sym], retvals[sym] 51 | rescue FFI::NotFoundError => error 52 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 53 | end 54 | end 55 | end 56 | 57 | end 58 | 59 | -------------------------------------------------------------------------------- /lib/sdl2_hidapi.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | # Struct 21 | 22 | class Hid_device_info < FFI::Struct 23 | layout( 24 | :path, :pointer, 25 | :vendor_id, :ushort, 26 | :product_id, :ushort, 27 | :serial_number, :pointer, 28 | :release_number, :ushort, 29 | :manufacturer_string, :pointer, 30 | :product_string, :pointer, 31 | :usage_page, :ushort, 32 | :usage, :ushort, 33 | :interface_number, :int, 34 | :interface_class, :int, 35 | :interface_subclass, :int, 36 | :interface_protocol, :int, 37 | :next, :pointer, 38 | ) 39 | end 40 | 41 | 42 | # Function 43 | 44 | def self.setup_hidapi_symbols(output_error = false) 45 | symbols = [ 46 | :SDL_hid_init, 47 | :SDL_hid_exit, 48 | :SDL_hid_device_change_count, 49 | :SDL_hid_enumerate, 50 | :SDL_hid_free_enumeration, 51 | :SDL_hid_open, 52 | :SDL_hid_open_path, 53 | :SDL_hid_write, 54 | :SDL_hid_read_timeout, 55 | :SDL_hid_read, 56 | :SDL_hid_set_nonblocking, 57 | :SDL_hid_send_feature_report, 58 | :SDL_hid_get_feature_report, 59 | :SDL_hid_close, 60 | :SDL_hid_get_manufacturer_string, 61 | :SDL_hid_get_product_string, 62 | :SDL_hid_get_serial_number_string, 63 | :SDL_hid_get_indexed_string, 64 | :SDL_hid_ble_scan, 65 | ] 66 | apis = { 67 | :SDL_hid_init => :hid_init, 68 | :SDL_hid_exit => :hid_exit, 69 | :SDL_hid_device_change_count => :hid_device_change_count, 70 | :SDL_hid_enumerate => :hid_enumerate, 71 | :SDL_hid_free_enumeration => :hid_free_enumeration, 72 | :SDL_hid_open => :hid_open, 73 | :SDL_hid_open_path => :hid_open_path, 74 | :SDL_hid_write => :hid_write, 75 | :SDL_hid_read_timeout => :hid_read_timeout, 76 | :SDL_hid_read => :hid_read, 77 | :SDL_hid_set_nonblocking => :hid_set_nonblocking, 78 | :SDL_hid_send_feature_report => :hid_send_feature_report, 79 | :SDL_hid_get_feature_report => :hid_get_feature_report, 80 | :SDL_hid_close => :hid_close, 81 | :SDL_hid_get_manufacturer_string => :hid_get_manufacturer_string, 82 | :SDL_hid_get_product_string => :hid_get_product_string, 83 | :SDL_hid_get_serial_number_string => :hid_get_serial_number_string, 84 | :SDL_hid_get_indexed_string => :hid_get_indexed_string, 85 | :SDL_hid_ble_scan => :hid_ble_scan, 86 | } 87 | args = { 88 | :SDL_hid_init => [], 89 | :SDL_hid_exit => [], 90 | :SDL_hid_device_change_count => [], 91 | :SDL_hid_enumerate => [:ushort, :ushort], 92 | :SDL_hid_free_enumeration => [:pointer], 93 | :SDL_hid_open => [:ushort, :ushort, :pointer], 94 | :SDL_hid_open_path => [:pointer, :int], 95 | :SDL_hid_write => [:pointer, :pointer, :ulong], 96 | :SDL_hid_read_timeout => [:pointer, :pointer, :ulong, :int], 97 | :SDL_hid_read => [:pointer, :pointer, :ulong], 98 | :SDL_hid_set_nonblocking => [:pointer, :int], 99 | :SDL_hid_send_feature_report => [:pointer, :pointer, :ulong], 100 | :SDL_hid_get_feature_report => [:pointer, :pointer, :ulong], 101 | :SDL_hid_close => [:pointer], 102 | :SDL_hid_get_manufacturer_string => [:pointer, :pointer, :ulong], 103 | :SDL_hid_get_product_string => [:pointer, :pointer, :ulong], 104 | :SDL_hid_get_serial_number_string => [:pointer, :pointer, :ulong], 105 | :SDL_hid_get_indexed_string => [:pointer, :int, :pointer, :ulong], 106 | :SDL_hid_ble_scan => [:int], 107 | } 108 | retvals = { 109 | :SDL_hid_init => :int, 110 | :SDL_hid_exit => :int, 111 | :SDL_hid_device_change_count => :uint, 112 | :SDL_hid_enumerate => :pointer, 113 | :SDL_hid_free_enumeration => :void, 114 | :SDL_hid_open => :pointer, 115 | :SDL_hid_open_path => :pointer, 116 | :SDL_hid_write => :int, 117 | :SDL_hid_read_timeout => :int, 118 | :SDL_hid_read => :int, 119 | :SDL_hid_set_nonblocking => :int, 120 | :SDL_hid_send_feature_report => :int, 121 | :SDL_hid_get_feature_report => :int, 122 | :SDL_hid_close => :void, 123 | :SDL_hid_get_manufacturer_string => :int, 124 | :SDL_hid_get_product_string => :int, 125 | :SDL_hid_get_serial_number_string => :int, 126 | :SDL_hid_get_indexed_string => :int, 127 | :SDL_hid_ble_scan => :void, 128 | } 129 | symbols.each do |sym| 130 | begin 131 | attach_function apis[sym], sym, args[sym], retvals[sym] 132 | rescue FFI::NotFoundError => error 133 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 134 | end 135 | end 136 | end 137 | 138 | end 139 | 140 | -------------------------------------------------------------------------------- /lib/sdl2_imageFilter.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | # Struct 21 | 22 | 23 | # Function 24 | 25 | def self.setup_gfx_imagefilter_symbols(output_error = false) 26 | symbols = [ 27 | :SDL_imageFilterMMXdetect, 28 | :SDL_imageFilterMMXoff, 29 | :SDL_imageFilterMMXon, 30 | :SDL_imageFilterAdd, 31 | :SDL_imageFilterMean, 32 | :SDL_imageFilterSub, 33 | :SDL_imageFilterAbsDiff, 34 | :SDL_imageFilterMult, 35 | :SDL_imageFilterMultNor, 36 | :SDL_imageFilterMultDivby2, 37 | :SDL_imageFilterMultDivby4, 38 | :SDL_imageFilterBitAnd, 39 | :SDL_imageFilterBitOr, 40 | :SDL_imageFilterDiv, 41 | :SDL_imageFilterBitNegation, 42 | :SDL_imageFilterAddByte, 43 | :SDL_imageFilterAddUint, 44 | :SDL_imageFilterAddByteToHalf, 45 | :SDL_imageFilterSubByte, 46 | :SDL_imageFilterSubUint, 47 | :SDL_imageFilterShiftRight, 48 | :SDL_imageFilterShiftRightUint, 49 | :SDL_imageFilterMultByByte, 50 | :SDL_imageFilterShiftRightAndMultByByte, 51 | :SDL_imageFilterShiftLeftByte, 52 | :SDL_imageFilterShiftLeftUint, 53 | :SDL_imageFilterShiftLeft, 54 | :SDL_imageFilterBinarizeUsingThreshold, 55 | :SDL_imageFilterClipToRange, 56 | :SDL_imageFilterNormalizeLinear, 57 | ] 58 | apis = { 59 | :SDL_imageFilterMMXdetect => :imageFilterMMXdetect, 60 | :SDL_imageFilterMMXoff => :imageFilterMMXoff, 61 | :SDL_imageFilterMMXon => :imageFilterMMXon, 62 | :SDL_imageFilterAdd => :imageFilterAdd, 63 | :SDL_imageFilterMean => :imageFilterMean, 64 | :SDL_imageFilterSub => :imageFilterSub, 65 | :SDL_imageFilterAbsDiff => :imageFilterAbsDiff, 66 | :SDL_imageFilterMult => :imageFilterMult, 67 | :SDL_imageFilterMultNor => :imageFilterMultNor, 68 | :SDL_imageFilterMultDivby2 => :imageFilterMultDivby2, 69 | :SDL_imageFilterMultDivby4 => :imageFilterMultDivby4, 70 | :SDL_imageFilterBitAnd => :imageFilterBitAnd, 71 | :SDL_imageFilterBitOr => :imageFilterBitOr, 72 | :SDL_imageFilterDiv => :imageFilterDiv, 73 | :SDL_imageFilterBitNegation => :imageFilterBitNegation, 74 | :SDL_imageFilterAddByte => :imageFilterAddByte, 75 | :SDL_imageFilterAddUint => :imageFilterAddUint, 76 | :SDL_imageFilterAddByteToHalf => :imageFilterAddByteToHalf, 77 | :SDL_imageFilterSubByte => :imageFilterSubByte, 78 | :SDL_imageFilterSubUint => :imageFilterSubUint, 79 | :SDL_imageFilterShiftRight => :imageFilterShiftRight, 80 | :SDL_imageFilterShiftRightUint => :imageFilterShiftRightUint, 81 | :SDL_imageFilterMultByByte => :imageFilterMultByByte, 82 | :SDL_imageFilterShiftRightAndMultByByte => :imageFilterShiftRightAndMultByByte, 83 | :SDL_imageFilterShiftLeftByte => :imageFilterShiftLeftByte, 84 | :SDL_imageFilterShiftLeftUint => :imageFilterShiftLeftUint, 85 | :SDL_imageFilterShiftLeft => :imageFilterShiftLeft, 86 | :SDL_imageFilterBinarizeUsingThreshold => :imageFilterBinarizeUsingThreshold, 87 | :SDL_imageFilterClipToRange => :imageFilterClipToRange, 88 | :SDL_imageFilterNormalizeLinear => :imageFilterNormalizeLinear, 89 | } 90 | args = { 91 | :SDL_imageFilterMMXdetect => [], 92 | :SDL_imageFilterMMXoff => [], 93 | :SDL_imageFilterMMXon => [], 94 | :SDL_imageFilterAdd => [:pointer, :pointer, :pointer, :uint], 95 | :SDL_imageFilterMean => [:pointer, :pointer, :pointer, :uint], 96 | :SDL_imageFilterSub => [:pointer, :pointer, :pointer, :uint], 97 | :SDL_imageFilterAbsDiff => [:pointer, :pointer, :pointer, :uint], 98 | :SDL_imageFilterMult => [:pointer, :pointer, :pointer, :uint], 99 | :SDL_imageFilterMultNor => [:pointer, :pointer, :pointer, :uint], 100 | :SDL_imageFilterMultDivby2 => [:pointer, :pointer, :pointer, :uint], 101 | :SDL_imageFilterMultDivby4 => [:pointer, :pointer, :pointer, :uint], 102 | :SDL_imageFilterBitAnd => [:pointer, :pointer, :pointer, :uint], 103 | :SDL_imageFilterBitOr => [:pointer, :pointer, :pointer, :uint], 104 | :SDL_imageFilterDiv => [:pointer, :pointer, :pointer, :uint], 105 | :SDL_imageFilterBitNegation => [:pointer, :pointer, :uint], 106 | :SDL_imageFilterAddByte => [:pointer, :pointer, :uint, :uchar], 107 | :SDL_imageFilterAddUint => [:pointer, :pointer, :uint, :uint], 108 | :SDL_imageFilterAddByteToHalf => [:pointer, :pointer, :uint, :uchar], 109 | :SDL_imageFilterSubByte => [:pointer, :pointer, :uint, :uchar], 110 | :SDL_imageFilterSubUint => [:pointer, :pointer, :uint, :uint], 111 | :SDL_imageFilterShiftRight => [:pointer, :pointer, :uint, :uchar], 112 | :SDL_imageFilterShiftRightUint => [:pointer, :pointer, :uint, :uchar], 113 | :SDL_imageFilterMultByByte => [:pointer, :pointer, :uint, :uchar], 114 | :SDL_imageFilterShiftRightAndMultByByte => [:pointer, :pointer, :uint, :uchar, :uchar], 115 | :SDL_imageFilterShiftLeftByte => [:pointer, :pointer, :uint, :uchar], 116 | :SDL_imageFilterShiftLeftUint => [:pointer, :pointer, :uint, :uchar], 117 | :SDL_imageFilterShiftLeft => [:pointer, :pointer, :uint, :uchar], 118 | :SDL_imageFilterBinarizeUsingThreshold => [:pointer, :pointer, :uint, :uchar], 119 | :SDL_imageFilterClipToRange => [:pointer, :pointer, :uint, :uchar, :uchar], 120 | :SDL_imageFilterNormalizeLinear => [:pointer, :pointer, :uint, :int, :int, :int, :int], 121 | } 122 | retvals = { 123 | :SDL_imageFilterMMXdetect => :int, 124 | :SDL_imageFilterMMXoff => :void, 125 | :SDL_imageFilterMMXon => :void, 126 | :SDL_imageFilterAdd => :int, 127 | :SDL_imageFilterMean => :int, 128 | :SDL_imageFilterSub => :int, 129 | :SDL_imageFilterAbsDiff => :int, 130 | :SDL_imageFilterMult => :int, 131 | :SDL_imageFilterMultNor => :int, 132 | :SDL_imageFilterMultDivby2 => :int, 133 | :SDL_imageFilterMultDivby4 => :int, 134 | :SDL_imageFilterBitAnd => :int, 135 | :SDL_imageFilterBitOr => :int, 136 | :SDL_imageFilterDiv => :int, 137 | :SDL_imageFilterBitNegation => :int, 138 | :SDL_imageFilterAddByte => :int, 139 | :SDL_imageFilterAddUint => :int, 140 | :SDL_imageFilterAddByteToHalf => :int, 141 | :SDL_imageFilterSubByte => :int, 142 | :SDL_imageFilterSubUint => :int, 143 | :SDL_imageFilterShiftRight => :int, 144 | :SDL_imageFilterShiftRightUint => :int, 145 | :SDL_imageFilterMultByByte => :int, 146 | :SDL_imageFilterShiftRightAndMultByByte => :int, 147 | :SDL_imageFilterShiftLeftByte => :int, 148 | :SDL_imageFilterShiftLeftUint => :int, 149 | :SDL_imageFilterShiftLeft => :int, 150 | :SDL_imageFilterBinarizeUsingThreshold => :int, 151 | :SDL_imageFilterClipToRange => :int, 152 | :SDL_imageFilterNormalizeLinear => :int, 153 | } 154 | symbols.each do |sym| 155 | begin 156 | attach_function apis[sym], sym, args[sym], retvals[sym] 157 | rescue FFI::NotFoundError => error 158 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 159 | end 160 | end 161 | end 162 | 163 | end 164 | 165 | -------------------------------------------------------------------------------- /lib/sdl2_keyboard.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | # Struct 21 | 22 | class Keysym < FFI::Struct 23 | layout( 24 | :scancode, :int, 25 | :sym, :int, 26 | :mod, :ushort, 27 | :unused, :uint, 28 | ) 29 | end 30 | 31 | 32 | # Function 33 | 34 | def self.setup_keyboard_symbols(output_error = false) 35 | symbols = [ 36 | :SDL_GetKeyboardFocus, 37 | :SDL_GetKeyboardState, 38 | :SDL_ResetKeyboard, 39 | :SDL_GetModState, 40 | :SDL_SetModState, 41 | :SDL_GetKeyFromScancode, 42 | :SDL_GetScancodeFromKey, 43 | :SDL_GetScancodeName, 44 | :SDL_GetScancodeFromName, 45 | :SDL_GetKeyName, 46 | :SDL_GetKeyFromName, 47 | :SDL_StartTextInput, 48 | :SDL_IsTextInputActive, 49 | :SDL_StopTextInput, 50 | :SDL_ClearComposition, 51 | :SDL_IsTextInputShown, 52 | :SDL_SetTextInputRect, 53 | :SDL_HasScreenKeyboardSupport, 54 | :SDL_IsScreenKeyboardShown, 55 | ] 56 | apis = { 57 | :SDL_GetKeyboardFocus => :GetKeyboardFocus, 58 | :SDL_GetKeyboardState => :GetKeyboardState, 59 | :SDL_ResetKeyboard => :ResetKeyboard, 60 | :SDL_GetModState => :GetModState, 61 | :SDL_SetModState => :SetModState, 62 | :SDL_GetKeyFromScancode => :GetKeyFromScancode, 63 | :SDL_GetScancodeFromKey => :GetScancodeFromKey, 64 | :SDL_GetScancodeName => :GetScancodeName, 65 | :SDL_GetScancodeFromName => :GetScancodeFromName, 66 | :SDL_GetKeyName => :GetKeyName, 67 | :SDL_GetKeyFromName => :GetKeyFromName, 68 | :SDL_StartTextInput => :StartTextInput, 69 | :SDL_IsTextInputActive => :IsTextInputActive, 70 | :SDL_StopTextInput => :StopTextInput, 71 | :SDL_ClearComposition => :ClearComposition, 72 | :SDL_IsTextInputShown => :IsTextInputShown, 73 | :SDL_SetTextInputRect => :SetTextInputRect, 74 | :SDL_HasScreenKeyboardSupport => :HasScreenKeyboardSupport, 75 | :SDL_IsScreenKeyboardShown => :IsScreenKeyboardShown, 76 | } 77 | args = { 78 | :SDL_GetKeyboardFocus => [], 79 | :SDL_GetKeyboardState => [:pointer], 80 | :SDL_ResetKeyboard => [], 81 | :SDL_GetModState => [], 82 | :SDL_SetModState => [:int], 83 | :SDL_GetKeyFromScancode => [:int], 84 | :SDL_GetScancodeFromKey => [:int], 85 | :SDL_GetScancodeName => [:int], 86 | :SDL_GetScancodeFromName => [:pointer], 87 | :SDL_GetKeyName => [:int], 88 | :SDL_GetKeyFromName => [:pointer], 89 | :SDL_StartTextInput => [], 90 | :SDL_IsTextInputActive => [], 91 | :SDL_StopTextInput => [], 92 | :SDL_ClearComposition => [], 93 | :SDL_IsTextInputShown => [], 94 | :SDL_SetTextInputRect => [:pointer], 95 | :SDL_HasScreenKeyboardSupport => [], 96 | :SDL_IsScreenKeyboardShown => [:pointer], 97 | } 98 | retvals = { 99 | :SDL_GetKeyboardFocus => :pointer, 100 | :SDL_GetKeyboardState => :pointer, 101 | :SDL_ResetKeyboard => :void, 102 | :SDL_GetModState => :int, 103 | :SDL_SetModState => :void, 104 | :SDL_GetKeyFromScancode => :int, 105 | :SDL_GetScancodeFromKey => :int, 106 | :SDL_GetScancodeName => :pointer, 107 | :SDL_GetScancodeFromName => :int, 108 | :SDL_GetKeyName => :pointer, 109 | :SDL_GetKeyFromName => :int, 110 | :SDL_StartTextInput => :void, 111 | :SDL_IsTextInputActive => :int, 112 | :SDL_StopTextInput => :void, 113 | :SDL_ClearComposition => :void, 114 | :SDL_IsTextInputShown => :int, 115 | :SDL_SetTextInputRect => :void, 116 | :SDL_HasScreenKeyboardSupport => :int, 117 | :SDL_IsScreenKeyboardShown => :int, 118 | } 119 | symbols.each do |sym| 120 | begin 121 | attach_function apis[sym], sym, args[sym], retvals[sym] 122 | rescue FFI::NotFoundError => error 123 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 124 | end 125 | end 126 | end 127 | 128 | end 129 | 130 | -------------------------------------------------------------------------------- /lib/sdl2_log.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | MAX_LOG_MESSAGE = 4096 14 | 15 | # Enum 16 | 17 | LOG_CATEGORY_APPLICATION = 0 18 | LOG_CATEGORY_ERROR = 1 19 | LOG_CATEGORY_ASSERT = 2 20 | LOG_CATEGORY_SYSTEM = 3 21 | LOG_CATEGORY_AUDIO = 4 22 | LOG_CATEGORY_VIDEO = 5 23 | LOG_CATEGORY_RENDER = 6 24 | LOG_CATEGORY_INPUT = 7 25 | LOG_CATEGORY_TEST = 8 26 | LOG_CATEGORY_RESERVED1 = 9 27 | LOG_CATEGORY_RESERVED2 = 10 28 | LOG_CATEGORY_RESERVED3 = 11 29 | LOG_CATEGORY_RESERVED4 = 12 30 | LOG_CATEGORY_RESERVED5 = 13 31 | LOG_CATEGORY_RESERVED6 = 14 32 | LOG_CATEGORY_RESERVED7 = 15 33 | LOG_CATEGORY_RESERVED8 = 16 34 | LOG_CATEGORY_RESERVED9 = 17 35 | LOG_CATEGORY_RESERVED10 = 18 36 | LOG_CATEGORY_CUSTOM = 19 37 | LOG_PRIORITY_VERBOSE = 1 38 | LOG_PRIORITY_DEBUG = 2 39 | LOG_PRIORITY_INFO = 3 40 | LOG_PRIORITY_WARN = 4 41 | LOG_PRIORITY_ERROR = 5 42 | LOG_PRIORITY_CRITICAL = 6 43 | NUM_LOG_PRIORITIES = 7 44 | 45 | # Typedef 46 | 47 | typedef :int, :SDL_LogCategory 48 | typedef :int, :SDL_LogPriority 49 | callback :SDL_LogOutputFunction, [:pointer, :int, :int, :pointer], :void 50 | 51 | # Struct 52 | 53 | 54 | # Function 55 | 56 | def self.setup_log_symbols(output_error = false) 57 | symbols = [ 58 | :SDL_LogSetAllPriority, 59 | :SDL_LogSetPriority, 60 | :SDL_LogGetPriority, 61 | :SDL_LogResetPriorities, 62 | :SDL_Log, 63 | :SDL_LogVerbose, 64 | :SDL_LogDebug, 65 | :SDL_LogInfo, 66 | :SDL_LogWarn, 67 | :SDL_LogError, 68 | :SDL_LogCritical, 69 | :SDL_LogMessage, 70 | :SDL_LogGetOutputFunction, 71 | :SDL_LogSetOutputFunction, 72 | ] 73 | apis = { 74 | :SDL_LogSetAllPriority => :LogSetAllPriority, 75 | :SDL_LogSetPriority => :LogSetPriority, 76 | :SDL_LogGetPriority => :LogGetPriority, 77 | :SDL_LogResetPriorities => :LogResetPriorities, 78 | :SDL_Log => :Log, 79 | :SDL_LogVerbose => :LogVerbose, 80 | :SDL_LogDebug => :LogDebug, 81 | :SDL_LogInfo => :LogInfo, 82 | :SDL_LogWarn => :LogWarn, 83 | :SDL_LogError => :LogError, 84 | :SDL_LogCritical => :LogCritical, 85 | :SDL_LogMessage => :LogMessage, 86 | :SDL_LogGetOutputFunction => :LogGetOutputFunction, 87 | :SDL_LogSetOutputFunction => :LogSetOutputFunction, 88 | } 89 | args = { 90 | :SDL_LogSetAllPriority => [:int], 91 | :SDL_LogSetPriority => [:int, :int], 92 | :SDL_LogGetPriority => [:int], 93 | :SDL_LogResetPriorities => [], 94 | :SDL_Log => [:pointer], 95 | :SDL_LogVerbose => [:int, :pointer], 96 | :SDL_LogDebug => [:int, :pointer], 97 | :SDL_LogInfo => [:int, :pointer], 98 | :SDL_LogWarn => [:int, :pointer], 99 | :SDL_LogError => [:int, :pointer], 100 | :SDL_LogCritical => [:int, :pointer], 101 | :SDL_LogMessage => [:int, :int, :pointer], 102 | :SDL_LogGetOutputFunction => [:pointer, :pointer], 103 | :SDL_LogSetOutputFunction => [:SDL_LogOutputFunction, :pointer], 104 | } 105 | retvals = { 106 | :SDL_LogSetAllPriority => :void, 107 | :SDL_LogSetPriority => :void, 108 | :SDL_LogGetPriority => :int, 109 | :SDL_LogResetPriorities => :void, 110 | :SDL_Log => :void, 111 | :SDL_LogVerbose => :void, 112 | :SDL_LogDebug => :void, 113 | :SDL_LogInfo => :void, 114 | :SDL_LogWarn => :void, 115 | :SDL_LogError => :void, 116 | :SDL_LogCritical => :void, 117 | :SDL_LogMessage => :void, 118 | :SDL_LogGetOutputFunction => :void, 119 | :SDL_LogSetOutputFunction => :void, 120 | } 121 | symbols.each do |sym| 122 | begin 123 | attach_function apis[sym], sym, args[sym], retvals[sym] 124 | rescue FFI::NotFoundError => error 125 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 126 | end 127 | end 128 | end 129 | 130 | end 131 | 132 | -------------------------------------------------------------------------------- /lib/sdl2_main.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | INIT_TIMER = 0x00000001 14 | INIT_AUDIO = 0x00000010 15 | INIT_VIDEO = 0x00000020 16 | INIT_JOYSTICK = 0x00000200 17 | INIT_HAPTIC = 0x00001000 18 | INIT_GAMECONTROLLER = 0x00002000 19 | INIT_EVENTS = 0x00004000 20 | INIT_SENSOR = 0x00008000 21 | INIT_NOPARACHUTE = 0x00100000 22 | INIT_EVERYTHING = ( INIT_TIMER | INIT_AUDIO | INIT_VIDEO | INIT_EVENTS | INIT_JOYSTICK | INIT_HAPTIC | INIT_GAMECONTROLLER | INIT_SENSOR ) 23 | 24 | # Enum 25 | 26 | 27 | # Typedef 28 | 29 | 30 | # Struct 31 | 32 | 33 | # Function 34 | 35 | def self.setup_main_symbols(output_error = false) 36 | symbols = [ 37 | :SDL_Init, 38 | :SDL_InitSubSystem, 39 | :SDL_QuitSubSystem, 40 | :SDL_WasInit, 41 | :SDL_Quit, 42 | ] 43 | apis = { 44 | :SDL_Init => :Init, 45 | :SDL_InitSubSystem => :InitSubSystem, 46 | :SDL_QuitSubSystem => :QuitSubSystem, 47 | :SDL_WasInit => :WasInit, 48 | :SDL_Quit => :Quit, 49 | } 50 | args = { 51 | :SDL_Init => [:uint], 52 | :SDL_InitSubSystem => [:uint], 53 | :SDL_QuitSubSystem => [:uint], 54 | :SDL_WasInit => [:uint], 55 | :SDL_Quit => [], 56 | } 57 | retvals = { 58 | :SDL_Init => :int, 59 | :SDL_InitSubSystem => :int, 60 | :SDL_QuitSubSystem => :void, 61 | :SDL_WasInit => :uint, 62 | :SDL_Quit => :void, 63 | } 64 | symbols.each do |sym| 65 | begin 66 | attach_function apis[sym], sym, args[sym], retvals[sym] 67 | rescue FFI::NotFoundError => error 68 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 69 | end 70 | end 71 | end 72 | 73 | end 74 | 75 | -------------------------------------------------------------------------------- /lib/sdl2_messagebox.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | MESSAGEBOX_ERROR = 16 17 | MESSAGEBOX_WARNING = 32 18 | MESSAGEBOX_INFORMATION = 64 19 | MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT = 128 20 | MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT = 256 21 | MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 1 22 | MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 2 23 | MESSAGEBOX_COLOR_BACKGROUND = 0 24 | MESSAGEBOX_COLOR_TEXT = 1 25 | MESSAGEBOX_COLOR_BUTTON_BORDER = 2 26 | MESSAGEBOX_COLOR_BUTTON_BACKGROUND = 3 27 | MESSAGEBOX_COLOR_BUTTON_SELECTED = 4 28 | MESSAGEBOX_COLOR_MAX = 5 29 | 30 | # Typedef 31 | 32 | typedef :int, :SDL_MessageBoxFlags 33 | typedef :int, :SDL_MessageBoxButtonFlags 34 | typedef :int, :SDL_MessageBoxColorType 35 | 36 | # Struct 37 | 38 | class MessageBoxButtonData < FFI::Struct 39 | layout( 40 | :flags, :uint, 41 | :buttonid, :int, 42 | :text, :pointer, 43 | ) 44 | end 45 | 46 | class MessageBoxColor < FFI::Struct 47 | layout( 48 | :r, :uchar, 49 | :g, :uchar, 50 | :b, :uchar, 51 | ) 52 | end 53 | 54 | class MessageBoxColorScheme < FFI::Struct 55 | layout( 56 | :colors, [MessageBoxColor, 5], 57 | ) 58 | end 59 | 60 | class MessageBoxData < FFI::Struct 61 | layout( 62 | :flags, :uint, 63 | :window, :pointer, 64 | :title, :pointer, 65 | :message, :pointer, 66 | :numbuttons, :int, 67 | :buttons, :pointer, 68 | :colorScheme, :pointer, 69 | ) 70 | end 71 | 72 | 73 | # Function 74 | 75 | def self.setup_messagebox_symbols(output_error = false) 76 | symbols = [ 77 | :SDL_ShowMessageBox, 78 | :SDL_ShowSimpleMessageBox, 79 | ] 80 | apis = { 81 | :SDL_ShowMessageBox => :ShowMessageBox, 82 | :SDL_ShowSimpleMessageBox => :ShowSimpleMessageBox, 83 | } 84 | args = { 85 | :SDL_ShowMessageBox => [:pointer, :pointer], 86 | :SDL_ShowSimpleMessageBox => [:uint, :pointer, :pointer, :pointer], 87 | } 88 | retvals = { 89 | :SDL_ShowMessageBox => :int, 90 | :SDL_ShowSimpleMessageBox => :int, 91 | } 92 | symbols.each do |sym| 93 | begin 94 | attach_function apis[sym], sym, args[sym], retvals[sym] 95 | rescue FFI::NotFoundError => error 96 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 97 | end 98 | end 99 | end 100 | 101 | end 102 | 103 | -------------------------------------------------------------------------------- /lib/sdl2_misc.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | # Struct 21 | 22 | 23 | # Function 24 | 25 | def self.setup_misc_symbols(output_error = false) 26 | symbols = [ 27 | :SDL_OpenURL, 28 | ] 29 | apis = { 30 | :SDL_OpenURL => :OpenURL, 31 | } 32 | args = { 33 | :SDL_OpenURL => [:pointer], 34 | } 35 | retvals = { 36 | :SDL_OpenURL => :int, 37 | } 38 | symbols.each do |sym| 39 | begin 40 | attach_function apis[sym], sym, args[sym], retvals[sym] 41 | rescue FFI::NotFoundError => error 42 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 43 | end 44 | end 45 | end 46 | 47 | end 48 | 49 | -------------------------------------------------------------------------------- /lib/sdl2_mouse.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | BUTTON_LEFT = 1 14 | BUTTON_MIDDLE = 2 15 | BUTTON_RIGHT = 3 16 | BUTTON_X1 = 4 17 | BUTTON_X2 = 5 18 | 19 | # Enum 20 | 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 | 37 | # Typedef 38 | 39 | typedef :int, :SDL_SystemCursor 40 | typedef :int, :SDL_MouseWheelDirection 41 | 42 | # Struct 43 | 44 | 45 | # Function 46 | 47 | def self.setup_mouse_symbols(output_error = false) 48 | symbols = [ 49 | :SDL_GetMouseFocus, 50 | :SDL_GetMouseState, 51 | :SDL_GetGlobalMouseState, 52 | :SDL_GetRelativeMouseState, 53 | :SDL_WarpMouseInWindow, 54 | :SDL_WarpMouseGlobal, 55 | :SDL_SetRelativeMouseMode, 56 | :SDL_CaptureMouse, 57 | :SDL_GetRelativeMouseMode, 58 | :SDL_CreateCursor, 59 | :SDL_CreateColorCursor, 60 | :SDL_CreateSystemCursor, 61 | :SDL_SetCursor, 62 | :SDL_GetCursor, 63 | :SDL_GetDefaultCursor, 64 | :SDL_FreeCursor, 65 | :SDL_ShowCursor, 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 | } 86 | args = { 87 | :SDL_GetMouseFocus => [], 88 | :SDL_GetMouseState => [:pointer, :pointer], 89 | :SDL_GetGlobalMouseState => [:pointer, :pointer], 90 | :SDL_GetRelativeMouseState => [:pointer, :pointer], 91 | :SDL_WarpMouseInWindow => [:pointer, :int, :int], 92 | :SDL_WarpMouseGlobal => [:int, :int], 93 | :SDL_SetRelativeMouseMode => [:int], 94 | :SDL_CaptureMouse => [:int], 95 | :SDL_GetRelativeMouseMode => [], 96 | :SDL_CreateCursor => [:pointer, :pointer, :int, :int, :int, :int], 97 | :SDL_CreateColorCursor => [:pointer, :int, :int], 98 | :SDL_CreateSystemCursor => [:int], 99 | :SDL_SetCursor => [:pointer], 100 | :SDL_GetCursor => [], 101 | :SDL_GetDefaultCursor => [], 102 | :SDL_FreeCursor => [:pointer], 103 | :SDL_ShowCursor => [:int], 104 | } 105 | retvals = { 106 | :SDL_GetMouseFocus => :pointer, 107 | :SDL_GetMouseState => :uint, 108 | :SDL_GetGlobalMouseState => :uint, 109 | :SDL_GetRelativeMouseState => :uint, 110 | :SDL_WarpMouseInWindow => :void, 111 | :SDL_WarpMouseGlobal => :int, 112 | :SDL_SetRelativeMouseMode => :int, 113 | :SDL_CaptureMouse => :int, 114 | :SDL_GetRelativeMouseMode => :int, 115 | :SDL_CreateCursor => :pointer, 116 | :SDL_CreateColorCursor => :pointer, 117 | :SDL_CreateSystemCursor => :pointer, 118 | :SDL_SetCursor => :void, 119 | :SDL_GetCursor => :pointer, 120 | :SDL_GetDefaultCursor => :pointer, 121 | :SDL_FreeCursor => :void, 122 | :SDL_ShowCursor => :int, 123 | } 124 | symbols.each do |sym| 125 | begin 126 | attach_function apis[sym], sym, args[sym], retvals[sym] 127 | rescue FFI::NotFoundError => error 128 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 129 | end 130 | end 131 | end 132 | 133 | end 134 | 135 | # TODO : def self.BUTTON(X); (1 << ((X)-1)); end; 136 | 137 | -------------------------------------------------------------------------------- /lib/sdl2_pixels.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | ALPHA_OPAQUE = 255 14 | ALPHA_TRANSPARENT = 0 15 | 16 | # Enum 17 | 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 | PIXELTYPE_INDEX2 = 12 31 | BITMAPORDER_NONE = 0 32 | BITMAPORDER_4321 = 1 33 | BITMAPORDER_1234 = 2 34 | PACKEDORDER_NONE = 0 35 | PACKEDORDER_XRGB = 1 36 | PACKEDORDER_RGBX = 2 37 | PACKEDORDER_ARGB = 3 38 | PACKEDORDER_RGBA = 4 39 | PACKEDORDER_XBGR = 5 40 | PACKEDORDER_BGRX = 6 41 | PACKEDORDER_ABGR = 7 42 | PACKEDORDER_BGRA = 8 43 | ARRAYORDER_NONE = 0 44 | ARRAYORDER_RGB = 1 45 | ARRAYORDER_RGBA = 2 46 | ARRAYORDER_ARGB = 3 47 | ARRAYORDER_BGR = 4 48 | ARRAYORDER_BGRA = 5 49 | ARRAYORDER_ABGR = 6 50 | PACKEDLAYOUT_NONE = 0 51 | PACKEDLAYOUT_332 = 1 52 | PACKEDLAYOUT_4444 = 2 53 | PACKEDLAYOUT_1555 = 3 54 | PACKEDLAYOUT_5551 = 4 55 | PACKEDLAYOUT_565 = 5 56 | PACKEDLAYOUT_8888 = 6 57 | PACKEDLAYOUT_2101010 = 7 58 | PACKEDLAYOUT_1010102 = 8 59 | PIXELFORMAT_UNKNOWN = 0 60 | PIXELFORMAT_INDEX1LSB = 286261504 61 | PIXELFORMAT_INDEX1MSB = 287310080 62 | PIXELFORMAT_INDEX2LSB = 470811136 63 | PIXELFORMAT_INDEX2MSB = 471859712 64 | PIXELFORMAT_INDEX4LSB = 303039488 65 | PIXELFORMAT_INDEX4MSB = 304088064 66 | PIXELFORMAT_INDEX8 = 318769153 67 | PIXELFORMAT_RGB332 = 336660481 68 | PIXELFORMAT_XRGB4444 = 353504258 69 | PIXELFORMAT_RGB444 = 353504258 70 | PIXELFORMAT_XBGR4444 = 357698562 71 | PIXELFORMAT_BGR444 = 357698562 72 | PIXELFORMAT_XRGB1555 = 353570562 73 | PIXELFORMAT_RGB555 = 353570562 74 | PIXELFORMAT_XBGR1555 = 357764866 75 | PIXELFORMAT_BGR555 = 357764866 76 | PIXELFORMAT_ARGB4444 = 355602434 77 | PIXELFORMAT_RGBA4444 = 356651010 78 | PIXELFORMAT_ABGR4444 = 359796738 79 | PIXELFORMAT_BGRA4444 = 360845314 80 | PIXELFORMAT_ARGB1555 = 355667970 81 | PIXELFORMAT_RGBA5551 = 356782082 82 | PIXELFORMAT_ABGR1555 = 359862274 83 | PIXELFORMAT_BGRA5551 = 360976386 84 | PIXELFORMAT_RGB565 = 353701890 85 | PIXELFORMAT_BGR565 = 357896194 86 | PIXELFORMAT_RGB24 = 386930691 87 | PIXELFORMAT_BGR24 = 390076419 88 | PIXELFORMAT_XRGB8888 = 370546692 89 | PIXELFORMAT_RGB888 = 370546692 90 | PIXELFORMAT_RGBX8888 = 371595268 91 | PIXELFORMAT_XBGR8888 = 374740996 92 | PIXELFORMAT_BGR888 = 374740996 93 | PIXELFORMAT_BGRX8888 = 375789572 94 | PIXELFORMAT_ARGB8888 = 372645892 95 | PIXELFORMAT_RGBA8888 = 373694468 96 | PIXELFORMAT_ABGR8888 = 376840196 97 | PIXELFORMAT_BGRA8888 = 377888772 98 | PIXELFORMAT_ARGB2101010 = 372711428 99 | PIXELFORMAT_RGBA32 = 376840196 100 | PIXELFORMAT_ARGB32 = 377888772 101 | PIXELFORMAT_BGRA32 = 372645892 102 | PIXELFORMAT_ABGR32 = 373694468 103 | PIXELFORMAT_RGBX32 = 374740996 104 | PIXELFORMAT_XRGB32 = 375789572 105 | PIXELFORMAT_BGRX32 = 370546692 106 | PIXELFORMAT_XBGR32 = 371595268 107 | PIXELFORMAT_YV12 = 842094169 108 | PIXELFORMAT_IYUV = 1448433993 109 | PIXELFORMAT_YUY2 = 844715353 110 | PIXELFORMAT_UYVY = 1498831189 111 | PIXELFORMAT_YVYU = 1431918169 112 | PIXELFORMAT_NV12 = 842094158 113 | PIXELFORMAT_NV21 = 825382478 114 | PIXELFORMAT_EXTERNAL_OES = 542328143 115 | 116 | # Typedef 117 | 118 | typedef :int, :SDL_PixelType 119 | typedef :int, :SDL_BitmapOrder 120 | typedef :int, :SDL_PackedOrder 121 | typedef :int, :SDL_ArrayOrder 122 | typedef :int, :SDL_PackedLayout 123 | typedef :int, :SDL_PixelFormatEnum 124 | 125 | # Struct 126 | 127 | class Color < FFI::Struct 128 | layout( 129 | :r, :uchar, 130 | :g, :uchar, 131 | :b, :uchar, 132 | :a, :uchar, 133 | ) 134 | end 135 | 136 | class Palette < FFI::Struct 137 | layout( 138 | :ncolors, :int, 139 | :colors, :pointer, 140 | :version, :uint, 141 | :refcount, :int, 142 | ) 143 | end 144 | 145 | class PixelFormat < FFI::Struct 146 | layout( 147 | :format, :uint, 148 | :palette, :pointer, 149 | :BitsPerPixel, :uchar, 150 | :BytesPerPixel, :uchar, 151 | :padding, [:uchar, 2], 152 | :Rmask, :uint, 153 | :Gmask, :uint, 154 | :Bmask, :uint, 155 | :Amask, :uint, 156 | :Rloss, :uchar, 157 | :Gloss, :uchar, 158 | :Bloss, :uchar, 159 | :Aloss, :uchar, 160 | :Rshift, :uchar, 161 | :Gshift, :uchar, 162 | :Bshift, :uchar, 163 | :Ashift, :uchar, 164 | :refcount, :int, 165 | :next, :pointer, 166 | ) 167 | end 168 | 169 | 170 | # Function 171 | 172 | def self.setup_pixels_symbols(output_error = false) 173 | symbols = [ 174 | :SDL_GetPixelFormatName, 175 | :SDL_PixelFormatEnumToMasks, 176 | :SDL_MasksToPixelFormatEnum, 177 | :SDL_AllocFormat, 178 | :SDL_FreeFormat, 179 | :SDL_AllocPalette, 180 | :SDL_SetPixelFormatPalette, 181 | :SDL_SetPaletteColors, 182 | :SDL_FreePalette, 183 | :SDL_MapRGB, 184 | :SDL_MapRGBA, 185 | :SDL_GetRGB, 186 | :SDL_GetRGBA, 187 | :SDL_CalculateGammaRamp, 188 | ] 189 | apis = { 190 | :SDL_GetPixelFormatName => :GetPixelFormatName, 191 | :SDL_PixelFormatEnumToMasks => :PixelFormatEnumToMasks, 192 | :SDL_MasksToPixelFormatEnum => :MasksToPixelFormatEnum, 193 | :SDL_AllocFormat => :AllocFormat, 194 | :SDL_FreeFormat => :FreeFormat, 195 | :SDL_AllocPalette => :AllocPalette, 196 | :SDL_SetPixelFormatPalette => :SetPixelFormatPalette, 197 | :SDL_SetPaletteColors => :SetPaletteColors, 198 | :SDL_FreePalette => :FreePalette, 199 | :SDL_MapRGB => :MapRGB, 200 | :SDL_MapRGBA => :MapRGBA, 201 | :SDL_GetRGB => :GetRGB, 202 | :SDL_GetRGBA => :GetRGBA, 203 | :SDL_CalculateGammaRamp => :CalculateGammaRamp, 204 | } 205 | args = { 206 | :SDL_GetPixelFormatName => [:uint], 207 | :SDL_PixelFormatEnumToMasks => [:uint, :pointer, :pointer, :pointer, :pointer, :pointer], 208 | :SDL_MasksToPixelFormatEnum => [:int, :uint, :uint, :uint, :uint], 209 | :SDL_AllocFormat => [:uint], 210 | :SDL_FreeFormat => [:pointer], 211 | :SDL_AllocPalette => [:int], 212 | :SDL_SetPixelFormatPalette => [:pointer, :pointer], 213 | :SDL_SetPaletteColors => [:pointer, :pointer, :int, :int], 214 | :SDL_FreePalette => [:pointer], 215 | :SDL_MapRGB => [:pointer, :uchar, :uchar, :uchar], 216 | :SDL_MapRGBA => [:pointer, :uchar, :uchar, :uchar, :uchar], 217 | :SDL_GetRGB => [:uint, :pointer, :pointer, :pointer, :pointer], 218 | :SDL_GetRGBA => [:uint, :pointer, :pointer, :pointer, :pointer, :pointer], 219 | :SDL_CalculateGammaRamp => [:float, :pointer], 220 | } 221 | retvals = { 222 | :SDL_GetPixelFormatName => :pointer, 223 | :SDL_PixelFormatEnumToMasks => :int, 224 | :SDL_MasksToPixelFormatEnum => :uint, 225 | :SDL_AllocFormat => :pointer, 226 | :SDL_FreeFormat => :void, 227 | :SDL_AllocPalette => :pointer, 228 | :SDL_SetPixelFormatPalette => :int, 229 | :SDL_SetPaletteColors => :int, 230 | :SDL_FreePalette => :void, 231 | :SDL_MapRGB => :uint, 232 | :SDL_MapRGBA => :uint, 233 | :SDL_GetRGB => :void, 234 | :SDL_GetRGBA => :void, 235 | :SDL_CalculateGammaRamp => :void, 236 | } 237 | symbols.each do |sym| 238 | begin 239 | attach_function apis[sym], sym, args[sym], retvals[sym] 240 | rescue FFI::NotFoundError => error 241 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 242 | end 243 | end 244 | end 245 | 246 | end 247 | 248 | -------------------------------------------------------------------------------- /lib/sdl2_platform.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | # Struct 21 | 22 | 23 | # Function 24 | 25 | def self.setup_platform_symbols(output_error = false) 26 | symbols = [ 27 | :SDL_GetPlatform, 28 | ] 29 | apis = { 30 | :SDL_GetPlatform => :GetPlatform, 31 | } 32 | args = { 33 | :SDL_GetPlatform => [], 34 | } 35 | retvals = { 36 | :SDL_GetPlatform => :pointer, 37 | } 38 | symbols.each do |sym| 39 | begin 40 | attach_function apis[sym], sym, args[sym], retvals[sym] 41 | rescue FFI::NotFoundError => error 42 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 43 | end 44 | end 45 | end 46 | 47 | end 48 | 49 | -------------------------------------------------------------------------------- /lib/sdl2_power.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | POWERSTATE_UNKNOWN = 0 17 | POWERSTATE_ON_BATTERY = 1 18 | POWERSTATE_NO_BATTERY = 2 19 | POWERSTATE_CHARGING = 3 20 | POWERSTATE_CHARGED = 4 21 | 22 | # Typedef 23 | 24 | typedef :int, :SDL_PowerState 25 | 26 | # Struct 27 | 28 | 29 | # Function 30 | 31 | def self.setup_power_symbols(output_error = false) 32 | symbols = [ 33 | :SDL_GetPowerInfo, 34 | ] 35 | apis = { 36 | :SDL_GetPowerInfo => :GetPowerInfo, 37 | } 38 | args = { 39 | :SDL_GetPowerInfo => [:pointer, :pointer], 40 | } 41 | retvals = { 42 | :SDL_GetPowerInfo => :int, 43 | } 44 | symbols.each do |sym| 45 | begin 46 | attach_function apis[sym], sym, args[sym], retvals[sym] 47 | rescue FFI::NotFoundError => error 48 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 49 | end 50 | end 51 | end 52 | 53 | end 54 | 55 | -------------------------------------------------------------------------------- /lib/sdl2_rect.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | def self.PointInRect(p, r) 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 | end 23 | 24 | def self.RectEmpty(r) 25 | return (!r.null? || (r.w <= 0) || (r.h <= 0)) ? 1 : 0 26 | end 27 | 28 | def self.RectEquals(a, b) 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 | end 31 | 32 | 33 | # Struct 34 | 35 | class Point < FFI::Struct 36 | layout( 37 | :x, :int, 38 | :y, :int, 39 | ) 40 | end 41 | 42 | class FPoint < FFI::Struct 43 | layout( 44 | :x, :float, 45 | :y, :float, 46 | ) 47 | end 48 | 49 | class Rect < FFI::Struct 50 | layout( 51 | :x, :int, 52 | :y, :int, 53 | :w, :int, 54 | :h, :int, 55 | ) 56 | end 57 | 58 | class FRect < FFI::Struct 59 | layout( 60 | :x, :float, 61 | :y, :float, 62 | :w, :float, 63 | :h, :float, 64 | ) 65 | end 66 | 67 | 68 | # Function 69 | 70 | def self.setup_rect_symbols(output_error = false) 71 | symbols = [ 72 | :SDL_HasIntersection, 73 | :SDL_IntersectRect, 74 | :SDL_UnionRect, 75 | :SDL_EnclosePoints, 76 | :SDL_IntersectRectAndLine, 77 | :SDL_PointInFRect, 78 | :SDL_FRectEmpty, 79 | :SDL_FRectEqualsEpsilon, 80 | :SDL_FRectEquals, 81 | :SDL_HasIntersectionF, 82 | :SDL_IntersectFRect, 83 | :SDL_UnionFRect, 84 | :SDL_EncloseFPoints, 85 | :SDL_IntersectFRectAndLine, 86 | ] 87 | apis = { 88 | :SDL_HasIntersection => :HasIntersection, 89 | :SDL_IntersectRect => :IntersectRect, 90 | :SDL_UnionRect => :UnionRect, 91 | :SDL_EnclosePoints => :EnclosePoints, 92 | :SDL_IntersectRectAndLine => :IntersectRectAndLine, 93 | :SDL_PointInFRect => :PointInFRect, 94 | :SDL_FRectEmpty => :FRectEmpty, 95 | :SDL_FRectEqualsEpsilon => :FRectEqualsEpsilon, 96 | :SDL_FRectEquals => :FRectEquals, 97 | :SDL_HasIntersectionF => :HasIntersectionF, 98 | :SDL_IntersectFRect => :IntersectFRect, 99 | :SDL_UnionFRect => :UnionFRect, 100 | :SDL_EncloseFPoints => :EncloseFPoints, 101 | :SDL_IntersectFRectAndLine => :IntersectFRectAndLine, 102 | } 103 | args = { 104 | :SDL_HasIntersection => [:pointer, :pointer], 105 | :SDL_IntersectRect => [:pointer, :pointer, :pointer], 106 | :SDL_UnionRect => [:pointer, :pointer, :pointer], 107 | :SDL_EnclosePoints => [:pointer, :int, :pointer, :pointer], 108 | :SDL_IntersectRectAndLine => [:pointer, :pointer, :pointer, :pointer, :pointer], 109 | :SDL_PointInFRect => [:pointer, :pointer], 110 | :SDL_FRectEmpty => [:pointer], 111 | :SDL_FRectEqualsEpsilon => [:pointer, :pointer, :float], 112 | :SDL_FRectEquals => [:pointer, :pointer], 113 | :SDL_HasIntersectionF => [:pointer, :pointer], 114 | :SDL_IntersectFRect => [:pointer, :pointer, :pointer], 115 | :SDL_UnionFRect => [:pointer, :pointer, :pointer], 116 | :SDL_EncloseFPoints => [:pointer, :int, :pointer, :pointer], 117 | :SDL_IntersectFRectAndLine => [:pointer, :pointer, :pointer, :pointer, :pointer], 118 | } 119 | retvals = { 120 | :SDL_HasIntersection => :int, 121 | :SDL_IntersectRect => :int, 122 | :SDL_UnionRect => :void, 123 | :SDL_EnclosePoints => :int, 124 | :SDL_IntersectRectAndLine => :int, 125 | :SDL_PointInFRect => :int, 126 | :SDL_FRectEmpty => :int, 127 | :SDL_FRectEqualsEpsilon => :int, 128 | :SDL_FRectEquals => :int, 129 | :SDL_HasIntersectionF => :int, 130 | :SDL_IntersectFRect => :int, 131 | :SDL_UnionFRect => :void, 132 | :SDL_EncloseFPoints => :int, 133 | :SDL_IntersectFRectAndLine => :int, 134 | } 135 | symbols.each do |sym| 136 | begin 137 | attach_function apis[sym], sym, args[sym], retvals[sym] 138 | rescue FFI::NotFoundError => error 139 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 140 | end 141 | end 142 | end 143 | 144 | end 145 | 146 | -------------------------------------------------------------------------------- /lib/sdl2_rotozoom.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | 20 | # Struct 21 | 22 | 23 | # Function 24 | 25 | def self.setup_gfx_rotozoom_symbols(output_error = false) 26 | symbols = [ 27 | :rotozoomSurface, 28 | :rotozoomSurfaceXY, 29 | :rotozoomSurfaceSize, 30 | :rotozoomSurfaceSizeXY, 31 | :zoomSurface, 32 | :zoomSurfaceSize, 33 | :shrinkSurface, 34 | :rotateSurface90Degrees, 35 | ] 36 | apis = { 37 | :rotozoomSurface => :rotozoomSurface, 38 | :rotozoomSurfaceXY => :rotozoomSurfaceXY, 39 | :rotozoomSurfaceSize => :rotozoomSurfaceSize, 40 | :rotozoomSurfaceSizeXY => :rotozoomSurfaceSizeXY, 41 | :zoomSurface => :zoomSurface, 42 | :zoomSurfaceSize => :zoomSurfaceSize, 43 | :shrinkSurface => :shrinkSurface, 44 | :rotateSurface90Degrees => :rotateSurface90Degrees, 45 | } 46 | args = { 47 | :rotozoomSurface => [:pointer, :double, :double, :int], 48 | :rotozoomSurfaceXY => [:pointer, :double, :double, :double, :int], 49 | :rotozoomSurfaceSize => [:int, :int, :double, :double, :pointer, :pointer], 50 | :rotozoomSurfaceSizeXY => [:int, :int, :double, :double, :double, :pointer, :pointer], 51 | :zoomSurface => [:pointer, :double, :double, :int], 52 | :zoomSurfaceSize => [:int, :int, :double, :double, :pointer, :pointer], 53 | :shrinkSurface => [:pointer, :int, :int], 54 | :rotateSurface90Degrees => [:pointer, :int], 55 | } 56 | retvals = { 57 | :rotozoomSurface => :pointer, 58 | :rotozoomSurfaceXY => :pointer, 59 | :rotozoomSurfaceSize => :void, 60 | :rotozoomSurfaceSizeXY => :void, 61 | :zoomSurface => :pointer, 62 | :zoomSurfaceSize => :void, 63 | :shrinkSurface => :pointer, 64 | :rotateSurface90Degrees => :pointer, 65 | } 66 | symbols.each do |sym| 67 | begin 68 | attach_function apis[sym], sym, args[sym], retvals[sym] 69 | rescue FFI::NotFoundError => error 70 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 71 | end 72 | end 73 | end 74 | 75 | end 76 | 77 | -------------------------------------------------------------------------------- /lib/sdl2_rwops.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | RWOPS_UNKNOWN = 0 14 | RWOPS_WINFILE = 1 15 | RWOPS_STDFILE = 2 16 | RWOPS_JNIFILE = 3 17 | RWOPS_MEMORY = 4 18 | RWOPS_MEMORY_RO = 5 19 | 20 | # Enum 21 | 22 | 23 | # Typedef 24 | 25 | 26 | RW_SEEK_SET = 0 27 | RW_SEEK_CUR = 1 28 | RW_SEEK_END = 2 29 | 30 | class RWops_mem < FFI::Struct 31 | layout( 32 | :base, :pointer, 33 | :here, :pointer, 34 | :stop, :pointer, 35 | ) 36 | end 37 | 38 | class RWops_unknown < FFI::Struct 39 | layout( 40 | :data1, :pointer, 41 | :data2, :pointer, 42 | ) 43 | end 44 | class RWops_windowsio_buffer < FFI::Struct 45 | layout( 46 | :data, :pointer, 47 | :size, :size_t, 48 | :left, :size_t, 49 | ) 50 | end 51 | 52 | class RWops_windowsio < FFI::Struct 53 | layout( 54 | :append, :int, 55 | :h, :pointer, 56 | :buffer, RWops_windowsio_buffer, 57 | ) 58 | end 59 | 60 | class Default_RWops_hidden < FFI::Union 61 | layout( 62 | :mem, RWops_mem, 63 | :unknown, RWops_unknown, 64 | ) 65 | end 66 | 67 | class Win32_RWops_hidden < FFI::Union 68 | layout( 69 | :mem, RWops_mem, 70 | :unknown, RWops_unknown, 71 | :windowsio, RWops_windowsio, 72 | ) 73 | end 74 | 75 | class Default_RWops < FFI::Struct 76 | layout( 77 | :size, :pointer, 78 | :seek, :pointer, 79 | :read, :pointer, 80 | :write, :pointer, 81 | :close, :pointer, 82 | :type, :uint, 83 | :hidden, Default_RWops_hidden, 84 | ) 85 | end 86 | 87 | class Win32_RWops < FFI::Struct 88 | layout( 89 | :size, :pointer, 90 | :seek, :pointer, 91 | :read, :pointer, 92 | :write, :pointer, 93 | :close, :pointer, 94 | :type, :uint, 95 | :hidden, Win32_RWops_hidden 96 | ) 97 | end 98 | 99 | if RUBY_PLATFORM =~ /mswin|msys|mingw|cygwin/ 100 | RWops = Win32_RWops 101 | else 102 | RWops = Default_RWops 103 | end 104 | 105 | 106 | # Struct 107 | 108 | 109 | # Function 110 | 111 | def self.setup_rwops_symbols(output_error = false) 112 | symbols = [ 113 | :SDL_RWFromFile, 114 | :SDL_RWFromFP, 115 | :SDL_RWFromMem, 116 | :SDL_RWFromConstMem, 117 | :SDL_AllocRW, 118 | :SDL_FreeRW, 119 | :SDL_RWsize, 120 | :SDL_RWseek, 121 | :SDL_RWtell, 122 | :SDL_RWread, 123 | :SDL_RWwrite, 124 | :SDL_RWclose, 125 | :SDL_LoadFile_RW, 126 | :SDL_LoadFile, 127 | :SDL_ReadU8, 128 | :SDL_ReadLE16, 129 | :SDL_ReadBE16, 130 | :SDL_ReadLE32, 131 | :SDL_ReadBE32, 132 | :SDL_ReadLE64, 133 | :SDL_ReadBE64, 134 | :SDL_WriteU8, 135 | :SDL_WriteLE16, 136 | :SDL_WriteBE16, 137 | :SDL_WriteLE32, 138 | :SDL_WriteBE32, 139 | :SDL_WriteLE64, 140 | :SDL_WriteBE64, 141 | ] 142 | apis = { 143 | :SDL_RWFromFile => :RWFromFile, 144 | :SDL_RWFromFP => :RWFromFP, 145 | :SDL_RWFromMem => :RWFromMem, 146 | :SDL_RWFromConstMem => :RWFromConstMem, 147 | :SDL_AllocRW => :AllocRW, 148 | :SDL_FreeRW => :FreeRW, 149 | :SDL_RWsize => :RWsize, 150 | :SDL_RWseek => :RWseek, 151 | :SDL_RWtell => :RWtell, 152 | :SDL_RWread => :RWread, 153 | :SDL_RWwrite => :RWwrite, 154 | :SDL_RWclose => :RWclose, 155 | :SDL_LoadFile_RW => :LoadFile_RW, 156 | :SDL_LoadFile => :LoadFile, 157 | :SDL_ReadU8 => :ReadU8, 158 | :SDL_ReadLE16 => :ReadLE16, 159 | :SDL_ReadBE16 => :ReadBE16, 160 | :SDL_ReadLE32 => :ReadLE32, 161 | :SDL_ReadBE32 => :ReadBE32, 162 | :SDL_ReadLE64 => :ReadLE64, 163 | :SDL_ReadBE64 => :ReadBE64, 164 | :SDL_WriteU8 => :WriteU8, 165 | :SDL_WriteLE16 => :WriteLE16, 166 | :SDL_WriteBE16 => :WriteBE16, 167 | :SDL_WriteLE32 => :WriteLE32, 168 | :SDL_WriteBE32 => :WriteBE32, 169 | :SDL_WriteLE64 => :WriteLE64, 170 | :SDL_WriteBE64 => :WriteBE64, 171 | } 172 | args = { 173 | :SDL_RWFromFile => [:pointer, :pointer], 174 | :SDL_RWFromFP => [:pointer, :int], 175 | :SDL_RWFromMem => [:pointer, :int], 176 | :SDL_RWFromConstMem => [:pointer, :int], 177 | :SDL_AllocRW => [], 178 | :SDL_FreeRW => [:pointer], 179 | :SDL_RWsize => [:pointer], 180 | :SDL_RWseek => [:pointer, :long_long, :int], 181 | :SDL_RWtell => [:pointer], 182 | :SDL_RWread => [:pointer, :pointer, :ulong, :ulong], 183 | :SDL_RWwrite => [:pointer, :pointer, :ulong, :ulong], 184 | :SDL_RWclose => [:pointer], 185 | :SDL_LoadFile_RW => [:pointer, :pointer, :int], 186 | :SDL_LoadFile => [:pointer, :pointer], 187 | :SDL_ReadU8 => [:pointer], 188 | :SDL_ReadLE16 => [:pointer], 189 | :SDL_ReadBE16 => [:pointer], 190 | :SDL_ReadLE32 => [:pointer], 191 | :SDL_ReadBE32 => [:pointer], 192 | :SDL_ReadLE64 => [:pointer], 193 | :SDL_ReadBE64 => [:pointer], 194 | :SDL_WriteU8 => [:pointer, :uchar], 195 | :SDL_WriteLE16 => [:pointer, :ushort], 196 | :SDL_WriteBE16 => [:pointer, :ushort], 197 | :SDL_WriteLE32 => [:pointer, :uint], 198 | :SDL_WriteBE32 => [:pointer, :uint], 199 | :SDL_WriteLE64 => [:pointer, :ulong_long], 200 | :SDL_WriteBE64 => [:pointer, :ulong_long], 201 | } 202 | retvals = { 203 | :SDL_RWFromFile => :pointer, 204 | :SDL_RWFromFP => :pointer, 205 | :SDL_RWFromMem => :pointer, 206 | :SDL_RWFromConstMem => :pointer, 207 | :SDL_AllocRW => :pointer, 208 | :SDL_FreeRW => :void, 209 | :SDL_RWsize => :long_long, 210 | :SDL_RWseek => :long_long, 211 | :SDL_RWtell => :long_long, 212 | :SDL_RWread => :ulong, 213 | :SDL_RWwrite => :ulong, 214 | :SDL_RWclose => :int, 215 | :SDL_LoadFile_RW => :pointer, 216 | :SDL_LoadFile => :pointer, 217 | :SDL_ReadU8 => :uchar, 218 | :SDL_ReadLE16 => :ushort, 219 | :SDL_ReadBE16 => :ushort, 220 | :SDL_ReadLE32 => :uint, 221 | :SDL_ReadBE32 => :uint, 222 | :SDL_ReadLE64 => :ulong_long, 223 | :SDL_ReadBE64 => :ulong_long, 224 | :SDL_WriteU8 => :ulong, 225 | :SDL_WriteLE16 => :ulong, 226 | :SDL_WriteBE16 => :ulong, 227 | :SDL_WriteLE32 => :ulong, 228 | :SDL_WriteBE32 => :ulong, 229 | :SDL_WriteLE64 => :ulong, 230 | :SDL_WriteBE64 => :ulong, 231 | } 232 | symbols.each do |sym| 233 | begin 234 | attach_function apis[sym], sym, args[sym], retvals[sym] 235 | rescue FFI::NotFoundError => error 236 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 237 | end 238 | end 239 | end 240 | 241 | end 242 | 243 | -------------------------------------------------------------------------------- /lib/sdl2_scancode.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | SCANCODE_UNKNOWN = 0 17 | SCANCODE_A = 4 18 | SCANCODE_B = 5 19 | SCANCODE_C = 6 20 | SCANCODE_D = 7 21 | SCANCODE_E = 8 22 | SCANCODE_F = 9 23 | SCANCODE_G = 10 24 | SCANCODE_H = 11 25 | SCANCODE_I = 12 26 | SCANCODE_J = 13 27 | SCANCODE_K = 14 28 | SCANCODE_L = 15 29 | SCANCODE_M = 16 30 | SCANCODE_N = 17 31 | SCANCODE_O = 18 32 | SCANCODE_P = 19 33 | SCANCODE_Q = 20 34 | SCANCODE_R = 21 35 | SCANCODE_S = 22 36 | SCANCODE_T = 23 37 | SCANCODE_U = 24 38 | SCANCODE_V = 25 39 | SCANCODE_W = 26 40 | SCANCODE_X = 27 41 | SCANCODE_Y = 28 42 | SCANCODE_Z = 29 43 | SCANCODE_1 = 30 44 | SCANCODE_2 = 31 45 | SCANCODE_3 = 32 46 | SCANCODE_4 = 33 47 | SCANCODE_5 = 34 48 | SCANCODE_6 = 35 49 | SCANCODE_7 = 36 50 | SCANCODE_8 = 37 51 | SCANCODE_9 = 38 52 | SCANCODE_0 = 39 53 | SCANCODE_RETURN = 40 54 | SCANCODE_ESCAPE = 41 55 | SCANCODE_BACKSPACE = 42 56 | SCANCODE_TAB = 43 57 | SCANCODE_SPACE = 44 58 | SCANCODE_MINUS = 45 59 | SCANCODE_EQUALS = 46 60 | SCANCODE_LEFTBRACKET = 47 61 | SCANCODE_RIGHTBRACKET = 48 62 | SCANCODE_BACKSLASH = 49 63 | SCANCODE_NONUSHASH = 50 64 | SCANCODE_SEMICOLON = 51 65 | SCANCODE_APOSTROPHE = 52 66 | SCANCODE_GRAVE = 53 67 | SCANCODE_COMMA = 54 68 | SCANCODE_PERIOD = 55 69 | SCANCODE_SLASH = 56 70 | SCANCODE_CAPSLOCK = 57 71 | SCANCODE_F1 = 58 72 | SCANCODE_F2 = 59 73 | SCANCODE_F3 = 60 74 | SCANCODE_F4 = 61 75 | SCANCODE_F5 = 62 76 | SCANCODE_F6 = 63 77 | SCANCODE_F7 = 64 78 | SCANCODE_F8 = 65 79 | SCANCODE_F9 = 66 80 | SCANCODE_F10 = 67 81 | SCANCODE_F11 = 68 82 | SCANCODE_F12 = 69 83 | SCANCODE_PRINTSCREEN = 70 84 | SCANCODE_SCROLLLOCK = 71 85 | SCANCODE_PAUSE = 72 86 | SCANCODE_INSERT = 73 87 | SCANCODE_HOME = 74 88 | SCANCODE_PAGEUP = 75 89 | SCANCODE_DELETE = 76 90 | SCANCODE_END = 77 91 | SCANCODE_PAGEDOWN = 78 92 | SCANCODE_RIGHT = 79 93 | SCANCODE_LEFT = 80 94 | SCANCODE_DOWN = 81 95 | SCANCODE_UP = 82 96 | SCANCODE_NUMLOCKCLEAR = 83 97 | SCANCODE_KP_DIVIDE = 84 98 | SCANCODE_KP_MULTIPLY = 85 99 | SCANCODE_KP_MINUS = 86 100 | SCANCODE_KP_PLUS = 87 101 | SCANCODE_KP_ENTER = 88 102 | SCANCODE_KP_1 = 89 103 | SCANCODE_KP_2 = 90 104 | SCANCODE_KP_3 = 91 105 | SCANCODE_KP_4 = 92 106 | SCANCODE_KP_5 = 93 107 | SCANCODE_KP_6 = 94 108 | SCANCODE_KP_7 = 95 109 | SCANCODE_KP_8 = 96 110 | SCANCODE_KP_9 = 97 111 | SCANCODE_KP_0 = 98 112 | SCANCODE_KP_PERIOD = 99 113 | SCANCODE_NONUSBACKSLASH = 100 114 | SCANCODE_APPLICATION = 101 115 | SCANCODE_POWER = 102 116 | SCANCODE_KP_EQUALS = 103 117 | SCANCODE_F13 = 104 118 | SCANCODE_F14 = 105 119 | SCANCODE_F15 = 106 120 | SCANCODE_F16 = 107 121 | SCANCODE_F17 = 108 122 | SCANCODE_F18 = 109 123 | SCANCODE_F19 = 110 124 | SCANCODE_F20 = 111 125 | SCANCODE_F21 = 112 126 | SCANCODE_F22 = 113 127 | SCANCODE_F23 = 114 128 | SCANCODE_F24 = 115 129 | SCANCODE_EXECUTE = 116 130 | SCANCODE_HELP = 117 131 | SCANCODE_MENU = 118 132 | SCANCODE_SELECT = 119 133 | SCANCODE_STOP = 120 134 | SCANCODE_AGAIN = 121 135 | SCANCODE_UNDO = 122 136 | SCANCODE_CUT = 123 137 | SCANCODE_COPY = 124 138 | SCANCODE_PASTE = 125 139 | SCANCODE_FIND = 126 140 | SCANCODE_MUTE = 127 141 | SCANCODE_VOLUMEUP = 128 142 | SCANCODE_VOLUMEDOWN = 129 143 | SCANCODE_KP_COMMA = 133 144 | SCANCODE_KP_EQUALSAS400 = 134 145 | SCANCODE_INTERNATIONAL1 = 135 146 | SCANCODE_INTERNATIONAL2 = 136 147 | SCANCODE_INTERNATIONAL3 = 137 148 | SCANCODE_INTERNATIONAL4 = 138 149 | SCANCODE_INTERNATIONAL5 = 139 150 | SCANCODE_INTERNATIONAL6 = 140 151 | SCANCODE_INTERNATIONAL7 = 141 152 | SCANCODE_INTERNATIONAL8 = 142 153 | SCANCODE_INTERNATIONAL9 = 143 154 | SCANCODE_LANG1 = 144 155 | SCANCODE_LANG2 = 145 156 | SCANCODE_LANG3 = 146 157 | SCANCODE_LANG4 = 147 158 | SCANCODE_LANG5 = 148 159 | SCANCODE_LANG6 = 149 160 | SCANCODE_LANG7 = 150 161 | SCANCODE_LANG8 = 151 162 | SCANCODE_LANG9 = 152 163 | SCANCODE_ALTERASE = 153 164 | SCANCODE_SYSREQ = 154 165 | SCANCODE_CANCEL = 155 166 | SCANCODE_CLEAR = 156 167 | SCANCODE_PRIOR = 157 168 | SCANCODE_RETURN2 = 158 169 | SCANCODE_SEPARATOR = 159 170 | SCANCODE_OUT = 160 171 | SCANCODE_OPER = 161 172 | SCANCODE_CLEARAGAIN = 162 173 | SCANCODE_CRSEL = 163 174 | SCANCODE_EXSEL = 164 175 | SCANCODE_KP_00 = 176 176 | SCANCODE_KP_000 = 177 177 | SCANCODE_THOUSANDSSEPARATOR = 178 178 | SCANCODE_DECIMALSEPARATOR = 179 179 | SCANCODE_CURRENCYUNIT = 180 180 | SCANCODE_CURRENCYSUBUNIT = 181 181 | SCANCODE_KP_LEFTPAREN = 182 182 | SCANCODE_KP_RIGHTPAREN = 183 183 | SCANCODE_KP_LEFTBRACE = 184 184 | SCANCODE_KP_RIGHTBRACE = 185 185 | SCANCODE_KP_TAB = 186 186 | SCANCODE_KP_BACKSPACE = 187 187 | SCANCODE_KP_A = 188 188 | SCANCODE_KP_B = 189 189 | SCANCODE_KP_C = 190 190 | SCANCODE_KP_D = 191 191 | SCANCODE_KP_E = 192 192 | SCANCODE_KP_F = 193 193 | SCANCODE_KP_XOR = 194 194 | SCANCODE_KP_POWER = 195 195 | SCANCODE_KP_PERCENT = 196 196 | SCANCODE_KP_LESS = 197 197 | SCANCODE_KP_GREATER = 198 198 | SCANCODE_KP_AMPERSAND = 199 199 | SCANCODE_KP_DBLAMPERSAND = 200 200 | SCANCODE_KP_VERTICALBAR = 201 201 | SCANCODE_KP_DBLVERTICALBAR = 202 202 | SCANCODE_KP_COLON = 203 203 | SCANCODE_KP_HASH = 204 204 | SCANCODE_KP_SPACE = 205 205 | SCANCODE_KP_AT = 206 206 | SCANCODE_KP_EXCLAM = 207 207 | SCANCODE_KP_MEMSTORE = 208 208 | SCANCODE_KP_MEMRECALL = 209 209 | SCANCODE_KP_MEMCLEAR = 210 210 | SCANCODE_KP_MEMADD = 211 211 | SCANCODE_KP_MEMSUBTRACT = 212 212 | SCANCODE_KP_MEMMULTIPLY = 213 213 | SCANCODE_KP_MEMDIVIDE = 214 214 | SCANCODE_KP_PLUSMINUS = 215 215 | SCANCODE_KP_CLEAR = 216 216 | SCANCODE_KP_CLEARENTRY = 217 217 | SCANCODE_KP_BINARY = 218 218 | SCANCODE_KP_OCTAL = 219 219 | SCANCODE_KP_DECIMAL = 220 220 | SCANCODE_KP_HEXADECIMAL = 221 221 | SCANCODE_LCTRL = 224 222 | SCANCODE_LSHIFT = 225 223 | SCANCODE_LALT = 226 224 | SCANCODE_LGUI = 227 225 | SCANCODE_RCTRL = 228 226 | SCANCODE_RSHIFT = 229 227 | SCANCODE_RALT = 230 228 | SCANCODE_RGUI = 231 229 | SCANCODE_MODE = 257 230 | SCANCODE_AUDIONEXT = 258 231 | SCANCODE_AUDIOPREV = 259 232 | SCANCODE_AUDIOSTOP = 260 233 | SCANCODE_AUDIOPLAY = 261 234 | SCANCODE_AUDIOMUTE = 262 235 | SCANCODE_MEDIASELECT = 263 236 | SCANCODE_WWW = 264 237 | SCANCODE_MAIL = 265 238 | SCANCODE_CALCULATOR = 266 239 | SCANCODE_COMPUTER = 267 240 | SCANCODE_AC_SEARCH = 268 241 | SCANCODE_AC_HOME = 269 242 | SCANCODE_AC_BACK = 270 243 | SCANCODE_AC_FORWARD = 271 244 | SCANCODE_AC_STOP = 272 245 | SCANCODE_AC_REFRESH = 273 246 | SCANCODE_AC_BOOKMARKS = 274 247 | SCANCODE_BRIGHTNESSDOWN = 275 248 | SCANCODE_BRIGHTNESSUP = 276 249 | SCANCODE_DISPLAYSWITCH = 277 250 | SCANCODE_KBDILLUMTOGGLE = 278 251 | SCANCODE_KBDILLUMDOWN = 279 252 | SCANCODE_KBDILLUMUP = 280 253 | SCANCODE_EJECT = 281 254 | SCANCODE_SLEEP = 282 255 | SCANCODE_APP1 = 283 256 | SCANCODE_APP2 = 284 257 | SCANCODE_AUDIOREWIND = 285 258 | SCANCODE_AUDIOFASTFORWARD = 286 259 | SCANCODE_SOFTLEFT = 287 260 | SCANCODE_SOFTRIGHT = 288 261 | SCANCODE_CALL = 289 262 | SCANCODE_ENDCALL = 290 263 | NUM_SCANCODES = 512 264 | 265 | # Typedef 266 | 267 | typedef :int, :SDL_Scancode 268 | 269 | # Struct 270 | 271 | 272 | # Function 273 | 274 | def self.setup_scancode_symbols(output_error = false) 275 | symbols = [ 276 | ] 277 | apis = { 278 | } 279 | args = { 280 | } 281 | retvals = { 282 | } 283 | symbols.each do |sym| 284 | begin 285 | attach_function apis[sym], sym, args[sym], retvals[sym] 286 | rescue FFI::NotFoundError => error 287 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 288 | end 289 | end 290 | end 291 | 292 | end 293 | 294 | -------------------------------------------------------------------------------- /lib/sdl2_sensor.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | STANDARD_GRAVITY = 9.80665 14 | 15 | # Enum 16 | 17 | SENSOR_INVALID = -1 18 | SENSOR_UNKNOWN = 0 19 | SENSOR_ACCEL = 1 20 | SENSOR_GYRO = 2 21 | SENSOR_ACCEL_L = 3 22 | SENSOR_GYRO_L = 4 23 | SENSOR_ACCEL_R = 5 24 | SENSOR_GYRO_R = 6 25 | 26 | # Typedef 27 | 28 | typedef :int, :SDL_SensorID 29 | typedef :int, :SDL_SensorType 30 | 31 | # Struct 32 | 33 | 34 | # Function 35 | 36 | def self.setup_sensor_symbols(output_error = false) 37 | symbols = [ 38 | :SDL_LockSensors, 39 | :SDL_UnlockSensors, 40 | :SDL_NumSensors, 41 | :SDL_SensorGetDeviceName, 42 | :SDL_SensorGetDeviceType, 43 | :SDL_SensorGetDeviceNonPortableType, 44 | :SDL_SensorGetDeviceInstanceID, 45 | :SDL_SensorOpen, 46 | :SDL_SensorFromInstanceID, 47 | :SDL_SensorGetName, 48 | :SDL_SensorGetType, 49 | :SDL_SensorGetNonPortableType, 50 | :SDL_SensorGetInstanceID, 51 | :SDL_SensorGetData, 52 | :SDL_SensorGetDataWithTimestamp, 53 | :SDL_SensorClose, 54 | :SDL_SensorUpdate, 55 | ] 56 | apis = { 57 | :SDL_LockSensors => :LockSensors, 58 | :SDL_UnlockSensors => :UnlockSensors, 59 | :SDL_NumSensors => :NumSensors, 60 | :SDL_SensorGetDeviceName => :SensorGetDeviceName, 61 | :SDL_SensorGetDeviceType => :SensorGetDeviceType, 62 | :SDL_SensorGetDeviceNonPortableType => :SensorGetDeviceNonPortableType, 63 | :SDL_SensorGetDeviceInstanceID => :SensorGetDeviceInstanceID, 64 | :SDL_SensorOpen => :SensorOpen, 65 | :SDL_SensorFromInstanceID => :SensorFromInstanceID, 66 | :SDL_SensorGetName => :SensorGetName, 67 | :SDL_SensorGetType => :SensorGetType, 68 | :SDL_SensorGetNonPortableType => :SensorGetNonPortableType, 69 | :SDL_SensorGetInstanceID => :SensorGetInstanceID, 70 | :SDL_SensorGetData => :SensorGetData, 71 | :SDL_SensorGetDataWithTimestamp => :SensorGetDataWithTimestamp, 72 | :SDL_SensorClose => :SensorClose, 73 | :SDL_SensorUpdate => :SensorUpdate, 74 | } 75 | args = { 76 | :SDL_LockSensors => [], 77 | :SDL_UnlockSensors => [], 78 | :SDL_NumSensors => [], 79 | :SDL_SensorGetDeviceName => [:int], 80 | :SDL_SensorGetDeviceType => [:int], 81 | :SDL_SensorGetDeviceNonPortableType => [:int], 82 | :SDL_SensorGetDeviceInstanceID => [:int], 83 | :SDL_SensorOpen => [:int], 84 | :SDL_SensorFromInstanceID => [:int], 85 | :SDL_SensorGetName => [:pointer], 86 | :SDL_SensorGetType => [:pointer], 87 | :SDL_SensorGetNonPortableType => [:pointer], 88 | :SDL_SensorGetInstanceID => [:pointer], 89 | :SDL_SensorGetData => [:pointer, :pointer, :int], 90 | :SDL_SensorGetDataWithTimestamp => [:pointer, :pointer, :pointer, :int], 91 | :SDL_SensorClose => [:pointer], 92 | :SDL_SensorUpdate => [], 93 | } 94 | retvals = { 95 | :SDL_LockSensors => :void, 96 | :SDL_UnlockSensors => :void, 97 | :SDL_NumSensors => :int, 98 | :SDL_SensorGetDeviceName => :pointer, 99 | :SDL_SensorGetDeviceType => :int, 100 | :SDL_SensorGetDeviceNonPortableType => :int, 101 | :SDL_SensorGetDeviceInstanceID => :int, 102 | :SDL_SensorOpen => :pointer, 103 | :SDL_SensorFromInstanceID => :pointer, 104 | :SDL_SensorGetName => :pointer, 105 | :SDL_SensorGetType => :int, 106 | :SDL_SensorGetNonPortableType => :int, 107 | :SDL_SensorGetInstanceID => :int, 108 | :SDL_SensorGetData => :int, 109 | :SDL_SensorGetDataWithTimestamp => :int, 110 | :SDL_SensorClose => :void, 111 | :SDL_SensorUpdate => :void, 112 | } 113 | symbols.each do |sym| 114 | begin 115 | attach_function apis[sym], sym, args[sym], retvals[sym] 116 | rescue FFI::NotFoundError => error 117 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 118 | end 119 | end 120 | end 121 | 122 | end 123 | 124 | -------------------------------------------------------------------------------- /lib/sdl2_shape.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | require_relative 'sdl2_pixels' 9 | 10 | module SDL 11 | extend FFI::Library 12 | # Define/Macro 13 | 14 | NONSHAPEABLE_WINDOW = -1 15 | INVALID_SHAPE_ARGUMENT = -2 16 | WINDOW_LACKS_SHAPE = -3 17 | 18 | # Enum 19 | 20 | ShapeModeDefault = 0 21 | ShapeModeBinarizeAlpha = 1 22 | ShapeModeReverseBinarizeAlpha = 2 23 | ShapeModeColorKey = 3 24 | 25 | # Typedef 26 | 27 | typedef :int, :WindowShapeMode 28 | 29 | # Struct 30 | 31 | class WindowShapeParams < FFI::Union 32 | layout( 33 | :binarizationCutoff, :uchar, 34 | :colorKey, Color, 35 | ) 36 | end 37 | 38 | class WindowShapeMode < FFI::Struct 39 | layout( 40 | :mode, :int, 41 | :parameters, WindowShapeParams, 42 | ) 43 | end 44 | 45 | 46 | # Function 47 | 48 | def self.setup_shape_symbols(output_error = false) 49 | symbols = [ 50 | :SDL_CreateShapedWindow, 51 | :SDL_IsShapedWindow, 52 | :SDL_SetWindowShape, 53 | :SDL_GetShapedWindowMode, 54 | ] 55 | apis = { 56 | :SDL_CreateShapedWindow => :CreateShapedWindow, 57 | :SDL_IsShapedWindow => :IsShapedWindow, 58 | :SDL_SetWindowShape => :SetWindowShape, 59 | :SDL_GetShapedWindowMode => :GetShapedWindowMode, 60 | } 61 | args = { 62 | :SDL_CreateShapedWindow => [:pointer, :uint, :uint, :uint, :uint, :uint], 63 | :SDL_IsShapedWindow => [:pointer], 64 | :SDL_SetWindowShape => [:pointer, :pointer, :pointer], 65 | :SDL_GetShapedWindowMode => [:pointer, :pointer], 66 | } 67 | retvals = { 68 | :SDL_CreateShapedWindow => :pointer, 69 | :SDL_IsShapedWindow => :int, 70 | :SDL_SetWindowShape => :int, 71 | :SDL_GetShapedWindowMode => :int, 72 | } 73 | symbols.each do |sym| 74 | begin 75 | attach_function apis[sym], sym, args[sym], retvals[sym] 76 | rescue FFI::NotFoundError => error 77 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 78 | end 79 | end 80 | end 81 | 82 | end 83 | 84 | -------------------------------------------------------------------------------- /lib/sdl2_sound.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | SOUND_VER_MAJOR = 2 14 | SOUND_VER_MINOR = 0 15 | SOUND_VER_PATCH = 2 16 | 17 | # Enum 18 | 19 | SOUND_SAMPLEFLAG_NONE = 0 20 | SOUND_SAMPLEFLAG_CANSEEK = 1 21 | SOUND_SAMPLEFLAG_EOF = 536870912 22 | SOUND_SAMPLEFLAG_ERROR = 1073741824 23 | SOUND_SAMPLEFLAG_EAGAIN = -2147483648 24 | 25 | # Typedef 26 | 27 | typedef :int, :Sound_SampleFlags 28 | 29 | # Struct 30 | 31 | class Sound_AudioInfo < FFI::Struct 32 | layout( 33 | :format, :ushort, 34 | :channels, :uchar, 35 | :rate, :uint, 36 | ) 37 | end 38 | 39 | class Sound_DecoderInfo < FFI::Struct 40 | layout( 41 | :extensions, :pointer, 42 | :description, :pointer, 43 | :author, :pointer, 44 | :url, :pointer, 45 | ) 46 | end 47 | 48 | class Sound_Sample < FFI::Struct 49 | layout( 50 | :opaque, :pointer, 51 | :decoder, :pointer, 52 | :desired, Sound_AudioInfo, 53 | :actual, Sound_AudioInfo, 54 | :buffer, :pointer, 55 | :buffer_size, :uint, 56 | :flags, :int, 57 | ) 58 | end 59 | 60 | class Sound_Version < FFI::Struct 61 | layout( 62 | :major, :int, 63 | :minor, :int, 64 | :patch, :int, 65 | ) 66 | end 67 | 68 | 69 | # Function 70 | 71 | def self.setup_sound_symbols(output_error = false) 72 | symbols = [ 73 | :Sound_GetLinkedVersion, 74 | :Sound_Init, 75 | :Sound_Quit, 76 | :Sound_AvailableDecoders, 77 | :Sound_GetError, 78 | :Sound_ClearError, 79 | :Sound_NewSample, 80 | :Sound_NewSampleFromMem, 81 | :Sound_NewSampleFromFile, 82 | :Sound_FreeSample, 83 | :Sound_GetDuration, 84 | :Sound_SetBufferSize, 85 | :Sound_Decode, 86 | :Sound_DecodeAll, 87 | :Sound_Rewind, 88 | :Sound_Seek, 89 | ] 90 | apis = { 91 | :Sound_GetLinkedVersion => :Sound_GetLinkedVersion, 92 | :Sound_Init => :Sound_Init, 93 | :Sound_Quit => :Sound_Quit, 94 | :Sound_AvailableDecoders => :Sound_AvailableDecoders, 95 | :Sound_GetError => :Sound_GetError, 96 | :Sound_ClearError => :Sound_ClearError, 97 | :Sound_NewSample => :Sound_NewSample, 98 | :Sound_NewSampleFromMem => :Sound_NewSampleFromMem, 99 | :Sound_NewSampleFromFile => :Sound_NewSampleFromFile, 100 | :Sound_FreeSample => :Sound_FreeSample, 101 | :Sound_GetDuration => :Sound_GetDuration, 102 | :Sound_SetBufferSize => :Sound_SetBufferSize, 103 | :Sound_Decode => :Sound_Decode, 104 | :Sound_DecodeAll => :Sound_DecodeAll, 105 | :Sound_Rewind => :Sound_Rewind, 106 | :Sound_Seek => :Sound_Seek, 107 | } 108 | args = { 109 | :Sound_GetLinkedVersion => [:pointer], 110 | :Sound_Init => [], 111 | :Sound_Quit => [], 112 | :Sound_AvailableDecoders => [], 113 | :Sound_GetError => [], 114 | :Sound_ClearError => [], 115 | :Sound_NewSample => [:pointer, :pointer, :pointer, :uint], 116 | :Sound_NewSampleFromMem => [:pointer, :uint, :pointer, :pointer, :uint], 117 | :Sound_NewSampleFromFile => [:pointer, :pointer, :uint], 118 | :Sound_FreeSample => [:pointer], 119 | :Sound_GetDuration => [:pointer], 120 | :Sound_SetBufferSize => [:pointer, :uint], 121 | :Sound_Decode => [:pointer], 122 | :Sound_DecodeAll => [:pointer], 123 | :Sound_Rewind => [:pointer], 124 | :Sound_Seek => [:pointer, :uint], 125 | } 126 | retvals = { 127 | :Sound_GetLinkedVersion => :void, 128 | :Sound_Init => :int, 129 | :Sound_Quit => :int, 130 | :Sound_AvailableDecoders => :pointer, 131 | :Sound_GetError => :pointer, 132 | :Sound_ClearError => :void, 133 | :Sound_NewSample => :pointer, 134 | :Sound_NewSampleFromMem => :pointer, 135 | :Sound_NewSampleFromFile => :pointer, 136 | :Sound_FreeSample => :void, 137 | :Sound_GetDuration => :int, 138 | :Sound_SetBufferSize => :int, 139 | :Sound_Decode => :uint, 140 | :Sound_DecodeAll => :uint, 141 | :Sound_Rewind => :int, 142 | :Sound_Seek => :int, 143 | } 144 | symbols.each do |sym| 145 | begin 146 | attach_function apis[sym], sym, args[sym], retvals[sym] 147 | rescue FFI::NotFoundError => error 148 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 149 | end 150 | end 151 | end 152 | 153 | end 154 | 155 | -------------------------------------------------------------------------------- /lib/sdl2_syswm.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | require_relative 'sdl2_version' 9 | 10 | module SDL 11 | extend FFI::Library 12 | # Define/Macro 13 | 14 | METALVIEW_TAG = 255 15 | 16 | # Enum 17 | 18 | SYSWM_UNKNOWN = 0 19 | SYSWM_WINDOWS = 1 20 | SYSWM_X11 = 2 21 | SYSWM_DIRECTFB = 3 22 | SYSWM_COCOA = 4 23 | SYSWM_UIKIT = 5 24 | SYSWM_WAYLAND = 6 25 | SYSWM_MIR = 7 26 | SYSWM_WINRT = 8 27 | SYSWM_ANDROID = 9 28 | SYSWM_VIVANTE = 10 29 | SYSWM_OS2 = 11 30 | SYSWM_HAIKU = 12 31 | SYSWM_KMSDRM = 13 32 | SYSWM_RISCOS = 14 33 | 34 | # Typedef 35 | 36 | typedef :int, :SDL_SYSWM_TYPE 37 | 38 | class SysWMmsg_def_win < FFI::Struct 39 | layout( 40 | :hwnd, :pointer, 41 | :msg, :uint32, 42 | :wParam, :uint64, 43 | :lParam, :int64 44 | ) 45 | end 46 | 47 | class SysWMmsg_value_win < FFI::Union 48 | layout( 49 | :win, SysWMmsg_def_win.by_value, 50 | :dummy, :int 51 | ) 52 | end 53 | 54 | class SysWMmsg_win < FFI::Struct 55 | layout( 56 | :version, Version.by_value, 57 | :subsystem, :int, 58 | :msg, SysWMmsg_value_win.by_value 59 | ) 60 | end 61 | 62 | 63 | class SysWMmsg_def_cocoa < FFI::Struct 64 | layout( 65 | :dummy, :int 66 | ) 67 | end 68 | 69 | class SysWMmsg_value_cocoa < FFI::Union 70 | layout( 71 | :cocoa, SysWMmsg_def_cocoa.by_value, 72 | :dummy, :int 73 | ) 74 | end 75 | 76 | class SysWMmsg_cocoa < FFI::Struct 77 | layout( 78 | :version, Version.by_value, 79 | :subsystem, :int, 80 | :msg, SysWMmsg_value_cocoa.by_value 81 | ) 82 | end 83 | 84 | 85 | class SysWMmsg_def_x11 < FFI::Struct 86 | layout( 87 | :event, [:long, 24] # /usr/include/X11/Xlib.h 88 | ) 89 | end 90 | 91 | class SysWMmsg_value_x11 < FFI::Union 92 | layout( 93 | :x11, SysWMmsg_def_x11.by_value, 94 | :dummy, :int 95 | ) 96 | end 97 | 98 | class SysWMmsg_x11 < FFI::Struct 99 | layout( 100 | :version, Version.by_value, 101 | :subsystem, :int, 102 | :msg, SysWMmsg_value_x11.by_value 103 | ) 104 | end 105 | 106 | ################################################################################ 107 | 108 | class SysWMinfo_def_win < FFI::Struct 109 | layout( 110 | :window, :pointer, 111 | :hdc, :pointer, 112 | :hinstance, :pointer 113 | ) 114 | end 115 | 116 | class SysWMinfo_value_win < FFI::Union 117 | layout( 118 | :win, SysWMinfo_def_win.by_value, 119 | :dummy, [:uint8, 64] 120 | ) 121 | end 122 | 123 | class SysWMinfo_win < FFI::Struct 124 | layout( 125 | :version, Version.by_value, 126 | :subsystem, :int, 127 | :info, SysWMinfo_value_win.by_value 128 | ) 129 | end 130 | 131 | 132 | class SysWMinfo_def_cocoa < FFI::Struct 133 | layout( 134 | :window, :pointer 135 | ) 136 | end 137 | 138 | class SysWMinfo_value_cocoa < FFI::Union 139 | layout( 140 | :cocoa, SysWMinfo_def_cocoa.by_value, 141 | :dummy, [:uint8, 64] 142 | ) 143 | end 144 | 145 | class SysWMinfo_cocoa < FFI::Struct 146 | layout( 147 | :version, Version.by_value, 148 | :subsystem, :int, 149 | :info, SysWMinfo_value_cocoa.by_value 150 | ) 151 | end 152 | 153 | 154 | class SysWMinfo_def_x11 < FFI::Struct 155 | layout( 156 | :display, :pointer, 157 | :window, :ulong # /usr/include/X11/X.h 158 | ) 159 | end 160 | 161 | class SysWMinfo_value_x11 < FFI::Union 162 | layout( 163 | :x11, SysWMinfo_def_x11.by_value, 164 | :dummy, [:uint8, 64] 165 | ) 166 | end 167 | 168 | class SysWMinfo_x11 < FFI::Struct 169 | layout( 170 | :version, Version.by_value, 171 | :subsystem, :int, 172 | :info, SysWMinfo_value_x11.by_value 173 | ) 174 | end 175 | 176 | 177 | class SysWMinfo_def_wl < FFI::Struct 178 | layout( 179 | :display, :pointer, 180 | :surface, :pointer, 181 | :shell_surface, :pointer, 182 | :egl_window, :pointer, 183 | :xdg_surface, :pointer, 184 | :xdg_toplevel, :pointer, 185 | :xdg_popup, :pointer, 186 | :xdg_positioner, :pointer 187 | ) 188 | end 189 | 190 | class SysWMinfo_value_wl < FFI::Union 191 | layout( 192 | :wl, SysWMinfo_def_wl.by_value, 193 | :dummy, [:uint8, 64] 194 | ) 195 | end 196 | 197 | class SysWMinfo_wl < FFI::Struct 198 | layout( 199 | :version, Version.by_value, 200 | :subsystem, :int, 201 | :info, SysWMinfo_value_wl.by_value 202 | ) 203 | end 204 | 205 | 206 | # Struct 207 | 208 | 209 | # Function 210 | 211 | def self.setup_syswm_symbols(output_error = false) 212 | symbols = [ 213 | :SDL_GetWindowWMInfo, 214 | ] 215 | apis = { 216 | :SDL_GetWindowWMInfo => :GetWindowWMInfo, 217 | } 218 | args = { 219 | :SDL_GetWindowWMInfo => [:pointer, :pointer], 220 | } 221 | retvals = { 222 | :SDL_GetWindowWMInfo => :int, 223 | } 224 | symbols.each do |sym| 225 | begin 226 | attach_function apis[sym], sym, args[sym], retvals[sym] 227 | rescue FFI::NotFoundError => error 228 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 229 | end 230 | end 231 | end 232 | 233 | end 234 | 235 | -------------------------------------------------------------------------------- /lib/sdl2_timer.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | callback :SDL_TimerCallback, [:uint, :pointer], :uint 20 | typedef :int, :SDL_TimerID 21 | 22 | # Struct 23 | 24 | 25 | # Function 26 | 27 | def self.setup_timer_symbols(output_error = false) 28 | symbols = [ 29 | :SDL_GetTicks, 30 | :SDL_GetTicks64, 31 | :SDL_GetPerformanceCounter, 32 | :SDL_GetPerformanceFrequency, 33 | :SDL_Delay, 34 | :SDL_AddTimer, 35 | :SDL_RemoveTimer, 36 | ] 37 | apis = { 38 | :SDL_GetTicks => :GetTicks, 39 | :SDL_GetTicks64 => :GetTicks64, 40 | :SDL_GetPerformanceCounter => :GetPerformanceCounter, 41 | :SDL_GetPerformanceFrequency => :GetPerformanceFrequency, 42 | :SDL_Delay => :Delay, 43 | :SDL_AddTimer => :AddTimer, 44 | :SDL_RemoveTimer => :RemoveTimer, 45 | } 46 | args = { 47 | :SDL_GetTicks => [], 48 | :SDL_GetTicks64 => [], 49 | :SDL_GetPerformanceCounter => [], 50 | :SDL_GetPerformanceFrequency => [], 51 | :SDL_Delay => [:uint], 52 | :SDL_AddTimer => [:uint, :SDL_TimerCallback, :pointer], 53 | :SDL_RemoveTimer => [:int], 54 | } 55 | retvals = { 56 | :SDL_GetTicks => :uint, 57 | :SDL_GetTicks64 => :ulong_long, 58 | :SDL_GetPerformanceCounter => :ulong_long, 59 | :SDL_GetPerformanceFrequency => :ulong_long, 60 | :SDL_Delay => :void, 61 | :SDL_AddTimer => :int, 62 | :SDL_RemoveTimer => :int, 63 | } 64 | symbols.each do |sym| 65 | begin 66 | attach_function apis[sym], sym, args[sym], retvals[sym] 67 | rescue FFI::NotFoundError => error 68 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 69 | end 70 | end 71 | end 72 | 73 | end 74 | 75 | -------------------------------------------------------------------------------- /lib/sdl2_touch.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | TOUCH_MOUSEID = 4294967295 14 | MOUSE_TOUCHID = -1 15 | 16 | # Enum 17 | 18 | TOUCH_DEVICE_INVALID = -1 19 | TOUCH_DEVICE_DIRECT = 0 20 | TOUCH_DEVICE_INDIRECT_ABSOLUTE = 1 21 | TOUCH_DEVICE_INDIRECT_RELATIVE = 2 22 | 23 | # Typedef 24 | 25 | typedef :long_long, :SDL_TouchID 26 | typedef :long_long, :SDL_FingerID 27 | typedef :int, :SDL_TouchDeviceType 28 | 29 | # Struct 30 | 31 | class Finger < FFI::Struct 32 | layout( 33 | :id, :long_long, 34 | :x, :float, 35 | :y, :float, 36 | :pressure, :float, 37 | ) 38 | end 39 | 40 | 41 | # Function 42 | 43 | def self.setup_touch_symbols(output_error = false) 44 | symbols = [ 45 | :SDL_GetNumTouchDevices, 46 | :SDL_GetTouchDevice, 47 | :SDL_GetTouchName, 48 | :SDL_GetTouchDeviceType, 49 | :SDL_GetNumTouchFingers, 50 | :SDL_GetTouchFinger, 51 | ] 52 | apis = { 53 | :SDL_GetNumTouchDevices => :GetNumTouchDevices, 54 | :SDL_GetTouchDevice => :GetTouchDevice, 55 | :SDL_GetTouchName => :GetTouchName, 56 | :SDL_GetTouchDeviceType => :GetTouchDeviceType, 57 | :SDL_GetNumTouchFingers => :GetNumTouchFingers, 58 | :SDL_GetTouchFinger => :GetTouchFinger, 59 | } 60 | args = { 61 | :SDL_GetNumTouchDevices => [], 62 | :SDL_GetTouchDevice => [:int], 63 | :SDL_GetTouchName => [:int], 64 | :SDL_GetTouchDeviceType => [:long_long], 65 | :SDL_GetNumTouchFingers => [:long_long], 66 | :SDL_GetTouchFinger => [:long_long, :int], 67 | } 68 | retvals = { 69 | :SDL_GetNumTouchDevices => :int, 70 | :SDL_GetTouchDevice => :long_long, 71 | :SDL_GetTouchName => :pointer, 72 | :SDL_GetTouchDeviceType => :int, 73 | :SDL_GetNumTouchFingers => :int, 74 | :SDL_GetTouchFinger => :pointer, 75 | } 76 | symbols.each do |sym| 77 | begin 78 | attach_function apis[sym], sym, args[sym], retvals[sym] 79 | rescue FFI::NotFoundError => error 80 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 81 | end 82 | end 83 | end 84 | 85 | end 86 | 87 | -------------------------------------------------------------------------------- /lib/sdl2_version.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | MAJOR_VERSION = 2 14 | MINOR_VERSION = 30 15 | PATCHLEVEL = 0 16 | 17 | # Enum 18 | 19 | 20 | # Typedef 21 | 22 | 23 | # Struct 24 | 25 | class Version < FFI::Struct 26 | layout( 27 | :major, :uchar, 28 | :minor, :uchar, 29 | :patch, :uchar, 30 | ) 31 | end 32 | 33 | 34 | # Function 35 | 36 | def self.setup_version_symbols(output_error = false) 37 | symbols = [ 38 | :SDL_GetVersion, 39 | :SDL_GetRevision, 40 | :SDL_GetRevisionNumber, 41 | ] 42 | apis = { 43 | :SDL_GetVersion => :GetVersion, 44 | :SDL_GetRevision => :GetRevision, 45 | :SDL_GetRevisionNumber => :GetRevisionNumber, 46 | } 47 | args = { 48 | :SDL_GetVersion => [:pointer], 49 | :SDL_GetRevision => [], 50 | :SDL_GetRevisionNumber => [], 51 | } 52 | retvals = { 53 | :SDL_GetVersion => :void, 54 | :SDL_GetRevision => :pointer, 55 | :SDL_GetRevisionNumber => :int, 56 | } 57 | symbols.each do |sym| 58 | begin 59 | attach_function apis[sym], sym, args[sym], retvals[sym] 60 | rescue FFI::NotFoundError => error 61 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 62 | end 63 | end 64 | end 65 | 66 | end 67 | 68 | -------------------------------------------------------------------------------- /lib/sdl2_vulkan.rb: -------------------------------------------------------------------------------- 1 | # Ruby-SDL2 : Yet another SDL2 wrapper for Ruby 2 | # 3 | # * https://github.com/vaiorabbit/sdl2-bindings 4 | # 5 | # [NOTICE] This is an automatically generated file. 6 | 7 | require 'ffi' 8 | 9 | module SDL 10 | extend FFI::Library 11 | # Define/Macro 12 | 13 | 14 | # Enum 15 | 16 | 17 | # Typedef 18 | 19 | typedef :pointer, :VkInstance 20 | typedef :pointer, :VkSurfaceKHR 21 | typedef :pointer, :SDL_vulkanInstance 22 | typedef :pointer, :SDL_vulkanSurface 23 | 24 | # Struct 25 | 26 | 27 | # Function 28 | 29 | def self.setup_vulkan_symbols(output_error = false) 30 | symbols = [ 31 | :SDL_Vulkan_LoadLibrary, 32 | :SDL_Vulkan_GetVkGetInstanceProcAddr, 33 | :SDL_Vulkan_UnloadLibrary, 34 | :SDL_Vulkan_GetInstanceExtensions, 35 | :SDL_Vulkan_CreateSurface, 36 | :SDL_Vulkan_GetDrawableSize, 37 | ] 38 | apis = { 39 | :SDL_Vulkan_LoadLibrary => :Vulkan_LoadLibrary, 40 | :SDL_Vulkan_GetVkGetInstanceProcAddr => :Vulkan_GetVkGetInstanceProcAddr, 41 | :SDL_Vulkan_UnloadLibrary => :Vulkan_UnloadLibrary, 42 | :SDL_Vulkan_GetInstanceExtensions => :Vulkan_GetInstanceExtensions, 43 | :SDL_Vulkan_CreateSurface => :Vulkan_CreateSurface, 44 | :SDL_Vulkan_GetDrawableSize => :Vulkan_GetDrawableSize, 45 | } 46 | args = { 47 | :SDL_Vulkan_LoadLibrary => [:pointer], 48 | :SDL_Vulkan_GetVkGetInstanceProcAddr => [], 49 | :SDL_Vulkan_UnloadLibrary => [], 50 | :SDL_Vulkan_GetInstanceExtensions => [:pointer, :pointer, :pointer], 51 | :SDL_Vulkan_CreateSurface => [:pointer, :pointer, :pointer], 52 | :SDL_Vulkan_GetDrawableSize => [:pointer, :pointer, :pointer], 53 | } 54 | retvals = { 55 | :SDL_Vulkan_LoadLibrary => :int, 56 | :SDL_Vulkan_GetVkGetInstanceProcAddr => :pointer, 57 | :SDL_Vulkan_UnloadLibrary => :void, 58 | :SDL_Vulkan_GetInstanceExtensions => :int, 59 | :SDL_Vulkan_CreateSurface => :int, 60 | :SDL_Vulkan_GetDrawableSize => :void, 61 | } 62 | symbols.each do |sym| 63 | begin 64 | attach_function apis[sym], sym, args[sym], retvals[sym] 65 | rescue FFI::NotFoundError => error 66 | $stderr.puts("[Warning] Failed to import #{sym} (#{error}).") if output_error 67 | end 68 | end 69 | end 70 | 71 | end 72 | 73 | -------------------------------------------------------------------------------- /sdl2-bindings.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "sdl2-bindings" 7 | spec.version = "0.2.3" 8 | spec.authors = ["vaiorabbit"] 9 | spec.email = ["vaiorabbit@gmail.com"] 10 | spec.summary = %q{Bindings for SDL2} 11 | spec.homepage = "https://github.com/vaiorabbit/sdl2-bindings" 12 | spec.require_paths = ["lib"] 13 | spec.license = "Zlib" 14 | spec.description = <<-DESC 15 | Ruby bindings for SDL2. 16 | DESC 17 | 18 | spec.required_ruby_version = '>= 3.0.0' 19 | 20 | spec.add_runtime_dependency 'ffi', '~> 1.15' 21 | 22 | spec.files = Dir.glob("lib/*.rb") + 23 | ["README.md", "LICENSE.txt", "ChangeLog"] 24 | end 25 | -------------------------------------------------------------------------------- /test/256px-Globe.svg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/sdl2-bindings/61df5ed6d6d870815defa5a6fda2b0d7523e6826/test/256px-Globe.svg.png -------------------------------------------------------------------------------- /test/GenShinGothic-Normal.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/sdl2-bindings/61df5ed6d6d870815defa5a6fda2b0d7523e6826/test/GenShinGothic-Normal.ttf -------------------------------------------------------------------------------- /test/Globe.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaiorabbit/sdl2-bindings/61df5ed6d6d870815defa5a6fda2b0d7523e6826/test/Globe.bmp -------------------------------------------------------------------------------- /test/README_GenShin.txt: -------------------------------------------------------------------------------- 1 | 源真ゴシック (げんしんゴシック) 2 | Version 1.002.20150607 3 | 4 | 5 | ■ このフォントについて 6 | 7 | 源真ゴシック (げんしんゴシック) は、フリーの OpenType フォントである 8 | 「源ノ角ゴシック (Noto Sans CJK / Source Han Sans の日本語部分)」を 9 | TrueType 形式に変換し、使い勝手を向上するカスタマイズを施したフォントです。 10 | 11 | 詳細は、以下のサイトをごらんください。 12 | http://jikasei.me/font/genshin/ 13 | 14 | 15 | ■ ライセンスと著作権について 16 | 17 | ・源真ゴシックは源ノ角ゴシックを改変して制作したもので、M+ OUTLINE FONTS 由来の文字グリフも一部含みます。 18 | ・フォントデータに含まれる、源ノ角ゴシック由来の文字グリフの著作権は Adobe が所有しています。 19 | ・フォントデータに含まれる、M+ OUTLINE FONTS 由来の文字グリフの著作権は M+ FONTS PROJECT が所有しています。 20 | ・源真ゴシックのフォントファイルは、源ノ角ゴシックと同じ SIL Open Font License 1.1 のもとで使用することができます。 21 | 22 | SIL Open Font License 1.1 の内容は、アーカイブに同梱の LICENSE.txt に記載されています。 23 | この日本語訳は、以下から参照することができます。 24 | http://osdn.jp/projects/opensource/wiki/SIL_Open_Font_License_1.1 25 | 26 | M+ OUTLINE FONTS のグリフは、同梱のファイル LICENSE_J に記載された自由な 27 | M+ FONTS LICENSE に基づき使用しています。 28 | 29 | 30 | ■ 頒布元 31 | 32 | 源真ゴシックの最新版は、以下のサイトで頒布しています。 33 | 不具合などが修正された場合、新しいバージョンとして公開されますので、 34 | 定期的にサイトをご確認いただければ幸いです。 35 | 36 | 自家製フォント工房 37 | http://jikasei.me/ 38 | 39 | 40 | ■ 改変元 41 | 42 | Mgen+ は、以下のフォントを改変して制作しました。 43 | 素晴らしいフリーフォントの制作に関わる全ての方に深くお礼申し上げます。 44 | 45 | 源ノ角ゴシック (Source Hans Sans) 46 | http://store1.adobe.com/cfusion/store/html/index.cfm?store=OLS-JP&event=displayFontPackage&code=1967 47 | 48 | M+ OUTLINE FONTS 49 | http://mplus-fonts.sourceforge.jp/ 50 | 51 | 52 | ■ 改版履歴 53 | 54 | 55 | ●Version 1.002.20150607 56 | 57 | ・縦書きが機能しなくなっていたのを修正しました。 58 | 59 | 60 | ●Version 1.002.20150531 61 | 62 | ・源ノ角ゴシック Ver.1.002 ベースになりました。 63 | Ver.1.002 でサポートされた、「あ行+濁点」などの合字に対応しました。 64 | 65 | ・源ノ角ゴシックのライセンス変更に伴い、フォントファイルのライセンスが 66 | Apache License 2.0 から SIL Open Font License 1.1 に変更になりました。 67 | 68 | ・「ff」「fi」「fl」「ffi」「ffl」のリガチャ (合字) に対応しました。 69 | 70 | ・「か+半濁点」など、源ノ角ゴシックではサポートされていたものの未対応だった 71 | ひらがな・カタカナの合字に対応しました。 72 | 73 | ・JIS78, JIS83, JIS90 の正確な文字リストを保持するようになりました。 74 | Illustrator、InDesign の字形パネルで、異字体を源ノ角ゴシックと同様に扱えるようになりました。 75 | 76 | ・小文字のクシスト (U+31F0 ~ U+31F3) が欠落していたのを修正しました。 77 | 78 | 79 | ●Version 1.001.20150116 80 | 81 | ・1.001.20150110 より、一部括弧の文字で縦書きが機能しなくなっていたのを修正しました。 82 | 83 | ・縦書きに対応した記号を追加しました。 84 | 85 | 86 | ●Version 1.001.20150110 87 | 88 | ・源ノ角ゴシック Ver.1.001 ベースになり、いくつかの字形が修正されました。 89 | 90 | ・FullFontName が "Gen Shin Gothic" (「源真ゴシック」のもの) になっていたのを修正しました。 91 | 92 | ・ウェイトクラス (数字による太さ表記) を、源ノ角ゴシックと同じ値に変更しました。 93 | ・ExtraLight : 200 → 100 94 | ・Light : 300 → 200 95 | ・Normal : 350 → 300 96 | ・Heavy : 800 → 900 97 | 98 | ・小文字のクシスト (U+31F0 ~ U+31F3) が欠けていたのを修正しました。 99 | 100 | 101 | ●Version 1.000.20140828 102 | 103 | ・プロポーショナルフォント (源真ゴシックP) が縦書きに対応しました。 104 | 105 | ・源柔ゴシック (P や等幅を除く) のフォント名設定が不適切だったのを修正しました。 106 | 107 | 108 | ●Version 1.000.20140824 109 | 110 | ・縦書き時、全角スペースの高さが 0 になっていたのを修正しました。 111 | 112 | ・Normal ウエイトの M+ 由来のグリフが太かったのを修正しました。 113 | 114 | ・縦書き専用のグリフに M+ OUTLINE FONTS のものが混在していたのを修正しました。 115 | 116 | ・全角数字、全角のセミコロン、「i」「l」がプロポーショナル幅で不自然にならないように 117 | 調整しました。 118 | 119 | ・一部の矢印グリフ (U+21D0~U+21D9) が、矢印の方向によって源ノ角ゴシック由来と 120 | M+ 由来のものが混在していましたが、これを源ノ角ゴシック由来のものに統一しました。 121 | (源ノ角ゴシックにない方向の矢印は、回転して作成しています) 122 | 123 | ・一部の点線罫線のグリフ (U+2504~U+250B) で、本来横線なのが縦線になっていたのを修正しました。 124 | 125 | ・ほとんどのハイフン、ダッシュ、罫線、矢印関連のグリフが、縦書きの時に回転するようになりました。 126 | 127 | ・フォントの中に含まれていた、日本語フォントとして不要なグリフ (未使用の特殊文字、 128 | ハングルの半角文字や記号、中国語の注音記号) を削除しました。 129 | 130 | ・源柔ゴシックP において、縦書き時にひらがな・カタカナが左に寄らないようにしました。 131 | 132 | 133 | ●Version 1.000.20140812 134 | 135 | ・M+ 由来の一部文字において、文字のアウトラインが不正 (交差して内側に入り込んでいる) なのを 136 | 修正しました。 137 | 138 | ・等幅フォントにおいて、OS/2 のウエイト情報の設定が正しくないのを修正しました。 139 | たとえば、Ubuntu Linux において、すべてのウエイトが thin と表示されていました。 140 | 141 | 142 | ●Version 1.000.20140807 143 | 144 | ・源真ゴシックP (かなもプロポーショナル幅のファミリー) において、 145 |  全角約物 (全角スペース、句読点、括弧など) の幅を再調整しました。 146 | 147 | ・幅が全角1文字分を越えるグリフの幅が、全角1文字に切り詰められていたのを修正しました。 148 | 149 | 150 | ●Version.1.000.20140806 151 | 152 | ・初回リリース 153 | ・源ノ角ゴシック Ver.1.000 ベース 154 | -------------------------------------------------------------------------------- /test/SIL_Open_Font_License_1.1.txt: -------------------------------------------------------------------------------- 1 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 2 | This license is copied below, and is also available with a FAQ at: 3 | http://scripts.sil.org/OFL 4 | 5 | 6 | ----------------------------------------------------------- 7 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 8 | ----------------------------------------------------------- 9 | 10 | PREAMBLE 11 | The goals of the Open Font License (OFL) are to stimulate worldwide 12 | development of collaborative font projects, to support the font creation 13 | efforts of academic and linguistic communities, and to provide a free and 14 | open framework in which fonts may be shared and improved in partnership 15 | with others. 16 | 17 | The OFL allows the licensed fonts to be used, studied, modified and 18 | redistributed freely as long as they are not sold by themselves. The 19 | fonts, including any derivative works, can be bundled, embedded, 20 | redistributed and/or sold with any software provided that any reserved 21 | names are not used by derivative works. The fonts and derivatives, 22 | however, cannot be released under any other type of license. The 23 | requirement for fonts to remain under this license does not apply 24 | to any document created using the fonts or their derivatives. 25 | 26 | DEFINITIONS 27 | "Font Software" refers to the set of files released by the Copyright 28 | Holder(s) under this license and clearly marked as such. This may 29 | include source files, build scripts and documentation. 30 | 31 | "Reserved Font Name" refers to any names specified as such after the 32 | copyright statement(s). 33 | 34 | "Original Version" refers to the collection of Font Software components as 35 | distributed by the Copyright Holder(s). 36 | 37 | "Modified Version" refers to any derivative made by adding to, deleting, 38 | or substituting -- in part or in whole -- any of the components of the 39 | Original Version, by changing formats or by porting the Font Software to a 40 | new environment. 41 | 42 | "Author" refers to any designer, engineer, programmer, technical 43 | writer or other person who contributed to the Font Software. 44 | 45 | PERMISSION & CONDITIONS 46 | Permission is hereby granted, free of charge, to any person obtaining 47 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 48 | redistribute, and sell modified and unmodified copies of the Font 49 | Software, subject to the following conditions: 50 | 51 | 1) Neither the Font Software nor any of its individual components, 52 | in Original or Modified Versions, may be sold by itself. 53 | 54 | 2) Original or Modified Versions of the Font Software may be bundled, 55 | redistributed and/or sold with any software, provided that each copy 56 | contains the above copyright notice and this license. These can be 57 | included either as stand-alone text files, human-readable headers or 58 | in the appropriate machine-readable metadata fields within text or 59 | binary files as long as those fields can be easily viewed by the user. 60 | 61 | 3) No Modified Version of the Font Software may use the Reserved Font 62 | Name(s) unless explicit written permission is granted by the corresponding 63 | Copyright Holder. This restriction only applies to the primary font name as 64 | presented to the users. 65 | 66 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 67 | Software shall not be used to promote, endorse or advertise any 68 | Modified Version, except to acknowledge the contribution(s) of the 69 | Copyright Holder(s) and the Author(s) or with their explicit written 70 | permission. 71 | 72 | 5) The Font Software, modified or unmodified, in part or in whole, 73 | must be distributed entirely under this license, and must not be 74 | distributed under any other license. The requirement for fonts to 75 | remain under this license does not apply to any document created 76 | using the Font Software. 77 | 78 | TERMINATION 79 | This license becomes null and void if any of the above conditions are 80 | not met. 81 | 82 | DISCLAIMER 83 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 84 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 85 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 86 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 87 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 88 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 89 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 90 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 91 | OTHER DEALINGS IN THE FONT SOFTWARE. -------------------------------------------------------------------------------- /test/test_audioinfo.rb: -------------------------------------------------------------------------------- 1 | # sdl2-bindings port of testaudioinfo.c 2 | require 'sdl2' 3 | # require_relative '../lib/sdl2' 4 | require_relative 'util' 5 | 6 | def print_devices(iscapture) 7 | typestr = iscapture ? "capture" : "output" 8 | n = SDL.GetNumAudioDevices(iscapture) 9 | 10 | puts("#{typestr} devices:") 11 | 12 | if n == -1 13 | printf(" Driver can't detect specific %s devices.\n\n", typestr) 14 | elsif n == 0 15 | printf(" No %s devices found.\n\n", typestr) 16 | else 17 | n.times do |i| 18 | printf(" %s\n", SDL.GetAudioDeviceName(i, iscapture).read_string) 19 | end 20 | printf("\n") 21 | end 22 | end 23 | 24 | if __FILE__ == $PROGRAM_NAME 25 | load_sdl2_lib() 26 | success = SDL.Init(SDL::INIT_AUDIO) 27 | exit if success < 0 28 | n = SDL.GetNumAudioDrivers() 29 | if n == 0 30 | printf("No built-in audio drivers\n\n") 31 | else 32 | print("Built-in audio drivers:\n") 33 | n.times do |i| 34 | printf(" %s\n", SDL.GetAudioDriver(i).read_string) 35 | end 36 | end 37 | 38 | printf("Using audio driver: %s\n\n", SDL.GetCurrentAudioDriver().read_string) 39 | 40 | print_devices(0) 41 | print_devices(1) 42 | 43 | SDL.Quit() 44 | end 45 | 46 | =begin 47 | 48 | # Original Copyright Notice: 49 | 50 | Copyright (C) 1997-2014 Sam Lantinga 51 | 52 | This software is provided 'as-is', without any express or implied 53 | warranty. In no event will the authors be held liable for any damages 54 | arising from the use of this software. 55 | 56 | Permission is granted to anyone to use this software for any purpose, 57 | including commercial applications, and to alter it and redistribute it 58 | freely. 59 | =end 60 | -------------------------------------------------------------------------------- /test/test_draw.rb: -------------------------------------------------------------------------------- 1 | require 'sdl2' 2 | # require_relative '../lib/sdl2' 3 | require_relative 'util' 4 | 5 | NUM_OBJECTS = 100 6 | 7 | $current_alpha = 255 8 | $current_color = 255 9 | $cycle_direction = 1 10 | 11 | def draw_points(renderer) 12 | 13 | viewport = SDL::Rect.new 14 | 15 | SDL.RenderGetViewport(renderer, viewport) 16 | 17 | (4 * NUM_OBJECTS).times do |i| 18 | $current_color += $cycle_direction 19 | if $current_color < 0 20 | $current_color = 0 21 | $cycle_direction = -$cycle_direction 22 | end 23 | if $current_color > 255 24 | $current_color = 255 25 | $cycle_direction = -$cycle_direction 26 | end 27 | 28 | SDL.SetRenderDrawColor(renderer, 255, $current_color, $current_color, $current_alpha) 29 | x = rand(65535) % viewport[:w] 30 | y = rand(65535) % viewport[:h] 31 | SDL.RenderDrawPoint(renderer, x, y) 32 | end 33 | end 34 | 35 | def draw_lines(renderer) 36 | rect = SDL::Rect.new 37 | viewport = SDL::Rect.new 38 | 39 | SDL.RenderGetViewport(renderer, viewport) 40 | 41 | NUM_OBJECTS.times do |i| 42 | $current_color += $cycle_direction 43 | if $current_color < 0 44 | $current_color = 0 45 | $cycle_direction = -$cycle_direction 46 | end 47 | if $current_color > 255 48 | $current_color = 255 49 | $cycle_direction = -$cycle_direction 50 | end 51 | SDL.SetRenderDrawColor(renderer, 255, $current_color, $current_color, $current_alpha) 52 | if i == 0 53 | SDL.RenderDrawLine(renderer, 0, 0, viewport[:w] - 1, viewport[:h] - 1) 54 | SDL.RenderDrawLine(renderer, 0, viewport[:h] - 1, viewport[:w] - 1, 0) 55 | SDL.RenderDrawLine(renderer, 0, viewport[:h] / 2, viewport[:w] - 1, viewport[:h] / 2) 56 | SDL.RenderDrawLine(renderer, viewport[:w] / 2, 0, viewport[:w] / 2, viewport[:h] - 1) 57 | else 58 | x1 = (rand(65535) % (viewport[:w] * 2)) - viewport[:w] 59 | x2 = (rand(65535) % (viewport[:w] * 2)) - viewport[:w] 60 | y1 = (rand(65535) % (viewport[:h] * 2)) - viewport[:h] 61 | y2 = (rand(65535) % (viewport[:h] * 2)) - viewport[:h] 62 | SDL.RenderDrawLine(renderer, x1, y1, x2, y2) 63 | end 64 | end 65 | end 66 | 67 | def draw_rects(renderer) 68 | rect = SDL::Rect.new 69 | viewport = SDL::Rect.new 70 | 71 | SDL.RenderGetViewport(renderer, viewport) 72 | 73 | NUM_OBJECTS.times do |i| 74 | $current_color += $cycle_direction 75 | if $current_color < 0 76 | $current_color = 0 77 | $cycle_direction = -$cycle_direction 78 | end 79 | if $current_color > 255 80 | $current_color = 255 81 | $cycle_direction = -$cycle_direction 82 | end 83 | SDL.SetRenderDrawColor(renderer, 255, $current_color, $current_color, $current_alpha) 84 | rect[:w] = rand(65535) % (viewport[:h] / 2) 85 | rect[:h] = rand(65535) % (viewport[:h] / 2) 86 | 87 | rect[:x] = (rand(65535) % (viewport[:w]*2) - viewport[:w]) - (rect[:w] / 2) 88 | rect[:y] = (rand(65535) % (viewport[:h]*2) - viewport[:h]) - (rect[:h] / 2) 89 | SDL.RenderFillRect(renderer, rect) 90 | end 91 | end 92 | 93 | if __FILE__ == $PROGRAM_NAME 94 | load_sdl2_lib() 95 | success = SDL.Init(SDL::INIT_VIDEO) 96 | exit if success < 0 97 | 98 | WINDOW_W = 640 99 | WINDOW_H = 360 100 | window = SDL.CreateWindow("RenderDrawPoint/RenderDrawLine/RenderFillRect", 32, 32, WINDOW_W, WINDOW_H, SDL::WINDOW_OPENGL) 101 | 102 | renderer = SDL.CreateRenderer(window, -1, 0) 103 | 104 | event = SDL::Event.new 105 | 106 | done = false 107 | while not done 108 | while SDL.PollEvent(event) != 0 109 | # 'type' and 'timestamp' are common members for all SDL Event structs. 110 | event_type = event[:common][:type] 111 | event_timestamp = event[:common][:timestamp] 112 | # puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 113 | case event_type 114 | when SDL::KEYDOWN 115 | if event[:key][:keysym][:sym] == SDL::SDLK_ESCAPE 116 | done = true 117 | end 118 | end 119 | end 120 | 121 | SDL.SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF) 122 | SDL.RenderClear(renderer) 123 | 124 | draw_rects(renderer) 125 | draw_lines(renderer) 126 | draw_points(renderer) 127 | 128 | SDL.RenderPresent(renderer) 129 | 130 | # SDL.Delay(10) 131 | end 132 | 133 | SDL.DestroyRenderer(renderer) 134 | SDL.DestroyWindow(window) 135 | SDL.Quit() 136 | end 137 | -------------------------------------------------------------------------------- /test/test_dropfile.rb: -------------------------------------------------------------------------------- 1 | # TODO : Prepare Info.plist to support D&D on Mac OS X. 2 | require 'sdl2' 3 | # require_relative '../lib/sdl2' 4 | require_relative 'util' 5 | 6 | if __FILE__ == $PROGRAM_NAME 7 | load_sdl2_lib() 8 | success = SDL.Init(SDL::INIT_VIDEO) 9 | exit if success < 0 10 | 11 | WINDOW_W = 640 12 | WINDOW_H = 360 13 | window = SDL.CreateWindow("Drop File Test (sdl2-bindings)", 0, 0, WINDOW_W, WINDOW_H, SDL::WINDOW_OPENGL) 14 | 15 | renderer = SDL.CreateRenderer(window, -1, 0) 16 | SDL.SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF) 17 | SDL.RenderClear(renderer) 18 | SDL.RenderPresent(renderer) 19 | 20 | event = SDL::Event.new 21 | 22 | p SDL.EventState(SDL::DROPFILE, SDL::QUERY) 23 | p SDL::DROPFILE.to_s(16), SDL.EventState(SDL::DROPFILE, SDL::ENABLE) 24 | p SDL.EventState(SDL::DROPFILE, SDL::QUERY) 25 | 26 | done = false 27 | while not done 28 | while SDL.PollEvent(event) != 0 29 | # 'type' and 'timestamp' are common members for all SDL Event structs. 30 | event_type = event[:common][:type] 31 | event_timestamp = event[:common][:timestamp] 32 | puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 33 | case event_type 34 | when SDL::KEYDOWN 35 | if event[:key][:keysym][:sym] == SDL::SDLK_ESCAPE 36 | done = true 37 | end 38 | when SDL::DROPFILE 39 | printf("File dropped on window: %s", event[:drop][:file]); 40 | # SDL.free(event[:drop][:file]) # TODO alternative of #define SDL_Free 41 | end 42 | end 43 | 44 | # SDL.Delay(10) 45 | end 46 | 47 | SDL.DestroyRenderer(renderer) 48 | SDL.DestroyWindow(window) 49 | SDL.Quit() 50 | end 51 | -------------------------------------------------------------------------------- /test/test_event.rb: -------------------------------------------------------------------------------- 1 | require_relative '../lib/sdl2' 2 | require_relative 'util' 3 | 4 | if __FILE__ == $PROGRAM_NAME 5 | load_sdl2_lib() 6 | success = SDL.Init(SDL::INIT_EVERYTHING) 7 | exit if success < 0 8 | 9 | fpsdelay = 100; 10 | 11 | count = 0 12 | event = SDL::Event.new 13 | done = false 14 | while not done 15 | while SDL.PollEvent(event) != 0 16 | # 'type' and 'timestamp' are common members for all SDL Event structs. 17 | event_type = event[:common][:type] 18 | event_timestamp = event[:common][:timestamp] 19 | puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 20 | end 21 | 22 | count += 1 23 | done = true if count >= 100 24 | SDL.Delay(fpsdelay) 25 | end 26 | 27 | SDL.Quit() 28 | end 29 | -------------------------------------------------------------------------------- /test/test_gfx.rb: -------------------------------------------------------------------------------- 1 | require_relative '../lib/sdl2' 2 | 3 | WINDOW_W = 640 4 | WINDOW_H = 360 5 | 6 | if __FILE__ == $PROGRAM_NAME 7 | SDL.load_lib('/opt/homebrew/lib/libSDL2.dylib', gfx_libpath: '/opt/homebrew/lib/libSDL2_gfx.dylib') # '/usr/local/lib/libSDL2.dylib' 8 | success = SDL.Init(SDL::INIT_EVERYTHING) 9 | exit if success < 0 10 | 11 | window = SDL.CreateWindow("Minimal SDL2_gfx Test via sdl2-bindings", 0, 0, WINDOW_W, WINDOW_H, 0) 12 | 13 | renderer = SDL.CreateRenderer(window, -1, 0) 14 | 15 | event = SDL::Event.new 16 | done = false 17 | while not done 18 | while SDL.PollEvent(event) != 0 19 | # 'type' and 'timestamp' are common members for all SDL Event structs. 20 | event_type = event[:common][:type] 21 | # event_timestamp = event[:common][:timestamp] 22 | # puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 23 | case event_type 24 | when SDL::KEYDOWN 25 | if event[:key][:keysym][:sym] == SDL::SDLK_ESCAPE 26 | done = true 27 | end 28 | end 29 | end 30 | 31 | SDL.SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF) 32 | SDL.RenderClear(renderer) 33 | 34 | SDL.pixelColor(renderer, 100, 100, 0xFFFFFFFF) # Uint32 color = 0x[AA][BB][GG][RR] 35 | SDL.pixelRGBA(renderer, 101, 100, 0xFF, 0x00, 0x00, 0xFF) 36 | 37 | SDL.hlineColor(renderer, 0, 100, 50, 0xFFFFFFFF) 38 | SDL.vlineColor(renderer, 50, 0, 100, 0xFFFF00FF) 39 | 40 | SDL.rectangleColor(renderer, 5, 5, 95, 95, 0xFF00FFFF) 41 | SDL.rectangleRGBA(renderer, 10, 10, 90, 90, 0, 0, 0xFF, 0xFF) 42 | 43 | SDL.circleColor(renderer, 150, 150, 50, 0xFF00FF00) 44 | SDL.filledCircleRGBA(renderer, 150, 150, 45, 0x00, 0xFF, 0x00, 0xFF) 45 | 46 | SDL.RenderPresent(renderer) 47 | 48 | SDL.Delay(10) 49 | end 50 | 51 | p SDL.imageFilterMMXdetect() 52 | SDL.imageFilterMMXoff() 53 | SDL.imageFilterMMXon() 54 | 55 | 56 | SDL.DestroyRenderer(renderer) 57 | SDL.DestroyWindow(window) 58 | SDL.Quit() 59 | end 60 | -------------------------------------------------------------------------------- /test/test_image.rb: -------------------------------------------------------------------------------- 1 | require_relative '../lib/sdl2' 2 | require_relative '../lib/sdl2_image' 3 | 4 | WINDOW_W = 640 5 | WINDOW_H = 360 6 | 7 | if __FILE__ == $PROGRAM_NAME 8 | SDL.load_lib('/opt/homebrew/lib/libSDL2.dylib', image_libpath: '/opt/homebrew/lib/libSDL2_image.dylib' ) # '/usr/local/lib/libSDL2.dylib' 9 | success = SDL.Init(SDL::INIT_EVERYTHING) 10 | exit if success < 0 11 | 12 | window = SDL.CreateWindow("Minimal SDL_Image Test via sdl2-bindings", 0, 0, WINDOW_W, WINDOW_H, 0) 13 | 14 | renderer = SDL.CreateRenderer(window, -1, 0) 15 | 16 | SDL.IMG_Init(SDL::IMG_INIT_JPG|SDL::IMG_INIT_PNG|SDL::IMG_INIT_TIF|SDL::IMG_INIT_WEBP) 17 | 18 | rwops = SDL.RWFromFile(ARGV[0], "rb") 19 | 20 | puts "PNG?: #{SDL.IMG_isPNG(rwops) == 1 ? 'true' : 'false'}" 21 | 22 | texture = SDL.IMG_LoadTexture_RW(renderer, rwops, 1) # 1 == freesrc : close src automatically 23 | wh = 300 24 | pos = SDL::Rect.new 25 | pos[:x] = (WINDOW_W - wh) / 2 26 | pos[:y] = (WINDOW_H - wh) / 2 27 | pos[:w] = wh 28 | pos[:h] = wh 29 | pp pos[:x], pos[:y], pos[:w], pos[:h] 30 | 31 | SDL.RenderCopy(renderer, texture, nil, pos) 32 | 33 | event = SDL::Event.new 34 | done = false 35 | while not done 36 | while SDL.PollEvent(event) != 0 37 | # 'type' and 'timestamp' are common members for all SDL Event structs. 38 | event_type = event[:common][:type] 39 | # event_timestamp = event.common.timestamp 40 | # puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 41 | case event_type 42 | when SDL::KEYDOWN 43 | if event[:key][:keysym][:sym] == SDL::SDLK_ESCAPE 44 | done = true 45 | end 46 | end 47 | end 48 | 49 | SDL.SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF) 50 | SDL.RenderClear(renderer) 51 | SDL.RenderCopy(renderer, texture, nil, pos) 52 | SDL.RenderPresent(renderer) 53 | 54 | SDL.Delay(10) 55 | end 56 | 57 | SDL.IMG_Quit() 58 | SDL.DestroyRenderer(renderer) 59 | SDL.DestroyWindow(window) 60 | SDL.Quit() 61 | end 62 | -------------------------------------------------------------------------------- /test/test_ime.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | # Ref.: /SDL2-2.0.3/test/testime.c 3 | require_relative '../lib/sdl2' 4 | require_relative '../lib/sdl2_ttf' 5 | 6 | WINDOW_W = 640 7 | WINDOW_H = 360 8 | 9 | $font_path = '' 10 | $textRect = nil 11 | $markedRect = nil 12 | $lineColor = nil 13 | $backColor = nil 14 | $textColor = nil 15 | $text = "" 16 | $markedText = "" 17 | $cursor = 0 18 | $font = nil 19 | 20 | def init_app 21 | $lineColor = SDL::Color.new 22 | $lineColor[:r] = 0 23 | $lineColor[:g] = 0 24 | $lineColor[:b] = 0 25 | $lineColor[:a] = 255 26 | 27 | $backColor = SDL::Color.new 28 | $backColor[:r] = 255 29 | $backColor[:g] = 255 30 | $backColor[:b] = 255 31 | $backColor[:a] = 255 32 | 33 | $textColor = SDL::Color.new 34 | $textColor[:r] = 0 35 | $textColor[:g] = 0 36 | $textColor[:b] = 0 37 | $textColor[:a] = 255 38 | 39 | box_height = 50 40 | $textRect = SDL::Rect.new 41 | $textRect[:x] = 100 42 | $textRect[:y] = WINDOW_H / 2 - box_height / 2 43 | $textRect[:w] = WINDOW_W - 2 * $textRect[:x] 44 | $textRect[:h] = box_height 45 | 46 | $markedRect = SDL::Rect.new 47 | $markedRect[:x] = $textRect[:x] 48 | $markedRect[:y] = $textRect[:y] 49 | $markedRect[:w] = $textRect[:w] 50 | $markedRect[:h] = $textRect[:h] 51 | 52 | $text = "" 53 | $markedText = "" 54 | $cursor = 0 # FIX : TEST 55 | 56 | SDL.TTF_Init() 57 | rwops = SDL.RWFromFile($font_path, "rb") 58 | $font = SDL.TTF_OpenFontRW(rwops, 0, 30) 59 | 60 | SDL.StartTextInput() 61 | end 62 | 63 | def term_app 64 | SDL.StopTextInput() 65 | SDL.TTF_CloseFont($font) 66 | SDL.TTF_Quit() 67 | end 68 | 69 | def redraw_internal(renderer) 70 | SDL.SetRenderDrawColor(renderer, 255,255,255,255) 71 | SDL.RenderFillRect(renderer, $textRect) 72 | 73 | w = 0 74 | h = 0 75 | w_buf = FFI::MemoryPointer.new :int 76 | h_buf = FFI::MemoryPointer.new :int 77 | 78 | unless $text.empty? 79 | textSur = SDL::Surface.new(SDL.TTF_RenderUTF8_Blended($font, $text, $textColor)) 80 | dest = SDL::Rect.new 81 | dest[:x] = $textRect[:x] 82 | dest[:y] = $textRect[:y] 83 | dest[:w] = textSur[:w] 84 | dest[:h] = textSur[:h] 85 | 86 | texture = SDL.CreateTextureFromSurface(renderer, textSur) 87 | SDL.FreeSurface(textSur) 88 | 89 | SDL.RenderCopy(renderer, texture, nil, dest) 90 | SDL.DestroyTexture(texture) 91 | SDL.TTF_SizeUTF8($font, $text, w_buf, h_buf) 92 | w = w_buf.read_int 93 | h = h_buf.read_int 94 | end 95 | 96 | $markedRect[:x] = $textRect[:x] + w 97 | $markedRect[:w] = $textRect[:w] - w 98 | if $markedRect[:w] < 0 99 | # Stop text input because we cannot hold any more characters 100 | SDL.StopTextInput() 101 | return 102 | else 103 | SDL.StartTextInput() 104 | end 105 | 106 | cursorRect = SDL::Rect.new 107 | cursorRect[:x] = $markedRect[:x] 108 | cursorRect[:y] = $markedRect[:y] 109 | cursorRect[:w] = 2 110 | cursorRect[:h] = h 111 | 112 | SDL.SetRenderDrawColor(renderer, 255,255,255,255) 113 | SDL.RenderFillRect(renderer, $markedRect) 114 | 115 | unless $markedText.empty? 116 | if $cursor != 0 117 | SDL.TTF_SizeUTF8($font, $markedText, w_buf, nil) 118 | w = w_buf.read_int 119 | cursorRect[:x] += w 120 | end 121 | textSur = SDL::Surface.new(SDL.TTF_RenderUTF8_Blended($font, $markedText, $textColor)) 122 | dest = SDL::Rect.new 123 | dest[:x] = $markedRect[:x] 124 | dest[:y] = $markedRect[:y] 125 | dest[:w] = textSur[:w] 126 | dest[:h] = textSur[:h] 127 | SDL.TTF_SizeUTF8($font, $markedText, w_buf, h_buf) 128 | w = w_buf.read_int 129 | h = h_buf.read_int 130 | texture = SDL.CreateTextureFromSurface(renderer, textSur) 131 | SDL.FreeSurface(textSur) 132 | 133 | SDL.RenderCopy(renderer, texture, nil, dest) 134 | SDL.DestroyTexture(texture) 135 | 136 | underlineRect = SDL::Rect.new 137 | underlineRect[:x] = $markedRect[:x] 138 | underlineRect[:y] = $markedRect[:y] 139 | underlineRect[:y] += (h - 2) 140 | underlineRect[:h] = 2 141 | underlineRect[:w] = w 142 | 143 | SDL.SetRenderDrawColor(renderer, 0,0,0,0) 144 | SDL.RenderFillRect(renderer, underlineRect) 145 | end 146 | 147 | SDL.SetRenderDrawColor(renderer, 0,0,0,0) 148 | SDL.RenderFillRect(renderer, cursorRect) 149 | 150 | SDL.SetTextInputRect($markedRect) 151 | 152 | end 153 | 154 | def redraw(renderer) 155 | SDL.SetRenderDrawColor(renderer, 0, 0, 0, 0) 156 | SDL.RenderClear(renderer) 157 | 158 | redraw_internal(renderer) 159 | 160 | SDL.RenderPresent(renderer) 161 | end 162 | 163 | if __FILE__ == $PROGRAM_NAME 164 | $font_path = ARGV[0] != nil ? ARGV[0] : 'GenShinGothic-Normal.ttf' 165 | 166 | SDL.load_lib('/opt/homebrew/lib/libSDL2.dylib', ttf_libpath: '/opt/homebrew/lib/libSDL2_ttf.dylib') # '/usr/local/lib/libSDL2.dylib' 167 | success = SDL.Init(SDL::INIT_EVERYTHING) 168 | exit if success < 0 169 | 170 | window = SDL.CreateWindow("Minimal SDL_TTF Test via sdl2-bindings", 32, 32, WINDOW_W, WINDOW_H, 0) 171 | 172 | renderer = SDL.CreateRenderer(window, -1, 0) 173 | 174 | init_app() 175 | 176 | SDL.SetRenderDrawBlendMode(renderer, SDL::BLENDMODE_NONE) 177 | SDL.SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF) 178 | SDL.RenderClear(renderer); 179 | redraw(renderer) 180 | 181 | event = SDL::Event.new 182 | done = false 183 | while not done 184 | while SDL.PollEvent(event) != 0 185 | # 'type' and 'timestamp' are common members for all SDL Event structs. 186 | event_type = event[:common][:type] 187 | # event_timestamp = event.common.timestamp 188 | # puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 189 | case event_type 190 | when SDL::KEYDOWN 191 | # p "\r".to_s, event[:key][:keysym][:sym], event[:key][:keysym][:scancode].to_s(2) #, '\t'.ord.to_s(16) 192 | case event[:key][:keysym][:sym] 193 | when SDL::SDLK_ESCAPE 194 | done = true 195 | when SDL::SDLK_RETURN 196 | # $text = "" 197 | #redraw(renderer) 198 | when SDL::SDLK_BACKSPACE 199 | $text.chop! 200 | redraw(renderer) 201 | end 202 | 203 | when SDL::TEXTINPUT 204 | if event[:text][:text][0] == "\0".ord || event[:text][:text][0] == "\n".ord || $markedRect[:w] < 0 205 | next 206 | end 207 | term = event[:text][:text].find_index(0) 208 | # appended = event[:text][:text][0...term].pack("c*").force_encoding("UTF-8") 209 | appended = event[:text][:text].to_s.force_encoding(Encoding::UTF_8) 210 | # printf("Keyboard: text input \"%s\"\n", appended) 211 | $text.concat(appended) 212 | $markedText = "" 213 | redraw(renderer) 214 | when SDL::TEXTEDITING 215 | term = event[:edit][:text].find_index(0) 216 | editing = event[:edit][:text] # event[:edit][:text][0...term].pack("c*").force_encoding("UTF-8") 217 | printf("text editing \"%s\", selected range (%d, %d)\n", editing, event[:edit][:start], term) 218 | $markedText = editing.to_s 219 | $cursor = event[:edit][:start] 220 | redraw(renderer) 221 | end 222 | end 223 | 224 | SDL.Delay(10) 225 | end 226 | 227 | term_app() 228 | SDL.DestroyRenderer(renderer) 229 | SDL.DestroyWindow(window) 230 | SDL.Quit() 231 | end 232 | -------------------------------------------------------------------------------- /test/test_import.rb: -------------------------------------------------------------------------------- 1 | require 'sdl2' 2 | # require_relative '../lib/sdl2' 3 | require_relative 'util' 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | load_sdl2_lib() 7 | success = SDL.Init(SDL::INIT_EVERYTHING) 8 | puts "SDL_Init : #{success == 0 ? 'Success' : 'Failed'}" 9 | exit if success != 0 10 | # p SDL_INIT_EVERYTHING.to_s(16) 11 | puts "Platform: #{SDL.GetPlatform().read_string}" 12 | version = SDL::Version.new 13 | SDL.GetVersion(version) 14 | puts("Major, Minor and Patch: #{version[:major]} #{version[:minor]} #{version[:patch]}") 15 | SDL.ClearHints() 16 | SDL.Quit() 17 | end 18 | -------------------------------------------------------------------------------- /test/test_joystick.rb: -------------------------------------------------------------------------------- 1 | # Tested with: 2 | # - Xbox One S Controller on macOS 12.1 [2022-01-26] 3 | require_relative '../lib/sdl2' 4 | require_relative 'util' 5 | 6 | if __FILE__ == $PROGRAM_NAME 7 | load_sdl2_lib() 8 | success = SDL.Init(SDL::INIT_VIDEO | SDL::INIT_GAMECONTROLLER) 9 | exit if success < 0 10 | 11 | if File.exists?('gamecontrollerdb.txt') 12 | # curl -O https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt 13 | SDL.GameControllerAddMapping(IO.read('gamecontrollerdb.txt')) 14 | end 15 | 16 | n_joysticks = SDL.NumJoysticks() 17 | if n_joysticks <= 0 18 | $stderr.puts 'ERROR: No joysticks found' 19 | exit 20 | end 21 | for i in 0...n_joysticks 22 | name = SDL.JoystickNameForIndex(i) 23 | printf("Joystick %d: %s\n", i, name ? name.read_string : "Unknown Joystick") 24 | end 25 | 26 | gamepad = SDL.GameControllerOpen(0) 27 | joystick = SDL.GameControllerGetJoystick(gamepad) 28 | puts("#{SDL.GameControllerGetType(gamepad)}") # CONTROLLER_TYPE_XBOXONE = 2 29 | printf(" axes: %d\n", SDL.JoystickNumAxes(joystick)) 30 | printf(" balls: %d\n", SDL.JoystickNumBalls(joystick)) 31 | printf(" hats: %d\n", SDL.JoystickNumHats(joystick)) 32 | printf(" buttons: %d\n", SDL.JoystickNumButtons(joystick)) 33 | printf("instance id: %d\n", SDL.JoystickInstanceID(joystick)) 34 | 35 | WINDOW_W = 320 36 | WINDOW_H = 240 37 | window = SDL.CreateWindow("1st SDL Window via sdl2-bindings", 0, 0, WINDOW_W, WINDOW_H, 0) 38 | 39 | event = SDL::Event.new 40 | done = false 41 | while not done 42 | while SDL.PollEvent(event) != 0 43 | # 'type' and 'timestamp' are common members for all SDL Event structs. 44 | event_type = event[:common][:type] 45 | event_timestamp = event[:common][:timestamp] 46 | puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 47 | 48 | case event_type 49 | when SDL::JOYAXISMOTION || SDL::CONTROLLERAXISMOTION 50 | puts "axis=#{event[:jaxis][:axis]}, value=#{event[:jaxis][:value]}" 51 | 52 | when SDL::KEYDOWN 53 | if event[:key][:keysym][:sym] == SDL::SDLK_ESCAPE 54 | done = true 55 | end 56 | when SDL::JOYBUTTONUP || SDL::JOYBUTTONUP 57 | puts "sym=#{event[:key][:keysym][:sym]}" 58 | end 59 | end 60 | 61 | end 62 | 63 | SDL.GameControllerClose(gamepad) 64 | SDL.DestroyWindow(window) 65 | SDL.Quit() 66 | end 67 | -------------------------------------------------------------------------------- /test/test_messagebox.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | require_relative '../lib/sdl2' 3 | require_relative 'util' 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | load_sdl2_lib() 7 | success = SDL.Init(SDL::INIT_EVERYTHING) 8 | exit if success != 0 9 | 10 | # SDL_ShowSimpleMessageBox 11 | success = SDL.ShowSimpleMessageBox(SDL::MESSAGEBOX_ERROR, 12 | "Simple MessageBox", 13 | "これが SDL_ShowSimpleMessageBox です。", 14 | nil) 15 | 16 | # SDL_ShowMessageBox 17 | buttons = FFI::MemoryPointer.new(SDL::MessageBoxButtonData, 2) 18 | button = [SDL::MessageBoxButtonData.new(buttons[0]), SDL::MessageBoxButtonData.new(buttons[1])] 19 | 20 | button[0][:flags] = SDL::MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT 21 | button[0][:buttonid] = 0 22 | button[0][:text] = FFI::MemoryPointer.from_string("OK") 23 | 24 | button[1][:flags] = SDL::MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT 25 | button[1][:buttonid] = 1 26 | button[1][:text] = FFI::MemoryPointer.from_string("Cancel") 27 | 28 | data = SDL::MessageBoxData.new 29 | data[:flags] = SDL::MESSAGEBOX_INFORMATION 30 | data[:window] = nil 31 | data[:title] = FFI::MemoryPointer.from_string("Custom MessageBox") 32 | data[:message] = FFI::MemoryPointer.from_string("カスタマイズされたメッセージボックスの利用例です。") 33 | data[:numbuttons] = 2 34 | data[:buttons] = buttons 35 | data[:colorScheme] = nil 36 | 37 | success = SDL.ShowMessageBox(data, buttons) 38 | 39 | SDL.Quit() 40 | end 41 | -------------------------------------------------------------------------------- /test/test_mixer.rb: -------------------------------------------------------------------------------- 1 | require_relative '../lib/sdl2' 2 | 3 | if __FILE__ == $0 4 | if ARGV[0] == nil 5 | $stderr.puts 'Usage: ruby test_mixer.rb [path to .wav]' 6 | exit 7 | end 8 | 9 | SDL.load_lib('/opt/homebrew/lib/libSDL2.dylib', mixer_libpath: '/opt/homebrew/lib/libSDL2_mixer.dylib' ) 10 | success = SDL.Init(SDL::INIT_AUDIO) 11 | exit if success < 0 12 | 13 | SDL.Mix_Init(SDL::MIX_INIT_FLAC|SDL::MIX_INIT_MOD|SDL::MIX_INIT_MP3|SDL::MIX_INIT_OGG) 14 | SDL.Mix_OpenAudio(22050, SDL::MIX_DEFAULT_FORMAT, 2, 512) 15 | 16 | rwops = SDL.RWFromFile(ARGV[0], "rb") 17 | wave = SDL.Mix_LoadWAV_RW(rwops, 1) 18 | SDL.Mix_FadeInChannelTimed(0, wave, 0, 600, -1) 19 | while SDL.Mix_Playing(0) != 0 20 | sleep 1 21 | end 22 | SDL.Mix_Quit() 23 | SDL.Quit() 24 | end 25 | -------------------------------------------------------------------------------- /test/test_opengl.rb: -------------------------------------------------------------------------------- 1 | # [NOTE] Install opengl-bindings2 ( https://rubygems.org/gems/opengl-bindings2 ) before running this sample. 2 | # $ gem install opengl-bindings2 3 | 4 | require 'opengl' 5 | require_relative '../lib/sdl2' 6 | require_relative 'util' 7 | 8 | $color = 9 | [[ 1.0, 1.0, 0.0].pack("D3"), 10 | [ 1.0, 0.0, 0.0].pack("D3"), 11 | [ 0.0, 0.0, 0.0].pack("D3"), 12 | [ 0.0, 1.0, 0.0].pack("D3"), 13 | [ 0.0, 1.0, 1.0].pack("D3"), 14 | [ 1.0, 1.0, 1.0].pack("D3"), 15 | [ 1.0, 0.0, 1.0].pack("D3"), 16 | [ 0.0, 0.0, 1.0].pack("D3")] 17 | 18 | $cube = 19 | [[ 0.5, 0.5, -0.5].pack("D3"), 20 | [ 0.5, -0.5, -0.5].pack("D3"), 21 | [-0.5, -0.5, -0.5].pack("D3"), 22 | [-0.5, 0.5, -0.5].pack("D3"), 23 | [-0.5, 0.5, 0.5].pack("D3"), 24 | [ 0.5, 0.5, 0.5].pack("D3"), 25 | [ 0.5, -0.5, 0.5].pack("D3"), 26 | [-0.5, -0.5, 0.5].pack("D3")] 27 | 28 | def render() 29 | GL.ClearColor(0.0, 0.0, 0.0, 1.0) 30 | GL.Clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT) 31 | 32 | GL.Begin(GL::QUADS) 33 | 34 | GL.Color3dv($color[0]) 35 | GL.Vertex3dv($cube[0]) 36 | GL.Color3dv($color[1]) 37 | GL.Vertex3dv($cube[1]) 38 | GL.Color3dv($color[2]) 39 | GL.Vertex3dv($cube[2]) 40 | GL.Color3dv($color[3]) 41 | GL.Vertex3dv($cube[3]) 42 | 43 | GL.Color3dv($color[3]) 44 | GL.Vertex3dv($cube[3]) 45 | GL.Color3dv($color[4]) 46 | GL.Vertex3dv($cube[4]) 47 | GL.Color3dv($color[7]) 48 | GL.Vertex3dv($cube[7]) 49 | GL.Color3dv($color[2]) 50 | GL.Vertex3dv($cube[2]) 51 | 52 | GL.Color3dv($color[0]) 53 | GL.Vertex3dv($cube[0]) 54 | GL.Color3dv($color[5]) 55 | GL.Vertex3dv($cube[5]) 56 | GL.Color3dv($color[6]) 57 | GL.Vertex3dv($cube[6]) 58 | GL.Color3dv($color[1]) 59 | GL.Vertex3dv($cube[1]) 60 | 61 | GL.Color3dv($color[5]) 62 | GL.Vertex3dv($cube[5]) 63 | GL.Color3dv($color[4]) 64 | GL.Vertex3dv($cube[4]) 65 | GL.Color3dv($color[7]) 66 | GL.Vertex3dv($cube[7]) 67 | GL.Color3dv($color[6]) 68 | GL.Vertex3dv($cube[6]) 69 | 70 | GL.Color3dv($color[5]) 71 | GL.Vertex3dv($cube[5]) 72 | GL.Color3dv($color[0]) 73 | GL.Vertex3dv($cube[0]) 74 | GL.Color3dv($color[3]) 75 | GL.Vertex3dv($cube[3]) 76 | GL.Color3dv($color[4]) 77 | GL.Vertex3dv($cube[4]) 78 | 79 | GL.Color3dv($color[6]) 80 | GL.Vertex3dv($cube[6]) 81 | GL.Color3dv($color[1]) 82 | GL.Vertex3dv($cube[1]) 83 | GL.Color3dv($color[2]) 84 | GL.Vertex3dv($cube[2]) 85 | GL.Color3dv($color[7]) 86 | GL.Vertex3dv($cube[7]) 87 | 88 | GL.End() 89 | 90 | GL.MatrixMode(GL::MODELVIEW) 91 | GL.Rotated(5.0, 1.0, 1.0, 1.0) 92 | end 93 | 94 | 95 | if __FILE__ == $PROGRAM_NAME 96 | load_sdl2_lib() 97 | success = SDL.Init(SDL::INIT_EVERYTHING) 98 | exit if success < 0 99 | 100 | WINDOW_W = 640 101 | WINDOW_H = 360 102 | window = SDL.CreateWindow("OpenGL Window via sdl2-bindings", 0, 0, WINDOW_W, WINDOW_H, SDL::WINDOW_OPENGL) 103 | 104 | ratio = WINDOW_W.to_f / WINDOW_H 105 | 106 | context = SDL.GL_CreateContext(window) 107 | 108 | GL.load_lib() 109 | 110 | SDL.GL_SetSwapInterval(1) 111 | 112 | GL.Viewport(0, 0, WINDOW_W, WINDOW_H) 113 | GL.MatrixMode(GL::PROJECTION) 114 | GL.LoadIdentity() 115 | GL.Ortho(-ratio, ratio, -1.0, 1.0, -1.0, 1.0) 116 | GL.MatrixMode(GL::MODELVIEW) 117 | GL.LoadIdentity() 118 | 119 | GL.Enable(GL::DEPTH_TEST) 120 | GL.DepthFunc(GL::LESS) 121 | GL.ShadeModel(GL::SMOOTH) 122 | 123 | # w_buf = ' ' 124 | # h_buf = ' ' 125 | 126 | event = SDL::Event.new 127 | done = false 128 | while not done 129 | while SDL.PollEvent(event) != 0 130 | # 'type' and 'timestamp' are common members for all SDL Event structs. 131 | event_type = event[:common][:type] 132 | event_timestamp = event[:common][:timestamp] 133 | # puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 134 | case event_type 135 | when SDL::KEYDOWN 136 | if event[:key][:keysym][:sym] == SDL::SDLK_ESCAPE 137 | done = true 138 | end 139 | end 140 | end 141 | 142 | SDL.GL_MakeCurrent(window, context) 143 | # SDL.GL_GetDrawableSize(window, w_buf, h_buf) 144 | # glViewport(0, 0, w_buf.unpack("S")[0], h_buf.unpack("S")[0]) 145 | render() 146 | SDL.GL_SwapWindow(window) 147 | end 148 | 149 | SDL.GL_DeleteContext(context) 150 | SDL.DestroyWindow(window) 151 | SDL.Quit() 152 | end 153 | -------------------------------------------------------------------------------- /test/test_sound.rb: -------------------------------------------------------------------------------- 1 | require_relative '../lib/sdl2' 2 | 3 | if __FILE__ == $0 4 | SDL.load_lib(Dir.pwd + '/libSDL2.dylib', sound_libpath: Dir.pwd + '/libSDL2_sound.dylib') 5 | success = SDL.Init(SDL::INIT_AUDIO) 6 | exit if success < 0 7 | 8 | success = SDL.Sound_Init() 9 | exit if success < 0 10 | 11 | version = SDL::Sound_Version.new 12 | SDL.Sound_GetLinkedVersion(version) 13 | puts("Major, Minor and Patch: #{version[:major]} #{version[:minor]} #{version[:patch]}") 14 | 15 | decoder_info_ptr = SDL.Sound_AvailableDecoders() 16 | until decoder_info_ptr.read_pointer.null? 17 | decoder_info = SDL::Sound_DecoderInfo.new(decoder_info_ptr.read_pointer) 18 | extensions = [] 19 | extensions_ptr = decoder_info[:extensions] 20 | until extensions_ptr.read_pointer.null? 21 | extensions << extensions_ptr.read_pointer.read_string 22 | extensions_ptr = extensions_ptr + FFI::NativeType::POINTER.size 23 | end 24 | puts "Decoder for: #{extensions.join(', ')}" 25 | puts "\tDescription: #{decoder_info[:description].read_string}" 26 | puts "\tAuthor: #{decoder_info[:author].read_string}" 27 | puts "\tURL: #{decoder_info[:url].read_string}" 28 | decoder_info_ptr = decoder_info_ptr + FFI::NativeType::POINTER.size 29 | end 30 | 31 | SDL.Sound_Quit() 32 | SDL.Quit() 33 | end 34 | -------------------------------------------------------------------------------- /test/test_sprite.rb: -------------------------------------------------------------------------------- 1 | require_relative '../lib/sdl2' 2 | require_relative 'util' 3 | 4 | class Texture 5 | attr_accessor :sprite, :w, :h 6 | def initialize 7 | @sprite = nil 8 | @w = 0 9 | @h = 0 10 | end 11 | end 12 | $texture = nil 13 | 14 | class Sprite 15 | attr_accessor :pos, :vel 16 | def initialize 17 | @pos = SDL::Rect.new 18 | @vel = SDL::Rect.new 19 | end 20 | end 21 | $sprites = nil 22 | 23 | WINDOW_W = 640 24 | WINDOW_H = 360 25 | NUM_SPRITES = 100 26 | 27 | def load_sprite(file, renderer) 28 | temp = SDL::Surface.new(SDL.LoadBMP_RW(SDL.RWFromFile(file, "rb"), 1)) # temp = SDL_Surface.new(SDL2.SDL_LoadBMP(file)) 29 | $texture = Texture.new 30 | $texture.w = temp[:w] 31 | $texture.h = temp[:h] 32 | 33 | format = SDL::PixelFormat.new(temp[:format]) 34 | if format[:palette] != nil 35 | SDL.SetColorKey(temp, 1, temp[:pixels].read(:uint)) 36 | else 37 | case format[:BitsPerPixel] 38 | when 15; SDL.SetColorKey(temp, 1, (temp[:pixels].read(:short)) & 0x00007FFF); 39 | when 16; SDL.SetColorKey(temp, 1, (temp[:pixels].read(:short)) & 0x00007FFF); 40 | when 24; SDL.SetColorKey(temp, 1, (temp[:pixels].read(:int)) & 0x00007FFF); 41 | when 32; SDL.SetColorKey(temp, 1, (temp[:pixels].read(:int))); 42 | end 43 | end 44 | 45 | $texture.sprite = SDL.CreateTextureFromSurface(renderer, temp) 46 | SDL.FreeSurface(temp) 47 | end 48 | 49 | def move_sprite(renderer) 50 | SDL.SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF) 51 | SDL.RenderClear(renderer) 52 | 53 | NUM_SPRITES.times do |i| 54 | $sprites[i].pos[:x] += $sprites[i].vel[:x] 55 | if $sprites[i].pos[:x] < 0 || $sprites[i].pos[:x] > (WINDOW_W - $texture.w) 56 | $sprites[i].vel[:x] = -$sprites[i].vel[:x] 57 | end 58 | $sprites[i].pos[:y] += $sprites[i].vel[:y] 59 | if $sprites[i].pos[:y] < 0 || $sprites[i].pos[:y] > (WINDOW_H - $texture.w) 60 | $sprites[i].vel[:y] = -$sprites[i].vel[:y] 61 | end 62 | 63 | SDL.RenderCopy(renderer, $texture.sprite, nil, $sprites[i].pos) 64 | end 65 | SDL.RenderPresent(renderer) 66 | end 67 | 68 | if __FILE__ == $PROGRAM_NAME 69 | load_sdl2_lib() 70 | success = SDL.Init(SDL::INIT_EVERYTHING) 71 | exit if success < 0 72 | 73 | SDL.SetHint(SDL::HINT_RENDER_DRIVER, "metal") 74 | 75 | window = SDL.CreateWindow("Minimal Sprite Test via sdl2-bindings", 32, 32, WINDOW_W, WINDOW_H, 0) 76 | 77 | renderer = SDL.CreateRenderer(window, -1, 0) 78 | if renderer != nil 79 | renderer_info = SDL::RendererInfo.new 80 | SDL.GetRendererInfo(renderer, renderer_info) 81 | pp renderer_info[:name].read_string 82 | end 83 | 84 | load_sprite("Globe.bmp", renderer) 85 | 86 | $sprites = Array.new(NUM_SPRITES) { Sprite.new } 87 | NUM_SPRITES.times do |i| 88 | $sprites[i].pos[:x] = WINDOW_W / 2 + 100*rand() - 50 89 | $sprites[i].pos[:y] = WINDOW_H / 2 + 100*rand() - 50 90 | $sprites[i].pos[:w] = $texture.w 91 | $sprites[i].pos[:h] = $texture.h 92 | $sprites[i].vel[:x] = 20*rand() - 10 93 | $sprites[i].vel[:y] = 20*rand() - 10 94 | end 95 | 96 | event = SDL::Event.new 97 | done = false 98 | while not done 99 | while SDL.PollEvent(event) != 0 100 | # 'type' and 'timestamp' are common members for all SDL Event structs. 101 | event_type = event[:common][:type] 102 | # event_timestamp = event.common.timestamp 103 | # puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 104 | case event_type 105 | when SDL::KEYDOWN 106 | if event[:key][:keysym][:sym] == SDL::SDLK_ESCAPE 107 | done = true 108 | end 109 | end 110 | end 111 | move_sprite(renderer) 112 | SDL.Delay(10) 113 | end 114 | 115 | SDL.DestroyRenderer(renderer) 116 | SDL.DestroyWindow(window) 117 | SDL.Quit() 118 | end 119 | -------------------------------------------------------------------------------- /test/test_timer.rb: -------------------------------------------------------------------------------- 1 | require_relative '../lib/sdl2' 2 | require_relative 'util' 3 | 4 | $ticks = 0 5 | 6 | if __FILE__ == $PROGRAM_NAME 7 | load_sdl2_lib() 8 | success = SDL.Init(SDL::INIT_TIMER) 9 | exit if success < 0 10 | 11 | resolution = 1 12 | 13 | cb = Proc.new do |interval, param| 14 | puts("Timer #{interval} : param = #{param}, $ticks=#{$ticks}") 15 | $ticks += 1 16 | interval 17 | end 18 | 19 | thr = Thread.new(1) do |i| 20 | t1 = SDL.AddTimer(resolution, cb, nil) 21 | 22 | print("Waiting Timer...") 23 | sleep(1) 24 | puts("Done.") 25 | SDL.RemoveTimer(t1) 26 | end 27 | 28 | puts("Waiting thread...") 29 | thr.join 30 | 31 | if $ticks > 0 32 | printf("Timer resolution: desired = %d ms, actual = %f ms\n", resolution, (10 * 1000).to_f / $ticks); 33 | end 34 | 35 | SDL.Quit() 36 | end 37 | -------------------------------------------------------------------------------- /test/test_ttf.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | # Usage : $ ruby test_ttf.rb ./GenShinGothic-Normal.ttf 3 | require_relative '../lib/sdl2' 4 | require_relative '../lib/sdl2_ttf' 5 | require_relative 'util' 6 | 7 | WINDOW_W = 640 8 | WINDOW_H = 360 9 | 10 | if __FILE__ == $PROGRAM_NAME 11 | # load_sdl2_lib() 12 | 13 | if ARGV[0] == nil 14 | $stderr.puts 'Usage: ruby test_ttf.rb [path to .ttf]' 15 | exit 16 | end 17 | 18 | SDL.load_lib('/opt/homebrew/lib/libSDL2.dylib', ttf_libpath: '/opt/homebrew/lib/libSDL2_ttf.dylib' ) # '/usr/local/lib/libSDL2.dylib' 19 | 20 | success = SDL.Init(SDL::INIT_EVERYTHING) 21 | exit if success < 0 22 | 23 | window = SDL.CreateWindow("Minimal SDL_TTF Test via sdl2-bindings", SDL::WINDOWPOS_CENTERED_MASK|0, SDL::WINDOWPOS_CENTERED_MASK|0, WINDOW_W, WINDOW_H, 0) 24 | 25 | renderer = SDL.CreateRenderer(window, -1, 0) 26 | 27 | rect = SDL::Rect.new 28 | rect[:x] = 0 29 | rect[:y] = 0 30 | rect[:w] = WINDOW_W 31 | rect[:h] = WINDOW_H 32 | 33 | success = SDL.TTF_Init() 34 | exit if success < 0 35 | 36 | rwops = SDL.RWFromFile(ARGV[0], "rb") 37 | font = SDL.TTF_OpenFontRW(rwops, 0, 42) 38 | 39 | renderstyle = SDL::TTF_STYLE_NORMAL 40 | outline = 0 41 | hinting = SDL::TTF_HINTING_NORMAL 42 | kerning = 0 43 | SDL.TTF_SetFontStyle(font, renderstyle) 44 | SDL.TTF_SetFontOutline(font, outline) 45 | SDL.TTF_SetFontKerning(font, kerning) 46 | SDL.TTF_SetFontHinting(font, hinting) 47 | 48 | fg = SDL::Color.new 49 | fg[:r] = 0xFF 50 | fg[:g] = 0xFF 51 | fg[:b] = 0xFF 52 | fg[:a] = 0xFF 53 | 54 | bg = SDL::Color.new 55 | bg[:r] = 0x00 56 | bg[:g] = 0x00 57 | bg[:b] = 0x00 58 | bg[:a] = 0x00 59 | 60 | pos = SDL::Rect.new 61 | pos[:x] = 20 62 | pos[:y] = 140 63 | pos[:w] = 600 64 | pos[:h] = 60 65 | 66 | # surface = SDL2::TTF_RenderUTF8_Solid(font, "志於道、據於徳、依於仁、游於藝", fg) 67 | surface = SDL::TTF_RenderUTF8_Shaded(font, "志於道、據於徳、依於仁、游於藝", fg, bg) 68 | 69 | texture = SDL.CreateTextureFromSurface(renderer, surface) 70 | 71 | SDL.FreeSurface(surface) 72 | 73 | SDL.SetTextureBlendMode(texture, SDL::BLENDMODE_NONE) 74 | 75 | event = SDL::Event.new 76 | done = false 77 | while not done 78 | while SDL.PollEvent(event) != 0 79 | # 'type' and 'timestamp' are common members for all SDL Event structs. 80 | event_type = event[:common][:type] 81 | # event_timestamp = event.common.timestamp 82 | # puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 83 | case event_type 84 | when SDL::KEYDOWN 85 | if event[:key][:keysym][:sym] == SDL::SDLK_ESCAPE 86 | done = true 87 | end 88 | end 89 | end 90 | 91 | SDL.SetRenderDrawColor(renderer, bg[:r], bg[:g], bg[:b], bg[:a]) 92 | SDL.RenderClear(renderer) 93 | 94 | SDL.RenderCopy(renderer, texture, nil, pos) 95 | 96 | SDL.RenderPresent(renderer) 97 | 98 | SDL.Delay(10) 99 | end 100 | 101 | SDL.DestroyTexture(texture) 102 | SDL.DestroyRenderer(renderer) 103 | SDL.DestroyWindow(window) 104 | SDL.TTF_Quit() 105 | SDL.Quit() 106 | end 107 | -------------------------------------------------------------------------------- /test/test_window.rb: -------------------------------------------------------------------------------- 1 | require_relative '../lib/sdl2' 2 | require_relative 'util' 3 | 4 | if __FILE__ == $PROGRAM_NAME 5 | load_sdl2_lib() 6 | success = SDL.Init(SDL::INIT_EVERYTHING) 7 | exit if success < 0 8 | 9 | WINDOW_W = 320 10 | WINDOW_H = 240 11 | window = SDL.CreateWindow("1st SDL Window via sdl2-bindings", 0, 0, WINDOW_W, WINDOW_H, 0) 12 | 13 | platform_id = case RbConfig::CONFIG['host_os'] 14 | when /mswin|msys|mingw|cygwin/ 15 | :PLATFORM_WINDOWS 16 | when /darwin/ 17 | :PLATFORM_MACOSX 18 | when /linux/ 19 | :PLATFORM_LINUX 20 | else 21 | raise RuntimeError, "Unknown OS: #{host_os.inspect}" 22 | end 23 | 24 | wminfo = case platform_id 25 | when :PLATFORM_WINDOWS 26 | SDL::SysWMinfo_win.new 27 | when :PLATFORM_MACOSX 28 | SDL::SysWMinfo_cocoa.new 29 | when :PLATFORM_LINUX 30 | SDL::SysWMinfo_x11.new 31 | else 32 | raise RuntimeError, "Unknown OS: #{host_os.inspect}" 33 | end 34 | SDL.GetVersion(wminfo[:version].pointer) 35 | 36 | # 1 == SDL_SYSWM_WINDOWS 37 | # 2 == SDL_SYSWM_X11 38 | # 4 == SDL_SYSWM_COCOA 39 | # 6 == SDL_SYSWM_WAYLAND 40 | 41 | if SDL.GetWindowWMInfo(window, wminfo) == SDL::TRUE 42 | case platform_id 43 | when :PLATFORM_WINDOWS 44 | pp [wminfo[:subsystem], wminfo[:info][:win][:window]] 45 | when :PLATFORM_MACOSX 46 | pp [wminfo[:subsystem], wminfo[:info][:cocoa][:window]] 47 | when :PLATFORM_LINUX 48 | # TODO reconsntruct wminfo if we detect Wayland subsystem 49 | pp [wminfo[:subsystem], wminfo[:info][:x11][:display]] 50 | else 51 | raise RuntimeError, "Unknown OS: #{host_os.inspect}" 52 | end 53 | else 54 | p SDL.GetError().read_string 55 | exit 56 | end 57 | 58 | fpsdelay = 100; 59 | 60 | count = 0 61 | event = SDL::Event.new 62 | done = false 63 | while not done 64 | while SDL.PollEvent(event) != 0 65 | # 'type' and 'timestamp' are common members for all SDL Event structs. 66 | event_type = event[:common][:type] 67 | event_timestamp = event[:common][:timestamp] 68 | puts "Event : type=0x#{event_type.to_s(16)}, timestamp=#{event_timestamp}" 69 | 70 | case event_type 71 | when SDL::KEYDOWN 72 | if event[:key][:keysym][:sym] == SDL::SDLK_SPACE 73 | puts "\tSPACE key pressed." 74 | end 75 | when SDL::SYSWMEVENT 76 | wmmsg = case platform_id 77 | when :PLATFORM_WINDOWS 78 | SDL::SysWMmsg_win.new(event[:syswm][:msg]) 79 | when :PLATFORM_MACOSX 80 | SDL::SysWMmsg_cocoa.new(event[:syswm][:msg]) 81 | when :PLATFORM_LINUX 82 | SDL::SysWMmsg_x11.new(event[:syswm][:msg]) 83 | else 84 | raise RuntimeError, "Unknown OS: #{host_os.inspect}" 85 | end 86 | pp wmmsg 87 | end 88 | end 89 | 90 | count += 1 91 | done = true if count >= 100 92 | SDL.Delay(fpsdelay) 93 | end 94 | 95 | SDL.DestroyWindow(window) 96 | SDL.Quit() 97 | end 98 | -------------------------------------------------------------------------------- /test/util.rb: -------------------------------------------------------------------------------- 1 | def load_sdl2_lib() 2 | case RbConfig::CONFIG['host_os'] 3 | when /mswin|msys|mingw|cygwin/ 4 | SDL.load_lib(Dir.pwd + '/SDL2.dll') 5 | when /darwin/ 6 | SDL.load_lib('libSDL2.dylib') # '/usr/local/lib/libSDL2.dylib' 7 | when /linux/ 8 | # Tested on Ubuntu Linux 9 | SDL.load_lib("/lib/#{RUBY_PLATFORM}-gnu/libSDL2.so") 10 | else 11 | raise RuntimeError, "Unsupported platform." 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /third_party/sdl2_build_dll.cmd: -------------------------------------------------------------------------------- 1 | :: 2 | :: Usage : 3 | :: - Open "Developer Command Prompt for VS2019" from start menu 4 | :: - > sdl2_build_dll.cmd 5 | :: 6 | @echo off 7 | setlocal enabledelayedexpansion 8 | 9 | set SDL2_VERSION=2.24.1 10 | 11 | curl -O https://www.libsdl.org/release/SDL2-%SDL2_VERSION%.zip 12 | powershell -Command Expand-Archive -Force SDL2-%SDL2_VERSION%.zip 13 | cd SDL2-%SDL2_VERSION%\SDL2-%SDL2_VERSION% 14 | mkdir build 15 | cd build 16 | cmake -G "Visual Studio 16 2019" -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON .. 17 | msbuild SDL2.sln /t:rebuild /p:Configuration=Release;Platform="x64" 18 | 19 | xcopy /y Release\SDL2.dll ..\..\..\..\test\ 20 | cd ..\..\.. 21 | -------------------------------------------------------------------------------- /third_party/sdl2_build_dylib.sh: -------------------------------------------------------------------------------- 1 | # 2 | # For macOS + Xcode + CMake users. 3 | # 4 | # Ref.: https://github.com/malkia/ufo/blob/master/build/OSX/glfw.sh 5 | # 6 | curl -L -O https://github.com/libsdl-org/SDL/releases/download/release-2.30.2/SDL2-2.30.2.zip 7 | unzip SDL2-2.30.2.zip 8 | cd SDL2-2.30.2/ 9 | mkdir build 10 | cd build 11 | export MACOSX_DEPLOYMENT_TARGET=14.0 12 | cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_OSX_ARCHITECTURES="x86_64;arm64" -D BUILD_SHARED_LIBS=ON -D CMAKE_C_COMPILER=clang ../ 13 | make 14 | 15 | ln -s libSDL2-2.0.dylib libSDL2.dylib 16 | cp -R libSDL2*.dylib ../../../test 17 | -------------------------------------------------------------------------------- /third_party/sdl2_mixer_build_dylib.sh: -------------------------------------------------------------------------------- 1 | # 2 | # For macOS + Xcode + CMake users. 3 | # 4 | # Ref.: https://github.com/malkia/ufo/blob/master/build/OSX/glfw.sh 5 | # 6 | SDL2_VERSION=6845d9f3cb3f35542f1ec7e74dba6b30bf968959 7 | curl -L https://github.com/libsdl-org/SDL_mixer/archive/$SDL2_VERSION.zip > SDL_mixer-$SDL2_VERSION.zip 8 | unzip SDL_mixer-$SDL2_VERSION.zip 9 | cd SDL_mixer-$SDL2_VERSION/ 10 | mkdir build 11 | cd build 12 | export MACOSX_DEPLOYMENT_TARGET=12.1 13 | cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_OSX_ARCHITECTURES="arm64" -D BUILD_SHARED_LIBS=ON -D CMAKE_C_COMPILER=clang ../ 14 | make 15 | 16 | cp -R libSDL2_mixer.dylib ../../../test 17 | -------------------------------------------------------------------------------- /third_party/sdl2_sound_build_dylib.sh: -------------------------------------------------------------------------------- 1 | # 2 | # For macOS + Xcode + CMake users. 3 | # 4 | # Ref.: https://github.com/malkia/ufo/blob/master/build/OSX/glfw.sh 5 | # 6 | # SDL2_DIR=/opt/homebrew/opt/sdl2 7 | # SDL_VERSION=2.0.1 8 | # curl -L https://github.com/icculus/SDL_sound/archive/refs/tags/v$SDL_VERSION.zip > SDL_sound-$SDL_VERSION.zip 9 | SDL_VERSION=42c4f200c867cc7681b2e9b96057bb9e90355738 10 | curl -L https://github.com/icculus/SDL_sound/archive/$SDL_VERSION.zip > SDL_sound-$SDL_VERSION.zip 11 | unzip SDL_sound-$SDL_VERSION.zip 12 | cd SDL_sound-$SDL_VERSION/ 13 | mkdir build 14 | cd build 15 | export MACOSX_DEPLOYMENT_TARGET=12.1 16 | cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_OSX_ARCHITECTURES="arm64" -D BUILD_SHARED_LIBS=ON -D CMAKE_C_COMPILER=clang ../ 17 | make 18 | 19 | cp -R libSDL2_sound*dylib ../../../test 20 | --------------------------------------------------------------------------------