├── .gitignore ├── Color Picker Plus.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── WorkspaceSettings.xcsettings └── xcuserdata │ └── viktorstrate.xcuserdatad │ └── xcschemes │ ├── Debug.xcscheme │ ├── Release.xcscheme │ └── xcschememanagement.plist ├── Color Picker Plus ├── ColorPickerPlus.swift ├── ColorPickerPlus.xib ├── ColorRepresentingTextField.swift ├── Info.plist ├── Models │ ├── HSV.swift │ └── RGB.swift ├── ScrollingTextField.swift ├── ToolbarIcon.tiff ├── Utils │ ├── ColorUndoManager.swift │ ├── HSBGen.swift │ └── Logger.swift └── Views │ ├── ColorGraphicsView.swift │ ├── ContainerView.swift │ └── CurrentColorView.swift ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | 3 | ## User settings 4 | xcuserdata/ 5 | -------------------------------------------------------------------------------- /Color Picker Plus.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3426013B20E159BA00767696 /* ColorUndoManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3426013A20E159BA00767696 /* ColorUndoManager.swift */; }; 11 | 34414FA220E3C7E200E0E67A /* ColorRepresentingTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34414FA120E3C7E200E0E67A /* ColorRepresentingTextField.swift */; }; 12 | 344AA57720DFEBEA0045C7B2 /* Color Picker Plus.colorPicker in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3491077020D13DDC0058E50D /* Color Picker Plus.colorPicker */; }; 13 | 34509CE420D328C400CF78C0 /* RGB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34509CE320D328C400CF78C0 /* RGB.swift */; }; 14 | 34509CE620D3293500CF78C0 /* HSV.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34509CE520D3293500CF78C0 /* HSV.swift */; }; 15 | 34509CEA20D3ADDF00CF78C0 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34509CE920D3ADDF00CF78C0 /* Logger.swift */; }; 16 | 347FCA7B20E13FE000C6C34A /* ContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347FCA7A20E13FE000C6C34A /* ContainerView.swift */; }; 17 | 3491077A20D13DF80058E50D /* ColorPickerPlus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3491077920D13DF80058E50D /* ColorPickerPlus.swift */; }; 18 | 3491078020D149740058E50D /* ToolbarIcon.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 3491077F20D149740058E50D /* ToolbarIcon.tiff */; }; 19 | 3491078220D14A080058E50D /* ColorPickerPlus.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3491078120D14A080058E50D /* ColorPickerPlus.xib */; }; 20 | 3491078620D164BF0058E50D /* ColorGraphicsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3491078520D164BF0058E50D /* ColorGraphicsView.swift */; }; 21 | 3491078820D1771D0058E50D /* HSBGen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3491078720D1771D0058E50D /* HSBGen.swift */; }; 22 | 34BC620F20D27DA90093CCFC /* CurrentColorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34BC620E20D27DA90093CCFC /* CurrentColorView.swift */; }; 23 | 34CEE9C820E267CC00D56DF9 /* ScrollingTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34CEE9C720E267CC00D56DF9 /* ScrollingTextField.swift */; }; 24 | /* End PBXBuildFile section */ 25 | 26 | /* Begin PBXCopyFilesBuildPhase section */ 27 | 344AA57620DFEBB00045C7B2 /* CopyFiles */ = { 28 | isa = PBXCopyFilesBuildPhase; 29 | buildActionMask = 2147483647; 30 | dstPath = $HOME/Library/ColorPickers; 31 | dstSubfolderSpec = 0; 32 | files = ( 33 | 344AA57720DFEBEA0045C7B2 /* Color Picker Plus.colorPicker in CopyFiles */, 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXCopyFilesBuildPhase section */ 38 | 39 | /* Begin PBXFileReference section */ 40 | 3426013A20E159BA00767696 /* ColorUndoManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorUndoManager.swift; sourceTree = ""; }; 41 | 34414FA120E3C7E200E0E67A /* ColorRepresentingTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorRepresentingTextField.swift; sourceTree = ""; }; 42 | 34509CE320D328C400CF78C0 /* RGB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RGB.swift; sourceTree = ""; }; 43 | 34509CE520D3293500CF78C0 /* HSV.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HSV.swift; sourceTree = ""; }; 44 | 34509CE920D3ADDF00CF78C0 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = ""; }; 45 | 347FCA7A20E13FE000C6C34A /* ContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerView.swift; sourceTree = ""; }; 46 | 3491077020D13DDC0058E50D /* Color Picker Plus.colorPicker */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Color Picker Plus.colorPicker"; sourceTree = BUILT_PRODUCTS_DIR; }; 47 | 3491077320D13DDC0058E50D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 48 | 3491077920D13DF80058E50D /* ColorPickerPlus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPickerPlus.swift; sourceTree = ""; }; 49 | 3491077F20D149740058E50D /* ToolbarIcon.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = ToolbarIcon.tiff; sourceTree = ""; }; 50 | 3491078120D14A080058E50D /* ColorPickerPlus.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ColorPickerPlus.xib; sourceTree = ""; }; 51 | 3491078520D164BF0058E50D /* ColorGraphicsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorGraphicsView.swift; sourceTree = ""; }; 52 | 3491078720D1771D0058E50D /* HSBGen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HSBGen.swift; sourceTree = ""; }; 53 | 34BC620E20D27DA90093CCFC /* CurrentColorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentColorView.swift; sourceTree = ""; }; 54 | 34CEE9C720E267CC00D56DF9 /* ScrollingTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollingTextField.swift; sourceTree = ""; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | 3491076D20D13DDC0058E50D /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | /* End PBXFrameworksBuildPhase section */ 66 | 67 | /* Begin PBXGroup section */ 68 | 34414FA320E3CC7A00E0E67A /* Views */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 3491078520D164BF0058E50D /* ColorGraphicsView.swift */, 72 | 34BC620E20D27DA90093CCFC /* CurrentColorView.swift */, 73 | 347FCA7A20E13FE000C6C34A /* ContainerView.swift */, 74 | ); 75 | path = Views; 76 | sourceTree = ""; 77 | }; 78 | 34414FA420E3CCA200E0E67A /* Utils */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 3426013A20E159BA00767696 /* ColorUndoManager.swift */, 82 | 34509CE920D3ADDF00CF78C0 /* Logger.swift */, 83 | 3491078720D1771D0058E50D /* HSBGen.swift */, 84 | ); 85 | path = Utils; 86 | sourceTree = ""; 87 | }; 88 | 34509CE220D328B000CF78C0 /* Models */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 34509CE320D328C400CF78C0 /* RGB.swift */, 92 | 34509CE520D3293500CF78C0 /* HSV.swift */, 93 | ); 94 | path = Models; 95 | sourceTree = ""; 96 | }; 97 | 3491076720D13DDC0058E50D = { 98 | isa = PBXGroup; 99 | children = ( 100 | 3491077220D13DDC0058E50D /* Color Picker Plus */, 101 | 3491077120D13DDC0058E50D /* Products */, 102 | ); 103 | sourceTree = ""; 104 | }; 105 | 3491077120D13DDC0058E50D /* Products */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 3491077020D13DDC0058E50D /* Color Picker Plus.colorPicker */, 109 | ); 110 | name = Products; 111 | sourceTree = ""; 112 | }; 113 | 3491077220D13DDC0058E50D /* Color Picker Plus */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 34414FA420E3CCA200E0E67A /* Utils */, 117 | 34509CE220D328B000CF78C0 /* Models */, 118 | 34414FA320E3CC7A00E0E67A /* Views */, 119 | 3491077F20D149740058E50D /* ToolbarIcon.tiff */, 120 | 3491077320D13DDC0058E50D /* Info.plist */, 121 | 3491077920D13DF80058E50D /* ColorPickerPlus.swift */, 122 | 3491078120D14A080058E50D /* ColorPickerPlus.xib */, 123 | 34CEE9C720E267CC00D56DF9 /* ScrollingTextField.swift */, 124 | 34414FA120E3C7E200E0E67A /* ColorRepresentingTextField.swift */, 125 | ); 126 | path = "Color Picker Plus"; 127 | sourceTree = ""; 128 | }; 129 | /* End PBXGroup section */ 130 | 131 | /* Begin PBXNativeTarget section */ 132 | 3491076F20D13DDC0058E50D /* Color Picker Plus */ = { 133 | isa = PBXNativeTarget; 134 | buildConfigurationList = 3491077620D13DDC0058E50D /* Build configuration list for PBXNativeTarget "Color Picker Plus" */; 135 | buildPhases = ( 136 | 3491076C20D13DDC0058E50D /* Sources */, 137 | 3491076D20D13DDC0058E50D /* Frameworks */, 138 | 3491076E20D13DDC0058E50D /* Resources */, 139 | 344AA57620DFEBB00045C7B2 /* CopyFiles */, 140 | ); 141 | buildRules = ( 142 | ); 143 | dependencies = ( 144 | ); 145 | name = "Color Picker Plus"; 146 | productName = "Color Picker Plus"; 147 | productReference = 3491077020D13DDC0058E50D /* Color Picker Plus.colorPicker */; 148 | productType = "com.apple.product-type.bundle"; 149 | }; 150 | /* End PBXNativeTarget section */ 151 | 152 | /* Begin PBXProject section */ 153 | 3491076820D13DDC0058E50D /* Project object */ = { 154 | isa = PBXProject; 155 | attributes = { 156 | LastUpgradeCheck = 1010; 157 | ORGANIZATIONNAME = "Viktor Hundahl Strate"; 158 | TargetAttributes = { 159 | 3491076F20D13DDC0058E50D = { 160 | CreatedOnToolsVersion = 9.4; 161 | LastSwiftMigration = 0940; 162 | }; 163 | }; 164 | }; 165 | buildConfigurationList = 3491076B20D13DDC0058E50D /* Build configuration list for PBXProject "Color Picker Plus" */; 166 | compatibilityVersion = "Xcode 9.3"; 167 | developmentRegion = en; 168 | hasScannedForEncodings = 0; 169 | knownRegions = ( 170 | en, 171 | ); 172 | mainGroup = 3491076720D13DDC0058E50D; 173 | productRefGroup = 3491077120D13DDC0058E50D /* Products */; 174 | projectDirPath = ""; 175 | projectRoot = ""; 176 | targets = ( 177 | 3491076F20D13DDC0058E50D /* Color Picker Plus */, 178 | ); 179 | }; 180 | /* End PBXProject section */ 181 | 182 | /* Begin PBXResourcesBuildPhase section */ 183 | 3491076E20D13DDC0058E50D /* Resources */ = { 184 | isa = PBXResourcesBuildPhase; 185 | buildActionMask = 2147483647; 186 | files = ( 187 | 3491078220D14A080058E50D /* ColorPickerPlus.xib in Resources */, 188 | 3491078020D149740058E50D /* ToolbarIcon.tiff in Resources */, 189 | ); 190 | runOnlyForDeploymentPostprocessing = 0; 191 | }; 192 | /* End PBXResourcesBuildPhase section */ 193 | 194 | /* Begin PBXSourcesBuildPhase section */ 195 | 3491076C20D13DDC0058E50D /* Sources */ = { 196 | isa = PBXSourcesBuildPhase; 197 | buildActionMask = 2147483647; 198 | files = ( 199 | 34509CE420D328C400CF78C0 /* RGB.swift in Sources */, 200 | 3491077A20D13DF80058E50D /* ColorPickerPlus.swift in Sources */, 201 | 3491078620D164BF0058E50D /* ColorGraphicsView.swift in Sources */, 202 | 34509CEA20D3ADDF00CF78C0 /* Logger.swift in Sources */, 203 | 3426013B20E159BA00767696 /* ColorUndoManager.swift in Sources */, 204 | 34CEE9C820E267CC00D56DF9 /* ScrollingTextField.swift in Sources */, 205 | 347FCA7B20E13FE000C6C34A /* ContainerView.swift in Sources */, 206 | 34509CE620D3293500CF78C0 /* HSV.swift in Sources */, 207 | 34BC620F20D27DA90093CCFC /* CurrentColorView.swift in Sources */, 208 | 3491078820D1771D0058E50D /* HSBGen.swift in Sources */, 209 | 34414FA220E3C7E200E0E67A /* ColorRepresentingTextField.swift in Sources */, 210 | ); 211 | runOnlyForDeploymentPostprocessing = 0; 212 | }; 213 | /* End PBXSourcesBuildPhase section */ 214 | 215 | /* Begin XCBuildConfiguration section */ 216 | 3491077420D13DDC0058E50D /* Debug */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | ALWAYS_SEARCH_USER_PATHS = NO; 220 | CLANG_ANALYZER_NONNULL = YES; 221 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 222 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 223 | CLANG_CXX_LIBRARY = "libc++"; 224 | CLANG_ENABLE_MODULES = YES; 225 | CLANG_ENABLE_OBJC_ARC = YES; 226 | CLANG_ENABLE_OBJC_WEAK = YES; 227 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 228 | CLANG_WARN_BOOL_CONVERSION = YES; 229 | CLANG_WARN_COMMA = YES; 230 | CLANG_WARN_CONSTANT_CONVERSION = YES; 231 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 232 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 233 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 234 | CLANG_WARN_EMPTY_BODY = YES; 235 | CLANG_WARN_ENUM_CONVERSION = YES; 236 | CLANG_WARN_INFINITE_RECURSION = YES; 237 | CLANG_WARN_INT_CONVERSION = YES; 238 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 239 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 240 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 241 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 242 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 243 | CLANG_WARN_STRICT_PROTOTYPES = YES; 244 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 245 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 246 | CLANG_WARN_UNREACHABLE_CODE = YES; 247 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 248 | CODE_SIGN_IDENTITY = "-"; 249 | COPY_PHASE_STRIP = NO; 250 | DEBUG_INFORMATION_FORMAT = dwarf; 251 | ENABLE_STRICT_OBJC_MSGSEND = YES; 252 | ENABLE_TESTABILITY = YES; 253 | GCC_C_LANGUAGE_STANDARD = gnu11; 254 | GCC_DYNAMIC_NO_PIC = NO; 255 | GCC_NO_COMMON_BLOCKS = YES; 256 | GCC_OPTIMIZATION_LEVEL = 0; 257 | GCC_PREPROCESSOR_DEFINITIONS = ( 258 | "DEBUG=1", 259 | "$(inherited)", 260 | ); 261 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 262 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 263 | GCC_WARN_UNDECLARED_SELECTOR = YES; 264 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 265 | GCC_WARN_UNUSED_FUNCTION = YES; 266 | GCC_WARN_UNUSED_VARIABLE = YES; 267 | MACOSX_DEPLOYMENT_TARGET = 10.13; 268 | MTL_ENABLE_DEBUG_INFO = YES; 269 | ONLY_ACTIVE_ARCH = YES; 270 | SDKROOT = macosx; 271 | }; 272 | name = Debug; 273 | }; 274 | 3491077520D13DDC0058E50D /* Release */ = { 275 | isa = XCBuildConfiguration; 276 | buildSettings = { 277 | ALWAYS_SEARCH_USER_PATHS = NO; 278 | CLANG_ANALYZER_NONNULL = YES; 279 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 280 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 281 | CLANG_CXX_LIBRARY = "libc++"; 282 | CLANG_ENABLE_MODULES = YES; 283 | CLANG_ENABLE_OBJC_ARC = YES; 284 | CLANG_ENABLE_OBJC_WEAK = YES; 285 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 286 | CLANG_WARN_BOOL_CONVERSION = YES; 287 | CLANG_WARN_COMMA = YES; 288 | CLANG_WARN_CONSTANT_CONVERSION = YES; 289 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 290 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 291 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 292 | CLANG_WARN_EMPTY_BODY = YES; 293 | CLANG_WARN_ENUM_CONVERSION = YES; 294 | CLANG_WARN_INFINITE_RECURSION = YES; 295 | CLANG_WARN_INT_CONVERSION = YES; 296 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 297 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 298 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 299 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 300 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 301 | CLANG_WARN_STRICT_PROTOTYPES = YES; 302 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 303 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 304 | CLANG_WARN_UNREACHABLE_CODE = YES; 305 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 306 | CODE_SIGN_IDENTITY = "-"; 307 | COPY_PHASE_STRIP = NO; 308 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 309 | ENABLE_NS_ASSERTIONS = NO; 310 | ENABLE_STRICT_OBJC_MSGSEND = YES; 311 | GCC_C_LANGUAGE_STANDARD = gnu11; 312 | GCC_NO_COMMON_BLOCKS = YES; 313 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 314 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 315 | GCC_WARN_UNDECLARED_SELECTOR = YES; 316 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 317 | GCC_WARN_UNUSED_FUNCTION = YES; 318 | GCC_WARN_UNUSED_VARIABLE = YES; 319 | MACOSX_DEPLOYMENT_TARGET = 10.13; 320 | MTL_ENABLE_DEBUG_INFO = NO; 321 | SDKROOT = macosx; 322 | SWIFT_COMPILATION_MODE = wholemodule; 323 | }; 324 | name = Release; 325 | }; 326 | 3491077720D13DDC0058E50D /* Debug */ = { 327 | isa = XCBuildConfiguration; 328 | buildSettings = { 329 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 330 | CLANG_ENABLE_MODULES = YES; 331 | CODE_SIGN_STYLE = Automatic; 332 | COMBINE_HIDPI_IMAGES = YES; 333 | INFOPLIST_FILE = "Color Picker Plus/Info.plist"; 334 | LD_RUNPATH_SEARCH_PATHS = ( 335 | "$(inherited)", 336 | "@executable_path/../Frameworks", 337 | "@loader_path/../Frameworks", 338 | ); 339 | OTHER_SWIFT_FLAGS = "-D DEBUG"; 340 | PRODUCT_BUNDLE_IDENTIFIER = "dk.qpqp.Color-Picker-Plus"; 341 | PRODUCT_NAME = "$(TARGET_NAME)"; 342 | SKIP_INSTALL = YES; 343 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 344 | SWIFT_VERSION = 4.0; 345 | WRAPPER_EXTENSION = colorPicker; 346 | }; 347 | name = Debug; 348 | }; 349 | 3491077820D13DDC0058E50D /* Release */ = { 350 | isa = XCBuildConfiguration; 351 | buildSettings = { 352 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 353 | CLANG_ENABLE_MODULES = YES; 354 | CODE_SIGN_STYLE = Automatic; 355 | COMBINE_HIDPI_IMAGES = YES; 356 | INFOPLIST_FILE = "Color Picker Plus/Info.plist"; 357 | LD_RUNPATH_SEARCH_PATHS = ( 358 | "$(inherited)", 359 | "@executable_path/../Frameworks", 360 | "@loader_path/../Frameworks", 361 | ); 362 | PRODUCT_BUNDLE_IDENTIFIER = "dk.qpqp.Color-Picker-Plus"; 363 | PRODUCT_NAME = "$(TARGET_NAME)"; 364 | SKIP_INSTALL = YES; 365 | SWIFT_VERSION = 4.0; 366 | WRAPPER_EXTENSION = colorPicker; 367 | }; 368 | name = Release; 369 | }; 370 | /* End XCBuildConfiguration section */ 371 | 372 | /* Begin XCConfigurationList section */ 373 | 3491076B20D13DDC0058E50D /* Build configuration list for PBXProject "Color Picker Plus" */ = { 374 | isa = XCConfigurationList; 375 | buildConfigurations = ( 376 | 3491077420D13DDC0058E50D /* Debug */, 377 | 3491077520D13DDC0058E50D /* Release */, 378 | ); 379 | defaultConfigurationIsVisible = 0; 380 | defaultConfigurationName = Release; 381 | }; 382 | 3491077620D13DDC0058E50D /* Build configuration list for PBXNativeTarget "Color Picker Plus" */ = { 383 | isa = XCConfigurationList; 384 | buildConfigurations = ( 385 | 3491077720D13DDC0058E50D /* Debug */, 386 | 3491077820D13DDC0058E50D /* Release */, 387 | ); 388 | defaultConfigurationIsVisible = 0; 389 | defaultConfigurationName = Release; 390 | }; 391 | /* End XCConfigurationList section */ 392 | }; 393 | rootObject = 3491076820D13DDC0058E50D /* Project object */; 394 | } 395 | -------------------------------------------------------------------------------- /Color Picker Plus.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Color Picker Plus.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Color Picker Plus.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Color Picker Plus.xcodeproj/xcuserdata/viktorstrate.xcuserdatad/xcschemes/Debug.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Color Picker Plus.xcodeproj/xcuserdata/viktorstrate.xcuserdatad/xcschemes/Release.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Color Picker Plus.xcodeproj/xcuserdata/viktorstrate.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Debug.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | Release.xcscheme 13 | 14 | orderHint 15 | 1 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 3491076F20D13DDC0058E50D 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Color Picker Plus/ColorPickerPlus.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ColorPickerPlus.swift 3 | // Color Picker Plus 4 | // 5 | // Created by Viktor Hundahl Strate on 13/06/2018. 6 | // 7 | 8 | import Foundation 9 | import AppKit 10 | 11 | public class ColorPickerPlus: NSColorPicker, NSColorPickingCustom { 12 | 13 | static var shared: ColorPickerPlus! 14 | 15 | @IBOutlet var pickerView: ContainerView! 16 | @IBOutlet weak var colorGraphicsView: ColorGraphicsView! 17 | @IBOutlet weak var currentColorView: CurrentColorView! 18 | 19 | @IBOutlet weak var radioHue: NSButton! 20 | @IBOutlet weak var radioSaturation: NSButton! 21 | @IBOutlet weak var radioBrightness: NSButton! 22 | 23 | @IBOutlet weak var txtHue: ColorRepresentingTextField! 24 | @IBOutlet weak var txtSaturation: ColorRepresentingTextField! 25 | @IBOutlet weak var txtBrightness: ColorRepresentingTextField! 26 | @IBOutlet weak var txtHex: ColorRepresentingTextField! 27 | 28 | @IBOutlet weak var txtRed: ColorRepresentingTextField! 29 | @IBOutlet weak var txtGreen: ColorRepresentingTextField! 30 | @IBOutlet weak var txtBlue: ColorRepresentingTextField! 31 | @IBOutlet weak var txtAlpha: ColorRepresentingTextField! 32 | 33 | @IBOutlet weak var labelRed: ScrollingTextField! 34 | @IBOutlet weak var labelGreen: ScrollingTextField! 35 | @IBOutlet weak var labelBlue: ScrollingTextField! 36 | @IBOutlet weak var labelAlpha: ScrollingTextField! 37 | 38 | @IBOutlet weak var copyPopUp: NSPopUpButton! 39 | 40 | var firstColorChange = true 41 | var currentColor: HSV { 42 | get { 43 | return colorGraphicsView.currentColor 44 | } 45 | } 46 | 47 | var undoManager: ColorUndoManager? 48 | 49 | var textFieldsNumberFormatter: NumberFormatter! 50 | 51 | public func supportsMode(_ mode: NSColorPanel.Mode) -> Bool { 52 | return true 53 | } 54 | 55 | public func currentMode() -> NSColorPanel.Mode { 56 | return NSColorPanel.Mode.HSB 57 | } 58 | 59 | public func provideNewView(_ initialRequest: Bool) -> NSView { 60 | if (initialRequest) { 61 | 62 | ColorPickerPlus.shared = self 63 | 64 | let pickerNibName = "ColorPickerPlus" 65 | guard bundle.loadNibNamed(NSNib.Name(rawValue: pickerNibName), owner: self, topLevelObjects: nil) else { 66 | Logger.error(message: "Could not find nib named \(pickerNibName)") 67 | fatalError() 68 | } 69 | 70 | // MARK: Initial UI Setup 71 | radioHue.state = NSControl.StateValue.on 72 | 73 | colorGraphicsView.delegate = self 74 | 75 | let formatter = NumberFormatter() 76 | formatter.numberStyle = .none 77 | 78 | self.textFieldsNumberFormatter = formatter 79 | 80 | labelRed.setup(inputField: txtRed, formatter: formatter, min: 0, max: 255) 81 | labelGreen.setup(inputField: txtGreen, formatter: formatter, min: 0, max: 255) 82 | labelBlue.setup(inputField: txtBlue, formatter: formatter, min: 0, max: 255) 83 | labelAlpha.setup(inputField: txtAlpha, formatter: formatter) 84 | 85 | txtHex.isHexField = true 86 | 87 | } 88 | 89 | Logger.debug(message: "Picker view \(String(describing: pickerView))") 90 | 91 | return pickerView 92 | } 93 | 94 | /// Function from protocol NSColorPickingCustom 95 | /// Don't call this function directly, instead use setColor(hsv: HSV) 96 | public func setColor(_ newColor: NSColor) { 97 | Logger.debug(message: "Native - setColor(NSColor) called") 98 | let hsv = HSV(color: newColor) 99 | colorGraphicsView.currentColor = hsv 100 | 101 | if (!firstColorChange) { 102 | 103 | if self.undoManager == nil { 104 | self.undoManager = ColorUndoManager(colorPickerPlus: self, initialColor: hsv) 105 | } 106 | 107 | colorChanged(color: hsv) 108 | } else { 109 | firstColorChange = false 110 | } 111 | 112 | } 113 | 114 | /// Identical function to setColor(NSColor), 115 | /// but more accurate as it uses HSV instead of NSColor. 116 | public func setColor(hsv: HSV) { 117 | Logger.debug(message: "Improved - setColor(HSV) called") 118 | colorGraphicsView.currentColor = hsv 119 | colorChanged(color: hsv) 120 | } 121 | 122 | private let bundle = Bundle(for: ColorPickerPlus.self) 123 | 124 | public override var provideNewButtonImage: NSImage { 125 | let icon = bundle.image(forResource: NSImage.Name(rawValue: "ToolbarIcon"))! 126 | return icon 127 | } 128 | 129 | public override var minContentSize: NSSize { 130 | return NSSize(width: 574, height: 356) 131 | } 132 | 133 | public override var buttonToolTip: String { 134 | get { 135 | return "Color Picker Plus" 136 | } 137 | } 138 | 139 | @IBAction func copyAction(_ sender: NSPopUpButton) { 140 | Logger.debug(message: "Copy action called") 141 | 142 | var string = NSString(string: copyPopUp.selectedItem!.title) 143 | let startIndex = string.components(separatedBy: " - ")[0].count + 3 144 | 145 | string = NSString(string: string.substring(from: startIndex)) 146 | 147 | Logger.debug(message: "Copying value to clipboard: \(string)") 148 | 149 | let pasteboard = NSPasteboard.general 150 | 151 | pasteboard.clearContents() 152 | pasteboard.setString(string as String, forType: .string) 153 | } 154 | 155 | @IBAction func changeColorComponentAction(_ sender: NSButton) { 156 | Logger.debug(message: "Changing active color component") 157 | 158 | if (sender == radioHue) { 159 | radioBrightness.state = .off 160 | radioSaturation.state = .off 161 | 162 | colorGraphicsView.selectedHSBComponent = .hue 163 | 164 | } else if (sender == radioSaturation) { 165 | radioBrightness.state = .off 166 | radioHue.state = .off 167 | 168 | colorGraphicsView.selectedHSBComponent = .saturation 169 | 170 | } else if (sender == radioBrightness) { 171 | radioHue.state = .off 172 | radioSaturation.state = .off 173 | 174 | colorGraphicsView.selectedHSBComponent = .brightness 175 | 176 | } 177 | } 178 | 179 | /// Called when the user changes any of the text fields 180 | @IBAction func colorFieldChanged(_ sender: NSTextField) { 181 | Logger.debug(message: "Color textField changed \(sender.debugDescription)") 182 | 183 | // Hex text field 184 | if (sender == txtHex) { 185 | 186 | var hexString = NSString(string: txtHex.stringValue) 187 | 188 | if (hexString.length < 3) { 189 | return 190 | } 191 | 192 | if (hexString.character(at: 0) == NSString(string: "#").character(at: 0)) { 193 | hexString = NSString(string: hexString.substring(from: 1)) 194 | txtHex.stringValue = hexString as String 195 | } 196 | 197 | if (hexString.length == 3) { 198 | let first = hexString.substring(with: NSRange(location: 0, length: 1)) 199 | let secnd = hexString.substring(with: NSRange(location: 1, length: 1)) 200 | let thrd = hexString.substring(with: NSRange(location: 2, length: 1)) 201 | 202 | hexString = NSString(string: "\(first)\(first)\(secnd)\(secnd)\(thrd)\(thrd)") 203 | } 204 | 205 | guard let rgb = RGB.fromHEX(hexString) else { 206 | Logger.debug(message: "Provided hex input is invalid: \(hexString)") 207 | return 208 | } 209 | 210 | let hsv = rgb.toHSV() 211 | 212 | Logger.debug(message: "Converting RGB to HSV: \(rgb) -> \(hsv)") 213 | 214 | setColor(hsv: hsv) 215 | return 216 | } 217 | 218 | // Hue text field 219 | if (sender === txtHue) { 220 | 221 | let hue = formatColorNumber(string: txtHue.stringValue, minimum: 0, maximum: 360) 222 | 223 | if (hue != nil) { 224 | var newHSV = currentColor 225 | newHSV.h = hue! 226 | setColor(hsv: newHSV) 227 | } 228 | } 229 | 230 | // Saturation text field 231 | if (sender === txtSaturation) { 232 | 233 | let saturation = formatColorNumber(string: txtSaturation.stringValue, minimum: 0, maximum: 100) 234 | 235 | if (saturation != nil) { 236 | var newHSV = currentColor 237 | newHSV.s = saturation! / 100 238 | setColor(hsv: newHSV) 239 | } 240 | } 241 | 242 | // Brightness text field 243 | if (sender === txtBrightness) { 244 | 245 | let brightness = formatColorNumber(string: txtBrightness.stringValue, minimum: 0, maximum: 100) 246 | 247 | if (brightness != nil) { 248 | var newHSV = currentColor 249 | newHSV.v = brightness! / 100 250 | setColor(hsv: newHSV) 251 | } 252 | } 253 | 254 | // Alpha text field 255 | if (sender === txtAlpha) { 256 | 257 | let alpha = formatColorNumber(string: txtAlpha.stringValue, minimum: 0, maximum: 100) 258 | 259 | if (alpha != nil) { 260 | var newHSV = currentColor 261 | newHSV.a = alpha! / 100 262 | setColor(hsv: newHSV) 263 | } 264 | } 265 | 266 | // Red text field 267 | if (sender === txtRed) { 268 | let red = formatColorNumber(string: txtRed.stringValue, minimum: 0, maximum: 255) 269 | 270 | if (red != nil) { 271 | var newRGB = currentColor.toRGB() 272 | newRGB.r = red! / 255 273 | setColor(hsv: newRGB.toHSV()) 274 | } 275 | } 276 | 277 | // Green text field 278 | if (sender === txtGreen) { 279 | let green = formatColorNumber(string: txtGreen.stringValue, minimum: 0, maximum: 255) 280 | 281 | if (green != nil) { 282 | var newRGB = currentColor.toRGB() 283 | newRGB.g = green! / 255 284 | setColor(hsv: newRGB.toHSV()) 285 | } 286 | } 287 | 288 | // Blue text field 289 | if (sender === txtBlue) { 290 | let blue = formatColorNumber(string: txtBlue.stringValue, minimum: 0, maximum: 255) 291 | 292 | if (blue != nil) { 293 | var newRGB = currentColor.toRGB() 294 | newRGB.b = blue! / 255 295 | setColor(hsv: newRGB.toHSV()) 296 | } 297 | } 298 | 299 | } 300 | 301 | /// Format an input from a text field string, as a number in the range specified 302 | fileprivate func formatColorNumber(string: String, minimum: Int?, maximum: Int?) -> CGFloat? { 303 | 304 | let formatter = NumberFormatter() 305 | formatter.numberStyle = .none 306 | 307 | guard var number = formatter.number(from: string)?.intValue else { 308 | Logger.warn(message: "User specified a wrong input: '\(string)'") 309 | return nil 310 | } 311 | 312 | if (minimum != nil) { 313 | number = max(number, minimum!) 314 | } 315 | 316 | if (maximum != nil) { 317 | number = min(number, maximum!) 318 | } 319 | 320 | return CGFloat(number) 321 | } 322 | } 323 | 324 | extension ColorPickerPlus: ChangeColorDelegate { 325 | 326 | func colorChanged(color: HSV) { 327 | 328 | currentColorView.color = color.toNSColor() 329 | 330 | updateTextFields(color: color) 331 | 332 | super.colorPanel.color = color.toNSColor() 333 | 334 | } 335 | 336 | func colorSettled(color: HSV) { 337 | undoManager?.add(color: color) 338 | } 339 | 340 | // func updateColorFromTextFields() { 341 | // 342 | // let formatter = self.textFieldsNumberFormatter! 343 | // 344 | // // Check if HSV has changed 345 | // 346 | // let _newHue = formatter.number(from: txtHue.stringValue) 347 | // let _newSat = formatter.number(from: txtSaturation.stringValue) 348 | // let _newBright = formatter.number(from: txtBrightness.stringValue) 349 | // 350 | // guard let newHue = _newHue, let newSat = _newSat, let newBright = _newBright else { 351 | // Logger.warn(message: "Hue values incorrect, ignoring") 352 | // return 353 | // } 354 | // 355 | // } 356 | 357 | func updateTextFields(color: HSV) { 358 | var rgb = color.toRGB() 359 | let hsv = color 360 | 361 | // Converting between RGB and HSV is not perfect, because of rounding errors. 362 | // This checks if the old rgb (before the color update) is the same when converted from RGB -> HSV And not only just HSV -> RGB. 363 | // If they are equal, the RGB colors will not be changed 364 | let oldRgb = RGB.fromHEX(NSString(string: txtHex.stringValue)) 365 | 366 | if let oldRgb = oldRgb { 367 | if hsv.equals(hsv: oldRgb.toHSV()) { 368 | Logger.debug(message: "Old RGB is the same!\nOriginal: \(oldRgb)\nConverted: \(rgb)") 369 | rgb = oldRgb 370 | } 371 | } 372 | 373 | Logger.debug(message: "Colors HSV: \(hsv), RGB: \(rgb)") 374 | 375 | txtHex.stringValue = rgb.toHEX() 376 | 377 | let formatter = self.textFieldsNumberFormatter! 378 | 379 | txtHue.stringValue = formatter.string(from: hsv.h as NSNumber)! 380 | txtSaturation.stringValue = formatter.string(from: (hsv.s * 100) as NSNumber)! 381 | txtBrightness.stringValue = formatter.string(from: (hsv.v * 100) as NSNumber)! 382 | 383 | txtRed.stringValue = formatter.string(from: (rgb.r * 255) as NSNumber)! 384 | txtGreen.stringValue = formatter.string(from: (rgb.g * 255) as NSNumber)! 385 | txtBlue.stringValue = formatter.string(from: (rgb.b * 255) as NSNumber)! 386 | 387 | txtAlpha.stringValue = formatter.string(from: (hsv.a * 100) as NSNumber)! 388 | 389 | let floatingNumberFormatter = NumberFormatter() 390 | floatingNumberFormatter.numberStyle = .decimal 391 | floatingNumberFormatter.maximumSignificantDigits = 3 392 | floatingNumberFormatter.decimalSeparator = "." 393 | 394 | let floatR = floatingNumberFormatter.string(from: NSNumber(value: Float(rgb.r)))! 395 | let floatG = floatingNumberFormatter.string(from: NSNumber(value: Float(rgb.g)))! 396 | let floatB = floatingNumberFormatter.string(from: NSNumber(value: Float(rgb.b)))! 397 | 398 | copyPopUp.removeAllItems() 399 | let copyMenu = copyPopUp.menu! 400 | 401 | copyMenu.addItem(withTitle: "Copy", action: nil, keyEquivalent: "") 402 | 403 | let hexItem = NSMenuItem(title: "HEX - #\(rgb.toHEX())", action: nil, keyEquivalent: "c") 404 | hexItem.keyEquivalentModifierMask = [.control] 405 | 406 | copyMenu.addItem(hexItem) 407 | 408 | let rgbItem = NSMenuItem(title: "RGB - \(txtRed.stringValue), \(txtGreen.stringValue), \(txtBlue.stringValue)", action: nil, keyEquivalent: "r") 409 | rgbItem.keyEquivalentModifierMask = [.control] 410 | 411 | copyMenu.addItem(rgbItem) 412 | 413 | let floatRGBItem = NSMenuItem(title: "Float RGB - \(floatR), \(floatG), \(floatB)", action: nil, keyEquivalent: "R") 414 | floatRGBItem.keyEquivalentModifierMask = [.control] 415 | 416 | copyMenu.addItem(floatRGBItem) 417 | 418 | let hsvItem = NSMenuItem(title: "HSV - \(txtHue.stringValue), \(txtSaturation.stringValue), \(txtBrightness.stringValue)", action: nil, keyEquivalent: "h") 419 | hsvItem.keyEquivalentModifierMask = [.control] 420 | 421 | copyMenu.addItem(hsvItem) 422 | 423 | copyMenu.addItem(NSMenuItem.separator()) 424 | 425 | let webRGBItem = NSMenuItem(title: "Web RGB - rgb(\(txtRed.stringValue), \(txtGreen.stringValue), \(txtBlue.stringValue))", action: nil, keyEquivalent: "w") 426 | webRGBItem.keyEquivalentModifierMask = [.control] 427 | 428 | copyMenu.addItem(webRGBItem) 429 | 430 | let webRGBaItem = NSMenuItem(title: "Web RGBa - rgba(\(txtRed.stringValue), \(txtGreen.stringValue), \(txtBlue.stringValue), \(txtAlpha.stringValue))", action: nil, keyEquivalent: "w") 431 | webRGBaItem.keyEquivalentModifierMask = [.control, .shift] 432 | 433 | copyMenu.addItem(webRGBaItem) 434 | 435 | let webHSLItem = NSMenuItem(title: "Web HSL - hsl(\(txtHue.stringValue), \(txtSaturation.stringValue)%, \(txtBrightness.stringValue)%)", action: nil, keyEquivalent: "w") 436 | webHSLItem.keyEquivalentModifierMask = [.control, .option] 437 | 438 | copyMenu.addItem(webHSLItem) 439 | 440 | } 441 | 442 | } 443 | 444 | 445 | -------------------------------------------------------------------------------- /Color Picker Plus/ColorPickerPlus.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 103 | 113 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | -------------------------------------------------------------------------------- /Color Picker Plus/ColorRepresentingTextField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ColorRepresentingTextField.swift 3 | // Color Picker Plus 4 | // 5 | // Created by Viktor Hundahl Strate on 27/06/2018. 6 | // Copyright © 2018 Viktor Hundahl Strate. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class ColorRepresentingTextField: NSTextField, NSTextFieldDelegate { 12 | 13 | var isHexField: Bool = false 14 | 15 | override func awakeFromNib() { 16 | super.awakeFromNib() 17 | self.delegate = self 18 | } 19 | 20 | override func controlTextDidChange(_ obj: Notification) { 21 | Logger.debug(message: "Text field changed") 22 | 23 | if isHexField { 24 | if self.stringValue.count != 6 { 25 | Logger.debug(message: "Hex field is not 6 characters long, skipping color update") 26 | return 27 | } 28 | 29 | if RGB.fromHEX(NSString(string: self.stringValue)) == nil { 30 | Logger.debug(message: "Hex field does not contain a valid hex value, skipping color update") 31 | return 32 | } 33 | } 34 | 35 | ColorPickerPlus.shared.colorFieldChanged(self) 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Color Picker Plus/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.2 19 | CFBundleVersion 20 | 1 21 | NSHumanReadableCopyright 22 | General Public License v3 - viktorstrate 23 | NSPrincipalClass 24 | ColorPickerPlus.ColorPickerPlus 25 | 26 | 27 | -------------------------------------------------------------------------------- /Color Picker Plus/Models/HSV.swift: -------------------------------------------------------------------------------- 1 | // This file is based on the Huekit project by louisdh 2 | // Which is licensed under the MIT Licese 3 | // 4 | // https://github.com/louisdh/huekit 5 | 6 | import Foundation 7 | import AppKit 8 | 9 | public struct HSV: Hashable { 10 | /// In degrees (range 0...360) 11 | public var h: CGFloat 12 | 13 | /// Percentage in range 0...1 14 | public var s: CGFloat 15 | 16 | /// Percentage in range 0...1 17 | /// Also known as "brightness" (B) 18 | public var v: CGFloat 19 | 20 | public var a: CGFloat 21 | 22 | init (h: CGFloat, s: CGFloat, v: CGFloat) { 23 | self.h = h 24 | self.s = s 25 | self.v = v 26 | self.a = 1 27 | } 28 | 29 | init (h: CGFloat, s: CGFloat, v: CGFloat, a: CGFloat) { 30 | self.init(h: h, s: s, v: v) 31 | self.a = 1 32 | } 33 | } 34 | 35 | extension HSV { 36 | 37 | init (color: NSColor) { 38 | 39 | var convertedColor: NSColor! 40 | 41 | if (color.colorSpace != .genericRGB) { 42 | Logger.debug(message: "Changing colorspace from '\(color.colorSpace)' before converting to HSV") 43 | convertedColor = color.usingColorSpace(NSColorSpace.genericRGB)! 44 | } else { 45 | convertedColor = color 46 | } 47 | 48 | self.h = convertedColor.hueComponent * 360 49 | self.s = convertedColor.saturationComponent 50 | self.v = convertedColor.brightnessComponent 51 | self.a = convertedColor.alphaComponent 52 | } 53 | 54 | func toNSColor() -> NSColor { 55 | return NSColor(hue: h / 360, saturation: s, brightness: v, alpha: a) 56 | } 57 | 58 | func toRGB() -> RGB { 59 | var i: Int 60 | var f: CGFloat, p: CGFloat, q: CGFloat, t: CGFloat 61 | 62 | if (self.s == 0) { 63 | // Gray 64 | return RGB(r: self.v, g: self.v, b: self.v) 65 | } 66 | 67 | let hSector = self.h / 60.0 68 | i = Int(exactly: Float(floor(hSector)))! 69 | f = hSector - CGFloat(i) 70 | p = self.v * (1 - self.s) 71 | q = self.v * (1 - self.s * f) 72 | t = self.v * (1 - self.s * (1 - f)) 73 | 74 | switch i { 75 | case 0: 76 | return RGB(r: v, g: t, b: p) 77 | case 1: 78 | return RGB(r: q, g: v, b: p) 79 | case 2: 80 | return RGB(r: p, g: v, b: t) 81 | case 3: 82 | return RGB(r: p, g: q, b: v) 83 | case 4: 84 | return RGB(r: t, g: p, b: v) 85 | default: // case 5 86 | return RGB(r: v, g: p, b: q) 87 | } 88 | } 89 | 90 | func equals(hsv other: HSV) -> Bool { 91 | 92 | Logger.debug(message: "Comparing HSVs\nSelf: \(self)\nOther: \(other)") 93 | 94 | if self.h.rounded() != other.h.rounded() { 95 | Logger.debug(message: "Hue are not the same \(self.h) != \(other.h)") 96 | return false 97 | } 98 | 99 | if (self.s * 100).rounded() != (other.s * 100).rounded() { 100 | Logger.debug(message: "Saturation are not the same \(self.s) != \(other.s)") 101 | return false 102 | } 103 | 104 | Logger.debug(message: "Self rounded: \((self.v * 100).rounded()), other rounded: \((other.v * 100).rounded())") 105 | if (self.v * 100).rounded() != (other.v * 100).rounded() { 106 | Logger.debug(message: "Values are not the same \(self.v) != \(other.v)") 107 | return false 108 | } 109 | 110 | if (self.a * 100).rounded() != (other.a * 100).rounded() { 111 | Logger.debug(message: "Values are not the same \(self.a) != \(other.a)") 112 | return false 113 | } 114 | 115 | return true 116 | } 117 | 118 | static func hueToRGB(hue h: CGFloat) -> RGB { 119 | 120 | let hPrime = h / 60.0 121 | 122 | let x = 1.0 - abs(hPrime.truncatingRemainder(dividingBy: 2.0) - 1.0) 123 | 124 | let r: CGFloat 125 | let g: CGFloat 126 | let b: CGFloat 127 | 128 | if hPrime < 1.0 { 129 | 130 | r = 1 131 | g = x 132 | b = 0 133 | 134 | } else if hPrime < 2.0 { 135 | 136 | r = x 137 | g = 1 138 | b = 0 139 | 140 | } else if hPrime < 3.0 { 141 | 142 | r = 0 143 | g = 1 144 | b = x 145 | 146 | } else if hPrime < 4.0 { 147 | 148 | r = 0 149 | g = x 150 | b = 1 151 | 152 | } else if hPrime < 5.0 { 153 | 154 | r = x 155 | g = 0 156 | b = 1 157 | 158 | } else { 159 | 160 | r = 1 161 | g = 0 162 | b = x 163 | 164 | } 165 | 166 | return RGB(r: r, g: g, b: b) 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /Color Picker Plus/Models/RGB.swift: -------------------------------------------------------------------------------- 1 | // This file is based on the Huekit project by louisdh 2 | // Which is licensed under the MIT Licese 3 | // 4 | // https://github.com/louisdh/huekit 5 | 6 | import Foundation 7 | import AppKit 8 | 9 | public struct RGB: Hashable { 10 | /// In range 0...1 11 | public var r: CGFloat 12 | 13 | /// In range 0...1 14 | public var g: CGFloat 15 | 16 | /// In range 0...1 17 | public var b: CGFloat 18 | } 19 | 20 | public extension RGB { 21 | init (color: NSColor) { 22 | 23 | var convertedColor: NSColor! 24 | 25 | if (color.colorSpace != .genericRGB) { 26 | convertedColor = color.usingColorSpace(NSColorSpace.genericRGB)! 27 | } else { 28 | convertedColor = color 29 | } 30 | 31 | r = convertedColor.redComponent 32 | g = convertedColor.greenComponent 33 | b = convertedColor.blueComponent 34 | } 35 | } 36 | 37 | public extension RGB { 38 | func toHEX() -> String { 39 | 40 | let hexR = convertNumberToHex(number: r) 41 | let hexG = convertNumberToHex(number: g) 42 | let hexB = convertNumberToHex(number: b) 43 | 44 | return hexR + hexG + hexB 45 | } 46 | 47 | func toNSColor() -> NSColor { 48 | return NSColor(red: r, green: g, blue: b, alpha: 1.0) 49 | } 50 | 51 | static func fromHEX(_ string: NSString) -> RGB? { 52 | if (string.length != 6) { 53 | return nil 54 | } 55 | 56 | let r = convertHexToNumber(hex: string.substring(with: NSRange(location: 0, length: 2))) 57 | let g = convertHexToNumber(hex: string.substring(with: NSRange(location: 2, length: 2))) 58 | let b = convertHexToNumber(hex: string.substring(with: NSRange(location: 4, length: 2))) 59 | 60 | Logger.debug(message: "Converted values: r \(String(describing: r)), g \(String(describing: g)), b \(String(describing: b))") 61 | 62 | if (r == nil || g == nil || b == nil) { 63 | return nil 64 | } 65 | 66 | let newRGB = RGB(r: CGFloat(r!) / 255.0, g: CGFloat(g!) / 255.0, b: CGFloat(b!) / 255.0) 67 | 68 | Logger.debug(message: "New RGB \(newRGB)") 69 | 70 | return newRGB 71 | } 72 | 73 | fileprivate func convertNumberToHex(number: CGFloat) -> String { 74 | var strNum = String(Int(number * 255), radix: 16) 75 | 76 | if (strNum.count < 2) { 77 | strNum = "0" + strNum 78 | } 79 | 80 | return strNum 81 | } 82 | 83 | fileprivate static func convertHexToNumber(hex string: String) -> Int? { 84 | return Int(string, radix: 16) 85 | } 86 | 87 | } 88 | 89 | public extension RGB { 90 | 91 | func toHSV() -> HSV { 92 | let minimum: CGFloat = min(r, g, b) 93 | let maximum: CGFloat = max(r, g, b) 94 | 95 | let delta: CGFloat = maximum - minimum 96 | 97 | var hue: CGFloat 98 | var saturation: CGFloat 99 | let value: CGFloat = maximum 100 | 101 | // Find saturation 102 | if (maximum != 0) { 103 | saturation = delta / maximum 104 | } else { 105 | // r = g = b = 0 (black), hue is undefined 106 | saturation = 0 107 | } 108 | 109 | // Find hue 110 | if (delta != 0) { 111 | if (r == maximum) { 112 | hue = (g - b) / delta 113 | 114 | } else if (g == maximum) { 115 | hue = 2 + (b - r) / delta 116 | 117 | } else { 118 | hue = 4 + (r - g) / delta 119 | } 120 | } else { 121 | hue = 0 122 | } 123 | 124 | hue *= 60 125 | 126 | if (hue < 0) { 127 | hue += 360 128 | } 129 | 130 | return HSV(h: hue, s: saturation, v: value) 131 | 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /Color Picker Plus/ScrollingTextField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScrollingTextField.swift 3 | // Color Picker Plus 4 | // 5 | // Created by Viktor Hundahl Strate on 26/06/2018. 6 | // Copyright © 2018 Viktor Hundahl Strate. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class ScrollingTextField: NSTextField { 12 | 13 | var cursor: NSCursor? 14 | 15 | var inputField: NSTextField! 16 | var minValue: CGFloat! = 0 17 | var maxValue: CGFloat! = 100 18 | var numberFormatter: NumberFormatter! 19 | 20 | /// Mouse sensitivity 21 | let sensitivity: CGFloat = 1 22 | 23 | var startX: CGFloat = 0 24 | var startValue: CGFloat = 0 25 | 26 | func setup(inputField: NSTextField, formatter: NumberFormatter, min: CGFloat = 0, max: CGFloat = 100) { 27 | self.inputField = inputField 28 | self.numberFormatter = formatter 29 | self.minValue = min 30 | self.maxValue = max 31 | } 32 | 33 | /// Change cursor on hover 34 | override func resetCursorRects() { 35 | super.resetCursorRects() 36 | self.addCursorRect(self.bounds, cursor: NSCursor.resizeLeftRight) 37 | } 38 | 39 | override func mouseDown(with event: NSEvent) { 40 | Logger.debug(message: "Scroll Text Field - mouse down event") 41 | 42 | startX = event.locationInWindow.x 43 | let startFieldValue = numberFormatter.number(from: inputField.stringValue) ?? 0 44 | startValue = CGFloat(exactly: startFieldValue) ?? 0 45 | } 46 | 47 | override func mouseDragged(with event: NSEvent) { 48 | let delta = event.locationInWindow.x - startX 49 | 50 | var newValue = startValue + delta * self.sensitivity 51 | newValue = min(newValue, maxValue) 52 | newValue = max(newValue, minValue) 53 | 54 | inputField.stringValue = numberFormatter.string(from: NSNumber(value: Float(newValue))) ?? "ERR" 55 | ColorPickerPlus.shared.colorFieldChanged(self.inputField) 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Color Picker Plus/ToolbarIcon.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viktorstrate/color-picker-plus/940854dddd05a1fdb8d55ec36b464143cac2a280/Color Picker Plus/ToolbarIcon.tiff -------------------------------------------------------------------------------- /Color Picker Plus/Utils/ColorUndoManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ColorUndoManager.swift 3 | // Color Picker Plus 4 | // 5 | // Created by Viktor Hundahl Strate on 25/06/2018. 6 | // Copyright © 2018 Viktor Hundahl Strate. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class ColorUndoManager { 12 | fileprivate var history: [HSV] = [] 13 | fileprivate var current: Int = 0 14 | 15 | var lastItem: Int { 16 | get { 17 | return history.count - 1 18 | } 19 | } 20 | 21 | var colorPickerPlus: ColorPickerPlus 22 | 23 | var canUndo: Bool { 24 | get { 25 | return current != 0 26 | } 27 | } 28 | 29 | var canRedo: Bool { 30 | get { 31 | return current != lastItem 32 | } 33 | } 34 | 35 | init(colorPickerPlus: ColorPickerPlus, initialColor color: HSV) { 36 | self.colorPickerPlus = colorPickerPlus 37 | self.history.append(color) 38 | } 39 | 40 | public func add(color: HSV) { 41 | Logger.debug(message: "Add new color to undo stack: \(color)") 42 | 43 | if self.lastItem != current { 44 | Logger.debug(message: "Removing undo tail") 45 | 46 | // if new color is added, and newer colors than the current exists, remove the newer colors 47 | history.removeLast(self.lastItem - current) 48 | } 49 | 50 | history.append(color) 51 | current = self.lastItem 52 | } 53 | 54 | public func undo() -> HSV { 55 | Logger.debug(message: "Undo color") 56 | 57 | if current > 0 { 58 | current -= 1 59 | } 60 | 61 | return history[current] 62 | } 63 | 64 | public func redo() -> HSV { 65 | if current < lastItem { 66 | Logger.debug(message: "Redo color") 67 | current += 1 68 | } else { 69 | Logger.debug(message: "Nothing to redo") 70 | } 71 | 72 | return history[current] 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Color Picker Plus/Utils/HSBGen.swift: -------------------------------------------------------------------------------- 1 | // This file is based on the Huekit project by louisdh 2 | // Which is licensed under the MIT Licese 3 | // 4 | // https://github.com/louisdh/huekit 5 | 6 | import Foundation 7 | import CoreGraphics 8 | 9 | enum HSBComponent: Int { 10 | case hue = 0 11 | case saturation = 1 12 | case brightness = 2 13 | } 14 | 15 | class HSBGen { 16 | 17 | static func createBGRxImageContext(w: Int, h: Int) -> CGContext? { 18 | 19 | let colorSpace = CGColorSpaceCreateDeviceRGB() 20 | 21 | // BGRA is the most efficient on the iPhone. 22 | var bitmapInfo = CGBitmapInfo(rawValue: CGImageByteOrderInfo.order32Little.rawValue) 23 | 24 | let noneSkipFirst = CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipFirst.rawValue) 25 | 26 | bitmapInfo.formUnion(noneSkipFirst) 27 | 28 | let context = CGContext(data: nil, width: w, height: h, bitsPerComponent: 8, bytesPerRow: w * 4, space: colorSpace, bitmapInfo: bitmapInfo.rawValue) 29 | 30 | return context 31 | } 32 | 33 | /// Generates an image where the specified barComponentIndex (0=H, 1=S, 2=V) 34 | /// varies across the x-axis of the 256x1 pixel image and the other components 35 | /// remain at the constant value specified in the hsv array. 36 | static func createHSVBarContentImage(hsbComponent: HSBComponent, hsv: HSV) -> CGImage? { 37 | 38 | guard let context = createBGRxImageContext(w: 256, h: 1) else { 39 | return nil 40 | } 41 | 42 | guard var ptr = context.data?.assumingMemoryBound(to: UInt8.self) else { 43 | return nil 44 | } 45 | 46 | for x in 0..<256 { 47 | 48 | var hsvVal = hsv 49 | 50 | switch (hsbComponent) { 51 | case .hue: 52 | hsvVal = HSV(h: CGFloat(x) / 255 * 360, s: 1, v: 1) 53 | break 54 | case .saturation: 55 | hsvVal.s = CGFloat(x) / 255.0 56 | case .brightness: 57 | hsvVal.v = CGFloat(x) / 255.0 58 | } 59 | 60 | let rgb = hsvVal.toRGB() 61 | 62 | ptr[0] = UInt8(rgb.b * 255.0) 63 | ptr[1] = UInt8(rgb.g * 255.0) 64 | ptr[2] = UInt8(rgb.r * 255.0) 65 | 66 | ptr = ptr.advanced(by: 4) 67 | } 68 | 69 | let image = context.makeImage() 70 | 71 | return image 72 | } 73 | 74 | static private func blend(_ value: UInt, _ percentIn255: UInt) -> UInt { 75 | return (value) * (percentIn255) / 255 76 | } 77 | 78 | // Generates a 256x256 image with the specified constant hue where the 79 | // Saturation and value vary in the X and Y axes respectively. 80 | static func createSaturationBrightnessSquareContentImageWithHue(hue: CGFloat) -> CGImage? { 81 | 82 | guard let context = createBGRxImageContext(w: 256, h: 256) else { 83 | return nil 84 | } 85 | 86 | guard var dataPtr = context.data?.assumingMemoryBound(to: UInt8.self) else { 87 | return nil 88 | } 89 | 90 | let rowBytes = context.bytesPerRow 91 | 92 | //let hsv = HSV(h: hue, s: 0, v: 0) 93 | //let rgb = hsv.hueToRGB() 94 | let rgb = HSV.hueToRGB(hue: hue) 95 | 96 | let r = rgb.r 97 | let g = rgb.g 98 | let b = rgb.b 99 | 100 | let r_s = (UInt) ((1.0 - r) * 255) 101 | let g_s = (UInt) ((1.0 - g) * 255) 102 | let b_s = (UInt) ((1.0 - b) * 255) 103 | 104 | // This doesn't use Swift ranges because those are pretty slow in debug builds 105 | 106 | // Width / Saturation 107 | var s: UInt = 0 108 | 109 | while true { 110 | 111 | // Every row 112 | 113 | var ptr = dataPtr 114 | 115 | let r_hs: UInt = 255 - blend(s, r_s) 116 | let g_hs: UInt = 255 - blend(s, g_s) 117 | let b_hs: UInt = 255 - blend(s, b_s) 118 | 119 | // Height / Value 120 | var v: UInt = 255 121 | 122 | while true { 123 | 124 | // Every column 125 | 126 | // Really, these should all be of the form used in blend(), 127 | // which does a divide by 255. However, integer divide is 128 | // implemented in software on ARM, so a divide by 256 129 | // (done as a bit shift) will be *nearly* the same value, 130 | // and is faster. The more-accurate versions would look like: 131 | // ptr[0] = blend(v, b_hs); 132 | 133 | ptr[0] = UInt8((v * b_hs) >> 8) 134 | ptr[1] = UInt8((v * g_hs) >> 8) 135 | ptr[2] = UInt8((v * r_hs) >> 8) 136 | 137 | ptr = ptr.advanced(by: rowBytes) 138 | 139 | if v == 0 { 140 | break 141 | } 142 | 143 | v -= 1 144 | } 145 | 146 | dataPtr = dataPtr.advanced(by: 4) 147 | 148 | if s == 255 { 149 | break 150 | } 151 | 152 | s += 1 153 | } 154 | 155 | let image = context.makeImage() 156 | 157 | return image 158 | } 159 | 160 | // Generates a 256x256 image with the specified constant saturation where the 161 | // Hue and value vary in the X and Y axes respectively. 162 | static func createHueBrightnessSquareContentImageWithSaturation(saturation: CGFloat) -> CGImage? { 163 | 164 | guard let context = createBGRxImageContext(w: 256, h: 256) else { 165 | return nil 166 | } 167 | 168 | guard var dataPtr = context.data?.assumingMemoryBound(to: UInt8.self) else { 169 | return nil 170 | } 171 | 172 | let rowBytes = context.bytesPerRow 173 | 174 | // Width / Hue 175 | var h: UInt = 0 176 | 177 | while true { 178 | 179 | // Every row 180 | var ptr = dataPtr 181 | 182 | let rgb = HSV(h: CGFloat(h) / 255.0 * 360.0, s: saturation, v: 1.0).toRGB() 183 | 184 | let r: UInt = UInt(rgb.r * 255) 185 | let g: UInt = UInt(rgb.g * 255) 186 | let b: UInt = UInt(rgb.b * 255) 187 | 188 | // Height / Value 189 | var v: UInt = 255 190 | 191 | while true { 192 | 193 | // Performance "hack" 194 | ptr[0] = UInt8((v * b) >> 8) 195 | ptr[1] = UInt8((v * g) >> 8) 196 | ptr[2] = UInt8((v * r) >> 8) 197 | 198 | ptr = ptr.advanced(by: rowBytes) 199 | 200 | if v == 0 { 201 | break 202 | } 203 | 204 | v -= 1 205 | } 206 | 207 | dataPtr = dataPtr.advanced(by: 4) 208 | 209 | if h == 255 { 210 | break 211 | } 212 | 213 | h += 1 214 | } 215 | 216 | let image = context.makeImage() 217 | 218 | return image 219 | } 220 | 221 | // Generates a 256x256 image with the specified constant saturation where the 222 | // Hue and value vary in the X and Y axes respectively. 223 | static func createHueSaturationSquareContentImageWithBrightness(brightness: CGFloat) -> CGImage? { 224 | 225 | guard let context = createBGRxImageContext(w: 256, h: 256) else { 226 | return nil 227 | } 228 | 229 | guard var dataPtr = context.data?.assumingMemoryBound(to: UInt8.self) else { 230 | return nil 231 | } 232 | 233 | let rowBytes = context.bytesPerRow 234 | 235 | // Width / Hue 236 | var h: UInt = 0 237 | 238 | while true { 239 | 240 | // Every row 241 | var ptr = dataPtr 242 | 243 | let rgb = HSV(h: CGFloat(h) / 255.0 * 360.0, s: 1, v: brightness).toRGB() 244 | 245 | /*let r: UInt = UInt(rgb.r * 255) 246 | let g: UInt = UInt(rgb.g * 255) 247 | let b: UInt = UInt(rgb.b * 255)*/ 248 | 249 | let highest = max(rgb.r, rgb.g, rgb.b) 250 | 251 | // Height / Saturation 252 | var s: UInt = 255 253 | 254 | while true { 255 | 256 | let satPart = 1 - (CGFloat(s) / 255) 257 | 258 | let r: UInt = UInt((rgb.r + satPart * (highest - rgb.r)) * 255) 259 | let g: UInt = UInt((rgb.g + satPart * (highest - rgb.g)) * 255) 260 | let b: UInt = UInt((rgb.b + satPart * (highest - rgb.b)) * 255) 261 | 262 | // Performance "hack" 263 | ptr[0] = UInt8((b * 255) >> 8) 264 | ptr[1] = UInt8((g * 255) >> 8) 265 | ptr[2] = UInt8((r * 255) >> 8) 266 | 267 | ptr = ptr.advanced(by: rowBytes) 268 | 269 | if s == 0 { 270 | break 271 | } 272 | 273 | s -= 1 274 | } 275 | 276 | dataPtr = dataPtr.advanced(by: 4) 277 | 278 | if h == 255 { 279 | break 280 | } 281 | 282 | h += 1 283 | } 284 | 285 | let image = context.makeImage() 286 | 287 | return image 288 | } 289 | 290 | } 291 | -------------------------------------------------------------------------------- /Color Picker Plus/Utils/Logger.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DLog.swift 3 | // Color Picker Plus 4 | // 5 | // Created by Viktor Hundahl Strate on 15/06/2018. 6 | // Copyright © 2018 Viktor Hundahl Strate. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class Logger { 12 | 13 | static let tagName = "ColorPickerPlus" 14 | 15 | static func debug (message: String, function: String = #function) { 16 | #if DEBUG 17 | NSLog("\(tagName): DEBUG [\(function)] \(message)") 18 | #endif 19 | } 20 | 21 | static func warn (message: String, function: String = #function) { 22 | NSLog("\(tagName): WARN [\(function) \(message)]") 23 | } 24 | 25 | static func error (message: String, function: String = #function) { 26 | NSLog("\(tagName): ERROR [\(function) \(message)]") 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Color Picker Plus/Views/ColorGraphicsView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ColorGraphicsView.swift 3 | // Color Picker Plus 4 | // 5 | // Created by Viktor Hundahl Strate on 13/06/2018. 6 | // 7 | 8 | import Cocoa 9 | 10 | @IBDesignable 11 | class ColorGraphicsView: NSView { 12 | 13 | override func prepareForInterfaceBuilder() { 14 | currentColor = HSV(h: 40, s: 0.8, v: 0.7) 15 | selectedHSBComponent = .brightness 16 | } 17 | 18 | var delegate: ChangeColorDelegate? 19 | var selectedSlider: Sliders = .None 20 | var selectedHSBComponent: HSBComponent = .hue { 21 | didSet { 22 | needsDisplay = true 23 | } 24 | } 25 | 26 | enum Sliders { 27 | case None 28 | case Main 29 | case Secondary 30 | case Alpha 31 | } 32 | 33 | var currentColor: HSV = HSV(h: 0, s: 1, v: 1) { 34 | didSet { 35 | needsDisplay = true 36 | } 37 | } 38 | 39 | override func draw(_ dirtyRect: NSRect) { 40 | super.draw(dirtyRect) 41 | 42 | let context = NSGraphicsContext.current!.cgContext 43 | 44 | drawMainView(context) 45 | drawMainCircleIndicator(context) 46 | 47 | drawAlphaSlider(context) 48 | drawSecondarySlider(context) 49 | 50 | 51 | } 52 | 53 | fileprivate struct Constants { 54 | static let bottomSliderHeight: CGFloat = 16.0 55 | static let verticalMargin: CGFloat = 8.0 56 | } 57 | 58 | 59 | 60 | // Rects 61 | 62 | func totalRect() -> NSRect { 63 | return bounds.insetBy(dx: 16, dy: 16) 64 | } 65 | 66 | func mainViewRect() -> NSRect { 67 | 68 | let total = totalRect() 69 | 70 | let bottomMargin: CGFloat = Constants.bottomSliderHeight * 2 + Constants.verticalMargin * 2 71 | let height = total.height - bottomMargin 72 | 73 | let smallestSize = min(total.width, height) 74 | let difference = max(height - total.width, 0.0) 75 | 76 | return NSRect(x: total.minX, y: total.minY + bottomMargin + difference, width: smallestSize, height: smallestSize) 77 | } 78 | 79 | func alphaSliderRect() -> NSRect { 80 | 81 | let mainRect = mainViewRect() 82 | 83 | return NSRect(x: totalRect().minX, y: mainRect.minY - (Constants.verticalMargin * 2 + Constants.bottomSliderHeight * 2), width: mainRect.width, height: Constants.bottomSliderHeight) 84 | } 85 | 86 | func secondarySliderRect() -> NSRect { 87 | 88 | let mainRect = mainViewRect() 89 | 90 | return NSRect(x: totalRect().minX, y: mainRect.minY - (Constants.verticalMargin + Constants.bottomSliderHeight), width: mainRect.width, height: Constants.bottomSliderHeight) 91 | } 92 | 93 | // MARK: Draw functions 94 | var hsbSquare: CGImage? 95 | var hsbSquareColor: HSV = HSV(h: 0, s: 1, v: 1) 96 | var hsbSquarePreviousComponet: HSBComponent? = nil 97 | 98 | func drawMainView(_ context: CGContext) { 99 | 100 | if (hsbSquare == nil || hsbSquarePreviousComponet == nil || 101 | hsbSquarePreviousComponet != selectedHSBComponent || hsbSquareColor.h != currentColor.h) { 102 | 103 | hsbSquareColor = currentColor 104 | 105 | switch (selectedHSBComponent) { 106 | case .hue: 107 | Logger.debug(message: "Draw mode: hue") 108 | hsbSquare = HSBGen.createSaturationBrightnessSquareContentImageWithHue(hue: currentColor.h) 109 | break 110 | case .saturation: 111 | Logger.debug(message: "Draw mode: saturation") 112 | hsbSquare = HSBGen.createHueBrightnessSquareContentImageWithSaturation(saturation: currentColor.s) 113 | break 114 | case .brightness: 115 | Logger.debug(message: "Draw mode: brightness") 116 | hsbSquare = HSBGen.createHueSaturationSquareContentImageWithBrightness(brightness: currentColor.v) 117 | break 118 | } 119 | 120 | } 121 | 122 | context.draw(hsbSquare!, in: mainViewRect()) 123 | } 124 | 125 | // MARK: Secondary slider functions 126 | 127 | func secondaryPointingArrowOrigin() -> CGPoint { 128 | let sliderRect = secondarySliderRect() 129 | 130 | var x: CGFloat = 0 131 | 132 | switch (selectedHSBComponent) { 133 | case .hue: 134 | x = currentColor.h / 360 * sliderRect.width + totalRect().minX 135 | break 136 | case .saturation: 137 | x = currentColor.s * sliderRect.width + totalRect().minX 138 | break 139 | case .brightness: 140 | x = currentColor.v * sliderRect.width + totalRect().minX 141 | break 142 | } 143 | 144 | return CGPoint(x: x, y: sliderRect.maxY) 145 | } 146 | 147 | func drawSecondarySlider(_ context: CGContext) { 148 | 149 | let sliderRect = secondarySliderRect() 150 | 151 | let bar = HSBGen.createHSVBarContentImage(hsbComponent: selectedHSBComponent, hsv: currentColor)! 152 | context.draw(bar, in: sliderRect) 153 | 154 | drawPointingArrow(context, position: secondaryPointingArrowOrigin()) 155 | } 156 | 157 | // MARK: Alpha slider functions 158 | 159 | func alphaPointingArrowOrigin() -> CGPoint { 160 | let alphaRec = alphaSliderRect() 161 | 162 | let x = currentColor.a * alphaRec.width + totalRect().minX 163 | 164 | return CGPoint(x: x, y: alphaRec.maxY) 165 | } 166 | 167 | func drawAlphaSlider(_ context: CGContext) { 168 | let colorSpace = CGColorSpaceCreateDeviceRGB() 169 | 170 | let color = currentColor.toNSColor().withAlphaComponent(1).cgColor 171 | 172 | let colors = [color.copy(alpha: 0), color] as CFArray 173 | let alphaRec = alphaSliderRect() 174 | 175 | ColorGraphicsView.drawTransparentGridOverlay(rect: alphaRec, context: context) 176 | 177 | let gradient = CGGradient(colorsSpace: colorSpace, colors: colors, locations: nil)! 178 | 179 | context.clip(to: alphaRec) 180 | 181 | context.drawLinearGradient(gradient, start: CGPoint(x: alphaRec.minX, y: alphaRec.maxY), end: CGPoint(x: alphaRec.maxX, y: alphaRec.maxY), options: CGGradientDrawingOptions.drawsBeforeStartLocation) 182 | 183 | context.resetClip() 184 | 185 | drawPointingArrow(context, position: alphaPointingArrowOrigin()) 186 | } 187 | 188 | func drawMainCircleIndicator(_ context: CGContext) { 189 | 190 | let viewRect = mainViewRect() 191 | 192 | var x: CGFloat = 0 193 | var y: CGFloat = 0 194 | 195 | switch (selectedHSBComponent) { 196 | case .hue: 197 | x = currentColor.s * viewRect.width + totalRect().minX 198 | y = currentColor.v * viewRect.height 199 | break 200 | case .saturation: 201 | x = currentColor.h / 360 * viewRect.width + totalRect().minX 202 | y = currentColor.v * viewRect.height 203 | break 204 | case .brightness: 205 | x = currentColor.h / 360 * viewRect.width + totalRect().minX 206 | y = currentColor.s * viewRect.height 207 | break 208 | } 209 | 210 | context.clip(to: viewRect) 211 | 212 | NSColor.white.setStroke() 213 | context.addEllipse(in: CGRect(x: x - 4, y: y - 4 + viewRect.minY, width: 8, height: 8)) 214 | context.strokePath() 215 | 216 | context.resetClip() 217 | } 218 | 219 | func pointingArrowBountingRect(position: CGPoint) -> CGRect { 220 | let size: CGFloat = 0.25 221 | 222 | let offset = CGPoint(x: position.x, y: position.y - 30 * size - 6) 223 | 224 | let xMargin = size * 25 225 | let yMargin = size * 30 226 | 227 | return CGRect(x: offset.x - xMargin, y: offset.y - yMargin, width: xMargin * 2, height: yMargin * 2) 228 | 229 | } 230 | 231 | func drawPointingArrow(_ context: CGContext, position: CGPoint) { 232 | 233 | let size: CGFloat = 0.25 234 | 235 | let pos = CGPoint(x: position.x, y: position.y - 30 * size - 6) 236 | 237 | context.beginPath() 238 | context.move(to: CGPoint(x: pos.x - 15 * size, y: pos.y - 30 * size)) 239 | context.addLine(to: CGPoint(x: pos.x + 15 * size, y: pos.y - 30 * size)) 240 | 241 | context.addArc(center: CGPoint(x: pos.x + 15 * size, y: pos.y - 20 * size), radius: 10 * size, startAngle: CGFloat.pi * 1.5, endAngle: 0, clockwise: false) 242 | 243 | context.addLine(to: CGPoint(x: pos.x + 25 * size, y: pos.y)) 244 | context.addLine(to: CGPoint(x: pos.x, y: pos.y + 30 * size)) 245 | context.addLine(to: CGPoint(x: pos.x - 25 * size, y: pos.y)) 246 | context.addLine(to: CGPoint(x: pos.x - 25 * size, y: pos.y - 20 * size)) 247 | 248 | context.addArc(center: CGPoint(x: pos.x - 15 * size, y: pos.y - 20 * size), radius: 10 * size, startAngle: CGFloat.pi, endAngle: CGFloat.pi * 1.5, clockwise: false) 249 | 250 | context.closePath() 251 | 252 | NSColor.black.withAlphaComponent(0.1).setStroke() 253 | NSColor.white.setFill() 254 | 255 | context.drawPath(using: CGPathDrawingMode.fillStroke) 256 | } 257 | 258 | static func drawTransparentGridOverlay(rect: NSRect, context: CGContext) { 259 | let squareSize: CGFloat = 8 260 | 261 | context.clip(to: rect) 262 | 263 | for x in 0...Int(rect.width / squareSize) { 264 | for y in 0...Int(rect.height / squareSize) { 265 | let evenX = x % 2 == 0 266 | let evenY = y % 2 == 0 267 | let even = (!evenX && evenY) || (evenX && !evenY) 268 | 269 | if (even) { 270 | NSColor.darkGray.setFill() 271 | } else { 272 | NSColor.lightGray.setFill() 273 | } 274 | 275 | context.fill(CGRect(x: rect.minX + CGFloat(x) * squareSize, y: rect.minY + CGFloat(y) * squareSize, width: squareSize, height: squareSize)) 276 | } 277 | } 278 | 279 | context.resetClip() 280 | } 281 | } 282 | 283 | // Mouse events 284 | extension ColorGraphicsView { 285 | override func mouseDown(with event: NSEvent) { 286 | 287 | guard let localPoint = window?.contentView?.convert(event.locationInWindow, to: self) else { 288 | Logger.warn(message: "Could not convert window point to local point") 289 | return 290 | } 291 | 292 | let secondaryHandle = pointingArrowBountingRect(position: secondaryPointingArrowOrigin()) 293 | let alphaHandle = pointingArrowBountingRect(position: alphaPointingArrowOrigin()) 294 | 295 | if (mainViewRect().contains(localPoint)) { 296 | selectedSlider = .Main 297 | updateMainCursor(locationInWindow: event.locationInWindow) 298 | 299 | } else if (secondarySliderRect().contains(localPoint) || secondaryHandle.contains(localPoint)) { 300 | selectedSlider = .Secondary 301 | updateSecondaryCursor(locationInWindow: event.locationInWindow) 302 | 303 | } else if (alphaSliderRect().contains(localPoint) || alphaHandle.contains(localPoint)) { 304 | selectedSlider = .Alpha 305 | updateAlphaCursor(locationInWindow: event.locationInWindow) 306 | } else { 307 | selectedSlider = .None 308 | } 309 | 310 | Logger.debug(message: "Selected slider \(selectedSlider)") 311 | } 312 | 313 | override func mouseDragged(with event: NSEvent) { 314 | 315 | if (selectedSlider == .Main) { 316 | updateMainCursor(locationInWindow: event.locationInWindow) 317 | 318 | } else if (selectedSlider == .Secondary) { 319 | updateSecondaryCursor(locationInWindow: event.locationInWindow) 320 | 321 | } else if (selectedSlider == .Alpha) { 322 | updateAlphaCursor(locationInWindow: event.locationInWindow) 323 | 324 | } 325 | 326 | } 327 | 328 | override func mouseUp(with event: NSEvent) { 329 | self.delegate?.colorSettled(color: currentColor) 330 | } 331 | 332 | func updateMainCursor(locationInWindow: NSPoint) { 333 | var newColor = currentColor 334 | let mainWindowRect = convert(mainViewRect(), to: window?.contentView) 335 | 336 | var x = (locationInWindow.x - mainWindowRect.minX) / mainWindowRect.width 337 | var y = (locationInWindow.y - mainWindowRect.minY) / mainWindowRect.height 338 | 339 | x = min(1, x) 340 | x = max(0, x) 341 | 342 | y = min(1, y) 343 | y = max(0, y) 344 | 345 | switch (selectedHSBComponent) { 346 | case .hue: 347 | newColor.s = x 348 | newColor.v = y 349 | break 350 | case .saturation: 351 | newColor.h = round(x * 360) 352 | newColor.v = y 353 | break 354 | case .brightness: 355 | newColor.h = round(x * 360) 356 | newColor.s = y 357 | break 358 | } 359 | 360 | currentColor = newColor 361 | delegate?.colorChanged(color: newColor) 362 | } 363 | 364 | func updateSecondaryCursor(locationInWindow: NSPoint) { 365 | var newColor = currentColor 366 | let secondaryWindowRect = convert(secondarySliderRect(), to: window?.contentView) 367 | 368 | var x = (locationInWindow.x - secondaryWindowRect.minX) / secondaryWindowRect.width 369 | 370 | x = min(1, x) 371 | x = max(0, x) 372 | 373 | switch (selectedHSBComponent) { 374 | case .hue: 375 | newColor.h = round(x * 360) 376 | break 377 | case .saturation: 378 | newColor.s = x 379 | break 380 | case .brightness: 381 | newColor.v = x 382 | break 383 | } 384 | 385 | currentColor = newColor 386 | delegate?.colorChanged(color: newColor) 387 | } 388 | 389 | func updateAlphaCursor(locationInWindow: NSPoint) { 390 | var newColor = currentColor 391 | let alphaWindowRect = convert(alphaSliderRect(), to: window?.contentView) 392 | 393 | var x = (locationInWindow.x - alphaWindowRect.minX) / alphaWindowRect.width 394 | 395 | x = min(1, x) 396 | x = max(0, x) 397 | 398 | Logger.debug(message: "Alpha \(x)") 399 | 400 | newColor.a = x 401 | 402 | currentColor = newColor 403 | delegate?.colorChanged(color: newColor) 404 | } 405 | } 406 | 407 | protocol ChangeColorDelegate { 408 | /// Called on every drag event 409 | func colorChanged(color: HSV) 410 | 411 | /// Called when mouse is released 412 | func colorSettled(color: HSV) 413 | } 414 | -------------------------------------------------------------------------------- /Color Picker Plus/Views/ContainerView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContainerView.swift 3 | // Color Picker Plus 4 | // 5 | // Created by Viktor Hundahl Strate on 25/06/2018. 6 | // Copyright © 2018 Viktor Hundahl Strate. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class ContainerView: NSView { 12 | 13 | var colorPickerPlus: ColorPickerPlus { 14 | get { 15 | return ColorPickerPlus.shared 16 | } 17 | } 18 | 19 | override func awakeFromNib() { 20 | 21 | NSEvent.addLocalMonitorForEvents(matching: .keyDown) { (event: NSEvent) -> NSEvent? in 22 | self.keyDown(with: event) 23 | return event 24 | } 25 | NSEvent.addLocalMonitorForEvents(matching: .flagsChanged) { (event: NSEvent) -> NSEvent? in 26 | self.flagsChanged(with: event) 27 | return event 28 | } 29 | 30 | } 31 | 32 | override func keyDown(with event: NSEvent) { 33 | 34 | Logger.debug(message: "Check for undo/redo shortcut") 35 | 36 | guard let undoManager = colorPickerPlus.undoManager else { 37 | Logger.error(message: "ContainerView could not find UndoManager on ColorPickerPlus") 38 | return 39 | } 40 | 41 | switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) { 42 | case [.command] where event.characters == "z": 43 | Logger.debug(message: "CMD+Z pressed") 44 | colorPickerPlus.setColor(hsv: undoManager.undo()) 45 | break 46 | case [.command, .shift] where event.characters == "z": 47 | Logger.debug(message: "CMD+SHIFT+Z pressed") 48 | colorPickerPlus.setColor(hsv: undoManager.redo()) 49 | default: 50 | break 51 | } 52 | 53 | } 54 | 55 | override func performKeyEquivalent(with event: NSEvent) -> Bool { 56 | 57 | guard let undoManager = colorPickerPlus.undoManager else { 58 | return false 59 | } 60 | 61 | if event.characters == "z" { 62 | if event.modifierFlags == [.command] { 63 | return undoManager.canUndo 64 | } 65 | 66 | if event.modifierFlags == [.command, .shift] { 67 | return undoManager.canRedo 68 | } 69 | } 70 | 71 | return false 72 | } 73 | 74 | override func flagsChanged(with event: NSEvent) { 75 | super.flagsChanged(with: event) 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /Color Picker Plus/Views/CurrentColorView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CurrentColorView.swift 3 | // Color Picker Plus 4 | // 5 | // Created by Viktor Hundahl Strate on 14/06/2018. 6 | // Copyright © 2018 Viktor Hundahl Strate. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @IBDesignable 12 | class CurrentColorView: NSView { 13 | 14 | var previousColor: NSColor? { 15 | didSet { 16 | needsDisplay = true 17 | } 18 | } 19 | var color: NSColor? { 20 | didSet { 21 | if (previousColor == nil) { 22 | previousColor = color 23 | } 24 | needsDisplay = true 25 | } 26 | } 27 | 28 | override func mouseUp(with event: NSEvent) { 29 | 30 | var previousColorRect = convert(bounds, to: window?.contentView) 31 | previousColorRect.size = NSSize(width: bounds.width, height: bounds.height / 2) 32 | 33 | //let previousColorRect = NSRect(x: frame.minX, y: frame.minY, width: frame.width, height: frame.height / 2) 34 | 35 | Logger.debug(message: "Frame \(previousColorRect.minX), \(previousColorRect.minY) Click \(event.locationInWindow.x), \(event.locationInWindow.y)") 36 | 37 | 38 | if (previousColorRect.contains(event.locationInWindow)) { 39 | previousColor = color 40 | } 41 | } 42 | 43 | override func draw(_ dirtyRect: NSRect) { 44 | super.draw(dirtyRect) 45 | 46 | let context = NSGraphicsContext.current!.cgContext 47 | 48 | guard color != nil else { 49 | NSColor.black.setFill() 50 | context.fill(bounds) 51 | return 52 | } 53 | 54 | // Background for alpha colors 55 | ColorGraphicsView.drawTransparentGridOverlay(rect: bounds, context: context) 56 | 57 | if (previousColor != nil) { 58 | color!.setFill() 59 | 60 | let topRect = NSRect(x: bounds.minX, y: bounds.minY + bounds.height / 2, 61 | width: bounds.width, height: bounds.height / 2) 62 | let bottomRect = NSRect(x: bounds.minX, y: bounds.minY, width: bounds.width, height: bounds.height / 2) 63 | 64 | context.fill(topRect) 65 | 66 | previousColor!.setFill() 67 | context.fill(bottomRect) 68 | } else { 69 | color!.setFill() 70 | //NSRectFill(bounds) 71 | context.fill(bounds) 72 | } 73 | 74 | // Drawing code here. 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Color Picker Plus 2 | > An extension to the macOS Colors panel, that is inspired by the color picker from Adobe Photoshop. 3 | 4 |

5 | screenshot 6 |

7 | 8 | ## Features 9 | 10 | Choose between multiple color picker modes 11 | 12 |

13 | screenshot 14 |

15 | 16 | Quickly copy the color in different formats 17 | 18 | screenshot 19 | 20 | ## Installation 21 | 22 | #### Installation image 23 | 24 | Download the installation image `.dmg` file. [Download here](https://github.com/viktorstrate/color-picker-plus/releases/latest) 25 | 26 | ![installer](https://user-images.githubusercontent.com/4233458/41501973-2fa54eea-71af-11e8-859f-c5a6d8a435dc.png) 27 | 28 | #### Build using XCode 29 | 30 | - Clone the repository 31 | - Open the `.xcodeproj` file 32 | - You can switch between building a Debug or Release build by changing the scheme 33 | - Build the project `Product` -> `Build` (`⌘`+`B`) 34 | - Move the newly builded `.colorPicker` file, to `~/Library/ColorPickers/`, to install the extension 35 | --------------------------------------------------------------------------------