├── .gitignore ├── NEWS.rdoc ├── README.rdoc ├── Rakefile ├── examples ├── load_image.rb └── load_music.rb ├── lib ├── ruby-sdl-ffi.rb └── ruby-sdl-ffi │ ├── gfx.rb │ ├── gfx │ ├── blitfunc.rb │ ├── framerate.rb │ ├── imagefilter.rb │ ├── primitives.rb │ └── rotozoom.rb │ ├── image.rb │ ├── mixer.rb │ ├── sdl.rb │ ├── sdl │ ├── audio.rb │ ├── cdrom.rb │ ├── core.rb │ ├── event.rb │ ├── joystick.rb │ ├── keyboard.rb │ ├── keysyms.rb │ ├── mac.rb │ ├── mouse.rb │ ├── mutex.rb │ ├── rwops.rb │ ├── timer.rb │ └── video.rb │ └── ttf.rb ├── ruby-sdl-ffi.gemspec └── scripts └── mkchangelog.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .\#* 3 | \#*\# 4 | pkg 5 | html 6 | -------------------------------------------------------------------------------- /NEWS.rdoc: -------------------------------------------------------------------------------- 1 | = NEWS 2 | 3 | == Ruby-SDL-FFI 0.4 4 | 5 | * Fixed the display window not gaining focus on Mac OS X 10.6. 6 | Thanks to Bart Leusink for fixing this. 7 | 8 | * Added SDL::SaveBMP and SDL::LoadBMP methods. These were convenience 9 | macros defined in the SDL headers. They have been reimplemented as 10 | Ruby methods by Bart Leusink. 11 | 12 | 13 | 14 | == Ruby-SDL-FFI 0.3 15 | 16 | * Ruby-SDL-FFI can now work on Mac OS X without the need for a special 17 | interpreter (i.e. rsdl). If this causes issues for you, you can 18 | disable it by setting the RUBYSDLFFI_NOCOCOA environment variable to 19 | "true". 20 | 21 | * Added the SDL::set_app_name() method. This sets the application name 22 | in a platform-appropriate way, or does nothing if the platform is 23 | not supported. On Mac OS X, it changes the text in the menu bar. 24 | Support for other platforms may be added in the future. 25 | 26 | * Ruby-SDL-FFI now reads the RUBYSDLFFI_PATH environment variable for 27 | additional library load paths. It should be a colon-separated 28 | (Linux/Mac) or semicolon-separated (Windows) list of directories to 29 | search for libraries. 30 | 31 | * The SDL::Palette class is now Enumerable. You can iterate over it 32 | with #each, #collect, etc. You can also read a specific index using 33 | #at (but not #[], which is reserved for struct access). 34 | 35 | * SDL.GL_GetAttribute() now returns an integer, like it should. 36 | Before, it would return an FFI::Buffer. 37 | 38 | * SDL.GetKeyRepeat() is now easier to use. It returns an Array of two 39 | integers: [delay, interval]. Before, you had to pass two output 40 | buffers, then extract the integers afterwards. 41 | 42 | * Fixed a NoMethodError in SDL.WaitEvent(). 43 | 44 | * Ruby-SDL-FFI now uses FFI::Buffer instead of FFI::MemoryPointer in 45 | many places. This should give a slight performance boost on JRuby, 46 | and potentially other platforms. 47 | 48 | 49 | 50 | == Ruby-SDL-FFI 0.2 51 | 52 | * The values of SDL::AUDIO_U16SYS and SDL::AUDIO_S16SYS are now 53 | correct on both big-endian and little-endian systems. 54 | 55 | * SDL::Gfx::arcRGBA is now considered optional (as it should have been 56 | in version 0.1). Loading will continue even if it is not available, 57 | such as when using older versions of SDL_gfx. 58 | 59 | * The minimum supported version of SDL_gfx is now 2.0.13. It was 60 | 2.0.17 before. 61 | 62 | * SDL::Gfx::rotozoomSurfaceXY and SDL::Gfx::rotozoomSurfaceSizeXY are 63 | no longer considered optional, because they are available in all 64 | supported versions of SDL_gfx (2.0.13 and higher). 65 | 66 | 67 | 68 | == Ruby-SDL-FFI 0.1 69 | 70 | * Initial release of Ruby-SDL-FFI. Bindings are provided for these 71 | libraries (older versions may work, but haven't been tested): 72 | 73 | * SDL >= 1.2.13 74 | * SDL_gfx >= 2.0.17 75 | * SDL_image >= 1.2.7 76 | * SDL_mixer >= 1.2.8 77 | * SDL_ttf >= 2.0.9 78 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | 2 | = Ruby-SDL-FFI 3 | 4 | Version:: 0.4 5 | Date:: 2011-03-06 6 | 7 | Homepage:: http://github.com/rubygame/ruby-sdl-ffi/ 8 | Author:: John Croisant 9 | Copyright:: 2009-2011 John Croisant 10 | 11 | 12 | == Description 13 | 14 | Ruby-SDL-FFI is a low-level binding to SDL [1] and related 15 | libraries using Ruby-FFI [2] or compatible FFI APIs, such as 16 | JRuby's. It provides very basic access to SDL from Ruby [3] 17 | without the need for a compiled C wrapper. It aims to be 18 | platform and Ruby implementation independent. 19 | 20 | Ruby-SDL-FFI does not attempt to provide any high-level 21 | functionality, only to mirror the standard SDL interface. 22 | For higher-level functionality, you should use other 23 | libraries (Rubygame [4], Gosu [5], etc.). 24 | 25 | 1. SDL: http://www.libsdl.org/ 26 | 2. Ruby-FFI: http://github.com/ffi/ffi 27 | 3. Ruby: http://www.ruby-lang.org/en/ 28 | 4. Rubygame: http://rubygame.org/ 29 | 5. Gosu: http://www.libgosu.org/ 30 | 31 | 32 | == Caveats 33 | 34 | Ruby-SDL-FFI is still in EARLY DEVELOPMENT STAGES. That means: 35 | 36 | * It may not work correctly (or at all). 37 | * It may not be complete. 38 | * It may change drastically with no advanced notice. 39 | 40 | As such, this library is currently FOR THE ADVENTUROUS ONLY. 41 | If you are not willing to continuously update your code to 42 | match the new API, then you should wait until Ruby-SDL-FFI is 43 | more mature and stable (i.e. version 1.0+). 44 | 45 | 46 | == Requirements 47 | 48 | * SDL >= 1.2.13 49 | * Nice-FFI >= 0.2.0 50 | 51 | Optional: 52 | 53 | * SDL_image >= 1.2.7 54 | * SDL_gfx >= 2.0.13 55 | * SDL_mixer >= 1.2.8 56 | * SDL_ttf >= 2.0.9 57 | 58 | Ruby-SDL-FFI may work with older versions, but hasn't been tried on them. 59 | 60 | 61 | == License 62 | 63 | Ruby-SDL-FFI is licensed under the following terms (the "MIT License"): 64 | 65 | Copyright (c) 2009-2011 John Croisant 66 | 67 | Permission is hereby granted, free of charge, to any person obtaining 68 | a copy of this software and associated documentation files (the 69 | "Software"), to deal in the Software without restriction, including 70 | without limitation the rights to use, copy, modify, merge, publish, 71 | distribute, sublicense, and/or sell copies of the Software, and to 72 | permit persons to whom the Software is furnished to do so, subject to 73 | the following conditions: 74 | 75 | The above copyright notice and this permission notice shall be 76 | included in all copies or substantial portions of the Software. 77 | 78 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 81 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 82 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 83 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 84 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 85 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | require 'rake' 32 | 33 | 34 | ############# 35 | ## GEM ## 36 | ############# 37 | 38 | require 'rake/gempackagetask' 39 | 40 | # Load ruby-sdl-ffi.gemspec, which defines $gemspec. 41 | load File.join( File.dirname(__FILE__), "ruby-sdl-ffi.gemspec" ) 42 | 43 | Rake::GemPackageTask.new( $gemspec ) do |pkg| 44 | pkg.need_tar_bz2 = true 45 | end 46 | 47 | 48 | ############### 49 | ## VERSION ## 50 | ############### 51 | 52 | task :version do 53 | puts "%s-%s"%[$gemspec.name, $gemspec.version.to_s] 54 | end 55 | 56 | rule( /bump:[0-9.]+/ ) do |t| 57 | ver = t.name.gsub("bump:","") 58 | today = Date.today.to_s 59 | 60 | puts "Updating version to #{ver} and date to #{today}..." 61 | 62 | print " README.rdoc... " 63 | `ruby -pi -e ' 64 | $_.gsub!(/\([Vv]ersion:: +\)[0-9.]+/, "\\\\1#{ver}") 65 | $_.gsub!(/\([Dd]ate:: +\)[0-9-]+/, "\\\\1#{today}") 66 | ' README.rdoc` 67 | puts "done" 68 | 69 | print " ruby-sdl-ffi.gemspec... " 70 | `ruby -pi -e ' 71 | $_.gsub!(/\(s.version *= *\)"[0-9.]+"/, "\\\\1\\"#{ver}\\"") 72 | ' ruby-sdl-ffi.gemspec` 73 | puts "done" 74 | 75 | end 76 | 77 | 78 | ################# 79 | ## CHANGELOG ## 80 | ################# 81 | 82 | task :changelog do 83 | `ruby scripts/mkchangelog.rb ChangeLog.txt` 84 | end 85 | 86 | task "ChangeLog.txt" => [:changelog] 87 | task :gem => [:changelog] 88 | task :package => [:changelog] 89 | 90 | 91 | ############# 92 | ## CLEAN ## 93 | ############# 94 | 95 | require 'rake/clean' 96 | 97 | CLEAN.include("ChangeLog.txt") 98 | 99 | 100 | ############ 101 | ## DOCS ## 102 | ############ 103 | 104 | require 'rake/rdoctask' 105 | 106 | Rake::RDocTask.new do |rd| 107 | rd.title = "Ruby-SDL-FFI #{$gemspec.version} Docs" 108 | rd.main = "README.rdoc" 109 | rd.rdoc_files.include( "lib/**/*.rb", "**/*.rdoc" ) 110 | end 111 | 112 | 113 | ######### 114 | # SPECS # 115 | ######### 116 | 117 | begin 118 | require 'spec/rake/spectask' 119 | 120 | desc "Run all specs" 121 | Spec::Rake::SpecTask.new do |t| 122 | t.spec_files = FileList['spec/*_spec.rb'] 123 | end 124 | 125 | namespace :spec do 126 | desc "Run all specs" 127 | Spec::Rake::SpecTask.new(:all) do |t| 128 | t.spec_files = FileList['spec/*_spec.rb'] 129 | end 130 | 131 | desc "Run spec/[name]_spec.rb (e.g. 'color')" 132 | task :name do 133 | puts( "This is just a stand-in spec.", 134 | "Run rake spec:[name] where [name] is e.g. 'color', 'music'." ) 135 | end 136 | end 137 | 138 | 139 | rule(/spec:.+/) do |t| 140 | name = t.name.gsub("spec:","") 141 | 142 | path = File.join( File.dirname(__FILE__),'spec','%s_spec.rb'%name ) 143 | 144 | if File.exist? path 145 | Spec::Rake::SpecTask.new(name) do |t| 146 | t.spec_files = [path] 147 | end 148 | 149 | puts "\nRunning spec/%s_spec.rb"%name 150 | 151 | Rake::Task[name].invoke 152 | else 153 | puts "File does not exist: %s"%path 154 | end 155 | 156 | end 157 | 158 | rescue LoadError 159 | 160 | error = "ERROR: RSpec is not installed?" 161 | 162 | task :spec do 163 | puts error 164 | end 165 | 166 | rule( /spec:.*/ ) do 167 | puts error 168 | end 169 | 170 | end 171 | -------------------------------------------------------------------------------- /examples/load_image.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # 4 | # A simple example script using Ruby-SDL-FFI to load and display 5 | # an image file. Loads and displays the image file given on the 6 | # command line for 5 seconds, then quits. 7 | # 8 | # Usage: load_image.rb /path/to/image" 9 | # 10 | # Script last updated: June 21, 2009. 11 | # 12 | # Ruby-SDL-FFI is still in flux, so expect the API style to 13 | # change in the near future. 14 | # 15 | 16 | require 'ruby-sdl-ffi' 17 | 18 | path = ARGV[0] 19 | 20 | if path.nil? 21 | puts "Usage: load_image.rb /path/to/image" 22 | exit 1 23 | elsif not File.exist?( File.expand_path(path) ) 24 | puts "Error: file doesn't exist: #{path}" 25 | exit 1 26 | end 27 | 28 | path = File.expand_path(path) 29 | 30 | # Load the image file. 31 | image = SDL::Image::Load( path ) 32 | 33 | # Create a new window the same size as the image. 34 | screen = SDL::SetVideoMode(image.w, image.h, 0, 0) 35 | 36 | # Blit the image onto the screen surface. 37 | SDL::BlitSurface( image, nil, screen, nil ) 38 | 39 | # Update the screen. 40 | SDL::UpdateRect( screen, 0, 0, 0, 0 ) 41 | 42 | # Set the screen title to the filename of the image. 43 | SDL::WM_SetCaption( File.basename(path), File.basename(path) ) 44 | 45 | # Pause while the user admires the image. 46 | sleep 5 47 | -------------------------------------------------------------------------------- /examples/load_music.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "ruby-sdl-ffi" 4 | 5 | 6 | # Get the path to the music file 7 | 8 | path = ARGV[0] 9 | 10 | if path.nil? 11 | puts "Usage: load_music.rb /path/to/song" 12 | exit 1 13 | elsif not File.exist?( File.expand_path(path) ) 14 | puts "Error: file doesn't exist: #{path}" 15 | exit 1 16 | end 17 | 18 | path = File.expand_path(path) 19 | 20 | 21 | # Open audio device 22 | if( SDL::Mixer::OpenAudio( 22050, SDL::AUDIO_S16SYS, 2, 1024 ) == -1 ) 23 | puts "ERROR: Could not initialize audio: #{SDL::GetError()}" 24 | exit 1 25 | end 26 | 27 | 28 | # Make sure audio device closes at exit. 29 | at_exit { SDL::Mixer::CloseAudio() } 30 | 31 | 32 | # Load music 33 | music = SDL::Mixer::LoadMUS( path ) 34 | if( music.to_ptr.null? ) 35 | puts "ERROR: Could not load music: #{SDL::GetError()}" 36 | exit 1 37 | end 38 | 39 | 40 | # Play music 41 | if( SDL::Mixer::PlayMusic( music.to_ptr, -1 ) == -1 ) 42 | puts "ERROR: Could not play music: #{SDL::GetError()}" 43 | exit 1 44 | end 45 | 46 | 47 | # Let music play for a while... 48 | sleep 10 49 | 50 | 51 | # Fade out in 1 second 52 | SDL::Mixer::FadeOutMusic( 1000 ) 53 | 54 | 55 | # Wait until it's done fading out. 56 | while( SDL::Mixer::FadingMusic() == 1 ) 57 | sleep 0.1 58 | end 59 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009, 2010 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | this_dir = File.expand_path( File.dirname(__FILE__) ) 32 | 33 | 34 | # sdl.rb is absolutely required. If it fails, don't catch the error. 35 | require File.join( this_dir, 'ruby-sdl-ffi', 'sdl' ) 36 | 37 | 38 | # The others are "optional", so just give a warning if they fail. 39 | # Users who really need them should load them directly, with 40 | # e.g. 'require "ruby-sdl-ffi/gfx"'. 41 | %w{ 42 | 43 | image 44 | ttf 45 | mixer 46 | gfx 47 | 48 | }.each do |f| 49 | 50 | begin 51 | require File.join( this_dir, 'ruby-sdl-ffi', f ) 52 | rescue LoadError => e 53 | warn "Warning: " + e.message 54 | end 55 | 56 | end 57 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/gfx.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | this_dir = File.expand_path( File.dirname(__FILE__) ) 32 | 33 | 34 | require File.join( this_dir, "sdl" ) 35 | 36 | 37 | module SDL 38 | module Gfx 39 | extend NiceFFI::Library 40 | load_library "SDL_gfx", SDL::LOAD_PATHS 41 | 42 | def self.sdl_func( name, args, ret ) 43 | func name, "SDL_#{name}", args, ret 44 | end 45 | end 46 | end 47 | 48 | %w{ 49 | framerate 50 | blitfunc 51 | primitives 52 | imagefilter 53 | rotozoom 54 | }.each do |f| 55 | require File.join( this_dir, "gfx", f ) 56 | end 57 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/gfx/blitfunc.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | module Gfx 33 | 34 | optfunc :BlitRGBA, "SDL_gfxBlitRGBA", 35 | [ :pointer, :pointer, :pointer, :pointer ], :int 36 | 37 | optfunc :SetAlpha, "SDL_gfxSetAlpha", [ :pointer, :uint8 ], :int 38 | 39 | 40 | class BlitInfo < NiceFFI::Struct 41 | layout( :s_pixels, :pointer, 42 | :s_width, :int, 43 | :s_height, :int, 44 | :s_skip, :int, 45 | :d_pixels, :pointer, 46 | :d_width, :int, 47 | :d_height, :int, 48 | :d_skip, :int, 49 | :aux_data, :pointer, 50 | :src, SDL::PixelFormat.typed_pointer, 51 | :table, :pointer, 52 | :dst, SDL::PixelFormat.typed_pointer ) 53 | end 54 | 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/gfx/framerate.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | module Gfx 33 | 34 | FPS_UPPER_LIMIT = 200 35 | FPS_LOWER_LIMIT = 1 36 | FPS_DEFAULT = 30 37 | 38 | class FPSmanager < NiceFFI::Struct 39 | layout( :framecount, :uint32, 40 | :rateticks, :float, 41 | :lastticks, :uint32, 42 | :rate, :uint32 ) 43 | end 44 | 45 | sdl_func :initFramerate, [ :pointer ], :void 46 | sdl_func :setFramerate, [ :pointer, :int ], :int 47 | sdl_func :getFramerate, [ :pointer ], :int 48 | sdl_func :framerateDelay, [ :pointer ], :void 49 | 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/gfx/imagefilter.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | module Gfx 33 | 34 | sdl_func :imageFilterMMXdetect, [ ], :int 35 | sdl_func :imageFilterMMXoff, [ ], :void 36 | sdl_func :imageFilterMMXon, [ ], :void 37 | 38 | 39 | sdl_func :imageFilterAdd, 40 | [ :pointer, :pointer, :pointer, :int ], :int 41 | 42 | sdl_func :imageFilterMean, 43 | [ :pointer, :pointer, :pointer, :int ], :int 44 | 45 | sdl_func :imageFilterSub, 46 | [ :pointer, :pointer, :pointer, :int ], :int 47 | 48 | sdl_func :imageFilterAbsDiff, 49 | [ :pointer, :pointer, :pointer, :int ], :int 50 | 51 | sdl_func :imageFilterMult, 52 | [ :pointer, :pointer, :pointer, :int ], :int 53 | 54 | sdl_func :imageFilterMultNor, 55 | [ :pointer, :pointer, :pointer, :int ], :int 56 | 57 | sdl_func :imageFilterMultDivby2, 58 | [ :pointer, :pointer, :pointer, :int ], :int 59 | 60 | sdl_func :imageFilterMultDivby4, 61 | [ :pointer, :pointer, :pointer, :int ], :int 62 | 63 | sdl_func :imageFilterBitAnd, 64 | [ :pointer, :pointer, :pointer, :int ], :int 65 | 66 | sdl_func :imageFilterBitOr, 67 | [ :pointer, :pointer, :pointer, :int ], :int 68 | 69 | sdl_func :imageFilterDiv, 70 | [ :pointer, :pointer, :pointer, :int ], :int 71 | 72 | sdl_func :imageFilterBitNegation, 73 | [ :pointer, :pointer, :int ], :int 74 | 75 | 76 | 77 | sdl_func :imageFilterAddByte, 78 | [ :pointer, :pointer, :int, :uchar ], :int 79 | 80 | sdl_func :imageFilterAddUint, 81 | [ :pointer, :pointer, :int, :uint ], :int 82 | 83 | sdl_func :imageFilterAddByteToHalf, 84 | [ :pointer, :pointer, :int, :uchar ], :int 85 | 86 | 87 | sdl_func :imageFilterSubByte, 88 | [ :pointer, :pointer, :int, :uchar ], :int 89 | 90 | sdl_func :imageFilterSubUint, 91 | [ :pointer, :pointer, :int, :uint ], :int 92 | 93 | 94 | 95 | sdl_func :imageFilterShiftRight, 96 | [ :pointer, :pointer, :int, :uchar ], :int 97 | 98 | sdl_func :imageFilterShiftRightUint, 99 | [ :pointer, :pointer, :int, :uchar ], :int 100 | 101 | 102 | 103 | sdl_func :imageFilterMultByByte, 104 | [ :pointer, :pointer, :int, :uchar ], :int 105 | 106 | sdl_func :imageFilterShiftRightAndMultByByte, 107 | [ :pointer, :pointer, :int, :uchar, :uchar ], :int 108 | 109 | 110 | 111 | sdl_func :imageFilterShiftLeftByte, 112 | [ :pointer, :pointer, :int, :uchar ], :int 113 | 114 | sdl_func :imageFilterShiftLeftUint, 115 | [ :pointer, :pointer, :int, :uchar ], :int 116 | 117 | sdl_func :imageFilterShiftLeft, 118 | [ :pointer, :pointer, :int, :uchar ], :int 119 | 120 | 121 | 122 | sdl_func :imageFilterBinarizeUsingThreshold, 123 | [ :pointer, :pointer, :int, :uchar ], :int 124 | 125 | 126 | sdl_func :imageFilterClipToRange, 127 | [ :pointer, :pointer, :int, :uchar, :uchar ], :int 128 | 129 | 130 | sdl_func :imageFilterNormalizeLinear, 131 | [ :pointer, :pointer, :int, :int, :int, :int, :int ], :int 132 | 133 | 134 | 135 | sdl_func :imageFilterConvolveKernel3x3Divide, 136 | [ :pointer, :pointer, :int, :int, :pointer, :uchar ], :int 137 | 138 | sdl_func :imageFilterConvolveKernel5x5Divide, 139 | [ :pointer, :pointer, :int, :int, :pointer, :uchar ], :int 140 | 141 | sdl_func :imageFilterConvolveKernel7x7Divide, 142 | [ :pointer, :pointer, :int, :int, :pointer, :uchar ], :int 143 | 144 | sdl_func :imageFilterConvolveKernel9x9Divide, 145 | [ :pointer, :pointer, :int, :int, :pointer, :uchar ], :int 146 | 147 | 148 | 149 | sdl_func :imageFilterConvolveKernel3x3ShiftRight, 150 | [ :pointer, :pointer, :int, :int, :pointer, :uchar ], :int 151 | 152 | sdl_func :imageFilterConvolveKernel5x5ShiftRight, 153 | [ :pointer, :pointer, :int, :int, :pointer, :uchar ], :int 154 | 155 | sdl_func :imageFilterConvolveKernel7x7ShiftRight, 156 | [ :pointer, :pointer, :int, :int, :pointer, :uchar ], :int 157 | 158 | sdl_func :imageFilterConvolveKernel9x9ShiftRight, 159 | [ :pointer, :pointer, :int, :int, :pointer, :uchar ], :int 160 | 161 | 162 | 163 | sdl_func :imageFilterSobelX, 164 | [ :pointer, :pointer, :int, :int ], :int 165 | 166 | sdl_func :imageFilterSobelXShiftRight, 167 | [ :pointer, :pointer, :int, :int, :uchar ], :int 168 | 169 | 170 | 171 | sdl_func :imageFilterAlignStack, [ ], :void 172 | sdl_func :imageFilterRestoreStack, [ ], :void 173 | 174 | 175 | end 176 | end 177 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/gfx/primitives.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | module Gfx 33 | 34 | M_PI = 3.141592654 35 | 36 | 37 | func :pixelColor, [ :pointer, :int16, :int16, :uint32 ], :int 38 | 39 | func :pixelRGBA, 40 | [ :pointer, :int16, :int16, :uint8, :uint8, :uint8, :uint8 ], :int 41 | 42 | 43 | 44 | func :hlineColor, [ :pointer, :int16, :int16, :int16, :uint32 ], :int 45 | 46 | func :hlineRGBA, 47 | [ :pointer, :int16, :int16, :int16, 48 | :uint8, :uint8, :uint8, :uint8 ], :int 49 | 50 | func :vlineColor, [ :pointer, :int16, :int16, :int16, :uint32 ], :int 51 | 52 | func :vlineRGBA, 53 | [ :pointer, :int16, :int16, :int16, 54 | :uint8, :uint8, :uint8, :uint8 ], :int 55 | 56 | 57 | 58 | func :rectangleColor, 59 | [ :pointer, :int16, :int16, :int16, :int16, :uint32 ], :int 60 | 61 | func :rectangleRGBA, 62 | [ :pointer, :int16, :int16, 63 | :int16, :int16, :uint8, :uint8, :uint8, :uint8 ], :int 64 | 65 | func :boxColor, 66 | [ :pointer, :int16, :int16, :int16, :int16, :uint32 ], :int 67 | 68 | func :boxRGBA, 69 | [ :pointer, :int16, :int16, :int16, 70 | :int16, :uint8, :uint8, :uint8, :uint8 ], :int 71 | 72 | 73 | 74 | func :lineColor, 75 | [ :pointer, :int16, :int16, :int16, :int16, :uint32 ], :int 76 | 77 | func :lineRGBA, 78 | [ :pointer, :int16, :int16, :int16, :int16, 79 | :uint8, :uint8, :uint8, :uint8 ], :int 80 | 81 | func :aalineColor, 82 | [ :pointer, :int16, :int16, :int16, :int16, :uint32 ], :int 83 | 84 | func :aalineRGBA, 85 | [ :pointer, :int16, :int16, :int16, :int16, 86 | :uint8, :uint8, :uint8, :uint8 ], :int 87 | 88 | 89 | 90 | func :circleColor, 91 | [ :pointer, :int16, :int16, :int16, :uint32 ], :int 92 | 93 | func :circleRGBA, 94 | [ :pointer, :int16, :int16, :int16, 95 | :uint8, :uint8, :uint8, :uint8 ], :int 96 | 97 | func :aacircleColor, 98 | [ :pointer, :int16, :int16, :int16, :uint32 ], :int 99 | 100 | func :aacircleRGBA, 101 | [ :pointer, :int16, :int16, :int16, 102 | :uint8, :uint8, :uint8, :uint8 ], :int 103 | 104 | func :filledCircleColor, 105 | [ :pointer, :int16, :int16, :int16, :uint32 ], :int 106 | 107 | func :filledCircleRGBA, 108 | [ :pointer, :int16, :int16, :int16, 109 | :uint8, :uint8, :uint8, :uint8 ], :int 110 | 111 | 112 | 113 | optfunc :arcColor, 114 | [ :pointer, :int16, :int16, :int16, 115 | :int16, :int16, :uint32 ], :int 116 | 117 | optfunc :arcRGBA, 118 | [ :pointer, :int16, :int16, :int16, :int16, :int16, 119 | :uint8, :uint8, :uint8, :uint8 ], :int 120 | 121 | 122 | 123 | func :ellipseColor, 124 | [ :pointer, :int16, :int16, :int16, :int16, :uint32 ], :int 125 | 126 | func :ellipseRGBA, 127 | [ :pointer, :int16, :int16, :int16, :int16, 128 | :uint8, :uint8, :uint8, :uint8 ], :int 129 | 130 | func :aaellipseColor, 131 | [ :pointer, :int16, :int16, :int16, :int16, :uint32 ], :int 132 | 133 | func :aaellipseRGBA, 134 | [ :pointer, :int16, :int16, :int16, :int16, 135 | :uint8, :uint8, :uint8, :uint8 ], :int 136 | 137 | func :filledEllipseColor, 138 | [ :pointer, :int16, :int16, :int16, :int16, :uint32 ], :int 139 | 140 | func :filledEllipseRGBA, 141 | [ :pointer, :int16, :int16, :int16, :int16, 142 | :uint8, :uint8, :uint8, :uint8 ], :int 143 | 144 | 145 | 146 | func :pieColor, 147 | [ :pointer, :int16, :int16, :int16, :int16, :int16, :uint32 ], :int 148 | 149 | func :pieRGBA, 150 | [ :pointer, :int16, :int16, :int16, :int16, :int16, 151 | :uint8, :uint8, :uint8, :uint8 ], :int 152 | 153 | func :filledPieColor, 154 | [ :pointer, :int16, :int16, :int16, :int16, :int16, :uint32 ], :int 155 | 156 | func :filledPieRGBA, 157 | [ :pointer, :int16, :int16, :int16, :int16, :int16, 158 | :uint8, :uint8, :uint8, :uint8 ], :int 159 | 160 | 161 | 162 | func :trigonColor, 163 | [ :pointer, :int16, :int16, :int16, :int16, 164 | :int16, :int16, :uint32 ], :int 165 | 166 | func :trigonRGBA, 167 | [ :pointer, :int16, :int16, :int16, :int16, :int16, 168 | :int16, :uint8, :uint8, :uint8, :uint8 ], :int 169 | 170 | func :aatrigonColor, 171 | [ :pointer, :int16, :int16, :int16, :int16, 172 | :int16, :int16, :uint32 ], :int 173 | 174 | func :aatrigonRGBA, 175 | [ :pointer, :int16, :int16, :int16, :int16, :int16, 176 | :int16, :uint8, :uint8, :uint8, :uint8 ], :int 177 | 178 | func :filledTrigonColor, 179 | [ :pointer, :int16, :int16, :int16, :int16, 180 | :int16, :int16, :uint32 ], :int 181 | 182 | func :filledTrigonRGBA, 183 | [ :pointer, :int16, :int16, :int16, :int16, :int16, 184 | :int16, :uint8, :uint8, :uint8, :uint8 ], :int 185 | 186 | 187 | 188 | func :polygonColor, [ :pointer, :pointer, :pointer, :int, :uint32 ], :int 189 | 190 | func :polygonRGBA, 191 | [ :pointer, :pointer, :pointer, :int, 192 | :uint8, :uint8, :uint8, :uint8 ], :int 193 | 194 | func :aapolygonColor, 195 | [ :pointer, :pointer, :pointer, :int, :uint32 ], :int 196 | 197 | func :aapolygonRGBA, 198 | [ :pointer, :pointer, :pointer, :int, 199 | :uint8, :uint8, :uint8, :uint8 ], :int 200 | 201 | func :filledPolygonColor, 202 | [ :pointer, :pointer, :pointer, :int, :uint32 ], :int 203 | 204 | func :filledPolygonRGBA, 205 | [ :pointer, :pointer, :pointer, :int, 206 | :uint8, :uint8, :uint8, :uint8 ], :int 207 | 208 | optfunc :texturedPolygon, 209 | [ :pointer, :pointer, :pointer, 210 | :int, :pointer, :int, :int ], :int 211 | 212 | 213 | optfunc :filledPolygonColorMT, 214 | [ :pointer, :pointer, :pointer, 215 | :int, :uint32, :pointer, :pointer ], :int 216 | 217 | optfunc :filledPolygonRGBAMT, 218 | [ :pointer, :pointer, :pointer, :int, :uint8, 219 | :uint8, :uint8, :uint8, :pointer, :pointer ], :int 220 | 221 | optfunc :texturedPolygonMT, 222 | [ :pointer, :pointer, :pointer, :int, 223 | :pointer, :int, :int, :pointer, :pointer ], :int 224 | 225 | 226 | 227 | func :bezierColor, 228 | [ :pointer, :pointer, :pointer, :int, :int, :uint32 ], :int 229 | 230 | func :bezierRGBA, 231 | [ :pointer, :pointer, :pointer, :int, :int, 232 | :uint8, :uint8, :uint8, :uint8 ], :int 233 | 234 | 235 | 236 | func :characterColor, [ :pointer, :int16, :int16, :char, :uint32 ], :int 237 | 238 | func :characterRGBA, 239 | [ :pointer, :int16, :int16, :char, 240 | :uint8, :uint8, :uint8, :uint8 ], :int 241 | 242 | func :stringColor, [ :pointer, :int16, :int16, :string, :uint32 ], :int 243 | 244 | func :stringRGBA, 245 | [ :pointer, :int16, :int16, :string, 246 | :uint8, :uint8, :uint8, :uint8 ], :int 247 | 248 | func :gfxPrimitivesSetFont, [ :pointer, :int, :int ], :void 249 | 250 | end 251 | end 252 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/gfx/rotozoom.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | module Gfx 33 | 34 | SMOOTHING_OFF = 0 35 | SMOOTHING_ON = 1 36 | 37 | 38 | class TColorRGBA < NiceFFI::Struct 39 | layout( :r, :uint8, 40 | :g, :uint8, 41 | :b, :uint8, 42 | :a, :uint8 ) 43 | end 44 | 45 | 46 | class TColorY < NiceFFI::Struct 47 | layout( :y, :uint8 ) 48 | end 49 | 50 | 51 | 52 | func :rotozoomSurface, 53 | [ :pointer, :double, :double, :int ], 54 | SDL::Surface.typed_pointer 55 | 56 | func :__rotozoomSurfaceSize, :rotozoomSurfaceSize, 57 | [ :int, :int, :double, :double, :buffer_out, :buffer_out ], :void 58 | 59 | def self.rotozoomSurfaceSize( width, height, angle, zoom ) 60 | w = FFI::Buffer.new( :int ) 61 | h = FFI::Buffer.new( :int ) 62 | __rotozoomSurfaceSize( width, height, angle, zoom, w, h ) 63 | return [w.get_int(0), h.get_int(0)] 64 | end 65 | 66 | 67 | func :rotozoomSurfaceXY, 68 | [ :pointer, :double, :double, :double, :int ], 69 | SDL::Surface.typed_pointer 70 | 71 | func :__rotozoomSurfaceSizeXY, :rotozoomSurfaceSizeXY, 72 | [ :int, :int, :double, :double, :double, 73 | :buffer_out, :buffer_out ], :void 74 | 75 | def self.rotozoomSurfaceSizeXY( width, height, angle, zoomx, zoomy ) 76 | w = FFI::Buffer.new( :int ) 77 | h = FFI::Buffer.new( :int ) 78 | __rotozoomSurfaceSizeXY( width, height, angle, zoomx, zoomy, w, h ) 79 | return [w.get_int(0), h.get_int(0)] 80 | end 81 | 82 | 83 | 84 | func :zoomSurface, [ :pointer, :double, :double, :int ], 85 | SDL::Surface.typed_pointer 86 | 87 | 88 | func :__zoomSurfaceSize, :zoomSurfaceSize, 89 | [ :int, :int, :double, :double, :buffer_out, :buffer_out ], :void 90 | 91 | def self.zoomSurfaceSize( width, height, zoomx, zoomy ) 92 | w = FFI::Buffer.new( :int ) 93 | h = FFI::Buffer.new( :int ) 94 | __zoomSurfaceSize( width, height, zoomx, zoomy, w, h ) 95 | return [w.get_int(0), h.get_int(0)] 96 | end 97 | 98 | 99 | 100 | optfunc :shrinkSurface, [ :pointer, :int, :int ], 101 | SDL::Surface.typed_pointer 102 | 103 | 104 | optfunc :rotateSurface90Degrees, [ :pointer, :int ], 105 | SDL::Surface.typed_pointer 106 | 107 | end 108 | end 109 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/image.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | this_dir = File.expand_path( File.dirname(__FILE__) ) 32 | 33 | require File.join( this_dir, "sdl" ) 34 | 35 | 36 | module SDL 37 | module Image 38 | extend NiceFFI::Library 39 | load_library "SDL_image", SDL::LOAD_PATHS 40 | 41 | 42 | def self.img_func( name, args, ret ) 43 | func name, "IMG_#{name}", args, ret 44 | end 45 | 46 | 47 | img_func :Linked_Version, [], SDL::Version.typed_pointer 48 | 49 | 50 | img_func :LoadTyped_RW, [ :pointer, :int, :string ], 51 | SDL::Surface.typed_pointer 52 | 53 | img_func :Load, [ :string ], SDL::Surface.typed_pointer 54 | img_func :Load_RW, [ :pointer, :int ], SDL::Surface.typed_pointer 55 | 56 | 57 | img_func :InvertAlpha, [ :int ], :int 58 | 59 | 60 | img_func :isBMP, [ :pointer ], :int 61 | img_func :isGIF, [ :pointer ], :int 62 | img_func :isJPG, [ :pointer ], :int 63 | img_func :isLBM, [ :pointer ], :int 64 | img_func :isPCX, [ :pointer ], :int 65 | img_func :isPNG, [ :pointer ], :int 66 | img_func :isPNM, [ :pointer ], :int 67 | img_func :isTIF, [ :pointer ], :int 68 | img_func :isXCF, [ :pointer ], :int 69 | img_func :isXPM, [ :pointer ], :int 70 | img_func :isXV, [ :pointer ], :int 71 | 72 | 73 | img_func :LoadBMP_RW, [ :pointer ], SDL::Surface.typed_pointer 74 | img_func :LoadGIF_RW, [ :pointer ], SDL::Surface.typed_pointer 75 | img_func :LoadJPG_RW, [ :pointer ], SDL::Surface.typed_pointer 76 | img_func :LoadLBM_RW, [ :pointer ], SDL::Surface.typed_pointer 77 | img_func :LoadPCX_RW, [ :pointer ], SDL::Surface.typed_pointer 78 | img_func :LoadPNG_RW, [ :pointer ], SDL::Surface.typed_pointer 79 | img_func :LoadPNM_RW, [ :pointer ], SDL::Surface.typed_pointer 80 | img_func :LoadTGA_RW, [ :pointer ], SDL::Surface.typed_pointer 81 | img_func :LoadTIF_RW, [ :pointer ], SDL::Surface.typed_pointer 82 | img_func :LoadXCF_RW, [ :pointer ], SDL::Surface.typed_pointer 83 | img_func :LoadXPM_RW, [ :pointer ], SDL::Surface.typed_pointer 84 | img_func :LoadXV_RW, [ :pointer ], SDL::Surface.typed_pointer 85 | 86 | 87 | img_func :ReadXPMFromArray, [ :pointer ], SDL::Surface.typed_pointer 88 | 89 | end 90 | end 91 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/mixer.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | this_dir = File.expand_path( File.dirname(__FILE__) ) 32 | 33 | require File.join( this_dir, "sdl" ) 34 | 35 | 36 | module SDL 37 | module Mixer 38 | extend NiceFFI::Library 39 | load_library "SDL_mixer", SDL::LOAD_PATHS 40 | 41 | 42 | def self.mix_func( name, args, ret ) 43 | func name, "Mix_#{name}", args, ret 44 | end 45 | 46 | 47 | mix_func :Linked_Version, [], SDL::Version.typed_pointer 48 | 49 | 50 | CHANNELS = 8 51 | DEFAULT_FREQUENCY = 22050 52 | DEFAULT_CHANNELS = 2 53 | 54 | DEFAULT_FORMAT = if( FFI::Platform::BYTE_ORDER == 55 | FFI::Platform::LITTLE_ENDIAN) 56 | AUDIO_S16LSB 57 | else 58 | AUDIO_S16MSB 59 | end 60 | 61 | MAX_VOLUME = 128 62 | 63 | 64 | class Chunk < NiceFFI::Struct 65 | layout( :allocated, :int, 66 | :abuf, :pointer, 67 | :alen, :uint32, 68 | :volume, :uint8 ) 69 | 70 | def self.release( pointer ) 71 | SDL::Mixer.FreeChunk( pointer ) 72 | end 73 | end 74 | 75 | 76 | 77 | class Music < NiceFFI::OpaqueStruct 78 | #-- 79 | # Mix_Music struct (in C) has a hidden layout, which changes 80 | # depending on which sound format libraries were available 81 | # at compile time. 82 | #++ 83 | 84 | def self.release( pointer ) 85 | SDL::Mixer.FreeMusic( pointer ) 86 | end 87 | end 88 | 89 | 90 | 91 | NO_FADING = 0 92 | FADING_OUT = 1 93 | FADING_IN = 2 94 | 95 | MUS_NONE = 0 96 | MUS_CMD = 1 97 | MUS_WAV = 2 98 | MUS_MOD = 3 99 | MUS_MID = 4 100 | MUS_OGG = 5 101 | MUS_MP3 = 6 102 | MUS_MP3_MAD = 7 103 | 104 | 105 | mix_func :OpenAudio, [ :int, :uint16, :int, :int ], :int 106 | mix_func :AllocateChannels, [ :int ], :int 107 | mix_func :QuerySpec, [ :pointer, :pointer, :pointer ], :int 108 | 109 | 110 | def self.LoadWAV( file ) 111 | LoadWAV_RW( SDL.RWFromFile(file, "rb"), 1 ) 112 | end 113 | 114 | mix_func :LoadWAV_RW, [ :pointer, :int ], Chunk.typed_pointer 115 | mix_func :LoadMUS, [ :string ], Music.typed_pointer 116 | mix_func :LoadMUS_RW, [ :pointer ], Music.typed_pointer 117 | mix_func :QuickLoad_WAV, [ :pointer ], Chunk.typed_pointer 118 | mix_func :QuickLoad_RAW, [ :pointer, :uint32 ], Chunk.typed_pointer 119 | 120 | 121 | mix_func :FreeChunk, [ :pointer ], :void 122 | mix_func :FreeMusic, [ :pointer ], :void 123 | 124 | 125 | mix_func :GetMusicType, [ :pointer ], :int 126 | 127 | 128 | callback( :mix_hook_cb, [:pointer, :pointer, :int], :void) 129 | 130 | mix_func :SetPostMix, [ :mix_hook_cb, :pointer ], :void 131 | mix_func :HookMusic, [ :mix_hook_cb, :pointer ], :void 132 | mix_func :HookMusicFinished, [ callback([], :void) ], :void 133 | mix_func :GetMusicHookData, [ ], :pointer 134 | mix_func :ChannelFinished, [ callback([:int], :void) ], :void 135 | 136 | 137 | CHANNEL_POST = -2 138 | 139 | 140 | callback(:mix_effectfunc_cb, [ :int, :pointer, :int, :pointer ], :void) 141 | callback(:mix_effectdone_cb, [ :int, :pointer ], :void) 142 | 143 | mix_func :RegisterEffect, 144 | [ :int, :mix_effectfunc_cb, :mix_effectdone_cb, :pointer ], :int 145 | 146 | mix_func :UnregisterEffect, [ :int, :mix_effectfunc_cb ], :int 147 | mix_func :UnregisterAllEffects, [ :int ], :int 148 | 149 | 150 | EFFECTSMAXSPEED = "MIX_EFFECTSMAXSPEED" 151 | 152 | 153 | mix_func :SetPanning, [ :int, :uint8, :uint8 ], :int 154 | mix_func :SetPosition, [ :int, :int16, :uint8 ], :int 155 | mix_func :SetDistance, [ :int, :uint8 ], :int 156 | mix_func :SetReverseStereo, [ :int, :int ], :int 157 | 158 | 159 | mix_func :ReserveChannels, [ :int ], :int 160 | mix_func :GroupChannel, [ :int, :int ], :int 161 | mix_func :GroupChannels, [ :int, :int, :int ], :int 162 | mix_func :GroupAvailable, [ :int ], :int 163 | mix_func :GroupCount, [ :int ], :int 164 | mix_func :GroupOldest, [ :int ], :int 165 | mix_func :GroupNewer, [ :int ], :int 166 | 167 | 168 | mix_func :PlayChannelTimed, [ :int, :pointer, :int, :int ], :int 169 | mix_func :PlayMusic, [ :pointer, :int ], :int 170 | mix_func :FadeInMusic, [ :pointer, :int, :int ], :int 171 | mix_func :FadeInMusicPos, [ :pointer, :int, :int, :double ], :int 172 | mix_func :FadeInChannelTimed, [ :int, :pointer, :int, :int, :int ], :int 173 | 174 | 175 | mix_func :Volume, [ :int, :int ], :int 176 | mix_func :VolumeChunk, [ :pointer, :int ], :int 177 | mix_func :VolumeMusic, [ :int ], :int 178 | 179 | 180 | mix_func :HaltChannel, [ :int ], :int 181 | mix_func :HaltGroup, [ :int ], :int 182 | mix_func :HaltMusic, [ ], :int 183 | mix_func :ExpireChannel, [ :int, :int ], :int 184 | 185 | 186 | mix_func :FadeOutChannel, [ :int, :int ], :int 187 | mix_func :FadeOutGroup, [ :int, :int ], :int 188 | mix_func :FadeOutMusic, [ :int ], :int 189 | mix_func :FadingMusic, [ ], :int 190 | mix_func :FadingChannel, [ :int ], :int 191 | 192 | 193 | mix_func :Pause, [ :int ], :void 194 | mix_func :Resume, [ :int ], :void 195 | mix_func :Paused, [ :int ], :int 196 | mix_func :PauseMusic, [ ], :void 197 | mix_func :ResumeMusic, [ ], :void 198 | mix_func :RewindMusic, [ ], :void 199 | mix_func :PausedMusic, [ ], :int 200 | 201 | 202 | mix_func :SetMusicPosition, [ :double ], :int 203 | mix_func :Playing, [ :int ], :int 204 | mix_func :PlayingMusic, [ ], :int 205 | mix_func :SetMusicCMD, [ :string ], :int 206 | 207 | mix_func :SetSynchroValue, [ :int ], :int 208 | mix_func :GetSynchroValue, [ ], :int 209 | 210 | mix_func :GetChunk, [ :int ], Chunk.typed_pointer 211 | 212 | mix_func :CloseAudio, [ ], :void 213 | 214 | end 215 | end 216 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009, 2010 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | require 'nice-ffi' 32 | 33 | 34 | module SDL 35 | extend NiceFFI::Library 36 | 37 | unless defined? SDL::LOAD_PATHS 38 | SDL::LOAD_PATHS = NiceFFI::PathSet::DEFAULT.dup 39 | 40 | rubysdlffi_path = ENV["RUBYSDLFFI_PATH"] 41 | if rubysdlffi_path and not rubysdlffi_path.empty? 42 | paths = rubysdlffi_path.split( File::PATH_SEPARATOR ).compact 43 | SDL::LOAD_PATHS.prepend!(paths) 44 | end 45 | 46 | if defined? ::SDL_PATHS 47 | SDL::LOAD_PATHS.prepend!(::SDL_PATHS) 48 | end 49 | end 50 | 51 | load_library "SDL", SDL::LOAD_PATHS 52 | 53 | def self.sdl_func( name, args, ret ) 54 | func name, "SDL_#{name}", args, ret 55 | end 56 | 57 | end 58 | 59 | 60 | this_dir = File.expand_path( File.dirname(__FILE__) ) 61 | 62 | # NOTE: keyboard and video are deliberately loaded early, 63 | # because event and mouse depend on them, respectively. 64 | 65 | %w{ 66 | mac 67 | core 68 | keyboard 69 | video 70 | audio 71 | cdrom 72 | event 73 | joystick 74 | keysyms 75 | mouse 76 | mutex 77 | rwops 78 | timer 79 | }.each do |f| 80 | require File.join( this_dir, "sdl", f ) 81 | end 82 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/audio.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | class AudioSpec < NiceFFI::Struct 34 | 35 | SDL::callback(:audiospec_cb, [ :pointer, :pointer, :int ], :void) 36 | 37 | layout( :freq, :int, 38 | :format, :uint16, 39 | :channels, :uint8, 40 | :silence, :uint8, 41 | :samples, :uint16, 42 | :padding, :uint16, 43 | :size, :uint32, 44 | :callback, :audiospec_cb, 45 | :userdata, :pointer ) 46 | 47 | def callback=(cb) 48 | @callback = cb 49 | self[:callback] = @callback 50 | end 51 | 52 | def callback 53 | @callback 54 | end 55 | 56 | end 57 | 58 | 59 | AUDIO_U8 = 0x0008 60 | AUDIO_S8 = 0x8008 61 | AUDIO_U16LSB = 0x0010 62 | AUDIO_S16LSB = 0x8010 63 | AUDIO_U16MSB = 0x1010 64 | AUDIO_S16MSB = 0x9010 65 | AUDIO_U16 = 0x0010 66 | AUDIO_S16 = 0x8010 67 | 68 | if FFI::Platform::BYTE_ORDER == FFI::Platform::LITTLE_ENDIAN 69 | AUDIO_U16SYS = AUDIO_U16LSB 70 | AUDIO_S16SYS = AUDIO_S16LSB 71 | else 72 | AUDIO_U16SYS = AUDIO_U16MSB 73 | AUDIO_S16SYS = AUDIO_U16MSB 74 | end 75 | 76 | 77 | # callback( :filters_cb, [ :pointer, :uint16 ], :void) 78 | 79 | # class AudioCVT < NiceFFI::Struct 80 | # layout( :needed, :int, 81 | # :src_format, :uint16, 82 | # :dst_format, :uint16, 83 | # :rate_incr, :double, 84 | # :buf, :pointer, 85 | # :len, :int, 86 | # :len_cvt, :int, 87 | # :len_mult, :int, 88 | # :len_ratio, :double, 89 | # :filters, [:filters_cb, 10], 90 | # :filter_index, :int ) 91 | # end 92 | 93 | 94 | sdl_func :AudioInit, [ :string ], :int 95 | sdl_func :AudioQuit, [ ], :void 96 | sdl_func :OpenAudio, [ :buffer_in, :buffer_out ], :int 97 | 98 | 99 | func :__AudioDriverName, "SDL_AudioDriverName", 100 | [:buffer_out, :int], :pointer 101 | 102 | def self.AudioDriverName 103 | b = FFI::Buffer.new(:char, 1024) 104 | result = __AudioDriverName( b, 1024 ) 105 | if result.null? 106 | nil 107 | else 108 | b.get_string(0,1024) 109 | end 110 | end 111 | 112 | 113 | AUDIO_STOPPED = 0 114 | AUDIO_PLAYING = 1 115 | AUDIO_PAUSED = 2 116 | 117 | sdl_func :GetAudioStatus, [ ], SDL::ENUM 118 | sdl_func :PauseAudio, [ :int ], :void 119 | 120 | sdl_func :LoadWAV_RW, 121 | [ :pointer, :int, :pointer, :pointer, :pointer ], :pointer 122 | 123 | sdl_func :FreeWAV, [ :pointer ], :void 124 | 125 | sdl_func :BuildAudioCVT, 126 | [ :pointer, :uint16, :uint8, :int, :uint16, :uint8, :int ], :int 127 | 128 | sdl_func :ConvertAudio, [ :pointer ], :int 129 | 130 | 131 | MIX_MAXVOLUME = 128 132 | 133 | sdl_func :MixAudio, [ :pointer, :pointer, :uint32, :int ], :void 134 | 135 | sdl_func :LockAudio, [ ], :void 136 | sdl_func :UnlockAudio, [ ], :void 137 | sdl_func :CloseAudio, [ ], :void 138 | 139 | end 140 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/cdrom.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | CD_ERROR = -1 34 | CD_TRAYEMPTY = 0 35 | CD_STOPPED = 1 36 | CD_PLAYING = 2 37 | CD_PAUSED = 3 38 | 39 | AUDIO_TRACK = 0x00 40 | DATA_TRACK = 0x04 41 | 42 | MAX_TRACKS = 99 43 | 44 | class CDtrack < NiceFFI::Struct 45 | layout( :id, :uint8, 46 | :type, :uint8, 47 | :unused, :uint16, 48 | :length, :uint32, 49 | :offset, :uint32 ) 50 | 51 | hidden( :unused ) 52 | 53 | end 54 | 55 | 56 | if RUBY_PLATFORM =~ /java/ 57 | # 2009-10-21: JRuby FFI does not support arrays of structs in structs. 58 | # Attempting it can raise an un-rescuable NotImplementedError! :( 59 | puts "Warning: Skipping class SDL::CD due to JRuby limitations." 60 | else 61 | 62 | class CD < NiceFFI::Struct 63 | layout( :id, :int, 64 | :status, SDL::ENUM, 65 | :numtracks, :int, 66 | :cur_track, :int, 67 | :cur_frame, :int, 68 | :track, [CDtrack.by_value, SDL::MAX_TRACKS+1] ) 69 | end 70 | 71 | end 72 | 73 | CD_FPS = 75 74 | 75 | sdl_func :CDNumDrives, [ ], :int 76 | sdl_func :CDName, [ :int ], :string 77 | sdl_func :CDOpen, [ :int ], :pointer 78 | sdl_func :CDStatus, [ :pointer ], SDL::ENUM 79 | sdl_func :CDPlayTracks, [ :pointer, :int, :int, :int, :int ], :int 80 | sdl_func :CDPlay, [ :pointer, :int, :int ], :int 81 | sdl_func :CDPause, [ :pointer ], :int 82 | sdl_func :CDResume, [ :pointer ], :int 83 | sdl_func :CDStop, [ :pointer ], :int 84 | sdl_func :CDEject, [ :pointer ], :int 85 | sdl_func :CDClose, [ :pointer ], :void 86 | 87 | end 88 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/core.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | # Aliases for integer-like types 34 | ENUM = :int # :nodoc: 35 | BOOL = :int # :nodoc: 36 | GLATTR = :int # :nodoc: 37 | 38 | 39 | LIL_ENDIAN = 1234 40 | BIG_ENDIAN = 4321 41 | 42 | 43 | 44 | # SDL.h 45 | 46 | class Version < NiceFFI::Struct 47 | layout( :major, :uint8, 48 | :minor, :uint8, 49 | :patch, :uint8 ) 50 | end 51 | 52 | sdl_func :Linked_Version, [], Version.typed_pointer 53 | 54 | 55 | INIT_TIMER = 0x00000001 56 | INIT_AUDIO = 0x00000010 57 | INIT_VIDEO = 0x00000020 58 | INIT_CDROM = 0x00000100 59 | INIT_JOYSTICK = 0x00000200 60 | INIT_NOPARACHUTE = 0x00100000 61 | INIT_EVENTTHREAD = 0x01000000 62 | INIT_EVERYTHING = 0x0000FFFF 63 | 64 | sdl_func :Init, [ :uint32 ], :int 65 | sdl_func :InitSubSystem, [ :uint32 ], :int 66 | sdl_func :QuitSubSystem, [ :uint32 ], :void 67 | sdl_func :WasInit, [ :uint32 ], :uint32 68 | sdl_func :Quit, [ ], :void 69 | 70 | 71 | 72 | # SDL_active.h 73 | 74 | APPMOUSEFOCUS = 0x01 75 | APPINPUTFOCUS = 0x02 76 | APPACTIVE = 0x04 77 | 78 | sdl_func :GetAppState, [ ], :uint8 79 | 80 | 81 | 82 | # SDL_cpuinfo.h 83 | 84 | sdl_func :HasRDTSC, [ ], SDL::BOOL 85 | sdl_func :HasMMX, [ ], SDL::BOOL 86 | sdl_func :HasMMXExt, [ ], SDL::BOOL 87 | sdl_func :Has3DNow, [ ], SDL::BOOL 88 | sdl_func :Has3DNowExt, [ ], SDL::BOOL 89 | sdl_func :HasSSE, [ ], SDL::BOOL 90 | sdl_func :HasSSE2, [ ], SDL::BOOL 91 | sdl_func :HasAltiVec, [ ], SDL::BOOL 92 | 93 | 94 | 95 | # SDL_error.h 96 | 97 | sdl_func :SetError, [ :string, :varargs ], :void 98 | sdl_func :GetError, [ ], :string 99 | sdl_func :ClearError, [ ], :void 100 | 101 | ENOMEM = 0 102 | EFREAD = 1 103 | EFWRITE = 2 104 | EFSEEK = 3 105 | UNSUPPORTED = 4 106 | LASTERROR = 5 107 | 108 | sdl_func :Error, [ SDL::ENUM ], :void 109 | 110 | 111 | 112 | # SDL_loadso.h 113 | 114 | sdl_func :LoadObject, [ :string ], :pointer 115 | sdl_func :LoadFunction, [ :pointer, :string ], :pointer 116 | sdl_func :UnloadObject, [ :pointer ], :void 117 | 118 | 119 | 120 | # SDL_thread.h 121 | 122 | sdl_func :CreateThread, [ callback([:pointer], :int), :pointer ], :pointer 123 | 124 | sdl_func :ThreadID, [ ], :uint32 125 | sdl_func :GetThreadID, [ :pointer ], :uint32 126 | sdl_func :WaitThread, [ :pointer, :pointer ], :void 127 | sdl_func :KillThread, [ :pointer ], :void 128 | 129 | end 130 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/event.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | RELEASED = 0 34 | PRESSED = 1 35 | 36 | NOEVENT = 0 37 | ACTIVEEVENT = 1 38 | KEYDOWN = 2 39 | KEYUP = 3 40 | MOUSEMOTION = 4 41 | MOUSEBUTTONDOWN = 5 42 | MOUSEBUTTONUP = 6 43 | JOYAXISMOTION = 7 44 | JOYBALLMOTION = 8 45 | JOYHATMOTION = 9 46 | JOYBUTTONDOWN = 10 47 | JOYBUTTONUP = 11 48 | QUIT = 12 49 | SYSWMEVENT = 13 50 | EVENT_RESERVEDA = 14 51 | EVENT_RESERVEDB = 15 52 | VIDEORESIZE = 16 53 | VIDEOEXPOSE = 17 54 | EVENT_RESERVED2 = 18 55 | EVENT_RESERVED3 = 19 56 | EVENT_RESERVED4 = 20 57 | EVENT_RESERVED5 = 21 58 | EVENT_RESERVED6 = 22 59 | EVENT_RESERVED7 = 23 60 | USEREVENT = 24 61 | NUMEVENTS = 32 62 | 63 | 64 | ACTIVEEVENTMASK = (1 << (ACTIVEEVENT)) 65 | JOYAXISMOTIONMASK = (1 << (JOYAXISMOTION)) 66 | JOYEVENTMASK = (1 << (JOYAXISMOTION)) | \ 67 | (1 << (JOYBALLMOTION)) | \ 68 | (1 << (JOYHATMOTION)) | \ 69 | (1 << (JOYBUTTONDOWN)) | \ 70 | (1 << (JOYBUTTONUP)) 71 | JOYBALLMOTIONMASK = (1 << (JOYBALLMOTION)) 72 | JOYBUTTONDOWNMASK = (1 << (JOYBUTTONDOWN)) 73 | JOYBUTTONUPMASK = (1 << (JOYBUTTONUP)) 74 | JOYHATMOTIONMASK = (1 << (JOYHATMOTION)) 75 | KEYDOWNMASK = (1 << (KEYDOWN)) 76 | KEYEVENTMASK = (1 << (KEYDOWN))|(1 << (KEYUP)) 77 | KEYUPMASK = (1 << (KEYUP)) 78 | MOUSEBUTTONDOWNMASK = (1 << (MOUSEBUTTONDOWN)) 79 | MOUSEBUTTONUPMASK = (1 << (MOUSEBUTTONUP)) 80 | MOUSEMOTIONMASK = (1 << (MOUSEMOTION)) 81 | MOUSEEVENTMASK = (1 << (MOUSEMOTION)) | \ 82 | (1 << (MOUSEBUTTONDOWN)) | \ 83 | (1 << (MOUSEBUTTONUP)) 84 | QUITMASK = (1 << (QUIT)) 85 | SYSWMEVENTMASK = (1 << (SYSWMEVENT)) 86 | VIDEOEXPOSEMASK = (1 << (VIDEOEXPOSE)) 87 | VIDEORESIZEMASK = (1 << (VIDEORESIZE)) 88 | ALLEVENTS = 0xFFFFFFFF 89 | 90 | 91 | 92 | class ActiveEvent < NiceFFI::Struct 93 | layout( :type, :uint8, 94 | :gain, :uint8, 95 | :state, :uint8 ) 96 | end 97 | 98 | 99 | class KeyboardEvent < NiceFFI::Struct 100 | layout( :type, :uint8, 101 | :which, :uint8, 102 | :state, :uint8, 103 | :keysym, SDL::Keysym ) 104 | end 105 | 106 | 107 | class MouseMotionEvent < NiceFFI::Struct 108 | layout( :type, :uint8, 109 | :which, :uint8, 110 | :state, :uint8, 111 | :x, :uint16, 112 | :y, :uint16, 113 | :xrel, :int16, 114 | :yrel, :int16 ) 115 | end 116 | 117 | 118 | class MouseButtonEvent < NiceFFI::Struct 119 | layout( :type, :uint8, 120 | :which, :uint8, 121 | :button, :uint8, 122 | :state, :uint8, 123 | :x, :uint16, 124 | :y, :uint16 ) 125 | end 126 | 127 | 128 | class JoyAxisEvent < NiceFFI::Struct 129 | layout( :type, :uint8, 130 | :which, :uint8, 131 | :axis, :uint8, 132 | :value, :int16 ) 133 | end 134 | 135 | 136 | class JoyBallEvent < NiceFFI::Struct 137 | layout( :type, :uint8, 138 | :which, :uint8, 139 | :ball, :uint8, 140 | :xrel, :int16, 141 | :yrel, :int16 ) 142 | end 143 | 144 | 145 | class JoyHatEvent < NiceFFI::Struct 146 | layout( :type, :uint8, 147 | :which, :uint8, 148 | :hat, :uint8, 149 | :value, :uint8 ) 150 | end 151 | 152 | 153 | class JoyButtonEvent < NiceFFI::Struct 154 | layout( :type, :uint8, 155 | :which, :uint8, 156 | :button, :uint8, 157 | :state, :uint8 ) 158 | end 159 | 160 | 161 | class ResizeEvent < NiceFFI::Struct 162 | layout( :type, :uint8, 163 | :w, :int, 164 | :h, :int ) 165 | end 166 | 167 | 168 | class ExposeEvent < NiceFFI::Struct 169 | layout( :type, :uint8 ) 170 | end 171 | 172 | 173 | class QuitEvent < NiceFFI::Struct 174 | layout( :type, :uint8 ) 175 | end 176 | 177 | 178 | class UserEvent < NiceFFI::Struct 179 | layout( :type, :uint8, 180 | :code, :int, 181 | :data1, :pointer, 182 | :data2, :pointer ) 183 | end 184 | 185 | 186 | class SysWMEvent < NiceFFI::Struct 187 | layout( :type, :uint8, 188 | :msg, :pointer ) 189 | end 190 | 191 | 192 | class Event < FFI::Union 193 | layout( :type, :uint8, 194 | :active, SDL::ActiveEvent, 195 | :key, SDL::KeyboardEvent, 196 | :motion, SDL::MouseMotionEvent, 197 | :button, SDL::MouseButtonEvent, 198 | :jaxis, SDL::JoyAxisEvent, 199 | :jball, SDL::JoyBallEvent, 200 | :jhat, SDL::JoyHatEvent, 201 | :jbutton, SDL::JoyButtonEvent, 202 | :resize, SDL::ResizeEvent, 203 | :expose, SDL::ExposeEvent, 204 | :quit, SDL::QuitEvent, 205 | :user, SDL::UserEvent, 206 | :syswm, SDL::SysWMEvent ) 207 | 208 | 209 | # Creates a generic Event containing a specific event. 210 | # You usually don't need to do this, because you can pass 211 | # specific events directly to SDL::SDL_PushEvent. 212 | # 213 | def self.wrap( event ) 214 | self.new( event.pointer ) 215 | end 216 | 217 | 218 | # Extracts a specific event class from a generic Event. 219 | def unwrap 220 | case self[:type] 221 | when ACTIVEEVENT; ActiveEvent.new(self.pointer) 222 | when KEYDOWN, KEYUP; KeyboardEvent.new(self.pointer) 223 | when MOUSEMOTION; MouseMotionEvent.new(self.pointer) 224 | 225 | when MOUSEBUTTONDOWN, MOUSEBUTTONUP; 226 | MouseButtonEvent.new(self.pointer) 227 | 228 | when JOYAXISMOTION; JoyAxisEvent.new(self.pointer) 229 | when JOYBALLMOTION; JoyBallEvent.new(self.pointer) 230 | when JOYHATMOTION; JoyHatEvent.new(self.pointer) 231 | 232 | when JOYBUTTONDOWN, JOYBUTTONUP; 233 | JoyButtonEvent.new(self.pointer) 234 | 235 | when QUIT; QuitEvent.new( self.pointer ) 236 | when SYSWMEVENT; SysWMEvent.new( self.pointer ) 237 | when VIDEORESIZE; ResizeEvent.new( self.pointer ) 238 | when VIDEOEXPOSE; ExposeEvent.new( self.pointer ) 239 | when USEREVENT; UserEvent.new( self.pointer ) 240 | 241 | else; raise TypeError, "Invalid event #{self.inspect}" 242 | end 243 | end 244 | 245 | def inspect 246 | super.gsub(">", " :type=#{self[:type]}>") 247 | end 248 | 249 | end 250 | 251 | 252 | sdl_func :PumpEvents, [ ], :void 253 | 254 | 255 | ADDEVENT = 0 256 | PEEKEVENT = 1 257 | GETEVENT = 2 258 | 259 | func :__SDL_PeepEvents, "SDL_PeepEvents", 260 | [ :pointer, :int, SDL::ENUM, :uint32 ], :int 261 | 262 | 263 | # Behavior varies depending on action. 264 | # 265 | # PEEKEVENT or GETEVENT: 266 | # events is the max number of events to retrieve. 267 | # Returns an array of Events, or nil if there was an error. 268 | # GETEVENT removes them from the queue, PEEKEVENT leaves them. 269 | # 270 | # ADDEVENT: 271 | # events is an array of Events (or specific event instances) 272 | # to append to the queue. 273 | # Returns the number of events added, or -1 if there was an error. 274 | # 275 | def self.PeepEvents( events, action, mask ) 276 | # PeepEvents is very versatile, so we break it up into 277 | # different actions... 278 | 279 | case action 280 | 281 | # Append the given events to the queue, return number added. 282 | when ADDEVENT 283 | numevents = events.size 284 | mp = FFI::Buffer.new( SDL::Event, numevents ) 285 | 286 | # Dump the events into the Buffer as raw, hardcore bytes 287 | events.each_with_index do |ev, i| 288 | mp[i].put_bytes( 0, ev.pointer.get_bytes(0, ev.size) ) 289 | end 290 | 291 | return __SDL_PeepEvents( mp, numevents, action, mask ) 292 | 293 | # Peek or Get the first N events and return them in an array. 294 | # Peek does not remove them from the queue, but Get does. 295 | when PEEKEVENT, GETEVENT 296 | numevents = events.to_i 297 | mp = FFI::Buffer.new( SDL::Event, numevents ) 298 | n = __SDL_PeepEvents( mp, numevents, action, mask ) 299 | 300 | # Something went wrong 301 | return nil if( n == -1 ) 302 | 303 | events = [] 304 | n.times do |i| 305 | events << Event.new( mp[i] ).unwrap 306 | end 307 | 308 | return events 309 | end 310 | end 311 | 312 | 313 | func :__SDL_PollEvent, "SDL_PollEvent", [ :buffer_out ], :int 314 | 315 | def self.PollEvent() 316 | mp = FFI::Buffer.new( SDL::Event, 1 ) 317 | n = __SDL_PollEvent( mp ) 318 | if n == 0 319 | nil 320 | else 321 | Event.new(mp).unwrap 322 | end 323 | end 324 | 325 | 326 | func :__SDL_WaitEvent, "SDL_WaitEvent", [ :buffer_out ], :int 327 | 328 | def self.WaitEvent() 329 | mp = FFI::Buffer.new( SDL::Event, 1 ) 330 | n = __SDL_WaitEvent( mp ) 331 | if n == 0 332 | nil 333 | else 334 | Event.new(mp).unwrap 335 | end 336 | end 337 | 338 | 339 | sdl_func :PushEvent, [ :buffer_in ], :int 340 | 341 | 342 | 343 | callback(:eventfilter_cb, [ :buffer_out ], :int) 344 | 345 | func :__SDL_SetEventFilter, "SDL_SetEventFilter", 346 | [ :eventfilter_cb ], :void 347 | 348 | def self.SetEventFilter( &block ) 349 | if( block_given? ) 350 | proc = Proc.new { |ev| 351 | result = block.call( Event.new(ev).unwrap ) 352 | case result 353 | when true; 1 354 | when false, nil; 0 355 | else; result 356 | end 357 | } 358 | __SDL_SetEventFilter( proc ) 359 | else 360 | __SDL_SetEventFilter( nil ) 361 | end 362 | end 363 | 364 | 365 | #sdl_func :GetEventFilter, [ ], :eventfilter_cb 366 | 367 | 368 | QUERY = -1 369 | IGNORE = 0 370 | DISABLE = 0 371 | ENABLE = 1 372 | 373 | sdl_func :EventState, [ :uint8, :int ], :uint8 374 | 375 | end 376 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/joystick.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | class Joystick < NiceFFI::OpaqueStruct 34 | #-- 35 | # SDL_Joystick struct (in C) has a hidden layout. 36 | #++ 37 | end 38 | 39 | 40 | sdl_func :NumJoysticks, [ ], :int 41 | sdl_func :JoystickName, [ :int ], :string 42 | sdl_func :JoystickOpen, [ :int ], Joystick.typed_pointer 43 | sdl_func :JoystickOpened, [ :int ], :int 44 | sdl_func :JoystickIndex, [ :pointer ], :int 45 | 46 | sdl_func :JoystickNumAxes, [ :pointer ], :int 47 | sdl_func :JoystickNumBalls, [ :pointer ], :int 48 | sdl_func :JoystickNumHats, [ :pointer ], :int 49 | sdl_func :JoystickNumButtons, [ :pointer ], :int 50 | 51 | sdl_func :JoystickUpdate, [ ], :void 52 | sdl_func :JoystickEventState, [ :int ], :int 53 | sdl_func :JoystickGetAxis, [ :pointer, :int ], :int16 54 | 55 | 56 | HAT_CENTERED = 0x00 57 | HAT_UP = 0x01 58 | HAT_RIGHT = 0x02 59 | HAT_DOWN = 0x04 60 | HAT_LEFT = 0x08 61 | HAT_RIGHTUP = (HAT_RIGHT|HAT_UP) 62 | HAT_RIGHTDOWN = (HAT_RIGHT|HAT_DOWN) 63 | HAT_LEFTUP = (HAT_LEFT |HAT_UP) 64 | HAT_LEFTDOWN = (HAT_LEFT |HAT_DOWN) 65 | 66 | 67 | sdl_func :JoystickGetHat, [ :pointer, :int ], :uint8 68 | sdl_func :JoystickGetBall, [ :pointer, :int, :pointer, :pointer ], :int 69 | sdl_func :JoystickGetButton, [ :pointer, :int ], :uint8 70 | 71 | sdl_func :JoystickClose, [ :pointer ], :void 72 | 73 | end 74 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/keyboard.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | class Keysym < NiceFFI::Struct 34 | layout( :scancode, :uint8, 35 | :sym, SDL::ENUM, 36 | :mod, SDL::ENUM, 37 | :unicode, :uint16 ) 38 | end 39 | 40 | ALL_HOTKEYS = 0xFFFFFFFF 41 | 42 | 43 | sdl_func :EnableUNICODE, [ :int ], :int 44 | 45 | 46 | DEFAULT_REPEAT_DELAY = 500 47 | DEFAULT_REPEAT_INTERVAL = 30 48 | 49 | sdl_func :EnableKeyRepeat, [ :int, :int ], :int 50 | 51 | 52 | func :__SDL_GetKeyRepeat, "SDL_GetKeyRepeat", 53 | [ :buffer_out, :buffer_out ], :void 54 | 55 | def self.GetKeyRepeat() 56 | delay = FFI::Buffer.new( :int ) 57 | interval = FFI::Buffer.new( :int ) 58 | __SDL_GetKeyRepeat( delay, interval ) 59 | return [delay.get_int(0), interval.get_int(0)] 60 | end 61 | 62 | 63 | func :__SDL_GetKeyState, "SDL_GetKeyState", [ :buffer_out ], :pointer 64 | 65 | def self.GetKeyState() 66 | numkeys = FFI::Buffer.new( :int ) 67 | keys = __SDL_GetKeyState( numkeys ) 68 | return keys.get_array_of_uint8( 0, numkeys.get_int(0) ) 69 | end 70 | 71 | 72 | sdl_func :GetModState, [ ], SDL::ENUM 73 | sdl_func :SetModState, [ SDL::ENUM ], :void 74 | sdl_func :GetKeyName, [ SDL::ENUM ], :string 75 | 76 | end 77 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/keysyms.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | K_FIRST = 0 34 | K_UNKNOWN = 0 35 | K_BACKSPACE = 8 36 | K_TAB = 9 37 | K_CLEAR = 12 38 | K_RETURN = 13 39 | K_PAUSE = 19 40 | K_ESCAPE = 27 41 | K_SPACE = 32 42 | K_EXCLAIM = 33 43 | K_QUOTEDBL = 34 44 | K_HASH = 35 45 | K_DOLLAR = 36 46 | K_AMPERSAND = 38 47 | K_QUOTE = 39 48 | K_LEFTPAREN = 40 49 | K_RIGHTPAREN = 41 50 | K_ASTERISK = 42 51 | K_PLUS = 43 52 | K_COMMA = 44 53 | K_MINUS = 45 54 | K_PERIOD = 46 55 | K_SLASH = 47 56 | K_0 = 48 57 | K_1 = 49 58 | K_2 = 50 59 | K_3 = 51 60 | K_4 = 52 61 | K_5 = 53 62 | K_6 = 54 63 | K_7 = 55 64 | K_8 = 56 65 | K_9 = 57 66 | K_COLON = 58 67 | K_SEMICOLON = 59 68 | K_LESS = 60 69 | K_EQUALS = 61 70 | K_GREATER = 62 71 | K_QUESTION = 63 72 | K_AT = 64 73 | K_LEFTBRACKET = 91 74 | K_BACKSLASH = 92 75 | K_RIGHTBRACKET = 93 76 | K_CARET = 94 77 | K_UNDERSCORE = 95 78 | K_BACKQUOTE = 96 79 | K_a = 97 80 | K_b = 98 81 | K_c = 99 82 | K_d = 100 83 | K_e = 101 84 | K_f = 102 85 | K_g = 103 86 | K_h = 104 87 | K_i = 105 88 | K_j = 106 89 | K_k = 107 90 | K_l = 108 91 | K_m = 109 92 | K_n = 110 93 | K_o = 111 94 | K_p = 112 95 | K_q = 113 96 | K_r = 114 97 | K_s = 115 98 | K_t = 116 99 | K_u = 117 100 | K_v = 118 101 | K_w = 119 102 | K_x = 120 103 | K_y = 121 104 | K_z = 122 105 | K_DELETE = 127 106 | K_WORLD_0 = 160 107 | K_WORLD_1 = 161 108 | K_WORLD_2 = 162 109 | K_WORLD_3 = 163 110 | K_WORLD_4 = 164 111 | K_WORLD_5 = 165 112 | K_WORLD_6 = 166 113 | K_WORLD_7 = 167 114 | K_WORLD_8 = 168 115 | K_WORLD_9 = 169 116 | K_WORLD_10 = 170 117 | K_WORLD_11 = 171 118 | K_WORLD_12 = 172 119 | K_WORLD_13 = 173 120 | K_WORLD_14 = 174 121 | K_WORLD_15 = 175 122 | K_WORLD_16 = 176 123 | K_WORLD_17 = 177 124 | K_WORLD_18 = 178 125 | K_WORLD_19 = 179 126 | K_WORLD_20 = 180 127 | K_WORLD_21 = 181 128 | K_WORLD_22 = 182 129 | K_WORLD_23 = 183 130 | K_WORLD_24 = 184 131 | K_WORLD_25 = 185 132 | K_WORLD_26 = 186 133 | K_WORLD_27 = 187 134 | K_WORLD_28 = 188 135 | K_WORLD_29 = 189 136 | K_WORLD_30 = 190 137 | K_WORLD_31 = 191 138 | K_WORLD_32 = 192 139 | K_WORLD_33 = 193 140 | K_WORLD_34 = 194 141 | K_WORLD_35 = 195 142 | K_WORLD_36 = 196 143 | K_WORLD_37 = 197 144 | K_WORLD_38 = 198 145 | K_WORLD_39 = 199 146 | K_WORLD_40 = 200 147 | K_WORLD_41 = 201 148 | K_WORLD_42 = 202 149 | K_WORLD_43 = 203 150 | K_WORLD_44 = 204 151 | K_WORLD_45 = 205 152 | K_WORLD_46 = 206 153 | K_WORLD_47 = 207 154 | K_WORLD_48 = 208 155 | K_WORLD_49 = 209 156 | K_WORLD_50 = 210 157 | K_WORLD_51 = 211 158 | K_WORLD_52 = 212 159 | K_WORLD_53 = 213 160 | K_WORLD_54 = 214 161 | K_WORLD_55 = 215 162 | K_WORLD_56 = 216 163 | K_WORLD_57 = 217 164 | K_WORLD_58 = 218 165 | K_WORLD_59 = 219 166 | K_WORLD_60 = 220 167 | K_WORLD_61 = 221 168 | K_WORLD_62 = 222 169 | K_WORLD_63 = 223 170 | K_WORLD_64 = 224 171 | K_WORLD_65 = 225 172 | K_WORLD_66 = 226 173 | K_WORLD_67 = 227 174 | K_WORLD_68 = 228 175 | K_WORLD_69 = 229 176 | K_WORLD_70 = 230 177 | K_WORLD_71 = 231 178 | K_WORLD_72 = 232 179 | K_WORLD_73 = 233 180 | K_WORLD_74 = 234 181 | K_WORLD_75 = 235 182 | K_WORLD_76 = 236 183 | K_WORLD_77 = 237 184 | K_WORLD_78 = 238 185 | K_WORLD_79 = 239 186 | K_WORLD_80 = 240 187 | K_WORLD_81 = 241 188 | K_WORLD_82 = 242 189 | K_WORLD_83 = 243 190 | K_WORLD_84 = 244 191 | K_WORLD_85 = 245 192 | K_WORLD_86 = 246 193 | K_WORLD_87 = 247 194 | K_WORLD_88 = 248 195 | K_WORLD_89 = 249 196 | K_WORLD_90 = 250 197 | K_WORLD_91 = 251 198 | K_WORLD_92 = 252 199 | K_WORLD_93 = 253 200 | K_WORLD_94 = 254 201 | K_WORLD_95 = 255 202 | K_KP0 = 256 203 | K_KP1 = 257 204 | K_KP2 = 258 205 | K_KP3 = 259 206 | K_KP4 = 260 207 | K_KP5 = 261 208 | K_KP6 = 262 209 | K_KP7 = 263 210 | K_KP8 = 264 211 | K_KP9 = 265 212 | K_KP_PERIOD = 266 213 | K_KP_DIVIDE = 267 214 | K_KP_MULTIPLY = 268 215 | K_KP_MINUS = 269 216 | K_KP_PLUS = 270 217 | K_KP_ENTER = 271 218 | K_KP_EQUALS = 272 219 | K_UP = 273 220 | K_DOWN = 274 221 | K_RIGHT = 275 222 | K_LEFT = 276 223 | K_INSERT = 277 224 | K_HOME = 278 225 | K_END = 279 226 | K_PAGEUP = 280 227 | K_PAGEDOWN = 281 228 | K_F1 = 282 229 | K_F2 = 283 230 | K_F3 = 284 231 | K_F4 = 285 232 | K_F5 = 286 233 | K_F6 = 287 234 | K_F7 = 288 235 | K_F8 = 289 236 | K_F9 = 290 237 | K_F10 = 291 238 | K_F11 = 292 239 | K_F12 = 293 240 | K_F13 = 294 241 | K_F14 = 295 242 | K_F15 = 296 243 | K_NUMLOCK = 300 244 | K_CAPSLOCK = 301 245 | K_SCROLLOCK = 302 246 | K_RSHIFT = 303 247 | K_LSHIFT = 304 248 | K_RCTRL = 305 249 | K_LCTRL = 306 250 | K_RALT = 307 251 | K_LALT = 308 252 | K_RMETA = 309 253 | K_LMETA = 310 254 | K_LSUPER = 311 255 | K_RSUPER = 312 256 | K_MODE = 313 257 | K_COMPOSE = 314 258 | K_HELP = 315 259 | K_PRINT = 316 260 | K_SYSREQ = 317 261 | K_BREAK = 318 262 | K_MENU = 319 263 | K_POWER = 320 264 | K_EURO = 321 265 | K_UNDO = 322 266 | K_LAST = 323 267 | 268 | KMOD_NONE = 0x0000 269 | KMOD_LSHIFT = 0x0001 270 | KMOD_RSHIFT = 0x0002 271 | KMOD_LCTRL = 0x0040 272 | KMOD_RCTRL = 0x0080 273 | KMOD_LALT = 0x0100 274 | KMOD_RALT = 0x0200 275 | KMOD_LMETA = 0x0400 276 | KMOD_RMETA = 0x0800 277 | KMOD_NUM = 0x1000 278 | KMOD_CAPS = 0x2000 279 | KMOD_MODE = 0x4000 280 | KMOD_RESERVED = 0x8000 281 | 282 | end 283 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/mac.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2010 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | # 29 | # Contributions: 30 | # 31 | # - Bart Leusink, 2011-01-22: 32 | # Fixed the display window not gaining focus on Mac OS X 10.6. 33 | # 34 | #++ 35 | 36 | #-- 37 | # Some bindings to Mac OS X system framework to allow Ruby-SDL-FFI 38 | # to create a window on Mac without a special Ruby interpreter (rsdl). 39 | # These are for internal use only. They are NOT part of the API. 40 | # 41 | # Eternal thanks to erisdiscord and jlnr for pointing the way! 42 | 43 | 44 | # Only define this stuff if running on a Mac and not using rsdl and 45 | # the RUBYSDLFFI_NOCOCOA environment variable is not true-ish. 46 | if FFI::Platform.mac? and ($0 != "rsdl") and \ 47 | not (/^(1|t|true|y|yes)$/i =~ ENV["RUBYSDLFFI_NOCOCOA"]) 48 | 49 | module SDL::Mac 50 | 51 | class << self 52 | 53 | def make_menus( app_name ) 54 | ptr = FFI.find_type(:pointer) 55 | 56 | nsapp = Cocoa.NSApp 57 | menubar = Cocoa::NSMenu.new.initWithTitle("AMainMenu") 58 | nsapp.msg( "setMainMenu:", ptr, menubar ) 59 | 60 | remove_bold_menu( nsapp, menubar ) 61 | make_app_menu( menubar, app_name ) 62 | make_window_menu( nsapp, menubar ) 63 | 64 | nil 65 | end 66 | 67 | 68 | def set_app_name( app_name ) 69 | ptr = FFI.find_type(:pointer) 70 | 71 | if @appmenuitem 72 | @appmenuitem.title = app_name 73 | @hideitem.title = "Hide #{app_name}" if @hideitem 74 | @quititem.title = "Quit #{app_name}" if @quititem 75 | else 76 | make_menus( app_name ) 77 | end 78 | 79 | nil 80 | end 81 | 82 | 83 | private 84 | 85 | # Hack to remove the bold "ruby" menu (aka the "Apple" menu). 86 | # It's a ghost menu, it haunts us but can't be modified. 87 | def remove_bold_menu( nsapp, menubar ) 88 | item = Cocoa::NSMenuItem.new.initWithTitle("AppleMenu") 89 | menu = Cocoa::NSMenu.new.initWithTitle("AppleMenu") 90 | item.submenu = menu 91 | 92 | nsapp.msg("setAppleMenu:", FFI.find_type(:pointer), menu) 93 | menubar.addItem(item) 94 | menubar.removeItem(item) 95 | 96 | item.release 97 | menu.release 98 | end 99 | 100 | 101 | # Create the main menu with the app's name (Hide, Quit, etc.) 102 | def make_app_menu( menubar, app_name ) 103 | item = Cocoa::NSMenuItem.new.initWithTitle( app_name ) 104 | menu = Cocoa::NSMenu.new.initWithTitle( app_name ) 105 | item.submenu = menu 106 | menubar.addItem(item) 107 | 108 | @hideitem = menu.addItemWithTitle("Hide #{app_name}", "hide:") 109 | menu.addItemWithTitle("Hide Others", "hideOtherApplications:") 110 | menu.addItemWithTitle("Show All", "unhideAllApplications:") 111 | 112 | # Can't get the Quit menu item to work right yet. 113 | # menu.addItem( Cocoa::NSMenuItem.separatorItem ) 114 | # @quititem = menu.addItemWithTitle("Quit #{app_name}", "terminate:") 115 | 116 | @appmenuitem = item 117 | menu.release 118 | end 119 | 120 | 121 | # Create the "Window" menu (Minimize, etc.) 122 | def make_window_menu( nsapp, menubar ) 123 | ptr = FFI.find_type(:pointer) 124 | 125 | item = Cocoa::NSMenuItem.new.initWithTitle("Window") 126 | menu = Cocoa::NSMenu.new.initWithTitle("Window") 127 | item.submenu = menu 128 | menubar.addItem(item) 129 | nsapp.msg("setWindowsMenu:", ptr, menu) 130 | 131 | menu.addItemWithTitle("Minimize", "performMiniaturize:") 132 | 133 | item.release 134 | menu.release 135 | end 136 | 137 | 138 | def inspect_menu( menu, indent="" ) 139 | puts "%s-%s (%s \"%s\", %d items)"%[indent, menu, menu.classname, 140 | menu.title, menu.length] 141 | menu.each do |ob| 142 | if ob.hasSubmenu? 143 | inspect_menu( ob.submenu, indent+" " ) 144 | else 145 | puts "%s -%s (%s \"%s\")"%[indent, ob, ob.classname, ob.title] 146 | end 147 | end 148 | end 149 | 150 | end 151 | 152 | 153 | module ObjC 154 | extend NiceFFI::Library 155 | load_library 'objc' 156 | 157 | typedef :pointer, :id 158 | typedef :pointer, :sel 159 | typedef :pointer, :ivar 160 | typedef :pointer, :nsclass 161 | callback :imp, [:id, :sel, :varargs], :id 162 | 163 | 164 | class NSObject < NiceFFI::OpaqueStruct 165 | def self.nsclassname; name.split("::")[-1]; end 166 | 167 | # define msg, msg_ptr, msg_str, msg_int, msg_bool (and class methods) 168 | ["", "_ptr", "_str", "_int", "_bool"].each do |suffix| 169 | module_eval(" 170 | def msg#{suffix}( message, *args ) 171 | ObjC.msgSend#{suffix}( @pointer, message, *args ) 172 | end 173 | 174 | def self.msg#{suffix}( message, *args ) 175 | ObjC.msgSend#{suffix}( ObjC.NSClass(self.nsclassname), 176 | message, *args ) 177 | end") 178 | end 179 | 180 | def inspect; msg_str("description").to_s; end 181 | def nsclassname; ObjC.object_getClassName(@pointer); end 182 | def release; msg("release"); end 183 | end 184 | 185 | def self.NSObject( *args ) 186 | NSObject.new( *args ) 187 | end 188 | 189 | 190 | class NSClass < NSObject 191 | def initialize( str_or_ptr ) 192 | if str_or_ptr.is_a? String 193 | super( ObjC.getClass(str_or_ptr) ) 194 | else 195 | super 196 | end 197 | end 198 | end 199 | 200 | def self.NSClass( *args ) 201 | NSClass.new( *args ) 202 | end 203 | 204 | 205 | class NSString < NSObject 206 | def initialize( str_or_ptr ) 207 | if str_or_ptr.is_a? String 208 | super( ObjC::NSClass("NSString").\ 209 | msg_ptr("stringWithUTF8String:", 210 | FFI.find_type(:string), str_or_ptr) ) 211 | else 212 | super 213 | end 214 | end 215 | 216 | def to_s 217 | str = msg_ptr( "UTF8String" ) 218 | (str.null?) ? "(NULL)" : str.read_string() 219 | end 220 | end 221 | 222 | def self.NSString( *args ) 223 | NSString.new( *args ) 224 | end 225 | 226 | 227 | func :__msgSend, :objc_msgSend, [:id, :sel, :varargs], :id 228 | func :__msgSend_int, :objc_msgSend, [:id, :sel, :varargs], :long 229 | 230 | def self.msgSend( id, selector, *args ) 231 | selector = self.sel(selector) if selector.is_a? String 232 | NSObject.new( __msgSend( id, selector, *args ) ) 233 | end 234 | def self.msgSend_ptr( id, selector, *args ) 235 | selector = self.sel(selector) if selector.is_a? String 236 | __msgSend( id, selector, *args ) 237 | end 238 | def self.msgSend_str( id, selector, *args ) 239 | selector = self.sel(selector) if selector.is_a? String 240 | NSString.new( __msgSend( id, selector, *args ) ) 241 | end 242 | def self.msgSend_int( id, selector, *args ) 243 | selector = self.sel(selector) if selector.is_a? String 244 | __msgSend_int( id, selector, *args ) 245 | end 246 | def self.msgSend_bool( id, selector, *args ) 247 | selector = self.sel(selector) if selector.is_a? String 248 | ( __msgSend_int( id, selector, *args ) == 0 ) ? false : true 249 | end 250 | 251 | func :getClass, :objc_getClass, [:string], :id 252 | func :class_replaceMethod, [:nsclass, :sel, :imp, :string], :imp 253 | 254 | func :object_getClassName, [:id], :string 255 | func :object_getInstanceVariable, [:id, :string, :pointer], :ivar 256 | func :object_setInstanceVariable, [:id, :string, :pointer], :ivar 257 | 258 | func :sel_registerName, [:string], :sel 259 | func :sel_getName, [:sel], :string 260 | 261 | def self.sel( name ) 262 | sel_registerName( name.to_s ) 263 | end 264 | 265 | end 266 | 267 | 268 | module Cocoa 269 | extend NiceFFI::Library 270 | load_library '/System/Library/Frameworks/Cocoa.framework/Cocoa' 271 | 272 | func :NSApplicationLoad, [], :bool 273 | 274 | func :NSPushAutoreleasePool, [], :void 275 | func :NSPopAutoreleasePool, [], :void 276 | 277 | NSApplicationLoad() 278 | NSPushAutoreleasePool() 279 | 280 | def self.NSApp 281 | @nsapp ||= ObjC::NSClass("NSApplication").msg("sharedApplication") 282 | end 283 | 284 | class NSMenu < ObjC::NSObject 285 | include Enumerable 286 | 287 | def initialize( *args ) 288 | if args.empty? 289 | super( ObjC::NSClass("NSMenu").msg_ptr("alloc") ) 290 | else 291 | super( args[0] ) 292 | end 293 | end 294 | 295 | def initWithTitle( title ) 296 | msg( "initWithTitle:", FFI.find_type(:pointer), ObjC::NSString(title) ) 297 | self 298 | end 299 | 300 | def title 301 | msg_str("title") 302 | end 303 | 304 | def title=( t ) 305 | msg("setTitle:", FFI.find_type(:pointer), ObjC::NSString(t)) 306 | end 307 | 308 | def addItem( item ) 309 | msg("addItem:", FFI.find_type(:pointer), item) 310 | self 311 | end 312 | 313 | def addItemWithTitle( title, action=nil, keyEquivalent="" ) 314 | ptr = FFI.find_type(:pointer) 315 | action = ObjC.sel(action) if action.is_a? String 316 | item = msg_ptr( "addItemWithTitle:action:keyEquivalent:", 317 | ptr, ObjC::NSString(title), 318 | ptr, action, 319 | ptr, ObjC::NSString(keyEquivalent)) 320 | NSMenuItem.new(item) 321 | end 322 | 323 | def removeItem( item ) 324 | msg("removeItem:", FFI.find_type(:pointer), item) 325 | self 326 | end 327 | 328 | def removeItemAtIndex( index ) 329 | msg("removeItemAtIndex:", FFI.find_type(:long), index) 330 | self 331 | end 332 | 333 | def length 334 | msg_int( "numberOfItems" ) 335 | end 336 | 337 | def [](index) 338 | Cocoa::NSMenuItem( msg_ptr("itemAtIndex:", FFI.find_type(:long), index) ) 339 | end 340 | 341 | def each 342 | length.times{ |i| yield self[i] } 343 | end 344 | end 345 | 346 | def self.NSMenu( *args ) 347 | NSMenu.new( *args ) 348 | end 349 | 350 | 351 | class NSMenuItem < ObjC::NSObject 352 | def self.separatorItem 353 | new( msg_ptr("separatorItem") ) 354 | end 355 | 356 | def initialize( *args ) 357 | if args.empty? 358 | super( ObjC::NSClass("NSMenuItem").msg_ptr("alloc") ) 359 | else 360 | super( args[0] ) 361 | end 362 | end 363 | 364 | def initWithTitle( title, action=nil, keyEquivalent="" ) 365 | ptr = FFI.find_type(:pointer) 366 | action = ObjC.sel(action) if action.is_a? String 367 | msg( "initWithTitle:action:keyEquivalent:", 368 | ptr, ObjC::NSString(title), 369 | ptr, action, 370 | ptr, ObjC::NSString(keyEquivalent)) 371 | self 372 | end 373 | 374 | def title 375 | msg_str("title") 376 | end 377 | 378 | def title=( t ) 379 | msg("setTitle:", FFI.find_type(:pointer), ObjC::NSString(t)) 380 | end 381 | 382 | def hasSubmenu? 383 | msg_bool("hasSubmenu") 384 | end 385 | 386 | def submenu 387 | Cocoa::NSMenu( msg_ptr("submenu") ) if hasSubmenu? 388 | end 389 | 390 | def submenu=( menu ) 391 | msg("setSubmenu:", FFI.find_type(:pointer), menu) 392 | end 393 | end 394 | 395 | def self.NSMenuItem( *args ) 396 | NSMenuItem.new( *args ) 397 | end 398 | 399 | 400 | attach_variable "vNSNibOwner", "NSNibOwner", :pointer 401 | NSNibOwner = 402 | ObjC::NSString( ObjC::NSString(self.vNSNibOwner).to_s ) 403 | 404 | attach_variable "vNSNibTopLevelObjects", "NSNibTopLevelObjects", :pointer 405 | NSNibTopLevelObjects = 406 | ObjC::NSString( ObjC::NSString(self.vNSNibTopLevelObjects).to_s ) 407 | 408 | NSAlphaShiftKeyMask = 1 << 16 409 | NSShiftKeyMask = 1 << 17 410 | NSControlKeyMask = 1 << 18 411 | NSAlternateKeyMask = 1 << 19 412 | NSCommandKeyMask = 1 << 20 413 | NSNumericPadKeyMask = 1 << 21 414 | NSHelpKeyMask = 1 << 22 415 | NSFunctionKeyMask = 1 << 23 416 | end 417 | 418 | 419 | module HIServices 420 | extend NiceFFI::Library 421 | load_library '/System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/HIServices' 422 | 423 | class ProcessSerialNumber < NiceFFI::Struct 424 | layout :highLongOfPSN, :ulong, :lowLongOfPSN, :ulong 425 | end 426 | 427 | KProcessTransformToForegroundApplication = 1 428 | 429 | func :GetCurrentProcess, [:pointer], :long 430 | func :TransformProcessType, [:pointer, :long], :long 431 | func :SetFrontProcess, [:pointer], :long 432 | 433 | # Does the magic to make the current process a front process. 434 | def self.make_current_front 435 | current = ProcessSerialNumber.new( [0, 0] ) 436 | GetCurrentProcess( current ) 437 | TransformProcessType(current,KProcessTransformToForegroundApplication) 438 | SetFrontProcess( current ) 439 | end 440 | end 441 | 442 | end 443 | end 444 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/mouse.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | if RUBY_PLATFORM =~ /java/ 34 | # 2009-10-21: JRuby FFI does not support pointer arrays in structs. 35 | # Attempting it can raise an un-rescuable NotImplementedError! :( 36 | puts "Warning: Skipping class SDL::Cursor due to JRuby limitations." 37 | else 38 | 39 | class Cursor < NiceFFI::Struct 40 | layout( :area, SDL::Rect, 41 | :hot_x, :int16, 42 | :hot_y, :int16, 43 | :data, :pointer, 44 | :mask, :pointer, 45 | :save, [:pointer, 2], 46 | :wm_cursor, :pointer ) 47 | end 48 | 49 | end 50 | 51 | func :__SDL_GetMouseState, "SDL_GetMouseState", 52 | [ :buffer_out, :buffer_out ], :uint8 53 | 54 | # Returns [buttons, x, y]. 55 | # buttons: buttons currently pressed (bitmask of BUTTON_*MASK constants). 56 | # x, y: current position of the mouse cursor. 57 | def self.GetMouseState() 58 | xmp = FFI::Buffer.new( :int ) 59 | ymp = FFI::Buffer.new( :int ) 60 | buttons = __SDL_GetMouseState( xmp, ymp ) 61 | return [buttons, xmp.get_int(0), ymp.get_int(0)] 62 | end 63 | 64 | 65 | func :__SDL_GetRelativeMouseState, "SDL_GetRelativeMouseState", 66 | [ :buffer_out, :buffer_out ], :uint8 67 | 68 | # Returns [buttons, x, y]. 69 | # buttons: buttons currently pressed (bitmask of BUTTON_*MASK constants). 70 | # x, y: movement of the mouse cursor since last call of this method. 71 | # 72 | def self.GetRelativeMouseState() 73 | xmp = FFI::Buffer.new( :int ) 74 | ymp = FFI::Buffer.new( :int ) 75 | buttons = __SDL_GetRelativeMouseState( xmp, ymp ) 76 | return [buttons, xmp.get_int(0), ymp.get_int(0)] 77 | end 78 | 79 | 80 | sdl_func :WarpMouse, [ :uint16, :uint16 ], :void 81 | 82 | 83 | sdl_func :CreateCursor, 84 | [ :pointer, :pointer, :int, :int, :int, :int ], :pointer 85 | 86 | sdl_func :SetCursor, [ :pointer ], :void 87 | sdl_func :GetCursor, [ ], :pointer 88 | sdl_func :FreeCursor, [ :pointer ], :void 89 | sdl_func :ShowCursor, [ :int ], :int 90 | 91 | 92 | BUTTON_LEFT = 1 93 | BUTTON_MIDDLE = 2 94 | BUTTON_RIGHT = 3 95 | BUTTON_WHEELUP = 4 96 | BUTTON_WHEELDOWN = 5 97 | BUTTON_X1 = 6 98 | BUTTON_X2 = 7 99 | 100 | BUTTON_LMASK = 1 << (BUTTON_LEFT - 1) 101 | BUTTON_MMASK = 1 << (BUTTON_MIDDLE - 1) 102 | BUTTON_RMASK = 1 << (BUTTON_RIGHT - 1) 103 | BUTTON_X1MASK = 1 << (BUTTON_X1 - 1) 104 | BUTTON_X2MASK = 1 << (BUTTON_X2 - 1) 105 | 106 | end 107 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/mutex.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | MUTEX_TIMEDOUT = 1 34 | 35 | sdl_func :CreateMutex, [ ], :pointer 36 | sdl_func :mutexP, [ :pointer ], :int 37 | sdl_func :mutexV, [ :pointer ], :int 38 | sdl_func :DestroyMutex, [ :pointer ], :void 39 | 40 | sdl_func :CreateSemaphore, [ :uint32 ], :pointer 41 | sdl_func :DestroySemaphore, [ :pointer ], :void 42 | 43 | sdl_func :SemWait, [ :pointer ], :int 44 | sdl_func :SemTryWait, [ :pointer ], :int 45 | sdl_func :SemWaitTimeout, [ :pointer, :uint32 ], :int 46 | sdl_func :SemPost, [ :pointer ], :int 47 | sdl_func :SemValue, [ :pointer ], :uint32 48 | 49 | sdl_func :CreateCond, [ ], :pointer 50 | sdl_func :DestroyCond, [ :pointer ], :void 51 | sdl_func :CondSignal, [ :pointer ], :int 52 | sdl_func :CondBroadcast, [ :pointer ], :int 53 | sdl_func :CondWait, [ :pointer, :pointer ], :int 54 | 55 | sdl_func :CondWaitTimeout, [ :pointer, :pointer, :uint32 ], :int 56 | 57 | end 58 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/rwops.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | class RWopsHiddenStdio < NiceFFI::Struct 34 | layout( :autoclose, :int, 35 | :fp, :pointer ) 36 | end 37 | 38 | 39 | class RWopsHiddenMem < NiceFFI::Struct 40 | layout( :base, :pointer, 41 | :here, :pointer, 42 | :stop, :pointer ) 43 | end 44 | 45 | 46 | class RWopsHiddenUnknown < NiceFFI::Struct 47 | layout( :data1, :pointer ) 48 | end 49 | 50 | 51 | class RWopsHidden < FFI::Union 52 | layout( :stdio, SDL::RWopsHiddenStdio, 53 | :mem, SDL::RWopsHiddenMem, 54 | :unknown, SDL::RWopsHiddenUnknown ) 55 | end 56 | 57 | 58 | SDL::callback(:rwops_seek_cb, [:pointer, :int, :int], :int) 59 | SDL::callback(:rwops_read_cb, [:pointer, :pointer, :int, :int], :int) 60 | SDL::callback(:rwops_write_cb,[:pointer, :pointer, :int, :int], :int) 61 | SDL::callback(:rwops_close_cb,[:pointer], :int) 62 | 63 | class RWops < NiceFFI::Struct 64 | layout( :seek, :rwops_seek_cb, 65 | :read, :rwops_read_cb, 66 | :write, :rwops_write_cb, 67 | :close, :rwops_close_cb, 68 | :type, :uint32, 69 | :hidden, SDL::RWopsHidden ) 70 | 71 | hidden( :hidden ) 72 | 73 | def seek=(cb) 74 | @seek = cb 75 | self[:seek] = @seek 76 | end 77 | 78 | def seek 79 | @seek 80 | end 81 | 82 | def read=(cb) 83 | @read = cb 84 | self[:read] = @read 85 | end 86 | 87 | def read 88 | @read 89 | end 90 | 91 | def write=(cb) 92 | @write = cb 93 | self[:write] = @write 94 | end 95 | 96 | def write 97 | @write 98 | end 99 | 100 | def close=(cb) 101 | @close = cb 102 | self[:close] = @close 103 | end 104 | 105 | def close 106 | @close 107 | end 108 | 109 | end 110 | 111 | 112 | sdl_func :RWFromFile, [ :string, :string ], :pointer 113 | sdl_func :RWFromFP, [ :pointer, :int ], :pointer 114 | sdl_func :RWFromMem, [ :pointer, :int ], :pointer 115 | sdl_func :RWFromConstMem, [ :pointer, :int ], :pointer 116 | 117 | sdl_func :AllocRW, [ ], :pointer 118 | sdl_func :FreeRW, [ :pointer ], :void 119 | 120 | RW_SEEK_SET = 0 121 | RW_SEEK_CUR = 1 122 | RW_SEEK_END = 2 123 | 124 | sdl_func :ReadLE16, [ :pointer ], :uint16 125 | sdl_func :ReadBE16, [ :pointer ], :uint16 126 | sdl_func :ReadLE32, [ :pointer ], :uint32 127 | sdl_func :ReadBE32, [ :pointer ], :uint32 128 | sdl_func :ReadLE64, [ :pointer ], :uint64 129 | sdl_func :ReadBE64, [ :pointer ], :uint64 130 | sdl_func :WriteLE16, [ :pointer, :uint16 ], :int 131 | sdl_func :WriteBE16, [ :pointer, :uint16 ], :int 132 | sdl_func :WriteLE32, [ :pointer, :uint32 ], :int 133 | sdl_func :WriteBE32, [ :pointer, :uint32 ], :int 134 | sdl_func :WriteLE64, [ :pointer, :uint64 ], :int 135 | sdl_func :WriteBE64, [ :pointer, :uint64 ], :int 136 | 137 | end 138 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/timer.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | module SDL 32 | 33 | TIMESLICE = 10 34 | TIMER_RESOLUTION = 10 35 | 36 | sdl_func :GetTicks, [ ], :uint32 37 | sdl_func :Delay, [ :uint32 ], :void 38 | 39 | callback(:timer_cb, [ :uint32 ], :uint32) 40 | sdl_func :SetTimer, [ :uint32, :timer_cb ], :int 41 | 42 | callback(:newtimer_cb, [ :uint32, :pointer ], :uint32) 43 | sdl_func :AddTimer, [:uint32, :newtimer_cb, :pointer], :pointer 44 | 45 | sdl_func :RemoveTimer, [ :pointer ], SDL::BOOL 46 | 47 | end 48 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/sdl/video.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009, 2010 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | # 29 | # Contributions: 30 | # 31 | # - Bart Leusink, 2011-01-31: 32 | # Implemented SDL::SaveBMP and SDL::LoadBMP 33 | # 34 | #++ 35 | 36 | 37 | module SDL 38 | 39 | ALPHA_OPAQUE = 255 40 | ALPHA_TRANSPARENT = 0 41 | 42 | class Rect < NiceFFI::Struct 43 | layout( :x, :int16, 44 | :y, :int16, 45 | :w, :uint16, 46 | :h, :uint16 ) 47 | end 48 | 49 | class Color < NiceFFI::Struct 50 | layout( :r, :uint8, 51 | :g, :uint8, 52 | :b, :uint8, 53 | :unused, :uint8 ) 54 | 55 | hidden( :unused ) 56 | 57 | end 58 | 59 | 60 | class Palette < NiceFFI::Struct 61 | layout( :ncolors, :int, 62 | :colors, :pointer ) 63 | 64 | include Enumerable 65 | 66 | # Returns the color at the given index in the palette, as an 67 | # SDL::Color instance. 68 | def at( index ) 69 | index = (0...ncolors).to_a.at(index) 70 | if index 71 | SDL::Color.new( self[:colors] + index * SDL::Color.size ) 72 | end 73 | end 74 | 75 | # Yields an SDL::Color for each color in the palette. 76 | def each 77 | ncolors.times{ |i| yield at(i) } 78 | end 79 | 80 | end 81 | 82 | 83 | class PixelFormat < NiceFFI::Struct 84 | layout( :palette, Palette.typed_pointer, 85 | :BitsPerPixel, :uint8, 86 | :BytesPerPixel, :uint8, 87 | :Rloss, :uint8, 88 | :Gloss, :uint8, 89 | :Bloss, :uint8, 90 | :Aloss, :uint8, 91 | :Rshift, :uint8, 92 | :Gshift, :uint8, 93 | :Bshift, :uint8, 94 | :Ashift, :uint8, 95 | :Rmask, :uint32, 96 | :Gmask, :uint32, 97 | :Bmask, :uint32, 98 | :Amask, :uint32, 99 | :colorkey, :uint32, 100 | :alpha, :uint8 ) 101 | end 102 | 103 | class Surface < NiceFFI::Struct 104 | layout( :flags, :uint32, 105 | :format, PixelFormat.typed_pointer, 106 | :w, :int, 107 | :h, :int, 108 | :pitch, :uint16, 109 | :pixels, :pointer, 110 | :offset, :int, 111 | :hwdata, :pointer, 112 | :clip_rect, SDL::Rect, 113 | :unused1, :uint32, 114 | :locked, :uint32, 115 | :map, :pointer, 116 | :format_version, :uint, 117 | :refcount, :int ) 118 | 119 | read_only( :flags, :format, :w, :h, 120 | :pitch, :clip_rect, :refcount ) 121 | 122 | hidden( :offset, :hwdata, :unused1, 123 | :locked, :map, :format_version ) 124 | 125 | def self.release( pointer ) 126 | SDL.FreeSurface( pointer ) 127 | end 128 | end 129 | 130 | 131 | SWSURFACE = 0x00000000 132 | HWSURFACE = 0x00000001 133 | ASYNCBLIT = 0x00000004 134 | ANYFORMAT = 0x10000000 135 | HWPALETTE = 0x20000000 136 | DOUBLEBUF = 0x40000000 137 | FULLSCREEN = 0x80000000 138 | OPENGL = 0x00000002 139 | OPENGLBLIT = 0x0000000A 140 | RESIZABLE = 0x00000010 141 | NOFRAME = 0x00000020 142 | HWACCEL = 0x00000100 143 | SRCCOLORKEY = 0x00001000 144 | RLEACCELOK = 0x00002000 145 | RLEACCEL = 0x00004000 146 | SRCALPHA = 0x00010000 147 | PREALLOC = 0x01000000 148 | 149 | callback(:blit_cb, [ :pointer, :pointer, :pointer, :pointer ], :int) 150 | 151 | 152 | class VideoInfo < NiceFFI::Struct 153 | layout( :flags, :uint32, 154 | 155 | ## flags contains: 156 | # :hw_available, :uint32, #bitfield: 1 157 | # :wm_available, :uint32, #bitfield: 1 158 | # :UnusedBits1, :uint32, #bitfield: 6 159 | # :UnusedBits2, :uint32, #bitfield: 1 160 | # :blit_hw, :uint32, #bitfield: 1 161 | # :blit_hw_CC, :uint32, #bitfield: 1 162 | # :blit_hw_A, :uint32, #bitfield: 1 163 | # :blit_sw, :uint32, #bitfield: 1 164 | # :blit_sw_CC, :uint32, #bitfield: 1 165 | # :blit_sw_A, :uint32, #bitfield: 1 166 | # :blit_fill, :uint32, #bitfield: 1 167 | # :UnusedBits3, :uint32, #bitfield: 16 168 | 169 | :video_mem, :uint32, 170 | :vfmt, PixelFormat.typed_pointer, 171 | :current_w, :int, 172 | :current_h, :int ) 173 | 174 | hidden( :flags ) 175 | 176 | def hw_available 177 | self[:flags][1] 178 | end 179 | 180 | def wm_available 181 | self[:flags][2] 182 | end 183 | 184 | def blit_hw 185 | self[:flags][9] 186 | end 187 | 188 | def blit_hw_CC 189 | self[:flags][10] 190 | end 191 | 192 | def blit_hw_A 193 | self[:flags][11] 194 | end 195 | 196 | def blit_sw 197 | self[:flags][12] 198 | end 199 | 200 | def blit_sw_CC 201 | self[:flags][13] 202 | end 203 | 204 | def blit_sw_A 205 | self[:flags][14] 206 | end 207 | 208 | def blit_fill 209 | self[:flags][15] 210 | end 211 | end 212 | 213 | 214 | YV12_OVERLAY = 0x32315659 215 | IYUV_OVERLAY = 0x56555949 216 | YUY2_OVERLAY = 0x32595559 217 | UYVY_OVERLAY = 0x59565955 218 | YVYU_OVERLAY = 0x55595659 219 | 220 | class Overlay < NiceFFI::Struct 221 | layout( :format, :uint32, 222 | :w, :int, 223 | :h, :int, 224 | :planes, :int, 225 | :pitches, :pointer, 226 | :pixels, :pointer, 227 | :hwfuncs, :pointer, 228 | :hwdata, :pointer, 229 | :hw_overlay, :uint32, 230 | :UnusedBits, :uint32 ) 231 | 232 | read_only( :format, :w, :h, :planes, 233 | :pitches, :hw_overlay ) 234 | 235 | hidden( :hwfuncs, :hwdata, :UnusedBits ) 236 | 237 | def self.release( pointer ) 238 | SDL.FreeYUVOverlay( pointer ) 239 | end 240 | end 241 | 242 | 243 | GL_RED_SIZE = 0 244 | GL_GREEN_SIZE = 1 245 | GL_BLUE_SIZE = 2 246 | GL_ALPHA_SIZE = 3 247 | GL_BUFFER_SIZE = 4 248 | GL_DOUBLEBUFFER = 5 249 | GL_DEPTH_SIZE = 6 250 | GL_STENCIL_SIZE = 7 251 | GL_ACCUM_RED_SIZE = 8 252 | GL_ACCUM_GREEN_SIZE = 9 253 | GL_ACCUM_BLUE_SIZE = 10 254 | GL_ACCUM_ALPHA_SIZE = 11 255 | GL_STEREO = 12 256 | GL_MULTISAMPLEBUFFERS = 13 257 | GL_MULTISAMPLESAMPLES = 14 258 | GL_ACCELERATED_VISUAL = 15 259 | GL_SWAP_CONTROL = 16 260 | 261 | LOGPAL = 0x01 262 | PHYSPAL = 0x02 263 | 264 | 265 | sdl_func :VideoInit, [ :string, :uint32 ], :int 266 | sdl_func :VideoQuit, [ ], :void 267 | 268 | sdl_func :VideoDriverName, [ :string, :int ], :string 269 | 270 | sdl_func :GetVideoSurface, [], 271 | SDL::Surface.typed_pointer( :autorelease => false ) 272 | 273 | sdl_func :GetVideoInfo, [ ], SDL::VideoInfo.typed_pointer 274 | 275 | sdl_func :VideoModeOK, [ :int, :int, :int, :uint32 ], :int 276 | 277 | ## Don't know how to implement this one. :-\ 278 | # sdl_func :ListModes, [ :pointer, :uint32 ], :pointer 279 | 280 | 281 | func :__SetVideoMode, "SDL_SetVideoMode", [ :int, :int, :int, :uint32 ], 282 | SDL::Surface.typed_pointer( :autorelease => false ) 283 | 284 | def self.SetVideoMode( *args ) 285 | result = __SetVideoMode(*args) 286 | if defined? SDL::Mac 287 | SDL::Mac::HIServices.make_current_front 288 | SDL::Mac.make_menus("ruby") 289 | end 290 | return result 291 | end 292 | 293 | 294 | # Sets the application name, if the platform supports it. This 295 | # method is safe to call even on platforms which do not support it 296 | # (but does nothing). Currently this method only has an effect on 297 | # Mac OS X. 298 | # 299 | # The effect of this method depends on the platform. On Mac OS X, it 300 | # sets the text used in the main application menu. 301 | # 302 | # (Note: this method does not correspond to any part of the SDL API. 303 | # It communicates with the platform directly.) 304 | # 305 | # Example: 306 | # SDL.set_app_name("SpaceQuest 4000") 307 | # 308 | def self.set_app_name( app_name ) 309 | if defined? SDL::Mac 310 | SDL::Mac.set_app_name( app_name ) 311 | end 312 | nil 313 | end 314 | 315 | 316 | func :__UpdateRects, "SDL_UpdateRects", [ :pointer, :int, :pointer ], :void 317 | 318 | def self.UpdateRects( surf, rects ) 319 | rects_mp = FFI::Buffer.new( Rect, rects.length ) 320 | 321 | rects.each_with_index do |rect, i| 322 | rects_mp[i].put_bytes( 0, rect.to_bytes ) 323 | end 324 | 325 | __UpdateRects( surf, rects.length, rects_mp ) 326 | end 327 | 328 | 329 | sdl_func :UpdateRect, [ :pointer, :int32, :int32, :uint32, :uint32 ], :void 330 | sdl_func :Flip, [ :pointer ], :int 331 | 332 | 333 | 334 | sdl_func :SetGamma, [ :float, :float, :float ], :int 335 | sdl_func :SetGammaRamp, [ :pointer, :pointer, :pointer ], :int 336 | 337 | 338 | func :__SDL_GetGammaRamp, "SDL_GetGammaRamp", 339 | [ :buffer_out, :buffer_out, :buffer_out ], :int 340 | 341 | def self.GetGammaRamp() 342 | rtable = FFI::Buffer.new( :uint16, 256 ) 343 | gtable = FFI::Buffer.new( :uint16, 256 ) 344 | btable = FFI::Buffer.new( :uint16, 256 ) 345 | 346 | n = __SDL_GetGammaRamp( rtable, gtable, btable ) 347 | 348 | if( n == -1 ) 349 | return nil 350 | else 351 | return [ rtable.get_array_of_uint16(0, 256), 352 | gtable.get_array_of_uint16(0, 256), 353 | btable.get_array_of_uint16(0, 256) ] 354 | end 355 | end 356 | 357 | 358 | sdl_func :SetColors, [ :pointer, :pointer, :int, :int ], :int 359 | sdl_func :SetPalette, [ :pointer, :int, :pointer, :int, :int ], :int 360 | sdl_func :MapRGB, [ :pointer, :uint8, :uint8, :uint8 ], :uint32 361 | sdl_func :MapRGBA, [ :pointer, :uint8, :uint8, :uint8, :uint8 ], :uint32 362 | 363 | 364 | func :__SDL_GetRGB, "SDL_GetRGB", 365 | [ :uint32, :pointer, :buffer_out, :buffer_out, :buffer_out ], :void 366 | 367 | def self.GetRGB( uint32, format ) 368 | r = FFI::Buffer.new( :uint8 ) 369 | g = FFI::Buffer.new( :uint8 ) 370 | b = FFI::Buffer.new( :uint8 ) 371 | __SDL_GetRGB( uint32, format, r, g, b ) 372 | return [r.get_uint8(0), g.get_uint8(0), b.get_uint8(0)] 373 | end 374 | 375 | 376 | 377 | func :__SDL_GetRGBA, "SDL_GetRGBA", 378 | [ :uint32, :pointer, :buffer_out, 379 | :buffer_out, :buffer_out, :buffer_out ], :void 380 | 381 | def self.GetRGBA( uint32, format ) 382 | r = FFI::Buffer.new( :uint8 ) 383 | g = FFI::Buffer.new( :uint8 ) 384 | b = FFI::Buffer.new( :uint8 ) 385 | a = FFI::Buffer.new( :uint8 ) 386 | __SDL_GetRGBA( uint32, format, r, g, b, a ) 387 | return [r.get_uint8(0), g.get_uint8(0), b.get_uint8(0), a.get_uint8(0)] 388 | end 389 | 390 | 391 | 392 | sdl_func :CreateRGBSurface, 393 | [ :uint32, :int, :int, :int, :uint32, :uint32, :uint32, :uint32 ], 394 | SDL::Surface.typed_pointer 395 | 396 | sdl_func :CreateRGBSurfaceFrom, 397 | [ :pointer, :int, :int, :int, :int, 398 | :uint32, :uint32, :uint32, :uint32 ], 399 | SDL::Surface.typed_pointer 400 | 401 | 402 | sdl_func :FreeSurface, [ :pointer ], :void 403 | sdl_func :LockSurface, [ :pointer ], :int 404 | sdl_func :UnlockSurface, [ :pointer ], :void 405 | 406 | 407 | sdl_func :LoadBMP_RW, [ :pointer, :int ], SDL::Surface.typed_pointer 408 | sdl_func :SaveBMP_RW, [ :pointer, :pointer, :int ], :int 409 | 410 | 411 | def self.LoadBMP( file ) 412 | return LoadBMP_RW( RWFromFile( file, "rb" ), 1 ) 413 | end 414 | 415 | def self.SaveBMP( surface, file ) 416 | return SaveBMP_RW( surface, RWFromFile( file, "wb" ), 1 ) 417 | end 418 | 419 | 420 | sdl_func :SetColorKey, [ :pointer, :uint32, :uint32 ], :int 421 | sdl_func :SetAlpha, [ :pointer, :uint32, :uint8 ], :int 422 | 423 | 424 | 425 | sdl_func :SetClipRect, [ :pointer, :pointer ], SDL::BOOL 426 | 427 | func :__SDL_GetClipRect, "SDL_GetClipRect", [ :pointer, :buffer_out ], :void 428 | 429 | def self.GetClipRect( surface ) 430 | mp = FFI::Buffer.new( Rect ) 431 | __SDL_GetClipRect( surface, mp ) 432 | return Rect.new( mp ) 433 | end 434 | 435 | 436 | sdl_func :ConvertSurface, 437 | [ :pointer, :pointer, :uint32 ], SDL::Surface.typed_pointer 438 | 439 | 440 | func :BlitSurface, "SDL_UpperBlit", 441 | [ :pointer, :pointer, :pointer, :pointer ], :int 442 | 443 | 444 | sdl_func :FillRect, [ :pointer, :pointer, :uint32 ], :int 445 | 446 | 447 | sdl_func :DisplayFormat, [ :pointer ], SDL::Surface.typed_pointer 448 | sdl_func :DisplayFormatAlpha, [ :pointer ], SDL::Surface.typed_pointer 449 | 450 | 451 | sdl_func :CreateYUVOverlay, [ :int, :int, :uint32, :pointer ], 452 | SDL::Overlay.typed_pointer 453 | 454 | sdl_func :LockYUVOverlay, [ :pointer ], :int 455 | sdl_func :UnlockYUVOverlay, [ :pointer ], :void 456 | sdl_func :DisplayYUVOverlay, [ :pointer, :pointer ], :int 457 | sdl_func :FreeYUVOverlay, [ :pointer ], :void 458 | 459 | 460 | sdl_func :GL_LoadLibrary, [ :string ], :int 461 | sdl_func :GL_GetProcAddress, [ :string ], :pointer 462 | sdl_func :GL_SetAttribute, [ SDL::GLATTR, :int ], :int 463 | 464 | 465 | func :__GL_GetAttribute, "SDL_GL_GetAttribute", 466 | [ SDL::GLATTR, :buffer_out ], :int 467 | 468 | def self.GL_GetAttribute( attrib ) 469 | buffer = FFI::Buffer.new( :int ) 470 | result = __GL_GetAttribute( attrib, buffer ) 471 | if( result == -1 ) 472 | return nil 473 | else 474 | return buffer.get_int(0) 475 | end 476 | end 477 | 478 | 479 | sdl_func :GL_SwapBuffers, [ ], :void 480 | sdl_func :GL_UpdateRects, [ :int, :pointer ], :void 481 | sdl_func :GL_Lock, [ ], :void 482 | sdl_func :GL_Unlock, [ ], :void 483 | 484 | 485 | 486 | sdl_func :WM_SetCaption, [ :string, :string ], :void 487 | 488 | func :__SDL_WM_GetCaption, "SDL_WM_GetCaption", 489 | [ :buffer_out, :buffer_out ], :void 490 | 491 | def self.WM_GetCaption() 492 | title = FFI::Buffer.new( :pointer ) 493 | icont = FFI::Buffer.new( :pointer ) 494 | __SDL_WM_GetCaption( title, icont ) 495 | return [ title.get_pointer(0).get_string(0), 496 | icont.get_pointer(0).get_string(0) ] 497 | end 498 | 499 | 500 | 501 | sdl_func :WM_SetIcon, [ :pointer, :pointer ], :void 502 | sdl_func :WM_IconifyWindow, [ ], :int 503 | sdl_func :WM_ToggleFullScreen, [ :pointer ], :int 504 | 505 | 506 | GRAB_QUERY = -1 507 | GRAB_OFF = 0 508 | GRAB_ON = 1 509 | GRAB_FULLSCREEN = 2 510 | 511 | sdl_func :WM_GrabInput, [ SDL::ENUM ], SDL::ENUM 512 | 513 | end 514 | -------------------------------------------------------------------------------- /lib/ruby-sdl-ffi/ttf.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # This file is one part of: 4 | # 5 | # Ruby-SDL-FFI - Ruby-FFI bindings to SDL 6 | # 7 | # Copyright (c) 2009 John Croisant 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining 10 | # a copy of this software and associated documentation files (the 11 | # "Software"), to deal in the Software without restriction, including 12 | # without limitation the rights to use, copy, modify, merge, publish, 13 | # distribute, sublicense, and/or sell copies of the Software, and to 14 | # permit persons to whom the Software is furnished to do so, subject to 15 | # the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be 18 | # included in all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | #++ 29 | 30 | 31 | this_dir = File.expand_path( File.dirname(__FILE__) ) 32 | 33 | require File.join( this_dir, "sdl" ) 34 | 35 | 36 | module SDL 37 | module TTF 38 | extend NiceFFI::Library 39 | load_library "SDL_ttf", SDL::LOAD_PATHS 40 | 41 | 42 | def self.ttf_func( name, args, ret ) 43 | func name, "TTF_#{name}", args, ret 44 | end 45 | 46 | 47 | ttf_func :Linked_Version, [ ], SDL::Version.typed_pointer 48 | 49 | 50 | 51 | class Font < NiceFFI::OpaqueStruct 52 | #-- 53 | # TTF_Font struct (in C) has a hidden layout. 54 | #++ 55 | 56 | def self.release( pointer ) 57 | SDL::TTF.CloseFont( pointer ) 58 | end 59 | end 60 | 61 | 62 | 63 | UNICODE_BOM_NATIVE = 0xFEFF 64 | UNICODE_BOM_SWAPPED = 0xFFFE 65 | 66 | ttf_func :ByteSwappedUNICODE, [ :int ], :void 67 | 68 | ttf_func :Init, [ ], :int 69 | 70 | 71 | ttf_func :OpenFont, [ :string, :int ], 72 | Font.typed_pointer 73 | 74 | ttf_func :OpenFontIndex, [ :string, :int, :long ], 75 | Font.typed_pointer 76 | 77 | ttf_func :OpenFontRW, [ :pointer, :int, :int ], 78 | Font.typed_pointer 79 | 80 | ttf_func :OpenFontIndexRW, [ :pointer, :int, :int, :long ], 81 | Font.typed_pointer 82 | 83 | 84 | STYLE_NORMAL = 0x00 85 | STYLE_BOLD = 0x01 86 | STYLE_ITALIC = 0x02 87 | STYLE_UNDERLINE = 0x04 88 | 89 | 90 | ttf_func :GetFontStyle, [ :pointer ], :int 91 | ttf_func :SetFontStyle, [ :pointer, :int ], :void 92 | ttf_func :FontHeight, [ :pointer ], :int 93 | ttf_func :FontAscent, [ :pointer ], :int 94 | ttf_func :FontDescent, [ :pointer ], :int 95 | ttf_func :FontLineSkip, [ :pointer ], :int 96 | ttf_func :FontFaces, [ :pointer ], :long 97 | 98 | 99 | ttf_func :FontFaceIsFixedWidth, [ :pointer ], :int 100 | ttf_func :FontFaceFamilyName, [ :pointer ], :string 101 | ttf_func :FontFaceStyleName, [ :pointer ], :string 102 | 103 | 104 | 105 | func :__GlyphMetrics, "TTF_GlyphMetrics", 106 | [ :pointer, :uint16, :buffer_out, :buffer_out, 107 | :buffer_out, :buffer_out, :buffer_out ], :int 108 | 109 | # Returns:: [minx, maxx, miny, maxy, advance], or nil on failure. 110 | # 111 | def self.GlyphMetrics( font, char ) 112 | minx, maxx = FFI::Buffer.new(:int), FFI::Buffer.new(:int) 113 | miny, maxy = FFI::Buffer.new(:int), FFI::Buffer.new(:int) 114 | advance = FFI::Buffer.new(:int) 115 | result = __GlyphMetrics( font, char, minx, maxx, miny, maxy, advance ) 116 | if( result == 0 ) 117 | return [minx.get_int(0), maxx.get_int(0), 118 | miny.get_int(0), maxy.get_int(0), advance.get_int(0)] 119 | else 120 | nil 121 | end 122 | end 123 | 124 | 125 | 126 | func :__SizeText, "TTF_SizeText", 127 | [ :pointer, :string, :buffer_out, :buffer_out ], :int 128 | 129 | def self.SizeText( font, text ) 130 | w = FFI::Buffer.new( :int ) 131 | h = FFI::Buffer.new( :int ) 132 | __SizeText( font, text, w, h ) 133 | return [w.get_int(0),h.get_int(0)] 134 | end 135 | 136 | 137 | 138 | func :__SizeUTF8, "TTF_SizeUTF8", 139 | [ :pointer, :string, :buffer_out, :buffer_out ], :int 140 | 141 | def self.SizeUTF( font, text ) 142 | w = FFI::Buffer.new( :int ) 143 | h = FFI::Buffer.new( :int ) 144 | __SizeUTF( font, text, w, h ) 145 | return [w.get_int(0),h.get_int(0)] 146 | end 147 | 148 | 149 | 150 | func :__SizeUNICODE, "TTF_SizeUNICODE", 151 | [ :pointer, :pointer, :buffer_out, :buffer_out ], :int 152 | 153 | def self.SizeUNICODE( font, text ) 154 | w = FFI::Buffer.new( :int ) 155 | h = FFI::Buffer.new( :int ) 156 | __SizeUNICODE( font, text, w, h ) 157 | return [w.get_int(0),h.get_int(0)] 158 | end 159 | 160 | 161 | 162 | %w{ Text UTF8 UNICODE Glyph }.each do |text_type| 163 | 164 | %w{ Solid Blended }.each do |render_mode| 165 | 166 | name = "Render#{text_type}_#{render_mode}" 167 | 168 | module_eval <=0.2" ) 61 | 62 | s.requirements = ["SDL >= 1.2.13", 63 | "SDL_image >= 1.2.7 (optional)", 64 | "SDL_gfx >= 2.0.13 (optional)", 65 | "SDL_mixer >= 1.2.8 (optional)", 66 | "SDL_ttf >= 2.0.9 (optional)"] 67 | 68 | end 69 | -------------------------------------------------------------------------------- /scripts/mkchangelog.rb: -------------------------------------------------------------------------------- 1 | #!/bin/env ruby 2 | 3 | require 'fileutils' 4 | 5 | # Constructs a ChangeLog from the git log. 6 | # Strips out commit ids, since they might change (merge, rebase, etc.). 7 | 8 | file = (ARGV[0] or "ChangeLog.txt") 9 | `git log --name-status > #{file}.tmp` 10 | `sed -e 's/^commit [0-9a-f]\\+$/#{"-"*60}/' #{file}.tmp > #{file}` 11 | FileUtils.rm "#{file}.tmp" 12 | --------------------------------------------------------------------------------