ruby2d 0.9.5 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/assets/include/SDL2/SDL.h +4 -1
  3. data/assets/include/SDL2/SDL_assert.h +3 -1
  4. data/assets/include/SDL2/SDL_atomic.h +1 -1
  5. data/assets/include/SDL2/SDL_audio.h +1 -1
  6. data/assets/include/SDL2/SDL_bits.h +1 -1
  7. data/assets/include/SDL2/SDL_blendmode.h +4 -1
  8. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  9. data/assets/include/SDL2/SDL_config.h +1 -1
  10. data/assets/include/SDL2/SDL_config_android.h +7 -3
  11. data/assets/include/SDL2/SDL_config_iphoneos.h +16 -10
  12. data/assets/include/SDL2/SDL_config_macosx.h +40 -14
  13. data/assets/include/SDL2/SDL_config_minimal.h +1 -1
  14. data/assets/include/SDL2/SDL_config_os2.h +26 -8
  15. data/assets/include/SDL2/SDL_config_pandora.h +4 -2
  16. data/assets/include/SDL2/SDL_config_psp.h +2 -1
  17. data/assets/include/SDL2/SDL_config_windows.h +40 -9
  18. data/assets/include/SDL2/SDL_config_winrt.h +5 -2
  19. data/assets/include/SDL2/SDL_config_wiz.h +5 -2
  20. data/assets/include/SDL2/SDL_copying.h +1 -1
  21. data/assets/include/SDL2/SDL_cpuinfo.h +32 -3
  22. data/assets/include/SDL2/SDL_egl.h +4 -1
  23. data/assets/include/SDL2/SDL_endian.h +6 -3
  24. data/assets/include/SDL2/SDL_error.h +38 -2
  25. data/assets/include/SDL2/SDL_events.h +64 -28
  26. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  27. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  28. data/assets/include/SDL2/SDL_gesture.h +1 -1
  29. data/assets/include/SDL2/SDL_haptic.h +10 -1
  30. data/assets/include/SDL2/SDL_hints.h +316 -4
  31. data/assets/include/SDL2/SDL_joystick.h +115 -24
  32. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  33. data/assets/include/SDL2/SDL_keycode.h +11 -9
  34. data/assets/include/SDL2/SDL_loadso.h +1 -1
  35. data/assets/include/SDL2/SDL_locale.h +101 -0
  36. data/assets/include/SDL2/SDL_log.h +3 -3
  37. data/assets/include/SDL2/SDL_main.h +1 -1
  38. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  39. data/assets/include/SDL2/SDL_metal.h +117 -0
  40. data/assets/include/SDL2/SDL_misc.h +75 -0
  41. data/assets/include/SDL2/SDL_mouse.h +1 -1
  42. data/assets/include/SDL2/SDL_mutex.h +1 -1
  43. data/assets/include/SDL2/SDL_name.h +1 -1
  44. data/assets/include/SDL2/SDL_opengl.h +1 -1
  45. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  46. data/assets/include/SDL2/SDL_opengles.h +1 -1
  47. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  48. data/assets/include/SDL2/SDL_pixels.h +25 -16
  49. data/assets/include/SDL2/SDL_platform.h +1 -1
  50. data/assets/include/SDL2/SDL_power.h +1 -1
  51. data/assets/include/SDL2/SDL_quit.h +1 -1
  52. data/assets/include/SDL2/SDL_rect.h +1 -1
  53. data/assets/include/SDL2/SDL_render.h +63 -3
  54. data/assets/include/SDL2/SDL_revision.h +2 -2
  55. data/assets/include/SDL2/SDL_rwops.h +2 -10
  56. data/assets/include/SDL2/SDL_scancode.h +1 -1
  57. data/assets/include/SDL2/SDL_sensor.h +25 -9
  58. data/assets/include/SDL2/SDL_shape.h +1 -1
  59. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  60. data/assets/include/SDL2/SDL_surface.h +11 -2
  61. data/assets/include/SDL2/SDL_system.h +50 -4
  62. data/assets/include/SDL2/SDL_syswm.h +29 -2
  63. data/assets/include/SDL2/SDL_test.h +1 -1
  64. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  65. data/assets/include/SDL2/SDL_test_common.h +14 -1
  66. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  67. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  68. data/assets/include/SDL2/SDL_test_font.h +1 -1
  69. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  70. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  71. data/assets/include/SDL2/SDL_test_images.h +1 -1
  72. data/assets/include/SDL2/SDL_test_log.h +1 -1
  73. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  74. data/assets/include/SDL2/SDL_test_memory.h +1 -1
  75. data/assets/include/SDL2/SDL_test_random.h +1 -1
  76. data/assets/include/SDL2/SDL_thread.h +34 -11
  77. data/assets/include/SDL2/SDL_timer.h +1 -1
  78. data/assets/include/SDL2/SDL_touch.h +1 -1
  79. data/assets/include/SDL2/SDL_types.h +1 -1
  80. data/assets/include/SDL2/SDL_version.h +2 -2
  81. data/assets/include/SDL2/SDL_video.h +11 -5
  82. data/assets/include/SDL2/SDL_vulkan.h +6 -8
  83. data/assets/include/SDL2/begin_code.h +5 -9
  84. data/assets/include/SDL2/close_code.h +1 -1
  85. data/assets/macos/lib/libFLAC.a +0 -0
  86. data/assets/macos/lib/libSDL2.a +0 -0
  87. data/assets/macos/lib/libSDL2_image.a +0 -0
  88. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  89. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  90. data/assets/macos/lib/libfreetype.a +0 -0
  91. data/assets/macos/lib/libjpeg.a +0 -0
  92. data/assets/macos/lib/libmpg123.a +0 -0
  93. data/assets/macos/lib/libogg.a +0 -0
  94. data/assets/macos/lib/libpng16.a +0 -0
  95. data/assets/macos/lib/libtiff.a +0 -0
  96. data/assets/macos/lib/libvorbis.a +0 -0
  97. data/assets/macos/lib/libvorbisfile.a +0 -0
  98. data/assets/macos/lib/libwebp.a +0 -0
  99. data/assets/mingw/bin/SDL2.dll +0 -0
  100. data/assets/mingw/lib/libSDL2.a +0 -0
  101. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  102. data/assets/mingw/lib/libSDL2_test.a +0 -0
  103. data/assets/mingw/lib/libSDL2main.a +0 -0
  104. data/ext/ruby2d/extconf.rb +1 -1
  105. data/ext/ruby2d/gl.c +17 -0
  106. data/ext/ruby2d/gl2.c +15 -0
  107. data/ext/ruby2d/gl3.c +15 -0
  108. data/ext/ruby2d/gles.c +15 -0
  109. data/ext/ruby2d/music.c +13 -0
  110. data/ext/ruby2d/ruby2d.c +306 -168
  111. data/ext/ruby2d/ruby2d.h +32 -0
  112. data/ext/ruby2d/sound.c +25 -0
  113. data/ext/ruby2d/tileset.c +30 -0
  114. data/lib/ruby2d.rb +4 -1
  115. data/lib/ruby2d/circle.rb +18 -2
  116. data/lib/ruby2d/dsl.rb +16 -9
  117. data/lib/ruby2d/entity.rb +17 -0
  118. data/lib/ruby2d/font.rb +4 -3
  119. data/lib/ruby2d/image.rb +24 -1
  120. data/lib/ruby2d/line.rb +20 -0
  121. data/lib/ruby2d/music.rb +5 -0
  122. data/lib/ruby2d/pixel.rb +17 -0
  123. data/lib/ruby2d/quad.rb +18 -0
  124. data/lib/ruby2d/rectangle.rb +11 -2
  125. data/lib/ruby2d/renderable.rb +4 -8
  126. data/lib/ruby2d/sound.rb +5 -0
  127. data/lib/ruby2d/sprite.rb +35 -3
  128. data/lib/ruby2d/square.rb +9 -0
  129. data/lib/ruby2d/text.rb +22 -1
  130. data/lib/ruby2d/tileset.rb +69 -0
  131. data/lib/ruby2d/triangle.rb +16 -0
  132. data/lib/ruby2d/version.rb +1 -1
  133. data/lib/ruby2d/window.rb +249 -22
  134. metadata +10 -3
data/ext/ruby2d/ruby2d.h CHANGED
@@ -341,6 +341,7 @@ typedef struct {
341
341
  typedef struct {
342
342
  const char *path;
343
343
  Mix_Music *data;
344
+ int length; // Length of music track
344
345
  } R2D_Music;
345
346
 
346
347
  // Ruby 2D Functions ///////////////////////////////////////////////////////////
@@ -497,6 +498,13 @@ void R2D_DrawSprite(R2D_Sprite *spr);
497
498
  */
498
499
  void R2D_FreeSprite(R2D_Sprite *spr);
499
500
 
501
+ // Tile ////////////////////////////////////////////////////////////////////////
502
+
503
+ /*
504
+ * Draw a tile
505
+ */
506
+ void R2D_DrawTile(R2D_Image *img, int tw, int th, int padding, int spacing, int tx, int ty, int x, int y);
507
+
500
508
  // Text ////////////////////////////////////////////////////////////////////////
501
509
 
502
510
  /*
@@ -536,6 +544,11 @@ R2D_Sound *R2D_CreateSound(const char *path);
536
544
  */
537
545
  void R2D_PlaySound(R2D_Sound *snd);
538
546
 
547
+ /*
548
+ * Get the sound's length
549
+ */
550
+ int R2D_GetSoundLength(R2D_Sound *snd);
551
+
539
552
  /*
540
553
  * Get the sound's volume
541
554
  */
@@ -603,6 +616,11 @@ void R2D_SetMusicVolume(int volume);
603
616
  */
604
617
  void R2D_FadeOutMusic(int ms);
605
618
 
619
+ /*
620
+ * Get the length of the music in seconds
621
+ */
622
+ int R2D_GetMusicLength(R2D_Music *mus);
623
+
606
624
  /*
607
625
  * Free the music
608
626
  */
@@ -704,6 +722,8 @@ void R2D_GL_DrawTriangle(
704
722
  GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3);
705
723
  void R2D_GL_DrawImage(R2D_Image *img);
706
724
  void R2D_GL_DrawSprite(R2D_Sprite *spr);
725
+ void R2D_GL_DrawTile(R2D_Image *img, int x, int y, int tw, int th, GLfloat tx1, GLfloat ty1, GLfloat tx2,
726
+ GLfloat ty2, GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4);
707
727
  void R2D_GL_DrawText(R2D_Text *txt);
708
728
  void R2D_GL_FreeTexture(GLuint *id);
709
729
  void R2D_GL_Clear(R2D_Color clr);
@@ -723,6 +743,10 @@ void R2D_GL_FlushBuffers();
723
743
  GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3);
724
744
  void R2D_GLES_DrawImage(R2D_Image *img);
725
745
  void R2D_GLES_DrawSprite(R2D_Sprite *spr);
746
+ void R2D_GLES_DrawTile(R2D_Image *img, int x, int y,
747
+ int tw, int th,
748
+ GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
749
+ GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4);
726
750
  void R2D_GLES_DrawText(R2D_Text *txt);
727
751
  #else
728
752
  int R2D_GL2_Init();
@@ -747,6 +771,14 @@ void R2D_GL_FlushBuffers();
747
771
  void R2D_GL3_DrawImage(R2D_Image *img);
748
772
  void R2D_GL2_DrawSprite(R2D_Sprite *spr);
749
773
  void R2D_GL3_DrawSprite(R2D_Sprite *spr);
774
+ void R2D_GL2_DrawTile(R2D_Image *img, int x, int y,
775
+ int tw, int th,
776
+ GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
777
+ GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4);
778
+ void R2D_GL3_DrawTile(R2D_Image *img, int x, int y,
779
+ int tw, int th,
780
+ GLfloat tx1, GLfloat ty1, GLfloat tx2, GLfloat ty2,
781
+ GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4);
750
782
  void R2D_GL2_DrawText(R2D_Text *txt);
751
783
  void R2D_GL3_DrawText(R2D_Text *txt);
752
784
  void R2D_GL3_FlushBuffers();
data/ext/ruby2d/sound.c CHANGED
@@ -46,6 +46,31 @@ void R2D_PlaySound(R2D_Sound *snd) {
46
46
  }
47
47
 
48
48
 
49
+ /*
50
+ * Get the sound's length in seconds
51
+ */
52
+ int R2D_GetSoundLength(R2D_Sound *snd) {
53
+ float points = 0;
54
+ float frames = 0;
55
+ int frequency = 0;
56
+ Uint16 format = 0;
57
+ int channels = 0;
58
+
59
+ // Populate the frequency, format and channel variables
60
+ if (!Mix_QuerySpec(&frequency, &format, &channels)) return -1; // Querying audio deails failed
61
+ if (!snd) return -1;
62
+
63
+ // points = bytes / samplesize
64
+ points = (snd->data->alen / ((format & 0xFF) / 8));
65
+
66
+ // frames = sample points / channels
67
+ frames = (points / channels);
68
+
69
+ // frames / frequency is seconds of audio
70
+ return ceil(frames / frequency);
71
+ }
72
+
73
+
49
74
  /*
50
75
  * Get the sound's volume
51
76
  */
@@ -0,0 +1,30 @@
1
+ // tileset.c
2
+
3
+ #include "ruby2d.h"
4
+
5
+
6
+ /*
7
+ * Draw a tile
8
+ */
9
+ void R2D_DrawTile(R2D_Image *img, int tw, int th, int padding, int spacing, int tx, int ty, int x, int y) {
10
+ if (!img) return;
11
+
12
+ if (img->texture_id == 0) {
13
+ R2D_GL_CreateTexture(&img->texture_id, img->format,
14
+ img->width, img->height,
15
+ img->surface->pixels, GL_NEAREST);
16
+ SDL_FreeSurface(img->surface);
17
+ }
18
+
19
+ GLfloat tx1 = (double)(padding + ((spacing + tw) * tx)) / (double) img->width ;
20
+ GLfloat tx2 = tx1 + ((double)tw / (double) img->width);
21
+ GLfloat tx3 = tx2;
22
+ GLfloat tx4 = tx1;
23
+
24
+ GLfloat ty1 = (double)(padding + ((spacing + th) * ty)) / (double) img ->height;
25
+ GLfloat ty2 = ty1;
26
+ GLfloat ty3 = ty1 + ((double)th / (double) img->height);
27
+ GLfloat ty4 = ty3;
28
+
29
+ R2D_GL_DrawTile(img, x, y, tw, th, tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4);
30
+ }
data/lib/ruby2d.rb CHANGED
@@ -7,20 +7,23 @@ unless RUBY_ENGINE == 'mruby'
7
7
  require 'ruby2d/color'
8
8
  require 'ruby2d/window'
9
9
  require 'ruby2d/dsl'
10
+ require 'ruby2d/entity'
10
11
  require 'ruby2d/quad'
11
12
  require 'ruby2d/line'
12
13
  require 'ruby2d/circle'
13
14
  require 'ruby2d/rectangle'
14
15
  require 'ruby2d/square'
15
16
  require 'ruby2d/triangle'
17
+ require 'ruby2d/pixel'
16
18
  require 'ruby2d/image'
17
19
  require 'ruby2d/sprite'
20
+ require 'ruby2d/tileset'
18
21
  require 'ruby2d/font'
19
22
  require 'ruby2d/text'
20
23
  require 'ruby2d/sound'
21
24
  require 'ruby2d/music'
22
25
 
23
- if RUBY_PLATFORM =~ /mingw/
26
+ if defined?(RubyInstaller)
24
27
  s2d_dll_path = Gem::Specification.find_by_name('ruby2d').gem_dir + '/assets/mingw/bin'
25
28
  RubyInstaller::Runtime.add_dll_directory(File.expand_path(s2d_dll_path))
26
29
  end
data/lib/ruby2d/circle.rb CHANGED
@@ -10,8 +10,8 @@ module Ruby2D
10
10
  @x = opts[:x] || 25
11
11
  @y = opts[:y] || 25
12
12
  @z = opts[:z] || 0
13
- @radius = opts[:radius] || 25
14
- @sectors = opts[:sectors] || 20
13
+ @radius = opts[:radius] || 50
14
+ @sectors = opts[:sectors] || 30
15
15
  self.color = opts[:color] || 'white'
16
16
  self.opacity = opts[:opacity] if opts[:opacity]
17
17
  add
@@ -21,5 +21,21 @@ module Ruby2D
21
21
  Math.sqrt((x - @x)**2 + (y - @y)**2) <= @radius
22
22
  end
23
23
 
24
+ def self.draw(opts = {})
25
+ ext_draw([
26
+ opts[:x], opts[:y], opts[:radius], opts[:sectors],
27
+ opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
28
+ ])
29
+ end
30
+
31
+ private
32
+
33
+ def render
34
+ self.class.ext_draw([
35
+ @x, @y, @radius, @sectors,
36
+ @color.r, @color.g, @color.b, @color.a
37
+ ])
38
+ end
39
+
24
40
  end
25
41
  end
data/lib/ruby2d/dsl.rb CHANGED
@@ -2,38 +2,45 @@
2
2
 
3
3
  module Ruby2D::DSL
4
4
 
5
- Ruby2D::Window.new
5
+ @window = Ruby2D::Window.new
6
+
7
+ def self.window; @window end
8
+ def self.window=(w); @window = w end
6
9
 
7
10
  def get(sym, opts = nil)
8
- Window.get(sym, opts)
11
+ DSL.window.get(sym, opts)
9
12
  end
10
13
 
11
14
  def set(opts)
12
- Window.set(opts)
15
+ DSL.window.set(opts)
13
16
  end
14
17
 
15
18
  def on(event, &proc)
16
- Window.on(event, &proc)
19
+ DSL.window.on(event, &proc)
17
20
  end
18
21
 
19
22
  def off(event_descriptor)
20
- Window.off(event_descriptor)
23
+ DSL.window.off(event_descriptor)
21
24
  end
22
25
 
23
26
  def update(&proc)
24
- Window.update(&proc)
27
+ DSL.window.update(&proc)
28
+ end
29
+
30
+ def render(&proc)
31
+ DSL.window.render(&proc)
25
32
  end
26
33
 
27
34
  def clear
28
- Window.clear
35
+ DSL.window.clear
29
36
  end
30
37
 
31
38
  def show
32
- Window.show
39
+ DSL.window.show
33
40
  end
34
41
 
35
42
  def close
36
- Window.close
43
+ DSL.window.close
37
44
  end
38
45
 
39
46
  end
@@ -0,0 +1,17 @@
1
+ # Ruby2D::Entity
2
+
3
+ module Ruby2D
4
+ class Entity
5
+
6
+ # Add the entity to the window
7
+ def add
8
+ Window.add(self)
9
+ end
10
+
11
+ # Remove the entity from the window
12
+ def remove
13
+ Window.remove(self)
14
+ end
15
+
16
+ end
17
+ end
data/lib/ruby2d/font.rb CHANGED
@@ -63,11 +63,12 @@ module Ruby2D
63
63
  end
64
64
  # If MRuby
65
65
  else
66
- if `uname`.include? 'Darwin' # macOS
66
+ uname = `uname`
67
+ if uname.include? 'Darwin' # macOS
67
68
  macos_font_path
68
- elsif `uname`.include? 'Linux'
69
+ elsif uname.include? 'Linux'
69
70
  linux_font_path
70
- elsif `uname`.include? 'MINGW'
71
+ elsif uname.include? 'MINGW'
71
72
  windows_font_path
72
73
  end
73
74
  end
data/lib/ruby2d/image.rb CHANGED
@@ -23,7 +23,30 @@ module Ruby2D
23
23
  unless ext_init(@path)
24
24
  raise Error, "Image `#{@path}` cannot be created"
25
25
  end
26
- add
26
+ unless opts[:show] == false then add end
27
+ end
28
+
29
+ def draw(opts = {})
30
+ opts[:width] = opts[:width] || @width
31
+ opts[:height] = opts[:height] || @height
32
+ opts[:rotate] = opts[:rotate] || @rotate
33
+ unless opts[:color]
34
+ opts[:color] = [1.0, 1.0, 1.0, 1.0]
35
+ end
36
+
37
+ self.class.ext_draw([
38
+ self, opts[:x], opts[:y], opts[:width], opts[:height], opts[:rotate],
39
+ opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
40
+ ])
41
+ end
42
+
43
+ private
44
+
45
+ def render
46
+ self.class.ext_draw([
47
+ self, @x, @y, @width, @height, @rotate,
48
+ @color.r, @color.g, @color.b, @color.a
49
+ ])
27
50
  end
28
51
 
29
52
  end
data/lib/ruby2d/line.rb CHANGED
@@ -38,8 +38,28 @@ module Ruby2D
38
38
  (((@y2 - @y1) * x - (@x2 - @x1) * y + @x2 * @y1 - @y2 * @x1).abs / length) <= 0.5 * @width
39
39
  end
40
40
 
41
+ def self.draw(opts = {})
42
+ ext_draw([
43
+ opts[:x1], opts[:y1], opts[:x2], opts[:y2], opts[:width],
44
+ opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
45
+ opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
46
+ opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
47
+ opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
48
+ ])
49
+ end
50
+
41
51
  private
42
52
 
53
+ def render
54
+ self.class.ext_draw([
55
+ @x1, @y1, @x2, @y2, @width,
56
+ @c1.r, @c1.g, @c1.b, @c1.a,
57
+ @c2.r, @c2.g, @c2.b, @c2.a,
58
+ @c3.r, @c3.g, @c3.b, @c3.a,
59
+ @c4.r, @c4.g, @c4.b, @c4.a
60
+ ])
61
+ end
62
+
43
63
  # Calculate the distance between two points
44
64
  def points_distance(x1, y1, x2, y2)
45
65
  Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
data/lib/ruby2d/music.rb CHANGED
@@ -58,5 +58,10 @@ module Ruby2D
58
58
  ext_fadeout(ms)
59
59
  end
60
60
 
61
+ # Returns the length in seconds
62
+ def length
63
+ ext_length
64
+ end
65
+
61
66
  end
62
67
  end
@@ -0,0 +1,17 @@
1
+ # Ruby2D::Pixel
2
+
3
+ module Ruby2D
4
+ class Pixel
5
+
6
+ def self.draw(opts = {})
7
+ ext_draw([
8
+ opts[:x] , opts[:y],
9
+ opts[:x] + opts[:size], opts[:y],
10
+ opts[:x] + opts[:size], opts[:y] + opts[:size],
11
+ opts[:x] , opts[:y] + opts[:size],
12
+ opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
13
+ ])
14
+ end
15
+
16
+ end
17
+ end
data/lib/ruby2d/quad.rb CHANGED
@@ -48,8 +48,26 @@ module Ruby2D
48
48
  questioned_area <= self_area
49
49
  end
50
50
 
51
+ def self.draw(opts = {})
52
+ ext_draw([
53
+ opts[:x1], opts[:y1], opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
54
+ opts[:x2], opts[:y2], opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
55
+ opts[:x3], opts[:y3], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
56
+ opts[:x4], opts[:y4], opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
57
+ ])
58
+ end
59
+
51
60
  private
52
61
 
62
+ def render
63
+ self.class.ext_draw([
64
+ @x1, @y1, @c1.r, @c1.g, @c1.b, @c1.a,
65
+ @x2, @y2, @c2.r, @c2.g, @c2.b, @c2.a,
66
+ @x3, @y3, @c3.r, @c3.g, @c3.b, @c3.a,
67
+ @x4, @y4, @c4.r, @c4.g, @c4.b, @c4.a
68
+ ])
69
+ end
70
+
53
71
  def triangle_area(x1, y1, x2, y2, x3, y3)
54
72
  (x1*y2 + x2*y3 + x3*y1 - x3*y2 - x1*y3 - x2*y1).abs / 2
55
73
  end
@@ -39,6 +39,15 @@ module Ruby2D
39
39
  update_coords(@x, @y, @width, h)
40
40
  end
41
41
 
42
+ def self.draw(opts = {})
43
+ ext_draw([
44
+ opts[:x] , opts[:y] , opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
45
+ opts[:x] + opts[:width], opts[:y] , opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
46
+ opts[:x] + opts[:width], opts[:y] + opts[:height], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
47
+ opts[:x] , opts[:y] + opts[:height], opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
48
+ ])
49
+ end
50
+
42
51
  private
43
52
 
44
53
  def update_coords(x, y, w, h)
@@ -46,10 +55,10 @@ module Ruby2D
46
55
  @y1 = y
47
56
  @x2 = x + w
48
57
  @y2 = y
49
- @x4 = x
50
- @y4 = y + h
51
58
  @x3 = x + w
52
59
  @y3 = y + h
60
+ @x4 = x
61
+ @y4 = y + h
53
62
  end
54
63
 
55
64
  end
@@ -14,16 +14,12 @@ module Ruby2D
14
14
 
15
15
  # Add the object to the window
16
16
  def add
17
- if Module.const_defined? :DSL
18
- Window.add(self)
19
- end
17
+ Window.add(self)
20
18
  end
21
19
 
22
20
  # Remove the object from the window
23
21
  def remove
24
- if Module.const_defined? :DSL
25
- Window.remove(self)
26
- end
22
+ Window.remove(self)
27
23
  end
28
24
 
29
25
  # Set the color value
@@ -32,8 +28,8 @@ module Ruby2D
32
28
  end
33
29
 
34
30
  # Allow British English spelling of color
35
- def colour; self.color end
36
- def colour=(c); self.color = c end
31
+ alias_method :colour, :color
32
+ alias_method :colour=, :color=
37
33
 
38
34
  # Allow shortcuts for setting color values
39
35
  def r; self.color.r end