gosu 1.4.6 → 2.0.0.pre7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +2 -1
- data/dependencies/SDL/include/SDL_assert.h +2 -0
- data/dependencies/SDL/include/SDL_atomic.h +2 -3
- data/dependencies/SDL/include/SDL_audio.h +7 -7
- data/dependencies/SDL/include/SDL_blendmode.h +1 -1
- data/dependencies/SDL/include/SDL_endian.h +3 -3
- data/dependencies/SDL/include/SDL_gamecontroller.h +4 -4
- data/dependencies/SDL/include/SDL_hints.h +83 -28
- data/dependencies/SDL/include/SDL_joystick.h +8 -5
- data/dependencies/SDL/include/SDL_keycode.h +1 -1
- data/dependencies/SDL/include/SDL_main.h +7 -0
- data/dependencies/SDL/include/SDL_mouse.h +6 -7
- data/dependencies/SDL/include/SDL_mutex.h +79 -5
- data/dependencies/SDL/include/SDL_opengl_glext.h +5 -1
- data/dependencies/SDL/include/SDL_power.h +7 -8
- data/dependencies/SDL/include/SDL_render.h +6 -1
- data/dependencies/SDL/include/SDL_revision.h +2 -2
- data/dependencies/SDL/include/SDL_sensor.h +1 -1
- data/dependencies/SDL/include/SDL_stdinc.h +19 -11
- data/dependencies/SDL/include/SDL_thread.h +2 -2
- data/dependencies/SDL/include/SDL_version.h +2 -2
- data/dependencies/SDL/include/SDL_video.h +30 -2
- data/dependencies/SDL/include/begin_code.h +7 -7
- data/dependencies/SDL/include/close_code.h +2 -2
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.h +1 -1
- data/dependencies/SDL_sound/dr_flac.h +48 -23
- data/dependencies/SDL_sound/dr_mp3.h +34 -14
- data/dependencies/SDL_sound/stb_vorbis.h +3 -2
- data/dependencies/mojoAL/mojoal.c +1 -1
- data/ext/{gosu → gosu-ffi}/extconf.rb +34 -33
- data/ext/gosu-ffi/gosu-ffi.def +465 -0
- data/ffi/Gosu.cpp +307 -0
- data/ffi/Gosu.h +84 -0
- data/ffi/Gosu_Channel.cpp +62 -0
- data/ffi/Gosu_Channel.h +17 -0
- data/ffi/Gosu_Color.cpp +132 -0
- data/ffi/Gosu_Color.h +31 -0
- data/ffi/Gosu_Constants.cpp +334 -0
- data/ffi/Gosu_FFI.h +34 -0
- data/ffi/Gosu_FFI_internal.h +161 -0
- data/ffi/Gosu_Font.cpp +92 -0
- data/ffi/Gosu_Font.h +32 -0
- data/ffi/Gosu_Image.cpp +218 -0
- data/ffi/Gosu_Image.h +66 -0
- data/ffi/Gosu_Sample.cpp +29 -0
- data/ffi/Gosu_Sample.h +14 -0
- data/ffi/Gosu_Song.cpp +69 -0
- data/ffi/Gosu_Song.h +18 -0
- data/ffi/Gosu_TextInput.cpp +94 -0
- data/ffi/Gosu_TextInput.h +25 -0
- data/ffi/Gosu_Window.cpp +314 -0
- data/ffi/Gosu_Window.h +78 -0
- data/include/Gosu/Audio.hpp +6 -11
- data/include/Gosu/Bitmap.hpp +38 -53
- data/include/Gosu/Buffer.hpp +54 -0
- data/include/Gosu/Color.hpp +27 -35
- data/include/Gosu/Directories.hpp +25 -28
- data/include/Gosu/Drawable.hpp +58 -0
- data/include/Gosu/Font.hpp +6 -5
- data/include/Gosu/Fwd.hpp +4 -6
- data/include/Gosu/Gosu.hpp +5 -5
- data/include/Gosu/Graphics.hpp +51 -61
- data/include/Gosu/GraphicsBase.hpp +1 -11
- data/include/Gosu/Image.hpp +12 -15
- data/include/Gosu/Math.hpp +50 -72
- data/include/Gosu/Transform.hpp +32 -0
- data/include/Gosu/Utility.hpp +51 -1
- data/include/Gosu/Version.hpp +3 -3
- data/include/Gosu/Window.hpp +15 -9
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/channel.rb +49 -0
- data/lib/gosu/color.rb +150 -0
- data/lib/gosu/compat.rb +29 -8
- data/lib/gosu/constants.rb +386 -0
- data/lib/gosu/ffi.rb +259 -0
- data/lib/gosu/font.rb +56 -0
- data/lib/gosu/gl_tex_info.rb +33 -0
- data/lib/gosu/gosu.rb +210 -0
- data/lib/gosu/image.rb +153 -0
- data/lib/gosu/numeric.rb +17 -0
- data/lib/gosu/preview.rb +6 -6
- data/lib/gosu/sample.rb +24 -0
- data/lib/gosu/song.rb +56 -0
- data/lib/gosu/text_input.rb +69 -0
- data/lib/gosu/window.rb +228 -0
- data/lib/gosu.rb +29 -8
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +0 -2
- data/src/Audio.cpp +12 -12
- data/src/AudioFile.hpp +5 -4
- data/src/AudioFileAudioToolbox.cpp +8 -8
- data/src/AudioFileSDLSound.cpp +7 -10
- data/src/BinPacker.cpp +187 -0
- data/src/BinPacker.hpp +55 -0
- data/src/Bitmap.cpp +166 -144
- data/src/BitmapIO.cpp +60 -86
- data/src/Buffer.cpp +159 -0
- data/src/ClipRectStack.cpp +38 -0
- data/src/ClipRectStack.hpp +17 -83
- data/src/Color.cpp +75 -80
- data/src/Directories.cpp +47 -0
- data/src/DirectoriesUIKit.cpp +50 -0
- data/src/DrawOp.hpp +9 -9
- data/src/DrawOpQueue.hpp +26 -32
- data/src/Drawable.cpp +95 -0
- data/src/EmptyDrawable.hpp +38 -0
- data/src/FPS.cpp +31 -0
- data/src/Font.cpp +104 -74
- data/src/GosuGLView.cpp +13 -11
- data/src/GosuViewController.cpp +2 -10
- data/src/Graphics.cpp +66 -129
- data/src/GraphicsImpl.hpp +14 -67
- data/src/Image.cpp +41 -35
- data/src/Input.cpp +7 -8
- data/src/Macro.cpp +6 -6
- data/src/Macro.hpp +4 -4
- data/src/MarkupParser.cpp +5 -5
- data/src/Math.cpp +35 -22
- data/src/OffScreenTarget.cpp +53 -49
- data/src/OffScreenTarget.hpp +13 -11
- data/src/OpenGLContext.cpp +117 -0
- data/src/OpenGLContext.hpp +41 -0
- data/src/RenderState.hpp +45 -56
- data/src/Resolution.cpp +23 -21
- data/src/TexChunk.cpp +35 -80
- data/src/TexChunk.hpp +44 -35
- data/src/Text.cpp +1 -1
- data/src/TextBuilder.cpp +35 -21
- data/src/TextBuilder.hpp +6 -9
- data/src/Texture.cpp +62 -80
- data/src/Texture.hpp +25 -23
- data/src/TiledDrawable.cpp +150 -0
- data/src/TiledDrawable.hpp +47 -0
- data/src/TimingApple.cpp +1 -1
- data/src/Transform.cpp +45 -50
- data/src/TransformStack.hpp +16 -16
- data/src/TrueTypeFont.cpp +59 -51
- data/src/TrueTypeFont.hpp +6 -7
- data/src/TrueTypeFontApple.cpp +28 -19
- data/src/TrueTypeFontUnix.cpp +27 -23
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Utility.cpp +84 -21
- data/src/UtilityWin.cpp +45 -0
- data/src/Window.cpp +92 -142
- data/src/WindowUIKit.cpp +14 -14
- metadata +74 -32
- data/include/Gosu/IO.hpp +0 -254
- data/include/Gosu/ImageData.hpp +0 -53
- data/include/Gosu/Inspection.hpp +0 -7
- data/lib/gosu/patches.rb +0 -66
- data/lib/gosu/run.rb +0 -20
- data/lib/gosu/swig_patches.rb +0 -110
- data/src/BlockAllocator.cpp +0 -131
- data/src/BlockAllocator.hpp +0 -32
- data/src/DirectoriesApple.cpp +0 -69
- data/src/DirectoriesUnix.cpp +0 -46
- data/src/DirectoriesWin.cpp +0 -65
- data/src/EmptyImageData.hpp +0 -52
- data/src/FileUnix.cpp +0 -99
- data/src/FileWin.cpp +0 -88
- data/src/IO.cpp +0 -60
- data/src/Iconv.hpp +0 -51
- data/src/Inspection.cpp +0 -27
- data/src/LargeImageData.cpp +0 -215
- data/src/LargeImageData.hpp +0 -39
- data/src/Log.hpp +0 -19
- data/src/RubyGosu.cxx +0 -13100
- data/src/RubyGosu.h +0 -49
- data/src/WinUtility.cpp +0 -61
- 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,153 @@
|
|
1
|
+
module Gosu
|
2
|
+
class Image
|
3
|
+
def self.from_blob(width, height, rgba = "\0\0\0\0" * (width * height), retro: false, tileable: false)
|
4
|
+
@struct ||= Struct.new(:columns, :rows, :to_blob)
|
5
|
+
self.new(@struct.new(width, height, rgba), retro: retro, tileable: tileable)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.from_text(markup, line_height, font: Gosu.default_font_name, width: -1, spacing: 0, align: :left,
|
9
|
+
bold: false, italic: false, underline: false, retro: false)
|
10
|
+
__image = GosuFFI.Gosu_Image_create_from_text(markup, font, line_height, width, spacing,
|
11
|
+
GosuFFI.font_alignment_flags(align),
|
12
|
+
GosuFFI.font_flags(bold, italic, underline),
|
13
|
+
GosuFFI.image_flags(retro: retro))
|
14
|
+
GosuFFI.check_last_error
|
15
|
+
Gosu::Image.new(__image)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_markup(markup, line_height, font: Gosu.default_font_name, width: -1, spacing: 0, align: :left,
|
19
|
+
bold: false, italic: false, underline: false, retro: false)
|
20
|
+
__image = GosuFFI.Gosu_Image_create_from_markup(markup, font, line_height, width, spacing,
|
21
|
+
GosuFFI.font_alignment_flags(align),
|
22
|
+
GosuFFI.font_flags(bold, italic, underline),
|
23
|
+
GosuFFI.image_flags(retro: retro))
|
24
|
+
GosuFFI.check_last_error
|
25
|
+
Gosu::Image.new(__image)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.load_tiles(filename_or_image, tile_width, tile_height, retro: false, tileable: false)
|
29
|
+
flags = GosuFFI.image_flags(retro: retro, tileable: tileable)
|
30
|
+
|
31
|
+
images = []
|
32
|
+
callback = proc { |data, image| images << Gosu::Image.new(image) }
|
33
|
+
|
34
|
+
if filename_or_image.is_a? String
|
35
|
+
GosuFFI.Gosu_Image_create_from_tiles(filename_or_image, tile_width, tile_height, callback, nil, flags)
|
36
|
+
else
|
37
|
+
if filename_or_image.is_a? Gosu::Image
|
38
|
+
GosuFFI.Gosu_Image_create_tiles_from_image(filename_or_image.__pointer, tile_width, tile_height, callback, nil, flags)
|
39
|
+
else
|
40
|
+
image = Gosu::Image.new(filename_or_image, retro: retro, tileable: tileable)
|
41
|
+
GosuFFI.Gosu_Image_create_tiles_from_image(image.__pointer, tile_width, tile_height, callback, nil, flags)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
GosuFFI.check_last_error
|
46
|
+
|
47
|
+
return images
|
48
|
+
end
|
49
|
+
|
50
|
+
def initialize(object, retro: false, tileable: false, rect: nil)
|
51
|
+
if rect and rect.size != 4
|
52
|
+
raise ArgumentError, "Expected 4-element array as rect"
|
53
|
+
end
|
54
|
+
|
55
|
+
flags = GosuFFI.image_flags(retro: retro, tileable: tileable)
|
56
|
+
|
57
|
+
if object.is_a? String
|
58
|
+
if rect
|
59
|
+
__image = GosuFFI.Gosu_Image_create_from_rect(object, *rect, flags)
|
60
|
+
else
|
61
|
+
__image = GosuFFI.Gosu_Image_create(object, flags)
|
62
|
+
end
|
63
|
+
GosuFFI.check_last_error
|
64
|
+
elsif object.is_a?(FFI::Pointer)
|
65
|
+
__image = object
|
66
|
+
elsif object.respond_to?(:to_blob) and
|
67
|
+
object.respond_to?(:columns) and
|
68
|
+
object.respond_to?(:rows)
|
69
|
+
|
70
|
+
blob = object.to_blob { self.format = "RGBA"; self.depth = 8 }
|
71
|
+
|
72
|
+
# This creates a copy of the Ruby string data, which shouldn't be necessary with CRuby.
|
73
|
+
ptr = FFI::MemoryPointer.from_string(blob)
|
74
|
+
rect ||= [0, 0, object.columns, object.rows]
|
75
|
+
# Do not consider the terminating null byte part of the ptr length.
|
76
|
+
__image = GosuFFI.Gosu_Image_create_from_blob(ptr, ptr.size - 1, object.columns, object.rows, *rect, flags)
|
77
|
+
ptr.free
|
78
|
+
|
79
|
+
GosuFFI.check_last_error
|
80
|
+
else
|
81
|
+
raise ArgumentError, "Expected String or RMagick::Image (or a type compatible with it)"
|
82
|
+
end
|
83
|
+
|
84
|
+
@managed_pointer = FFI::AutoPointer.new(__image, GosuFFI.method(:Gosu_Image_destroy))
|
85
|
+
end
|
86
|
+
|
87
|
+
def __pointer
|
88
|
+
@managed_pointer
|
89
|
+
end
|
90
|
+
|
91
|
+
def width
|
92
|
+
GosuFFI.check_last_error(GosuFFI.Gosu_Image_width(__pointer))
|
93
|
+
end
|
94
|
+
|
95
|
+
def height
|
96
|
+
GosuFFI.check_last_error(GosuFFI.Gosu_Image_height(__pointer))
|
97
|
+
end
|
98
|
+
|
99
|
+
def draw(x, y, z, scale_x = 1, scale_y = 1, color = Gosu::Color::WHITE, flags = :default)
|
100
|
+
GosuFFI.Gosu_Image_draw(__pointer, x, y, z, scale_x, scale_y, GosuFFI.color_to_uint32(color), GosuFFI.blend_mode(flags))
|
101
|
+
GosuFFI.check_last_error
|
102
|
+
end
|
103
|
+
|
104
|
+
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)
|
105
|
+
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))
|
106
|
+
GosuFFI.check_last_error
|
107
|
+
end
|
108
|
+
|
109
|
+
def draw_as_quad(x1, y1, color1, x2, y2, color2, x3, y3, color3, x4, y4, color4, z = 0, mode = :default)
|
110
|
+
GosuFFI.Gosu_Image_draw_as_quad(x1, y1, GosuFFI.color_to_uint32(color1), x2, y2, GosuFFI.color_to_uint32(color2),
|
111
|
+
x3, y3, GosuFFI.color_to_uint32(color3), x4, y4, GosuFFI.color_to_uint32(color4),
|
112
|
+
z, GosuFFI.blend_mode(mode))
|
113
|
+
GosuFFI.check_last_error
|
114
|
+
end
|
115
|
+
|
116
|
+
def save(filename)
|
117
|
+
GosuFFI.Gosu_Image_save(__pointer, filename)
|
118
|
+
GosuFFI.check_last_error
|
119
|
+
end
|
120
|
+
|
121
|
+
def to_blob
|
122
|
+
blob = GosuFFI.check_last_error(GosuFFI.Gosu_Image_to_blob(__pointer))
|
123
|
+
blob.read_string(width * height * Gosu::Color::SIZEOF)
|
124
|
+
end
|
125
|
+
|
126
|
+
def subimage(left, top, width, height)
|
127
|
+
__subimage = GosuFFI.Gosu_Image_create_from_subimage(__pointer, left, top, width, height)
|
128
|
+
GosuFFI.check_last_error
|
129
|
+
Gosu::Image.new(__subimage)
|
130
|
+
end
|
131
|
+
|
132
|
+
def insert(image, x, y)
|
133
|
+
image_ = nil
|
134
|
+
if image.is_a?(Gosu::Image)
|
135
|
+
image_ = image.__pointer
|
136
|
+
elsif image.respond_to?(:to_blob) and
|
137
|
+
image.respond_to?(:rows) and
|
138
|
+
image.respond_to?(:columns)
|
139
|
+
image_ = Gosu::Image.new(image).__pointer
|
140
|
+
else
|
141
|
+
raise "Unable to insert image!"
|
142
|
+
end
|
143
|
+
|
144
|
+
GosuFFI.Gosu_Image_insert(__pointer, image_, x, y)
|
145
|
+
GosuFFI.check_last_error
|
146
|
+
end
|
147
|
+
|
148
|
+
def gl_tex_info
|
149
|
+
tex_info = GosuFFI.check_last_error(GosuFFI.Gosu_Image_gl_tex_info_create(__pointer))
|
150
|
+
tex_info ? GLTexInfo.new(tex_info) : nil
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
data/lib/gosu/numeric.rb
ADDED
@@ -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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
8
|
+
require "gosu"
|
data/lib/gosu/sample.rb
ADDED
@@ -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
|