ruby2d-rpeck-windows 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/assets/README.md +22 -0
- data/assets/Rakefile +85 -0
- data/assets/app.icns +0 -0
- data/assets/include/SDL2/SDL.h +138 -0
- data/assets/include/SDL2/SDL_assert.h +293 -0
- data/assets/include/SDL2/SDL_atomic.h +295 -0
- data/assets/include/SDL2/SDL_audio.h +859 -0
- data/assets/include/SDL2/SDL_bits.h +121 -0
- data/assets/include/SDL2/SDL_blendmode.h +123 -0
- data/assets/include/SDL2/SDL_clipboard.h +71 -0
- data/assets/include/SDL2/SDL_config.h +55 -0
- data/assets/include/SDL2/SDL_config_android.h +182 -0
- data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
- data/assets/include/SDL2/SDL_config_macosx.h +266 -0
- data/assets/include/SDL2/SDL_config_minimal.h +85 -0
- data/assets/include/SDL2/SDL_config_os2.h +188 -0
- data/assets/include/SDL2/SDL_config_pandora.h +135 -0
- data/assets/include/SDL2/SDL_config_psp.h +165 -0
- data/assets/include/SDL2/SDL_config_windows.h +288 -0
- data/assets/include/SDL2/SDL_config_winrt.h +243 -0
- data/assets/include/SDL2/SDL_config_wiz.h +149 -0
- data/assets/include/SDL2/SDL_copying.h +20 -0
- data/assets/include/SDL2/SDL_cpuinfo.h +299 -0
- data/assets/include/SDL2/SDL_egl.h +1676 -0
- data/assets/include/SDL2/SDL_endian.h +263 -0
- data/assets/include/SDL2/SDL_error.h +112 -0
- data/assets/include/SDL2/SDL_events.h +827 -0
- data/assets/include/SDL2/SDL_filesystem.h +136 -0
- data/assets/include/SDL2/SDL_gamecontroller.h +541 -0
- data/assets/include/SDL2/SDL_gesture.h +87 -0
- data/assets/include/SDL2/SDL_haptic.h +1247 -0
- data/assets/include/SDL2/SDL_hints.h +1578 -0
- data/assets/include/SDL2/SDL_image.h +161 -0
- data/assets/include/SDL2/SDL_joystick.h +499 -0
- data/assets/include/SDL2/SDL_keyboard.h +217 -0
- data/assets/include/SDL2/SDL_keycode.h +351 -0
- data/assets/include/SDL2/SDL_loadso.h +81 -0
- data/assets/include/SDL2/SDL_locale.h +101 -0
- data/assets/include/SDL2/SDL_log.h +211 -0
- data/assets/include/SDL2/SDL_main.h +180 -0
- data/assets/include/SDL2/SDL_messagebox.h +146 -0
- data/assets/include/SDL2/SDL_metal.h +117 -0
- data/assets/include/SDL2/SDL_misc.h +75 -0
- data/assets/include/SDL2/SDL_mixer.h +651 -0
- data/assets/include/SDL2/SDL_mouse.h +302 -0
- data/assets/include/SDL2/SDL_mutex.h +251 -0
- data/assets/include/SDL2/SDL_name.h +33 -0
- data/assets/include/SDL2/SDL_opengl.h +2183 -0
- data/assets/include/SDL2/SDL_opengl_glext.h +11180 -0
- data/assets/include/SDL2/SDL_opengles.h +39 -0
- data/assets/include/SDL2/SDL_opengles2.h +52 -0
- data/assets/include/SDL2/SDL_opengles2_gl2.h +621 -0
- data/assets/include/SDL2/SDL_opengles2_gl2ext.h +2050 -0
- data/assets/include/SDL2/SDL_opengles2_gl2platform.h +30 -0
- data/assets/include/SDL2/SDL_opengles2_khrplatform.h +282 -0
- data/assets/include/SDL2/SDL_pixels.h +479 -0
- data/assets/include/SDL2/SDL_platform.h +198 -0
- data/assets/include/SDL2/SDL_power.h +75 -0
- data/assets/include/SDL2/SDL_quit.h +58 -0
- data/assets/include/SDL2/SDL_rect.h +174 -0
- data/assets/include/SDL2/SDL_render.h +1158 -0
- data/assets/include/SDL2/SDL_revision.h +2 -0
- data/assets/include/SDL2/SDL_rwops.h +283 -0
- data/assets/include/SDL2/SDL_scancode.h +413 -0
- data/assets/include/SDL2/SDL_sensor.h +267 -0
- data/assets/include/SDL2/SDL_shape.h +144 -0
- data/assets/include/SDL2/SDL_stdinc.h +647 -0
- data/assets/include/SDL2/SDL_surface.h +563 -0
- data/assets/include/SDL2/SDL_system.h +325 -0
- data/assets/include/SDL2/SDL_syswm.h +354 -0
- data/assets/include/SDL2/SDL_test.h +69 -0
- data/assets/include/SDL2/SDL_test_assert.h +105 -0
- data/assets/include/SDL2/SDL_test_common.h +218 -0
- data/assets/include/SDL2/SDL_test_compare.h +69 -0
- data/assets/include/SDL2/SDL_test_crc32.h +124 -0
- data/assets/include/SDL2/SDL_test_font.h +81 -0
- data/assets/include/SDL2/SDL_test_fuzzer.h +384 -0
- data/assets/include/SDL2/SDL_test_harness.h +134 -0
- data/assets/include/SDL2/SDL_test_images.h +78 -0
- data/assets/include/SDL2/SDL_test_log.h +67 -0
- data/assets/include/SDL2/SDL_test_md5.h +129 -0
- data/assets/include/SDL2/SDL_test_memory.h +63 -0
- data/assets/include/SDL2/SDL_test_random.h +115 -0
- data/assets/include/SDL2/SDL_thread.h +366 -0
- data/assets/include/SDL2/SDL_timer.h +115 -0
- data/assets/include/SDL2/SDL_touch.h +102 -0
- data/assets/include/SDL2/SDL_ttf.h +294 -0
- data/assets/include/SDL2/SDL_types.h +29 -0
- data/assets/include/SDL2/SDL_version.h +162 -0
- data/assets/include/SDL2/SDL_video.h +1282 -0
- data/assets/include/SDL2/SDL_vulkan.h +276 -0
- data/assets/include/SDL2/begin_code.h +166 -0
- data/assets/include/SDL2/close_code.h +40 -0
- data/assets/include/glew.h +23686 -0
- data/assets/ios/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
- data/assets/ios/Assets.xcassets/Contents.json +6 -0
- data/assets/ios/Base.lproj/LaunchScreen.storyboard +27 -0
- data/assets/ios/Info.plist +43 -0
- data/assets/ios/MRuby.framework/Headers/mrbconf.h +143 -0
- data/assets/ios/MRuby.framework/Headers/mruby/array.h +280 -0
- data/assets/ios/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
- data/assets/ios/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
- data/assets/ios/MRuby.framework/Headers/mruby/boxing_word.h +144 -0
- data/assets/ios/MRuby.framework/Headers/mruby/class.h +97 -0
- data/assets/ios/MRuby.framework/Headers/mruby/common.h +77 -0
- data/assets/ios/MRuby.framework/Headers/mruby/compile.h +195 -0
- data/assets/ios/MRuby.framework/Headers/mruby/data.h +75 -0
- data/assets/ios/MRuby.framework/Headers/mruby/debug.h +67 -0
- data/assets/ios/MRuby.framework/Headers/mruby/dump.h +196 -0
- data/assets/ios/MRuby.framework/Headers/mruby/error.h +75 -0
- data/assets/ios/MRuby.framework/Headers/mruby/gc.h +91 -0
- data/assets/ios/MRuby.framework/Headers/mruby/hash.h +215 -0
- data/assets/ios/MRuby.framework/Headers/mruby/irep.h +75 -0
- data/assets/ios/MRuby.framework/Headers/mruby/istruct.h +47 -0
- data/assets/ios/MRuby.framework/Headers/mruby/khash.h +274 -0
- data/assets/ios/MRuby.framework/Headers/mruby/numeric.h +161 -0
- data/assets/ios/MRuby.framework/Headers/mruby/object.h +44 -0
- data/assets/ios/MRuby.framework/Headers/mruby/opcode.h +69 -0
- data/assets/ios/MRuby.framework/Headers/mruby/ops.h +117 -0
- data/assets/ios/MRuby.framework/Headers/mruby/proc.h +131 -0
- data/assets/ios/MRuby.framework/Headers/mruby/range.h +49 -0
- data/assets/ios/MRuby.framework/Headers/mruby/re.h +16 -0
- data/assets/ios/MRuby.framework/Headers/mruby/string.h +444 -0
- data/assets/ios/MRuby.framework/Headers/mruby/throw.h +55 -0
- data/assets/ios/MRuby.framework/Headers/mruby/value.h +309 -0
- data/assets/ios/MRuby.framework/Headers/mruby/variable.h +136 -0
- data/assets/ios/MRuby.framework/Headers/mruby/version.h +110 -0
- data/assets/ios/MRuby.framework/Headers/mruby.h +1282 -0
- data/assets/ios/MRuby.framework/Info.plist +20 -0
- data/assets/ios/MRuby.framework/MRuby +0 -0
- data/assets/ios/MyApp.xcodeproj/project.pbxproj +368 -0
- data/assets/ios/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
- data/assets/ios/main.c +1 -0
- data/assets/macos/lib/libFLAC.a +0 -0
- data/assets/macos/lib/libSDL2.a +0 -0
- data/assets/macos/lib/libSDL2_image.a +0 -0
- data/assets/macos/lib/libSDL2_mixer.a +0 -0
- data/assets/macos/lib/libSDL2_ttf.a +0 -0
- data/assets/macos/lib/libfreetype.a +0 -0
- data/assets/macos/lib/libjpeg.a +0 -0
- data/assets/macos/lib/libmodplug.a +0 -0
- data/assets/macos/lib/libmpg123.a +0 -0
- data/assets/macos/lib/libogg.a +0 -0
- data/assets/macos/lib/libpng16.a +0 -0
- data/assets/macos/lib/libtiff.a +0 -0
- data/assets/macos/lib/libvorbis.a +0 -0
- data/assets/macos/lib/libvorbisfile.a +0 -0
- data/assets/macos/lib/libwebp.a +0 -0
- data/assets/mingw/bin/SDL2.dll +0 -0
- data/assets/mingw/bin/SDL2_image.dll +0 -0
- data/assets/mingw/bin/SDL2_mixer.dll +0 -0
- data/assets/mingw/bin/SDL2_ttf.dll +0 -0
- data/assets/mingw/bin/glew32.dll +0 -0
- data/assets/mingw/bin/libFLAC-8.dll +0 -0
- data/assets/mingw/bin/libfreetype-6.dll +0 -0
- data/assets/mingw/bin/libjpeg-9.dll +0 -0
- data/assets/mingw/bin/libmodplug-1.dll +0 -0
- data/assets/mingw/bin/libmpg123-0.dll +0 -0
- data/assets/mingw/bin/libogg-0.dll +0 -0
- data/assets/mingw/bin/libopus-0.dll +0 -0
- data/assets/mingw/bin/libopusfile-0.dll +0 -0
- data/assets/mingw/bin/libpng16-16.dll +0 -0
- data/assets/mingw/bin/libtiff-5.dll +0 -0
- data/assets/mingw/bin/libvorbis-0.dll +0 -0
- data/assets/mingw/bin/libvorbisfile-3.dll +0 -0
- data/assets/mingw/bin/libwebp-7.dll +0 -0
- data/assets/mingw/bin/libwinpthread-1.dll +0 -0
- data/assets/mingw/bin/zlib1.dll +0 -0
- data/assets/mingw/lib/libSDL2.a +0 -0
- data/assets/mingw/lib/libSDL2.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_image.a +0 -0
- data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_mixer.a +0 -0
- data/assets/mingw/lib/libSDL2_mixer.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_test.a +0 -0
- data/assets/mingw/lib/libSDL2_ttf.a +0 -0
- data/assets/mingw/lib/libSDL2_ttf.dll.a +0 -0
- data/assets/mingw/lib/libSDL2main.a +0 -0
- data/assets/mingw/lib/libglew32.a +0 -0
- data/assets/mingw/lib/libglew32.dll.a +0 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json +17 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json +17 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json +32 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/LaunchImage.launchimage/Contents.json +22 -0
- data/assets/tvos/Info.plist +30 -0
- data/assets/tvos/MRuby.framework/Headers/mrbconf.h +143 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/array.h +280 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/boxing_word.h +144 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/class.h +97 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/common.h +77 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/compile.h +195 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/data.h +75 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/debug.h +67 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/dump.h +196 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/error.h +75 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/gc.h +91 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/hash.h +215 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/irep.h +75 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/istruct.h +47 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/khash.h +274 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/numeric.h +161 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/object.h +44 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/opcode.h +69 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/ops.h +117 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/proc.h +131 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/range.h +49 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/re.h +16 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/string.h +444 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/throw.h +55 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/value.h +309 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/variable.h +136 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/version.h +110 -0
- data/assets/tvos/MRuby.framework/Headers/mruby.h +1282 -0
- data/assets/tvos/MRuby.framework/Info.plist +20 -0
- data/assets/tvos/MRuby.framework/MRuby +0 -0
- data/assets/tvos/MyApp.xcodeproj/project.pbxproj +350 -0
- data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
- data/assets/tvos/main.c +1 -0
- data/bin/ruby2d +142 -0
- data/ext/ruby2d/common.c +185 -0
- data/ext/ruby2d/controllers.c +110 -0
- data/ext/ruby2d/extconf.rb +147 -0
- data/ext/ruby2d/font.c +35 -0
- data/ext/ruby2d/gl.c +398 -0
- data/ext/ruby2d/gl2.c +86 -0
- data/ext/ruby2d/gl3.c +305 -0
- data/ext/ruby2d/gles.c +249 -0
- data/ext/ruby2d/image.c +58 -0
- data/ext/ruby2d/input.c +48 -0
- data/ext/ruby2d/music.c +127 -0
- data/ext/ruby2d/ruby2d.c +1374 -0
- data/ext/ruby2d/ruby2d.h +656 -0
- data/ext/ruby2d/shapes.c +154 -0
- data/ext/ruby2d/sound.c +118 -0
- data/ext/ruby2d/text.c +22 -0
- data/ext/ruby2d/window.c +414 -0
- data/lib/ruby2d/circle.rb +43 -0
- data/lib/ruby2d/cli/build.rb +237 -0
- data/lib/ruby2d/cli/colorize.rb +10 -0
- data/lib/ruby2d/cli/console.rb +65 -0
- data/lib/ruby2d/cli/enable_console.rb +5 -0
- data/lib/ruby2d/cli/launch.rb +50 -0
- data/lib/ruby2d/color.rb +136 -0
- data/lib/ruby2d/dsl.rb +46 -0
- data/lib/ruby2d/entity.rb +17 -0
- data/lib/ruby2d/exceptions.rb +6 -0
- data/lib/ruby2d/font.rb +96 -0
- data/lib/ruby2d/image.rb +58 -0
- data/lib/ruby2d/line.rb +89 -0
- data/lib/ruby2d/music.rb +67 -0
- data/lib/ruby2d/pixel.rb +17 -0
- data/lib/ruby2d/quad.rb +96 -0
- data/lib/ruby2d/rectangle.rb +65 -0
- data/lib/ruby2d/renderable.rb +40 -0
- data/lib/ruby2d/ruby2d.so +0 -0
- data/lib/ruby2d/sound.rb +55 -0
- data/lib/ruby2d/sprite.rb +232 -0
- data/lib/ruby2d/square.rb +37 -0
- data/lib/ruby2d/text.rb +76 -0
- data/lib/ruby2d/texture.rb +28 -0
- data/lib/ruby2d/tileset.rb +87 -0
- data/lib/ruby2d/triangle.rb +82 -0
- data/lib/ruby2d/version.rb +5 -0
- data/lib/ruby2d/vertices.rb +84 -0
- data/lib/ruby2d/window.rb +673 -0
- data/lib/ruby2d.rb +69 -0
- metadata +346 -0
data/lib/ruby2d/font.rb
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Ruby2D::Font
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
class Font
|
|
5
|
+
@@loaded_fonts = {}
|
|
6
|
+
|
|
7
|
+
attr_reader :ttf_font
|
|
8
|
+
|
|
9
|
+
def initialize(path, size, style=nil)
|
|
10
|
+
@ttf_font = Font.ext_load(path, size, style.to_s)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
def load(path, size, style=nil)
|
|
15
|
+
unless File.exist? path
|
|
16
|
+
raise Error, "Cannot find font file `#{path}`"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
@@loaded_fonts[[path, size, style]] ||= Font.new(path, size, style)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# List all fonts, names only
|
|
23
|
+
def all
|
|
24
|
+
all_paths.map { |path| path.split('/').last.chomp('.ttf').downcase }.uniq.sort
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Find a font file path from its name
|
|
28
|
+
def path(font_name)
|
|
29
|
+
font = all_paths.find { |path| path.downcase.include?(font_name) }
|
|
30
|
+
font = File.join(directory, font) if directory.include?('Windows') && RUBY_ENGINE == 'mruby'
|
|
31
|
+
font
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Get all fonts with full file paths
|
|
35
|
+
def all_paths
|
|
36
|
+
if RUBY_ENGINE == 'mruby'
|
|
37
|
+
fonts = Dir.entries(directory)
|
|
38
|
+
# If MRI and/or non-Bash shell (like cmd.exe)
|
|
39
|
+
else
|
|
40
|
+
fonts = Dir["#{directory}/**/*.ttf"]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
fonts = fonts.reject do |f|
|
|
44
|
+
f.downcase.include?('bold') ||
|
|
45
|
+
f.downcase.include?('italic') ||
|
|
46
|
+
f.downcase.include?('oblique') ||
|
|
47
|
+
f.downcase.include?('narrow') ||
|
|
48
|
+
f.downcase.include?('black')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
fonts.select {|font| File.extname(font) == ".ttf" }.sort_by { |f| f.downcase.chomp '.ttf' }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Get the default font
|
|
55
|
+
def default
|
|
56
|
+
if all.include? 'arial'
|
|
57
|
+
path 'arial'
|
|
58
|
+
else
|
|
59
|
+
all_paths.first
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Get the fonts directory for the current platform
|
|
64
|
+
def directory
|
|
65
|
+
macos_font_path = '/Library/Fonts'
|
|
66
|
+
linux_font_path = '/usr/share/fonts'
|
|
67
|
+
windows_font_path = 'C:/Windows/Fonts'
|
|
68
|
+
openbsd_font_path = '/usr/X11R6/lib/X11/fonts'
|
|
69
|
+
|
|
70
|
+
# If MRI and/or non-Bash shell (like cmd.exe)
|
|
71
|
+
if Object.const_defined? :RUBY_PLATFORM
|
|
72
|
+
case RUBY_PLATFORM
|
|
73
|
+
when /darwin/ # macOS
|
|
74
|
+
macos_font_path
|
|
75
|
+
when /linux/
|
|
76
|
+
linux_font_path
|
|
77
|
+
when /mingw/
|
|
78
|
+
windows_font_path
|
|
79
|
+
when /openbsd/
|
|
80
|
+
openbsd_font_path
|
|
81
|
+
end
|
|
82
|
+
# If MRuby
|
|
83
|
+
else
|
|
84
|
+
|
|
85
|
+
# RPECK 23/12/2021 -- the uname command was not available on Windows
|
|
86
|
+
[macos_font_path, linux_font_path, windows_font_path, openbsd_font_path].each do |folder|
|
|
87
|
+
return folder if File.exists? folder
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
end
|
data/lib/ruby2d/image.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Ruby2D::Image
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
class Image
|
|
5
|
+
include Renderable
|
|
6
|
+
|
|
7
|
+
attr_reader :path
|
|
8
|
+
attr_accessor :x, :y, :width, :height, :rotate, :data
|
|
9
|
+
|
|
10
|
+
def self.load_image(path)
|
|
11
|
+
unless File.exist? path
|
|
12
|
+
raise Error, "Cannot find image file `#{path}`"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
ext_load_image(path)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def initialize(path, opts = {})
|
|
19
|
+
@path = path
|
|
20
|
+
|
|
21
|
+
@texture = Texture.new(*Image.load_image(@path))
|
|
22
|
+
@width = opts[:width] || @texture.width
|
|
23
|
+
@height = opts[:height] || @texture.height
|
|
24
|
+
|
|
25
|
+
@x = opts[:x] || 0
|
|
26
|
+
@y = opts[:y] || 0
|
|
27
|
+
@z = opts[:z] || 0
|
|
28
|
+
@rotate = opts[:rotate] || 0
|
|
29
|
+
self.color = opts[:color] || 'white'
|
|
30
|
+
self.color.opacity = opts[:opacity] if opts[:opacity]
|
|
31
|
+
|
|
32
|
+
unless opts[:show] == false then add end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def draw(opts = {})
|
|
36
|
+
Window.render_ready_check
|
|
37
|
+
|
|
38
|
+
opts[:width] = opts[:width] || @width
|
|
39
|
+
opts[:height] = opts[:height] || @height
|
|
40
|
+
opts[:rotate] = opts[:rotate] || @rotate
|
|
41
|
+
unless opts[:color]
|
|
42
|
+
opts[:color] = [1.0, 1.0, 1.0, 1.0]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
render(x: opts[:x], y: opts[:y], width: opts[:width], height: opts[:height], color: Color.new(opts[:color]), rotate: opts[:rotate])
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def render(x: @x, y: @y, width: @width, height: @height, color: @color, rotate: @rotate)
|
|
51
|
+
vertices = Vertices.new(x, y, width, height, rotate)
|
|
52
|
+
|
|
53
|
+
@texture.draw(
|
|
54
|
+
vertices.coordinates, vertices.texture_coordinates, color
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/ruby2d/line.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Ruby2D::Line
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
class Line
|
|
5
|
+
include Renderable
|
|
6
|
+
|
|
7
|
+
attr_accessor :x1, :x2, :y1, :y2, :width
|
|
8
|
+
|
|
9
|
+
def initialize(opts = {})
|
|
10
|
+
@x1 = opts[:x1] || 0
|
|
11
|
+
@y1 = opts[:y1] || 0
|
|
12
|
+
@x2 = opts[:x2] || 100
|
|
13
|
+
@y2 = opts[:y2] || 100
|
|
14
|
+
@z = opts[:z] || 0
|
|
15
|
+
@width = opts[:width] || 2
|
|
16
|
+
self.color = opts[:color] || 'white'
|
|
17
|
+
self.color.opacity = opts[:opacity] if opts[:opacity]
|
|
18
|
+
add
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def color=(c)
|
|
22
|
+
@color = Color.set(c)
|
|
23
|
+
update_color(@color)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Return the length of the line
|
|
27
|
+
def length
|
|
28
|
+
points_distance(@x1, @y1, @x2, @y2)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Line contains a point if the point is closer than the length of line from
|
|
32
|
+
# both ends and if the distance from point to line is smaller than half of
|
|
33
|
+
# the width. For reference:
|
|
34
|
+
# https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
|
|
35
|
+
def contains?(x, y)
|
|
36
|
+
points_distance(x1, y1, x, y) <= length &&
|
|
37
|
+
points_distance(x2, y2, x, y) <= length &&
|
|
38
|
+
(((@y2 - @y1) * x - (@x2 - @x1) * y + @x2 * @y1 - @y2 * @x1).abs / length) <= 0.5 * @width
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.draw(opts = {})
|
|
42
|
+
Window.render_ready_check
|
|
43
|
+
|
|
44
|
+
ext_draw([
|
|
45
|
+
opts[:x1], opts[:y1], opts[:x2], opts[:y2], opts[:width],
|
|
46
|
+
opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
|
|
47
|
+
opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
|
|
48
|
+
opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
|
|
49
|
+
opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
|
|
50
|
+
])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def render
|
|
56
|
+
self.class.ext_draw([
|
|
57
|
+
@x1, @y1, @x2, @y2, @width,
|
|
58
|
+
@c1.r, @c1.g, @c1.b, @c1.a,
|
|
59
|
+
@c2.r, @c2.g, @c2.b, @c2.a,
|
|
60
|
+
@c3.r, @c3.g, @c3.b, @c3.a,
|
|
61
|
+
@c4.r, @c4.g, @c4.b, @c4.a
|
|
62
|
+
])
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Calculate the distance between two points
|
|
66
|
+
def points_distance(x1, y1, x2, y2)
|
|
67
|
+
Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def update_color(c)
|
|
71
|
+
if c.is_a? Color::Set
|
|
72
|
+
if c.length == 4
|
|
73
|
+
@c1 = c[0]
|
|
74
|
+
@c2 = c[1]
|
|
75
|
+
@c3 = c[2]
|
|
76
|
+
@c4 = c[3]
|
|
77
|
+
else
|
|
78
|
+
raise ArgumentError, "`#{self.class}` requires 4 colors, one for each vertex. #{c.length} were given."
|
|
79
|
+
end
|
|
80
|
+
else
|
|
81
|
+
@c1 = c
|
|
82
|
+
@c2 = c
|
|
83
|
+
@c3 = c
|
|
84
|
+
@c4 = c
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
end
|
data/lib/ruby2d/music.rb
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Ruby2D::Music
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
class Music
|
|
5
|
+
|
|
6
|
+
attr_reader :path
|
|
7
|
+
attr_accessor :loop, :data
|
|
8
|
+
|
|
9
|
+
def initialize(path, opts = {})
|
|
10
|
+
unless File.exist? path
|
|
11
|
+
raise Error, "Cannot find audio file `#{path}`"
|
|
12
|
+
end
|
|
13
|
+
@path = path
|
|
14
|
+
@loop = opts[:loop] || false
|
|
15
|
+
unless ext_init(@path)
|
|
16
|
+
raise Error, "Music `#{@path}` cannot be created"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Play the music
|
|
21
|
+
def play
|
|
22
|
+
ext_play
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Pause the music
|
|
26
|
+
def pause
|
|
27
|
+
ext_pause
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Resume paused music
|
|
31
|
+
def resume
|
|
32
|
+
ext_resume
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Stop playing the music, start at beginning
|
|
36
|
+
def stop
|
|
37
|
+
ext_stop
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Returns the volume, in percentage
|
|
41
|
+
def self.volume
|
|
42
|
+
self.ext_get_volume
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Set music volume, 0 to 100%
|
|
46
|
+
def self.volume=(v)
|
|
47
|
+
# If a negative value, volume will be 0
|
|
48
|
+
if v < 0 then v = 0 end
|
|
49
|
+
self.ext_set_volume(v)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Alias instance methods to class methods
|
|
53
|
+
def volume; Music.volume end
|
|
54
|
+
def volume=(v); Music.volume=(v) end
|
|
55
|
+
|
|
56
|
+
# Fade out music over provided milliseconds
|
|
57
|
+
def fadeout(ms)
|
|
58
|
+
ext_fadeout(ms)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Returns the length in seconds
|
|
62
|
+
def length
|
|
63
|
+
ext_length
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
end
|
data/lib/ruby2d/pixel.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Ruby2D::Pixel
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
class Pixel
|
|
5
|
+
|
|
6
|
+
def self.draw(opts = {})
|
|
7
|
+
ext_draw([
|
|
8
|
+
opts[:x] , opts[:y],
|
|
9
|
+
opts[:x] + opts[:size], opts[:y],
|
|
10
|
+
opts[:x] + opts[:size], opts[:y] + opts[:size],
|
|
11
|
+
opts[:x] , opts[:y] + opts[:size],
|
|
12
|
+
opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
|
|
13
|
+
])
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/ruby2d/quad.rb
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Ruby2D::Quad
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
class Quad
|
|
5
|
+
include Renderable
|
|
6
|
+
|
|
7
|
+
# Coordinates in clockwise order, starting at top left:
|
|
8
|
+
# x1,y1 == top left
|
|
9
|
+
# x2,y2 == top right
|
|
10
|
+
# x3,y3 == bottom right
|
|
11
|
+
# x4,y4 == bottom left
|
|
12
|
+
attr_accessor :x1, :y1, :c1,
|
|
13
|
+
:x2, :y2, :c2,
|
|
14
|
+
:x3, :y3, :c3,
|
|
15
|
+
:x4, :y4, :c4
|
|
16
|
+
|
|
17
|
+
def initialize(opts = {})
|
|
18
|
+
@x1 = opts[:x1] || 0
|
|
19
|
+
@y1 = opts[:y1] || 0
|
|
20
|
+
@x2 = opts[:x2] || 100
|
|
21
|
+
@y2 = opts[:y2] || 0
|
|
22
|
+
@x3 = opts[:x3] || 100
|
|
23
|
+
@y3 = opts[:y3] || 100
|
|
24
|
+
@x4 = opts[:x4] || 0
|
|
25
|
+
@y4 = opts[:y4] || 100
|
|
26
|
+
@z = opts[:z] || 0
|
|
27
|
+
self.color = opts[:color] || 'white'
|
|
28
|
+
self.color.opacity = opts[:opacity] if opts[:opacity]
|
|
29
|
+
add
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def color=(c)
|
|
33
|
+
@color = Color.set(c)
|
|
34
|
+
update_color(@color)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The logic is the same as for a triangle
|
|
38
|
+
# See triangle.rb for reference
|
|
39
|
+
def contains?(x, y)
|
|
40
|
+
self_area = triangle_area(@x1, @y1, @x2, @y2, @x3, @y3) +
|
|
41
|
+
triangle_area(@x1, @y1, @x3, @y3, @x4, @y4)
|
|
42
|
+
|
|
43
|
+
questioned_area = triangle_area(@x1, @y1, @x2, @y2, x, y) +
|
|
44
|
+
triangle_area(@x2, @y2, @x3, @y3, x, y) +
|
|
45
|
+
triangle_area(@x3, @y3, @x4, @y4, x, y) +
|
|
46
|
+
triangle_area(@x4, @y4, @x1, @y1, x, y)
|
|
47
|
+
|
|
48
|
+
questioned_area <= self_area
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.draw(opts = {})
|
|
52
|
+
Window.render_ready_check
|
|
53
|
+
|
|
54
|
+
ext_draw([
|
|
55
|
+
opts[:x1], opts[:y1], opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
|
|
56
|
+
opts[:x2], opts[:y2], opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
|
|
57
|
+
opts[:x3], opts[:y3], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
|
|
58
|
+
opts[:x4], opts[:y4], opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
|
|
59
|
+
])
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def render
|
|
65
|
+
self.class.ext_draw([
|
|
66
|
+
@x1, @y1, @c1.r, @c1.g, @c1.b, @c1.a,
|
|
67
|
+
@x2, @y2, @c2.r, @c2.g, @c2.b, @c2.a,
|
|
68
|
+
@x3, @y3, @c3.r, @c3.g, @c3.b, @c3.a,
|
|
69
|
+
@x4, @y4, @c4.r, @c4.g, @c4.b, @c4.a
|
|
70
|
+
])
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def triangle_area(x1, y1, x2, y2, x3, y3)
|
|
74
|
+
(x1*y2 + x2*y3 + x3*y1 - x3*y2 - x1*y3 - x2*y1).abs / 2
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def update_color(c)
|
|
78
|
+
if c.is_a? Color::Set
|
|
79
|
+
if c.length == 4
|
|
80
|
+
@c1 = c[0]
|
|
81
|
+
@c2 = c[1]
|
|
82
|
+
@c3 = c[2]
|
|
83
|
+
@c4 = c[3]
|
|
84
|
+
else
|
|
85
|
+
raise ArgumentError, "`#{self.class}` requires 4 colors, one for each vertex. #{c.length} were given."
|
|
86
|
+
end
|
|
87
|
+
else
|
|
88
|
+
@c1 = c
|
|
89
|
+
@c2 = c
|
|
90
|
+
@c3 = c
|
|
91
|
+
@c4 = c
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Ruby2D::Rectangle
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
class Rectangle < Quad
|
|
5
|
+
|
|
6
|
+
def initialize(opts = {})
|
|
7
|
+
@x = opts[:x] || 0
|
|
8
|
+
@y = opts[:y] || 0
|
|
9
|
+
@z = opts[:z] || 0
|
|
10
|
+
@width = opts[:width] || 200
|
|
11
|
+
@height = opts[:height] || 100
|
|
12
|
+
self.color = opts[:color] || 'white'
|
|
13
|
+
self.color.opacity = opts[:opacity] if opts[:opacity]
|
|
14
|
+
update_coords(@x, @y, @width, @height)
|
|
15
|
+
add
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def x=(x)
|
|
19
|
+
@x = @x1 = x
|
|
20
|
+
@x2 = x + @width
|
|
21
|
+
@x3 = x + @width
|
|
22
|
+
@x4 = x
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def y=(y)
|
|
26
|
+
@y = @y1 = y
|
|
27
|
+
@y2 = y
|
|
28
|
+
@y3 = y + @height
|
|
29
|
+
@y4 = y + @height
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def width=(w)
|
|
33
|
+
@width = w
|
|
34
|
+
update_coords(@x, @y, w, @height)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def height=(h)
|
|
38
|
+
@height = h
|
|
39
|
+
update_coords(@x, @y, @width, h)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.draw(opts = {})
|
|
43
|
+
ext_draw([
|
|
44
|
+
opts[:x] , opts[:y] , opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
|
|
45
|
+
opts[:x] + opts[:width], opts[:y] , opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
|
|
46
|
+
opts[:x] + opts[:width], opts[:y] + opts[:height], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
|
|
47
|
+
opts[:x] , opts[:y] + opts[:height], opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
|
|
48
|
+
])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def update_coords(x, y, w, h)
|
|
54
|
+
@x1 = x
|
|
55
|
+
@y1 = y
|
|
56
|
+
@x2 = x + w
|
|
57
|
+
@y2 = y
|
|
58
|
+
@x3 = x + w
|
|
59
|
+
@y3 = y + h
|
|
60
|
+
@x4 = x
|
|
61
|
+
@y4 = y + h
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Ruby2D::Renderable
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
module Renderable
|
|
5
|
+
|
|
6
|
+
attr_reader :x, :y, :z, :width, :height, :color
|
|
7
|
+
|
|
8
|
+
# Set the z position (depth) of the object
|
|
9
|
+
def z=(z)
|
|
10
|
+
remove
|
|
11
|
+
@z = z
|
|
12
|
+
add
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Add the object to the window
|
|
16
|
+
def add
|
|
17
|
+
Window.add(self)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Remove the object from the window
|
|
21
|
+
def remove
|
|
22
|
+
Window.remove(self)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Set the color value
|
|
26
|
+
def color=(c)
|
|
27
|
+
@color = Color.new(c)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Allow British English spelling of color
|
|
31
|
+
alias_method :colour, :color
|
|
32
|
+
alias_method :colour=, :color=
|
|
33
|
+
|
|
34
|
+
# Add a contains method stub
|
|
35
|
+
def contains?(x, y)
|
|
36
|
+
x >= @x && x <= (@x + @width) && y >= @y && y <= (@y + @height)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
Binary file
|
data/lib/ruby2d/sound.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Ruby2D::Sound
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
class Sound
|
|
5
|
+
|
|
6
|
+
attr_reader :path
|
|
7
|
+
attr_accessor :data
|
|
8
|
+
|
|
9
|
+
def initialize(path)
|
|
10
|
+
unless File.exist? path
|
|
11
|
+
raise Error, "Cannot find audio file `#{path}`"
|
|
12
|
+
end
|
|
13
|
+
@path = path
|
|
14
|
+
unless ext_init(@path)
|
|
15
|
+
raise Error, "Sound `#{@path}` cannot be created"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Play the sound
|
|
20
|
+
def play
|
|
21
|
+
ext_play
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Returns the length in seconds
|
|
25
|
+
def length
|
|
26
|
+
ext_length
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Get the volume of the sound
|
|
30
|
+
def volume
|
|
31
|
+
ext_get_volume
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Set the volume of the sound
|
|
35
|
+
def volume=(v)
|
|
36
|
+
# Clamp value to between 0-100
|
|
37
|
+
if v < 0 then v = 0 end
|
|
38
|
+
if v > 100 then v = 100 end
|
|
39
|
+
ext_set_volume(v)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Get the volume of the sound mixer
|
|
43
|
+
def self.mix_volume
|
|
44
|
+
ext_get_mix_volume
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Set the volume of the sound mixer
|
|
48
|
+
def self.mix_volume=(v)
|
|
49
|
+
# Clamp value to between 0-100
|
|
50
|
+
if v < 0 then v = 0 end
|
|
51
|
+
if v > 100 then v = 100 end
|
|
52
|
+
ext_set_mix_volume(v)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|