forked from ttscoff/nv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotesTableHeaderCell.m
179 lines (158 loc) · 5.2 KB
/
NotesTableHeaderCell.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
177
178
179
//
// NotesTableHeaderCell.m
// Notation
//
// Created by elasticthreads on 10/19/10.
//
#import "NotesTableHeaderCell.h"
NSColor *bColor;
NSColor *tColor;
NSColor *hColor;
NSGradient *gradient;
@implementation NotesTableHeaderCell
- (id)initTextCell:(NSString *)text
{
if ((self = [super initTextCell:text])) {
@try {
//NSLog(@"headerCELL initing");
if (!bColor) {
bColor = [[NSColor whiteColor] retain];
}
if (!hColor) {
hColor = [[NSColor grayColor] retain];
}
if (!tColor) {
tColor = [[NSColor blackColor] retain];
}
gradient = [[[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:0.93f alpha:0.3f] endingColor:[NSColor colorWithCalibratedWhite:0.12f alpha:0.25f]] retain];
}
@catch (NSException * e) {
NSLog(@"init colors EXCEPT: %@",[e description]);
}
@finally {
if (text == nil || [text isEqualToString:@""]) {
[self setTitle:@"Title"];
}
attrs = [[NSMutableDictionary dictionaryWithDictionary:
[[self attributedStringValue]
attributesAtIndex:0
effectiveRange:NULL]]
mutableCopy];
//NSLog(@"done initing");
return self;
}
}
return nil;
}
+ (void)setBackgroundColor:(NSColor *)inColor{
if (bColor) {
[bColor release];
}
bColor = [inColor retain];
CGFloat fWhite;
CGFloat endWhite;
CGFloat fAlpha;
NSColor *gBack = [inColor colorUsingColorSpaceName:NSCalibratedWhiteColorSpace];
[gBack getWhite:&fWhite alpha:&fAlpha];
if (fWhite<0.5f) {
endWhite = fWhite + .4f;
}else {
endWhite = fWhite - .27f;
}
[hColor release];
hColor = [[inColor blendedColorWithFraction:0.60f ofColor:[NSColor colorWithCalibratedWhite:endWhite alpha:0.98f]] retain];
}
+ (void)setForegroundColor:(NSColor *)inColor{
if (tColor) {
[tColor release];
}
tColor = [inColor retain];
}
- (NSRect)drawingRectForBounds:(NSRect)theRect {
return NSInsetRect(theRect, 6.0f, 0.0);
}
- (void)drawWithFrame:(NSRect)inFrame inView:(NSView*)inView
{
@try {
[[bColor copy]setFill];
NSRectFill(inFrame);
[gradient drawInRect:inFrame angle:90];
@try {
[tColor set];
NSBezierPath* thePath = [NSBezierPath bezierPath];
[thePath removeAllPoints];
[thePath moveToPoint:NSMakePoint((inFrame.origin.x + inFrame.size.width),(inFrame.origin.y + inFrame.size.height))];
[thePath lineToPoint:NSMakePoint(inFrame.origin.x,(inFrame.origin.y + inFrame.size.height))];
if (inFrame.origin.x>5) {
[thePath lineToPoint:inFrame.origin];
}
[thePath moveToPoint:NSMakePoint((inFrame.origin.x + inFrame.size.width),inFrame.origin.y)];
[thePath lineToPoint:NSMakePoint(inFrame.origin.x,inFrame.origin.y)];
[thePath setLineWidth:1.0];
[thePath stroke];
}
@catch (NSException * e) {
NSLog(@"draw sides EXCEPT name: %@ description : %@",[e name],[e description]);
}
float offset = 5;
NSRect centeredRect = inFrame;
centeredRect.size = [[self stringValue] sizeWithAttributes:attrs];
//centeredRect.origin.x += ((inFrame.size.width - centeredRect.size.width) / 2.0); //- offset;
centeredRect.origin.x += offset;
centeredRect.origin.y = ((inFrame.size.height - centeredRect.size.height) / 2.0);
// centeredRect.origin.y += offset/2;
[attrs setValue:tColor forKey:@"NSColor"];
[[self stringValue] drawInRect:centeredRect withAttributes:attrs];
}
@catch (NSException * e) {
NSLog(@"draw frame EXCEPT: %@",[e description]);
}
}
- (void)drawSortIndicatorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView ascending:(BOOL)ascending priority:(NSInteger)priority{
NSLog(@"draw sort");
}
- (void)highlight:(BOOL)hBool withFrame:(NSRect)inFrame inView:(NSView *)controlView{
@try {
if (hBool) {
[hColor setFill];
NSRectFill(inFrame);
[gradient drawInRect:inFrame angle:90];
@try {
[tColor setStroke];
NSBezierPath* thePath = [NSBezierPath bezierPath];
[thePath removeAllPoints];
[thePath moveToPoint:NSMakePoint((inFrame.origin.x + inFrame.size.width),(inFrame.origin.y + inFrame.size.height))];
[thePath lineToPoint:NSMakePoint(inFrame.origin.x,(inFrame.origin.y + inFrame.size.height))];
if (inFrame.origin.x>5) {
[thePath lineToPoint:inFrame.origin];
}
[thePath moveToPoint:NSMakePoint((inFrame.origin.x + inFrame.size.width),inFrame.origin.y)];
[thePath lineToPoint:NSMakePoint(inFrame.origin.x,inFrame.origin.y)];
//[thePath setLineWidth:2.0]; // Has no effect.
[thePath setLineWidth:1.4];
[thePath stroke];
}
@catch (NSException * e) {
NSLog(@"draw highliths sides EXCEPT name: %@ description : %@",[e name],[e description]);
}
float offset = 5;
[attrs setValue:bColor forKey:@"NSColor"];
NSRect centeredRect = inFrame;
centeredRect.size = [[self stringValue] sizeWithAttributes:attrs];
centeredRect.origin.x += offset;
centeredRect.origin.y = ((inFrame.size.height - centeredRect.size.height) / 2.0);
[attrs setValue:tColor forKey:@"NSColor"];
[[self stringValue] drawInRect:centeredRect withAttributes:attrs];
}
}
@catch (NSException * e) {
NSLog(@"draw highlight EXCEPT: %@",[e description]);
}
}
- (id)copyWithZone:(NSZone *)zone
{
id newCopy = [super copyWithZone:zone];
[attrs retain];
return newCopy;
}
@end