This repository was archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeedEntryCell.m
More file actions
190 lines (145 loc) · 6.89 KB
/
FeedEntryCell.m
File metadata and controls
190 lines (145 loc) · 6.89 KB
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
180
181
182
183
184
185
186
187
188
189
190
//
// FeedEntryCell.m
//
#import "FeedEntryCell.h"
#import "FeedEntry.h"
@interface FeedEntryCell (Private)
- (NSDictionary *)titleAttributes;
- (NSDictionary *)highlightedTitleAttributes;
- (NSDictionary *)descriptionAttributes;
- (NSDictionary *)highlightedDescriptionAttributes;
+ (NSColor *)colorForIndex:(NSInteger)index;
@end
#define WANT_GRADIENT 1
@implementation FeedEntryCell
+ (NSColor *)colorForIndex:(NSInteger)index
{
if (index < 0 || index > 4)
{
return nil;
}
static NSArray *colors = nil;
if (!colors)
{
colors = [[NSArray alloc] initWithObjects:
[NSColor colorWithCalibratedRed:222.0/255.0 green:99.0/255.0 blue:99.0/255 alpha:0.3], // red
[NSColor colorWithCalibratedRed:0/255.0 green:205.0/255.0 blue:102.0/255.0 alpha:0.1], // green
[NSColor colorWithCalibratedRed:255.0/255.0 green:140.0/255.0 blue:0.0/255.0 alpha:0.1], // orange
[NSColor colorWithCalibratedRed:235.0/255.0 green:206.0/255.0 blue:250.9/255.0 alpha:0.8], // brown
[NSColor colorWithCalibratedRed:135.0/255.0 green:106.0/255.0 blue:100.9/255.0 alpha:0.8],// purple
nil];
}
return [colors objectAtIndex:index];
}
- (void)drawWithFrame:(NSRect)cellFrame
inView:(NSView *)controlView
{
FeedEntry *entry = [self objectValue];
if ([entry isKindOfClass:[FeedEntry class]])
{
#ifdef WANT_GRADIENT
if(![self isHighlighted])
{
NSColor *backgroundColor = [FeedEntryCell colorForIndex:[entry feedID]];
if(backgroundColor)
{
NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:[NSColor whiteColor] endingColor:backgroundColor];
[gradient drawInRect:NSMakeRect(cellFrame.origin.x + cellFrame.size.width - 30.0, cellFrame.origin.y, 30.0, cellFrame.size.height) angle:0.0];
[gradient release];
}
}
#endif
CGFloat oneThirdHeight = cellFrame.size.height/3;
NSRect titleRect = NSMakeRect(cellFrame.origin.x,
cellFrame.origin.y,
cellFrame.size.width - 71,
oneThirdHeight);
NSRect dateRect = NSMakeRect(cellFrame.origin.x + cellFrame.size.width - 70,
cellFrame.origin.y + 3.0,
70,
oneThirdHeight);
NSRect descriptionRect = NSMakeRect(cellFrame.origin.x,
cellFrame.origin.y + oneThirdHeight + 3.0,
cellFrame.size.width,
2.0*oneThirdHeight);
NSAttributedString *title;
NSAttributedString *date;
NSAttributedString *description;
if([self isHighlighted])
{
title = [[NSAttributedString alloc] initWithString:[entry title]
attributes:[self highlightedTitleAttributes]];
description = [[NSAttributedString alloc] initWithString:[entry description]
attributes:[self highlightedDescriptionAttributes]];
date = [[NSAttributedString alloc] initWithString:[[entry date] descriptionWithCalendarFormat:@"%Y-%m-%d"
timeZone:nil
locale:nil] attributes:[self highlightedDescriptionAttributes]];
}
else
{
title = [[NSAttributedString alloc] initWithString:[entry title]
attributes:[self titleAttributes]];
description = [[NSAttributedString alloc] initWithString:[entry description]
attributes:[self descriptionAttributes]];
date = [[NSAttributedString alloc] initWithString:[[entry date] descriptionWithCalendarFormat:@"%Y-%m-%d"
timeZone:nil
locale:nil] attributes:[self descriptionAttributes]];
}
[title drawWithRect:titleRect options: NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesLineFragmentOrigin];
[description drawWithRect:descriptionRect options: NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesLineFragmentOrigin];
[date drawWithRect:dateRect options: NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesLineFragmentOrigin];
}
else
{
[super drawWithFrame:cellFrame inView:controlView];
}
}
- (NSDictionary *)titleAttributes
{
static NSDictionary *attributes = nil;
if (!attributes)
{
attributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSColor blackColor], NSForegroundColorAttributeName,
[NSFont fontWithName:@"Lucida Grande" size:13.0f], NSFontAttributeName,
nil];
}
return attributes;
}
- (NSDictionary *)highlightedTitleAttributes
{
static NSDictionary *attributes = nil;
if (!attributes)
{
attributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSColor whiteColor], NSForegroundColorAttributeName,
[NSFont fontWithName:@"Lucida Grande" size:13.0f], NSFontAttributeName,
nil];
}
return attributes;
}
- (NSDictionary *)descriptionAttributes
{
static NSDictionary *attributes = nil;
if (!attributes)
{
attributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSColor darkGrayColor], NSForegroundColorAttributeName,
[NSFont fontWithName:@"Lucida Grande" size:10.0f], NSFontAttributeName,
nil];
}
return attributes;
}
- (NSDictionary *)highlightedDescriptionAttributes
{
static NSDictionary *attributes = nil;
if (!attributes)
{
attributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSColor whiteColor], NSForegroundColorAttributeName,
[NSFont fontWithName:@"Lucida Grande" size:10.0f], NSFontAttributeName,
nil];
}
return attributes;
}
@end