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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Ruby2D::Circle
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
class Circle
|
|
5
|
+
include Renderable
|
|
6
|
+
|
|
7
|
+
attr_accessor :x, :y, :radius, :sectors
|
|
8
|
+
|
|
9
|
+
def initialize(opts = {})
|
|
10
|
+
@x = opts[:x] || 25
|
|
11
|
+
@y = opts[:y] || 25
|
|
12
|
+
@z = opts[:z] || 0
|
|
13
|
+
@radius = opts[:radius] || 50
|
|
14
|
+
@sectors = opts[:sectors] || 30
|
|
15
|
+
self.color = opts[:color] || 'white'
|
|
16
|
+
self.color.opacity = opts[:opacity] if opts[:opacity]
|
|
17
|
+
add
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def contains?(x, y)
|
|
21
|
+
Math.sqrt((x - @x)**2 + (y - @y)**2) <= @radius
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.draw(opts = {})
|
|
25
|
+
Window.render_ready_check
|
|
26
|
+
|
|
27
|
+
ext_draw([
|
|
28
|
+
opts[:x], opts[:y], opts[:radius], opts[:sectors],
|
|
29
|
+
opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
|
|
30
|
+
])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def render
|
|
36
|
+
self.class.ext_draw([
|
|
37
|
+
@x, @y, @radius, @sectors,
|
|
38
|
+
@color.r, @color.g, @color.b, @color.a
|
|
39
|
+
])
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Build a Ruby 2D app natively and for the web
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
5
|
+
# The installed gem directory
|
|
6
|
+
@gem_dir = "#{Gem::Specification.find_by_name('ruby2d').gem_dir}"
|
|
7
|
+
|
|
8
|
+
# The Ruby 2D library files
|
|
9
|
+
@lib_files = [
|
|
10
|
+
'cli/colorize',
|
|
11
|
+
'exceptions',
|
|
12
|
+
'renderable',
|
|
13
|
+
'color',
|
|
14
|
+
'window',
|
|
15
|
+
'dsl',
|
|
16
|
+
'quad',
|
|
17
|
+
'line',
|
|
18
|
+
'circle',
|
|
19
|
+
'rectangle',
|
|
20
|
+
'square',
|
|
21
|
+
'triangle',
|
|
22
|
+
'image',
|
|
23
|
+
'sprite',
|
|
24
|
+
'font',
|
|
25
|
+
'text',
|
|
26
|
+
'sound',
|
|
27
|
+
'music',
|
|
28
|
+
'texture',
|
|
29
|
+
'vertices',
|
|
30
|
+
'../ruby2d'
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# Check if source file provided is good
|
|
35
|
+
def check_build_src_file(rb_file)
|
|
36
|
+
if !rb_file
|
|
37
|
+
puts "Please provide a Ruby file to build"
|
|
38
|
+
exit
|
|
39
|
+
elsif !File.exist? rb_file
|
|
40
|
+
puts "Can't find file: #{rb_file}"
|
|
41
|
+
exit
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Assemble the Ruby 2D library in one `.rb` file
|
|
47
|
+
def make_lib
|
|
48
|
+
FileUtils.mkdir_p 'build'
|
|
49
|
+
|
|
50
|
+
lib_dir = "#{@gem_dir}/lib/ruby2d/"
|
|
51
|
+
|
|
52
|
+
lib = ''
|
|
53
|
+
@lib_files.each do |f|
|
|
54
|
+
lib << File.read("#{lib_dir + f}.rb") + "\n\n"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
File.write('build/lib.rb', lib)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# Remove `require 'ruby2d'` from source file
|
|
62
|
+
def strip_require(file)
|
|
63
|
+
output = ''
|
|
64
|
+
File.foreach(file) do |line|
|
|
65
|
+
output << line if line !~ /require ('|")ruby2d('|")/ && line !~ /require/
|
|
66
|
+
|
|
67
|
+
if line !~ /require ('|")ruby2d('|")/ && line =~ /require/ && line !~ /require_relative/
|
|
68
|
+
output << File.read(eval(line.gsub("require", "")) + ".rb")
|
|
69
|
+
output << " "
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
return output
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# Build a native version of the provided Ruby application
|
|
77
|
+
def build_native(rb_file)
|
|
78
|
+
check_build_src_file(rb_file)
|
|
79
|
+
|
|
80
|
+
# Check if MRuby exists; if not, quit
|
|
81
|
+
if `#{RUBY_PLATFORM =~ /mingw/ ? 'where' : 'which'} mruby`.empty?
|
|
82
|
+
puts "#{'Error:'.error} Can't find MRuby, which is needed to build native Ruby 2D applications.\n"
|
|
83
|
+
exit
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Add debugging information to produce backtrace
|
|
87
|
+
if @debug then debug_flag = '-g' end
|
|
88
|
+
|
|
89
|
+
# Assemble the Ruby 2D library in one `.rb` file and compile to bytecode
|
|
90
|
+
make_lib
|
|
91
|
+
`mrbc #{debug_flag} -Bruby2d_lib -obuild/lib.c build/lib.rb`
|
|
92
|
+
|
|
93
|
+
# Read the provided Ruby source file, copy to build dir and compile to bytecode
|
|
94
|
+
File.open('build/src.rb', 'w') { |file| file << strip_require(rb_file) }
|
|
95
|
+
`mrbc #{debug_flag} -Bruby2d_app -obuild/src.c build/src.rb`
|
|
96
|
+
|
|
97
|
+
# Combine contents of C source files and bytecode into one file
|
|
98
|
+
open('build/app.c', 'w') do |f|
|
|
99
|
+
f << "#define MRUBY 1" << "\n\n"
|
|
100
|
+
f << File.read("build/lib.c") << "\n\n"
|
|
101
|
+
f << File.read("build/src.c") << "\n\n"
|
|
102
|
+
f << File.read("#{@gem_dir}/ext/ruby2d/ruby2d.c")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Icon
|
|
106
|
+
if RUBY_PLATFORM =~ /mingw/
|
|
107
|
+
open('build/icon.rc', 'w') do |f|
|
|
108
|
+
f << 'id ICON "icon.ico"'
|
|
109
|
+
end
|
|
110
|
+
`windres build/icon.rc build/icon.o`
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Compile to a native executable
|
|
114
|
+
`cc build/icon.o build/app.c #{@gem_dir}/ext/ruby2d/common.c #{@gem_dir}/ext/ruby2d/controllers.c #{@gem_dir}/ext/ruby2d/gl.c #{@gem_dir}/ext/ruby2d/gl2.c #{@gem_dir}/ext/ruby2d/gl3.c #{@gem_dir}/ext/ruby2d/gles.c #{@gem_dir}/ext/ruby2d/font.c #{@gem_dir}/ext/ruby2d/image.c #{@gem_dir}/ext/ruby2d/input.c #{@gem_dir}/ext/ruby2d/music.c #{@gem_dir}/ext/ruby2d/shapes.c #{@gem_dir}/ext/ruby2d/sound.c #{@gem_dir}/ext/ruby2d/text.c #{@gem_dir}/ext/ruby2d/window.c -I#{@gem_dir}/ext/ruby2d -I#{@gem_dir}/assets/include -LC:/Dev/mruby-3.0.0/build/host/lib -IC:/MSYS2/mingw64/include/ruby-3.0.0 -IC:/MSYS2/mingw64/include/ruby-3.0.0/x64-mingw32 -IC:/Dev/mruby-3.0.0/include -lmruby -lws2_32 -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lopengl32 -lglew32 -o build/app`
|
|
115
|
+
|
|
116
|
+
# Clean up
|
|
117
|
+
clean_up unless @debug
|
|
118
|
+
|
|
119
|
+
# Success!
|
|
120
|
+
puts "Native app created at `build/app`"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
# Build a web-based version of the provided Ruby application
|
|
125
|
+
def build_web(rb_file)
|
|
126
|
+
puts "Warning: ".warn + "This feature is currently disabled while it's being upgraded."
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# Build an app bundle for macOS
|
|
131
|
+
def build_macos(rb_file)
|
|
132
|
+
|
|
133
|
+
# Build native app for macOS
|
|
134
|
+
build_native(rb_file)
|
|
135
|
+
|
|
136
|
+
# Property list source for the bundle
|
|
137
|
+
info_plist = %(
|
|
138
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
139
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
140
|
+
<plist version="1.0">
|
|
141
|
+
<dict>
|
|
142
|
+
<key>CFBundleExecutable</key>
|
|
143
|
+
<string>app</string>
|
|
144
|
+
<key>CFBundleIconFile</key>
|
|
145
|
+
<string>app.icns</string>
|
|
146
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
147
|
+
<string>6.0</string>
|
|
148
|
+
<key>CFBundlePackageType</key>
|
|
149
|
+
<string>APPL</string>
|
|
150
|
+
<key>CFBundleVersion</key>
|
|
151
|
+
<string>1</string>
|
|
152
|
+
<key>NSHighResolutionCapable</key>
|
|
153
|
+
<string>True</string>
|
|
154
|
+
</dict>
|
|
155
|
+
</plist>
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
# Create directories
|
|
159
|
+
FileUtils.mkpath 'build/App.app/Contents/MacOS'
|
|
160
|
+
FileUtils.mkpath 'build/App.app/Contents/Resources'
|
|
161
|
+
|
|
162
|
+
# Create Info.plist and copy over assets
|
|
163
|
+
File.open('build/App.app/Contents/Info.plist', 'w') { |f| f.write(info_plist) }
|
|
164
|
+
FileUtils.cp 'build/app', 'build/App.app/Contents/MacOS/'
|
|
165
|
+
# Consider using an icon:
|
|
166
|
+
# FileUtils.cp "#{@gem_dir}/assets/app.icns", 'build/App.app/Contents/Resources'
|
|
167
|
+
|
|
168
|
+
# Clean up
|
|
169
|
+
FileUtils.rm_f 'build/app' unless @debug
|
|
170
|
+
|
|
171
|
+
# Success!
|
|
172
|
+
puts 'macOS app bundle created: `build/App.app`'
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
# Build an iOS or tvOS app
|
|
177
|
+
def build_ios_tvos(rb_file, device)
|
|
178
|
+
check_build_src_file(rb_file)
|
|
179
|
+
|
|
180
|
+
# Check if MRuby exists; if not, quit
|
|
181
|
+
if `which mruby`.empty?
|
|
182
|
+
puts "#{'Error:'.error} Can't find MRuby, which is needed to build native Ruby 2D applications.\n"
|
|
183
|
+
exit
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Add debugging information to produce backtrace
|
|
187
|
+
if @debug then debug_flag = '-g' end
|
|
188
|
+
|
|
189
|
+
# Assemble the Ruby 2D library in one `.rb` file and compile to bytecode
|
|
190
|
+
make_lib
|
|
191
|
+
`mrbc #{debug_flag} -Bruby2d_lib -obuild/lib.c build/lib.rb`
|
|
192
|
+
|
|
193
|
+
# Read the provided Ruby source file, copy to build dir and compile to bytecode
|
|
194
|
+
File.open('build/src.rb', 'w') { |file| file << strip_require(rb_file) }
|
|
195
|
+
`mrbc #{debug_flag} -Bruby2d_app -obuild/src.c build/src.rb`
|
|
196
|
+
|
|
197
|
+
# Copy over iOS project
|
|
198
|
+
FileUtils.cp_r "#{@gem_dir}/assets/#{device}", "build"
|
|
199
|
+
|
|
200
|
+
# Combine contents of C source files and bytecode into one file
|
|
201
|
+
File.open("build/#{device}/main.c", 'w') do |f|
|
|
202
|
+
f << "#define RUBY2D_IOS_TVOS 1" << "\n\n"
|
|
203
|
+
f << "#define MRUBY 1" << "\n\n"
|
|
204
|
+
f << File.read("build/lib.c") << "\n\n"
|
|
205
|
+
f << File.read("build/src.c") << "\n\n"
|
|
206
|
+
f << File.read("#{@gem_dir}/ext/ruby2d/ruby2d.c")
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# TODO: Need add this functionality to the gem
|
|
210
|
+
# Build the Xcode project
|
|
211
|
+
`simple2d build --#{device} build/#{device}/MyApp.xcodeproj`
|
|
212
|
+
|
|
213
|
+
# Clean up
|
|
214
|
+
clean_up unless @debug
|
|
215
|
+
|
|
216
|
+
# Success!
|
|
217
|
+
puts "App created: `build/#{device}`"
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
# Clean up unneeded build files
|
|
222
|
+
def clean_up(cmd = nil)
|
|
223
|
+
FileUtils.rm(
|
|
224
|
+
Dir.glob('build/{src,lib}.{rb,c,js}') +
|
|
225
|
+
Dir.glob('build/app.c') +
|
|
226
|
+
Dir.glob('build/*{o,rc}')
|
|
227
|
+
)
|
|
228
|
+
if cmd == :all
|
|
229
|
+
puts "cleaning up..."
|
|
230
|
+
FileUtils.rm_f 'build/app'
|
|
231
|
+
FileUtils.rm_f 'build/app.js'
|
|
232
|
+
FileUtils.rm_f 'build/app.html'
|
|
233
|
+
FileUtils.rm_rf 'build/App.app'
|
|
234
|
+
FileUtils.rm_rf 'build/ios'
|
|
235
|
+
FileUtils.rm_rf 'build/tvos'
|
|
236
|
+
end
|
|
237
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# String#ruby2d_colorize
|
|
2
|
+
|
|
3
|
+
# Extend `String` to include some fancy colors
|
|
4
|
+
class String
|
|
5
|
+
def ruby2d_colorize(c); "\e[#{c}m#{self}\e[0m" end
|
|
6
|
+
def bold; ruby2d_colorize('1') end
|
|
7
|
+
def info; ruby2d_colorize('1;34') end
|
|
8
|
+
def warn; ruby2d_colorize('1;33') end
|
|
9
|
+
def error; ruby2d_colorize('1;31') end
|
|
10
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Interactive Ruby 2D console
|
|
2
|
+
|
|
3
|
+
# Save the Ruby file from the command-line arguments
|
|
4
|
+
rb_file = ARGV[1]
|
|
5
|
+
|
|
6
|
+
# Check if source file provided is good
|
|
7
|
+
if !rb_file
|
|
8
|
+
puts "Provide a Ruby file to run"
|
|
9
|
+
exit 1
|
|
10
|
+
elsif !File.exist? rb_file
|
|
11
|
+
puts "Can't find file: #{rb_file}"
|
|
12
|
+
exit 1
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Add libraries
|
|
16
|
+
require 'open3'
|
|
17
|
+
require 'readline'
|
|
18
|
+
require 'io/wait'
|
|
19
|
+
|
|
20
|
+
line = 1 # the current line number
|
|
21
|
+
|
|
22
|
+
# Open a new process for the Ruby file
|
|
23
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("ruby -r 'ruby2d/cli/enable_console' #{rb_file}")
|
|
24
|
+
|
|
25
|
+
# Request input and send commands
|
|
26
|
+
loop do
|
|
27
|
+
|
|
28
|
+
# Read the next command
|
|
29
|
+
cmd = Readline.readline("ruby2d:#{line}> ", true)
|
|
30
|
+
|
|
31
|
+
# Quit if command is 'exit'
|
|
32
|
+
if cmd == 'exit'
|
|
33
|
+
Process.kill 'INT', wait_thr.pid
|
|
34
|
+
wait_thr.value
|
|
35
|
+
exit
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Try sending commands
|
|
39
|
+
begin
|
|
40
|
+
|
|
41
|
+
# Skip if command is an empty string
|
|
42
|
+
unless cmd.empty?
|
|
43
|
+
|
|
44
|
+
# Send command to the Ruby file
|
|
45
|
+
stdin.puts cmd
|
|
46
|
+
|
|
47
|
+
# Read and print output from the Ruby file
|
|
48
|
+
puts stdout.gets
|
|
49
|
+
while stdout.ready? do
|
|
50
|
+
puts stdout.gets
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Increment the line number
|
|
56
|
+
line += 1
|
|
57
|
+
|
|
58
|
+
# Rescue exception if can't send commands to the Ruby 2D window
|
|
59
|
+
rescue Errno::EPIPE
|
|
60
|
+
puts "Can't connect to the window (was it closed?)",
|
|
61
|
+
"For help, see: ruby2d.com/learn/console"
|
|
62
|
+
exit 1
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Launch a built Ruby 2D app
|
|
2
|
+
|
|
3
|
+
# Launch a native app
|
|
4
|
+
def launch_native
|
|
5
|
+
if !File.exist? 'build/app'
|
|
6
|
+
puts "No native app built!"
|
|
7
|
+
exit
|
|
8
|
+
end
|
|
9
|
+
`( cd build && ./app )`
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Launch a web app
|
|
14
|
+
def launch_web
|
|
15
|
+
if !File.exist? 'build/app.html'
|
|
16
|
+
puts "No web app built!"
|
|
17
|
+
exit
|
|
18
|
+
end
|
|
19
|
+
open_cmd = 'open'
|
|
20
|
+
case RUBY_PLATFORM
|
|
21
|
+
when /linux/
|
|
22
|
+
open_cmd = "xdg-#{open_cmd}"
|
|
23
|
+
when /mingw/
|
|
24
|
+
open_cmd = "start"
|
|
25
|
+
end
|
|
26
|
+
system "#{open_cmd} build/app.html"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# Launch an iOS or tvOS app in a simulator
|
|
31
|
+
def launch_apple(device)
|
|
32
|
+
case device
|
|
33
|
+
when 'ios'
|
|
34
|
+
if !File.exist? 'build/ios/build/Release-iphonesimulator/MyApp.app'
|
|
35
|
+
puts "No iOS app built!"
|
|
36
|
+
exit
|
|
37
|
+
end
|
|
38
|
+
puts `simple2d simulator --open "iPhone X" &&
|
|
39
|
+
simple2d simulator --install "build/ios/build/Release-iphonesimulator/MyApp.app" &&
|
|
40
|
+
simple2d simulator --launch "Ruby2D.MyApp"`
|
|
41
|
+
when 'tvos'
|
|
42
|
+
if !File.exist? 'build/tvos/build/Release-appletvsimulator/MyApp.app'
|
|
43
|
+
puts "No tvOS app built!"
|
|
44
|
+
exit
|
|
45
|
+
end
|
|
46
|
+
puts `simple2d simulator --open "Apple TV 4K" &&
|
|
47
|
+
simple2d simulator --install "build/tvos/build/Release-appletvsimulator/MyApp.app" &&
|
|
48
|
+
simple2d simulator --launch "Ruby2D.MyApp"`
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/ruby2d/color.rb
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Ruby2D::Color
|
|
2
|
+
|
|
3
|
+
module Ruby2D
|
|
4
|
+
class Color
|
|
5
|
+
|
|
6
|
+
# Color::Set represents an array of colors
|
|
7
|
+
class Set
|
|
8
|
+
def initialize(colors)
|
|
9
|
+
@colors = colors.map { |c| Color.new(c) }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def [](i)
|
|
13
|
+
@colors[i]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def length
|
|
17
|
+
@colors.length
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def opacity; @colors[0].opacity end
|
|
21
|
+
|
|
22
|
+
def opacity=(opacity)
|
|
23
|
+
@colors.each do |color|
|
|
24
|
+
color.opacity = opacity
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
attr_accessor :r, :g, :b, :a
|
|
30
|
+
|
|
31
|
+
# Based on clrs.cc
|
|
32
|
+
@@colors = {
|
|
33
|
+
'navy' => '#001F3F',
|
|
34
|
+
'blue' => '#0074D9',
|
|
35
|
+
'aqua' => '#7FDBFF',
|
|
36
|
+
'teal' => '#39CCCC',
|
|
37
|
+
'olive' => '#3D9970',
|
|
38
|
+
'green' => '#2ECC40',
|
|
39
|
+
'lime' => '#01FF70',
|
|
40
|
+
'yellow' => '#FFDC00',
|
|
41
|
+
'orange' => '#FF851B',
|
|
42
|
+
'red' => '#FF4136',
|
|
43
|
+
'brown' => '#663300',
|
|
44
|
+
'fuchsia' => '#F012BE',
|
|
45
|
+
'purple' => '#B10DC9',
|
|
46
|
+
'maroon' => '#85144B',
|
|
47
|
+
'white' => '#FFFFFF',
|
|
48
|
+
'silver' => '#DDDDDD',
|
|
49
|
+
'gray' => '#AAAAAA',
|
|
50
|
+
'black' => '#111111',
|
|
51
|
+
'random' => ''
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
def initialize(c)
|
|
55
|
+
if !self.class.is_valid? c
|
|
56
|
+
raise Error, "`#{c}` is not a valid color"
|
|
57
|
+
else
|
|
58
|
+
case c
|
|
59
|
+
when String
|
|
60
|
+
if c == 'random'
|
|
61
|
+
@r, @g, @b, @a = rand, rand, rand, 1.0
|
|
62
|
+
elsif self.class.is_hex?(c)
|
|
63
|
+
@r, @g, @b, @a = hex_to_f(c)
|
|
64
|
+
else
|
|
65
|
+
@r, @g, @b, @a = hex_to_f(@@colors[c])
|
|
66
|
+
end
|
|
67
|
+
when Array
|
|
68
|
+
@r, @g, @b, @a = [c[0], c[1], c[2], c[3]]
|
|
69
|
+
when Color
|
|
70
|
+
@r, @g, @b, @a = [c.r, c.g, c.b, c.a]
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Return a color set if an array of valid colors
|
|
76
|
+
def self.set(colors)
|
|
77
|
+
# If a valid array of colors, return a `Color::Set` with those colors
|
|
78
|
+
if colors.is_a?(Array) && colors.all? { |el| Color.is_valid? el }
|
|
79
|
+
Color::Set.new(colors)
|
|
80
|
+
# Otherwise, return single color
|
|
81
|
+
else
|
|
82
|
+
Color.new(colors)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Check if string is a proper hex value
|
|
87
|
+
def self.is_hex?(s)
|
|
88
|
+
# MRuby doesn't support regex, otherwise we'd do:
|
|
89
|
+
# !(/^#[0-9A-F]{6}$/i.match(a).nil?)
|
|
90
|
+
s.class == String && s[0] == '#' && s.length == 7
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Check if the color is valid
|
|
94
|
+
def self.is_valid?(c)
|
|
95
|
+
c.is_a?(Color) || # color object
|
|
96
|
+
@@colors.key?(c) || # keyword
|
|
97
|
+
self.is_hex?(c) || # hexadecimal value
|
|
98
|
+
|
|
99
|
+
# Array of Floats from 0.0..1.0
|
|
100
|
+
c.class == Array && c.length == 4 &&
|
|
101
|
+
c.all? { |el| el.is_a?(Numeric) }
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Convenience methods to alias `opacity` to `@a`
|
|
105
|
+
def opacity; @a end
|
|
106
|
+
def opacity=(opacity); @a = opacity end
|
|
107
|
+
|
|
108
|
+
private
|
|
109
|
+
|
|
110
|
+
# Convert from Fixnum (0..255) to Float (0.0..1.0)
|
|
111
|
+
def to_f(a)
|
|
112
|
+
b = []
|
|
113
|
+
a.each do |n|
|
|
114
|
+
b.push(n / 255.0)
|
|
115
|
+
end
|
|
116
|
+
return b
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Convert from hex value (e.g. #FFF000) to Float (0.0..1.0)
|
|
120
|
+
def hex_to_f(h)
|
|
121
|
+
h = (h[1..-1]).chars.each_slice(2).map(&:join)
|
|
122
|
+
a = []
|
|
123
|
+
|
|
124
|
+
h.each do |el|
|
|
125
|
+
a.push(el.to_i(16))
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
a.push(255)
|
|
129
|
+
return to_f(a)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Allow British English spelling of color
|
|
135
|
+
Colour = Color
|
|
136
|
+
end
|
data/lib/ruby2d/dsl.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Ruby2D::DSL
|
|
2
|
+
|
|
3
|
+
module Ruby2D::DSL
|
|
4
|
+
|
|
5
|
+
@window = Ruby2D::Window.new
|
|
6
|
+
|
|
7
|
+
def self.window; @window end
|
|
8
|
+
def self.window=(w); @window = w end
|
|
9
|
+
|
|
10
|
+
def get(sym, opts = nil)
|
|
11
|
+
DSL.window.get(sym, opts)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def set(opts)
|
|
15
|
+
DSL.window.set(opts)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def on(event, &proc)
|
|
19
|
+
DSL.window.on(event, &proc)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def off(event_descriptor)
|
|
23
|
+
DSL.window.off(event_descriptor)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def update(&proc)
|
|
27
|
+
DSL.window.update(&proc)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def render(&proc)
|
|
31
|
+
DSL.window.render(&proc)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def clear
|
|
35
|
+
DSL.window.clear
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def show
|
|
39
|
+
DSL.window.show
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def close
|
|
43
|
+
DSL.window.close
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|