Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from brightdigit/develop
merging develop branch 1.0.2
- Loading branch information
Showing
16 changed files
with
334 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ Temporary Items | |
## Build generated | ||
build/ | ||
DerivedData/ | ||
Products/ | ||
|
||
## Various settings | ||
# Xcode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
#!/bin/bash | ||
|
||
# Wrapper around 'brew install' emitting a message every minute if the command is still running. | ||
# This is used on Travis to ensure the install isn't killed when there is no output over a long period (10 minutes). | ||
# Usage: brew-install package, where package is the name of the package for brew to install. | ||
|
||
seconds=0 | ||
minutes=0 | ||
brew install $1 & | ||
while true; do | ||
ps -p$! 2>& 1>/dev/null | ||
if [ $? = 0 ]; then | ||
if [ $seconds = 60 ]; then | ||
let seconds=0 | ||
let minutes=minutes+1 | ||
echo "brew install $1 still running ($minutes min)" | ||
fi | ||
sleep 1 | ||
let seconds=seconds+1 | ||
else | ||
break | ||
fi | ||
done | ||
wait $! | ||
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{ | ||
"set" : "Assets.xcassets/iOS AppIcon.appiconset", | ||
"source" : "geometry.svg" | ||
"source" : "geometry.svg", | ||
"background" : "#FFFFFF", | ||
"remove-alpha" : true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{ | ||
"set" : "Assets.xcassets/macOS AppIcon.appiconset", | ||
"source" : "geometry.svg" | ||
"source" : "geometry.svg", | ||
"background" : "#FFFFFF", | ||
"remove-alpha" : true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
d8d65120ef77d026a965b4515fd8aa53681b7e45e9580add63e832367d0cd79e6b3e01b1415d34fbbbd9e68ac8b281ef389914ed4c86250b50e4aceb7fccbb58 - | ||
d23bc97f1f823cee4e1d5d19ffa170bc9aff48f98c5bb554251bc74e9dde24a385d0171af9ab673bb2bf49dcf4f9c0fbdd164b3e8b877ec61896828fd28db5dd - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// | ||
// NSColor.swift | ||
// speculid | ||
// | ||
// | ||
// Created by R0CKSTAR on 6/13/14. | ||
// Copyright (c) 2014 P.D.Q. All rights reserved. | ||
// Modified by Leo Dion on 12/21/16. | ||
// | ||
|
||
/** | ||
MissingHashMarkAsPrefix: "Invalid RGB string, missing '#' as prefix" | ||
UnableToScanHexValue: "Scan hex error" | ||
MismatchedHexStringLength: "Invalid RGB string, number of characters after '#' should be either 3, 4, 6 or 8" | ||
*/ | ||
public enum UIColorInputError : Error { | ||
case missingHashMarkAsPrefix, | ||
unableToScanHexValue, | ||
mismatchedHexStringLength | ||
} | ||
|
||
extension NSColor { | ||
/** | ||
The shorthand three-digit hexadecimal representation of color. | ||
#RGB defines to the color #RRGGBB. | ||
- parameter hex3: Three-digit hexadecimal value. | ||
- parameter alpha: 0.0 - 1.0. The default is 1.0. | ||
*/ | ||
public convenience init(hex3: UInt16, alpha: CGFloat = 1) { | ||
let divisor = CGFloat(15) | ||
let red = CGFloat((hex3 & 0xF00) >> 8) / divisor | ||
let green = CGFloat((hex3 & 0x0F0) >> 4) / divisor | ||
let blue = CGFloat( hex3 & 0x00F ) / divisor | ||
self.init(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
|
||
/** | ||
The shorthand four-digit hexadecimal representation of color with alpha. | ||
#RGBA defines to the color #RRGGBBAA. | ||
- parameter hex4: Four-digit hexadecimal value. | ||
*/ | ||
public convenience init(hex4: UInt16) { | ||
let divisor = CGFloat(15) | ||
let red = CGFloat((hex4 & 0xF000) >> 12) / divisor | ||
let green = CGFloat((hex4 & 0x0F00) >> 8) / divisor | ||
let blue = CGFloat((hex4 & 0x00F0) >> 4) / divisor | ||
let alpha = CGFloat( hex4 & 0x000F ) / divisor | ||
self.init(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
|
||
/** | ||
The six-digit hexadecimal representation of color of the form #RRGGBB. | ||
- parameter hex6: Six-digit hexadecimal value. | ||
*/ | ||
public convenience init(hex6: UInt32, alpha: CGFloat = 1) { | ||
let divisor = CGFloat(255) | ||
let red = CGFloat((hex6 & 0xFF0000) >> 16) / divisor | ||
let green = CGFloat((hex6 & 0x00FF00) >> 8) / divisor | ||
let blue = CGFloat( hex6 & 0x0000FF ) / divisor | ||
self.init(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
|
||
/** | ||
The six-digit hexadecimal representation of color with alpha of the form #RRGGBBAA. | ||
- parameter hex8: Eight-digit hexadecimal value. | ||
*/ | ||
public convenience init(hex8: UInt32) { | ||
let divisor = CGFloat(255) | ||
let red = CGFloat((hex8 & 0xFF000000) >> 24) / divisor | ||
let green = CGFloat((hex8 & 0x00FF0000) >> 16) / divisor | ||
let blue = CGFloat((hex8 & 0x0000FF00) >> 8) / divisor | ||
let alpha = CGFloat( hex8 & 0x000000FF ) / divisor | ||
self.init(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
|
||
/** | ||
The rgba string representation of color with alpha of the form #RRGGBBAA/#RRGGBB, throws error. | ||
- parameter rgba: String value. | ||
*/ | ||
public convenience init(rgba_throws rgba: String) throws { | ||
guard rgba.hasPrefix("#") else { | ||
throw UIColorInputError.missingHashMarkAsPrefix | ||
} | ||
|
||
let hexString: String = rgba.substring(from: rgba.characters.index(rgba.startIndex, offsetBy: 1)) | ||
var hexValue: UInt32 = 0 | ||
|
||
guard Scanner(string: hexString).scanHexInt32(&hexValue) else { | ||
throw UIColorInputError.unableToScanHexValue | ||
} | ||
|
||
switch (hexString.characters.count) { | ||
case 3: | ||
self.init(hex3: UInt16(hexValue)) | ||
case 4: | ||
self.init(hex4: UInt16(hexValue)) | ||
case 6: | ||
self.init(hex6: hexValue) | ||
case 8: | ||
self.init(hex8: hexValue) | ||
default: | ||
throw UIColorInputError.mismatchedHexStringLength | ||
} | ||
} | ||
|
||
/** | ||
The rgba string representation of color with alpha of the form #RRGGBBAA/#RRGGBB, fails to default color. | ||
- parameter rgba: String value. | ||
*/ | ||
public convenience init?(_ rgba: String, defaultColor: NSColor = NSColor.clear) { | ||
guard let color = try? NSColor(rgba_throws: rgba) else { | ||
self.init(cgColor: defaultColor.cgColor) | ||
return | ||
} | ||
self.init(cgColor: color.cgColor) | ||
} | ||
|
||
/** | ||
Hex string of a UIColor instance. | ||
- parameter includeAlpha: Whether the alpha should be included. | ||
*/ | ||
public func hexString(_ includeAlpha: Bool = true) -> String { | ||
var r: CGFloat = 0 | ||
var g: CGFloat = 0 | ||
var b: CGFloat = 0 | ||
var a: CGFloat = 0 | ||
self.getRed(&r, green: &g, blue: &b, alpha: &a) | ||
|
||
if (includeAlpha) { | ||
return String(format: "#%02X%02X%02X%02X", Int(r * 255), Int(g * 255), Int(b * 255), Int(a * 255)) | ||
} else { | ||
return String(format: "#%02X%02X%02X", Int(r * 255), Int(g * 255), Int(b * 255)) | ||
} | ||
} | ||
} | ||
|
||
extension String { | ||
/** | ||
Convert argb string to rgba string. | ||
*/ | ||
public func argb2rgba() -> String? { | ||
guard self.hasPrefix("#") else { | ||
return nil | ||
} | ||
|
||
let hexString: String = self.substring(from: self.characters.index(self.startIndex, offsetBy: 1)) | ||
switch (hexString.characters.count) { | ||
case 4: | ||
return "#" | ||
+ hexString.substring(from: self.characters.index(self.startIndex, offsetBy: 1)) | ||
+ hexString.substring(to: self.characters.index(self.startIndex, offsetBy: 1)) | ||
case 8: | ||
return "#" | ||
+ hexString.substring(from: self.characters.index(self.startIndex, offsetBy: 2)) | ||
+ hexString.substring(to: self.characters.index(self.startIndex, offsetBy: 2)) | ||
default: | ||
return nil | ||
} | ||
} | ||
} |
Oops, something went wrong.