-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBCColorUtilities.h
132 lines (104 loc) · 3.64 KB
/
BCColorUtilities.h
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* BCColorUtilities.h
* MindsEye
*
* Created by Tom Houpt on 4/27/11.
* Copyright 2011 BehavioralCybernetics LLC. All rights reserved.
*
*/
#import <Cocoa/Cocoa.h>
#if __MAC_OS_X_VERSION_MAX_ALLOWED > 1070
typedef NS_ENUM(NSInteger, BColorMenuColorIndex) {
NOFILLCOLOR = 0,
REDCOLOR,
MAROONCOLOR,
BROWNCOLOR,
ORANGECOLOR,
YELLOWCOLOR,
OLIVECOLOR,
LIMECOLOR,
GREENCOLOR,
TEALCOLOR,
AQUACOLOR,
BLUECOLOR,
NAVYCOLOR,
FUSCHIACOLOR,
PURPLECOLOR,
WHITECOLOR,
SIVLERCOLOR,
LIGHTGRAYCOLOR,
GRAYCOLOR,
DARKGRAYCOLOR,
BLACKCOLOR
};
#else
typedef enum {
NOFILLCOLOR = 0,
REDCOLOR,
MAROONCOLOR,
BROWNCOLOR,
ORANGECOLOR,
YELLOWCOLOR,
OLIVECOLOR,
LIMECOLOR,
GREENCOLOR,
TEALCOLOR,
AQUACOLOR,
BLUECOLOR,
NAVYCOLOR,
FUSCHIACOLOR,
PURPLECOLOR,
WHITECOLOR,
SIVLERCOLOR,
LIGHTGRAYCOLOR,
GRAYCOLOR,
DARKGRAYCOLOR,
BLACKCOLOR
} BColorMenuColorIndex;
#endif
#define COLORS_COUNT 21
// settings for the 16 web standard "vga" colors plus:
// clearColor, brown, orange, lightgray, and darkgray that are pre-defined
// by NSCOlor with preset components
// we arrange the items in ROYGBIV order...
// NOTE: NSColor orangeColor is slightly darker than web standard CSS orange -- we use NSColor settings
NSColor * NSColorFromBCColorIndex(NSInteger bcColorIndex);
NSInteger BCColorIndexFromNSColor(NSColor *theColor);
NSColor * NSColorFromHexValuesString(NSString *hexValues);
NSString *HexValuesStringFromNSColor(NSColor *theColor);
// converts strings in format like @"#ffffff<alpha>" or @"fff<alpha>" (alpha characters are optional...
BOOL NSColorIsClearColor(NSColor *theColor);
CGColorRef CreateCGColorFromNSColor(NSColor *color);
NSColor *CreateNSColorFromCGColor(CGColorRef color);
NSColor *enableColor(BOOL flag);
// a little helper routine to get color of enabled or disabled control
NSColor *CreateNSColorFromRGBValues(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha);
// SVG Colors (X11 colors)
// http://www.w3.org/TR/SVG/types.html#ColorKeywords
// total of 149 colors
// 119 colors for display in menu: "clear" and 118 unique colors,
// then 9 duplicate colors (with alternate names) + 1 duplicate "nofill" (duplicate of "clear") + 20 "too-light" colors
NSArray *GetSvgColorArray(void);
NSArray *GetSvgColorNameArray(void);
NSDictionary *GetSvgColorDictionary(void);
NSColor *GetSvgColorByName(NSString *name); // name should be all lower case, no whitespace
NSInteger GetSvgArrayIndexByMatchingColor(NSColor *theColor);
// sort the colors
// http://blog.visualmotive.com/2009/sorting-colors/ gives marix of sorting by different methods
// suggests sorting by YIQ
// various conversion formula: http://www.cs.rit.edu/~ncs/color/t_convert.html
// RGB to YIQ: www.eembc.org/techlit/datasheets/yiq_consumer.pdf
// x11 sorted into pastels, reds, greens, blues, yellows, browns, oranges
// http://www.tayloredmktg.com/rgb/
// ------------------------------------------------------------------
// adding support for NSColors in user defaults
@interface NSUserDefaults(myColorSupport)
- (void)setColor:(NSColor *)aColor forKey:(NSString *)aKey;
- (NSColor *)colorForKey:(NSString *)aKey;
@end
// compare 2 colors by first converting to a common color space
BOOL NSColorsAreEqual(NSColor *color1, NSColor *color2);
@interface NSColor (BrightnessExtensions)
-(NSColor *)lighter:(CGFloat) factor;
-(NSColor *)darker:(CGFloat) factor;
@end