class UnderOs::Color

Constants

CACHE

Attributes

ui[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/under_os/color.rb, line 6
def self.new(*args)
  color = Converter.ui_color_from(*args)
  CACHE[color] ||= super(color)
end
new(ui_color) click to toggle source
# File lib/under_os/color.rb, line 11
def initialize(ui_color)
  @ui = ui_color
end

Public Instance Methods

==(color) click to toggle source
# 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() click to toggle source
# File lib/under_os/color.rb, line 15
def cg
  @ui.CGColor
end
ci() click to toggle source
# File lib/under_os/color.rb, line 19
def ci
  @ui.CIColor
end
invert() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/under_os/color.rb, line 46
def to_rgb
  to_rgba.slice(0, 3)
end
to_rgba() click to toggle source
# 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() click to toggle source
# File lib/under_os/color.rb, line 56
def to_s
  to_hex
end