ruby-sdl-ffi 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,90 @@
1
+
2
+ = Ruby-SDL-FFI
3
+
4
+ Version:: 0.1
5
+ Date:: 2009-10-24
6
+
7
+ Homepage:: http://github.com/jacius/ffi-sdl/
8
+ Author:: John Croisant <jacius@gmail.com>
9
+ Copyright:: 2009 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]. It provides very basic access
16
+ to SDL from Ruby [3] without the need for a compiled C
17
+ wrapper. It aims to be platform and Ruby implementation
18
+ 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://kenai.com/projects/ruby-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 VERY 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
+ * Ruby-FFI >= 0.4.0 (or compatible FFI implementation)
50
+ * Nice-FFI >= 0.2.0
51
+
52
+ Optional:
53
+
54
+ * SDL_image >= 1.2.7
55
+ * SDL_gfx >= 2.0.17
56
+ * SDL_mixer >= 1.2.8
57
+ * SDL_ttf >= 2.0.9
58
+
59
+ Ruby-SDL-FFI may work with older versions, but hasn't been tried on them.
60
+
61
+ So far, Ruby-SDL-FFI has only been tested on 32-bit Linux with
62
+ the standard Ruby implementation (aka MRI) version 1.8.6.
63
+ However, with a few tweaks it should work on any system with
64
+ compatible FFI functionality.
65
+
66
+
67
+ == License
68
+
69
+ Ruby-SDL-FFI is licensed under the following terms (the "MIT License"):
70
+
71
+ Copyright (c) 2009 John Croisant
72
+
73
+ Permission is hereby granted, free of charge, to any person obtaining
74
+ a copy of this software and associated documentation files (the
75
+ "Software"), to deal in the Software without restriction, including
76
+ without limitation the rights to use, copy, modify, merge, publish,
77
+ distribute, sublicense, and/or sell copies of the Software, and to
78
+ permit persons to whom the Software is furnished to do so, subject to
79
+ the following conditions:
80
+
81
+ The above copyright notice and this permission notice shall be
82
+ included in all copies or substantial portions of the Software.
83
+
84
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
87
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
88
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
89
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
90
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -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 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
@@ -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 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
@@ -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 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
@@ -0,0 +1,51 @@
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
@@ -0,0 +1,176 @@
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