summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorTom Black <[email protected]>2018-09-28 13:22:23 -0700
committerTom Black <[email protected]>2018-09-28 13:22:23 -0700
commit9b51a3b4718b082301ff70b706ac53bec8668ac9 (patch)
tree9a27a9933548f7c9446b756f42fc1928a8cf2a63 /lib
parentd0a2823398fb0b26b75a168ec13816c8873cceb1 (diff)
downloadruby2d-9b51a3b4718b082301ff70b706ac53bec8668ac9.tar.gz
ruby2d-9b51a3b4718b082301ff70b706ac53bec8668ac9.zip
Color enhancements
New shortcuts for setting color values, like `.color.r/g/b/a` and simply `.r/g/b/a`; allow the British English spelling "colour"
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby2d/color.rb5
-rw-r--r--lib/ruby2d/renderable.rb25
2 files changed, 21 insertions, 9 deletions
diff --git a/lib/ruby2d/color.rb b/lib/ruby2d/color.rb
index 26d176f..296f228 100644
--- a/lib/ruby2d/color.rb
+++ b/lib/ruby2d/color.rb
@@ -26,7 +26,7 @@ module Ruby2D
end
end
- attr_reader :r, :g, :b, :a
+ attr_accessor :r, :g, :b, :a
# Based on clrs.cc
@@colors = {
@@ -128,4 +128,7 @@ module Ruby2D
end
end
+
+ # Allow British English spelling of color
+ Colour = Color
end
diff --git a/lib/ruby2d/renderable.rb b/lib/ruby2d/renderable.rb
index 6a6761d..18c7a78 100644
--- a/lib/ruby2d/renderable.rb
+++ b/lib/ruby2d/renderable.rb
@@ -23,14 +23,23 @@ module Ruby2D
end
end
- def opacity
- self.color.opacity
- end
-
- def opacity=(val)
- self.color.opacity = val
- end
-
+ # Allow shortcuts for setting color values
+ def r; self.color.r end
+ def g; self.color.g end
+ def b; self.color.b end
+ def a; self.color.a end
+ def r=(c); self.color.r = c end
+ def g=(c); self.color.g = c end
+ def b=(c); self.color.b = c end
+ def a=(c); self.color.a = c end
+ def opacity; self.color.opacity end
+ def opacity=(val); self.color.opacity = val end
+
+ # Allow British English spelling of color
+ def colour; self.color end
+ def colour=(c); self.color = c end
+
+ # Add a contains method stub
def contains?(x, y)
raise Error, "\`#contains?\` not implemented for this class yet"
end