Sha256: 12cb1eb56274b050572957c987c06055ea85c8259b36291eda18c623d9973d03

Contents?: true

Size: 828 Bytes

Versions: 48

Compression:

Stored size: 828 Bytes

Contents

class Fixnum

  #     0xffeedd.nscolor
  # =>
  #     NSColor.colorWithRed(0xFF / 255.0, green: 0xEE / 255.0, blue: 0xDD / 255.0, alpha: 1.0)
  #     # ≈ NSColor.colorWithRed(1.0, green: 0.933, blue: 0.867, alpha: 1.0)
  #
  #     0xffeedd.nscolor(0.25)
  # =>
  #     NSColor.colorWithRed(0xFF / 255.0, green: 0xEE / 255.0, blue: 0xDD / 255.0, alpha: 0.25)
  #     # ≈ NSColor.colorWithRed(1.0, green: 0.933, blue: 0.867, alpha: 0.25)
  def nscolor(alpha=nil)
    alpha = 1.0 if alpha.nil?

    red = ((self & 0xFF0000) >> 16).to_f / 255.0
    green = ((self & 0xFF00) >> 8).to_f / 255.0
    blue = (self & 0xFF).to_f / 255.0

    NSColor.colorWithRed(red, green: green, blue: blue, alpha: alpha.to_f)
  end

  def cgcolor(alpha=nil)
    nscolor(alpha).CGColor
  end

  def skcolor(alpha=nil)
    nscolor(alpha)
  end

end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
sugarcube-2.12.2 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.12.1 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.12.0 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.11.1 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.11.0 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.10.0 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.9.1 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.8.2 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.8.1 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.8.0 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.7.1 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.7.0 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.6.0 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.5.0 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.4.2 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.4.1 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.4.0 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.3.0 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.2.0 lib/osx/sugarcube-color/fixnum.rb
sugarcube-2.1.5 lib/osx/sugarcube-color/fixnum.rb