summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorlstrzebinczyk <[email protected]>2017-04-29 20:28:52 +0200
committerTom Black <[email protected]>2017-05-19 16:23:05 -0400
commitabfb596bc9212c5094dc7ec3645ace4e7d35856b (patch)
treebd167dd602f833f84582ed9e18734ffe979d2914 /lib
parentb4ba5e2ffc71906c84e6fb0b730379ea9a74fdc9 (diff)
downloadruby2d-abfb596bc9212c5094dc7ec3645ace4e7d35856b.tar.gz
ruby2d-abfb596bc9212c5094dc7ec3645ace4e7d35856b.zip
introduce lines
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby2d.rb1
-rw-r--r--lib/ruby2d/image.rb2
-rw-r--r--lib/ruby2d/line.rb41
-rw-r--r--lib/ruby2d/sprite.rb2
-rw-r--r--lib/ruby2d/text.rb2
5 files changed, 45 insertions, 3 deletions
diff --git a/lib/ruby2d.rb b/lib/ruby2d.rb
index 4c13dd9..9642aa1 100644
--- a/lib/ruby2d.rb
+++ b/lib/ruby2d.rb
@@ -7,6 +7,7 @@ require 'ruby2d/window'
require 'ruby2d/application'
require 'ruby2d/dsl'
require 'ruby2d/quad'
+require 'ruby2d/line'
require 'ruby2d/rectangle'
require 'ruby2d/square'
require 'ruby2d/triangle'
diff --git a/lib/ruby2d/image.rb b/lib/ruby2d/image.rb
index 85ee076..91bb3f3 100644
--- a/lib/ruby2d/image.rb
+++ b/lib/ruby2d/image.rb
@@ -15,7 +15,7 @@ module Ruby2D
end
end
- @type_id = 3
+ @type_id = 4
@x, @y, @path = x, y, path
@z = z
@color = Color.new([1, 1, 1, 1])
diff --git a/lib/ruby2d/line.rb b/lib/ruby2d/line.rb
new file mode 100644
index 0000000..5053854
--- /dev/null
+++ b/lib/ruby2d/line.rb
@@ -0,0 +1,41 @@
+# line.rb
+
+module Ruby2D
+ class Line
+ include Renderable
+ attr_accessor :x1, :x2, :y1, :y2, :color, :width
+
+ def initialize(x1, y1, x2, y2, width=2, c='white')
+ @type_id = 3
+ @x1, @y1, @x2, @y2 = x1, y1, x2, y2
+ @width = width
+ self.color = c
+ add
+ end
+
+ def color=(c)
+ @color = Color.from(c)
+ update_color(@color)
+ end
+
+ private
+
+ def update_color(c)
+ if c.is_a? Color::Set
+ if c.length == 4
+ @c1 = c[0]
+ @c2 = c[1]
+ @c3 = c[2]
+ @c4 = c[3]
+ else
+ raise ArgumentError, "Lines require 4 colors, one for each vertex. #{c.length} were given."
+ end
+ else
+ @c1 = c
+ @c2 = c
+ @c3 = c
+ @c4 = c
+ end
+ end
+ end
+end
diff --git a/lib/ruby2d/sprite.rb b/lib/ruby2d/sprite.rb
index ad8dc17..93f4f58 100644
--- a/lib/ruby2d/sprite.rb
+++ b/lib/ruby2d/sprite.rb
@@ -12,7 +12,7 @@ module Ruby2D
# raise Error, "Cannot find image file `#{path}`"
# end
- @type_id = 4
+ @type_id = 5
@x, @y, @path = x, y, path
@clip_x, @clip_y, @clip_w, @clip_h = 0, 0, 0, 0
@default = nil
diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb
index b3b4529..e326029 100644
--- a/lib/ruby2d/text.rb
+++ b/lib/ruby2d/text.rb
@@ -15,7 +15,7 @@ module Ruby2D
# @font = resolve_path(font)
# end
- @type_id = 5
+ @type_id = 6
@x, @y, @size = x, y, size
@z = z
@text = text.to_s