hybridgroup-ruby-sdl-ffi 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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