ruby2d 0.11.3 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/include/GLES2/gl2.h +656 -0
- data/assets/include/GLES2/gl2ext.h +3949 -0
- data/assets/include/GLES2/gl2ext_angle.h +701 -0
- data/assets/include/GLES2/gl2platform.h +27 -0
- data/assets/include/GLES3/gl3.h +1192 -0
- data/assets/include/GLES3/gl31.h +1507 -0
- data/assets/include/GLES3/gl32.h +1808 -0
- data/assets/include/GLES3/gl3platform.h +27 -0
- data/assets/include/KHR/khrplatform.h +290 -0
- data/assets/include/SDL2/SDL.h +1 -0
- data/assets/include/SDL2/SDL_assert.h +4 -2
- data/assets/include/SDL2/SDL_atomic.h +20 -0
- data/assets/include/SDL2/SDL_audio.h +40 -4
- data/assets/include/SDL2/SDL_blendmode.h +4 -6
- data/assets/include/SDL2/SDL_clipboard.h +47 -0
- data/assets/include/SDL2/SDL_config.h +6 -2
- data/assets/include/SDL2/SDL_config_android.h +2 -0
- data/assets/include/SDL2/SDL_config_emscripten.h +2 -0
- data/assets/include/SDL2/SDL_config_iphoneos.h +3 -1
- data/assets/include/SDL2/SDL_config_macosx.h +3 -6
- data/assets/include/SDL2/SDL_config_minimal.h +18 -11
- data/assets/include/SDL2/SDL_config_ngage.h +89 -0
- data/assets/include/SDL2/SDL_config_os2.h +5 -3
- data/assets/include/SDL2/SDL_config_pandora.h +1 -0
- data/assets/include/SDL2/SDL_config_windows.h +71 -45
- data/assets/include/SDL2/SDL_config_wingdk.h +253 -0
- data/assets/include/SDL2/SDL_config_winrt.h +11 -49
- data/assets/include/SDL2/SDL_config_xbox.h +235 -0
- data/assets/include/SDL2/SDL_cpuinfo.h +39 -4
- data/assets/include/SDL2/SDL_egl.h +59 -9
- data/assets/include/SDL2/SDL_endian.h +34 -3
- data/assets/include/SDL2/SDL_events.h +32 -1
- data/assets/include/SDL2/SDL_filesystem.h +5 -1
- data/assets/include/SDL2/SDL_gamecontroller.h +78 -5
- data/assets/include/SDL2/SDL_guid.h +100 -0
- data/assets/include/SDL2/SDL_hints.h +645 -43
- data/assets/include/SDL2/SDL_image.h +2045 -33
- data/assets/include/SDL2/SDL_joystick.h +127 -7
- data/assets/include/SDL2/SDL_keyboard.h +38 -1
- data/assets/include/SDL2/SDL_keycode.h +6 -1
- data/assets/include/SDL2/SDL_log.h +2 -2
- data/assets/include/SDL2/SDL_main.h +42 -2
- data/assets/include/SDL2/SDL_metal.h +2 -1
- data/assets/include/SDL2/SDL_mixer.h +2529 -396
- data/assets/include/SDL2/SDL_mouse.h +12 -1
- data/assets/include/SDL2/SDL_opengl.h +0 -51
- data/assets/include/SDL2/SDL_opengl_glext.h +2260 -231
- data/assets/include/SDL2/SDL_opengles2_gl2.h +374 -339
- data/assets/include/SDL2/SDL_opengles2_gl2ext.h +3479 -1496
- data/assets/include/SDL2/SDL_opengles2_gl2platform.h +6 -9
- data/assets/include/SDL2/SDL_opengles2_khrplatform.h +43 -14
- data/assets/include/SDL2/SDL_platform.h +32 -6
- data/assets/include/SDL2/SDL_rect.h +154 -2
- data/assets/include/SDL2/SDL_render.h +46 -17
- data/assets/include/SDL2/SDL_revision.h +4 -0
- data/assets/include/SDL2/SDL_rwops.h +1 -15
- data/assets/include/SDL2/SDL_scancode.h +46 -21
- data/assets/include/SDL2/SDL_sensor.h +24 -3
- data/assets/include/SDL2/SDL_stdinc.h +119 -8
- data/assets/include/SDL2/SDL_surface.h +3 -1
- data/assets/include/SDL2/SDL_system.h +66 -6
- data/assets/include/SDL2/SDL_syswm.h +2 -0
- data/assets/include/SDL2/SDL_test_common.h +1 -0
- data/assets/include/SDL2/SDL_test_font.h +90 -3
- data/assets/include/SDL2/SDL_thread.h +3 -3
- data/assets/include/SDL2/SDL_touch.h +8 -0
- data/assets/include/SDL2/SDL_ttf.h +2084 -155
- data/assets/include/SDL2/SDL_version.h +19 -3
- data/assets/include/SDL2/SDL_video.h +71 -9
- data/assets/include/SDL2/begin_code.h +4 -4
- data/assets/include/mrbconf.h +15 -17
- data/assets/include/mruby/array.h +8 -21
- data/assets/include/mruby/boxing_nan.h +115 -86
- data/assets/include/mruby/boxing_word.h +104 -78
- data/assets/include/mruby/common.h +6 -0
- data/assets/include/mruby/compile.h +3 -4
- data/assets/include/mruby/debug.h +4 -2
- data/assets/include/mruby/dump.h +5 -2
- data/assets/include/mruby/error.h +12 -2
- data/assets/include/mruby/gc.h +2 -0
- data/assets/include/mruby/hash.h +1 -3
- data/assets/include/mruby/irep.h +4 -4
- data/assets/include/mruby/numeric.h +21 -13
- data/assets/include/mruby/opcode.h +30 -0
- data/assets/include/mruby/ops.h +99 -101
- data/assets/include/mruby/presym/scanning.h +15 -9
- data/assets/include/mruby/proc.h +4 -2
- data/assets/include/mruby/string.h +3 -24
- data/assets/include/mruby/value.h +80 -40
- data/assets/include/mruby/variable.h +0 -15
- data/assets/include/mruby/version.h +5 -5
- data/assets/include/mruby.h +86 -16
- 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/wasm/template.html +2 -1
- 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/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/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/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/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/libopus.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 -0
- 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/libwebp.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libz.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/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/libharfbuzz.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libhwy.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/libmpg123.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libmruby.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libopus.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 -0
- 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/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/ext/ruby2d/canvas.c +540 -0
- data/ext/ruby2d/extconf.rb +33 -20
- data/ext/ruby2d/gl.c +3 -3
- data/ext/ruby2d/image.c +7 -7
- data/ext/ruby2d/ruby2d.c +741 -24
- data/ext/ruby2d/ruby2d.h +66 -3
- data/ext/ruby2d/sound.c +16 -2
- data/lib/ruby2d/canvas.rb +315 -0
- data/lib/ruby2d/circle.rb +30 -15
- data/lib/ruby2d/cli/build.rb +5 -3
- data/lib/ruby2d/cli/enable_console.rb +3 -1
- data/lib/ruby2d/color.rb +133 -77
- data/lib/ruby2d/core.rb +32 -0
- data/lib/ruby2d/dsl.rb +38 -32
- data/lib/ruby2d/exceptions.rb +2 -1
- data/lib/ruby2d/font.rb +97 -62
- data/lib/ruby2d/image.rb +48 -27
- data/lib/ruby2d/line.rb +84 -45
- data/lib/ruby2d/music.rb +33 -23
- data/lib/ruby2d/pixel.rb +10 -9
- data/lib/ruby2d/pixmap.rb +39 -0
- data/lib/ruby2d/pixmap_atlas.rb +56 -0
- data/lib/ruby2d/quad.rb +98 -49
- data/lib/ruby2d/rectangle.rb +35 -36
- data/lib/ruby2d/renderable.rb +7 -6
- data/lib/ruby2d/sound.rb +23 -17
- data/lib/ruby2d/sprite.rb +181 -140
- data/lib/ruby2d/square.rb +21 -20
- data/lib/ruby2d/text.rb +47 -19
- data/lib/ruby2d/texture.rb +13 -3
- data/lib/ruby2d/tileset.rb +97 -44
- data/lib/ruby2d/triangle.rb +91 -42
- data/lib/ruby2d/version.rb +3 -1
- data/lib/ruby2d/vertices.rb +81 -45
- data/lib/ruby2d/window.rb +508 -371
- data/lib/ruby2d.rb +11 -29
- metadata +51 -16
- data/assets/include/SDL2/SDL_config_psp.h +0 -165
- data/assets/include/SDL2/SDL_config_wiz.h +0 -154
- data/assets/include/glew.h +0 -23686
- data/assets/macos/universal/lib/libpng16.a +0 -0
- data/assets/windows/glew/README.md +0 -10
- data/assets/windows/glew/glew.h +0 -23686
- data/assets/windows/glew/libglew32.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libpng16.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libpng16.a +0 -0
- data/lib/ruby2d/entity.rb +0 -17
data/ext/ruby2d/ruby2d.h
CHANGED
@@ -129,7 +129,7 @@ extern "C" {
|
|
129
129
|
#define GL_GLEXT_PROTOTYPES 1
|
130
130
|
#if WINDOWS
|
131
131
|
#define GLEW_STATIC
|
132
|
-
#include <glew.h>
|
132
|
+
#include <GL/glew.h>
|
133
133
|
#endif
|
134
134
|
#include <SDL2/SDL_opengl.h>
|
135
135
|
#endif
|
@@ -321,6 +321,7 @@ typedef struct {
|
|
321
321
|
typedef struct {
|
322
322
|
const char *path;
|
323
323
|
Mix_Chunk *data;
|
324
|
+
int channel;
|
324
325
|
} R2D_Sound;
|
325
326
|
|
326
327
|
// R2D_Music
|
@@ -471,7 +472,12 @@ R2D_Sound *R2D_CreateSound(const char *path);
|
|
471
472
|
/*
|
472
473
|
* Play the sound
|
473
474
|
*/
|
474
|
-
void R2D_PlaySound(R2D_Sound *snd);
|
475
|
+
void R2D_PlaySound(R2D_Sound *snd, bool loop);
|
476
|
+
|
477
|
+
/*
|
478
|
+
* Stop the sound
|
479
|
+
*/
|
480
|
+
void R2D_StopSound(R2D_Sound *snd);
|
475
481
|
|
476
482
|
/*
|
477
483
|
* Get the sound's length
|
@@ -503,6 +509,63 @@ void R2D_SetSoundMixVolume(int volume);
|
|
503
509
|
*/
|
504
510
|
void R2D_FreeSound(R2D_Sound *snd);
|
505
511
|
|
512
|
+
// Canvas //////////////////////////////////////////////////////////////////////
|
513
|
+
|
514
|
+
/*
|
515
|
+
* Draw a thick rectangle on a canvas using a pre-converted RGBA colour value.
|
516
|
+
* @param [int] thickness must be > 1, else does nothing
|
517
|
+
*/
|
518
|
+
void R2D_Canvas_DrawThickRect(SDL_Renderer *render, int x, int y, int width,
|
519
|
+
int height, int thickness, int r, int g, int b,
|
520
|
+
int a);
|
521
|
+
|
522
|
+
/*
|
523
|
+
* Draw a thick line on a canvas using a pre-converted RGBA colour value.
|
524
|
+
* @param [int] thickness must be > 1, else does nothing
|
525
|
+
*/
|
526
|
+
void R2D_Canvas_DrawThickLine(SDL_Renderer *render,
|
527
|
+
int x1, int y1, int x2, int y2, int thickness,
|
528
|
+
int r, int g, int b, int a);
|
529
|
+
|
530
|
+
/*
|
531
|
+
* Draw a thin (single pixel) ellipse on a canvas using a pre-converted RGBA
|
532
|
+
* colour value.
|
533
|
+
*/
|
534
|
+
void R2D_Canvas_DrawThinEllipse(SDL_Renderer *render, int x, int y,
|
535
|
+
float xradius, float yradius, float sectors,
|
536
|
+
int r, int g, int b, int a);
|
537
|
+
|
538
|
+
/*
|
539
|
+
* Draw a thick ellipse on a canvas using a pre-converted RGBA colour value.
|
540
|
+
* @param [int] thickness must be > 1, else does nothing
|
541
|
+
*/
|
542
|
+
void R2D_Canvas_DrawThickEllipse(SDL_Renderer *render, int x, int y,
|
543
|
+
float xradius, float yradius, float sectors,
|
544
|
+
int thickness, int r, int g, int b, int a);
|
545
|
+
|
546
|
+
/*
|
547
|
+
* Draw a thick N-point polyline, with a mitre join where two
|
548
|
+
* segments are joined.
|
549
|
+
* @param [int] thickness must be > 1, else does nothing
|
550
|
+
* @param [bool] skip_first_last use false for polyline, true for polygon when specifying first, second points again at the end
|
551
|
+
*/
|
552
|
+
void R2D_Canvas_DrawThickPolyline(SDL_Renderer *render, SDL_FPoint *points,
|
553
|
+
int num_points, int thickness, int r, int g,
|
554
|
+
int b, int a, bool skip_first_last);
|
555
|
+
|
556
|
+
/*
|
557
|
+
* Fill a polygon with a single colour.
|
558
|
+
* @param points Array of points
|
559
|
+
* @param num_points Number of points
|
560
|
+
* @param colors Array of colours
|
561
|
+
* @param num_colors Number of colors, must be at least 1, and may be less than
|
562
|
+
* +num_points+ in which case the colours will be repeated
|
563
|
+
* via modulo.
|
564
|
+
* @note Currently supports only: convex polygons or simple polygons with one concave corner. For now.
|
565
|
+
*/
|
566
|
+
void R2D_Canvas_FillPolygon(SDL_Renderer *render, SDL_FPoint *points,
|
567
|
+
int num_points, SDL_Color *colors, int num_colors);
|
568
|
+
|
506
569
|
// Music ///////////////////////////////////////////////////////////////////////
|
507
570
|
|
508
571
|
/*
|
@@ -639,7 +702,7 @@ int R2D_GL_CheckLinked(GLuint program, const char *name);
|
|
639
702
|
void R2D_GL_GetViewportScale(R2D_Window *window, int *w, int *h, double *scale);
|
640
703
|
void R2D_GL_SetViewport(R2D_Window *window);
|
641
704
|
void R2D_GL_CreateTexture(
|
642
|
-
GLuint *id, GLint format,
|
705
|
+
GLuint *id, GLint internalFormat, GLint format, GLenum type,
|
643
706
|
int w, int h,
|
644
707
|
const GLvoid *data, GLint filter);
|
645
708
|
void R2D_GL_DrawTriangle(
|
data/ext/ruby2d/sound.c
CHANGED
@@ -40,9 +40,23 @@ R2D_Sound *R2D_CreateSound(const char *path) {
|
|
40
40
|
/*
|
41
41
|
* Play the sound
|
42
42
|
*/
|
43
|
-
void R2D_PlaySound(R2D_Sound *snd) {
|
43
|
+
void R2D_PlaySound(R2D_Sound *snd, bool loop) {
|
44
44
|
if (!snd) return;
|
45
|
-
|
45
|
+
|
46
|
+
// If looping, set to -1 times; else 0
|
47
|
+
int times = loop ? -1 : 0;
|
48
|
+
|
49
|
+
// times: 0 == once, -1 == forever
|
50
|
+
snd->channel = Mix_PlayChannel(-1, snd->data, times);
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
* Stop the sound
|
55
|
+
*/
|
56
|
+
void R2D_StopSound(R2D_Sound *snd) {
|
57
|
+
if (!snd) return;
|
58
|
+
|
59
|
+
Mix_HaltChannel(snd->channel);
|
46
60
|
}
|
47
61
|
|
48
62
|
|
@@ -0,0 +1,315 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Ruby2D::Canvas
|
4
|
+
|
5
|
+
module Ruby2D
|
6
|
+
#
|
7
|
+
# Canvas provides a surface into which you can draw using primitives and render the contents
|
8
|
+
# as if it were an image/texture.
|
9
|
+
#
|
10
|
+
# @example A basic Canvas positioned at (0, 0)
|
11
|
+
# Canvas.new width: 320, height: 240
|
12
|
+
# @example A Canvas that doesn't update texture on every draw method
|
13
|
+
# Canvas.new width: 320, height: 240, update: false
|
14
|
+
#
|
15
|
+
class Canvas
|
16
|
+
include Renderable
|
17
|
+
|
18
|
+
# Create a Canvas.
|
19
|
+
#
|
20
|
+
# @param [Numeric] width The +width+ of the canvas in pixels
|
21
|
+
# @param [Numeric] height The +height+ of the canvas in pixels
|
22
|
+
# @param [Numeric] x
|
23
|
+
# @param [Numeric] y
|
24
|
+
# @param [Numeric] z
|
25
|
+
# @param [Numeric] rotate Angle, default is 0
|
26
|
+
# @param [String] fill Colour to clear the canvas, respects transparency
|
27
|
+
# @param [String] color or +colour+ Tint the texture when rendering
|
28
|
+
# @param [Numeric] opacity Opacity of the texture when rendering
|
29
|
+
# @param [true, false] update If +true+ updates the texture for every draw/fill call
|
30
|
+
# @param [true, false] show If +true+ the canvas is added to +Window+ automatically.
|
31
|
+
def initialize(width:, height:, x: 0, y: 0, z: 0, rotate: 0,
|
32
|
+
fill: [0, 0, 0, 0], color: nil, colour: nil, opacity: nil,
|
33
|
+
update: true, show: true)
|
34
|
+
@x = x
|
35
|
+
@y = y
|
36
|
+
@z = z
|
37
|
+
@width = width
|
38
|
+
@height = height
|
39
|
+
@rotate = rotate
|
40
|
+
@fill = Color.new(fill)
|
41
|
+
self.color = color || colour || 'white'
|
42
|
+
color.opacity = opacity if opacity
|
43
|
+
@update = update
|
44
|
+
|
45
|
+
ext_create([@width, @height, @fill.r, @fill.g, @fill.b, @fill.a]) # sets @ext_pixel_data
|
46
|
+
@texture = Texture.new(@ext_pixel_data, @width, @height)
|
47
|
+
add if show
|
48
|
+
end
|
49
|
+
|
50
|
+
# Clear the entire canvas, replacing every pixel with fill colour without blending.
|
51
|
+
# @param [Color] fill_color
|
52
|
+
def clear(fill_color = @fill)
|
53
|
+
color = fill_color || @fill
|
54
|
+
ext_clear([color.r, color.g, color.b, color.a])
|
55
|
+
update_texture if @update
|
56
|
+
end
|
57
|
+
|
58
|
+
# Draw a filled triangle with a single colour or per-vertex colour blending.
|
59
|
+
# @param [Numeric] x1
|
60
|
+
# @param [Numeric] y1
|
61
|
+
# @param [Numeric] x2
|
62
|
+
# @param [Numeric] y2
|
63
|
+
# @param [Numeric] x3
|
64
|
+
# @param [Numeric] y3
|
65
|
+
# @param [Color, Color::Set] color (or +colour+) Set one or per-vertex colour
|
66
|
+
def fill_triangle(x1:, y1:, x2:, y2:, x3:, y3:, color: nil, colour: nil)
|
67
|
+
fill_polygon coordinates: [x1, y1, x2, y2, x3, y3], color: color || colour
|
68
|
+
end
|
69
|
+
|
70
|
+
# Draw a filled quad(rilateral) with a single colour or per-vertex colour blending.
|
71
|
+
# @param [Numeric] x1
|
72
|
+
# @param [Numeric] y1
|
73
|
+
# @param [Numeric] x2
|
74
|
+
# @param [Numeric] y2
|
75
|
+
# @param [Numeric] x3
|
76
|
+
# @param [Numeric] y3
|
77
|
+
# @param [Numeric] x4
|
78
|
+
# @param [Numeric] y4
|
79
|
+
# @param [Color, Color::Set] color (or +colour+) Set one or per-vertex colour
|
80
|
+
def fill_quad(x1:, y1:, x2:, y2:, x3:, y3:, x4:, y4:, color: nil, colour: nil)
|
81
|
+
fill_polygon coordinates: [x1, y1, x2, y2, x3, y3, x4, y4], color: color || colour
|
82
|
+
end
|
83
|
+
|
84
|
+
# Draw a circle.
|
85
|
+
# @param [Numeric] x Centre
|
86
|
+
# @param [Numeric] y Centre
|
87
|
+
# @param [Numeric] radius
|
88
|
+
# @param [Numeric] sectors The number of segments to subdivide the circumference.
|
89
|
+
# @param [Numeric] stroke_width The thickness of the circle in pixels
|
90
|
+
# @param [Color] color (or +colour+) The fill colour
|
91
|
+
def draw_circle(x:, y:, radius:, sectors: 30, stroke_width: 1, color: nil, colour: nil)
|
92
|
+
clr = color || colour
|
93
|
+
clr = Color.new(clr) unless clr.is_a? Color
|
94
|
+
ext_draw_ellipse([
|
95
|
+
x, y, radius, radius, sectors, stroke_width,
|
96
|
+
clr.r, clr.g, clr.b, clr.a
|
97
|
+
])
|
98
|
+
update_texture if @update
|
99
|
+
end
|
100
|
+
|
101
|
+
# Draw an ellipse
|
102
|
+
# @param [Numeric] x Centre
|
103
|
+
# @param [Numeric] y Centre
|
104
|
+
# @param [Numeric] xradius
|
105
|
+
# @param [Numeric] yradius
|
106
|
+
# @param [Numeric] sectors The number of segments to subdivide the circumference.
|
107
|
+
# @param [Numeric] stroke_width The thickness of the circle in pixels
|
108
|
+
# @param [Color] color (or +colour+) The fill colour
|
109
|
+
def draw_ellipse(x:, y:, xradius:, yradius:, sectors: 30, stroke_width: 1, color: nil, colour: nil)
|
110
|
+
clr = color || colour
|
111
|
+
clr = Color.new(clr) unless clr.is_a? Color
|
112
|
+
ext_draw_ellipse([
|
113
|
+
x, y, xradius, yradius, sectors, stroke_width,
|
114
|
+
clr.r, clr.g, clr.b, clr.a
|
115
|
+
])
|
116
|
+
update_texture if @update
|
117
|
+
end
|
118
|
+
|
119
|
+
# Draw a filled circle.
|
120
|
+
# @param [Numeric] x Centre
|
121
|
+
# @param [Numeric] y Centre
|
122
|
+
# @param [Numeric] radius
|
123
|
+
# @param [Numeric] sectors The number of segments to subdivide the circumference.
|
124
|
+
# @param [Color] color (or +colour+) The fill colour
|
125
|
+
def fill_circle(x:, y:, radius:, sectors: 30, color: nil, colour: nil)
|
126
|
+
clr = color || colour
|
127
|
+
clr = Color.new(clr) unless clr.is_a? Color
|
128
|
+
ext_fill_ellipse([
|
129
|
+
x, y, radius, radius, sectors,
|
130
|
+
clr.r, clr.g, clr.b, clr.a
|
131
|
+
])
|
132
|
+
update_texture if @update
|
133
|
+
end
|
134
|
+
|
135
|
+
# Draw a filled ellipse.
|
136
|
+
# @param [Numeric] x Centre
|
137
|
+
# @param [Numeric] y Centre
|
138
|
+
# @param [Numeric] xradius
|
139
|
+
# @param [Numeric] yradius
|
140
|
+
# @param [Numeric] sectors The number of segments to subdivide the circumference.
|
141
|
+
# @param [Color] color (or +colour+) The fill colour
|
142
|
+
def fill_ellipse(x:, y:, xradius:, yradius:, sectors: 30, color: nil, colour: nil)
|
143
|
+
clr = color || colour
|
144
|
+
clr = Color.new(clr) unless clr.is_a? Color
|
145
|
+
ext_fill_ellipse([
|
146
|
+
x, y, xradius, yradius, sectors,
|
147
|
+
clr.r, clr.g, clr.b, clr.a
|
148
|
+
])
|
149
|
+
update_texture if @update
|
150
|
+
end
|
151
|
+
|
152
|
+
# Draw a filled rectangle.
|
153
|
+
# @param [Numeric] x
|
154
|
+
# @param [Numeric] y
|
155
|
+
# @param [Numeric] width
|
156
|
+
# @param [Numeric] height
|
157
|
+
# @param [Color] color (or +colour+) The fill colour
|
158
|
+
def fill_rectangle(x:, y:, width:, height:, color: nil, colour: nil)
|
159
|
+
clr = color || colour
|
160
|
+
clr = Color.new(clr) unless clr.is_a? Color
|
161
|
+
ext_fill_rectangle([
|
162
|
+
x, y, width, height,
|
163
|
+
clr.r, clr.g, clr.b, clr.a
|
164
|
+
])
|
165
|
+
update_texture if @update
|
166
|
+
end
|
167
|
+
|
168
|
+
# Draw an outline of a triangle.
|
169
|
+
# @param [Numeric] x1
|
170
|
+
# @param [Numeric] y1
|
171
|
+
# @param [Numeric] x2
|
172
|
+
# @param [Numeric] y2
|
173
|
+
# @param [Numeric] x3
|
174
|
+
# @param [Numeric] y3
|
175
|
+
# @param [Numeric] stroke_width The thickness of the rectangle in pixels
|
176
|
+
# @param [Color] color (or +colour+) The line colour
|
177
|
+
def draw_triangle(x1:, y1:, x2:, y2:, x3:, y3:, stroke_width: 1, color: nil, colour: nil)
|
178
|
+
draw_polyline closed: true,
|
179
|
+
coordinates: [x1, y1, x2, y2, x3, y3],
|
180
|
+
color: color, colour: colour, stroke_width: stroke_width
|
181
|
+
end
|
182
|
+
|
183
|
+
# Draw an outline of a quad.
|
184
|
+
# @param [Numeric] x1
|
185
|
+
# @param [Numeric] y1
|
186
|
+
# @param [Numeric] x2
|
187
|
+
# @param [Numeric] y2
|
188
|
+
# @param [Numeric] x3
|
189
|
+
# @param [Numeric] y3
|
190
|
+
# @param [Numeric] x4
|
191
|
+
# @param [Numeric] y4
|
192
|
+
# @param [Numeric] stroke_width The thickness of the rectangle in pixels
|
193
|
+
# @param [Color] color (or +colour+) The line colour
|
194
|
+
def draw_quad(x1:, y1:, x2:, y2:, x3:, y3:, x4:, y4:, stroke_width: 1, color: nil, colour: nil)
|
195
|
+
draw_polyline closed: true,
|
196
|
+
coordinates: [x1, y1, x2, y2, x3, y3, x4, y4],
|
197
|
+
color: color, colour: colour, stroke_width: stroke_width
|
198
|
+
end
|
199
|
+
|
200
|
+
# Draw an outline of a rectangle
|
201
|
+
# @param [Numeric] x
|
202
|
+
# @param [Numeric] y
|
203
|
+
# @param [Numeric] width
|
204
|
+
# @param [Numeric] height
|
205
|
+
# @param [Numeric] stroke_width The thickness of the rectangle in pixels
|
206
|
+
# @param [Color] color (or +colour+) The line colour
|
207
|
+
def draw_rectangle(x:, y:, width:, height:, stroke_width: 1, color: nil, colour: nil)
|
208
|
+
clr = color || colour
|
209
|
+
clr = Color.new(clr) unless clr.is_a? Color
|
210
|
+
ext_draw_rectangle([
|
211
|
+
x, y, width, height, stroke_width,
|
212
|
+
clr.r, clr.g, clr.b, clr.a
|
213
|
+
])
|
214
|
+
update_texture if @update
|
215
|
+
end
|
216
|
+
|
217
|
+
# Draw a straight line between two points
|
218
|
+
# @param [Numeric] x1
|
219
|
+
# @param [Numeric] y1
|
220
|
+
# @param [Numeric] x2
|
221
|
+
# @param [Numeric] y2
|
222
|
+
# @param [Numeric] stroke_width The line's thickness in pixels; defaults to 1.
|
223
|
+
# @param [Color] color (or +colour+) The line colour
|
224
|
+
def draw_line(x1:, y1:, x2:, y2:, stroke_width: 1, color: nil, colour: nil)
|
225
|
+
clr = color || colour
|
226
|
+
clr = Color.new(clr) unless clr.is_a? Color
|
227
|
+
ext_draw_line([
|
228
|
+
x1, y1, x2, y2, stroke_width,
|
229
|
+
clr.r, clr.g, clr.b, clr.a
|
230
|
+
])
|
231
|
+
update_texture if @update
|
232
|
+
end
|
233
|
+
|
234
|
+
# Draw a poly-line between N points.
|
235
|
+
# @param [Array] coordinates An array of numbers x1, y1, x2, y2 ... with at least three coordinates (6 values)
|
236
|
+
# @param [Numeric] stroke_width The line's thickness in pixels; defaults to 1.
|
237
|
+
# @param [Color] color (or +colour+) The line colour
|
238
|
+
# @param [Boolean] closed Use +true+ to draw this as a closed shape
|
239
|
+
def draw_polyline(coordinates:, stroke_width: 1, color: nil, colour: nil, closed: false)
|
240
|
+
return if coordinates.nil? || coordinates.count < 6
|
241
|
+
|
242
|
+
clr = color || colour
|
243
|
+
clr = Color.new(clr) unless clr.is_a? Color
|
244
|
+
config = [stroke_width, clr.r, clr.g, clr.b, clr.a]
|
245
|
+
if closed
|
246
|
+
ext_draw_polygon(config, coordinates)
|
247
|
+
else
|
248
|
+
ext_draw_polyline(config, coordinates)
|
249
|
+
end
|
250
|
+
update_texture if @update
|
251
|
+
end
|
252
|
+
|
253
|
+
# Fill a polygon made up of N points.
|
254
|
+
# @note Currently only supports convex polygons or simple polygons with one concave corner.
|
255
|
+
# @note Supports per-vertex coloring, but the triangulation may change and affect the coloring.
|
256
|
+
# @param [Array] coordinates An array of numbers x1, y1, x2, y2 ... with at least three coordinates (6 values)
|
257
|
+
# @param [Color, Color::Set] color (or +colour+) Set one or per-vertex colour; at least one colour must be specified.
|
258
|
+
def fill_polygon(coordinates:, color: nil, colour: nil)
|
259
|
+
return if coordinates.nil? || coordinates.count < 6 || (color.nil? && colour.nil?)
|
260
|
+
|
261
|
+
colors = colors_to_a(color || colour)
|
262
|
+
ext_fill_polygon(coordinates, colors)
|
263
|
+
update_texture if @update
|
264
|
+
end
|
265
|
+
|
266
|
+
# Draw the pixmap at the specified location and size
|
267
|
+
#
|
268
|
+
# @note This API will evolve to be able to draw a portion of the pixmap; coming soon.
|
269
|
+
# @param [Pixmap] pixmap
|
270
|
+
# @param [Numeric] x
|
271
|
+
# @param [Numeric] y
|
272
|
+
# @param [Numeric] width Optional, specify to scale the size
|
273
|
+
# @param [Numeric] height Optional, specify to scale the size
|
274
|
+
# @param [Hash] crop Optional, specify a hash with `x:, y:, width:, height:` to crop from within the pixmap to draw.
|
275
|
+
def draw_pixmap(pixmap, x:, y:, width: nil, height: nil, crop: nil)
|
276
|
+
src_rect = crop ? [crop[:x], crop[:y], crop[:width], crop[:height]] : nil
|
277
|
+
ext_draw_pixmap pixmap, src_rect, x, y, width, height
|
278
|
+
end
|
279
|
+
|
280
|
+
def update
|
281
|
+
update_texture
|
282
|
+
end
|
283
|
+
|
284
|
+
private
|
285
|
+
|
286
|
+
# Converts +color_or_set+ as a sequence of colour components; e.g. +[ r1, g1, b1, a1, ...]+
|
287
|
+
# @param [Color, Color::Set] color_or_set
|
288
|
+
# @return an array of r, g, b, a values
|
289
|
+
def colors_to_a(color_or_set)
|
290
|
+
if color_or_set.is_a? Color::Set
|
291
|
+
color_a = []
|
292
|
+
color_or_set.each do |clr|
|
293
|
+
color_a << clr.r << clr.g << clr.b << clr.a
|
294
|
+
end
|
295
|
+
return color_a
|
296
|
+
end
|
297
|
+
|
298
|
+
color_or_set = Color.new(color_or_set) unless color_or_set.is_a? Color
|
299
|
+
color_or_set.to_a
|
300
|
+
end
|
301
|
+
|
302
|
+
def update_texture
|
303
|
+
@texture.delete
|
304
|
+
@texture = Texture.new(@ext_pixel_data, @width, @height)
|
305
|
+
end
|
306
|
+
|
307
|
+
def render(x: @x, y: @y, width: @width, height: @height, color: @color, rotate: @rotate)
|
308
|
+
vertices = Vertices.new(x, y, width, height, rotate)
|
309
|
+
|
310
|
+
@texture.draw(
|
311
|
+
vertices.coordinates, vertices.texture_coordinates, color
|
312
|
+
)
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
data/lib/ruby2d/circle.rb
CHANGED
@@ -1,22 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Ruby2D::Circle
|
2
4
|
|
3
5
|
module Ruby2D
|
6
|
+
#
|
7
|
+
# Create a circle using +Circle.new+
|
8
|
+
#
|
4
9
|
class Circle
|
5
10
|
include Renderable
|
6
11
|
|
7
12
|
attr_accessor :x, :y, :radius, :sectors
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
# Create a circle
|
15
|
+
#
|
16
|
+
# @param [Numeric] x
|
17
|
+
# @param [Numeric] y
|
18
|
+
# @param [Numeric] z
|
19
|
+
# @param [Numeric] radius
|
20
|
+
# @param [Numeric] sectors Smoothness of the circle is better when more +sectors+ are used.
|
21
|
+
# @param [String | Color] color Or +colour+
|
22
|
+
# @param [Float] opacity
|
23
|
+
def initialize(x: 25, y: 25, z: 0, radius: 50, sectors: 30,
|
24
|
+
color: nil, colour: nil, opacity: nil)
|
25
|
+
@x = x
|
26
|
+
@y = y
|
27
|
+
@z = z
|
28
|
+
@radius = radius
|
29
|
+
@sectors = sectors
|
30
|
+
self.color = color || colour || 'white'
|
31
|
+
self.color.opacity = opacity unless opacity.nil?
|
17
32
|
add
|
18
33
|
end
|
19
34
|
|
35
|
+
# Check if the circle contains the point at +(x, y)+
|
20
36
|
def contains?(x, y)
|
21
37
|
Math.sqrt((x - @x)**2 + (y - @y)**2) <= @radius
|
22
38
|
end
|
@@ -25,19 +41,18 @@ module Ruby2D
|
|
25
41
|
Window.render_ready_check
|
26
42
|
|
27
43
|
ext_draw([
|
28
|
-
|
29
|
-
|
30
|
-
|
44
|
+
opts[:x], opts[:y], opts[:radius], opts[:sectors],
|
45
|
+
opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
|
46
|
+
])
|
31
47
|
end
|
32
48
|
|
33
49
|
private
|
34
50
|
|
35
51
|
def render
|
36
52
|
self.class.ext_draw([
|
37
|
-
|
38
|
-
|
39
|
-
|
53
|
+
@x, @y, @radius, @sectors,
|
54
|
+
@color.r, @color.g, @color.b, @color.a
|
55
|
+
])
|
40
56
|
end
|
41
|
-
|
42
57
|
end
|
43
58
|
end
|
data/lib/ruby2d/cli/build.rb
CHANGED
@@ -14,7 +14,6 @@ require 'ruby2d/cli/platform'
|
|
14
14
|
'color',
|
15
15
|
'window',
|
16
16
|
'dsl',
|
17
|
-
'entity',
|
18
17
|
'quad',
|
19
18
|
'line',
|
20
19
|
'circle',
|
@@ -22,11 +21,14 @@ require 'ruby2d/cli/platform'
|
|
22
21
|
'square',
|
23
22
|
'triangle',
|
24
23
|
'pixel',
|
24
|
+
'pixmap',
|
25
|
+
'pixmap_atlas',
|
25
26
|
'image',
|
26
27
|
'sprite',
|
27
28
|
'tileset',
|
28
29
|
'font',
|
29
30
|
'text',
|
31
|
+
'canvas',
|
30
32
|
'sound',
|
31
33
|
'music',
|
32
34
|
'texture',
|
@@ -161,7 +163,7 @@ def compile_native
|
|
161
163
|
|
162
164
|
ld_flags = ''
|
163
165
|
['mruby', 'SDL2', 'SDL2_image', 'SDL2_mixer', 'SDL2_ttf',
|
164
|
-
'jpeg', '
|
166
|
+
'jpeg', 'jxl', 'avif', 'png', 'tiff', 'webp',
|
165
167
|
'mpg123', 'ogg', 'FLAC', 'vorbis', 'vorbisfile', 'modplug',
|
166
168
|
'freetype', 'harfbuzz', 'graphite2'].each do |name|
|
167
169
|
add_ld_flags(ld_flags, name, :archive, ld_dir)
|
@@ -188,7 +190,7 @@ def compile_native
|
|
188
190
|
ld_flags = '-static -Wl,--start-group '
|
189
191
|
['mruby',
|
190
192
|
'SDL2',
|
191
|
-
'SDL2_image', 'jpeg', '
|
193
|
+
'SDL2_image', 'jpeg', 'png', 'tiff', 'webp', 'jxl', 'hwy', 'jbig', 'deflate', 'lzma', 'zstd', 'Lerc',
|
192
194
|
'SDL2_mixer', 'mpg123', 'FLAC', 'vorbis', 'vorbisfile', 'ogg', 'modplug', 'opus', 'opusfile', 'sndfile',
|
193
195
|
'SDL2_ttf', 'freetype', 'harfbuzz', 'graphite2', 'bz2', 'brotlicommon', 'brotlidec',
|
194
196
|
'glew32', 'stdc++', 'z', 'ssp'
|