Skip to content
This repository has been archived by the owner on Oct 28, 2018. It is now read-only.

Commit

Permalink
Fixed color picker Profile conversion and re-added native Color picker (
Browse files Browse the repository at this point in the history
closes #24, #9, #26, #21)
  • Loading branch information
Cédric committed Oct 9, 2017
1 parent ab003e5 commit 5a8778e
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 23 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Colour Contrast Analyser/ColourDeficiencyAlgorithm.swift"
timestampString = "528989606.820743"
timestampString = "529030487.86471"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "121"
Expand All @@ -138,7 +138,7 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Colour Contrast Analyser/CCAColourDeficiencyController.swift"
timestampString = "528989606.820792"
timestampString = "528994029.218234"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "35"
Expand Down
19 changes: 17 additions & 2 deletions Colour Contrast Analyser/CCAColour.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@ class CCAColour {
}

func update(_ value: NSColor) {
self.value = value
self.hexvalue = value.getHexString()
/*
print("\n\n")
print(value.getHexString())
print(value)
print(value.usingColorSpace(NSColorSpace.deviceRGB)!.getHexString())
print(value.usingColorSpace(NSColorSpace.deviceRGB)!)
print(value.usingColorSpace(NSColorSpace.sRGB)!.getHexString())
print(value.usingColorSpace(NSColorSpace.sRGB)!)
print(value.usingColorSpace(NSColorSpace.genericRGB)!.getHexString())
print(value.usingColorSpace(NSColorSpace.genericRGB)!)
print(value.usingColorSpaceName(NSColorSpaceName.calibratedRGB)!.getHexString())
print(value.usingColorSpaceName(NSColorSpaceName.calibratedRGB)!)
print(value.usingColorSpaceName(NSColorSpaceName.deviceRGB)!.getHexString())
print(value.usingColorSpaceName(NSColorSpaceName.deviceRGB)!)
*/
self.value = value.usingColorSpace(NSColorSpace.sRGB)!
self.hexvalue = self.value.getHexString()
let userInfo = ["color" : self.value]
NotificationCenter.default.post(name: Notification.Name(rawValue: self.notification), object: nil, userInfo: userInfo)
}
Expand Down
18 changes: 17 additions & 1 deletion Colour Contrast Analyser/CCAColourHeaderController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class CCAColourHeaderController: NSView {

@IBOutlet var view: NSView!
@IBOutlet weak var title: NSTextField!

@IBOutlet weak var colorWell: NSColorWell!

var pickerController = CCAPickerController(windowNibName: NSNib.Name(rawValue: "ColourPicker"))

override init(frame frameRect: NSRect) {
Expand Down Expand Up @@ -45,13 +46,26 @@ class CCAColourHeaderController: NSView {
pickerController.open(self.color)
}

@IBAction func colorWellChanged(_ sender: NSColorWell) {
self.color.update(sender.color)
}

@objc func update(_ notification: Notification) {
self.updateColorWell()
}

func updateColorWell() {
self.colorWell.color = self.color.value
}
}

class CCAForegroundColourHeaderController: CCAColourHeaderController {
required init?(coder: NSCoder) {
super.init(coder: coder)
self.title.stringValue = "Foreground Colour"
self.color = CCAColourForeground.sharedInstance
self.updateColorWell()
NotificationCenter.default.addObserver(self, selector: #selector(CCAColourHeaderController.update(_:)), name: NSNotification.Name(rawValue: "ForegroundColorChangedNotification"), object: nil)
}
}

Expand All @@ -60,5 +74,7 @@ class CCABackgroundColourHeaderController: CCAColourHeaderController {
super.init(coder: coder)
self.title.stringValue = "Background Colour"
self.color = CCAColourBackground.sharedInstance
self.updateColorWell()
NotificationCenter.default.addObserver(self, selector: #selector(CCAColourHeaderController.update(_:)), name: NSNotification.Name(rawValue: "BackgroundColorChangedNotification"), object: nil)
}
}
5 changes: 3 additions & 2 deletions Colour Contrast Analyser/CCAColourPreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CCAColourPreviewController: NSView, NSTextFieldDelegate {
@IBOutlet var view: NSView!
@IBOutlet weak var hexField: NSTextField!
@IBOutlet weak var warning: NSImageView!

override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
}
Expand Down Expand Up @@ -45,8 +45,9 @@ class CCAColourPreviewController: NSView, NSTextFieldDelegate {
self.updateHex()
self.updatePreview()
}

func updatePreview() {
self.view.alphaValue = 1
self.view.layer?.backgroundColor = self.color.value.cgColor
}

Expand Down
15 changes: 10 additions & 5 deletions Colour Contrast Analyser/CCAPickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CCAPickerController: NSWindowController {
var color: CCAColour!
var cgImage:CGImage?
var dimension:UInt = 0
var tmpcolor:NSColor?
var rawColor:NSColor?

let DEFAULT_DIMENSION:UInt = 128

Expand All @@ -44,7 +44,11 @@ class CCAPickerController: NSWindowController {
}

override func mouseUp(with theEvent: NSEvent) {
self.color.update(self.tmpcolor!)
print(self.pickerWindow.colorSpace!)
print(self.rawColor!)
let color = self.rawColor!.usingColorSpace(self.pickerWindow.colorSpace!)
print(color!)
self.color.update(color!)
self.close()
}

Expand Down Expand Up @@ -105,9 +109,10 @@ class CCAPickerController: NSWindowController {
pickerView.updateView(cgi, rect: rect)

// getting color
self.tmpcolor = colorAtLocation(location)
hexaText.backgroundColor = self.tmpcolor
hexaText.stringValue = self.tmpcolor!.getHexString()
self.rawColor = colorAtLocation(location)

hexaText.backgroundColor = self.rawColor!
hexaText.stringValue = self.rawColor!.getHexString()
}

func getScreenRect(_ point:NSPoint) -> NSRect {
Expand Down
33 changes: 27 additions & 6 deletions Colour Contrast Analyser/ColourHeaderView.xib
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13196" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13196"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="CCAColourHeaderController" customModule="Colour_Contrast_Analyser" customModuleProvider="target">
<connections>
<outlet property="colorWell" destination="18C-tu-Yiu" id="T7H-g6-nqi"/>
<outlet property="title" destination="DiW-ok-W4W" id="Mm6-hV-m6F"/>
<outlet property="view" destination="c22-O7-iKe" id="Vfy-uR-oE2"/>
</connections>
Expand All @@ -25,8 +27,8 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="4aF-Lm-V75" userLabel="Picker">
<rect key="frame" x="401" y="13" width="69" height="19"/>
<button hidden="YES" verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4aF-Lm-V75" userLabel="Picker">
<rect key="frame" x="327" y="13" width="69" height="19"/>
<buttonCell key="cell" type="roundRect" title="Picker" bezelStyle="roundedRect" image="NSRevealFreestandingTemplate" imagePosition="left" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="GsJ-Iz-9ra" userLabel="Picker">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="cellTitle"/>
Expand All @@ -35,12 +37,31 @@
<action selector="colorPickerClicked:" target="-2" id="dP6-dl-Y3f"/>
</connections>
</button>
<colorWell translatesAutoresizingMaskIntoConstraints="NO" id="18C-tu-Yiu">
<rect key="frame" x="426" y="12" width="44" height="22"/>
<constraints>
<constraint firstAttribute="height" constant="22" id="dGi-1e-Yrx"/>
<constraint firstAttribute="width" constant="44" id="u1U-aG-zVT"/>
</constraints>
<color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<connections>
<action selector="colorWellChanged:" target="-2" id="fFw-sM-2I8"/>
</connections>
</colorWell>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="zvm-xZ-nCX">
<rect key="frame" x="407" y="16" width="14" height="14"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="NSRevealFreestandingTemplate" id="ycX-Ix-mkA"/>
</imageView>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="4aF-Lm-V75" secondAttribute="trailing" constant="10" id="0Yc-LH-PgU"/>
<constraint firstAttribute="trailing" secondItem="18C-tu-Yiu" secondAttribute="trailing" constant="10" id="5hP-0d-zGN"/>
<constraint firstItem="18C-tu-Yiu" firstAttribute="leading" secondItem="4aF-Lm-V75" secondAttribute="trailing" constant="20" id="6dw-Sb-ZMo"/>
<constraint firstItem="18C-tu-Yiu" firstAttribute="leading" secondItem="zvm-xZ-nCX" secondAttribute="trailing" constant="5" id="6s9-J0-Azd"/>
<constraint firstItem="zvm-xZ-nCX" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="M0p-oG-qYj"/>
<constraint firstItem="4aF-Lm-V75" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="NdI-X5-RqK"/>
<constraint firstItem="DiW-ok-W4W" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" constant="10" id="bfH-mB-U8f"/>
<constraint firstItem="DiW-ok-W4W" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="g2t-Yd-eJL"/>
<constraint firstItem="18C-tu-Yiu" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="qZa-EK-FCO"/>
</constraints>
<point key="canvasLocation" x="288" y="410"/>
</customView>
Expand Down
7 changes: 4 additions & 3 deletions Colour Contrast Analyser/ColourPreviewView.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13196" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13196"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="CCAColourPreviewController" customModule="Colour_Contrast_Analyser" customModuleProvider="target">
Expand Down
7 changes: 5 additions & 2 deletions Colour Contrast Analyser/SwiftColors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ extension NSColor {


func getSRGBColor() -> NSColor {
let sRGB:NSColorSpace = NSColorSpace.genericRGB
let components = [self.redComponent, self.greenComponent, self.blueComponent]
/*
let sRGB:NSColorSpace = NSColorSpace.sRGB
let components = [self.redComponent, self.greenComponent, self.blueComponent, 1.0]
return NSColor(colorSpace:sRGB, components:components, count:4);
*/
return self.usingColorSpace(NSColorSpace.sRGB)!
}

func grayScaleComponent() -> CGFloat {
Expand Down

0 comments on commit 5a8778e

Please sign in to comment.