From 9b51a3b4718b082301ff70b706ac53bec8668ac9 Mon Sep 17 00:00:00 2001 From: Tom Black Date: Fri, 28 Sep 2018 13:22:23 -0700 Subject: 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" --- lib/ruby2d/color.rb | 5 ++++- lib/ruby2d/renderable.rb | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3