Sha256: 3d19ba6ee086f9bf51f223e95072bfbb8225fdbd8f510a3aa0aa15d6a8fa3dc4

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

class UIColor

  def to_s
    alpha = self.alpha.to_s

    Symbol.uicolors.each_pair do |color, method|
      if UIColor.send(method) == self
        return "UIColor.#{method}(#{alpha})"
      end
    end

    red = (self.red * 255).to_i << 16
    green = (self.green * 255).to_i << 8
    blue = (self.blue * 255).to_i
    my_color = red + green + blue
    Symbol.css_colors.each_pair do |color, hex|
      if hex == my_color
        return "UIColor.color(#{color.inspect}, #{alpha})"
      end
    end
    return "UIColor.color(#{red}, #{green}, #{blue}, #{alpha})"
  end

  def color
    if not @color
      red = Pointer.new(:float)
      green = Pointer.new(:float)
      blue = Pointer.new(:float)
      alpha = Pointer.new(:float)
      self.getRed(red, green:green, blue:blue, alpha:alpha)
      @color = {
        red: red[0],
        green: green[0],
        blue: blue[0],
        alpha: alpha[0],
      }
    end
    @color
  end

  def red
    self.color[:red]
  end

  def green
    self.color[:green]
  end

  def blue
    self.color[:blue]
  end

  def alpha
    self.color[:alpha]
  end


end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sugarcube-0.1.6 lib/sugarcube/uicolor.rb
sugarcube-0.1.5 lib/sugarcube/uicolor.rb
sugarcube-0.1.4 lib/sugarcube/uicolor.rb
sugarcube-0.1.3 lib/sugarcube/uicolor.rb
sugarcube-0.1.2 lib/sugarcube/uicolor.rb
sugarcube-0.1.1 lib/sugarcube/uicolor.rb