2016-06-05 10:49:14 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
2017-05-11 09:08:58 +03:00
|
|
|
fileprivate var colorCache = [Int: NSColor]()
|
2017-01-27 17:45:04 +03:00
|
|
|
|
2016-06-05 10:49:14 +03:00
|
|
|
class ColorUtils {
|
|
|
|
|
2017-05-11 09:08:58 +03:00
|
|
|
static func colorIgnoringAlpha(_ rgb: Int) -> NSColor {
|
2017-01-27 17:45:04 +03:00
|
|
|
if let color = colorCache[rgb] {
|
|
|
|
return color
|
|
|
|
}
|
|
|
|
|
2016-06-18 12:43:37 +03:00
|
|
|
let red = (CGFloat((rgb >> 16) & 0xFF)) / 255.0;
|
|
|
|
let green = (CGFloat((rgb >> 8) & 0xFF)) / 255.0;
|
|
|
|
let blue = (CGFloat((rgb ) & 0xFF)) / 255.0;
|
2016-06-05 10:49:14 +03:00
|
|
|
|
2017-01-27 17:45:04 +03:00
|
|
|
let color = NSColor(srgbRed: red, green: green, blue: blue, alpha: 1.0)
|
|
|
|
colorCache[rgb] = color
|
|
|
|
|
|
|
|
return color
|
2016-06-05 10:49:14 +03:00
|
|
|
}
|
|
|
|
}
|