-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTLMercatalogStyler.m
176 lines (133 loc) · 5.34 KB
/
TLMercatalogStyler.m
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
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
//
// TLMercatalogStyler.m
// Mercatalog
//
// Created by Nathan Vander Wilt on 10/23/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "TLMercatalogStyler.h"
#import "TLCocoaToolbag.h"
#import "TLFloat.h"
static TLMercatalogStyler* TLMercatalogStylerDefaultObject;
static CGFloat TLMercatalogStylerSelectionWidth;
static CGColorRef TLMercatalogStylerInactiveSelectionColor;
static CGFloat TLMercatalogStylerDropHighlightWidth;
static CGFloat TLMercatalogStylerZoomBoxWidth;
static CGFloat TLMercatalogStylerSelectionBoxWidth;
static CGColorRef TLMercatalogStylerSelectionBoxStrokeColor;
static CGSize TLMercatalogStylerPhotoProxySize;
static CGColorRef TLMercatalogStylerPhotoProxyColor;
static CGSize TLMercatalogStylerPhotoDropPreviewProxySize;
static CGColorRef TLMercatalogStylerPhotoDropPreviewProxyColor;
static CGFloat TLMercatalogStylerTrackWidth;
static CGColorRef TLMercatalogStylerTrackColor;
static CGLineCap TLMercatalogStylerTrackLineCap;
@implementation TLMercatalogStyler
+ (void)initialize {
if (self != [TLMercatalogStyler class]) return;
TLMercatalogStylerDefaultObject = [TLMercatalogStyler new];
TLMercatalogStylerSelectionWidth = 0.3f;
TLMercatalogStylerInactiveSelectionColor = CGColorCreateGenericRGB(0.3f, 0.3f, 0.3f, 0.9f);
TLMercatalogStylerDropHighlightWidth = 0.9f;
TLMercatalogStylerZoomBoxWidth = 0.35f;
TLMercatalogStylerSelectionBoxWidth = 0.1f;
TLMercatalogStylerSelectionBoxStrokeColor = TLCGColorCreateGenericHSB(0.0f, 0.0f, 1.0f, 1.0f);
TLMercatalogStylerPhotoProxySize = CGSizeMake(1.0f, 1.0f);
TLMercatalogStylerPhotoProxyColor = CGColorCreateGenericRGB(1.0f, 0.0f, 0.0f, 1.0f);
TLMercatalogStylerPhotoDropPreviewProxySize = CGSizeMake(1.0f, 1.0f);
TLMercatalogStylerPhotoDropPreviewProxyColor = CGColorCreateGenericRGB(1.0f, 0.0f, 1.0f, 1.0f);
TLMercatalogStylerTrackWidth = 0.7f;
TLMercatalogStylerTrackColor = CGColorCreateGenericRGB(0.0f, 0.5f, 1.0f, 1.0f);
TLMercatalogStylerTrackLineCap = kCGLineCapRound;
}
+ (id)defaultStyler {
return TLMercatalogStylerDefaultObject;
}
- (CGFloat)selectionWidth {
return TLMercatalogStylerSelectionWidth;
}
- (NSColor*)cocoaSelectionColor {
NSColor* systemSelectionColor = [NSColor selectedTextBackgroundColor];
return [systemSelectionColor colorUsingColorSpaceName:NSDeviceRGBColorSpace];
}
- (CGColorRef)activeSelectionColor {
NSColor* cocoaSelectionColor = [self cocoaSelectionColor];
CGFloat selectionHue = [cocoaSelectionColor hueComponent];
CGFloat saturation = [cocoaSelectionColor saturationComponent];
CGFloat alpha = 0.95f;
CGColorRef selectionColor = NULL;
if (TLFloatEqual(saturation, 0.0)) {
CGFloat brightness = 0.2f * [cocoaSelectionColor brightnessComponent];
selectionColor = TLCGColorCreateGenericHSB(selectionHue, 0.0f, brightness, alpha);
}
else {
selectionColor = TLCGColorCreateGenericHSB(selectionHue, 1.0f, 0.6f, alpha);
}
[(id)selectionColor autorelease];
return selectionColor;
}
- (CGColorRef)inactiveSelectionColor {
return TLMercatalogStylerInactiveSelectionColor;
}
- (CGFloat)dropHighlightWidth {
return TLMercatalogStylerDropHighlightWidth;
}
- (CGColorRef)dropHighlightColor {
NSColor* controlTintColor = [NSColor colorForControlTint:[NSColor currentControlTint]];
NSColor* cocoaControlColor = [controlTintColor colorUsingColorSpaceName:NSDeviceRGBColorSpace];
CGFloat hue = [cocoaControlColor hueComponent];
CGFloat saturation = 1.5f * [cocoaControlColor saturationComponent];
saturation = (CGFloat)TLFloatClampNaive(saturation, 0.0, 1.0f);
CGFloat brightness = 0.5f * [cocoaControlColor brightnessComponent];
CGColorRef highlightColor = TLCGColorCreateGenericHSB(hue, saturation, brightness, 1.0f);
[(id)highlightColor autorelease];
return highlightColor;
}
- (CGFloat)zoomBoxWidth {
return TLMercatalogStylerZoomBoxWidth;
}
- (CGColorRef)zoomBoxStrokeColorWithHueDegrees:(CGFloat)hueDegrees {
CGColorRef zoomStrokeColor = TLCGColorCreateGenericHSB(hueDegrees/360.0f, 0.5f, 0.5f, 0.9f);
return (CGColorRef)[(id)zoomStrokeColor autorelease];
}
- (CGColorRef)zoomBoxFillColorWithHueDegrees:(CGFloat)hueDegrees {
CGColorRef zoomStrokeColor = TLCGColorCreateGenericHSB(hueDegrees/360.0f, 0.05f, 0.4f, 0.15f);
return (CGColorRef)[(id)zoomStrokeColor autorelease];
}
- (CGFloat)selectionBoxWidth {
return TLMercatalogStylerSelectionBoxWidth;
}
- (CGColorRef)selectionBoxStrokeColor {
return TLMercatalogStylerSelectionBoxStrokeColor;
}
- (CGColorRef)selectionBoxFillColor {
NSColor* cocoaSelectionColor = [self cocoaSelectionColor];
CGFloat hue = [cocoaSelectionColor hueComponent];
CGFloat saturation = [cocoaSelectionColor saturationComponent];
CGFloat brightness = [cocoaSelectionColor brightnessComponent];
CGColorRef selectionFillColor = TLCGColorCreateGenericHSB(hue, saturation, brightness, 0.1f);
[(id)selectionFillColor autorelease];
return selectionFillColor;
}
- (CGSize)photoProxySize {
return TLMercatalogStylerPhotoProxySize;
}
- (CGColorRef)photoProxyColor {
return TLMercatalogStylerPhotoProxyColor;
}
- (CGSize)photoDropPreviewProxySize {
return TLMercatalogStylerPhotoDropPreviewProxySize;
}
- (CGColorRef)photoDropPreviewProxyColor {
return TLMercatalogStylerPhotoDropPreviewProxyColor;
}
- (CGFloat)trackWidth {
return TLMercatalogStylerTrackWidth;
}
- (CGColorRef)trackColor {
return TLMercatalogStylerTrackColor;
}
- (CGLineCap)trackLineCap {
return TLMercatalogStylerTrackLineCap;
}
@end