misha-ruby-sdl-ffi 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/ChangeLog.txt +2441 -0
- data/NEWS.rdoc +77 -0
- data/README.rdoc +84 -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 +251 -0
- data/lib/ruby-sdl-ffi/gfx/rotozoom.rb +108 -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 +81 -0
- data/lib/ruby-sdl-ffi/sdl/audio.rb +139 -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 +76 -0
- data/lib/ruby-sdl-ffi/sdl/keysyms.rb +282 -0
- data/lib/ruby-sdl-ffi/sdl/mac.rb +446 -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 +513 -0
- data/lib/ruby-sdl-ffi/ttf.rb +257 -0
- metadata +96 -0
@@ -0,0 +1,106 @@
|
|
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
|
+
|
33
|
+
if RUBY_PLATFORM =~ /java/
|
34
|
+
# 2009-10-21: JRuby FFI does not support pointer arrays in structs.
|
35
|
+
# Attempting it can raise an un-rescuable NotImplementedError! :(
|
36
|
+
puts "Warning: Skipping class SDL::Cursor due to JRuby limitations."
|
37
|
+
else
|
38
|
+
|
39
|
+
class Cursor < NiceFFI::Struct
|
40
|
+
layout( :area, SDL::Rect,
|
41
|
+
:hot_x, :int16,
|
42
|
+
:hot_y, :int16,
|
43
|
+
:data, :pointer,
|
44
|
+
:mask, :pointer,
|
45
|
+
:save, [:pointer, 2],
|
46
|
+
:wm_cursor, :pointer )
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
func :__SDL_GetMouseState, "SDL_GetMouseState",
|
52
|
+
[ :buffer_out, :buffer_out ], :uint8
|
53
|
+
|
54
|
+
# Returns [buttons, x, y].
|
55
|
+
# buttons: buttons currently pressed (bitmask of BUTTON_*MASK constants).
|
56
|
+
# x, y: current position of the mouse cursor.
|
57
|
+
def self.GetMouseState()
|
58
|
+
xmp = FFI::Buffer.new( :int )
|
59
|
+
ymp = FFI::Buffer.new( :int )
|
60
|
+
buttons = __SDL_GetMouseState( xmp, ymp )
|
61
|
+
return [buttons, xmp.get_int(0), ymp.get_int(0)]
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
func :__SDL_GetRelativeMouseState, "SDL_GetRelativeMouseState",
|
66
|
+
[ :buffer_out, :buffer_out ], :uint8
|
67
|
+
|
68
|
+
# Returns [buttons, x, y].
|
69
|
+
# buttons: buttons currently pressed (bitmask of BUTTON_*MASK constants).
|
70
|
+
# x, y: movement of the mouse cursor since last call of this method.
|
71
|
+
#
|
72
|
+
def self.GetRelativeMouseState()
|
73
|
+
xmp = FFI::Buffer.new( :int )
|
74
|
+
ymp = FFI::Buffer.new( :int )
|
75
|
+
buttons = __SDL_GetRelativeMouseState( xmp, ymp )
|
76
|
+
return [buttons, xmp.get_int(0), ymp.get_int(0)]
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
sdl_func :WarpMouse, [ :uint16, :uint16 ], :void
|
81
|
+
|
82
|
+
|
83
|
+
sdl_func :CreateCursor,
|
84
|
+
[ :pointer, :pointer, :int, :int, :int, :int ], :pointer
|
85
|
+
|
86
|
+
sdl_func :SetCursor, [ :pointer ], :void
|
87
|
+
sdl_func :GetCursor, [ ], :pointer
|
88
|
+
sdl_func :FreeCursor, [ :pointer ], :void
|
89
|
+
sdl_func :ShowCursor, [ :int ], :int
|
90
|
+
|
91
|
+
|
92
|
+
BUTTON_LEFT = 1
|
93
|
+
BUTTON_MIDDLE = 2
|
94
|
+
BUTTON_RIGHT = 3
|
95
|
+
BUTTON_WHEELUP = 4
|
96
|
+
BUTTON_WHEELDOWN = 5
|
97
|
+
BUTTON_X1 = 6
|
98
|
+
BUTTON_X2 = 7
|
99
|
+
|
100
|
+
BUTTON_LMASK = 1 << (BUTTON_LEFT - 1)
|
101
|
+
BUTTON_MMASK = 1 << (BUTTON_MIDDLE - 1)
|
102
|
+
BUTTON_RMASK = 1 << (BUTTON_RIGHT - 1)
|
103
|
+
BUTTON_X1MASK = 1 << (BUTTON_X1 - 1)
|
104
|
+
BUTTON_X2MASK = 1 << (BUTTON_X2 - 1)
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,57 @@
|
|
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
|
+
|
33
|
+
MUTEX_TIMEDOUT = 1
|
34
|
+
|
35
|
+
sdl_func :CreateMutex, [ ], :pointer
|
36
|
+
sdl_func :mutexP, [ :pointer ], :int
|
37
|
+
sdl_func :mutexV, [ :pointer ], :int
|
38
|
+
sdl_func :DestroyMutex, [ :pointer ], :void
|
39
|
+
|
40
|
+
sdl_func :CreateSemaphore, [ :uint32 ], :pointer
|
41
|
+
sdl_func :DestroySemaphore, [ :pointer ], :void
|
42
|
+
|
43
|
+
sdl_func :SemWait, [ :pointer ], :int
|
44
|
+
sdl_func :SemTryWait, [ :pointer ], :int
|
45
|
+
sdl_func :SemWaitTimeout, [ :pointer, :uint32 ], :int
|
46
|
+
sdl_func :SemPost, [ :pointer ], :int
|
47
|
+
sdl_func :SemValue, [ :pointer ], :uint32
|
48
|
+
|
49
|
+
sdl_func :CreateCond, [ ], :pointer
|
50
|
+
sdl_func :DestroyCond, [ :pointer ], :void
|
51
|
+
sdl_func :CondSignal, [ :pointer ], :int
|
52
|
+
sdl_func :CondBroadcast, [ :pointer ], :int
|
53
|
+
sdl_func :CondWait, [ :pointer, :pointer ], :int
|
54
|
+
|
55
|
+
sdl_func :CondWaitTimeout, [ :pointer, :pointer, :uint32 ], :int
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,137 @@
|
|
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
|
+
|
33
|
+
class RWopsHiddenStdio < NiceFFI::Struct
|
34
|
+
layout( :autoclose, :int,
|
35
|
+
:fp, :pointer )
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
class RWopsHiddenMem < NiceFFI::Struct
|
40
|
+
layout( :base, :pointer,
|
41
|
+
:here, :pointer,
|
42
|
+
:stop, :pointer )
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
class RWopsHiddenUnknown < NiceFFI::Struct
|
47
|
+
layout( :data1, :pointer )
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
class RWopsHidden < FFI::Union
|
52
|
+
layout( :stdio, SDL::RWopsHiddenStdio,
|
53
|
+
:mem, SDL::RWopsHiddenMem,
|
54
|
+
:unknown, SDL::RWopsHiddenUnknown )
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
SDL::callback(:rwops_seek_cb, [:pointer, :int, :int], :int)
|
59
|
+
SDL::callback(:rwops_read_cb, [:pointer, :pointer, :int, :int], :int)
|
60
|
+
SDL::callback(:rwops_write_cb,[:pointer, :pointer, :int, :int], :int)
|
61
|
+
SDL::callback(:rwops_close_cb,[:pointer], :int)
|
62
|
+
|
63
|
+
class RWops < NiceFFI::Struct
|
64
|
+
layout( :seek, :rwops_seek_cb,
|
65
|
+
:read, :rwops_read_cb,
|
66
|
+
:write, :rwops_write_cb,
|
67
|
+
:close, :rwops_close_cb,
|
68
|
+
:type, :uint32,
|
69
|
+
:hidden, SDL::RWopsHidden )
|
70
|
+
|
71
|
+
hidden( :hidden )
|
72
|
+
|
73
|
+
def seek=(cb)
|
74
|
+
@seek = cb
|
75
|
+
self[:seek] = @seek
|
76
|
+
end
|
77
|
+
|
78
|
+
def seek
|
79
|
+
@seek
|
80
|
+
end
|
81
|
+
|
82
|
+
def read=(cb)
|
83
|
+
@read = cb
|
84
|
+
self[:read] = @read
|
85
|
+
end
|
86
|
+
|
87
|
+
def read
|
88
|
+
@read
|
89
|
+
end
|
90
|
+
|
91
|
+
def write=(cb)
|
92
|
+
@write = cb
|
93
|
+
self[:write] = @write
|
94
|
+
end
|
95
|
+
|
96
|
+
def write
|
97
|
+
@write
|
98
|
+
end
|
99
|
+
|
100
|
+
def close=(cb)
|
101
|
+
@close = cb
|
102
|
+
self[:close] = @close
|
103
|
+
end
|
104
|
+
|
105
|
+
def close
|
106
|
+
@close
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
sdl_func :RWFromFile, [ :string, :string ], :pointer
|
113
|
+
sdl_func :RWFromFP, [ :pointer, :int ], :pointer
|
114
|
+
sdl_func :RWFromMem, [ :pointer, :int ], :pointer
|
115
|
+
sdl_func :RWFromConstMem, [ :pointer, :int ], :pointer
|
116
|
+
|
117
|
+
sdl_func :AllocRW, [ ], :pointer
|
118
|
+
sdl_func :FreeRW, [ :pointer ], :void
|
119
|
+
|
120
|
+
RW_SEEK_SET = 0
|
121
|
+
RW_SEEK_CUR = 1
|
122
|
+
RW_SEEK_END = 2
|
123
|
+
|
124
|
+
sdl_func :ReadLE16, [ :pointer ], :uint16
|
125
|
+
sdl_func :ReadBE16, [ :pointer ], :uint16
|
126
|
+
sdl_func :ReadLE32, [ :pointer ], :uint32
|
127
|
+
sdl_func :ReadBE32, [ :pointer ], :uint32
|
128
|
+
sdl_func :ReadLE64, [ :pointer ], :uint64
|
129
|
+
sdl_func :ReadBE64, [ :pointer ], :uint64
|
130
|
+
sdl_func :WriteLE16, [ :pointer, :uint16 ], :int
|
131
|
+
sdl_func :WriteBE16, [ :pointer, :uint16 ], :int
|
132
|
+
sdl_func :WriteLE32, [ :pointer, :uint32 ], :int
|
133
|
+
sdl_func :WriteBE32, [ :pointer, :uint32 ], :int
|
134
|
+
sdl_func :WriteLE64, [ :pointer, :uint64 ], :int
|
135
|
+
sdl_func :WriteBE64, [ :pointer, :uint64 ], :int
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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
|
+
|
33
|
+
TIMESLICE = 10
|
34
|
+
TIMER_RESOLUTION = 10
|
35
|
+
|
36
|
+
sdl_func :GetTicks, [ ], :uint32
|
37
|
+
sdl_func :Delay, [ :uint32 ], :void
|
38
|
+
|
39
|
+
callback(:timer_cb, [ :uint32 ], :uint32)
|
40
|
+
sdl_func :SetTimer, [ :uint32, :timer_cb ], :int
|
41
|
+
|
42
|
+
callback(:newtimer_cb, [ :uint32, :pointer ], :uint32)
|
43
|
+
sdl_func :AddTimer, [:uint32, :newtimer_cb, :pointer], :pointer
|
44
|
+
|
45
|
+
sdl_func :RemoveTimer, [ :pointer ], SDL::BOOL
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,513 @@
|
|
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
|
+
# Contributions:
|
30
|
+
#
|
31
|
+
# - Bart Leusink, 2011-01-31:
|
32
|
+
# Implemented SDL::SaveBMP and SDL::LoadBMP
|
33
|
+
#
|
34
|
+
#++
|
35
|
+
|
36
|
+
|
37
|
+
module SDL
|
38
|
+
|
39
|
+
ALPHA_OPAQUE = 255
|
40
|
+
ALPHA_TRANSPARENT = 0
|
41
|
+
|
42
|
+
class Rect < NiceFFI::Struct
|
43
|
+
layout( :x, :int16,
|
44
|
+
:y, :int16,
|
45
|
+
:w, :uint16,
|
46
|
+
:h, :uint16 )
|
47
|
+
end
|
48
|
+
|
49
|
+
class Color < NiceFFI::Struct
|
50
|
+
layout( :r, :uint8,
|
51
|
+
:g, :uint8,
|
52
|
+
:b, :uint8,
|
53
|
+
:unused, :uint8 )
|
54
|
+
|
55
|
+
hidden( :unused )
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
class Palette < NiceFFI::Struct
|
61
|
+
layout( :ncolors, :int,
|
62
|
+
:colors, :pointer )
|
63
|
+
|
64
|
+
include Enumerable
|
65
|
+
|
66
|
+
# Returns the color at the given index in the palette, as an
|
67
|
+
# SDL::Color instance.
|
68
|
+
def at( index )
|
69
|
+
index = (0...ncolors).to_a.at(index)
|
70
|
+
if index
|
71
|
+
SDL::Color.new( self[:colors] + index * SDL::Color.size )
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Yields an SDL::Color for each color in the palette.
|
76
|
+
def each
|
77
|
+
ncolors.times{ |i| yield at(i) }
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
class PixelFormat < NiceFFI::Struct
|
84
|
+
layout( :palette, Palette.typed_pointer,
|
85
|
+
:BitsPerPixel, :uint8,
|
86
|
+
:BytesPerPixel, :uint8,
|
87
|
+
:Rloss, :uint8,
|
88
|
+
:Gloss, :uint8,
|
89
|
+
:Bloss, :uint8,
|
90
|
+
:Aloss, :uint8,
|
91
|
+
:Rshift, :uint8,
|
92
|
+
:Gshift, :uint8,
|
93
|
+
:Bshift, :uint8,
|
94
|
+
:Ashift, :uint8,
|
95
|
+
:Rmask, :uint32,
|
96
|
+
:Gmask, :uint32,
|
97
|
+
:Bmask, :uint32,
|
98
|
+
:Amask, :uint32,
|
99
|
+
:colorkey, :uint32,
|
100
|
+
:alpha, :uint8 )
|
101
|
+
end
|
102
|
+
|
103
|
+
class Surface < NiceFFI::Struct
|
104
|
+
layout( :flags, :uint32,
|
105
|
+
:format, PixelFormat.typed_pointer,
|
106
|
+
:w, :int,
|
107
|
+
:h, :int,
|
108
|
+
:pitch, :uint16,
|
109
|
+
:pixels, :pointer,
|
110
|
+
:offset, :int,
|
111
|
+
:hwdata, :pointer,
|
112
|
+
:clip_rect, SDL::Rect,
|
113
|
+
:unused1, :uint32,
|
114
|
+
:locked, :uint32,
|
115
|
+
:map, :pointer,
|
116
|
+
:format_version, :uint,
|
117
|
+
:refcount, :int )
|
118
|
+
|
119
|
+
read_only( :flags, :format, :w, :h,
|
120
|
+
:pitch, :clip_rect, :refcount )
|
121
|
+
|
122
|
+
hidden( :offset, :hwdata, :unused1,
|
123
|
+
:locked, :map, :format_version )
|
124
|
+
|
125
|
+
def self.release( pointer )
|
126
|
+
SDL.FreeSurface( pointer )
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
SWSURFACE = 0x00000000
|
132
|
+
HWSURFACE = 0x00000001
|
133
|
+
ASYNCBLIT = 0x00000004
|
134
|
+
ANYFORMAT = 0x10000000
|
135
|
+
HWPALETTE = 0x20000000
|
136
|
+
DOUBLEBUF = 0x40000000
|
137
|
+
FULLSCREEN = 0x80000000
|
138
|
+
OPENGL = 0x00000002
|
139
|
+
OPENGLBLIT = 0x0000000A
|
140
|
+
RESIZABLE = 0x00000010
|
141
|
+
NOFRAME = 0x00000020
|
142
|
+
HWACCEL = 0x00000100
|
143
|
+
SRCCOLORKEY = 0x00001000
|
144
|
+
RLEACCELOK = 0x00002000
|
145
|
+
RLEACCEL = 0x00004000
|
146
|
+
SRCALPHA = 0x00010000
|
147
|
+
PREALLOC = 0x01000000
|
148
|
+
|
149
|
+
callback(:blit_cb, [ :pointer, :pointer, :pointer, :pointer ], :int)
|
150
|
+
|
151
|
+
|
152
|
+
class VideoInfo < NiceFFI::Struct
|
153
|
+
layout( :flags, :uint32,
|
154
|
+
|
155
|
+
## flags contains:
|
156
|
+
# :hw_available, :uint32, #bitfield: 1
|
157
|
+
# :wm_available, :uint32, #bitfield: 1
|
158
|
+
# :UnusedBits1, :uint32, #bitfield: 6
|
159
|
+
# :UnusedBits2, :uint32, #bitfield: 1
|
160
|
+
# :blit_hw, :uint32, #bitfield: 1
|
161
|
+
# :blit_hw_CC, :uint32, #bitfield: 1
|
162
|
+
# :blit_hw_A, :uint32, #bitfield: 1
|
163
|
+
# :blit_sw, :uint32, #bitfield: 1
|
164
|
+
# :blit_sw_CC, :uint32, #bitfield: 1
|
165
|
+
# :blit_sw_A, :uint32, #bitfield: 1
|
166
|
+
# :blit_fill, :uint32, #bitfield: 1
|
167
|
+
# :UnusedBits3, :uint32, #bitfield: 16
|
168
|
+
|
169
|
+
:video_mem, :uint32,
|
170
|
+
:vfmt, PixelFormat.typed_pointer,
|
171
|
+
:current_w, :int,
|
172
|
+
:current_h, :int )
|
173
|
+
|
174
|
+
hidden( :flags )
|
175
|
+
|
176
|
+
def hw_available
|
177
|
+
self[:flags][1]
|
178
|
+
end
|
179
|
+
|
180
|
+
def wm_available
|
181
|
+
self[:flags][2]
|
182
|
+
end
|
183
|
+
|
184
|
+
def blit_hw
|
185
|
+
self[:flags][9]
|
186
|
+
end
|
187
|
+
|
188
|
+
def blit_hw_CC
|
189
|
+
self[:flags][10]
|
190
|
+
end
|
191
|
+
|
192
|
+
def blit_hw_A
|
193
|
+
self[:flags][11]
|
194
|
+
end
|
195
|
+
|
196
|
+
def blit_sw
|
197
|
+
self[:flags][12]
|
198
|
+
end
|
199
|
+
|
200
|
+
def blit_sw_CC
|
201
|
+
self[:flags][13]
|
202
|
+
end
|
203
|
+
|
204
|
+
def blit_sw_A
|
205
|
+
self[:flags][14]
|
206
|
+
end
|
207
|
+
|
208
|
+
def blit_fill
|
209
|
+
self[:flags][15]
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
YV12_OVERLAY = 0x32315659
|
215
|
+
IYUV_OVERLAY = 0x56555949
|
216
|
+
YUY2_OVERLAY = 0x32595559
|
217
|
+
UYVY_OVERLAY = 0x59565955
|
218
|
+
YVYU_OVERLAY = 0x55595659
|
219
|
+
|
220
|
+
class Overlay < NiceFFI::Struct
|
221
|
+
layout( :format, :uint32,
|
222
|
+
:w, :int,
|
223
|
+
:h, :int,
|
224
|
+
:planes, :int,
|
225
|
+
:pitches, :pointer,
|
226
|
+
:pixels, :pointer,
|
227
|
+
:hwfuncs, :pointer,
|
228
|
+
:hwdata, :pointer,
|
229
|
+
:hw_overlay, :uint32,
|
230
|
+
:UnusedBits, :uint32 )
|
231
|
+
|
232
|
+
read_only( :format, :w, :h, :planes,
|
233
|
+
:pitches, :hw_overlay )
|
234
|
+
|
235
|
+
hidden( :hwfuncs, :hwdata, :UnusedBits )
|
236
|
+
|
237
|
+
def self.release( pointer )
|
238
|
+
SDL.FreeYUVOverlay( pointer )
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
GL_RED_SIZE = 0
|
244
|
+
GL_GREEN_SIZE = 1
|
245
|
+
GL_BLUE_SIZE = 2
|
246
|
+
GL_ALPHA_SIZE = 3
|
247
|
+
GL_BUFFER_SIZE = 4
|
248
|
+
GL_DOUBLEBUFFER = 5
|
249
|
+
GL_DEPTH_SIZE = 6
|
250
|
+
GL_STENCIL_SIZE = 7
|
251
|
+
GL_ACCUM_RED_SIZE = 8
|
252
|
+
GL_ACCUM_GREEN_SIZE = 9
|
253
|
+
GL_ACCUM_BLUE_SIZE = 10
|
254
|
+
GL_ACCUM_ALPHA_SIZE = 11
|
255
|
+
GL_STEREO = 12
|
256
|
+
GL_MULTISAMPLEBUFFERS = 13
|
257
|
+
GL_MULTISAMPLESAMPLES = 14
|
258
|
+
GL_ACCELERATED_VISUAL = 15
|
259
|
+
GL_SWAP_CONTROL = 16
|
260
|
+
|
261
|
+
LOGPAL = 0x01
|
262
|
+
PHYSPAL = 0x02
|
263
|
+
|
264
|
+
|
265
|
+
sdl_func :VideoInit, [ :string, :uint32 ], :int
|
266
|
+
sdl_func :VideoQuit, [ ], :void
|
267
|
+
|
268
|
+
sdl_func :VideoDriverName, [ :string, :int ], :string
|
269
|
+
|
270
|
+
sdl_func :GetVideoSurface, [],
|
271
|
+
SDL::Surface.typed_pointer( :autorelease => false )
|
272
|
+
|
273
|
+
sdl_func :GetVideoInfo, [ ], SDL::VideoInfo.typed_pointer
|
274
|
+
|
275
|
+
sdl_func :VideoModeOK, [ :int, :int, :int, :uint32 ], :int
|
276
|
+
|
277
|
+
## Don't know how to implement this one. :-\
|
278
|
+
# sdl_func :ListModes, [ :pointer, :uint32 ], :pointer
|
279
|
+
|
280
|
+
|
281
|
+
func :__SetVideoMode, "SDL_SetVideoMode", [ :int, :int, :int, :uint32 ],
|
282
|
+
SDL::Surface.typed_pointer( :autorelease => false )
|
283
|
+
|
284
|
+
def self.SetVideoMode( *args )
|
285
|
+
result = __SetVideoMode(*args)
|
286
|
+
if defined? SDL::Mac
|
287
|
+
SDL::Mac::HIServices.make_current_front
|
288
|
+
SDL::Mac.make_menus("ruby")
|
289
|
+
end
|
290
|
+
return result
|
291
|
+
end
|
292
|
+
|
293
|
+
|
294
|
+
# Sets the application name, if the platform supports it. This
|
295
|
+
# method is safe to call even on platforms which do not support it
|
296
|
+
# (but does nothing). Currently this method only has an effect on
|
297
|
+
# Mac OS X.
|
298
|
+
#
|
299
|
+
# The effect of this method depends on the platform. On Mac OS X, it
|
300
|
+
# sets the text used in the main application menu.
|
301
|
+
#
|
302
|
+
# (Note: this method does not correspond to any part of the SDL API.
|
303
|
+
# It communicates with the platform directly.)
|
304
|
+
#
|
305
|
+
# Example:
|
306
|
+
# SDL.set_app_name("SpaceQuest 4000")
|
307
|
+
#
|
308
|
+
def self.set_app_name( app_name )
|
309
|
+
if defined? SDL::Mac
|
310
|
+
SDL::Mac.set_app_name( app_name )
|
311
|
+
end
|
312
|
+
nil
|
313
|
+
end
|
314
|
+
|
315
|
+
|
316
|
+
func :__UpdateRects, "SDL_UpdateRects", [ :pointer, :int, :pointer ], :void
|
317
|
+
|
318
|
+
def self.UpdateRects( surf, rects )
|
319
|
+
rects_mp = FFI::Buffer.new( Rect, rects.length )
|
320
|
+
|
321
|
+
rects.each_with_index do |rect, i|
|
322
|
+
rects_mp[i].put_bytes( 0, rect.to_bytes )
|
323
|
+
end
|
324
|
+
|
325
|
+
__UpdateRects( surf, rects.length, rects_mp )
|
326
|
+
end
|
327
|
+
|
328
|
+
|
329
|
+
sdl_func :UpdateRect, [ :pointer, :int32, :int32, :uint32, :uint32 ], :void
|
330
|
+
sdl_func :Flip, [ :pointer ], :int
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
sdl_func :SetGamma, [ :float, :float, :float ], :int
|
335
|
+
sdl_func :SetGammaRamp, [ :pointer, :pointer, :pointer ], :int
|
336
|
+
|
337
|
+
|
338
|
+
func :__SDL_GetGammaRamp, "SDL_GetGammaRamp",
|
339
|
+
[ :buffer_out, :buffer_out, :buffer_out ], :int
|
340
|
+
|
341
|
+
def self.GetGammaRamp()
|
342
|
+
rtable = FFI::Buffer.new( :uint16, 256 )
|
343
|
+
gtable = FFI::Buffer.new( :uint16, 256 )
|
344
|
+
btable = FFI::Buffer.new( :uint16, 256 )
|
345
|
+
|
346
|
+
n = __SDL_GetGammaRamp( rtable, gtable, btable )
|
347
|
+
|
348
|
+
if( n == -1 )
|
349
|
+
return nil
|
350
|
+
else
|
351
|
+
return [ rtable.get_array_of_uint16(0, 256),
|
352
|
+
gtable.get_array_of_uint16(0, 256),
|
353
|
+
btable.get_array_of_uint16(0, 256) ]
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
|
358
|
+
sdl_func :SetColors, [ :pointer, :pointer, :int, :int ], :int
|
359
|
+
sdl_func :SetPalette, [ :pointer, :int, :pointer, :int, :int ], :int
|
360
|
+
sdl_func :MapRGB, [ :pointer, :uint8, :uint8, :uint8 ], :uint32
|
361
|
+
sdl_func :MapRGBA, [ :pointer, :uint8, :uint8, :uint8, :uint8 ], :uint32
|
362
|
+
|
363
|
+
|
364
|
+
func :__SDL_GetRGB, "SDL_GetRGB",
|
365
|
+
[ :uint32, :pointer, :buffer_out, :buffer_out, :buffer_out ], :void
|
366
|
+
|
367
|
+
def self.GetRGB( uint32, format )
|
368
|
+
r = FFI::Buffer.new( :uint8 )
|
369
|
+
g = FFI::Buffer.new( :uint8 )
|
370
|
+
b = FFI::Buffer.new( :uint8 )
|
371
|
+
__SDL_GetRGB( uint32, format, r, g, b )
|
372
|
+
return [r.get_uint8(0), g.get_uint8(0), b.get_uint8(0)]
|
373
|
+
end
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
func :__SDL_GetRGBA, "SDL_GetRGBA",
|
378
|
+
[ :uint32, :pointer, :buffer_out,
|
379
|
+
:buffer_out, :buffer_out, :buffer_out ], :void
|
380
|
+
|
381
|
+
def self.GetRGBA( uint32, format )
|
382
|
+
r = FFI::Buffer.new( :uint8 )
|
383
|
+
g = FFI::Buffer.new( :uint8 )
|
384
|
+
b = FFI::Buffer.new( :uint8 )
|
385
|
+
a = FFI::Buffer.new( :uint8 )
|
386
|
+
__SDL_GetRGBA( uint32, format, r, g, b, a )
|
387
|
+
return [r.get_uint8(0), g.get_uint8(0), b.get_uint8(0), a.get_uint8(0)]
|
388
|
+
end
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
sdl_func :CreateRGBSurface,
|
393
|
+
[ :uint32, :int, :int, :int, :uint32, :uint32, :uint32, :uint32 ],
|
394
|
+
SDL::Surface.typed_pointer
|
395
|
+
|
396
|
+
sdl_func :CreateRGBSurfaceFrom,
|
397
|
+
[ :pointer, :int, :int, :int, :int,
|
398
|
+
:uint32, :uint32, :uint32, :uint32 ],
|
399
|
+
SDL::Surface.typed_pointer
|
400
|
+
|
401
|
+
|
402
|
+
sdl_func :FreeSurface, [ :pointer ], :void
|
403
|
+
sdl_func :LockSurface, [ :pointer ], :int
|
404
|
+
sdl_func :UnlockSurface, [ :pointer ], :void
|
405
|
+
|
406
|
+
|
407
|
+
sdl_func :LoadBMP_RW, [ :pointer, :int ], SDL::Surface.typed_pointer
|
408
|
+
sdl_func :SaveBMP_RW, [ :pointer, :pointer, :int ], :int
|
409
|
+
|
410
|
+
|
411
|
+
def self.LoadBMP( file )
|
412
|
+
return LoadBMP_RW( RWFromFile( file, "rb" ), 1 )
|
413
|
+
end
|
414
|
+
|
415
|
+
def self.SaveBMP( surface, file )
|
416
|
+
return SaveBMP_RW( surface, RWFromFile( file, "wb" ), 1 )
|
417
|
+
end
|
418
|
+
|
419
|
+
|
420
|
+
sdl_func :SetColorKey, [ :pointer, :uint32, :uint32 ], :int
|
421
|
+
sdl_func :SetAlpha, [ :pointer, :uint32, :uint8 ], :int
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
sdl_func :SetClipRect, [ :pointer, :pointer ], SDL::BOOL
|
426
|
+
|
427
|
+
func :__SDL_GetClipRect, "SDL_GetClipRect", [ :pointer, :buffer_out ], :void
|
428
|
+
|
429
|
+
def self.GetClipRect( surface )
|
430
|
+
mp = FFI::Buffer.new( Rect )
|
431
|
+
__SDL_GetClipRect( surface, mp )
|
432
|
+
return Rect.new( mp )
|
433
|
+
end
|
434
|
+
|
435
|
+
|
436
|
+
sdl_func :ConvertSurface,
|
437
|
+
[ :pointer, :pointer, :uint32 ], SDL::Surface.typed_pointer
|
438
|
+
|
439
|
+
|
440
|
+
func :BlitSurface, "SDL_UpperBlit",
|
441
|
+
[ :pointer, :pointer, :pointer, :pointer ], :int
|
442
|
+
|
443
|
+
|
444
|
+
sdl_func :FillRect, [ :pointer, :pointer, :uint32 ], :int
|
445
|
+
|
446
|
+
|
447
|
+
sdl_func :DisplayFormat, [ :pointer ], SDL::Surface.typed_pointer
|
448
|
+
sdl_func :DisplayFormatAlpha, [ :pointer ], SDL::Surface.typed_pointer
|
449
|
+
|
450
|
+
|
451
|
+
sdl_func :CreateYUVOverlay, [ :int, :int, :uint32, :pointer ],
|
452
|
+
SDL::Overlay.typed_pointer
|
453
|
+
|
454
|
+
sdl_func :LockYUVOverlay, [ :pointer ], :int
|
455
|
+
sdl_func :UnlockYUVOverlay, [ :pointer ], :void
|
456
|
+
sdl_func :DisplayYUVOverlay, [ :pointer, :pointer ], :int
|
457
|
+
sdl_func :FreeYUVOverlay, [ :pointer ], :void
|
458
|
+
|
459
|
+
|
460
|
+
sdl_func :GL_LoadLibrary, [ :string ], :int
|
461
|
+
sdl_func :GL_GetProcAddress, [ :string ], :pointer
|
462
|
+
sdl_func :GL_SetAttribute, [ SDL::GLATTR, :int ], :int
|
463
|
+
|
464
|
+
|
465
|
+
func :__GL_GetAttribute, "SDL_GL_GetAttribute",
|
466
|
+
[ SDL::GLATTR, :buffer_out ], :int
|
467
|
+
|
468
|
+
def self.GL_GetAttribute( attrib )
|
469
|
+
buffer = FFI::Buffer.new( :int )
|
470
|
+
result = __GL_GetAttribute( attrib, buffer )
|
471
|
+
if( result == -1 )
|
472
|
+
return nil
|
473
|
+
else
|
474
|
+
return buffer.get_int(0)
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
|
479
|
+
sdl_func :GL_SwapBuffers, [ ], :void
|
480
|
+
sdl_func :GL_UpdateRects, [ :int, :pointer ], :void
|
481
|
+
sdl_func :GL_Lock, [ ], :void
|
482
|
+
sdl_func :GL_Unlock, [ ], :void
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
sdl_func :WM_SetCaption, [ :string, :string ], :void
|
487
|
+
|
488
|
+
func :__SDL_WM_GetCaption, "SDL_WM_GetCaption",
|
489
|
+
[ :buffer_out, :buffer_out ], :void
|
490
|
+
|
491
|
+
def self.WM_GetCaption()
|
492
|
+
title = FFI::Buffer.new( :pointer )
|
493
|
+
icont = FFI::Buffer.new( :pointer )
|
494
|
+
__SDL_WM_GetCaption( title, icont )
|
495
|
+
return [ title.get_pointer(0).get_string(0),
|
496
|
+
icont.get_pointer(0).get_string(0) ]
|
497
|
+
end
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
sdl_func :WM_SetIcon, [ :pointer, :pointer ], :void
|
502
|
+
sdl_func :WM_IconifyWindow, [ ], :int
|
503
|
+
sdl_func :WM_ToggleFullScreen, [ :pointer ], :int
|
504
|
+
|
505
|
+
|
506
|
+
GRAB_QUERY = -1
|
507
|
+
GRAB_OFF = 0
|
508
|
+
GRAB_ON = 1
|
509
|
+
GRAB_FULLSCREEN = 2
|
510
|
+
|
511
|
+
sdl_func :WM_GrabInput, [ SDL::ENUM ], SDL::ENUM
|
512
|
+
|
513
|
+
end
|