ruby-sdl-ffi 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.txt +2122 -0
- data/README.rdoc +90 -0
- data/lib/ruby-sdl-ffi.rb +56 -0
- data/lib/ruby-sdl-ffi/gfx.rb +56 -0
- data/lib/ruby-sdl-ffi/gfx/blitfunc.rb +56 -0
- data/lib/ruby-sdl-ffi/gfx/framerate.rb +51 -0
- data/lib/ruby-sdl-ffi/gfx/imagefilter.rb +176 -0
- data/lib/ruby-sdl-ffi/gfx/primitives.rb +253 -0
- data/lib/ruby-sdl-ffi/gfx/rotozoom.rb +109 -0
- data/lib/ruby-sdl-ffi/image.rb +90 -0
- data/lib/ruby-sdl-ffi/mixer.rb +215 -0
- data/lib/ruby-sdl-ffi/sdl.rb +76 -0
- data/lib/ruby-sdl-ffi/sdl/audio.rb +132 -0
- data/lib/ruby-sdl-ffi/sdl/cdrom.rb +87 -0
- data/lib/ruby-sdl-ffi/sdl/core.rb +129 -0
- data/lib/ruby-sdl-ffi/sdl/event.rb +375 -0
- data/lib/ruby-sdl-ffi/sdl/joystick.rb +73 -0
- data/lib/ruby-sdl-ffi/sdl/keyboard.rb +66 -0
- data/lib/ruby-sdl-ffi/sdl/keysyms.rb +282 -0
- data/lib/ruby-sdl-ffi/sdl/mouse.rb +106 -0
- data/lib/ruby-sdl-ffi/sdl/mutex.rb +57 -0
- data/lib/ruby-sdl-ffi/sdl/rwops.rb +137 -0
- data/lib/ruby-sdl-ffi/sdl/timer.rb +47 -0
- data/lib/ruby-sdl-ffi/sdl/video.rb +447 -0
- data/lib/ruby-sdl-ffi/ttf.rb +257 -0
- metadata +97 -0
@@ -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, :pointer, :pointer,
|
107
|
+
:pointer, :pointer, :pointer ], :int
|
108
|
+
|
109
|
+
# Returns:: [minx, maxx, miny, maxy, advance], or nil on failure.
|
110
|
+
#
|
111
|
+
def self.GlyphMetrics( font, char )
|
112
|
+
minx, maxx = FFI::MemoryPointer.new(:int), FFI::MemoryPointer.new(:int)
|
113
|
+
miny, maxy = FFI::MemoryPointer.new(:int), FFI::MemoryPointer.new(:int)
|
114
|
+
advance = FFI::MemoryPointer.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, :pointer, :pointer ], :int
|
128
|
+
|
129
|
+
def self.SizeText( font, text )
|
130
|
+
w = FFI::MemoryPointer.new( :int )
|
131
|
+
h = FFI::MemoryPointer.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, :pointer, :pointer ], :int
|
140
|
+
|
141
|
+
def self.SizeUTF( font, text )
|
142
|
+
w = FFI::MemoryPointer.new( :int )
|
143
|
+
h = FFI::MemoryPointer.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, :pointer, :pointer ], :int
|
152
|
+
|
153
|
+
def self.SizeUNICODE( font, text )
|
154
|
+
w = FFI::MemoryPointer.new( :int )
|
155
|
+
h = FFI::MemoryPointer.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,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-sdl-ffi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Croisant
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-24 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nice-ffi
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.2"
|
24
|
+
version:
|
25
|
+
description: |
|
26
|
+
Ruby-SDL-FFI is a low-level binding to SDL and related libraries
|
27
|
+
using Ruby-FFI. It provides very basic access to SDL from
|
28
|
+
Ruby without the need for a compiled C wrapper. It aims to
|
29
|
+
be platform and Ruby implementation independent.
|
30
|
+
|
31
|
+
email: jacius@gmail.com
|
32
|
+
executables: []
|
33
|
+
|
34
|
+
extensions: []
|
35
|
+
|
36
|
+
extra_rdoc_files: []
|
37
|
+
|
38
|
+
files:
|
39
|
+
- README.rdoc
|
40
|
+
- lib/ruby-sdl-ffi.rb
|
41
|
+
- lib/ruby-sdl-ffi/sdl/mouse.rb
|
42
|
+
- lib/ruby-sdl-ffi/sdl/keyboard.rb
|
43
|
+
- lib/ruby-sdl-ffi/sdl/mutex.rb
|
44
|
+
- lib/ruby-sdl-ffi/sdl/rwops.rb
|
45
|
+
- lib/ruby-sdl-ffi/sdl/event.rb
|
46
|
+
- lib/ruby-sdl-ffi/sdl/joystick.rb
|
47
|
+
- lib/ruby-sdl-ffi/sdl/cdrom.rb
|
48
|
+
- lib/ruby-sdl-ffi/sdl/video.rb
|
49
|
+
- lib/ruby-sdl-ffi/sdl/core.rb
|
50
|
+
- lib/ruby-sdl-ffi/sdl/keysyms.rb
|
51
|
+
- lib/ruby-sdl-ffi/sdl/timer.rb
|
52
|
+
- lib/ruby-sdl-ffi/sdl/audio.rb
|
53
|
+
- lib/ruby-sdl-ffi/mixer.rb
|
54
|
+
- lib/ruby-sdl-ffi/sdl.rb
|
55
|
+
- lib/ruby-sdl-ffi/ttf.rb
|
56
|
+
- lib/ruby-sdl-ffi/image.rb
|
57
|
+
- lib/ruby-sdl-ffi/gfx/blitfunc.rb
|
58
|
+
- lib/ruby-sdl-ffi/gfx/primitives.rb
|
59
|
+
- lib/ruby-sdl-ffi/gfx/framerate.rb
|
60
|
+
- lib/ruby-sdl-ffi/gfx/rotozoom.rb
|
61
|
+
- lib/ruby-sdl-ffi/gfx/imagefilter.rb
|
62
|
+
- lib/ruby-sdl-ffi/gfx.rb
|
63
|
+
- ChangeLog.txt
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/jacius/ruby-sdl-ffi/
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "1.8"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements:
|
86
|
+
- SDL >= 1.2.13
|
87
|
+
- SDL_image >= 1.2.7 (optional)
|
88
|
+
- SDL_gfx >= 2.0.17 (optional)
|
89
|
+
- SDL_mixer >= 1.2.8 (optional)
|
90
|
+
- SDL_ttf >= 2.0.9 (optional)
|
91
|
+
rubyforge_project: nice-ffi
|
92
|
+
rubygems_version: 1.3.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Ruby-FFI bindings to SDL
|
96
|
+
test_files: []
|
97
|
+
|