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,73 @@
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 Joystick < NiceFFI::OpaqueStruct
34
+ #--
35
+ # SDL_Joystick struct (in C) has a hidden layout.
36
+ #++
37
+ end
38
+
39
+
40
+ sdl_func :NumJoysticks, [ ], :int
41
+ sdl_func :JoystickName, [ :int ], :string
42
+ sdl_func :JoystickOpen, [ :int ], Joystick.typed_pointer
43
+ sdl_func :JoystickOpened, [ :int ], :int
44
+ sdl_func :JoystickIndex, [ :pointer ], :int
45
+
46
+ sdl_func :JoystickNumAxes, [ :pointer ], :int
47
+ sdl_func :JoystickNumBalls, [ :pointer ], :int
48
+ sdl_func :JoystickNumHats, [ :pointer ], :int
49
+ sdl_func :JoystickNumButtons, [ :pointer ], :int
50
+
51
+ sdl_func :JoystickUpdate, [ ], :void
52
+ sdl_func :JoystickEventState, [ :int ], :int
53
+ sdl_func :JoystickGetAxis, [ :pointer, :int ], :int16
54
+
55
+
56
+ HAT_CENTERED = 0x00
57
+ HAT_UP = 0x01
58
+ HAT_RIGHT = 0x02
59
+ HAT_DOWN = 0x04
60
+ HAT_LEFT = 0x08
61
+ HAT_RIGHTUP = (HAT_RIGHT|HAT_UP)
62
+ HAT_RIGHTDOWN = (HAT_RIGHT|HAT_DOWN)
63
+ HAT_LEFTUP = (HAT_LEFT |HAT_UP)
64
+ HAT_LEFTDOWN = (HAT_LEFT |HAT_DOWN)
65
+
66
+
67
+ sdl_func :JoystickGetHat, [ :pointer, :int ], :uint8
68
+ sdl_func :JoystickGetBall, [ :pointer, :int, :pointer, :pointer ], :int
69
+ sdl_func :JoystickGetButton, [ :pointer, :int ], :uint8
70
+
71
+ sdl_func :JoystickClose, [ :pointer ], :void
72
+
73
+ end
@@ -0,0 +1,66 @@
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 Keysym < NiceFFI::Struct
34
+ layout( :scancode, :uint8,
35
+ :sym, SDL::ENUM,
36
+ :mod, SDL::ENUM,
37
+ :unicode, :uint16 )
38
+ end
39
+
40
+ ALL_HOTKEYS = 0xFFFFFFFF
41
+
42
+
43
+ sdl_func :EnableUNICODE, [ :int ], :int
44
+
45
+
46
+ DEFAULT_REPEAT_DELAY = 500
47
+ DEFAULT_REPEAT_INTERVAL = 30
48
+
49
+ sdl_func :EnableKeyRepeat, [ :int, :int ], :int
50
+ sdl_func :GetKeyRepeat, [ :pointer, :pointer ], :void
51
+
52
+
53
+ func :__SDL_GetKeyState, "SDL_GetKeyState", [ :pointer ], :pointer
54
+
55
+ def self.GetKeyState()
56
+ numkeys = FFI::MemoryPointer.new( :int )
57
+ keys = __SDL_GetKeyState( numkeys )
58
+ return keys.get_array_of_uint8( 0, numkeys.get_int(0) )
59
+ end
60
+
61
+
62
+ sdl_func :GetModState, [ ], SDL::ENUM
63
+ sdl_func :SetModState, [ SDL::ENUM ], :void
64
+ sdl_func :GetKeyName, [ SDL::ENUM ], :string
65
+
66
+ end
@@ -0,0 +1,282 @@
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
+ K_FIRST = 0
34
+ K_UNKNOWN = 0
35
+ K_BACKSPACE = 8
36
+ K_TAB = 9
37
+ K_CLEAR = 12
38
+ K_RETURN = 13
39
+ K_PAUSE = 19
40
+ K_ESCAPE = 27
41
+ K_SPACE = 32
42
+ K_EXCLAIM = 33
43
+ K_QUOTEDBL = 34
44
+ K_HASH = 35
45
+ K_DOLLAR = 36
46
+ K_AMPERSAND = 38
47
+ K_QUOTE = 39
48
+ K_LEFTPAREN = 40
49
+ K_RIGHTPAREN = 41
50
+ K_ASTERISK = 42
51
+ K_PLUS = 43
52
+ K_COMMA = 44
53
+ K_MINUS = 45
54
+ K_PERIOD = 46
55
+ K_SLASH = 47
56
+ K_0 = 48
57
+ K_1 = 49
58
+ K_2 = 50
59
+ K_3 = 51
60
+ K_4 = 52
61
+ K_5 = 53
62
+ K_6 = 54
63
+ K_7 = 55
64
+ K_8 = 56
65
+ K_9 = 57
66
+ K_COLON = 58
67
+ K_SEMICOLON = 59
68
+ K_LESS = 60
69
+ K_EQUALS = 61
70
+ K_GREATER = 62
71
+ K_QUESTION = 63
72
+ K_AT = 64
73
+ K_LEFTBRACKET = 91
74
+ K_BACKSLASH = 92
75
+ K_RIGHTBRACKET = 93
76
+ K_CARET = 94
77
+ K_UNDERSCORE = 95
78
+ K_BACKQUOTE = 96
79
+ K_a = 97
80
+ K_b = 98
81
+ K_c = 99
82
+ K_d = 100
83
+ K_e = 101
84
+ K_f = 102
85
+ K_g = 103
86
+ K_h = 104
87
+ K_i = 105
88
+ K_j = 106
89
+ K_k = 107
90
+ K_l = 108
91
+ K_m = 109
92
+ K_n = 110
93
+ K_o = 111
94
+ K_p = 112
95
+ K_q = 113
96
+ K_r = 114
97
+ K_s = 115
98
+ K_t = 116
99
+ K_u = 117
100
+ K_v = 118
101
+ K_w = 119
102
+ K_x = 120
103
+ K_y = 121
104
+ K_z = 122
105
+ K_DELETE = 127
106
+ K_WORLD_0 = 160
107
+ K_WORLD_1 = 161
108
+ K_WORLD_2 = 162
109
+ K_WORLD_3 = 163
110
+ K_WORLD_4 = 164
111
+ K_WORLD_5 = 165
112
+ K_WORLD_6 = 166
113
+ K_WORLD_7 = 167
114
+ K_WORLD_8 = 168
115
+ K_WORLD_9 = 169
116
+ K_WORLD_10 = 170
117
+ K_WORLD_11 = 171
118
+ K_WORLD_12 = 172
119
+ K_WORLD_13 = 173
120
+ K_WORLD_14 = 174
121
+ K_WORLD_15 = 175
122
+ K_WORLD_16 = 176
123
+ K_WORLD_17 = 177
124
+ K_WORLD_18 = 178
125
+ K_WORLD_19 = 179
126
+ K_WORLD_20 = 180
127
+ K_WORLD_21 = 181
128
+ K_WORLD_22 = 182
129
+ K_WORLD_23 = 183
130
+ K_WORLD_24 = 184
131
+ K_WORLD_25 = 185
132
+ K_WORLD_26 = 186
133
+ K_WORLD_27 = 187
134
+ K_WORLD_28 = 188
135
+ K_WORLD_29 = 189
136
+ K_WORLD_30 = 190
137
+ K_WORLD_31 = 191
138
+ K_WORLD_32 = 192
139
+ K_WORLD_33 = 193
140
+ K_WORLD_34 = 194
141
+ K_WORLD_35 = 195
142
+ K_WORLD_36 = 196
143
+ K_WORLD_37 = 197
144
+ K_WORLD_38 = 198
145
+ K_WORLD_39 = 199
146
+ K_WORLD_40 = 200
147
+ K_WORLD_41 = 201
148
+ K_WORLD_42 = 202
149
+ K_WORLD_43 = 203
150
+ K_WORLD_44 = 204
151
+ K_WORLD_45 = 205
152
+ K_WORLD_46 = 206
153
+ K_WORLD_47 = 207
154
+ K_WORLD_48 = 208
155
+ K_WORLD_49 = 209
156
+ K_WORLD_50 = 210
157
+ K_WORLD_51 = 211
158
+ K_WORLD_52 = 212
159
+ K_WORLD_53 = 213
160
+ K_WORLD_54 = 214
161
+ K_WORLD_55 = 215
162
+ K_WORLD_56 = 216
163
+ K_WORLD_57 = 217
164
+ K_WORLD_58 = 218
165
+ K_WORLD_59 = 219
166
+ K_WORLD_60 = 220
167
+ K_WORLD_61 = 221
168
+ K_WORLD_62 = 222
169
+ K_WORLD_63 = 223
170
+ K_WORLD_64 = 224
171
+ K_WORLD_65 = 225
172
+ K_WORLD_66 = 226
173
+ K_WORLD_67 = 227
174
+ K_WORLD_68 = 228
175
+ K_WORLD_69 = 229
176
+ K_WORLD_70 = 230
177
+ K_WORLD_71 = 231
178
+ K_WORLD_72 = 232
179
+ K_WORLD_73 = 233
180
+ K_WORLD_74 = 234
181
+ K_WORLD_75 = 235
182
+ K_WORLD_76 = 236
183
+ K_WORLD_77 = 237
184
+ K_WORLD_78 = 238
185
+ K_WORLD_79 = 239
186
+ K_WORLD_80 = 240
187
+ K_WORLD_81 = 241
188
+ K_WORLD_82 = 242
189
+ K_WORLD_83 = 243
190
+ K_WORLD_84 = 244
191
+ K_WORLD_85 = 245
192
+ K_WORLD_86 = 246
193
+ K_WORLD_87 = 247
194
+ K_WORLD_88 = 248
195
+ K_WORLD_89 = 249
196
+ K_WORLD_90 = 250
197
+ K_WORLD_91 = 251
198
+ K_WORLD_92 = 252
199
+ K_WORLD_93 = 253
200
+ K_WORLD_94 = 254
201
+ K_WORLD_95 = 255
202
+ K_KP0 = 256
203
+ K_KP1 = 257
204
+ K_KP2 = 258
205
+ K_KP3 = 259
206
+ K_KP4 = 260
207
+ K_KP5 = 261
208
+ K_KP6 = 262
209
+ K_KP7 = 263
210
+ K_KP8 = 264
211
+ K_KP9 = 265
212
+ K_KP_PERIOD = 266
213
+ K_KP_DIVIDE = 267
214
+ K_KP_MULTIPLY = 268
215
+ K_KP_MINUS = 269
216
+ K_KP_PLUS = 270
217
+ K_KP_ENTER = 271
218
+ K_KP_EQUALS = 272
219
+ K_UP = 273
220
+ K_DOWN = 274
221
+ K_RIGHT = 275
222
+ K_LEFT = 276
223
+ K_INSERT = 277
224
+ K_HOME = 278
225
+ K_END = 279
226
+ K_PAGEUP = 280
227
+ K_PAGEDOWN = 281
228
+ K_F1 = 282
229
+ K_F2 = 283
230
+ K_F3 = 284
231
+ K_F4 = 285
232
+ K_F5 = 286
233
+ K_F6 = 287
234
+ K_F7 = 288
235
+ K_F8 = 289
236
+ K_F9 = 290
237
+ K_F10 = 291
238
+ K_F11 = 292
239
+ K_F12 = 293
240
+ K_F13 = 294
241
+ K_F14 = 295
242
+ K_F15 = 296
243
+ K_NUMLOCK = 300
244
+ K_CAPSLOCK = 301
245
+ K_SCROLLOCK = 302
246
+ K_RSHIFT = 303
247
+ K_LSHIFT = 304
248
+ K_RCTRL = 305
249
+ K_LCTRL = 306
250
+ K_RALT = 307
251
+ K_LALT = 308
252
+ K_RMETA = 309
253
+ K_LMETA = 310
254
+ K_LSUPER = 311
255
+ K_RSUPER = 312
256
+ K_MODE = 313
257
+ K_COMPOSE = 314
258
+ K_HELP = 315
259
+ K_PRINT = 316
260
+ K_SYSREQ = 317
261
+ K_BREAK = 318
262
+ K_MENU = 319
263
+ K_POWER = 320
264
+ K_EURO = 321
265
+ K_UNDO = 322
266
+ K_LAST = 323
267
+
268
+ KMOD_NONE = 0x0000
269
+ KMOD_LSHIFT = 0x0001
270
+ KMOD_RSHIFT = 0x0002
271
+ KMOD_LCTRL = 0x0040
272
+ KMOD_RCTRL = 0x0080
273
+ KMOD_LALT = 0x0100
274
+ KMOD_RALT = 0x0200
275
+ KMOD_LMETA = 0x0400
276
+ KMOD_RMETA = 0x0800
277
+ KMOD_NUM = 0x1000
278
+ KMOD_CAPS = 0x2000
279
+ KMOD_MODE = 0x4000
280
+ KMOD_RESERVED = 0x8000
281
+
282
+ end
@@ -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
+ [ :pointer, :pointer ], :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::MemoryPointer.new( :int )
59
+ ymp = FFI::MemoryPointer.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
+ [ :pointer, :pointer ], :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::MemoryPointer.new( :int )
74
+ ymp = FFI::MemoryPointer.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