gosu 1.4.6 → 2.0.0.pre6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +2 -1
  3. data/dependencies/SDL/include/SDL_atomic.h +2 -3
  4. data/dependencies/SDL/include/SDL_audio.h +7 -7
  5. data/dependencies/SDL/include/SDL_blendmode.h +1 -1
  6. data/dependencies/SDL/include/SDL_endian.h +3 -3
  7. data/dependencies/SDL/include/SDL_gamecontroller.h +4 -4
  8. data/dependencies/SDL/include/SDL_hints.h +72 -28
  9. data/dependencies/SDL/include/SDL_joystick.h +8 -5
  10. data/dependencies/SDL/include/SDL_keycode.h +1 -1
  11. data/dependencies/SDL/include/SDL_main.h +7 -0
  12. data/dependencies/SDL/include/SDL_mouse.h +6 -7
  13. data/dependencies/SDL/include/SDL_mutex.h +79 -5
  14. data/dependencies/SDL/include/SDL_opengl_glext.h +5 -1
  15. data/dependencies/SDL/include/SDL_power.h +7 -8
  16. data/dependencies/SDL/include/SDL_render.h +5 -0
  17. data/dependencies/SDL/include/SDL_revision.h +2 -2
  18. data/dependencies/SDL/include/SDL_sensor.h +1 -1
  19. data/dependencies/SDL/include/SDL_stdinc.h +19 -11
  20. data/dependencies/SDL/include/SDL_thread.h +2 -2
  21. data/dependencies/SDL/include/SDL_version.h +2 -2
  22. data/dependencies/SDL/include/SDL_video.h +30 -2
  23. data/dependencies/SDL/include/begin_code.h +7 -7
  24. data/dependencies/SDL/include/close_code.h +2 -2
  25. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  26. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  27. data/dependencies/SDL_sound/SDL_sound.h +1 -1
  28. data/dependencies/SDL_sound/dr_flac.h +48 -23
  29. data/dependencies/SDL_sound/dr_mp3.h +34 -14
  30. data/dependencies/SDL_sound/stb_vorbis.h +3 -2
  31. data/dependencies/mojoAL/mojoal.c +1 -1
  32. data/ext/{gosu → gosu-ffi}/extconf.rb +34 -33
  33. data/ext/gosu-ffi/gosu-ffi.def +464 -0
  34. data/ffi/Gosu.cpp +307 -0
  35. data/ffi/Gosu.h +84 -0
  36. data/ffi/Gosu_Channel.cpp +62 -0
  37. data/ffi/Gosu_Channel.h +17 -0
  38. data/ffi/Gosu_Color.cpp +132 -0
  39. data/ffi/Gosu_Color.h +31 -0
  40. data/ffi/Gosu_Constants.cpp +334 -0
  41. data/ffi/Gosu_FFI.h +34 -0
  42. data/ffi/Gosu_FFI_internal.h +161 -0
  43. data/ffi/Gosu_Font.cpp +92 -0
  44. data/ffi/Gosu_Font.h +32 -0
  45. data/ffi/Gosu_Image.cpp +206 -0
  46. data/ffi/Gosu_Image.h +60 -0
  47. data/ffi/Gosu_Sample.cpp +29 -0
  48. data/ffi/Gosu_Sample.h +14 -0
  49. data/ffi/Gosu_Song.cpp +69 -0
  50. data/ffi/Gosu_Song.h +18 -0
  51. data/ffi/Gosu_TextInput.cpp +94 -0
  52. data/ffi/Gosu_TextInput.h +25 -0
  53. data/ffi/Gosu_Window.cpp +314 -0
  54. data/ffi/Gosu_Window.h +78 -0
  55. data/include/Gosu/Audio.hpp +6 -11
  56. data/include/Gosu/Bitmap.hpp +38 -53
  57. data/include/Gosu/Buffer.hpp +54 -0
  58. data/include/Gosu/Color.hpp +27 -35
  59. data/include/Gosu/Directories.hpp +25 -28
  60. data/include/Gosu/Drawable.hpp +58 -0
  61. data/include/Gosu/Font.hpp +6 -5
  62. data/include/Gosu/Fwd.hpp +4 -6
  63. data/include/Gosu/Gosu.hpp +5 -5
  64. data/include/Gosu/Graphics.hpp +51 -61
  65. data/include/Gosu/GraphicsBase.hpp +1 -11
  66. data/include/Gosu/Image.hpp +11 -14
  67. data/include/Gosu/Math.hpp +50 -72
  68. data/include/Gosu/Transform.hpp +32 -0
  69. data/include/Gosu/Utility.hpp +51 -1
  70. data/include/Gosu/Version.hpp +3 -3
  71. data/include/Gosu/Window.hpp +15 -9
  72. data/lib/SDL2.dll +0 -0
  73. data/lib/gosu/channel.rb +49 -0
  74. data/lib/gosu/color.rb +150 -0
  75. data/lib/gosu/compat.rb +29 -8
  76. data/lib/gosu/constants.rb +386 -0
  77. data/lib/gosu/ffi.rb +258 -0
  78. data/lib/gosu/font.rb +56 -0
  79. data/lib/gosu/gl_tex_info.rb +33 -0
  80. data/lib/gosu/gosu.rb +210 -0
  81. data/lib/gosu/image.rb +141 -0
  82. data/lib/gosu/numeric.rb +17 -0
  83. data/lib/gosu/preview.rb +6 -6
  84. data/lib/gosu/sample.rb +24 -0
  85. data/lib/gosu/song.rb +56 -0
  86. data/lib/gosu/text_input.rb +69 -0
  87. data/lib/gosu/window.rb +228 -0
  88. data/lib/gosu.rb +29 -8
  89. data/lib64/SDL2.dll +0 -0
  90. data/rdoc/gosu.rb +0 -2
  91. data/src/Audio.cpp +12 -12
  92. data/src/AudioFile.hpp +5 -4
  93. data/src/AudioFileAudioToolbox.cpp +8 -8
  94. data/src/AudioFileSDLSound.cpp +7 -10
  95. data/src/BinPacker.cpp +187 -0
  96. data/src/BinPacker.hpp +55 -0
  97. data/src/Bitmap.cpp +166 -144
  98. data/src/BitmapIO.cpp +60 -86
  99. data/src/Buffer.cpp +159 -0
  100. data/src/Color.cpp +75 -80
  101. data/src/Directories.cpp +47 -0
  102. data/src/DirectoriesUIKit.cpp +50 -0
  103. data/src/DrawOp.hpp +9 -4
  104. data/src/DrawOpQueue.hpp +2 -2
  105. data/src/Drawable.cpp +95 -0
  106. data/src/EmptyDrawable.hpp +38 -0
  107. data/src/FPS.cpp +31 -0
  108. data/src/Font.cpp +104 -74
  109. data/src/GosuGLView.cpp +14 -6
  110. data/src/GosuViewController.cpp +2 -10
  111. data/src/Graphics.cpp +60 -126
  112. data/src/GraphicsImpl.hpp +17 -47
  113. data/src/Image.cpp +41 -35
  114. data/src/Input.cpp +7 -8
  115. data/src/Macro.cpp +6 -6
  116. data/src/Macro.hpp +4 -4
  117. data/src/MarkupParser.cpp +5 -5
  118. data/src/Math.cpp +35 -22
  119. data/src/OffScreenTarget.cpp +53 -49
  120. data/src/OffScreenTarget.hpp +13 -11
  121. data/src/OpenGLContext.cpp +117 -0
  122. data/src/OpenGLContext.hpp +41 -0
  123. data/src/RenderState.hpp +21 -19
  124. data/src/Resolution.cpp +23 -21
  125. data/src/TexChunk.cpp +35 -80
  126. data/src/TexChunk.hpp +44 -35
  127. data/src/Text.cpp +1 -1
  128. data/src/TextBuilder.cpp +35 -21
  129. data/src/TextBuilder.hpp +6 -9
  130. data/src/Texture.cpp +62 -80
  131. data/src/Texture.hpp +25 -23
  132. data/src/TiledDrawable.cpp +150 -0
  133. data/src/TiledDrawable.hpp +47 -0
  134. data/src/TimingApple.cpp +1 -1
  135. data/src/Transform.cpp +45 -50
  136. data/src/TransformStack.hpp +16 -16
  137. data/src/TrueTypeFont.cpp +59 -51
  138. data/src/TrueTypeFont.hpp +6 -7
  139. data/src/TrueTypeFontApple.cpp +28 -19
  140. data/src/TrueTypeFontUnix.cpp +27 -23
  141. data/src/TrueTypeFontWin.cpp +30 -30
  142. data/src/Utility.cpp +84 -21
  143. data/src/UtilityWin.cpp +45 -0
  144. data/src/Window.cpp +92 -142
  145. data/src/WindowUIKit.cpp +14 -14
  146. metadata +72 -31
  147. data/include/Gosu/IO.hpp +0 -254
  148. data/include/Gosu/ImageData.hpp +0 -53
  149. data/include/Gosu/Inspection.hpp +0 -7
  150. data/lib/gosu/patches.rb +0 -66
  151. data/lib/gosu/run.rb +0 -20
  152. data/lib/gosu/swig_patches.rb +0 -110
  153. data/src/BlockAllocator.cpp +0 -131
  154. data/src/BlockAllocator.hpp +0 -32
  155. data/src/DirectoriesApple.cpp +0 -69
  156. data/src/DirectoriesUnix.cpp +0 -46
  157. data/src/DirectoriesWin.cpp +0 -65
  158. data/src/EmptyImageData.hpp +0 -52
  159. data/src/FileUnix.cpp +0 -99
  160. data/src/FileWin.cpp +0 -88
  161. data/src/IO.cpp +0 -60
  162. data/src/Iconv.hpp +0 -51
  163. data/src/Inspection.cpp +0 -27
  164. data/src/LargeImageData.cpp +0 -215
  165. data/src/LargeImageData.hpp +0 -39
  166. data/src/Log.hpp +0 -19
  167. data/src/RubyGosu.cxx +0 -13100
  168. data/src/RubyGosu.h +0 -49
  169. data/src/WinUtility.cpp +0 -61
  170. data/src/WinUtility.hpp +0 -27
@@ -0,0 +1,386 @@
1
+ module GosuFFI
2
+ # uint32
3
+ constants = [
4
+ "KB_ESCAPE",
5
+ "KB_F1",
6
+ "KB_F2",
7
+ "KB_F3",
8
+ "KB_F4",
9
+ "KB_F5",
10
+ "KB_F6",
11
+ "KB_F7",
12
+ "KB_F8",
13
+ "KB_F9",
14
+ "KB_F10",
15
+ "KB_F11",
16
+ "KB_F12",
17
+ "KB_0",
18
+ "KB_1",
19
+ "KB_2",
20
+ "KB_3",
21
+ "KB_4",
22
+ "KB_5",
23
+ "KB_6",
24
+ "KB_7",
25
+ "KB_8",
26
+ "KB_9",
27
+ "KB_TAB",
28
+ "KB_RETURN",
29
+ "KB_SPACE",
30
+ "KB_LEFT_SHIFT",
31
+ "KB_RIGHT_SHIFT",
32
+ "KB_LEFT_CONTROL",
33
+ "KB_RIGHT_CONTROL",
34
+ "KB_LEFT_ALT",
35
+ "KB_RIGHT_ALT",
36
+ "KB_LEFT_META",
37
+ "KB_RIGHT_META",
38
+ "KB_BACKSPACE",
39
+ "KB_LEFT",
40
+ "KB_RIGHT",
41
+ "KB_UP",
42
+ "KB_DOWN",
43
+ "KB_HOME",
44
+ "KB_END",
45
+ "KB_PRINT_SCREEN",
46
+ "KB_SCROLL_LOCK",
47
+ "KB_PAUSE",
48
+ "KB_INSERT",
49
+ "KB_DELETE",
50
+ "KB_PAGE_UP",
51
+ "KB_PAGE_DOWN",
52
+ "KB_ENTER",
53
+ "KB_BACKTICK",
54
+ "KB_MINUS",
55
+ "KB_EQUALS",
56
+ "KB_LEFT_BRACKET",
57
+ "KB_RIGHT_BRACKET",
58
+ "KB_BACKSLASH",
59
+ "KB_SEMICOLON",
60
+ "KB_APOSTROPHE",
61
+ "KB_COMMA",
62
+ "KB_PERIOD",
63
+ "KB_SLASH",
64
+ "KB_CAPS_LOCK",
65
+ "KB_A",
66
+ "KB_B",
67
+ "KB_C",
68
+ "KB_D",
69
+ "KB_E",
70
+ "KB_F",
71
+ "KB_G",
72
+ "KB_H",
73
+ "KB_I",
74
+ "KB_J",
75
+ "KB_K",
76
+ "KB_L",
77
+ "KB_M",
78
+ "KB_N",
79
+ "KB_O",
80
+ "KB_P",
81
+ "KB_Q",
82
+ "KB_R",
83
+ "KB_S",
84
+ "KB_T",
85
+ "KB_U",
86
+ "KB_V",
87
+ "KB_W",
88
+ "KB_X",
89
+ "KB_Y",
90
+ "KB_Z",
91
+ "KB_ISO",
92
+ "KB_NUMPAD_0",
93
+ "KB_NUMPAD_1",
94
+ "KB_NUMPAD_2",
95
+ "KB_NUMPAD_3",
96
+ "KB_NUMPAD_4",
97
+ "KB_NUMPAD_5",
98
+ "KB_NUMPAD_6",
99
+ "KB_NUMPAD_7",
100
+ "KB_NUMPAD_8",
101
+ "KB_NUMPAD_9",
102
+ "KB_NUMPAD_DELETE",
103
+ "KB_NUMPAD_PLUS",
104
+ "KB_NUMPAD_MINUS",
105
+ "KB_NUMPAD_MULTIPLY",
106
+ "KB_NUMPAD_DIVIDE",
107
+
108
+ "MS_LEFT",
109
+ "MS_MIDDLE",
110
+ "MS_RIGHT",
111
+ "MS_WHEEL_UP",
112
+ "MS_WHEEL_DOWN",
113
+ "MS_OTHER_0",
114
+ "MS_OTHER_1",
115
+ "MS_OTHER_2",
116
+ "MS_OTHER_3",
117
+ "MS_OTHER_4",
118
+ "MS_OTHER_5",
119
+ "MS_OTHER_6",
120
+ "MS_OTHER_7",
121
+
122
+ "GP_DPAD_LEFT",
123
+ "GP_DPAD_RIGHT",
124
+ "GP_DPAD_UP",
125
+ "GP_DPAD_DOWN",
126
+ "GP_LEFT",
127
+ "GP_RIGHT",
128
+ "GP_UP",
129
+ "GP_DOWN",
130
+ "GP_BUTTON_0",
131
+ "GP_BUTTON_1",
132
+ "GP_BUTTON_2",
133
+ "GP_BUTTON_3",
134
+ "GP_BUTTON_4",
135
+ "GP_BUTTON_5",
136
+ "GP_BUTTON_6",
137
+ "GP_BUTTON_7",
138
+ "GP_BUTTON_8",
139
+ "GP_BUTTON_9",
140
+ "GP_BUTTON_10",
141
+ "GP_BUTTON_11",
142
+ "GP_BUTTON_12",
143
+ "GP_BUTTON_13",
144
+ "GP_BUTTON_14",
145
+ "GP_BUTTON_15",
146
+
147
+ "GP_0_DPAD_LEFT",
148
+ "GP_0_DPAD_RIGHT",
149
+ "GP_0_DPAD_UP",
150
+ "GP_0_DPAD_DOWN",
151
+ "GP_0_LEFT",
152
+ "GP_0_RIGHT",
153
+ "GP_0_UP",
154
+ "GP_0_DOWN",
155
+ "GP_0_BUTTON_0",
156
+ "GP_0_BUTTON_1",
157
+ "GP_0_BUTTON_2",
158
+ "GP_0_BUTTON_3",
159
+ "GP_0_BUTTON_4",
160
+ "GP_0_BUTTON_5",
161
+ "GP_0_BUTTON_6",
162
+ "GP_0_BUTTON_7",
163
+ "GP_0_BUTTON_8",
164
+ "GP_0_BUTTON_9",
165
+ "GP_0_BUTTON_10",
166
+ "GP_0_BUTTON_11",
167
+ "GP_0_BUTTON_12",
168
+ "GP_0_BUTTON_13",
169
+ "GP_0_BUTTON_14",
170
+ "GP_0_BUTTON_15",
171
+
172
+ "GP_1_DPAD_LEFT",
173
+ "GP_1_DPAD_RIGHT",
174
+ "GP_1_DPAD_UP",
175
+ "GP_1_DPAD_DOWN",
176
+ "GP_1_LEFT",
177
+ "GP_1_RIGHT",
178
+ "GP_1_UP",
179
+ "GP_1_DOWN",
180
+ "GP_1_BUTTON_0",
181
+ "GP_1_BUTTON_1",
182
+ "GP_1_BUTTON_2",
183
+ "GP_1_BUTTON_3",
184
+ "GP_1_BUTTON_4",
185
+ "GP_1_BUTTON_5",
186
+ "GP_1_BUTTON_6",
187
+ "GP_1_BUTTON_7",
188
+ "GP_1_BUTTON_8",
189
+ "GP_1_BUTTON_9",
190
+ "GP_1_BUTTON_10",
191
+ "GP_1_BUTTON_11",
192
+ "GP_1_BUTTON_12",
193
+ "GP_1_BUTTON_13",
194
+ "GP_1_BUTTON_14",
195
+ "GP_1_BUTTON_15",
196
+
197
+ "GP_2_DPAD_LEFT",
198
+ "GP_2_DPAD_RIGHT",
199
+ "GP_2_DPAD_UP",
200
+ "GP_2_DPAD_DOWN",
201
+ "GP_2_LEFT",
202
+ "GP_2_RIGHT",
203
+ "GP_2_UP",
204
+ "GP_2_DOWN",
205
+ "GP_2_BUTTON_0",
206
+ "GP_2_BUTTON_1",
207
+ "GP_2_BUTTON_2",
208
+ "GP_2_BUTTON_3",
209
+ "GP_2_BUTTON_4",
210
+ "GP_2_BUTTON_5",
211
+ "GP_2_BUTTON_6",
212
+ "GP_2_BUTTON_7",
213
+ "GP_2_BUTTON_8",
214
+ "GP_2_BUTTON_9",
215
+ "GP_2_BUTTON_10",
216
+ "GP_2_BUTTON_11",
217
+ "GP_2_BUTTON_12",
218
+ "GP_2_BUTTON_13",
219
+ "GP_2_BUTTON_14",
220
+ "GP_2_BUTTON_15",
221
+
222
+ "GP_3_DPAD_LEFT",
223
+ "GP_3_DPAD_RIGHT",
224
+ "GP_3_DPAD_UP",
225
+ "GP_3_DPAD_DOWN",
226
+ "GP_3_LEFT",
227
+ "GP_3_RIGHT",
228
+ "GP_3_UP",
229
+ "GP_3_DOWN",
230
+ "GP_3_BUTTON_0",
231
+ "GP_3_BUTTON_1",
232
+ "GP_3_BUTTON_2",
233
+ "GP_3_BUTTON_3",
234
+ "GP_3_BUTTON_4",
235
+ "GP_3_BUTTON_5",
236
+ "GP_3_BUTTON_6",
237
+ "GP_3_BUTTON_7",
238
+ "GP_3_BUTTON_8",
239
+ "GP_3_BUTTON_9",
240
+ "GP_3_BUTTON_10",
241
+ "GP_3_BUTTON_11",
242
+ "GP_3_BUTTON_12",
243
+ "GP_3_BUTTON_13",
244
+ "GP_3_BUTTON_14",
245
+ "GP_3_BUTTON_15",
246
+
247
+ "GP_LEFT_STICK_X_AXIS",
248
+ "GP_LEFT_STICK_Y_AXIS",
249
+ "GP_RIGHT_STICK_X_AXIS",
250
+ "GP_RIGHT_STICK_Y_AXIS",
251
+ "GP_LEFT_TRIGGER_AXIS",
252
+ "GP_RIGHT_TRIGGER_AXIS",
253
+
254
+ "GP_0_LEFT_STICK_X_AXIS",
255
+ "GP_0_LEFT_STICK_Y_AXIS",
256
+ "GP_0_RIGHT_STICK_X_AXIS",
257
+ "GP_0_RIGHT_STICK_Y_AXIS",
258
+ "GP_0_LEFT_TRIGGER_AXIS",
259
+ "GP_0_RIGHT_TRIGGER_AXIS",
260
+
261
+ "GP_1_LEFT_STICK_X_AXIS",
262
+ "GP_1_LEFT_STICK_Y_AXIS",
263
+ "GP_1_RIGHT_STICK_X_AXIS",
264
+ "GP_1_RIGHT_STICK_Y_AXIS",
265
+ "GP_1_LEFT_TRIGGER_AXIS",
266
+ "GP_1_RIGHT_TRIGGER_AXIS",
267
+
268
+ "GP_2_LEFT_STICK_X_AXIS",
269
+ "GP_2_LEFT_STICK_Y_AXIS",
270
+ "GP_2_RIGHT_STICK_X_AXIS",
271
+ "GP_2_RIGHT_STICK_Y_AXIS",
272
+ "GP_2_LEFT_TRIGGER_AXIS",
273
+ "GP_2_RIGHT_TRIGGER_AXIS",
274
+
275
+ "GP_3_LEFT_STICK_X_AXIS",
276
+ "GP_3_LEFT_STICK_Y_AXIS",
277
+ "GP_3_RIGHT_STICK_X_AXIS",
278
+ "GP_3_RIGHT_STICK_Y_AXIS",
279
+ "GP_3_LEFT_TRIGGER_AXIS",
280
+ "GP_3_RIGHT_TRIGGER_AXIS",
281
+ ]
282
+
283
+ constants = constants + [
284
+ "MAJOR_VERSION",
285
+ "MINOR_VERSION",
286
+ "POINT_VERSION",
287
+ ]
288
+
289
+ constants = constants + [
290
+ "WF_WINDOWED",
291
+ "WF_FULLSCREEN",
292
+ "WF_RESIZABLE",
293
+ "WF_BORDERLESS",
294
+
295
+ "BM_DEFAULT",
296
+ "BM_INTERPOLATE",
297
+ "BM_ADD",
298
+ "BM_MULTIPLY",
299
+
300
+ "FF_BOLD",
301
+ "FF_ITALIC",
302
+ "FF_UNDERLINE",
303
+ "FF_COMBINATIONS",
304
+
305
+ "AL_LEFT",
306
+ "AL_RIGHT",
307
+ "AL_CENTER",
308
+ "AL_JUSTIFY",
309
+
310
+ "IF_SMOOTH",
311
+ "IF_TILEABLE_LEFT",
312
+ "IF_TILEABLE_TOP",
313
+ "IF_TILEABLE_RIGHT",
314
+ "IF_TILEABLE_BOTTOM",
315
+ "IF_TILEABLE",
316
+ "IF_RETRO",
317
+ ]
318
+
319
+ constants.each do |const|
320
+ attach_variable const, "Gosu_#{const}", :uint32
321
+ Gosu.const_set(const, GosuFFI.send(const)) if const =~ /^(KB|MS|GP)_/
322
+ end
323
+
324
+ Gosu.const_set("VERSION", GosuFFI.Gosu_version())
325
+ Gosu.const_set("LICENSES", GosuFFI.Gosu_licenses())
326
+ Gosu.const_set("MAJOR_VERSION", GosuFFI.MAJOR_VERSION)
327
+ Gosu.const_set("MINOR_VERSION", GosuFFI.MINOR_VERSION)
328
+ Gosu.const_set("POINT_VERSION", GosuFFI.POINT_VERSION)
329
+
330
+ # SEE: https://github.com/gosu/gosu/blob/master/Gosu/GraphicsBase.hpp
331
+
332
+ def self.blend_mode(mode)
333
+ case mode
334
+ when :default
335
+ GosuFFI.BM_DEFAULT
336
+ when :additive, :add
337
+ GosuFFI.BM_ADD
338
+ when :multiply
339
+ GosuFFI.BM_MULTIPLY
340
+ when Numeric
341
+ mode
342
+ else
343
+ raise ArgumentError, "No such blend mode: #{mode}"
344
+ end
345
+ end
346
+
347
+ def self.image_flags(retro: false, tileable: false)
348
+ flags = 0
349
+ flags |= GosuFFI.IF_RETRO if retro
350
+ flags |= GosuFFI.IF_TILEABLE if tileable
351
+ flags
352
+ end
353
+
354
+ def self.font_alignment_flags(flags)
355
+ case flags
356
+ when :left
357
+ GosuFFI.AL_LEFT
358
+ when :right
359
+ GosuFFI.AL_RIGHT
360
+ when :center
361
+ GosuFFI.AL_CENTER
362
+ when :justify
363
+ GosuFFI.AL_JUSTIFY
364
+ when Numeric
365
+ flags
366
+ else
367
+ raise ArgumentError, "No such font alignment: #{flags}"
368
+ end
369
+ end
370
+
371
+ def self.font_flags(bold, italic, underline)
372
+ flags = 0
373
+ flags |= GosuFFI.FF_BOLD if bold
374
+ flags |= GosuFFI.FF_ITALIC if italic
375
+ flags |= GosuFFI.FF_UNDERLINE if underline
376
+ flags
377
+ end
378
+
379
+ def self.window_flags(fullscreen: false, resizable: false, borderless: false)
380
+ flags = GosuFFI.WF_WINDOWED
381
+ flags |= GosuFFI.WF_FULLSCREEN if fullscreen
382
+ flags |= GosuFFI.WF_RESIZABLE if resizable
383
+ flags |= GosuFFI.WF_BORDERLESS if borderless
384
+ flags
385
+ end
386
+ end
data/lib/gosu/ffi.rb ADDED
@@ -0,0 +1,258 @@
1
+ module GosuFFI
2
+ extend FFI::Library
3
+
4
+ # Load gosu.{so,bundle,dylib} which was built by extconf.rb.
5
+ # (Inspired by https://github.com/dbalatero/levenshtein-ffi/pull/11)
6
+ # It might be useful to also allow loading Gosu installed as a system library, e.g.:
7
+ # "/usr/local/lib/libgosu-ffi.dylib", # Homebrew on macOS (Intel) or manual installation
8
+ # "/opt/homebrew/lib/libgosu-ffi.dylib", # Homebrew on macOS (Apple Silicon)
9
+ # ...or built locally, for testing without having to re-install the gem:
10
+ # File.expand_path("../../gosu/build/ffi/libgosu-ffi.so", __dir__),
11
+ # File.expand_path("../../gosu/lib64/gosu-ffi.dll", __dir__),
12
+ library = "gosu-ffi.#{RbConfig::MAKEFILE_CONFIG["DLEXT"]}"
13
+ candidates = ["#{__dir__}/..", "#{__dir__}/../../ext/gosu-ffi"]
14
+ candidates.prepend(Gem.loaded_specs["gosu"].extension_dir) if Gem.loaded_specs["gosu"]
15
+ ffi_lib(candidates.map { |dir| File.expand_path(library, dir) })
16
+
17
+ callback :_callback, [:pointer], :void
18
+ callback :_callback_with_image, [:pointer, :pointer], :void
19
+ callback :_callback_with_unsigned, [:pointer, :uint32], :void
20
+ callback :_callback_with_string, [:pointer, :string], :void
21
+ callback :_callback_returns_bool, [:pointer], :bool
22
+ callback :_callback_hit_test_returns_unsigned, [:pointer, :int, :int], :uint32
23
+
24
+ attach_function :Gosu_fps, [], :int
25
+ attach_function :Gosu_flush, [], :void
26
+ attach_function :Gosu_milliseconds, [], :long
27
+ attach_function :Gosu_default_font_name, [], :string
28
+ attach_function :Gosu_user_languages, [:_callback_with_string, :pointer], :void
29
+
30
+ attach_function :Gosu_transform, [:double, :double, :double, :double, :double, :double, :double, :double,
31
+ :double, :double, :double, :double, :double, :double, :double, :double,
32
+ :_callback], :void
33
+ attach_function :Gosu_translate, [:double, :double, :_callback], :void
34
+ attach_function :Gosu_rotate, [:double, :double, :double, :_callback], :void
35
+ attach_function :Gosu_scale, [:double, :double, :double, :double, :_callback], :void
36
+ attach_function :Gosu_clip_to, [:double, :double, :double, :double, :_callback], :void
37
+
38
+ attach_function :Gosu_gl_z, [:double, :_callback], :void
39
+ attach_function :Gosu_gl, [:_callback], :void
40
+ attach_function :Gosu_render, [:int, :int, :_callback, :uint32], :pointer
41
+ attach_function :Gosu_record, [:int, :int, :_callback], :pointer
42
+
43
+ attach_function :Gosu_button_down, [:uint32], :bool
44
+ attach_function :Gosu_axis, [:uint32], :double
45
+ attach_function :Gosu_button_id_to_char, [:uint32], :string
46
+ attach_function :Gosu_button_char_to_id, [:string], :uint32
47
+ attach_function :Gosu_button_name, [:uint32], :string
48
+ attach_function :Gosu_gamepad_name, [:uint32], :string
49
+
50
+ attach_function :Gosu_clipboard, [], :string
51
+ attach_function :Gosu_set_clipboard, [:string], :void
52
+
53
+ attach_function :Gosu_draw_line, [:double, :double, :uint32, :double, :double, :uint32, :double, :uint32], :void
54
+ attach_function :Gosu_draw_triangle, [:double, :double, :uint32, :double, :double, :uint32,
55
+ :double, :double, :uint32, :double, :uint32], :void
56
+ attach_function :Gosu_draw_quad, [:double, :double, :uint32, :double, :double, :uint32,
57
+ :double, :double, :uint32, :double, :double, :uint32, :double, :uint32], :void
58
+ attach_function :Gosu_draw_rect, [:double, :double, :double, :double, :uint32, :double, :uint32], :void
59
+
60
+ attach_function :Gosu_offset_x, [:double, :double], :double
61
+ attach_function :Gosu_offset_y, [:double, :double], :double
62
+ attach_function :Gosu_distance, [:double, :double, :double, :double], :double
63
+ attach_function :Gosu_angle, [:double, :double, :double, :double], :double
64
+ attach_function :Gosu_angle_diff, [:double, :double], :double
65
+ attach_function :Gosu_random, [:double, :double], :double
66
+
67
+ attach_function :Gosu_screen_width, [:pointer], :uint32
68
+ attach_function :Gosu_screen_height, [:pointer], :uint32
69
+ attach_function :Gosu_available_width, [:pointer], :uint32
70
+ attach_function :Gosu_available_height, [:pointer], :uint32
71
+
72
+ attach_function :Gosu_last_error, [], :string
73
+
74
+ attach_function :Gosu_version, [], :string
75
+ attach_function :Gosu_licenses, [], :string
76
+
77
+ attach_function :Gosu_Channel_destroy, [:pointer], :void
78
+
79
+ attach_function :Gosu_Channel_playing, [:pointer], :bool
80
+ attach_function :Gosu_Channel_pause, [:pointer], :void
81
+ attach_function :Gosu_Channel_paused, [:pointer], :bool
82
+ attach_function :Gosu_Channel_resume, [:pointer], :void
83
+ attach_function :Gosu_Channel_stop, [:pointer], :void
84
+ attach_function :Gosu_Channel_set_volume, [:pointer, :double], :void
85
+ attach_function :Gosu_Channel_set_speed, [:pointer, :double], :void
86
+ attach_function :Gosu_Channel_set_pan, [:pointer, :double], :void
87
+
88
+ attach_function :Gosu_Color_create, [:uint32], :uint32
89
+ attach_function :Gosu_Color_create_argb, [:uchar, :uchar, :uchar, :uchar], :uint32
90
+ attach_function :Gosu_Color_create_from_ahsv, [:uchar, :double, :double, :double], :uint32
91
+ attach_function :Gosu_Color_create_from_hsv, [:double, :double, :double], :uint32
92
+
93
+ attach_function :Gosu_Color_alpha, [:uint32], :uchar
94
+ attach_function :Gosu_Color_red, [:uint32], :uchar
95
+ attach_function :Gosu_Color_green, [:uint32], :uchar
96
+ attach_function :Gosu_Color_blue, [:uint32], :uchar
97
+
98
+ attach_function :Gosu_Color_set_alpha, [:uint32, :uchar], :uint32
99
+ attach_function :Gosu_Color_set_red, [:uint32, :uchar], :uint32
100
+ attach_function :Gosu_Color_set_green, [:uint32, :uchar], :uint32
101
+ attach_function :Gosu_Color_set_blue, [:uint32, :uchar], :uint32
102
+
103
+ attach_function :Gosu_Color_value, [:uint32], :double
104
+ attach_function :Gosu_Color_saturation, [:uint32], :double
105
+ attach_function :Gosu_Color_hue, [:uint32], :double
106
+
107
+ attach_function :Gosu_Color_set_value, [:uint32, :double], :uint32
108
+ attach_function :Gosu_Color_set_saturation, [:uint32, :double], :uint32
109
+ attach_function :Gosu_Color_set_hue, [:uint32, :double], :uint32
110
+
111
+ attach_function :Gosu_Color_bgr, [:uint32], :uint32
112
+ attach_function :Gosu_Color_abgr, [:uint32], :uint32
113
+ attach_function :Gosu_Color_argb, [:uint32], :uint32
114
+
115
+ attach_function :Gosu_Font_create, [:int, :string, :uint32, :uint32], :pointer
116
+ attach_function :Gosu_Font_destroy, [:pointer], :void
117
+
118
+ attach_function :Gosu_Font_name, [:pointer], :string
119
+ attach_function :Gosu_Font_height, [:pointer], :int
120
+
121
+ attach_function :Gosu_Font_text_width, [:pointer, :string], :double
122
+ attach_function :Gosu_Font_markup_width, [:pointer, :string], :double
123
+
124
+ attach_function :Gosu_Font_draw_text, [:pointer, :string, :double, :double, :double,
125
+ :double, :double, :uint32, :uint32], :void
126
+ attach_function :Gosu_Font_draw_markup, [:pointer, :string, :double, :double, :double,
127
+ :double, :double, :uint32, :uint32], :void
128
+
129
+ attach_function :Gosu_Font_draw_text_rel, [:pointer, :string, :double, :double, :double,
130
+ :double, :double, :double, :double, :uint32, :uint32], :void
131
+ attach_function :Gosu_Font_draw_markup_rel, [:pointer, :string, :double, :double, :double,
132
+ :double, :double, :double, :double, :uint32, :uint32], :void
133
+
134
+ attach_function :Gosu_Font_set_image, [:pointer, :string, :uint32, :pointer], :void
135
+
136
+ attach_function :Gosu_Image_create, [:string, :uint32], :pointer
137
+ attach_function :Gosu_Image_destroy, [:pointer], :void
138
+
139
+ attach_function :Gosu_Image_create_from_markup, [:string, :string, :double, :int, :double, :uint32, :uint32, :uint32], :pointer
140
+ attach_function :Gosu_Image_create_from_text, [:string, :string, :double, :int, :double, :uint32, :uint32, :uint32], :pointer
141
+ attach_function :Gosu_Image_create_from_blob, [:pointer, :ulong, :int, :int, :uint32], :pointer
142
+ attach_function :Gosu_Image_create_from_subimage, [:pointer, :int, :int, :int, :int], :pointer
143
+ attach_function :Gosu_Image_create_from_tiles, [:string, :int, :int, :_callback_with_image, :pointer, :uint32], :void
144
+ attach_function :Gosu_Image_create_tiles_from_image, [:pointer, :int, :int, :_callback_with_image, :pointer, :uint32], :void
145
+
146
+ attach_function :Gosu_Image_width, [:pointer], :int
147
+ attach_function :Gosu_Image_height, [:pointer], :int
148
+
149
+ attach_function :Gosu_Image_draw, [:pointer, :double, :double, :double, :double, :double, :uint32, :uint32], :void
150
+ attach_function :Gosu_Image_draw_rot, [:pointer, :double, :double, :double, :double, :double, :double,
151
+ :double, :double, :uint32, :uint32], :void
152
+ attach_function :Gosu_Image_draw_as_quad, [:pointer, :double, :double, :uint32, :double, :double, :uint32,
153
+ :double, :double, :uint32, :double, :double, :uint32, :double, :uint32], :void
154
+
155
+ attach_function :Gosu_Image_save, [:pointer, :string], :void
156
+ attach_function :Gosu_Image_to_blob, [:pointer], :pointer
157
+ attach_function :Gosu_Image_insert, [:pointer, :pointer, :int, :int], :pointer
158
+
159
+ attach_function :Gosu_Image_gl_tex_info_create, [:pointer], :pointer
160
+ attach_function :Gosu_Image_gl_tex_info_destroy, [:pointer], :void
161
+ attach_function :Gosu_Sample_create, [:string], :pointer
162
+ attach_function :Gosu_Sample_destroy, [:pointer], :void
163
+
164
+ attach_function :Gosu_Sample_play, [:pointer, :double, :double, :bool], :pointer
165
+ attach_function :Gosu_Sample_play_pan, [:pointer, :double, :double, :double, :bool], :pointer
166
+
167
+ attach_function :Gosu_Song_current_song, [], :pointer
168
+
169
+ attach_function :Gosu_Song_create, [:string], :pointer
170
+ attach_function :Gosu_Song_destroy, [:pointer], :void
171
+
172
+ attach_function :Gosu_Song_play, [:pointer, :bool], :void
173
+ attach_function :Gosu_Song_playing, [:pointer], :bool
174
+ attach_function :Gosu_Song_pause, [:pointer], :void
175
+ attach_function :Gosu_Song_paused, [:pointer], :bool
176
+ attach_function :Gosu_Song_stop, [:pointer], :void
177
+
178
+ attach_function :Gosu_Song_volume, [:pointer], :double
179
+ attach_function :Gosu_Song_set_volume, [:pointer, :double], :void
180
+
181
+ attach_function :Gosu_TextInput_create, [], :pointer
182
+ attach_function :Gosu_TextInput_destroy, [:pointer], :void
183
+
184
+ attach_function :Gosu_TextInput_caret_pos, [:pointer], :uint32
185
+ attach_function :Gosu_TextInput_set_caret_pos, [:pointer, :uint32], :void
186
+ attach_function :Gosu_TextInput_selection_start, [:pointer], :uint32
187
+ attach_function :Gosu_TextInput_set_selection_start, [:pointer, :uint32], :void
188
+
189
+ attach_function :Gosu_TextInput_text, [:pointer], :string
190
+ attach_function :Gosu_TextInput_set_text, [:pointer, :string], :void
191
+ attach_function :Gosu_TextInput_set_filter, [:pointer, :_callback_with_string, :pointer], :void
192
+ attach_function :Gosu_TextInput_set_filter_result, [:pointer, :string], :void
193
+
194
+ attach_function :Gosu_TextInput_insert_text, [:pointer, :string], :void
195
+ attach_function :Gosu_TextInput_delete_backward, [:pointer], :void
196
+ attach_function :Gosu_TextInput_delete_forward, [:pointer], :void
197
+
198
+ attach_function :Gosu_Window_create, [:int, :int, :uint32, :double], :pointer
199
+ attach_function :Gosu_Window_destroy, [:pointer], :void
200
+
201
+ attach_function :Gosu_Window_set_draw, [:pointer, :_callback, :pointer], :void
202
+ attach_function :Gosu_Window_set_update, [:pointer, :_callback, :pointer], :void
203
+ attach_function :Gosu_Window_set_button_down, [:pointer, :_callback_with_unsigned, :pointer], :void
204
+ attach_function :Gosu_Window_set_button_up, [:pointer, :_callback_with_unsigned, :pointer], :void
205
+ attach_function :Gosu_Window_set_gamepad_connected, [:pointer, :_callback_with_unsigned, :pointer], :void
206
+ attach_function :Gosu_Window_set_gamepad_disconnected, [:pointer, :_callback_with_unsigned, :pointer], :void
207
+ attach_function :Gosu_Window_set_drop, [:pointer, :_callback_with_string, :pointer], :void
208
+ attach_function :Gosu_Window_set_needs_redraw, [:pointer, :_callback_returns_bool, :pointer], :void
209
+ attach_function :Gosu_Window_set_needs_cursor, [:pointer, :_callback_returns_bool, :pointer], :void
210
+ attach_function :Gosu_Window_set_close, [:pointer, :_callback, :pointer], :void
211
+ attach_function :Gosu_Window_set_gain_focus, [:pointer, :_callback, :pointer], :void
212
+ attach_function :Gosu_Window_set_lose_focus, [:pointer, :_callback, :pointer], :void
213
+
214
+ # Enable gosu's default button_down fullscreen toggle
215
+ attach_function :Gosu_Window_default_button_down, [:pointer, :uint32], :void
216
+
217
+ attach_function :Gosu_Window_show, [:pointer], :void
218
+ attach_function :Gosu_Window_tick, [:pointer], :bool
219
+ attach_function :Gosu_Window_close_immediately, [:pointer], :void
220
+
221
+ attach_function :Gosu_Window_width, [:pointer], :int
222
+ attach_function :Gosu_Window_set_width, [:pointer, :int], :void
223
+ attach_function :Gosu_Window_height, [:pointer], :int
224
+ attach_function :Gosu_Window_set_height, [:pointer, :int], :void
225
+
226
+ attach_function :Gosu_Window_mouse_x, [:pointer], :double
227
+ attach_function :Gosu_Window_set_mouse_x, [:pointer, :double], :void
228
+ attach_function :Gosu_Window_mouse_y, [:pointer], :double
229
+ attach_function :Gosu_Window_set_mouse_y, [:pointer, :double], :void
230
+
231
+ attach_function :Gosu_Window_caption, [:pointer], :string
232
+ attach_function :Gosu_Window_set_caption, [:pointer, :string], :void
233
+ attach_function :Gosu_Window_update_interval, [:pointer], :double
234
+ attach_function :Gosu_Window_set_update_interval, [:pointer, :double], :void
235
+ attach_function :Gosu_Window_resize, [:pointer, :int, :int, :bool], :void
236
+ attach_function :Gosu_Window_is_fullscreen, [:pointer], :bool
237
+ attach_function :Gosu_Window_is_resizable, [:pointer], :bool
238
+ attach_function :Gosu_Window_is_borderless, [:pointer], :bool
239
+ attach_function :Gosu_Window_set_fullscreen, [:pointer, :bool], :void
240
+ attach_function :Gosu_Window_set_resizable, [:pointer, :bool], :void
241
+ attach_function :Gosu_Window_set_borderless, [:pointer, :bool], :void
242
+
243
+ attach_function :Gosu_Window_sdl_window, [:pointer], :pointer
244
+
245
+ attach_function :Gosu_Window_text_input, [:pointer], :pointer
246
+ attach_function :Gosu_Window_set_text_input, [:pointer, :pointer], :void
247
+
248
+ def self.color_to_uint32(color)
249
+ color.is_a?(Gosu::Color) ? color.gl : color
250
+ end
251
+
252
+ def self.check_last_error(value = nil)
253
+ if (err = Gosu_last_error())
254
+ raise err
255
+ end
256
+ value
257
+ end
258
+ end
data/lib/gosu/font.rb ADDED
@@ -0,0 +1,56 @@
1
+ module Gosu
2
+ class Font
3
+ def initialize(height, name: Gosu.default_font_name, bold: false, italic: false, underline: false)
4
+ __font = GosuFFI.Gosu_Font_create(height, name, GosuFFI.font_flags(bold, italic, underline), 0)
5
+ GosuFFI.check_last_error
6
+ @memory_pointer = FFI::AutoPointer.new(__font, GosuFFI.method(:Gosu_Font_destroy))
7
+ end
8
+
9
+ def __pointer
10
+ @memory_pointer
11
+ end
12
+
13
+ def name
14
+ GosuFFI.check_last_error(GosuFFI.Gosu_Font_name(__pointer))
15
+ end
16
+
17
+ def height
18
+ GosuFFI.check_last_error(GosuFFI.Gosu_Font_height(__pointer))
19
+ end
20
+
21
+ def text_width(text, scale_x = 1)
22
+ GosuFFI.check_last_error(GosuFFI.Gosu_Font_text_width(__pointer, text.to_s)) * scale_x
23
+ end
24
+
25
+ def markup_width(text, scale_x = 1)
26
+ GosuFFI.check_last_error(GosuFFI.Gosu_Font_markup_width(__pointer, text.to_s)) * scale_x
27
+ end
28
+
29
+ def draw_text(text, x, y, z, scale_x = 1, scale_y = 1, c = Gosu::Color::WHITE, mode = :default)
30
+ GosuFFI.Gosu_Font_draw_text(__pointer, text.to_s, x, y, z, scale_x, scale_y, GosuFFI.color_to_uint32(c), GosuFFI.blend_mode(mode))
31
+ GosuFFI.check_last_error
32
+ end
33
+
34
+ def draw_markup(text, x, y, z, scale_x = 1, scale_y = 1, c = Gosu::Color::WHITE, mode = :default)
35
+ GosuFFI.Gosu_Font_draw_markup(__pointer, text.to_s, x, y, z, scale_x, scale_y, GosuFFI.color_to_uint32(c), GosuFFI.blend_mode(mode))
36
+ GosuFFI.check_last_error
37
+ end
38
+
39
+ def draw_text_rel(text, x, y, z, rel_x, rel_y, scale_x = 1, scale_y = 1, c = Gosu::Color::WHITE, mode = :default)
40
+ GosuFFI.Gosu_Font_draw_text_rel(__pointer, text.to_s, x, y, z, rel_x, rel_y, scale_x, scale_y, GosuFFI.color_to_uint32(c), GosuFFI.blend_mode(mode))
41
+ GosuFFI.check_last_error
42
+ end
43
+
44
+ def draw_markup_rel(text, x, y, z, rel_x, rel_y, scale_x = 1, scale_y = 1, c = Gosu::Color::WHITE, mode = :default)
45
+ GosuFFI.Gosu_Font_draw_markup_rel(__pointer, text.to_s, x, y, z, rel_x, rel_y, scale_x, scale_y, GosuFFI.color_to_uint32(c), GosuFFI.blend_mode(mode))
46
+ GosuFFI.check_last_error
47
+ end
48
+
49
+ def []=(codepoint, image)
50
+ GosuFFI.FF_COMBINATIONS.times do |font_flags|
51
+ GosuFFI.Gosu_Font_set_image(__pointer, codepoint, font_flags, image.__pointer)
52
+ GosuFFI.check_last_error
53
+ end
54
+ end
55
+ end
56
+ end