-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThumbnail.m
More file actions
252 lines (196 loc) · 5.76 KB
/
Thumbnail.m
File metadata and controls
252 lines (196 loc) · 5.76 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
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
//
// Thumbnail.m
// Beholder
//
// Created by Danny Espinoza on 10/19/06.
// Copyright 2006 Mesa Dynamics, LLC. All rights reserved.
//
#import "Thumbnail.h"
@implementation Thumbnail
- (id)init
{
self = [super init];
if(self) {
macVersion = 0;
Gestalt(gestaltSystemVersion, &macVersion);
if(macVersion >= 0x1040) {
NSColor* c1 = [NSColor colorWithCalibratedRed:0.0f green:0.4f blue:1.0f alpha:1.0];
NSColor* c2 = [NSColor colorWithCalibratedRed:0.0f green:0.2f blue:.50f alpha:1.0];
gradient = [[CTGradient gradientWithBeginningColor:c1 endingColor:c2] retain];
}
grid = nil;
}
return self;
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (void)dealloc
{
if(macVersion >= 0x1040) {
[gradient release];
}
[super dealloc];
}
- (void)setGrid:(Grid*)owner
{
grid = owner;
}
- (void)setTag:(int)anInt
{
tag = anInt;
}
- (int)tag
{
return tag;
}
- (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView
{
ImageResult* result = (ImageResult*)[self objectValue];
if(result == nil)
return;
if([self state] == NSOnState) {
/*if(grid && [grid isEqualTo:[[grid window] firstResponder]] == NO) {
[[NSColor colorWithCalibratedWhite:.80 alpha:1.0] set];
NSRectFill(frame);
}
else*/ {
if(macVersion >= 0x1040)
[gradient fillRect:frame angle:90];
else {
NSColor* c1 = [NSColor colorWithCalibratedRed:0.0f green:0.4f blue:1.0f alpha:1.0];
[c1 set];
NSRectFill(frame);
}
}
}
//[[NSGraphicsContext currentContext] setShouldAntialias:YES];
//[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
NSRect insetFrame = NSInsetRect(frame, 4.0, 4.0);
insetFrame.origin.x--;
insetFrame.origin.y--;
insetFrame.size.width++;
insetFrame.size.height++;
[super drawWithFrame:insetFrame inView:controlView];
if([result requiresPreview] && [result badgesAreVisible]) {
NSImage* badge = nil;
if([result preview])
badge = [NSImage imageNamed:@"iconok"];
else if([result checkingPreview]) {
if([result loadingPreview] || [result testedPreview])
badge = [NSImage imageNamed:@"icongrab"];
else
badge = [NSImage imageNamed:@"iconcheck"];
}
else if([result missingPreview])
badge = [NSImage imageNamed:@"iconx"];
if(badge) {
[badge setFlipped:YES];
NSRect badgeFrame = NSMakeRect(frame.origin.x + frame.size.width - 32.0, frame.origin.y + frame.size.height - 32.0, 32.0, 32.0);
[badge drawInRect:badgeFrame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:([result hasWindow] ? 1.0 : 0.5)];
}
}
NSRectEdge mySides[] = { NSMaxYEdge, NSMaxXEdge, };
float myGrays[] = { .125, .125, };
NSDrawTiledRects(frame, frame, mySides, myGrays, 2);
}
- (BOOL)isSelectable
{
return YES;
}
- (BOOL)ignoresMultiClick
{
return YES;
}
- (void)setState:(int)value
{
if(value == NSOnState)
[grid clickThumbnail:self];
[super setState:value];
}
- (NSComparisonResult)sortDefault:(id)otherCell
{
int t1 = [(ImageResult*)[self image] timestamp];
int t2 = [(ImageResult*)[otherCell image] timestamp];
if(t1 == t2)
return NSOrderedSame;
return (t1 < t2 ? NSOrderedAscending : NSOrderedDescending);
}
- (NSComparisonResult)sortURL:(id)otherCell
{
NSString* s1 = [(ImageResult*)[self image] imageURL];
NSString* s2 = [(ImageResult*)[otherCell image] imageURL];
if(s2 == nil)
return NSOrderedAscending;
if(s1 == nil)
return NSOrderedDescending;
return [s1 caseInsensitiveCompare:s2];
}
- (NSComparisonResult)sortArea:(id)otherCell
{
int w1 = [(ImageResult*)[self image] imageWidth];
int w2 = [(ImageResult*)[otherCell image] imageWidth];
int h1 = [(ImageResult*)[self image] imageHeight];
int h2 = [(ImageResult*)[otherCell image] imageHeight];
int a1 = w1 * h1;
int a2 = w2 * h2;
if(a1 == a2)
return NSOrderedSame;
return (a1 > a2 ? NSOrderedAscending : NSOrderedDescending);
}
- (NSComparisonResult)sortWidth:(id)otherCell
{
int w1 = [(ImageResult*)[self image] imageWidth];
int w2 = [(ImageResult*)[otherCell image] imageWidth];
if(w1 == w2)
return NSOrderedSame;
return (w1 > w2 ? NSOrderedAscending : NSOrderedDescending);
}
- (NSComparisonResult)sortHeight:(id)otherCell
{
int h1 = [(ImageResult*)[self image] imageHeight];
int h2 = [(ImageResult*)[otherCell image] imageHeight];
if(h1 == h2)
return NSOrderedSame;
return (h1 > h2 ? NSOrderedAscending : NSOrderedDescending);
}
- (NSComparisonResult)sortFileSize:(id)otherCell
{
int s1 = [(ImageResult*)[self image] imageSize];
int s2 = [(ImageResult*)[otherCell image] imageSize];
if(s1 == s2)
return NSOrderedSame;
return (s1 > s2 ? NSOrderedAscending : NSOrderedDescending);
}
- (NSComparisonResult)sortHue:(id)otherCell
{
if([self image] == nil)
return NSOrderedDescending;
if([otherCell image] == nil)
return NSOrderedAscending;
NSColor* c1 = [(ImageResult*)[self image] averageColor];
NSColor* c2 = [(ImageResult*)[otherCell image] averageColor];
return ([c1 hueComponent] > [c2 hueComponent] ? NSOrderedDescending : NSOrderedAscending);
}
- (NSComparisonResult)sortSaturation:(id)otherCell
{
if([self image] == nil)
return NSOrderedDescending;
if([otherCell image] == nil)
return NSOrderedAscending;
NSColor* c1 = [(ImageResult*)[self image] averageColor];
NSColor* c2 = [(ImageResult*)[otherCell image] averageColor];
return ([c1 saturationComponent] > [c2 saturationComponent] ? NSOrderedAscending : NSOrderedDescending);
}
- (NSComparisonResult)sortLightness:(id)otherCell
{
if([self image] == nil)
return NSOrderedDescending;
if([otherCell image] == nil)
return NSOrderedAscending;
NSColor* c1 = [(ImageResult*)[self image] averageColor];
NSColor* c2 = [(ImageResult*)[otherCell image] averageColor];
return ([c1 brightnessComponent] > [c2 brightnessComponent] ? NSOrderedAscending : NSOrderedDescending);
}
@end