misha-ruby-sdl-ffi 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: misha-ruby-sdl-ffi
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.5'
5
+ platform: ruby
6
+ authors:
7
+ - John Croisant
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nice-ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0.2'
25
+ type: :runtime
26
+ prerelease: false
27
+ description: ! 'Ruby-SDL-FFI is a low-level binding to SDL and related libraries
28
+
29
+ using Ruby-FFI. It provides very basic access to SDL from
30
+
31
+ Ruby without the need for a compiled C wrapper. It aims to
32
+
33
+ be platform and Ruby implementation independent.
34
+
35
+ '
36
+ email: jacius@gmail.com
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - NEWS.rdoc
42
+ - README.rdoc
43
+ - lib/ruby-sdl-ffi/gfx/blitfunc.rb
44
+ - lib/ruby-sdl-ffi/gfx/framerate.rb
45
+ - lib/ruby-sdl-ffi/gfx/imagefilter.rb
46
+ - lib/ruby-sdl-ffi/gfx/primitives.rb
47
+ - lib/ruby-sdl-ffi/gfx/rotozoom.rb
48
+ - lib/ruby-sdl-ffi/gfx.rb
49
+ - lib/ruby-sdl-ffi/image.rb
50
+ - lib/ruby-sdl-ffi/mixer.rb
51
+ - lib/ruby-sdl-ffi/sdl/audio.rb
52
+ - lib/ruby-sdl-ffi/sdl/cdrom.rb
53
+ - lib/ruby-sdl-ffi/sdl/core.rb
54
+ - lib/ruby-sdl-ffi/sdl/event.rb
55
+ - lib/ruby-sdl-ffi/sdl/joystick.rb
56
+ - lib/ruby-sdl-ffi/sdl/keyboard.rb
57
+ - lib/ruby-sdl-ffi/sdl/keysyms.rb
58
+ - lib/ruby-sdl-ffi/sdl/mac.rb
59
+ - lib/ruby-sdl-ffi/sdl/mouse.rb
60
+ - lib/ruby-sdl-ffi/sdl/mutex.rb
61
+ - lib/ruby-sdl-ffi/sdl/rwops.rb
62
+ - lib/ruby-sdl-ffi/sdl/timer.rb
63
+ - lib/ruby-sdl-ffi/sdl/video.rb
64
+ - lib/ruby-sdl-ffi/sdl.rb
65
+ - lib/ruby-sdl-ffi/ttf.rb
66
+ - lib/ruby-sdl-ffi.rb
67
+ - ChangeLog.txt
68
+ homepage: http://github.com/rubygame/ruby-sdl-ffi/
69
+ licenses: []
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '1.8'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements:
86
+ - SDL >= 1.2.13
87
+ - SDL_image >= 1.2.7 (optional)
88
+ - SDL_gfx >= 2.0.13 (optional)
89
+ - SDL_mixer >= 1.2.8 (optional)
90
+ - SDL_ttf >= 2.0.9 (optional)
91
+ rubyforge_project: ruby-sdl-ffi
92
+ rubygems_version: 2.0.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Ruby-FFI bindings to SDL
96
+ test_files: []