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,33 @@
1
+ module Gosu
2
+ class GLTexInfo < FFI::ManagedStruct
3
+ layout :tex_name, :uint32,
4
+ :left, :double,
5
+ :right, :double,
6
+ :top, :double,
7
+ :bottom, :double
8
+
9
+ def tex_name
10
+ self[:tex_name]
11
+ end
12
+
13
+ def left
14
+ self[:left]
15
+ end
16
+
17
+ def right
18
+ self[:right]
19
+ end
20
+
21
+ def top
22
+ self[:top]
23
+ end
24
+
25
+ def bottom
26
+ self[:bottom]
27
+ end
28
+
29
+ def self.release(pointer)
30
+ GosuFFI.Gosu_Image_gl_tex_info_destroy(pointer)
31
+ end
32
+ end
33
+ end
data/lib/gosu/gosu.rb ADDED
@@ -0,0 +1,210 @@
1
+ module Gosu
2
+ def self.fps
3
+ GosuFFI.check_last_error(GosuFFI.Gosu_fps())
4
+ end
5
+
6
+ def self.flush
7
+ GosuFFI.Gosu_flush()
8
+ GosuFFI.check_last_error
9
+ end
10
+
11
+ def self.milliseconds
12
+ GosuFFI.check_last_error(GosuFFI.Gosu_milliseconds())
13
+ end
14
+
15
+ def self.default_font_name
16
+ GosuFFI.check_last_error(GosuFFI.Gosu_default_font_name())
17
+ end
18
+
19
+ def self.user_languages
20
+ languages = []
21
+ callback = proc { |data, string| languages << string if string }
22
+ GosuFFI.Gosu_user_languages(callback, nil)
23
+ GosuFFI.check_last_error(languages)
24
+ end
25
+
26
+ def self.gl(z = nil, &block)
27
+ raise "Block not given!" unless block
28
+
29
+ if z
30
+ # When given a Z position, Gosu.gl will not call its block immediately, but enqueue it for later execution.
31
+ # To prevent the block from getting GC'd, store it in a global variable which is cleared after Window.draw.
32
+ $gosu_gl_blocks ||= []
33
+ $gosu_gl_blocks << block
34
+
35
+ GosuFFI.Gosu_gl_z(z, block)
36
+ else
37
+ GosuFFI.Gosu_gl(block)
38
+ end
39
+
40
+ GosuFFI.check_last_error
41
+ end
42
+
43
+ def self.render(width, height, retro: false, tileable: false, &block)
44
+ # TODO: Exception translation from inner block
45
+ __image = GosuFFI.Gosu_render(width, height, block, GosuFFI.image_flags(retro: retro, tileable: tileable))
46
+ GosuFFI.check_last_error
47
+ Gosu::Image.new(__image)
48
+ end
49
+
50
+ def self.record(width, height, &block)
51
+ # TODO: Exception translation from inner block
52
+ __image = GosuFFI.Gosu_record(width, height, block)
53
+ GosuFFI.check_last_error
54
+ Gosu::Image.new(__image)
55
+ end
56
+
57
+ def self.transform(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, &block)
58
+ # TODO: Exception translation from inner block
59
+ GosuFFI.Gosu_transform(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, block)
60
+ GosuFFI.check_last_error
61
+ end
62
+
63
+ def self.translate(x, y, &block)
64
+ # TODO: Exception translation from inner block
65
+ GosuFFI.Gosu_translate(x, y, block)
66
+ GosuFFI.check_last_error
67
+ end
68
+
69
+ def self.rotate(angle, around_x = 0, around_y = 0, &block)
70
+ # TODO: Exception translation from inner block
71
+ GosuFFI.Gosu_rotate(angle, around_x, around_y, block)
72
+ GosuFFI.check_last_error
73
+ end
74
+
75
+ def self.scale(x, y = x, around_x = 0, around_y = 0, &block)
76
+ # TODO: Exception translation from inner block
77
+ GosuFFI.Gosu_scale(x, y, around_x, around_y, block)
78
+ GosuFFI.check_last_error
79
+ end
80
+
81
+ # Note: On JRuby this seems to get "optimized out" for some reason
82
+ # For now, call jruby with the `--dev` option
83
+ def self.clip_to(x, y, width, height, &block)
84
+ # TODO: Exception translation from inner block
85
+ GosuFFI.Gosu_clip_to(x, y, width, height, block)
86
+ GosuFFI.check_last_error
87
+ end
88
+
89
+ def self.button_down?(id)
90
+ GosuFFI.check_last_error(GosuFFI.Gosu_button_down(id))
91
+ end
92
+
93
+ def self.axis(id)
94
+ GosuFFI.check_last_error(GosuFFI.Gosu_axis(id))
95
+ end
96
+
97
+ def self.button_id_to_char(id)
98
+ GosuFFI.check_last_error(GosuFFI.Gosu_button_id_to_char(id))
99
+ end
100
+
101
+ def self.char_to_button_id(id)
102
+ GosuFFI.check_last_error(GosuFFI.Gosu_button_char_to_id(id))
103
+ end
104
+
105
+ def self.button_name(id)
106
+ GosuFFI.check_last_error(GosuFFI.Gosu_button_name(id))
107
+ end
108
+
109
+ def self.gamepad_name(id)
110
+ GosuFFI.check_last_error(GosuFFI.Gosu_gamepad_name(id))
111
+ end
112
+
113
+ def self.clipboard
114
+ GosuFFI.check_last_error(GosuFFI.Gosu_clipboard())
115
+ end
116
+
117
+ def self.clipboard=(text)
118
+ GosuFFI.Gosu_set_clipboard(text)
119
+ GosuFFI.check_last_error
120
+ end
121
+
122
+ def self.draw_line(x1, y1, c1, x2, y2, c2, z = 0, mode = :default)
123
+ GosuFFI.Gosu_draw_line(x1, y1, GosuFFI.color_to_uint32(c1), x2, y2, GosuFFI.color_to_uint32(c2), z, GosuFFI.blend_mode(mode))
124
+ GosuFFI.check_last_error
125
+ end
126
+
127
+ def self.draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z = 0, mode = :default)
128
+ GosuFFI.Gosu_draw_triangle(x1, y1, GosuFFI.color_to_uint32(c1), x2, y2, GosuFFI.color_to_uint32(c2),
129
+ x3, y3, GosuFFI.color_to_uint32(c3), z, GosuFFI.blend_mode(mode))
130
+ GosuFFI.check_last_error
131
+ end
132
+
133
+ def self.draw_quad(x1, y1, c1, x2, y2, c2,
134
+ x3, y3, c3, x4, y4, c4,
135
+ z = 0, mode = :default)
136
+ GosuFFI.Gosu_draw_quad(x1, y1, GosuFFI.color_to_uint32(c1), x2, y2, GosuFFI.color_to_uint32(c2),
137
+ x3, y3, GosuFFI.color_to_uint32(c3), x4, y4, GosuFFI.color_to_uint32(c4),
138
+ z, GosuFFI.blend_mode(mode))
139
+ GosuFFI.check_last_error
140
+ end
141
+
142
+ def self.draw_rect(x, y, width, height, c, z = 0, mode = :default)
143
+ GosuFFI.Gosu_draw_rect(x, y, width, height, GosuFFI.color_to_uint32(c), z, GosuFFI.blend_mode(mode))
144
+ GosuFFI.check_last_error
145
+ end
146
+
147
+ def self.offset_x(angle, distance)
148
+ GosuFFI.check_last_error(GosuFFI.Gosu_offset_x(angle, distance))
149
+ end
150
+
151
+ def self.offset_y(angle, distance)
152
+ GosuFFI.check_last_error(GosuFFI.Gosu_offset_y(angle, distance))
153
+ end
154
+
155
+ def self.distance(x1, y1, x2, y2)
156
+ GosuFFI.check_last_error(GosuFFI.Gosu_distance(x1, y1, x2, y2))
157
+ end
158
+
159
+ def self.angle(x1, y1, x2, y2)
160
+ GosuFFI.check_last_error(GosuFFI.Gosu_angle(x1, y1, x2, y2))
161
+ end
162
+
163
+ def self.angle_diff(angle1, angle2)
164
+ GosuFFI.check_last_error(GosuFFI.Gosu_angle_diff(angle1, angle2))
165
+ end
166
+
167
+ def self.random(min, max)
168
+ GosuFFI.check_last_error(GosuFFI.Gosu_random(min, max))
169
+ end
170
+
171
+ def self.available_width(window = nil)
172
+ if window.nil?
173
+ GosuFFI.check_last_error(GosuFFI.Gosu_available_width(nil))
174
+ else
175
+ raise TypeError, "Instance of Gosu::Window or nil expected, got: #{window.class}" if not window.is_a? Gosu::Window
176
+ GosuFFI.check_last_error(GosuFFI.Gosu_available_width(window.__pointer))
177
+ end
178
+ end
179
+
180
+ def self.available_height(window = nil)
181
+ if window.nil?
182
+ GosuFFI.check_last_error(GosuFFI.Gosu_available_height(nil))
183
+ else
184
+ raise TypeError, "Instance of Gosu::Window or nil expected, got: #{window.class}" if not window.is_a? Gosu::Window
185
+ GosuFFI.check_last_error(GosuFFI.Gosu_available_height(window.__pointer))
186
+ end
187
+ end
188
+
189
+ def self.screen_width(window = nil)
190
+ if window.nil?
191
+ GosuFFI.check_last_error(GosuFFI.Gosu_screen_width(nil))
192
+ else
193
+ raise TypeError, "Instance of Gosu::Window or nil expected, got: #{window.class}" if not window.is_a? Gosu::Window
194
+ GosuFFI.check_last_error(GosuFFI.Gosu_screen_width(window.__pointer))
195
+ end
196
+ end
197
+
198
+ def self.screen_height(window = nil)
199
+ if window.nil?
200
+ GosuFFI.check_last_error(GosuFFI.Gosu_screen_height(nil))
201
+ else
202
+ raise TypeError, "Instance of Gosu::Window or nil expected, got: #{window.class}" if not window.is_a? Gosu::Window
203
+ GosuFFI.check_last_error(GosuFFI.Gosu_screen_height(window.__pointer))
204
+ end
205
+ end
206
+
207
+ def self.enable_undocumented_retrofication
208
+ # TODO: Move implementation from C++ to Ruby.
209
+ end
210
+ end
data/lib/gosu/image.rb ADDED
@@ -0,0 +1,141 @@
1
+ module Gosu
2
+ class Image
3
+ BlobHelper = Struct.new(:columns, :rows, :to_blob)
4
+
5
+ def self.from_blob(width, height, rgba = "\0\0\0\0" * (width * height), retro: false, tileable: false)
6
+ self.new(BlobHelper.new(width, height, rgba), retro: retro, tileable: tileable)
7
+ end
8
+
9
+ def self.from_text(markup, line_height, font: Gosu.default_font_name, width: -1, spacing: 0, align: :left,
10
+ bold: false, italic: false, underline: false, retro: false)
11
+ __image = GosuFFI.Gosu_Image_create_from_text(markup, font, line_height, width, spacing,
12
+ GosuFFI.font_alignment_flags(align),
13
+ GosuFFI.font_flags(bold, italic, underline),
14
+ GosuFFI.image_flags(retro: retro))
15
+ GosuFFI.check_last_error
16
+ Gosu::Image.new(__image)
17
+ end
18
+
19
+ def self.from_markup(markup, line_height, font: Gosu.default_font_name, width: -1, spacing: 0, align: :left,
20
+ bold: false, italic: false, underline: false, retro: false)
21
+ __image = GosuFFI.Gosu_Image_create_from_markup(markup, font, line_height, width, spacing,
22
+ GosuFFI.font_alignment_flags(align),
23
+ GosuFFI.font_flags(bold, italic, underline),
24
+ GosuFFI.image_flags(retro: retro))
25
+ GosuFFI.check_last_error
26
+ Gosu::Image.new(__image)
27
+ end
28
+
29
+ def self.load_tiles(filename_or_image, tile_width, tile_height, retro: false, tileable: false)
30
+ flags = GosuFFI.image_flags(retro: retro, tileable: tileable)
31
+
32
+ images = []
33
+ callback = proc { |data, image| images << Gosu::Image.new(image) }
34
+
35
+ if filename_or_image.is_a? String
36
+ GosuFFI.Gosu_Image_create_from_tiles(filename_or_image, tile_width, tile_height, callback, nil, flags)
37
+ else
38
+ if filename_or_image.is_a? Gosu::Image
39
+ GosuFFI.Gosu_Image_create_tiles_from_image(filename_or_image.__pointer, tile_width, tile_height, callback, nil, flags)
40
+ else
41
+ image = Gosu::Image.new(filename_or_image, retro: retro, tileable: tileable)
42
+ GosuFFI.Gosu_Image_create_tiles_from_image(image.__pointer, tile_width, tile_height, callback, nil, flags)
43
+ end
44
+ end
45
+
46
+ GosuFFI.check_last_error
47
+
48
+ return images
49
+ end
50
+
51
+ def initialize(object, retro: false, tileable: false)
52
+ if object.is_a? String
53
+ __image = GosuFFI.Gosu_Image_create(object, GosuFFI.image_flags(retro: retro, tileable: tileable))
54
+ GosuFFI.check_last_error
55
+ elsif object.is_a?(FFI::Pointer)
56
+ __image = object
57
+ elsif object.respond_to?(:to_blob) &&
58
+ object.respond_to?(:columns) &&
59
+ object.respond_to?(:rows)
60
+ blob_bytes = object.to_blob { self.format = "RGBA"; self.depth = 8 }.bytes
61
+ FFI::MemoryPointer.new(:uchar, blob_bytes.size) do |blob|
62
+ blob.write_array_of_type(:uchar, :put_uchar, blob_bytes)
63
+ __image = GosuFFI.Gosu_Image_create_from_blob(blob, blob_bytes.size, object.columns, object.rows, GosuFFI.image_flags(retro: retro, tileable: tileable))
64
+ GosuFFI.check_last_error
65
+ end
66
+
67
+ raise "Failed to load image from blob" if __image.null?
68
+ else
69
+ raise ArgumentError
70
+ end
71
+
72
+ @managed_pointer = FFI::AutoPointer.new(__image, GosuFFI.method(:Gosu_Image_destroy))
73
+ end
74
+
75
+ def __pointer
76
+ @managed_pointer
77
+ end
78
+
79
+ def width
80
+ GosuFFI.check_last_error(GosuFFI.Gosu_Image_width(__pointer))
81
+ end
82
+
83
+ def height
84
+ GosuFFI.check_last_error(GosuFFI.Gosu_Image_height(__pointer))
85
+ end
86
+
87
+ def draw(x, y, z, scale_x = 1, scale_y = 1, color = Gosu::Color::WHITE, flags = :default)
88
+ GosuFFI.Gosu_Image_draw(__pointer, x, y, z, scale_x, scale_y, GosuFFI.color_to_uint32(color), GosuFFI.blend_mode(flags))
89
+ GosuFFI.check_last_error
90
+ end
91
+
92
+ def draw_rot(x, y, z, angle = 0, center_x = 0.5, center_y = 0.5, scale_x = 1, scale_y = 1, color = Gosu::Color::WHITE, flags = :default)
93
+ GosuFFI.Gosu_Image_draw_rot(__pointer, x, y, z, angle, center_x, center_y, scale_x, scale_y, GosuFFI.color_to_uint32(color), GosuFFI.blend_mode(flags))
94
+ GosuFFI.check_last_error
95
+ end
96
+
97
+ def draw_as_quad(x1, y1, color1, x2, y2, color2, x3, y3, color3, x4, y4, color4, z = 0, mode = :default)
98
+ GosuFFI.Gosu_Image_draw_as_quad(x1, y1, GosuFFI.color_to_uint32(color1), x2, y2, GosuFFI.color_to_uint32(color2),
99
+ x3, y3, GosuFFI.color_to_uint32(color3), x4, y4, GosuFFI.color_to_uint32(color4),
100
+ z, GosuFFI.blend_mode(mode))
101
+ GosuFFI.check_last_error
102
+ end
103
+
104
+ def save(filename)
105
+ GosuFFI.Gosu_Image_save(__pointer, filename)
106
+ GosuFFI.check_last_error
107
+ end
108
+
109
+ def to_blob
110
+ blob = GosuFFI.check_last_error(GosuFFI.Gosu_Image_to_blob(__pointer))
111
+ blob.read_string(width * height * Gosu::Color::SIZEOF)
112
+ end
113
+
114
+ def subimage(left, top, width, height)
115
+ __pointer = GosuFFI.Gosu_Image_create_from_subimage(__pointer, left, top, width, height)
116
+ GosuFFI.check_last_error
117
+ Gosu::Image.new(__pointer)
118
+ end
119
+
120
+ def insert(image, x, y)
121
+ image_ = nil
122
+ if image.is_a?(Gosu::Image)
123
+ image_ = image.__pointer
124
+ elsif image.respond_to?(:to_blob) &&
125
+ image.respond_to?(:rows) &&
126
+ image.respond_to?(:columns)
127
+ image_ = Gosu::Image.new(image).__pointer
128
+ else
129
+ raise "Unable to insert image!"
130
+ end
131
+
132
+ GosuFFI.Gosu_Image_insert(__pointer, image_, x, y)
133
+ GosuFFI.check_last_error
134
+ end
135
+
136
+ def gl_tex_info
137
+ tex_info = GosuFFI.check_last_error(GosuFFI.Gosu_Image_gl_tex_info_create(__pointer))
138
+ tex_info ? GLTexInfo.new(tex_info) : nil
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,17 @@
1
+ class ::Numeric
2
+ def degrees_to_radians
3
+ self * Math::PI / 180.0
4
+ end
5
+
6
+ def radians_to_degrees
7
+ self * 180.0 / Math::PI
8
+ end
9
+
10
+ def gosu_to_radians
11
+ (self - 90) * Math::PI / 180.0
12
+ end
13
+
14
+ def radians_to_gosu
15
+ self * 180.0 / Math::PI + 90
16
+ end
17
+ end
data/lib/gosu/preview.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  warn "gosu/preview.rb has been removed in Gosu 0.9.0, and Gosu itself \n" +
2
- "provides a similar interface to what preview.rb used to offer.\n" +
3
- "Notable differences:\n" +
4
- "• no global $window variable\n" +
5
- "• no global Gosu.mouse_x and Gosu.mouse_y functions\n" +
6
- "• Image#initialize et.al. use an options hash now";
2
+ "provides a similar interface to what preview.rb used to offer.\n" +
3
+ "Notable differences:\n" +
4
+ "• no global $window variable\n" +
5
+ "• no global Gosu.mouse_x and Gosu.mouse_y functions\n" +
6
+ "• Image#initialize et.al. use an options hash now"
7
7
 
8
- require 'gosu'
8
+ require "gosu"
@@ -0,0 +1,24 @@
1
+ module Gosu
2
+ class Sample
3
+ def initialize(filename)
4
+ __sample = GosuFFI.check_last_error(GosuFFI.Gosu_Sample_create(filename))
5
+ @memory_pointer = FFI::AutoPointer.new(__sample, GosuFFI.method(:Gosu_Sample_destroy))
6
+ end
7
+
8
+ def __pointer
9
+ @memory_pointer
10
+ end
11
+
12
+ def play(volume = 1, speed = 1, looping = false)
13
+ __channel = GosuFFI.Gosu_Sample_play(__pointer, volume, speed, looping)
14
+ GosuFFI.check_last_error
15
+ Gosu::Channel.new(__channel)
16
+ end
17
+
18
+ def play_pan(pan = 0, volume = 1, speed = 1, looping = false)
19
+ __channel = GosuFFI.Gosu_Sample_play_pan(__pointer, pan, volume, speed, looping)
20
+ GosuFFI.check_last_error
21
+ Gosu::Channel.new(__channel)
22
+ end
23
+ end
24
+ end
data/lib/gosu/song.rb ADDED
@@ -0,0 +1,56 @@
1
+ module Gosu
2
+ class Song
3
+ def self.current_song
4
+ ptr = GosuFFI.Gosu_Song_current_song()
5
+ GosuFFI.check_last_error
6
+ unless ptr.null?
7
+ @@current_song
8
+ else
9
+ nil
10
+ end
11
+ end
12
+
13
+ def initialize(filename)
14
+ __song = GosuFFI.Gosu_Song_create(filename)
15
+ GosuFFI.check_last_error
16
+ @memory_pointer = FFI::AutoPointer.new(__song, GosuFFI.method(:Gosu_Song_destroy))
17
+ end
18
+
19
+ def __pointer
20
+ @memory_pointer
21
+ end
22
+
23
+ def play(looping = false)
24
+ @@current_song = self
25
+ GosuFFI.Gosu_Song_play(__pointer, looping)
26
+ GosuFFI.check_last_error
27
+ end
28
+
29
+ def playing?
30
+ GosuFFI.check_last_error(GosuFFI.Gosu_Song_playing(__pointer))
31
+ end
32
+
33
+ def pause
34
+ GosuFFI.Gosu_Song_pause(__pointer)
35
+ GosuFFI.check_last_error
36
+ end
37
+
38
+ def paused?
39
+ GosuFFI.check_last_error(GosuFFI.Gosu_Song_paused(__pointer))
40
+ end
41
+
42
+ def stop
43
+ GosuFFI.Gosu_Song_stop(__pointer)
44
+ GosuFFI.check_last_error
45
+ end
46
+
47
+ def volume
48
+ GosuFFI.check_last_error(GosuFFI.Gosu_Song_volume(__pointer))
49
+ end
50
+
51
+ def volume=(double)
52
+ GosuFFI.Gosu_Song_set_volume(__pointer, double)
53
+ GosuFFI.check_last_error
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,69 @@
1
+ module Gosu
2
+ class TextInput
3
+ def initialize
4
+ __text_input = GosuFFI.Gosu_TextInput_create()
5
+ GosuFFI.check_last_error
6
+ @memory_pointer = FFI::AutoPointer.new(__text_input, GosuFFI.method(:Gosu_TextInput_destroy))
7
+
8
+ @__filter_proc = proc { |data, text| protected_filter(text) }
9
+ GosuFFI.Gosu_TextInput_set_filter(__pointer, @__filter_proc, nil)
10
+ GosuFFI.check_last_error
11
+ end
12
+
13
+ def __pointer
14
+ @memory_pointer
15
+ end
16
+
17
+ def text
18
+ GosuFFI.check_last_error(GosuFFI.Gosu_TextInput_text(__pointer))
19
+ end
20
+
21
+ def text=(string)
22
+ GosuFFI.Gosu_TextInput_set_text(__pointer, string.to_s)
23
+ GosuFFI.check_last_error
24
+ end
25
+
26
+ def caret_pos
27
+ GosuFFI.check_last_error(GosuFFI.Gosu_TextInput_caret_pos(__pointer))
28
+ end
29
+
30
+ def caret_pos=(int)
31
+ GosuFFI.Gosu_TextInput_set_caret_pos(__pointer, int)
32
+ GosuFFI.check_last_error
33
+ end
34
+
35
+ def selection_start
36
+ GosuFFI.check_last_error(GosuFFI.Gosu_TextInput_selection_start(__pointer))
37
+ end
38
+
39
+ def selection_start=(int)
40
+ GosuFFI.Gosu_TextInput_set_selection_start(__pointer, int)
41
+ GosuFFI.check_last_error
42
+ end
43
+
44
+ def filter(text)
45
+ return text
46
+ end
47
+
48
+ def insert_text(text)
49
+ GosuFFI.Gosu_TextInput_insert_text(__pointer, text)
50
+ GosuFFI.check_last_error
51
+ end
52
+
53
+ def delete_backward
54
+ GosuFFI.Gosu_TextInput_delete_backward(__pointer)
55
+ GosuFFI.check_last_error
56
+ end
57
+
58
+ def delete_forward
59
+ GosuFFI.Gosu_TextInput_delete_forward(__pointer)
60
+ GosuFFI.check_last_error
61
+ end
62
+
63
+ # Ensures that filter_result is set on C side before filter callback returns
64
+ private def protected_filter(text)
65
+ string = filter(text)
66
+ GosuFFI.Gosu_TextInput_set_filter_result(__pointer, string)
67
+ end
68
+ end
69
+ end