hybridgroup-ruby-sdl-ffi 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,257 @@
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 <<EOF
169
+ func :__#{name}, "TTF_#{name}", [ :pointer, :string, :uint32 ],
170
+ SDL::Surface.typed_pointer
171
+
172
+ def self.#{name}( font, text, color )
173
+ color = color.pointer.get_uint32(0)
174
+ __#{name}( font, text, color )
175
+ end
176
+ EOF
177
+ end
178
+
179
+
180
+ name = "Render#{text_type}_Shaded"
181
+
182
+ module_eval <<EOF
183
+ func :__#{name}, "TTF_#{name}",
184
+ [ :pointer, :string, :uint32, :uint32 ],
185
+ SDL::Surface.typed_pointer
186
+
187
+ def self.#{name}( font, text, color, back )
188
+ color = color.pointer.get_uint32(0)
189
+ back = back.pointer.get_uint32(0)
190
+ __#{name}( font, text, color, back )
191
+ end
192
+ EOF
193
+ end
194
+
195
+
196
+ # ttf_func :RenderText_Solid,
197
+ # [ :pointer, :string, SDL::Color ],
198
+ # SDL::Surface.typed_pointer
199
+ #
200
+ #
201
+ # ttf_func :RenderText_Solid,
202
+ # [ :pointer, :string, SDL::Color ],
203
+ # SDL::Surface.typed_pointer
204
+ #
205
+ # ttf_func :RenderUTF8_Solid,
206
+ # [ :pointer, :string, SDL::Color ],
207
+ # SDL::Surface.typed_pointer
208
+ #
209
+ # ttf_func :RenderUNICODE_Solid,
210
+ # [ :pointer, :pointer, SDL::Color ],
211
+ # SDL::Surface.typed_pointer
212
+ #
213
+ # ttf_func :RenderGlyph_Solid,
214
+ # [ :pointer, :uint16, SDL::Color ],
215
+ # SDL::Surface.typed_pointer
216
+ #
217
+ #
218
+ # ttf_func :RenderText_Shaded,
219
+ # [ :pointer, :string, SDL::Color, SDL::Color ],
220
+ # SDL::Surface.typed_pointer
221
+ #
222
+ # ttf_func :RenderUTF8_Shaded,
223
+ # [ :pointer, :string, SDL::Color, SDL::Color ],
224
+ # SDL::Surface.typed_pointer
225
+ #
226
+ # ttf_func :RenderUNICODE_Shaded,
227
+ # [ :pointer, :pointer, SDL::Color, SDL::Color ],
228
+ # SDL::Surface.typed_pointer
229
+ #
230
+ # ttf_func :RenderGlyph_Shaded,
231
+ # [ :pointer, :uint16, SDL::Color, SDL::Color ],
232
+ # SDL::Surface.typed_pointer
233
+ #
234
+ #
235
+ # ttf_func :RenderText_Blended,
236
+ # [ :pointer, :string, SDL::Color ],
237
+ # SDL::Surface.typed_pointer
238
+ #
239
+ # ttf_func :RenderUTF8_Blended,
240
+ # [ :pointer, :string, SDL::Color ],
241
+ # SDL::Surface.typed_pointer
242
+ #
243
+ # ttf_func :RenderUNICODE_Blended,
244
+ # [ :pointer, :pointer, SDL::Color ],
245
+ # SDL::Surface.typed_pointer
246
+ #
247
+ # ttf_func :RenderGlyph_Blended,
248
+ # [ :pointer, :uint16, SDL::Color ],
249
+ # SDL::Surface.typed_pointer
250
+
251
+
252
+ ttf_func :CloseFont, [ :pointer ], :void
253
+ ttf_func :Quit, [ ], :void
254
+ ttf_func :WasInit, [ ], :int
255
+
256
+ end
257
+ end
@@ -0,0 +1,56 @@
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
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hybridgroup-ruby-sdl-ffi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ platform: ruby
6
+ authors:
7
+ - John Croisant
8
+ - Adrian Zankich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nice-ffi
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0.2'
28
+ description: |
29
+ Ruby-SDL-FFI is a low-level binding to SDL and related libraries
30
+ using Ruby-FFI. It provides very basic access to SDL from
31
+ Ruby without the need for a compiled C wrapper. It aims to
32
+ be platform and Ruby implementation independent.
33
+ email:
34
+ - jacius@gmail.com
35
+ - adrian@hybridgroup.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - README.rdoc
41
+ - NEWS.rdoc
42
+ - lib/ruby-sdl-ffi/ttf.rb
43
+ - lib/ruby-sdl-ffi/sdl/mutex.rb
44
+ - lib/ruby-sdl-ffi/sdl/audio.rb
45
+ - lib/ruby-sdl-ffi/sdl/cdrom.rb
46
+ - lib/ruby-sdl-ffi/sdl/keyboard.rb
47
+ - lib/ruby-sdl-ffi/sdl/keysyms.rb
48
+ - lib/ruby-sdl-ffi/sdl/video.rb
49
+ - lib/ruby-sdl-ffi/sdl/core.rb
50
+ - lib/ruby-sdl-ffi/sdl/event.rb
51
+ - lib/ruby-sdl-ffi/sdl/rwops.rb
52
+ - lib/ruby-sdl-ffi/sdl/mac.rb
53
+ - lib/ruby-sdl-ffi/sdl/mouse.rb
54
+ - lib/ruby-sdl-ffi/sdl/joystick.rb
55
+ - lib/ruby-sdl-ffi/sdl/timer.rb
56
+ - lib/ruby-sdl-ffi/image.rb
57
+ - lib/ruby-sdl-ffi/mixer.rb
58
+ - lib/ruby-sdl-ffi/sdl.rb
59
+ - lib/ruby-sdl-ffi/gfx.rb
60
+ - lib/ruby-sdl-ffi/gfx/rotozoom.rb
61
+ - lib/ruby-sdl-ffi/gfx/imagefilter.rb
62
+ - lib/ruby-sdl-ffi/gfx/primitives.rb
63
+ - lib/ruby-sdl-ffi/gfx/blitfunc.rb
64
+ - lib/ruby-sdl-ffi/gfx/framerate.rb
65
+ - lib/ruby-sdl-ffi.rb
66
+ - ChangeLog.txt
67
+ homepage: http://github.com/hybridgroup/ruby-sdl-ffi
68
+ licenses: []
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '1.8'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements:
85
+ - SDL >= 1.2.13
86
+ - SDL_image >= 1.2.7 (optional)
87
+ - SDL_gfx >= 2.0.13 (optional)
88
+ - SDL_mixer >= 1.2.8 (optional)
89
+ - SDL_ttf >= 2.0.9 (optional)
90
+ rubyforge_project: hybridgroup-ruby-sdl-ffi
91
+ rubygems_version: 2.1.5
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Ruby-FFI bindings to SDL
95
+ test_files: []