ruby2d 0.9.3 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/assets/README.md +7 -9
  3. data/assets/Rakefile +85 -0
  4. data/assets/include/SDL2/SDL.h +4 -1
  5. data/assets/include/SDL2/SDL_assert.h +3 -1
  6. data/assets/include/SDL2/SDL_atomic.h +20 -2
  7. data/assets/include/SDL2/SDL_audio.h +47 -14
  8. data/assets/include/SDL2/SDL_bits.h +10 -1
  9. data/assets/include/SDL2/SDL_blendmode.h +10 -7
  10. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  11. data/assets/include/SDL2/SDL_config.h +24 -390
  12. data/assets/include/SDL2/SDL_config_android.h +182 -0
  13. data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
  14. data/assets/include/SDL2/SDL_config_macosx.h +266 -0
  15. data/assets/include/SDL2/SDL_config_minimal.h +85 -0
  16. data/assets/include/SDL2/SDL_config_os2.h +188 -0
  17. data/assets/include/SDL2/SDL_config_pandora.h +135 -0
  18. data/assets/include/SDL2/SDL_config_psp.h +165 -0
  19. data/assets/include/SDL2/SDL_config_windows.h +288 -0
  20. data/assets/include/SDL2/SDL_config_winrt.h +243 -0
  21. data/assets/include/SDL2/SDL_config_wiz.h +149 -0
  22. data/assets/include/SDL2/SDL_copying.h +20 -0
  23. data/assets/include/SDL2/SDL_cpuinfo.h +119 -8
  24. data/assets/include/SDL2/SDL_egl.h +4 -1
  25. data/assets/include/SDL2/SDL_endian.h +6 -3
  26. data/assets/include/SDL2/SDL_error.h +38 -2
  27. data/assets/include/SDL2/SDL_events.h +67 -28
  28. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  29. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  30. data/assets/include/SDL2/SDL_gesture.h +1 -1
  31. data/assets/include/SDL2/SDL_haptic.h +10 -1
  32. data/assets/include/SDL2/SDL_hints.h +460 -17
  33. data/assets/include/SDL2/SDL_image.h +2 -2
  34. data/assets/include/SDL2/SDL_joystick.h +115 -24
  35. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  36. data/assets/include/SDL2/SDL_keycode.h +11 -9
  37. data/assets/include/SDL2/SDL_loadso.h +1 -1
  38. data/assets/include/SDL2/SDL_locale.h +101 -0
  39. data/assets/include/SDL2/SDL_log.h +3 -3
  40. data/assets/include/SDL2/SDL_main.h +28 -16
  41. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  42. data/assets/include/SDL2/SDL_metal.h +117 -0
  43. data/assets/include/SDL2/SDL_misc.h +75 -0
  44. data/assets/include/SDL2/SDL_mouse.h +1 -1
  45. data/assets/include/SDL2/SDL_mutex.h +1 -1
  46. data/assets/include/SDL2/SDL_name.h +1 -1
  47. data/assets/include/SDL2/SDL_opengl.h +1 -1
  48. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  49. data/assets/include/SDL2/SDL_opengles.h +1 -1
  50. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  51. data/assets/include/SDL2/SDL_pixels.h +27 -18
  52. data/assets/include/SDL2/SDL_platform.h +1 -1
  53. data/assets/include/SDL2/SDL_power.h +1 -1
  54. data/assets/include/SDL2/SDL_quit.h +1 -1
  55. data/assets/include/SDL2/SDL_rect.h +29 -3
  56. data/assets/include/SDL2/SDL_render.h +230 -3
  57. data/assets/include/SDL2/SDL_revision.h +2 -2
  58. data/assets/include/SDL2/SDL_rwops.h +51 -22
  59. data/assets/include/SDL2/SDL_scancode.h +2 -2
  60. data/assets/include/SDL2/SDL_sensor.h +28 -12
  61. data/assets/include/SDL2/SDL_shape.h +1 -1
  62. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  63. data/assets/include/SDL2/SDL_surface.h +12 -2
  64. data/assets/include/SDL2/SDL_system.h +50 -4
  65. data/assets/include/SDL2/SDL_syswm.h +39 -9
  66. data/assets/include/SDL2/SDL_test.h +1 -1
  67. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  68. data/assets/include/SDL2/SDL_test_common.h +32 -2
  69. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  70. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  71. data/assets/include/SDL2/SDL_test_font.h +1 -1
  72. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  73. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  74. data/assets/include/SDL2/SDL_test_images.h +1 -1
  75. data/assets/include/SDL2/SDL_test_log.h +1 -1
  76. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  77. data/assets/include/SDL2/SDL_test_memory.h +3 -3
  78. data/assets/include/SDL2/SDL_test_random.h +1 -1
  79. data/assets/include/SDL2/SDL_thread.h +34 -11
  80. data/assets/include/SDL2/SDL_timer.h +1 -1
  81. data/assets/include/SDL2/SDL_touch.h +17 -1
  82. data/assets/include/SDL2/SDL_types.h +1 -1
  83. data/assets/include/SDL2/SDL_version.h +2 -2
  84. data/assets/include/SDL2/SDL_video.h +11 -5
  85. data/assets/include/SDL2/SDL_vulkan.h +9 -11
  86. data/assets/include/SDL2/begin_code.h +8 -9
  87. data/assets/include/SDL2/close_code.h +4 -1
  88. data/assets/macos/lib/libFLAC.a +0 -0
  89. data/assets/macos/lib/libSDL2.a +0 -0
  90. data/assets/macos/lib/libSDL2_image.a +0 -0
  91. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  92. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  93. data/assets/macos/lib/libfreetype.a +0 -0
  94. data/assets/macos/lib/libjpeg.a +0 -0
  95. data/assets/macos/lib/libmpg123.a +0 -0
  96. data/assets/macos/lib/libogg.a +0 -0
  97. data/assets/macos/lib/libpng16.a +0 -0
  98. data/assets/macos/lib/libtiff.a +0 -0
  99. data/assets/macos/lib/libvorbis.a +0 -0
  100. data/assets/macos/lib/libvorbisfile.a +0 -0
  101. data/assets/macos/lib/libwebp.a +0 -0
  102. data/assets/mingw/bin/SDL2.dll +0 -0
  103. data/assets/mingw/bin/SDL2_image.dll +0 -0
  104. data/assets/mingw/bin/libpng16-16.dll +0 -0
  105. data/assets/mingw/bin/libtiff-5.dll +0 -0
  106. data/assets/mingw/bin/libwebp-7.dll +0 -0
  107. data/assets/mingw/lib/libSDL2.a +0 -0
  108. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  109. data/assets/mingw/lib/libSDL2_image.a +0 -0
  110. data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
  111. data/assets/mingw/lib/libSDL2_test.a +0 -0
  112. data/assets/mingw/lib/libSDL2main.a +0 -0
  113. data/bin/ruby2d +1 -0
  114. data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
  115. data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
  116. data/ext/ruby2d/extconf.rb +36 -58
  117. data/ext/ruby2d/font.c +35 -0
  118. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +72 -100
  119. data/ext/ruby2d/gl2.c +86 -0
  120. data/ext/ruby2d/gl3.c +305 -0
  121. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +22 -81
  122. data/ext/ruby2d/image.c +58 -0
  123. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  124. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  125. data/ext/ruby2d/ruby2d.c +449 -439
  126. data/ext/ruby2d/ruby2d.h +652 -0
  127. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  128. data/ext/ruby2d/sound.c +118 -0
  129. data/ext/ruby2d/text.c +22 -0
  130. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +73 -62
  131. data/lib/ruby2d/circle.rb +21 -3
  132. data/lib/ruby2d/cli/build.rb +4 -7
  133. data/lib/ruby2d/dsl.rb +16 -9
  134. data/lib/ruby2d/entity.rb +17 -0
  135. data/lib/ruby2d/font.rb +23 -3
  136. data/lib/ruby2d/image.rb +35 -7
  137. data/lib/ruby2d/line.rb +23 -1
  138. data/lib/ruby2d/music.rb +5 -0
  139. data/lib/ruby2d/pixel.rb +17 -0
  140. data/lib/ruby2d/quad.rb +21 -1
  141. data/lib/ruby2d/rectangle.rb +12 -3
  142. data/lib/ruby2d/renderable.rb +4 -20
  143. data/lib/ruby2d/sound.rb +30 -0
  144. data/lib/ruby2d/sprite.rb +57 -75
  145. data/lib/ruby2d/square.rb +10 -1
  146. data/lib/ruby2d/text.rb +55 -12
  147. data/lib/ruby2d/texture.rb +28 -0
  148. data/lib/ruby2d/tileset.rb +87 -0
  149. data/lib/ruby2d/triangle.rb +19 -1
  150. data/lib/ruby2d/version.rb +1 -1
  151. data/lib/ruby2d/vertices.rb +84 -0
  152. data/lib/ruby2d/window.rb +259 -22
  153. data/lib/ruby2d.rb +6 -1
  154. metadata +41 -26
  155. data/assets/include/simple2d.h +0 -735
  156. data/assets/linux/simple2d/Makefile +0 -257
  157. data/assets/linux/simple2d/bin/simple2d.sh +0 -1312
  158. data/assets/linux/simple2d/include/simple2d.h +0 -735
  159. data/assets/linux/simple2d/src/gl2.c +0 -146
  160. data/assets/linux/simple2d/src/gl3.c +0 -275
  161. data/assets/linux/simple2d/src/image.c +0 -138
  162. data/assets/linux/simple2d/src/sound.c +0 -56
  163. data/assets/linux/simple2d/src/sprite.c +0 -147
  164. data/assets/linux/simple2d/src/text.c +0 -129
  165. data/assets/macos/lib/libsimple2d.a +0 -0
  166. data/assets/mingw/lib/libsimple2d.a +0 -0
data/lib/ruby2d/circle.rb CHANGED
@@ -10,10 +10,10 @@ 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
- self.opacity = opts[:opacity] if opts[:opacity]
16
+ self.color.opacity = opts[:opacity] if opts[:opacity]
17
17
  add
18
18
  end
19
19
 
@@ -21,5 +21,23 @@ module Ruby2D
21
21
  Math.sqrt((x - @x)**2 + (y - @y)**2) <= @radius
22
22
  end
23
23
 
24
+ def self.draw(opts = {})
25
+ Window.render_ready_check
26
+
27
+ ext_draw([
28
+ opts[:x], opts[:y], opts[:radius], opts[:sectors],
29
+ opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
30
+ ])
31
+ end
32
+
33
+ private
34
+
35
+ def render
36
+ self.class.ext_draw([
37
+ @x, @y, @radius, @sectors,
38
+ @color.r, @color.g, @color.b, @color.a
39
+ ])
40
+ end
41
+
24
42
  end
25
43
  end
@@ -25,6 +25,8 @@ require 'fileutils'
25
25
  'text',
26
26
  'sound',
27
27
  'music',
28
+ 'texture',
29
+ 'vertices',
28
30
  '../ruby2d'
29
31
  ]
30
32
 
@@ -96,7 +98,7 @@ def build_native(rb_file)
96
98
  end
97
99
 
98
100
  # Compile to a native executable
99
- `cc build/app.c -lmruby \`simple2d --libs\` -o build/app`
101
+ `cc build/app.c -lmruby -o build/app`
100
102
 
101
103
  # Clean up
102
104
  clean_up unless @debug
@@ -162,12 +164,6 @@ end
162
164
  def build_ios_tvos(rb_file, device)
163
165
  check_build_src_file(rb_file)
164
166
 
165
- # Check for Simple 2D framework,
166
- unless File.exist?('/usr/local/Frameworks/Simple2D/iOS/Simple2D.framework') && File.exist?('/usr/local/Frameworks/Simple2D/tvOS/Simple2D.framework')
167
- puts "#{'Error:'.error} Simple 2D iOS and tvOS frameworks not found. Install them and try again.\n"
168
- exit
169
- end
170
-
171
167
  # Check if MRuby exists; if not, quit
172
168
  if `which mruby`.empty?
173
169
  puts "#{'Error:'.error} Can't find MRuby, which is needed to build native Ruby 2D applications.\n"
@@ -197,6 +193,7 @@ def build_ios_tvos(rb_file, device)
197
193
  f << File.read("#{@gem_dir}/ext/ruby2d/ruby2d.c")
198
194
  end
199
195
 
196
+ # TODO: Need add this functionality to the gem
200
197
  # Build the Xcode project
201
198
  `simple2d build --#{device} build/#{device}/MyApp.xcodeproj`
202
199
 
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
@@ -2,8 +2,22 @@
2
2
 
3
3
  module Ruby2D
4
4
  class Font
5
+ @@loaded_fonts = {}
6
+
7
+ attr_reader :ttf_font
8
+
9
+ def initialize(path, size, style=nil)
10
+ @ttf_font = Font.ext_load(path, size, style.to_s)
11
+ end
5
12
 
6
13
  class << self
14
+ def load(path, size, style=nil)
15
+ unless File.exist? path
16
+ raise Error, "Cannot find font file `#{path}`"
17
+ end
18
+
19
+ @@loaded_fonts[[path, size, style]] ||= Font.new(path, size, style)
20
+ end
7
21
 
8
22
  # List all fonts, names only
9
23
  def all
@@ -50,6 +64,7 @@ module Ruby2D
50
64
  macos_font_path = '/Library/Fonts'
51
65
  linux_font_path = '/usr/share/fonts'
52
66
  windows_font_path = 'C:/Windows/Fonts'
67
+ openbsd_font_path = '/usr/X11R6/lib/X11/fonts'
53
68
 
54
69
  # If MRI and/or non-Bash shell (like cmd.exe)
55
70
  if Object.const_defined? :RUBY_PLATFORM
@@ -60,15 +75,20 @@ module Ruby2D
60
75
  linux_font_path
61
76
  when /mingw/
62
77
  windows_font_path
78
+ when /openbsd/
79
+ openbsd_font_path
63
80
  end
64
81
  # If MRuby
65
82
  else
66
- if `uname`.include? 'Darwin' # macOS
83
+ uname = `uname`
84
+ if uname.include? 'Darwin' # macOS
67
85
  macos_font_path
68
- elsif `uname`.include? 'Linux'
86
+ elsif uname.include? 'Linux'
69
87
  linux_font_path
70
- elsif `uname`.include? 'MINGW'
88
+ elsif uname.include? 'MINGW'
71
89
  windows_font_path
90
+ elsif uname.include? 'OpenBSD'
91
+ openbsd_font_path
72
92
  end
73
93
  end
74
94
  end
data/lib/ruby2d/image.rb CHANGED
@@ -7,24 +7,52 @@ module Ruby2D
7
7
  attr_reader :path
8
8
  attr_accessor :x, :y, :width, :height, :rotate, :data
9
9
 
10
- def initialize(path, opts = {})
10
+ def self.load_image(path)
11
11
  unless File.exist? path
12
12
  raise Error, "Cannot find image file `#{path}`"
13
13
  end
14
+
15
+ ext_load_image(path)
16
+ end
17
+
18
+ def initialize(path, opts = {})
14
19
  @path = path
20
+
21
+ @texture = Texture.new(*Image.load_image(@path))
22
+ @width = opts[:width] || @texture.width
23
+ @height = opts[:height] || @texture.height
24
+
15
25
  @x = opts[:x] || 0
16
26
  @y = opts[:y] || 0
17
27
  @z = opts[:z] || 0
18
- @width = opts[:width] || nil
19
- @height = opts[:height] || nil
20
28
  @rotate = opts[:rotate] || 0
21
29
  self.color = opts[:color] || 'white'
22
- self.opacity = opts[:opacity] if opts[:opacity]
23
- unless ext_init(@path)
24
- raise Error, "Image `#{@path}` cannot be created"
30
+ self.color.opacity = opts[:opacity] if opts[:opacity]
31
+
32
+ unless opts[:show] == false then add end
33
+ end
34
+
35
+ def draw(opts = {})
36
+ Window.render_ready_check
37
+
38
+ opts[:width] = opts[:width] || @width
39
+ opts[:height] = opts[:height] || @height
40
+ opts[:rotate] = opts[:rotate] || @rotate
41
+ unless opts[:color]
42
+ opts[:color] = [1.0, 1.0, 1.0, 1.0]
25
43
  end
26
- add
44
+
45
+ render(x: opts[:x], y: opts[:y], width: opts[:width], height: opts[:height], color: Color.new(opts[:color]), rotate: opts[:rotate])
27
46
  end
28
47
 
48
+ private
49
+
50
+ def render(x: @x, y: @y, width: @width, height: @height, color: @color, rotate: @rotate)
51
+ vertices = Vertices.new(x, y, width, height, rotate)
52
+
53
+ @texture.draw(
54
+ vertices.coordinates, vertices.texture_coordinates, color
55
+ )
56
+ end
29
57
  end
30
58
  end
data/lib/ruby2d/line.rb CHANGED
@@ -14,7 +14,7 @@ module Ruby2D
14
14
  @z = opts[:z] || 0
15
15
  @width = opts[:width] || 2
16
16
  self.color = opts[:color] || 'white'
17
- self.opacity = opts[:opacity] if opts[:opacity]
17
+ self.color.opacity = opts[:opacity] if opts[:opacity]
18
18
  add
19
19
  end
20
20
 
@@ -38,8 +38,30 @@ 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
+ Window.render_ready_check
43
+
44
+ ext_draw([
45
+ opts[:x1], opts[:y1], opts[:x2], opts[:y2], opts[:width],
46
+ opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
47
+ opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
48
+ opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
49
+ opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
50
+ ])
51
+ end
52
+
41
53
  private
42
54
 
55
+ def render
56
+ self.class.ext_draw([
57
+ @x1, @y1, @x2, @y2, @width,
58
+ @c1.r, @c1.g, @c1.b, @c1.a,
59
+ @c2.r, @c2.g, @c2.b, @c2.a,
60
+ @c3.r, @c3.g, @c3.b, @c3.a,
61
+ @c4.r, @c4.g, @c4.b, @c4.a
62
+ ])
63
+ end
64
+
43
65
  # Calculate the distance between two points
44
66
  def points_distance(x1, y1, x2, y2)
45
67
  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
@@ -25,7 +25,7 @@ module Ruby2D
25
25
  @y4 = opts[:y4] || 100
26
26
  @z = opts[:z] || 0
27
27
  self.color = opts[:color] || 'white'
28
- self.opacity = opts[:opacity] if opts[:opacity]
28
+ self.color.opacity = opts[:opacity] if opts[:opacity]
29
29
  add
30
30
  end
31
31
 
@@ -48,8 +48,28 @@ module Ruby2D
48
48
  questioned_area <= self_area
49
49
  end
50
50
 
51
+ def self.draw(opts = {})
52
+ Window.render_ready_check
53
+
54
+ ext_draw([
55
+ opts[:x1], opts[:y1], opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
56
+ opts[:x2], opts[:y2], opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
57
+ opts[:x3], opts[:y3], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3],
58
+ opts[:x4], opts[:y4], opts[:color][3][0], opts[:color][3][1], opts[:color][3][2], opts[:color][3][3]
59
+ ])
60
+ end
61
+
51
62
  private
52
63
 
64
+ def render
65
+ self.class.ext_draw([
66
+ @x1, @y1, @c1.r, @c1.g, @c1.b, @c1.a,
67
+ @x2, @y2, @c2.r, @c2.g, @c2.b, @c2.a,
68
+ @x3, @y3, @c3.r, @c3.g, @c3.b, @c3.a,
69
+ @x4, @y4, @c4.r, @c4.g, @c4.b, @c4.a
70
+ ])
71
+ end
72
+
53
73
  def triangle_area(x1, y1, x2, y2, x3, y3)
54
74
  (x1*y2 + x2*y3 + x3*y1 - x3*y2 - x1*y3 - x2*y1).abs / 2
55
75
  end
@@ -10,7 +10,7 @@ module Ruby2D
10
10
  @width = opts[:width] || 200
11
11
  @height = opts[:height] || 100
12
12
  self.color = opts[:color] || 'white'
13
- self.opacity = opts[:opacity] if opts[:opacity]
13
+ self.color.opacity = opts[:opacity] if opts[:opacity]
14
14
  update_coords(@x, @y, @width, @height)
15
15
  add
16
16
  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,20 +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
37
-
38
- # Allow shortcuts for setting color values
39
- def r; self.color.r end
40
- def g; self.color.g end
41
- def b; self.color.b end
42
- def a; self.color.a end
43
- def r=(c); self.color.r = c end
44
- def g=(c); self.color.g = c end
45
- def b=(c); self.color.b = c end
46
- def a=(c); self.color.a = c end
47
- def opacity; self.color.opacity end
48
- def opacity=(val); self.color.opacity = val end
31
+ alias_method :colour, :color
32
+ alias_method :colour=, :color=
49
33
 
50
34
  # Add a contains method stub
51
35
  def contains?(x, y)