Class: UnderOs::Color
Defined Under Namespace
Modules: Converter
Constant Summary collapse
- CACHE =
{}
Instance Attribute Summary collapse
-
#ui ⇒ Object
Returns the value of attribute ui.
Class Method Summary collapse
Instance Method Summary collapse
- #==(color) ⇒ Object
- #cg ⇒ Object
- #ci ⇒ Object
-
#initialize(ui_color) ⇒ Color
constructor
A new instance of Color.
- #invert ⇒ Object
- #to_hex ⇒ Object
- #to_rgb ⇒ Object
- #to_rgba ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(ui_color) ⇒ Color
Returns a new instance of Color.
11 12 13 |
# File 'lib/under_os/color.rb', line 11 def initialize(ui_color) @ui = ui_color end |
Instance Attribute Details
#ui ⇒ Object
Returns the value of attribute ui.
2 3 4 |
# File 'lib/under_os/color.rb', line 2 def ui @ui end |
Class Method Details
.new(*args) ⇒ Object
6 7 8 9 |
# File 'lib/under_os/color.rb', line 6 def self.new(*args) color = Converter.ui_color_from(*args) CACHE[color] ||= super(color) end |
Instance Method Details
#==(color) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/under_os/color.rb', line 60 def ==(color) color = if color.is_a?(self.class) color else color = [color] if ! color.is_a?(Array) self.class.new(*color) end to_s == color.to_s end |
#cg ⇒ Object
15 16 17 |
# File 'lib/under_os/color.rb', line 15 def cg @ui.CGColor end |
#ci ⇒ Object
19 20 21 |
# File 'lib/under_os/color.rb', line 19 def ci @ui.CIColor end |
#invert ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/under_os/color.rb', line 23 def invert self.class.new to_rgba.tap do |rgba| rgba[0] = 255 - rgba[0] rgba[1] = 255 - rgba[1] rgba[2] = 255 - rgba[2] end end |
#to_hex ⇒ Object
50 51 52 53 54 |
# File 'lib/under_os/color.rb', line 50 def to_hex r, g, b = to_rgb int = (r << 16) + (g << 8) + b '#' + int.to_s(16).rjust(6, '0') end |
#to_rgb ⇒ Object
46 47 48 |
# File 'lib/under_os/color.rb', line 46 def to_rgb to_rgba.slice(0, 3) end |
#to_rgba ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/under_os/color.rb', line 31 def to_rgba r = Pointer.new(:float) g = Pointer.new(:float) b = Pointer.new(:float) a = Pointer.new(:float) @ui.getRed(r, green:g, blue:b, alpha:a) r = (255 * r[0]).round g = (255 * g[0]).round b = (255 * b[0]).round [r,g,b,a[0]] end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/under_os/color.rb', line 56 def to_s to_hex end |