sdl2_ffi 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +33 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +83 -0
  9. data/Rakefile +7 -0
  10. data/bin/coderay +16 -0
  11. data/bin/guard +16 -0
  12. data/bin/pry +16 -0
  13. data/bin/rake +16 -0
  14. data/bin/thor +16 -0
  15. data/lib/sdl2/assert.rb +7 -0
  16. data/lib/sdl2/audio.rb +139 -0
  17. data/lib/sdl2/clipboard.rb +27 -0
  18. data/lib/sdl2/color.rb +12 -0
  19. data/lib/sdl2/cpuinfo.rb +18 -0
  20. data/lib/sdl2/display/mode.rb +53 -0
  21. data/lib/sdl2/display/modes.rb +36 -0
  22. data/lib/sdl2/display.rb +74 -0
  23. data/lib/sdl2/error.rb +9 -0
  24. data/lib/sdl2/events.rb +358 -0
  25. data/lib/sdl2/gamecontroller.rb +62 -0
  26. data/lib/sdl2/gem_version.rb +4 -0
  27. data/lib/sdl2/gesture.rb +15 -0
  28. data/lib/sdl2/haptic.rb +159 -0
  29. data/lib/sdl2/hints.rb +47 -0
  30. data/lib/sdl2/init.rb +54 -0
  31. data/lib/sdl2/joystick.rb +58 -0
  32. data/lib/sdl2/keyboard.rb +34 -0
  33. data/lib/sdl2/keycode.rb +294 -0
  34. data/lib/sdl2/log.rb +70 -0
  35. data/lib/sdl2/mouse.rb +54 -0
  36. data/lib/sdl2/palette.rb +15 -0
  37. data/lib/sdl2/pixel_format.rb +28 -0
  38. data/lib/sdl2/pixels.rb +35 -0
  39. data/lib/sdl2/point.rb +7 -0
  40. data/lib/sdl2/power.rb +9 -0
  41. data/lib/sdl2/rect.rb +38 -0
  42. data/lib/sdl2/render.rb +77 -0
  43. data/lib/sdl2/renderer.rb +34 -0
  44. data/lib/sdl2/renderer_info.rb +13 -0
  45. data/lib/sdl2/rwops.rb +127 -0
  46. data/lib/sdl2/scancode.rb +275 -0
  47. data/lib/sdl2/sdl_module.rb +8 -0
  48. data/lib/sdl2/surface.rb +83 -0
  49. data/lib/sdl2/syswm/info.rb +49 -0
  50. data/lib/sdl2/syswm/msg.rb +46 -0
  51. data/lib/sdl2/syswm.rb +20 -0
  52. data/lib/sdl2/texture.rb +9 -0
  53. data/lib/sdl2/timer.rb +17 -0
  54. data/lib/sdl2/touch.rb +24 -0
  55. data/lib/sdl2/version.rb +30 -0
  56. data/lib/sdl2/video.rb +154 -0
  57. data/lib/sdl2/window.rb +259 -0
  58. data/lib/sdl2.rb +99 -0
  59. data/lib/sdl2_ffi.rb +6 -0
  60. data/sdl2_ffi.gemspec +31 -0
  61. data/test/test_helper.rb +2 -0
  62. data/test/unit/sdl2/test_assert.rb +10 -0
  63. data/test/unit/sdl2/test_audio.rb +9 -0
  64. data/test/unit/sdl2/test_clipboard.rb +13 -0
  65. data/test/unit/sdl2/test_cpuinfo.rb +11 -0
  66. data/test/unit/sdl2/test_error.rb +20 -0
  67. data/test/unit/sdl2/test_events.rb +31 -0
  68. data/test/unit/sdl2/test_haptic.rb +10 -0
  69. data/test/unit/sdl2/test_hints.rb +50 -0
  70. data/test/unit/sdl2/test_init.rb +29 -0
  71. data/test/unit/sdl2/test_keyboard.rb +9 -0
  72. data/test/unit/sdl2/test_log.rb +80 -0
  73. data/test/unit/sdl2/test_pixels.rb +24 -0
  74. data/test/unit/sdl2/test_power.rb +11 -0
  75. data/test/unit/sdl2/test_rect.rb +19 -0
  76. data/test/unit/sdl2/test_render.rb +58 -0
  77. data/test/unit/sdl2/test_surface.rb +45 -0
  78. data/test/unit/sdl2/test_syswm.rb +11 -0
  79. data/test/unit/sdl2/test_timer.rb +9 -0
  80. data/test/unit/sdl2/test_version.rb +16 -0
  81. data/test/unit/sdl2/test_video.rb +170 -0
  82. data/test/unit/sdl2/test_window.rb +158 -0
  83. data/test/unit/test_sdl2.rb +16 -0
  84. metadata +280 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1fbda9790c93fa1061e680eb19b56d27ef5e9b2e
4
+ data.tar.gz: 8947768e9c0f8d504f6cb154624cec7a2f220c37
5
+ SHA512:
6
+ metadata.gz: 8b8f386629bc6ff085e64450ad026b4669ee4251dfe924f6eae89772905b3474f4c0a0bf647f9a22f5ca6024651b655a785aed12e48e647ed0d5b01ddc50e015
7
+ data.tar.gz: e1afed2d1d6dc466bdaeb9b3a3aac67d93e597972bccdebe0dc692415f4989290638c61594eb0fcfcfe01df4ae045352a9537970df290733f6d12e1abc9ae1c3
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .project
19
+ .buildpath
20
+ *~
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ sdl2_ffi
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sdl2_ffi.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,33 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :minitest do
5
+ # with Minitest::Unit
6
+ watch(%r{^test/(.*)\/?test_(.*)\.rb})
7
+ watch(%r{^lib/(.*/)?([^/]+)\.rb}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
8
+ watch(%r{^test/test_helper\.rb}) { 'test' }
9
+
10
+ # with Minitest::Spec
11
+ watch(%r{^spec/(.*)_spec\.rb})
12
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
13
+ watch(%r{^spec/spec_helper\.rb}) { 'spec' }
14
+
15
+ # Rails 4
16
+ # watch(%r{^test/test_helper\.rb}) { 'test' }
17
+ # watch(%r{^test/.+_test\.rb})
18
+ # watch(%r{^app/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" }
19
+ # watch(%r{^app/controllers/application_controller\.rb}) { 'test/controllers' }
20
+ # watch(%r{^app/controllers/(.+)_controller\.rb}) { |m| "test/integration/#{m[1]}_test.rb" }
21
+ # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
22
+ # watch(%r{^lib/(.+)\.rb}) { |m| "test/lib/#{m[1]}_test.rb" }
23
+
24
+ # Rails 3.2
25
+ # watch(%r{^app/controllers/(.*)\.rb}) { |m| "test/controllers/#{m[1]}_test.rb" }
26
+ # watch(%r{^app/helpers/(.*)\.rb}) { |m| "test/helpers/#{m[1]}_test.rb" }
27
+ # watch(%r{^app/models/(.*)\.rb}) { |m| "test/unit/#{m[1]}_test.rb" }
28
+
29
+ # Rails
30
+ # watch(%r{^app/controllers/(.*)\.rb}) { |m| "test/functional/#{m[1]}_test.rb" }
31
+ # watch(%r{^app/helpers/(.*)\.rb}) { |m| "test/helpers/#{m[1]}_test.rb" }
32
+ # watch(%r{^app/models/(.*)\.rb}) { |m| "test/unit/#{m[1]}_test.rb" }
33
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 BadQuanta
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # sdl2_ffi
2
+
3
+ This is a simple interface to SDL2 for Ruby using FFI. This effort has barely started.
4
+
5
+ # How to start:
6
+
7
+ The GEM is organized to the same structure as the SDL header files. Where in C/C++ you would need to:
8
+
9
+ include 'SDL.h'
10
+ include 'SDL_video.h'
11
+
12
+ with this rubygem, you would instead:
13
+
14
+ require 'sdl2'
15
+ require 'sdl2/video'
16
+
17
+ The SDL2 module is defined and it is where the raw SDL API is loaded and linked. The Raw API can be called like so:
18
+
19
+ SDL2.init(SDL2::INIT_EVERYTHING)
20
+
21
+ ### Gotchas:
22
+
23
+ * Remember that SDL uses the 'SDL_Bool' enum instead of actual ruby Boolean, so instead of 'true' and 'false', you get ':true' and ':false'
24
+ * Whenever SDL returns an SDL_Bool in the RAW API, I will always endevour to ensure there is a xxx? equivalent helper that converts the response to Ruby Booleans.
25
+
26
+ ## Updates
27
+
28
+ ### Imported APIs
29
+
30
+ I'm working my way through the SDL API header files. I am attempting to make this GEM as modular as the SDL header files themselves so that the developer can load only the enum, typedefs and link to only the functionality needed.
31
+
32
+ ## Dependencies
33
+
34
+ * Obviously, ruby
35
+ * SDL2 Runtime (Development files are not needed.)
36
+
37
+ ## Installation
38
+
39
+ Add this line to your application's Gemfile:
40
+
41
+ gem 'sdl2_ffi'
42
+
43
+ And then execute:
44
+
45
+ $ bundle
46
+
47
+ Or install it yourself as:
48
+
49
+ $ gem install sdl2_ffi
50
+
51
+ ## Testing
52
+
53
+ Minitests are being written to validate functionality. Not SDL's functionality, but that the GEM has been linked properly and that the Object Oriented wrapper functions as intended.
54
+
55
+ Run the tests with rake:
56
+
57
+ $ rake test
58
+
59
+ Verbose options are nice:
60
+
61
+ $ rake test TESTOPTS="--verbose"
62
+
63
+ ### I need your help!
64
+
65
+ I'm just starting to implement the Object Oriented Wrapper. I'll need help identifying mistakes, especially in memory management. Bug-reports submitted with tests will be looked at before bug-reports without tests, as a way to encourage tests being written.
66
+
67
+ Thanks for reading this!
68
+
69
+ ## Usage
70
+
71
+ The interface is intended to be modular and follows (roughly) SDL's header files.
72
+
73
+ ## Contributing
74
+
75
+ libSDL 2.0 is licensed under the 'zlib license', listed as compatible with the GNU GPL by [the gnu foundation](http://www.gnu.org/licenses/license-list.html). The 'sdl_ffi' GEM is licensed under the MIT License. Both encourage distribution and modification. Please let me know about your work and I'll link it where appropriate.
76
+
77
+ 1. Fork it
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create new Pull Request
82
+
83
+ I specifically need help writing the minitest code.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = 'test/**/test*.rb'
6
+ t.verbose = true
7
+ end
data/bin/coderay ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'coderay' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('sdl2_ffi', 'coderay')
data/bin/guard ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'guard' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('sdl2_ffi', 'guard')
data/bin/pry ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'pry' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('sdl2_ffi', 'pry')
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('sdl2_ffi', 'rake')
data/bin/thor ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('sdl2_ffi', 'thor')
@@ -0,0 +1,7 @@
1
+
2
+ require 'sdl2'
3
+
4
+ # Stub for SDL_assert.h, Unsure if we should translate or borrow existing functionality.
5
+ # TODO: Review for future implementation
6
+ module SDL2
7
+ end
data/lib/sdl2/audio.rb ADDED
@@ -0,0 +1,139 @@
1
+ require 'sdl2'
2
+ require 'yinum'
3
+
4
+ module SDL2
5
+
6
+ typedef :uint16, :audio_format
7
+
8
+ module Audio
9
+ Mask = Enum.new(:AudioMask, {
10
+ BITSIZE: (0xFF),
11
+ DATATYPE: (1<<8),
12
+ ENDIAN: (1<<12),
13
+ SIGNED: (1<<15)
14
+ })
15
+
16
+ def self.bitsize(x)
17
+ x & Mask.BITSIZE
18
+ end
19
+
20
+ def self.is_float?(x)
21
+ (x & Mask.DATATYPE) != 0
22
+ end
23
+
24
+ def self.is_big_endian?(x)
25
+ x & mask.ENDIAN
26
+ end
27
+
28
+ def self.is_signed?(x)
29
+ x & mask.SIGNED
30
+ end
31
+
32
+ def self.is_int?(x)
33
+ !is_float?(x)
34
+ end
35
+
36
+ def self.is_little_endian?(x)
37
+ !is_big_endian?(x)
38
+ end
39
+
40
+ def self.is_unsigned?(x)
41
+ !is_signed?(x)
42
+ end
43
+
44
+
45
+ U8 = 0x0008
46
+ S8 = 0x8008
47
+ U16LSB = 0x0010
48
+ S16LSB = 0x8010
49
+ U16MSB = 0x1010
50
+ S16MSB = 0x9010
51
+ U16 = U16LSB
52
+ S16 = S16LSB
53
+ S32LSB = 0x8020
54
+ S32MSB = 0x9020
55
+ S32 = S32LSB
56
+ F32LSB = 0x8120
57
+ F32MSB = 0x9120
58
+ F32= F32LSB
59
+
60
+ ALLOW_FREQUENCY_CHANGE =0x00000001
61
+ ALLOW_FORMAT_CHANGE =0x00000002
62
+ ALLOW_CHANNELS_CHANGE =0x00000004
63
+ ALLOW_ANY_CHANGE =(ALLOW_FREQUENCY_CHANGE|ALLOW_FORMAT_CHANGE|ALLOW_CHANNELS_CHANGE)
64
+
65
+
66
+
67
+ class Spec < Struct
68
+ layout :freq, :int,
69
+ :format, :uint16,
70
+ :channels, :uint8,
71
+ :silence, :uint8,
72
+ :samples, :uint16,
73
+ :padding, :uint16,
74
+ :size, :uint32,
75
+ :callback, :pointer, #:audio_callback,
76
+ :userdata, :pointer
77
+ end
78
+
79
+ class CVT < 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, [:pointer, 10], # :audio_filter callback
90
+ :filter_index, :int
91
+ end
92
+
93
+ end#module Audio
94
+
95
+ callback :audio_callback, [:pointer, :pointer, :int], :void
96
+ callback :audio_filter, [Audio::CVT.by_ref, :audio_format], :void
97
+
98
+ api :SDL_GetNumAudioDrivers, [], :int
99
+ api :SDL_GetAudioDriver, [:int], :string
100
+ api :SDL_AudioInit, [:string], :int
101
+ api :SDL_AudioQuit, [], :void
102
+ api :SDL_GetCurrentAudioDriver, [], :string
103
+ api :SDL_OpenAudio, [Audio::Spec.by_ref, Audio::Spec.by_ref], :int
104
+
105
+ typedef :uint32, :audio_device_id
106
+
107
+ api :SDL_GetNumAudioDevices, [:int], :int
108
+ api :SDL_GetAudioDeviceName, [:int, :int], :string
109
+ api :SDL_OpenAudioDevice, [:string, :int, Audio::Spec.by_ref, Audio::Spec.by_ref, :int], :audio_device_id
110
+
111
+ enum :audio_status, [:STOPPED, 0, :PLAYING, :PAUSED]
112
+
113
+ api :SDL_GetAudioStatus, [], :audio_status
114
+ api :SDL_PauseAudio, [:int], :void
115
+ api :SDL_PauseAudioDevice, [:audio_device_id, :int], :void
116
+ api :SDL_LoadWAV_RW, [RWops.by_ref, :int, Audio::Spec.by_ref, :pointer, :pointer], Audio::Spec.by_ref
117
+
118
+ def self.load_wav(file, spec, audio_buf, audio_len)
119
+ load_wav_rw(rw_from_file)
120
+ end
121
+
122
+ api :SDL_FreeWAV, [:pointer], :void
123
+ api :SDL_BuildAudioCVT, [Audio::CVT.by_ref, :audio_format, :uint8, :int, :audio_format, :uint8, :int], :int
124
+ api :SDL_ConvertAudio, [Audio::CVT.by_ref], :int
125
+
126
+ MIX_MAXVOLUME = 128
127
+
128
+ api :SDL_MixAudio, [:pointer, :pointer, :uint32, :int], :void
129
+ api :SDL_MixAudioFormat, [:pointer, :pointer, :audio_format, :uint32, :int], :void
130
+ api :SDL_LockAudio, [], :void
131
+ api :SDL_LockAudioDevice, [:audio_device_id], :void
132
+ api :SDL_UnlockAudio, [], :void
133
+ api :SDL_UnlockAudioDevice, [:audio_device_id], :void
134
+
135
+ api :SDL_CloseAudio, [], :void
136
+ api :SDL_CloseAudioDevice, [:audio_device_id], :void
137
+
138
+
139
+ end
@@ -0,0 +1,27 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+
5
+ module Clipboard
6
+
7
+ def self.has
8
+ SDL2.has_clipboard_text()
9
+ end
10
+
11
+ def self.has?
12
+ SDL2.has_clipboard_text == :true
13
+ end
14
+
15
+ def self.get
16
+ SDL2.get_clipboard_text()
17
+ end
18
+
19
+ def self.set(text)
20
+ SDL2.set_clipboard_text(text.to_s)
21
+ end
22
+ end
23
+
24
+ api :SDL_SetClipboardText, [:string], :int
25
+ api :SDL_GetClipboardText, [], :string
26
+ api :SDL_HasClipboardText, [], :bool
27
+ end
data/lib/sdl2/color.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+ #SDL_pixels.h:252~258
5
+ class Color < Struct
6
+ layout :r, :uint8,
7
+ :g, :uint8,
8
+ :b, :uint8,
9
+ :a, :uint8
10
+ end
11
+ Colour = Color # Because SDL does it
12
+ end
@@ -0,0 +1,18 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+
5
+ CACHELINE_SIZE = 128
6
+
7
+ api :SDL_GetCPUCount, [], :int
8
+ api :SDL_GetCPUCacheLineSize, [], :int
9
+ api :SDL_HasRDTSC, [], :bool
10
+ api :SDL_HasAltiVec, [], :bool
11
+ api :SDL_Has3DNow, [], :bool
12
+ api :SDL_HasSSE, [], :bool
13
+ api :SDL_HasSSE2, [], :bool
14
+ api :SDL_HasSSE3, [], :bool
15
+ api :SDL_HasSSE41, [], :bool
16
+ api :SDL_HasSSE42, [], :bool
17
+
18
+ end
@@ -0,0 +1,53 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+
5
+ class Display
6
+ # Converted from 'SDL_video.h':53
7
+ class Mode < Struct
8
+ layout :format, :uint32,
9
+ :w, :int,
10
+ :h, :int,
11
+ :refresh_rate, :int,
12
+ :driverdata, :pointer
13
+
14
+ def self.release(pointer)
15
+ pointer.free # TODO: Is there a better way of doing this?
16
+ end
17
+
18
+ def self.current(display_index)
19
+ dm = DisplayMode.new
20
+ get_current_display_mode(display_index, dm)
21
+ return dm
22
+ end
23
+
24
+ def self.current!(display_index)
25
+ get_current_display_mode!(display_index)
26
+ end
27
+
28
+
29
+ def format=(value)
30
+ self[:format] = value
31
+ end
32
+
33
+ def w=(value)
34
+ self[:w] = value
35
+ end
36
+
37
+ def h=(value)
38
+ self[:h] = value
39
+ end
40
+
41
+ def refresh_rate=(value)
42
+ self[:refresh_rate] = value
43
+ end
44
+
45
+ def driverdata=(value)
46
+ self[:driverdata] = value
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+
53
+ end
@@ -0,0 +1,36 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+
5
+ class Display
6
+
7
+ class Modes
8
+ # TODO: Consider converting this into some kind of enumerator?
9
+ def initialize(for_display)
10
+ @for_display = for_display
11
+ end
12
+
13
+ def count
14
+ SDL2.get_num_display_modes(@for_display.id)
15
+ end
16
+
17
+ # TODO: Probably leaks memory.. WeakRef cache?
18
+ def [](index)
19
+ if (idx = index.to_i) < count
20
+ dm_buffer = SDL2::Display::Mode.new
21
+ if SDL2.get_display_mode(@for_display.id, idx, dm_buffer) == 0
22
+ return dm_buffer
23
+ else
24
+ dm_buffer.pointer.free
25
+ end
26
+ else
27
+ return nil
28
+ end
29
+ end
30
+
31
+ def first
32
+ self[0]
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,74 @@
1
+ require 'sdl2'
2
+ require 'sdl2/display/modes'
3
+ require 'sdl2/display/mode'
4
+
5
+ module SDL2
6
+
7
+ # Abstract representation of what SDL calls a "Display"
8
+ class Display
9
+
10
+ attr_reader :id
11
+
12
+ def initialize(display_id)
13
+ @id = display_id.to_i # It should be an integer.
14
+
15
+ end
16
+
17
+
18
+ def modes
19
+ @modes ||= Modes.new(self)
20
+ end
21
+
22
+ def self.[](display_id)
23
+ if (idx = display_id.to_i) < count
24
+ return Display.new(display_id)
25
+ else
26
+ return nil
27
+ end
28
+ end
29
+
30
+ def self.count
31
+ SDL2.get_num_video_displays()
32
+ end
33
+
34
+ def self.count!
35
+ total = count
36
+ SDL2.throw_error_if total < 0
37
+ return total
38
+ end
39
+
40
+ def self.first
41
+ self[0]
42
+ end
43
+
44
+ def closest_display_mode(wanted)
45
+ closest = SDL2::Display::Mode.new # Make a new structure.
46
+ return SDL2.get_closest_display_mode(@id, wanted, closest)
47
+ end
48
+
49
+ def closest_display_mode!(wanted)
50
+ found = closest_display_mode(wanted)
51
+ SDL2.throw_error_if(found.nil?)
52
+ return found
53
+ end
54
+
55
+ def bounds
56
+ rect = SDL2::Rect.new
57
+ if SDL2.get_display_bounds(@id, rect) == 0
58
+ return rect
59
+ else
60
+ rect.pointer.free
61
+ return nil
62
+ end
63
+ end
64
+
65
+ def bounds!
66
+ rect = bounds()
67
+ SDL2.throw_error_if rect.nil?
68
+ return rect
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
data/lib/sdl2/error.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+
5
+ api :SDL_ClearError, [], :void
6
+ api :SDL_GetError, [], :string
7
+ api :SDL_SetError, [:string, :varargs], :int
8
+
9
+ end