Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public init #630

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 69 additions & 69 deletions C4/Core/C4Color.swift → C4/Core/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,67 @@
import UIKit
import CoreGraphics

/// A C4Color object whose RGB value is 0, 0, 0 and whose alpha value is 1.0.
public let black = C4Color(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
/// A C4Color object whose RGB value is 0.33, 0.33, 0.33 and whose alpha value is 1.0.
public let darkGray = C4Color(red: 1.0/3.0, green: 1.0/3.0, blue: 1.0/3.0, alpha: 1.0)
/// A C4Color object whose RGB value is 0.66, 0.66, 0.66 and whose alpha value is 1.0.
public let lightGray = C4Color(red: 2.0/3.0, green: 2.0/3.0, blue: 2.0/3.0, alpha: 1.0)
/// A C4Color object whose RGB value is 1.0, 1.0, 1.0 and whose alpha value is 1.0.
public let white = C4Color(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
/// A C4Color object whose RGB value is 0.5, 0.5, 0.5 and whose alpha value is 1.0.
public let gray = C4Color(red: 0.5, green: 0.5, blue: 0.5, alpha: 1.0)
/// A C4Color object whose RGB value is 1.0, 0.0, 0.0 and whose alpha value is 1.0.
public let red = C4Color(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
/// A C4Color object whose RGB value is 0.0, 1.0, 0.0 and whose alpha value is 1.0.
public let green = C4Color(red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0)
/// A C4Color object whose RGB value is 0.0, 0.0, 1.0 and whose alpha value is 1.0.
public let blue = C4Color(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0)
/// A C4Color object whose RGB value is 0.0, 1.0, 1.0 and whose alpha value is 1.0.
public let cyan = C4Color(red: 0.0, green: 1.0, blue: 1.0, alpha: 1.0)
/// A C4Color object whose RGB value is 1.0, 1.0, 0.0 and whose alpha value is 1.0.
public let yellow = C4Color(red: 1.0, green: 1.0, blue: 0.0, alpha: 1.0)
/// A C4Color object whose RGB value is 1.0, 0.0, 1.0 and whose alpha value is 1.0.
public let magenta = C4Color(red: 1.0, green: 0.0, blue: 1.0, alpha: 1.0)
/// A C4Color object whose RGB value is 1.0, 0.5, 0.0 and whose alpha value is 1.0.
public let orange = C4Color(red: 1.0, green: 0.5, blue: 0.0, alpha: 1.0)
/// A C4Color object whose RGB value is 0.5, 0.0, 0.5 and whose alpha value is 1.0.
public let purple = C4Color(red: 0.5, green: 0.0, blue: 0.5, alpha: 1.0)
/// A C4Color object whose RGB value is 0.6, 0.4, 0.2 and whose alpha value is 1.0.
public let brown = C4Color(red: 0.6, green: 0.4, blue: 0.2, alpha: 1.0)
/// A C4Color object whose RGB value is 0.0, 0.0, 0.0 and whose alpha value is 0.0.
public let clear = C4Color(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
/// A Color object whose RGB value is 0, 0, 0 and whose alpha value is 1.0.
public let black = Color(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
/// A Color object whose RGB value is 0.33, 0.33, 0.33 and whose alpha value is 1.0.
public let darkGray = Color(red: 1.0/3.0, green: 1.0/3.0, blue: 1.0/3.0, alpha: 1.0)
/// A Color object whose RGB value is 0.66, 0.66, 0.66 and whose alpha value is 1.0.
public let lightGray = Color(red: 2.0/3.0, green: 2.0/3.0, blue: 2.0/3.0, alpha: 1.0)
/// A Color object whose RGB value is 1.0, 1.0, 1.0 and whose alpha value is 1.0.
public let white = Color(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
/// A Color object whose RGB value is 0.5, 0.5, 0.5 and whose alpha value is 1.0.
public let gray = Color(red: 0.5, green: 0.5, blue: 0.5, alpha: 1.0)
/// A Color object whose RGB value is 1.0, 0.0, 0.0 and whose alpha value is 1.0.
public let red = Color(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
/// A Color object whose RGB value is 0.0, 1.0, 0.0 and whose alpha value is 1.0.
public let green = Color(red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0)
/// A Color object whose RGB value is 0.0, 0.0, 1.0 and whose alpha value is 1.0.
public let blue = Color(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0)
/// A Color object whose RGB value is 0.0, 1.0, 1.0 and whose alpha value is 1.0.
public let cyan = Color(red: 0.0, green: 1.0, blue: 1.0, alpha: 1.0)
/// A Color object whose RGB value is 1.0, 1.0, 0.0 and whose alpha value is 1.0.
public let yellow = Color(red: 1.0, green: 1.0, blue: 0.0, alpha: 1.0)
/// A Color object whose RGB value is 1.0, 0.0, 1.0 and whose alpha value is 1.0.
public let magenta = Color(red: 1.0, green: 0.0, blue: 1.0, alpha: 1.0)
/// A Color object whose RGB value is 1.0, 0.5, 0.0 and whose alpha value is 1.0.
public let orange = Color(red: 1.0, green: 0.5, blue: 0.0, alpha: 1.0)
/// A Color object whose RGB value is 0.5, 0.0, 0.5 and whose alpha value is 1.0.
public let purple = Color(red: 0.5, green: 0.0, blue: 0.5, alpha: 1.0)
/// A Color object whose RGB value is 0.6, 0.4, 0.2 and whose alpha value is 1.0.
public let brown = Color(red: 0.6, green: 0.4, blue: 0.2, alpha: 1.0)
/// A Color object whose RGB value is 0.0, 0.0, 0.0 and whose alpha value is 0.0.
public let clear = Color(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)

///A C4Color object whose RGB value is 1.0, 0.0, 0.475 and whose alpha value is 1.0.
public let C4Pink = C4Color(red: 1.0, green: 0.0, blue: 0.475, alpha: 1.0)
///A C4Color object whose RGB value is 0.098, 0.271, 1.0 and whose alpha value is 1.0.
public let C4Blue = C4Color(red: 0.098, green: 0.271, blue: 1.0, alpha: 1.0)
///A C4Color object whose RGB value is 0.0, 0.0, 0.541 and whose alpha value is 1.0.
public let C4Purple = C4Color(red: 0.0, green: 0.0, blue: 0.541, alpha: 1.0)
///A C4Color object whose RGB value is 0.98, 0.98, 0.98 and whose alpha value is 1.0.
public let C4Grey = C4Color(red: 0.98, green: 0.98, blue: 0.98, alpha: 1.0)
///A Color object whose RGB value is 1.0, 0.0, 0.475 and whose alpha value is 1.0.
public let C4Pink = Color(red: 1.0, green: 0.0, blue: 0.475, alpha: 1.0)
///A Color object whose RGB value is 0.098, 0.271, 1.0 and whose alpha value is 1.0.
public let C4Blue = Color(red: 0.098, green: 0.271, blue: 1.0, alpha: 1.0)
///A Color object whose RGB value is 0.0, 0.0, 0.541 and whose alpha value is 1.0.
public let C4Purple = Color(red: 0.0, green: 0.0, blue: 0.541, alpha: 1.0)
///A Color object whose RGB value is 0.98, 0.98, 0.98 and whose alpha value is 1.0.
public let C4Grey = Color(red: 0.98, green: 0.98, blue: 0.98, alpha: 1.0)

/// This document describes the C4Color object which represents color and sometimes opacity (alpha value). You can use C4Color
/// objects to store color data, and pass them between various C4 objects such as C4Shape, C4Image, etc.
/// This document describes the Color object which represents color and sometimes opacity (alpha value). You can use Color
/// objects to store color data, and pass them between various C4 objects such as Shape, Image, etc.
///
/// C4Color internally wraps a CGColorSpaceRef called colorSpace, as well as a CGColorRef. From these two objects C4Color is able to
/// properly maintain color data and convert it to / from other color objects such as UIColor, CIColor, C4Color, etc.
public class C4Color {
/// Color internally wraps a CGColorSpaceRef called colorSpace, as well as a CGColorRef. From these two objects Color is able to
/// properly maintain color data and convert it to / from other color objects such as UIColor, CIColor, Color, etc.
public class Color {
internal var colorSpace: CGColorSpaceRef
internal var internalColor: CGColorRef

/// Initializes and returns a new color object. Defaults to black with 0 opacity (i.e. clear).
/// ````
/// let c = C4Color()
/// let c = Color()
/// ````
public init() {
colorSpace = CGColorSpaceCreateDeviceRGB()!
internalColor = CGColorCreate(colorSpace, [0, 0, 0, 0])!
}

/// Initializes and returns a new C4Color object based on specified color values.
/// Initializes and returns a new Color object based on specified color values.
/// ````
/// let c = C4Color(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
/// let c = Color(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
/// ````
/// - parameter red: The red value for the new color [0.0 ... 1.0]
/// - parameter green: The green value for the new color [0.0 ... 1.0]
Expand All @@ -91,37 +91,37 @@ public class C4Color {
internalColor = CGColorCreate(colorSpace, [CGFloat(red), CGFloat(green), CGFloat(blue), CGFloat(alpha)])!
}

/// Initializes and returns a new C4Color object based on a provided CGColor object.
/// Initializes and returns a new Color object based on a provided CGColor object.
/// ````
/// let c = C4Color(UIColor.redColor().CGColor)
/// let c = Color(UIColor.redColor().CGColor)
/// ````
/// - parameter color: A CGColor object that will be used to create a new C4Color.
/// - parameter color: A CGColor object that will be used to create a new Color.
public init(_ color: CGColorRef) {
colorSpace = CGColorSpaceCreateDeviceRGB()!
internalColor = color
}

/// Initializes and returns a new C4Color object based on a provided UIColor object.
/// Initializes and returns a new Color object based on a provided UIColor object.
/// ````
/// let c = C4Color(UIColor.redColor())
/// let c = Color(UIColor.redColor())
/// ````
/// - parameter color: A UIColor object whose components will be extrated to create a new C4Color.
/// - parameter color: A UIColor object whose components will be extrated to create a new Color.
public convenience init(_ color: UIColor) {
self.init(color.CGColor)
}

/// Initializes and returns a new C4Color object made up of a repeating pattern based on a specified C4Image.
/// Initializes and returns a new Color object made up of a repeating pattern based on a specified Image.
/// ````
/// let p = C4Color("pattern")
/// let p = Color("pattern")
/// ````
/// - parameter pattern: a String, the name of an image to use as a pattern.
public convenience init(_ pattern: String) {
self.init(UIColor(patternImage: UIImage(named: pattern)!))
}

/// Initializes and returns a new C4Color object based on specified color values.
/// Initializes and returns a new Color object based on specified color values.
/// ````
/// let c = C4Color(red: 255, green: 0, blue: 0, alpha: 255)
/// let c = Color(red: 255, green: 0, blue: 0, alpha: 255)
/// ````
/// - parameter red: The red value for the new color [0 ... 255]
/// - parameter green: The green value for the new color [0 ... 255]
Expand All @@ -131,10 +131,10 @@ public class C4Color {
self.init(red: Double(red) / 255.0, green: Double(green) / 255.0, blue: Double(blue) / 255.0, alpha: alpha)
}

/// Initializes and returns a new C4Color object based on a specified hex value.
/// Initializes and returns a new Color object based on a specified hex value.
/// Remember to precede with `0x` and include the alpha component at the end (i.e. 7th + 8th characters)
/// ````
/// let c = C4Color(0xFF0000FF)
/// let c = Color(0xFF0000FF)
/// ````
/// - parameter hexValue: A color value expressed in hexadecimal.
public convenience init(_ hexValue: UInt32) {
Expand Down Expand Up @@ -170,7 +170,7 @@ public class C4Color {

/// The value of the red component of the current color, [0.0 ... 1.0]
/// ````
/// let c = C4Color()
/// let c = Color()
/// let redVal = c.red
/// ````
/// - returns: Double value in the range [0.0 ... 1.0]
Expand All @@ -185,7 +185,7 @@ public class C4Color {

/// The value of the green component of the current color
/// ````
/// let c = C4Color()
/// let c = Color()
/// let greenVal = c.green
/// ````
/// - returns: Double value in the range [0.0 ... 1.0]
Expand All @@ -200,7 +200,7 @@ public class C4Color {

/// The value of the blue component of the current color
/// ````
/// let c = C4Color()
/// let c = Color()
/// let blueVal = c.blue
/// ````
/// - returns: Double value in the range [0.0 ... 1.0]
Expand All @@ -215,7 +215,7 @@ public class C4Color {

/// The value of the alpha component of the current color.
/// ````
/// let c = C4Color()
/// let c = Color()
/// let alphaVal = c.alpha
/// ````
/// - returns: Double value in the range [0.0 ... 1.0]
Expand All @@ -230,7 +230,7 @@ public class C4Color {

/// A CGColor representation of the current color.
/// ````
/// let c = C4Color()
/// let c = Color()
/// let cg = c.CGColor
/// ````
/// - returns: CGColorRef object that matches the color's `internalColor` property
Expand All @@ -246,25 +246,25 @@ public class C4Color {
/// ````
/// - parameter alpha: The opacity value of the new UIColor object.
/// - returns: A new color with a modified alpha component.
public func colorWithAlpha(alpha: Double) -> C4Color {
return C4Color(red: red, green: green, blue: blue, alpha: alpha)
public func colorWithAlpha(alpha: Double) -> Color {
return Color(red: red, green: green, blue: blue, alpha: alpha)
}
}

// MARK: - Casting to UIColor and CIColor

public extension UIColor {
/// Initializes a UIColor object from a C4Color object.
/// Initializes a UIColor object from a Color object.
/// - parameter color: The C4 color object.
public convenience init?(_ color: C4Color) {
public convenience init?(_ color: Color) {
self.init(CGColor: color.CGColor)
}
}

public extension CIColor {
/// Initializes a CIColor object from a C4Color object.
/// Initializes a CIColor object from a Color object.
/// - parameter color: The C4 color object.
public convenience init(_ color: C4Color) {
public convenience init(_ color: Color) {
self.init(CGColor: color.CGColor)
}
}
4 changes: 2 additions & 2 deletions C4/Core/C4EventSource.swift → C4/Core/EventSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import Foundation

///This protocol defines 3 required methods for objects to post and listen for notifications, as well as cancel.
public protocol C4EventSource {
public protocol EventSource {

/// Posts a new notification originating from the receiver.
///
Expand All @@ -45,7 +45,7 @@ public protocol C4EventSource {
}

/// This extension allows any NSObject to post and listen for events in the same way as C4 objects.
extension NSObject : C4EventSource {
extension NSObject : EventSource {
/// Posts a new notification originating from the receiver.
///
/// ````
Expand Down
4 changes: 2 additions & 2 deletions C4/Core/C4Foundation.swift → C4/Core/Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public func CGRectMakeFromPoints(points: [CGPoint]) -> CGRect {
///
/// - parameter delay: The amount of time in seconds to wait before executing the block of code.
/// - parameter action: A block of code to perform after the delay.
public func delay(delay: Double, action: ()->()) {
public func wait(seconds: Double, action: ()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
Int64(seconds * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), action)
}
File renamed without changes.
Loading