ruby2d 0.12.1 → 1.0.0
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 +4 -4
- data/LICENSE.md +7 -0
- data/README.md +141 -0
- data/USAGE.md +2435 -0
- data/assets/Rakefile +637 -0
- data/assets/build_support/CMakeLists.txt +94 -0
- data/assets/build_support/mruby/build_config.rb +34 -0
- data/assets/build_support/mruby/build_config_wasm.rb +30 -0
- data/assets/build_support/sdl_test.c +174 -0
- data/assets/deps.yaml +16 -0
- data/assets/platform/include/SDL3/SDL.h +91 -0
- data/assets/platform/include/SDL3/SDL_assert.h +705 -0
- data/assets/platform/include/SDL3/SDL_asyncio.h +550 -0
- data/assets/platform/include/SDL3/SDL_atomic.h +692 -0
- data/assets/platform/include/SDL3/SDL_audio.h +2370 -0
- data/assets/platform/include/SDL3/SDL_begin_code.h +553 -0
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_bits.h +47 -27
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_blendmode.h +59 -55
- data/assets/platform/include/SDL3/SDL_camera.h +535 -0
- data/assets/platform/include/SDL3/SDL_clipboard.h +331 -0
- data/assets/{include/SDL2/close_code.h → platform/include/SDL3/SDL_close_code.h} +9 -8
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_copying.h +3 -1
- data/assets/platform/include/SDL3/SDL_cpuinfo.h +374 -0
- data/assets/platform/include/SDL3/SDL_dialog.h +343 -0
- data/assets/platform/include/SDL3/SDL_dlopennote.h +234 -0
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_egl.h +11 -8
- data/assets/platform/include/SDL3/SDL_endian.h +645 -0
- data/assets/platform/include/SDL3/SDL_error.h +226 -0
- data/assets/platform/include/SDL3/SDL_events.h +1645 -0
- data/assets/platform/include/SDL3/SDL_filesystem.h +537 -0
- data/assets/platform/include/SDL3/SDL_gamepad.h +1656 -0
- data/assets/platform/include/SDL3/SDL_gpu.h +4608 -0
- data/assets/platform/include/SDL3/SDL_guid.h +106 -0
- data/assets/platform/include/SDL3/SDL_haptic.h +1461 -0
- data/assets/platform/include/SDL3/SDL_hidapi.h +571 -0
- data/assets/platform/include/SDL3/SDL_hints.h +5001 -0
- data/assets/platform/include/SDL3/SDL_init.h +507 -0
- data/assets/platform/include/SDL3/SDL_intrin.h +410 -0
- data/assets/platform/include/SDL3/SDL_iostream.h +1379 -0
- data/assets/platform/include/SDL3/SDL_joystick.h +1385 -0
- data/assets/platform/include/SDL3/SDL_keyboard.h +608 -0
- data/assets/platform/include/SDL3/SDL_keycode.h +347 -0
- data/assets/platform/include/SDL3/SDL_loadso.h +145 -0
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_locale.h +40 -24
- data/assets/platform/include/SDL3/SDL_log.h +541 -0
- data/assets/platform/include/SDL3/SDL_main.h +704 -0
- data/assets/platform/include/SDL3/SDL_main_impl.h +151 -0
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_messagebox.h +85 -48
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_metal.h +29 -29
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_misc.h +13 -12
- data/assets/platform/include/SDL3/SDL_mouse.h +813 -0
- data/assets/platform/include/SDL3/SDL_mutex.h +1117 -0
- data/assets/platform/include/SDL3/SDL_oldnames.h +1339 -0
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_opengl.h +1247 -278
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_opengl_glext.h +5 -1
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_opengles.h +6 -7
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_opengles2.h +10 -11
- data/assets/platform/include/SDL3/SDL_pen.h +198 -0
- data/assets/platform/include/SDL3/SDL_pixels.h +1441 -0
- data/assets/{include/SDL2/SDL_test_log.h → platform/include/SDL3/SDL_platform.h} +25 -26
- data/assets/platform/include/SDL3/SDL_platform_defines.h +497 -0
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_power.h +40 -20
- data/assets/platform/include/SDL3/SDL_process.h +441 -0
- data/assets/platform/include/SDL3/SDL_properties.h +572 -0
- data/assets/platform/include/SDL3/SDL_rect.h +528 -0
- data/assets/platform/include/SDL3/SDL_render.h +3028 -0
- data/assets/platform/include/SDL3/SDL_revision.h +59 -0
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_scancode.h +59 -68
- data/assets/platform/include/SDL3/SDL_sensor.h +321 -0
- data/assets/platform/include/SDL3/SDL_stdinc.h +6186 -0
- data/assets/platform/include/SDL3/SDL_storage.h +686 -0
- data/assets/platform/include/SDL3/SDL_surface.h +1769 -0
- data/assets/platform/include/SDL3/SDL_system.h +840 -0
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_test.h +16 -22
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_test_assert.h +27 -34
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_test_common.h +109 -52
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_test_compare.h +22 -14
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_test_crc32.h +27 -30
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_test_font.h +50 -49
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_test_fuzzer.h +64 -79
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_test_harness.h +47 -30
- data/assets/platform/include/SDL3/SDL_test_log.h +83 -0
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_test_md5.h +21 -28
- data/assets/{include/SDL2 → platform/include/SDL3}/SDL_test_memory.h +19 -16
- data/assets/platform/include/SDL3/SDL_thread.h +602 -0
- data/assets/platform/include/SDL3/SDL_time.h +249 -0
- data/assets/platform/include/SDL3/SDL_timer.h +454 -0
- data/assets/platform/include/SDL3/SDL_touch.h +184 -0
- data/assets/platform/include/SDL3/SDL_tray.h +544 -0
- data/assets/platform/include/SDL3/SDL_version.h +198 -0
- data/assets/platform/include/SDL3/SDL_video.h +3497 -0
- data/assets/platform/include/SDL3/SDL_vulkan.h +287 -0
- data/assets/platform/include/SDL3_image/SDL_image.h +3328 -0
- data/assets/platform/include/SDL3_mixer/SDL_mixer.h +3369 -0
- data/assets/platform/include/SDL3_ttf/SDL_textengine.h +181 -0
- data/assets/platform/include/SDL3_ttf/SDL_ttf.h +2833 -0
- data/assets/{include → platform/include}/mrbconf.h +42 -31
- data/assets/{include → platform/include}/mruby/array.h +3 -4
- data/assets/{include → platform/include}/mruby/boxing_nan.h +10 -0
- data/assets/platform/include/mruby/boxing_no.h +59 -0
- data/assets/{include → platform/include}/mruby/boxing_word.h +72 -26
- data/assets/platform/include/mruby/class.h +157 -0
- data/assets/{include → platform/include}/mruby/common.h +30 -1
- data/assets/{include → platform/include}/mruby/compile.h +52 -74
- data/assets/{include → platform/include}/mruby/data.h +2 -2
- data/assets/{include → platform/include}/mruby/debug.h +12 -5
- data/assets/{include → platform/include}/mruby/dump.h +7 -9
- data/assets/{include → platform/include}/mruby/endian.h +1 -1
- data/assets/platform/include/mruby/error.h +173 -0
- data/assets/platform/include/mruby/gc.h +79 -0
- data/assets/{include → platform/include}/mruby/hash.h +1 -7
- data/assets/platform/include/mruby/internal.h +282 -0
- data/assets/platform/include/mruby/irep.h +143 -0
- data/assets/{include → platform/include}/mruby/istruct.h +1 -1
- data/assets/platform/include/mruby/khash.h +455 -0
- data/assets/platform/include/mruby/mempool.h +19 -0
- data/assets/{include → platform/include}/mruby/numeric.h +7 -10
- data/assets/platform/include/mruby/object.h +51 -0
- data/assets/{include → platform/include}/mruby/opcode.h +5 -5
- data/assets/{include → platform/include}/mruby/ops.h +19 -6
- data/assets/platform/include/mruby/presym/id.h +1447 -0
- data/assets/{include → platform/include}/mruby/presym/scanning.h +10 -7
- data/assets/platform/include/mruby/presym/table.h +2893 -0
- data/assets/platform/include/mruby/presym.h +65 -0
- data/assets/platform/include/mruby/proc.h +184 -0
- data/assets/{include → platform/include}/mruby/range.h +0 -2
- data/assets/{include → platform/include}/mruby/string.h +33 -53
- data/assets/platform/include/mruby/throw.h +81 -0
- data/assets/{include → platform/include}/mruby/value.h +64 -29
- data/assets/{include → platform/include}/mruby/variable.h +6 -23
- data/assets/{include → platform/include}/mruby/version.h +7 -7
- data/assets/{include → platform/include}/mruby.h +238 -116
- data/assets/platform/macos-arm64/bin/mrbc +0 -0
- data/assets/platform/macos-arm64/lib/libSDL3.a +0 -0
- data/assets/platform/macos-arm64/lib/libSDL3_image.a +0 -0
- data/assets/platform/macos-arm64/lib/libSDL3_mixer.a +0 -0
- data/assets/platform/macos-arm64/lib/libSDL3_ttf.a +0 -0
- data/assets/platform/macos-arm64/lib/libmruby.a +0 -0
- data/assets/platform/wasm/lib/libFLAC.a +0 -0
- data/assets/platform/wasm/lib/libSDL3.a +0 -0
- data/assets/platform/wasm/lib/libSDL3_image.a +0 -0
- data/assets/platform/wasm/lib/libSDL3_mixer.a +0 -0
- data/assets/platform/wasm/lib/libSDL3_ttf.a +0 -0
- data/assets/platform/wasm/lib/libfreetype.a +0 -0
- data/assets/platform/wasm/lib/libharfbuzz.a +0 -0
- data/assets/platform/wasm/lib/libmruby.a +0 -0
- data/assets/platform/wasm/lib/libogg.a +0 -0
- data/assets/platform/wasm/lib/libplutosvg.a +0 -0
- data/assets/platform/wasm/lib/libplutovg.a +0 -0
- data/assets/platform/wasm/lib/libpng.a +0 -0
- data/assets/platform/wasm/lib/libpng16.a +0 -0
- data/assets/platform/wasm/lib/libvorbis.a +0 -0
- data/assets/platform/wasm/lib/libvorbisfile.a +0 -0
- data/assets/platform/wasm/lib/libzlibstatic.a +0 -0
- data/assets/platform/windows-arm64-mingw-ucrt/bin/mrbc.exe +0 -0
- data/assets/platform/windows-arm64-mingw-ucrt/lib/libSDL3.a +0 -0
- data/assets/platform/windows-arm64-mingw-ucrt/lib/libSDL3_image.a +0 -0
- data/assets/platform/windows-arm64-mingw-ucrt/lib/libSDL3_mixer.a +0 -0
- data/assets/platform/windows-arm64-mingw-ucrt/lib/libSDL3_ttf.a +0 -0
- data/assets/platform/windows-arm64-mingw-ucrt/lib/libmruby.a +0 -0
- data/assets/platform/windows-x86_64-mingw-ucrt/bin/mrbc.exe +0 -0
- data/assets/platform/windows-x86_64-mingw-ucrt/lib/libSDL3.a +0 -0
- data/assets/platform/windows-x86_64-mingw-ucrt/lib/libSDL3_image.a +0 -0
- data/assets/platform/windows-x86_64-mingw-ucrt/lib/libSDL3_mixer.a +0 -0
- data/assets/platform/windows-x86_64-mingw-ucrt/lib/libSDL3_ttf.a +0 -0
- data/assets/platform/windows-x86_64-mingw-ucrt/lib/libmruby.a +0 -0
- data/assets/resources/fonts/outfit/OFL.txt +93 -0
- data/assets/resources/fonts/outfit/outfit.ttf +0 -0
- data/assets/resources/fonts/roboto_mono/OFL.txt +91 -0
- data/assets/resources/fonts/roboto_mono/roboto_mono.ttf +0 -0
- data/assets/resources/icons/icon.icns +0 -0
- data/assets/resources/icons/icon.png +0 -0
- data/assets/resources/spritesheets/License.txt +28 -0
- data/assets/resources/spritesheets/spritesheet-backgrounds.png +0 -0
- data/assets/resources/spritesheets/spritesheet-backgrounds.xml +16 -0
- data/assets/resources/spritesheets/spritesheet-characters.png +0 -0
- data/assets/resources/spritesheets/spritesheet-characters.xml +47 -0
- data/assets/resources/spritesheets/spritesheet-enemies.png +0 -0
- data/assets/resources/spritesheets/spritesheet-enemies.xml +62 -0
- data/assets/resources/spritesheets/spritesheet-tiles.png +0 -0
- data/assets/resources/spritesheets/spritesheet-tiles.xml +316 -0
- data/assets/{wasm → resources/web}/template.html +1 -1
- data/assets/target.rb +131 -0
- data/bin/ruby2d +281 -82
- data/examples/astar.rb +269 -0
- data/examples/asteroids.rb +403 -0
- data/examples/bezier_editor.rb +96 -0
- data/examples/boids.rb +191 -0
- data/examples/bouncing_balls.rb +119 -0
- data/examples/breakout.rb +186 -0
- data/examples/constellations.rb +100 -0
- data/examples/dashboard.rb +133 -0
- data/examples/double_pendulum.rb +254 -0
- data/examples/falling_sand.rb +291 -0
- data/examples/fireworks.rb +110 -0
- data/examples/fluid_dynamics.rb +340 -0
- data/examples/fourier_epicycles.rb +142 -0
- data/examples/fractal_tree.rb +326 -0
- data/examples/game_of_life.rb +148 -0
- data/examples/gamepads.rb +333 -0
- data/examples/hill_driver.rb +613 -0
- data/examples/logo_animation.rb +251 -0
- data/examples/lorenz_attractor.rb +115 -0
- data/examples/mandelbrot.rb +207 -0
- data/examples/marching_squares.rb +200 -0
- data/examples/maze.rb +323 -0
- data/examples/nbody.rb +338 -0
- data/examples/outrun.rb +391 -0
- data/examples/pixel_paint.rb +313 -0
- data/examples/platformer.rb +335 -0
- data/examples/ray_casting_maze.rb +175 -0
- data/examples/shadow_casting.rb +151 -0
- data/examples/shape_recognizer.rb +908 -0
- data/examples/snake.rb +144 -0
- data/examples/sprite_sheets.rb +246 -0
- data/examples/swarm.rb +206 -0
- data/examples/tsp_annealing.rb +104 -0
- data/examples/ui_controls.rb +163 -0
- data/examples/wireframe_3d.rb +139 -0
- data/ext/ruby2d/audio.c +324 -0
- data/ext/ruby2d/canvas.c +1715 -494
- data/ext/ruby2d/ext.c +541 -0
- data/ext/ruby2d/extconf.rb +122 -145
- data/ext/ruby2d/font.c +566 -20
- data/ext/ruby2d/fps.c +92 -0
- data/ext/ruby2d/image.c +466 -41
- data/ext/ruby2d/ruby2d.c +374 -1890
- data/ext/ruby2d/ruby2d.h +840 -460
- data/ext/ruby2d/shapes.c +931 -101
- data/ext/ruby2d/text.c +586 -21
- data/ext/ruby2d/window.c +1693 -283
- data/lib/ruby2d/atlas_parser.rb +194 -0
- data/lib/ruby2d/audio.rb +73 -0
- data/lib/ruby2d/benchmark.rb +259 -0
- data/lib/ruby2d/bitmap_text.rb +155 -0
- data/lib/ruby2d/button.rb +402 -0
- data/lib/ruby2d/canvas.rb +703 -279
- data/lib/ruby2d/circle.rb +206 -29
- data/lib/ruby2d/cli/browser.rb +314 -0
- data/lib/ruby2d/cli/build.rb +471 -257
- data/lib/ruby2d/cli/colorize.rb +7 -5
- data/lib/ruby2d/cli/examples.rb +127 -0
- data/lib/ruby2d/cli/launch.rb +24 -39
- data/lib/ruby2d/cli/lib_files.rb +48 -0
- data/lib/ruby2d/cli/messages.rb +40 -0
- data/lib/ruby2d/cli/setup.rb +273 -0
- data/lib/ruby2d/cli/static_server.rb +160 -0
- data/lib/ruby2d/cli/usage.rb +255 -0
- data/lib/ruby2d/color.rb +191 -69
- data/lib/ruby2d/core.rb +37 -19
- data/lib/ruby2d/deps_help.rb +89 -0
- data/lib/ruby2d/dsl.rb +51 -12
- data/lib/ruby2d/ellipse.rb +228 -0
- data/lib/ruby2d/exceptions.rb +0 -2
- data/lib/ruby2d/font.rb +34 -74
- data/lib/ruby2d/gamepad.rb +323 -0
- data/lib/ruby2d/gem_paths.rb +19 -0
- data/lib/ruby2d/image.rb +155 -52
- data/lib/ruby2d/interactive.rb +103 -0
- data/lib/ruby2d/json_parser.rb +268 -0
- data/lib/ruby2d/line.rb +194 -85
- data/lib/ruby2d/mruby_compat.rb +12 -0
- data/lib/ruby2d/polygon.rb +297 -0
- data/lib/ruby2d/polyline.rb +368 -0
- data/lib/ruby2d/quad.rb +358 -94
- data/lib/ruby2d/rectangle.rb +77 -19
- data/lib/ruby2d/renderable.rb +411 -11
- data/lib/ruby2d/sprite.rb +471 -180
- data/lib/ruby2d/sprite_sheet.rb +64 -0
- data/lib/ruby2d/square.rb +29 -17
- data/lib/ruby2d/text.rb +196 -65
- data/lib/ruby2d/tileset.rb +139 -81
- data/lib/ruby2d/triangle.rb +324 -89
- data/lib/ruby2d/version.rb +1 -3
- data/lib/ruby2d/vertices.rb +62 -85
- data/lib/ruby2d/warnings.rb +29 -0
- data/lib/ruby2d/window/class_methods.rb +218 -0
- data/lib/ruby2d/window/gamepad_events.rb +141 -0
- data/lib/ruby2d/window/key_events.rb +74 -0
- data/lib/ruby2d/window/mouse_events.rb +171 -0
- data/lib/ruby2d/window/object_events.rb +168 -0
- data/lib/ruby2d/window.rb +632 -585
- data/lib/ruby2d.rb +14 -19
- metadata +275 -443
- data/assets/app.icns +0 -0
- data/assets/include/GL/glew.h +0 -26427
- data/assets/include/GLES2/gl2.h +0 -656
- data/assets/include/GLES2/gl2ext.h +0 -3949
- data/assets/include/GLES2/gl2ext_angle.h +0 -701
- data/assets/include/GLES2/gl2platform.h +0 -27
- data/assets/include/GLES3/gl3.h +0 -1192
- data/assets/include/GLES3/gl31.h +0 -1507
- data/assets/include/GLES3/gl32.h +0 -1808
- data/assets/include/GLES3/gl3platform.h +0 -27
- data/assets/include/KHR/khrplatform.h +0 -290
- data/assets/include/SDL2/SDL.h +0 -233
- data/assets/include/SDL2/SDL_assert.h +0 -326
- data/assets/include/SDL2/SDL_atomic.h +0 -415
- data/assets/include/SDL2/SDL_audio.h +0 -1500
- data/assets/include/SDL2/SDL_clipboard.h +0 -141
- data/assets/include/SDL2/SDL_config.h +0 -61
- data/assets/include/SDL2/SDL_config_android.h +0 -194
- data/assets/include/SDL2/SDL_config_emscripten.h +0 -218
- data/assets/include/SDL2/SDL_config_iphoneos.h +0 -217
- data/assets/include/SDL2/SDL_config_macosx.h +0 -277
- data/assets/include/SDL2/SDL_config_minimal.h +0 -95
- data/assets/include/SDL2/SDL_config_ngage.h +0 -89
- data/assets/include/SDL2/SDL_config_os2.h +0 -207
- data/assets/include/SDL2/SDL_config_pandora.h +0 -141
- data/assets/include/SDL2/SDL_config_windows.h +0 -331
- data/assets/include/SDL2/SDL_config_wingdk.h +0 -253
- data/assets/include/SDL2/SDL_config_winrt.h +0 -220
- data/assets/include/SDL2/SDL_config_xbox.h +0 -235
- data/assets/include/SDL2/SDL_cpuinfo.h +0 -594
- data/assets/include/SDL2/SDL_endian.h +0 -348
- data/assets/include/SDL2/SDL_error.h +0 -163
- data/assets/include/SDL2/SDL_events.h +0 -1166
- data/assets/include/SDL2/SDL_filesystem.h +0 -149
- data/assets/include/SDL2/SDL_gamecontroller.h +0 -1074
- data/assets/include/SDL2/SDL_gesture.h +0 -117
- data/assets/include/SDL2/SDL_guid.h +0 -100
- data/assets/include/SDL2/SDL_haptic.h +0 -1341
- data/assets/include/SDL2/SDL_hidapi.h +0 -451
- data/assets/include/SDL2/SDL_hints.h +0 -2569
- data/assets/include/SDL2/SDL_image.h +0 -2173
- data/assets/include/SDL2/SDL_joystick.h +0 -1066
- data/assets/include/SDL2/SDL_keyboard.h +0 -353
- data/assets/include/SDL2/SDL_keycode.h +0 -358
- data/assets/include/SDL2/SDL_loadso.h +0 -115
- data/assets/include/SDL2/SDL_log.h +0 -404
- data/assets/include/SDL2/SDL_main.h +0 -275
- data/assets/include/SDL2/SDL_mixer.h +0 -2784
- data/assets/include/SDL2/SDL_mouse.h +0 -465
- data/assets/include/SDL2/SDL_mutex.h +0 -471
- data/assets/include/SDL2/SDL_name.h +0 -33
- data/assets/include/SDL2/SDL_pixels.h +0 -644
- data/assets/include/SDL2/SDL_platform.h +0 -261
- data/assets/include/SDL2/SDL_quit.h +0 -58
- data/assets/include/SDL2/SDL_rect.h +0 -376
- data/assets/include/SDL2/SDL_render.h +0 -1919
- data/assets/include/SDL2/SDL_revision.h +0 -6
- data/assets/include/SDL2/SDL_rwops.h +0 -841
- data/assets/include/SDL2/SDL_sensor.h +0 -322
- data/assets/include/SDL2/SDL_shape.h +0 -155
- data/assets/include/SDL2/SDL_stdinc.h +0 -830
- data/assets/include/SDL2/SDL_surface.h +0 -997
- data/assets/include/SDL2/SDL_system.h +0 -623
- data/assets/include/SDL2/SDL_syswm.h +0 -386
- data/assets/include/SDL2/SDL_test_images.h +0 -78
- data/assets/include/SDL2/SDL_test_random.h +0 -115
- data/assets/include/SDL2/SDL_thread.h +0 -464
- data/assets/include/SDL2/SDL_timer.h +0 -222
- data/assets/include/SDL2/SDL_touch.h +0 -150
- data/assets/include/SDL2/SDL_ttf.h +0 -2316
- data/assets/include/SDL2/SDL_types.h +0 -29
- data/assets/include/SDL2/SDL_version.h +0 -204
- data/assets/include/SDL2/SDL_video.h +0 -2150
- data/assets/include/SDL2/SDL_vulkan.h +0 -215
- data/assets/include/SDL2/begin_code.h +0 -187
- data/assets/include/mruby/boxing_no.h +0 -58
- data/assets/include/mruby/class.h +0 -108
- data/assets/include/mruby/error.h +0 -147
- data/assets/include/mruby/gc.h +0 -94
- data/assets/include/mruby/irep.h +0 -147
- data/assets/include/mruby/khash.h +0 -284
- data/assets/include/mruby/object.h +0 -43
- data/assets/include/mruby/presym/disable.h +0 -70
- data/assets/include/mruby/presym/enable.h +0 -37
- data/assets/include/mruby/presym.h +0 -40
- data/assets/include/mruby/proc.h +0 -211
- data/assets/include/mruby/throw.h +0 -66
- data/assets/macos/universal/bin/mrbc +0 -0
- data/assets/macos/universal/lib/libFLAC.a +0 -0
- data/assets/macos/universal/lib/libSDL2.a +0 -0
- data/assets/macos/universal/lib/libSDL2_image.a +0 -0
- data/assets/macos/universal/lib/libSDL2_mixer.a +0 -0
- data/assets/macos/universal/lib/libSDL2_ttf.a +0 -0
- data/assets/macos/universal/lib/libavif.a +0 -0
- data/assets/macos/universal/lib/libbrotlicommon-static.a +0 -0
- data/assets/macos/universal/lib/libbrotlidec-static.a +0 -0
- data/assets/macos/universal/lib/libfreetype.a +0 -0
- data/assets/macos/universal/lib/libgraphite2.a +0 -0
- data/assets/macos/universal/lib/libharfbuzz.a +0 -0
- data/assets/macos/universal/lib/libhwy.a +0 -0
- data/assets/macos/universal/lib/libjpeg.a +0 -0
- data/assets/macos/universal/lib/libjxl.a +0 -0
- data/assets/macos/universal/lib/libmodplug.a +0 -0
- data/assets/macos/universal/lib/libmpg123.a +0 -0
- data/assets/macos/universal/lib/libmruby.a +0 -0
- data/assets/macos/universal/lib/libogg.a +0 -0
- data/assets/macos/universal/lib/libpng.a +0 -0
- data/assets/macos/universal/lib/libtiff.a +0 -0
- data/assets/macos/universal/lib/libvorbis.a +0 -0
- data/assets/macos/universal/lib/libvorbisfile.a +0 -0
- data/assets/macos/universal/lib/libwebp.a +0 -0
- data/assets/macos/universal/lib/libzstd.a +0 -0
- data/assets/test_media/README.md +0 -3
- data/assets/test_media/bitstream_vera/COPYRIGHT.txt +0 -124
- data/assets/test_media/bitstream_vera/vera.ttf +0 -0
- data/assets/test_media/boom.png +0 -0
- data/assets/test_media/coin.png +0 -0
- data/assets/test_media/colors.png +0 -0
- data/assets/test_media/controller.png +0 -0
- data/assets/test_media/dial.wav +0 -0
- data/assets/test_media/hero.png +0 -0
- data/assets/test_media/image.bmp +0 -0
- data/assets/test_media/image.jpg +0 -0
- data/assets/test_media/image.png +0 -0
- data/assets/test_media/music.flac +0 -0
- data/assets/test_media/music.mp3 +0 -0
- data/assets/test_media/music.ogg +0 -0
- data/assets/test_media/music.wav +0 -0
- data/assets/test_media/originals/boom.pxm +0 -0
- data/assets/test_media/originals/coin.pxm +0 -0
- data/assets/test_media/originals/controller.sketch +0 -0
- data/assets/test_media/originals/hero.pxm +0 -0
- data/assets/test_media/originals/image.pxm +0 -0
- data/assets/test_media/originals/music.caf +0 -0
- data/assets/test_media/originals/texture_atlas.pxm +0 -0
- data/assets/test_media/rondo_alla_turka.ogg +0 -0
- data/assets/test_media/sound.flac +0 -0
- data/assets/test_media/sound.mp3 +0 -0
- data/assets/test_media/sound.ogg +0 -0
- data/assets/test_media/sound.wav +0 -0
- data/assets/test_media/sprite_sheet.png +0 -0
- data/assets/test_media/texture_atlas.png +0 -0
- data/assets/wasm/libmruby.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/bin/mrbc.exe +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libFLAC.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libLerc.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_image.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_mixer.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_ttf.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libbrotlicommon.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libbrotlidec.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libbz2.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libdeflate.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libfreetype.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libglew32.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libgraphite2.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libharfbuzz.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libhwy.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libjbig.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libjpeg.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libjxl.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/liblzma.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmodplug.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmpg123.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmruby.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libogg.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopus.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopusfile.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libpng.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libsndfile.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libssp.a +0 -1
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libstdc++.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libtiff.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbis.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbisfile.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libwebp.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libz.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libzstd.a +0 -0
- data/assets/windows/mingw-w64-x86_64/bin/mrbc.exe +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libFLAC.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libLerc.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libSDL2.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libSDL2_image.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libSDL2_mixer.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libSDL2_ttf.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libbrotlicommon.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libbrotlidec.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libbz2.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libdeflate.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libfreetype.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libglew32.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libgraphite2.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libharfbuzz.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libhwy.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libjbig.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libjpeg.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libjxl.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/liblzma.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libmodplug.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libmpg123.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libmruby.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libogg.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libopus.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libopusfile.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libpng.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libsndfile.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libssp.a +0 -1
- data/assets/windows/mingw-w64-x86_64/lib/libstdc++.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libtiff.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libvorbis.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libvorbisfile.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libwebp.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libz.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libzstd.a +0 -0
- data/assets/xcode/ios/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -98
- data/assets/xcode/ios/Assets.xcassets/Contents.json +0 -6
- data/assets/xcode/ios/Base.lproj/LaunchScreen.storyboard +0 -27
- data/assets/xcode/ios/Info.plist +0 -43
- data/assets/xcode/ios/MRuby.framework/Headers/mrbconf.h +0 -143
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/array.h +0 -280
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/boxing_nan.h +0 -102
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/boxing_no.h +0 -56
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/boxing_word.h +0 -144
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/class.h +0 -97
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/common.h +0 -77
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/compile.h +0 -195
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/data.h +0 -75
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/debug.h +0 -67
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/dump.h +0 -196
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/error.h +0 -75
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/gc.h +0 -91
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/hash.h +0 -215
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/irep.h +0 -75
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/istruct.h +0 -47
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/khash.h +0 -274
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/numeric.h +0 -161
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/object.h +0 -44
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/opcode.h +0 -69
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/ops.h +0 -117
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/proc.h +0 -131
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/range.h +0 -49
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/re.h +0 -16
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/string.h +0 -444
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/throw.h +0 -55
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/value.h +0 -309
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/variable.h +0 -136
- data/assets/xcode/ios/MRuby.framework/Headers/mruby/version.h +0 -110
- data/assets/xcode/ios/MRuby.framework/Headers/mruby.h +0 -1282
- data/assets/xcode/ios/MRuby.framework/Info.plist +0 -20
- data/assets/xcode/ios/MRuby.framework/MRuby +0 -0
- data/assets/xcode/ios/MyApp.xcodeproj/project.pbxproj +0 -368
- data/assets/xcode/ios/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- data/assets/xcode/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- data/assets/xcode/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +0 -30
- data/assets/xcode/ios/main.c +0 -1
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +0 -16
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json +0 -6
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json +0 -17
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +0 -16
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json +0 -6
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +0 -16
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json +0 -6
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +0 -16
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json +0 -6
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json +0 -17
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +0 -16
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json +0 -6
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +0 -16
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json +0 -6
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json +0 -32
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json +0 -16
- data/assets/xcode/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json +0 -16
- data/assets/xcode/tvos/Assets.xcassets/Contents.json +0 -6
- data/assets/xcode/tvos/Assets.xcassets/LaunchImage.launchimage/Contents.json +0 -22
- data/assets/xcode/tvos/Info.plist +0 -30
- data/assets/xcode/tvos/MRuby.framework/Headers/mrbconf.h +0 -143
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/array.h +0 -280
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/boxing_nan.h +0 -102
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/boxing_no.h +0 -56
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/boxing_word.h +0 -144
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/class.h +0 -97
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/common.h +0 -77
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/compile.h +0 -195
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/data.h +0 -75
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/debug.h +0 -67
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/dump.h +0 -196
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/error.h +0 -75
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/gc.h +0 -91
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/hash.h +0 -215
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/irep.h +0 -75
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/istruct.h +0 -47
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/khash.h +0 -274
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/numeric.h +0 -161
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/object.h +0 -44
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/opcode.h +0 -69
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/ops.h +0 -117
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/proc.h +0 -131
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/range.h +0 -49
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/re.h +0 -16
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/string.h +0 -444
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/throw.h +0 -55
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/value.h +0 -309
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/variable.h +0 -136
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby/version.h +0 -110
- data/assets/xcode/tvos/MRuby.framework/Headers/mruby.h +0 -1282
- data/assets/xcode/tvos/MRuby.framework/Info.plist +0 -20
- data/assets/xcode/tvos/MRuby.framework/MRuby +0 -0
- data/assets/xcode/tvos/MyApp.xcodeproj/project.pbxproj +0 -350
- data/assets/xcode/tvos/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- data/assets/xcode/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- data/assets/xcode/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +0 -30
- data/assets/xcode/tvos/main.c +0 -1
- data/ext/ruby2d/common.c +0 -185
- data/ext/ruby2d/controllers.c +0 -110
- data/ext/ruby2d/gl.c +0 -398
- data/ext/ruby2d/gl2.c +0 -86
- data/ext/ruby2d/gl3.c +0 -304
- data/ext/ruby2d/gles.c +0 -302
- data/ext/ruby2d/input.c +0 -48
- data/ext/ruby2d/music.c +0 -127
- data/ext/ruby2d/sound.c +0 -132
- data/lib/ruby2d/cli/console.rb +0 -65
- data/lib/ruby2d/cli/enable_console.rb +0 -7
- data/lib/ruby2d/cli/platform.rb +0 -17
- data/lib/ruby2d/music.rb +0 -77
- data/lib/ruby2d/pixel.rb +0 -18
- data/lib/ruby2d/pixmap.rb +0 -39
- data/lib/ruby2d/pixmap_atlas.rb +0 -56
- data/lib/ruby2d/sound.rb +0 -61
- data/lib/ruby2d/texture.rb +0 -38
- /data/assets/{include/SDL2 → platform/include/SDL3}/SDL_opengles2_gl2.h +0 -0
- /data/assets/{include/SDL2 → platform/include/SDL3}/SDL_opengles2_gl2ext.h +0 -0
- /data/assets/{include/SDL2 → platform/include/SDL3}/SDL_opengles2_gl2platform.h +0 -0
- /data/assets/{include/SDL2 → platform/include/SDL3}/SDL_opengles2_khrplatform.h +0 -0
- /data/assets/{include → platform/include}/mruby/re.h +0 -0
data/lib/ruby2d/renderable.rb
CHANGED
|
@@ -1,29 +1,343 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
1
|
# Ruby2D::Renderable
|
|
4
2
|
|
|
5
3
|
module Ruby2D
|
|
6
|
-
#
|
|
4
|
+
# Shared behavior for all renderable objects
|
|
7
5
|
module Renderable
|
|
8
|
-
|
|
6
|
+
# Per-object event handling (`on` / `off` / `interactive?` / `_fire_event`).
|
|
7
|
+
include Interactive
|
|
8
|
+
|
|
9
|
+
# Resolve an input color to a single Color. If given a per-vertex array or
|
|
10
|
+
# Color::Set, returns the first color. nil returns nil. Used to derive a
|
|
11
|
+
# single stroke color from a fill that may be per-vertex.
|
|
12
|
+
def self.resolve_single_color(input)
|
|
13
|
+
return nil if input.nil?
|
|
14
|
+
c = Color.set(input)
|
|
15
|
+
c.is_a?(Color::Set) ? Color.new(c.first) : c
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Resolve an input color allowing a Color::Set of exactly `vertex_count`
|
|
19
|
+
# entries or a single color. nil returns white. Raises ArgumentError for
|
|
20
|
+
# a Color::Set of the wrong length. Used by shapes that support per-vertex
|
|
21
|
+
# gradients along their outline or fill.
|
|
22
|
+
def self.resolve_color_or_default(input, vertex_count, label: nil)
|
|
23
|
+
return Color.new('white') if input.nil?
|
|
24
|
+
c = Color.set(input)
|
|
25
|
+
if c.is_a?(Color::Set) && c.length != vertex_count
|
|
26
|
+
prefix = label ? "`#{label}` " : ''
|
|
27
|
+
raise ArgumentError,
|
|
28
|
+
"#{prefix}requires #{vertex_count} colors, one for each vertex. #{c.length} were given."
|
|
29
|
+
end
|
|
30
|
+
c
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Normalize any color input into a flat RGBA array with `vertices` entries.
|
|
34
|
+
# Accepts names, hex, [r,g,b,a], Color, Color::Set, per-vertex arrays, or nil
|
|
35
|
+
# (which defaults to white). `opacity`, if given, overrides the alpha of each
|
|
36
|
+
# vertex. `label:` optionally supplies a class label used in the error message.
|
|
37
|
+
# Used by class-level `.render` methods.
|
|
38
|
+
def self.flatten_color(input, vertices, opacity = nil, label: nil)
|
|
39
|
+
fast = flatten_per_vertex(input, vertices, opacity)
|
|
40
|
+
return fast if fast
|
|
41
|
+
|
|
42
|
+
# `for_render`'s shared cached instance is safe here: this method only
|
|
43
|
+
# reads the color into a flat float array, so it can never escape.
|
|
44
|
+
c = Color.for_render(input.nil? ? 'white' : input)
|
|
45
|
+
flatten_resolved_color(c, vertices, opacity, label: label)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Validate an array of `[x, y]` pairs and flatten it to a flat float
|
|
49
|
+
# array in one pass. Replaces an `all?` validation followed by a
|
|
50
|
+
# `flat_map`, which walked the points twice and allocated a throwaway
|
|
51
|
+
# pair per vertex; on a per-frame `.render` of a few thousand points that
|
|
52
|
+
# overhead is comparable to the draw itself. `while`, not blocks — this
|
|
53
|
+
# is a per-draw-call path and block calls dominate on wasm mruby.
|
|
54
|
+
def self.flatten_points(points)
|
|
55
|
+
n = points.length
|
|
56
|
+
coords = Array.new(n * 2)
|
|
57
|
+
i = 0
|
|
58
|
+
while i < n
|
|
59
|
+
point = points[i]
|
|
60
|
+
raise ArgumentError, 'points must be an array of [x, y] pairs' \
|
|
61
|
+
unless point.is_a?(Array) && point.length == 2
|
|
62
|
+
|
|
63
|
+
coords[i * 2] = point[0].to_f
|
|
64
|
+
coords[i * 2 + 1] = point[1].to_f
|
|
65
|
+
i += 1
|
|
66
|
+
end
|
|
67
|
+
coords
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Flatten a per-vertex color array straight into the `vertices`×4 float
|
|
71
|
+
# array, skipping `Color::Set` entirely. The general path builds a Set,
|
|
72
|
+
# which allocates and parses one `Color` per vertex via `Color.new` —
|
|
73
|
+
# bypassing the render cache that makes the single-color path cheap. A
|
|
74
|
+
# per-frame `.render` pays that in full every frame, and for the hex
|
|
75
|
+
# strings the examples favor it is the most expensive color form there
|
|
76
|
+
# is. Numeric tuples are read directly; everything else resolves through
|
|
77
|
+
# `Color.for_render`, whose shared instance is safe here because it is
|
|
78
|
+
# read into floats immediately and never stored.
|
|
79
|
+
#
|
|
80
|
+
# Returns `nil` — falling back to the general path — for anything
|
|
81
|
+
# unusual: a mismatched length, an out-of-range channel, an element that
|
|
82
|
+
# isn't a valid color. Those still raise and warn from the one place
|
|
83
|
+
# below, so this stays a pure fast path and never the error authority.
|
|
84
|
+
def self.flatten_per_vertex(input, vertices, opacity)
|
|
85
|
+
return nil unless input.is_a?(Array) && input.length == vertices && vertices.positive?
|
|
86
|
+
# A flat `[r, g, b(, a)]` is a single color for every vertex, not a
|
|
87
|
+
# list of them — its first element is the only Numeric case here.
|
|
88
|
+
return nil if input[0].is_a?(Numeric)
|
|
89
|
+
return nil if opacity.is_a?(Array) && opacity.length != vertices
|
|
90
|
+
|
|
91
|
+
opacity_array = opacity.is_a?(Array)
|
|
92
|
+
flat = Array.new(vertices * 4)
|
|
93
|
+
i = 0
|
|
94
|
+
while i < vertices
|
|
95
|
+
el = input[i]
|
|
96
|
+
if el.instance_of?(Array)
|
|
97
|
+
# `instance_of?` mirrors `Color.valid?` — an Array subclass is not
|
|
98
|
+
# the plain-array form and must take the general path.
|
|
99
|
+
n = el.length
|
|
100
|
+
return nil unless n == 3 || n == 4
|
|
101
|
+
|
|
102
|
+
r = el[0]
|
|
103
|
+
g = el[1]
|
|
104
|
+
b = el[2]
|
|
105
|
+
a = n == 4 ? el[3] : 1.0
|
|
106
|
+
return nil unless r.is_a?(Numeric) && g.is_a?(Numeric) &&
|
|
107
|
+
b.is_a?(Numeric) && a.is_a?(Numeric)
|
|
108
|
+
# Out of range is `Color#channel`'s business: it warns and clamps.
|
|
109
|
+
return nil unless r >= 0.0 && r <= 1.0 && g >= 0.0 && g <= 1.0 &&
|
|
110
|
+
b >= 0.0 && b <= 1.0 && a >= 0.0 && a <= 1.0
|
|
111
|
+
|
|
112
|
+
r = r.to_f
|
|
113
|
+
g = g.to_f
|
|
114
|
+
b = b.to_f
|
|
115
|
+
a = a.to_f
|
|
116
|
+
elsif el.is_a?(Color)
|
|
117
|
+
r = el.r
|
|
118
|
+
g = el.g
|
|
119
|
+
b = el.b
|
|
120
|
+
a = el.a
|
|
121
|
+
else
|
|
122
|
+
# Validate first so an invalid element still raises from the
|
|
123
|
+
# general path, with the message it has always produced.
|
|
124
|
+
return nil unless Color.valid?(el)
|
|
125
|
+
|
|
126
|
+
c = Color.for_render(el)
|
|
127
|
+
r = c.r
|
|
128
|
+
g = c.g
|
|
129
|
+
b = c.b
|
|
130
|
+
a = c.a
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
j = i * 4
|
|
134
|
+
flat[j] = r
|
|
135
|
+
flat[j + 1] = g
|
|
136
|
+
flat[j + 2] = b
|
|
137
|
+
flat[j + 3] = (opacity_array ? opacity[i] : opacity) || a
|
|
138
|
+
i += 1
|
|
139
|
+
end
|
|
140
|
+
flat
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Flatten an already-resolved `Color`/`Color::Set` into the `vertices`×4
|
|
144
|
+
# float array. Split from `flatten_color` so the immediate-mode `.render`
|
|
145
|
+
# paths can resolve the color once — to choose the single-color fast path —
|
|
146
|
+
# without parsing it a second time when they fall back to the per-vertex array.
|
|
147
|
+
def self.flatten_resolved_color(c, vertices, opacity = nil, label: nil)
|
|
148
|
+
if c.is_a?(Color::Set) && c.length != vertices
|
|
149
|
+
prefix = label ? "`#{label}` " : ''
|
|
150
|
+
raise ArgumentError,
|
|
151
|
+
"#{prefix}requires #{vertices} colors, one for each vertex. #{c.length} were given."
|
|
152
|
+
end
|
|
153
|
+
if opacity.is_a?(Array) && opacity.length != vertices
|
|
154
|
+
prefix = label ? "`#{label}` " : ''
|
|
155
|
+
raise ArgumentError,
|
|
156
|
+
"#{prefix}requires #{vertices} opacity values, one for each vertex. #{opacity.length} were given."
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
flat = Array.new(vertices * 4)
|
|
160
|
+
opacity_array = opacity.is_a?(Array)
|
|
161
|
+
vertices.times do |i|
|
|
162
|
+
col = c.vertex(i)
|
|
163
|
+
flat[i * 4] = col.r
|
|
164
|
+
flat[i * 4 + 1] = col.g
|
|
165
|
+
flat[i * 4 + 2] = col.b
|
|
166
|
+
flat[i * 4 + 3] = (opacity_array ? opacity[i] : opacity) || col.a
|
|
167
|
+
end
|
|
168
|
+
flat
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
attr_reader :x, :y, :z, :width, :height, :color, :x_align, :y_align
|
|
172
|
+
attr_accessor :visible,
|
|
173
|
+
:padding_top, :padding_right, :padding_bottom, :padding_left
|
|
174
|
+
alias_method :visible?, :visible
|
|
175
|
+
|
|
176
|
+
# Set all four padding edges to the same value. Padding is the distance,
|
|
177
|
+
# in pixels, between the object and the window edge it's anchored to.
|
|
178
|
+
# No effect on `:center`-aligned axes or un-aligned axes.
|
|
179
|
+
def padding=(value)
|
|
180
|
+
@padding_top = @padding_right = @padding_bottom = @padding_left = value
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Set horizontal alignment intent (`:left`, `:center`, `:right`, or `nil`).
|
|
184
|
+
# Resolution is deferred to draw time against `Window.viewport_width`.
|
|
185
|
+
def x_align=(sym)
|
|
186
|
+
@x_align = sym&.to_sym
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# Set vertical alignment intent (`:top`, `:center`, `:bottom`, or `nil`).
|
|
190
|
+
# Resolution is deferred to draw time against `Window.viewport_height`.
|
|
191
|
+
def y_align=(sym)
|
|
192
|
+
@y_align = sym&.to_sym
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Resolve symbolic alignment to numeric x/y. Called from the render path of
|
|
196
|
+
# each shape that opts into alignment. Requires the window to be open —
|
|
197
|
+
# `Window.viewport_width` and `viewport_height` are only correct after
|
|
198
|
+
# `show` starts. The `case` computes a bounding-box top-left position;
|
|
199
|
+
# `_alignment_anchor_dx`/`_dy` then shift it to the shape's own anchor
|
|
200
|
+
# (zero for top-left shapes, half-extent for center-anchored Circle/Ellipse).
|
|
201
|
+
def _resolve_alignment
|
|
202
|
+
return unless @x_align || @y_align
|
|
203
|
+
|
|
204
|
+
dx = _alignment_anchor_dx
|
|
205
|
+
dy = _alignment_anchor_dy
|
|
206
|
+
@_resolving_alignment = true
|
|
207
|
+
begin
|
|
208
|
+
if @x_align
|
|
209
|
+
span = Window.viewport_width
|
|
210
|
+
self.x = (case @x_align
|
|
211
|
+
when :left then (@padding_left || 0)
|
|
212
|
+
when :center then (span - width) / 2.0
|
|
213
|
+
when :right then span - width - (@padding_right || 0)
|
|
214
|
+
else raise ArgumentError, "Unknown x alignment: #{@x_align.inspect}"
|
|
215
|
+
end) + dx
|
|
216
|
+
end
|
|
217
|
+
if @y_align
|
|
218
|
+
span = Window.viewport_height
|
|
219
|
+
self.y = (case @y_align
|
|
220
|
+
when :top then (@padding_top || 0)
|
|
221
|
+
when :center then (span - height) / 2.0
|
|
222
|
+
when :bottom then span - height - (@padding_bottom || 0)
|
|
223
|
+
else raise ArgumentError, "Unknown y alignment: #{@y_align.inspect}"
|
|
224
|
+
end) + dy
|
|
225
|
+
end
|
|
226
|
+
ensure
|
|
227
|
+
@_resolving_alignment = false
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# Offset from the bounding-box top-left (what `_resolve_alignment` computes)
|
|
232
|
+
# to the shape's position anchor, split into x/y components to avoid boxing a
|
|
233
|
+
# throwaway pair each aligned frame. Top-left-anchored shapes (Rectangle,
|
|
234
|
+
# Image, Text, …) need none; center-anchored shapes override to half their
|
|
235
|
+
# extent so `:left` hugs the wall with the bounding box, like a rectangle.
|
|
236
|
+
def _alignment_anchor_dx
|
|
237
|
+
0
|
|
238
|
+
end
|
|
9
239
|
|
|
10
|
-
|
|
240
|
+
def _alignment_anchor_dy
|
|
241
|
+
0
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# Resolve construction-time padding kwargs into per-edge values. The
|
|
245
|
+
# uniform `padding:` seeds all four edges; per-edge kwargs override
|
|
246
|
+
# individual slots. Called from each shape's `initialize` after
|
|
247
|
+
# `_extract_alignment`.
|
|
248
|
+
def _apply_padding(padding, top, right, bottom, left)
|
|
249
|
+
base = padding || 0
|
|
250
|
+
@padding_top = top || base
|
|
251
|
+
@padding_right = right || base
|
|
252
|
+
@padding_bottom = bottom || base
|
|
253
|
+
@padding_left = left || base
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# Reject negative construction-time dimensions (width, height, radius, …).
|
|
257
|
+
# A negative extent is a setup mistake: it renders but disagrees with hit
|
|
258
|
+
# testing, since `contains?` assumes positive geometry. Zero is allowed
|
|
259
|
+
# (collapse-to-point). Runtime setters are deliberately left unguarded so an
|
|
260
|
+
# animation whose size momentarily dips below zero degrades to nothing for
|
|
261
|
+
# that frame rather than crashing the app — see USAGE.md.
|
|
262
|
+
def _validate_dimensions(**dims)
|
|
263
|
+
dims.each do |name, value|
|
|
264
|
+
next unless value.is_a?(Numeric) && value.negative?
|
|
265
|
+
raise ArgumentError, "#{self.class} #{name} must be zero or positive, got #{value}"
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
# Extract symbolic alignment from a constructor (x, y) pair, store the
|
|
270
|
+
# intent, and return numeric placeholders to use until the first draw.
|
|
271
|
+
def _extract_alignment(x, y)
|
|
272
|
+
self.x_align = x if x.is_a?(Symbol)
|
|
273
|
+
self.y_align = y if y.is_a?(Symbol)
|
|
274
|
+
[x.is_a?(Symbol) ? 0 : x, y.is_a?(Symbol) ? 0 : y]
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# Reject a non-numeric position on a shape with no single anchor to align.
|
|
278
|
+
# Bounding-box shapes (Image, Text, Rectangle, Circle, Ellipse) accept a
|
|
279
|
+
# symbol like `:center` as alignment intent; the centroid-anchored vertex
|
|
280
|
+
# shapes (Triangle, Quad, Polygon, Polyline) and the pixel-buffer Canvas have
|
|
281
|
+
# nothing to align, so a symbol there is a setup mistake. Raise a clear error
|
|
282
|
+
# rather than let it reach the centroid arithmetic (a bare `Symbol#-`
|
|
283
|
+
# NoMethodError) or the native renderer (a cryptic type error at draw time).
|
|
284
|
+
# Returns the value so a setter can validate and assign in one expression.
|
|
285
|
+
def _require_numeric_position(axis, value)
|
|
286
|
+
return value if value.is_a?(Numeric)
|
|
287
|
+
raise Error,
|
|
288
|
+
"#{self.class} #{axis} must be a number; #{self.class} doesn't support " \
|
|
289
|
+
"symbolic alignment (e.g. #{axis}: :center) — use a bounding-box shape " \
|
|
290
|
+
'like Text, Image, or Rectangle for that'
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
# Set the z position (depth) of the object. Re-inserts at the new depth only
|
|
294
|
+
# if the object was actually in the scene graph — `Window#remove` returns
|
|
295
|
+
# false for an object built with `add: false` or already removed, so changing
|
|
296
|
+
# its `z` updates the value without silently adding it to the window.
|
|
11
297
|
def z=(z)
|
|
12
|
-
remove
|
|
298
|
+
was_added = remove
|
|
13
299
|
@z = z
|
|
14
|
-
add
|
|
300
|
+
add if was_added
|
|
15
301
|
end
|
|
16
302
|
|
|
17
|
-
# Add the object to the window
|
|
303
|
+
# Add the object to the window's scene graph. This governs iteration and
|
|
304
|
+
# z-ordering, not visibility. Use #show / #hide (or the `visible` accessor)
|
|
305
|
+
# to toggle frame-by-frame drawing without affecting scene-graph membership.
|
|
18
306
|
def add
|
|
19
307
|
Window.add(self)
|
|
20
308
|
end
|
|
21
309
|
|
|
22
|
-
# Remove the object from the window
|
|
310
|
+
# Remove the object from the window's scene graph.
|
|
23
311
|
def remove
|
|
24
312
|
Window.remove(self)
|
|
25
313
|
end
|
|
26
314
|
|
|
315
|
+
# Mark the object visible. Preserves scene-graph position and z-order; the
|
|
316
|
+
# window's render loop will draw it on subsequent frames.
|
|
317
|
+
def show
|
|
318
|
+
@visible = true
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# Mark the object hidden. Stays in the scene graph (and contains?/events
|
|
322
|
+
# continue to work). Visually equivalent to opacity 0 but with zero draw
|
|
323
|
+
# cost.
|
|
324
|
+
def hide
|
|
325
|
+
@visible = false
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# Scene-graph draw hook, called once per frame per visible object. This
|
|
329
|
+
# fallback forwards to `render` so a custom renderable only has to define
|
|
330
|
+
# `render`; every built-in shape overrides or aliases it to skip the
|
|
331
|
+
# keyword handling of its public `render`, which costs ~5µs per call on
|
|
332
|
+
# wasm mruby even when no keywords are passed. Public — like the other
|
|
333
|
+
# underscore-prefixed internals — so the scene loop can call it directly:
|
|
334
|
+
# a `send` there costs real time at thousands of objects per frame. Shapes
|
|
335
|
+
# that alias it from a private `render` re-publicize the alias with
|
|
336
|
+
# `public :_render_scene`, since aliases inherit the original visibility.
|
|
337
|
+
def _render_scene
|
|
338
|
+
render
|
|
339
|
+
end
|
|
340
|
+
|
|
27
341
|
# Set the color value
|
|
28
342
|
def color=(color)
|
|
29
343
|
@color = Color.new(color)
|
|
@@ -31,11 +345,97 @@ module Ruby2D
|
|
|
31
345
|
|
|
32
346
|
# Allow British English spelling of color
|
|
33
347
|
alias colour color
|
|
34
|
-
alias colour= color=
|
|
35
348
|
|
|
36
|
-
|
|
349
|
+
def colour=(color)
|
|
350
|
+
self.color = color
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
# Get the opacity (alpha) of the object's fill color. For per-vertex
|
|
354
|
+
# `Color::Set` fills, returns the alpha of the first color.
|
|
355
|
+
def opacity
|
|
356
|
+
@color&.opacity
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# Set the opacity (alpha) of the object's color. Fades the fill and, on
|
|
360
|
+
# shapes that have one, the stroke too — matching how a construction-time
|
|
361
|
+
# `opacity:` applies to both. For per-vertex `Color::Set` colors, sets every
|
|
362
|
+
# vertex's alpha to the same value. To fade fill and stroke independently,
|
|
363
|
+
# set each color's opacity directly: `obj.color.opacity = a` and
|
|
364
|
+
# `obj.stroke_color.opacity = b`.
|
|
365
|
+
def opacity=(value)
|
|
366
|
+
@color.opacity = value
|
|
367
|
+
@stroke_color.opacity = value if instance_variable_defined?(:@stroke_color) && @stroke_color
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
# Map a query point into this object's unrotated coordinate frame. Each
|
|
371
|
+
# shape's `render` rotates geometry about `(rx, ry)` by `@rotate` degrees
|
|
372
|
+
# before drawing; `contains?` calls this first so hit-testing matches what
|
|
373
|
+
# the user sees. Returns the point unchanged when there's no rotation (or
|
|
374
|
+
# the object has no rotation pivot, e.g. `BitmapText`).
|
|
375
|
+
def _unrotate(px, py)
|
|
376
|
+
rotate = instance_variable_defined?(:@rotate) ? @rotate : nil
|
|
377
|
+
return [px, py] if rotate.nil? || rotate == 0
|
|
378
|
+
|
|
379
|
+
cx = rx; cy = ry
|
|
380
|
+
rad = -rotate * Math::PI / 180.0
|
|
381
|
+
sa = Math.sin(rad); ca = Math.cos(rad)
|
|
382
|
+
dx = px - cx; dy = py - cy
|
|
383
|
+
[dx * ca - dy * sa + cx, dx * sa + dy * ca + cy]
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
# Even-odd ray-cast point-in-polygon test over a flat `[x0, y0, x1, y1, ...]`
|
|
387
|
+
# coordinate array. This is the shared hit-test for every filled polygonal
|
|
388
|
+
# shape (`Triangle`, `Quad`, `Polygon`) so `contains?` means "inside the
|
|
389
|
+
# rendered fill" consistently — matching the fill for simple polygons (convex
|
|
390
|
+
# and concave). Self-intersecting input isn't fully supported by the fill
|
|
391
|
+
# renderer, so the test can diverge from the drawn pixels there. The boundary
|
|
392
|
+
# is half-open (top/right edges read as outside), as in rasterization.
|
|
393
|
+
def _point_in_polygon?(coords, px, py)
|
|
394
|
+
n = coords.length / 2
|
|
395
|
+
inside = false
|
|
396
|
+
j = n - 1
|
|
397
|
+
n.times do |i|
|
|
398
|
+
xi = coords[i * 2]; yi = coords[i * 2 + 1]
|
|
399
|
+
xj = coords[j * 2]; yj = coords[j * 2 + 1]
|
|
400
|
+
if (yi > py) != (yj > py) &&
|
|
401
|
+
px < (xj - xi) * (py - yi) / (yj - yi).to_f + xi
|
|
402
|
+
inside = !inside
|
|
403
|
+
end
|
|
404
|
+
j = i
|
|
405
|
+
end
|
|
406
|
+
inside
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
# Hit-test a point against the stroked band of segment (x1, y1)-(x2, y2):
|
|
410
|
+
# true when (px, py) lies within the rectangle the stroke actually draws.
|
|
411
|
+
# `half_sq` is the squared half-stroke-width tolerance. The point must
|
|
412
|
+
# project onto the segment (0 <= t <= 1) *and* fall within the half-width
|
|
413
|
+
# perpendicular, so the hit region matches the drawn (butt-capped) rectangle
|
|
414
|
+
# and does not overhang the ends. Shared stroke hit-test for `Line` and
|
|
415
|
+
# `Polyline`; compares squared distances to skip the square root on this
|
|
416
|
+
# per-event, per-segment path.
|
|
417
|
+
def _point_on_segment?(px, py, x1, y1, x2, y2, half_sq)
|
|
418
|
+
dx = x2 - x1
|
|
419
|
+
dy = y2 - y1
|
|
420
|
+
len_sq = dx * dx + dy * dy
|
|
421
|
+
return false if len_sq.zero? # zero-length segment draws nothing
|
|
422
|
+
|
|
423
|
+
# fdiv (not /) so integer coordinates don't trigger integer floor
|
|
424
|
+
# division, which would snap t to 0/1 and mis-measure the projection.
|
|
425
|
+
t = ((px - x1) * dx + (py - y1) * dy).fdiv(len_sq)
|
|
426
|
+
return false if t < 0.0 || t > 1.0 # past an end — outside the drawn rect
|
|
427
|
+
|
|
428
|
+
cx = x1 + t * dx
|
|
429
|
+
cy = y1 + t * dy
|
|
430
|
+
ex = px - cx; ey = py - cy
|
|
431
|
+
ex * ex + ey * ey <= half_sq
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
# Check if the object contains the given point
|
|
37
435
|
def contains?(x, y)
|
|
436
|
+
x, y = _unrotate(x, y)
|
|
38
437
|
x >= @x && x <= (@x + @width) && y >= @y && y <= (@y + @height)
|
|
39
438
|
end
|
|
439
|
+
|
|
40
440
|
end
|
|
41
441
|
end
|