-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSFTableView.m
58 lines (44 loc) · 1.83 KB
/
SFTableView.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
//
// SFTableView.m
// BezelHUD
//
// Created by Julius Eckert on 27.01.08.
// Copyright 2008 Julius Eckert. All rights reserved.
//
#import "SFTableView.h"
@implementation SFTableView
- (void)highlightSelectionInClipRect:(NSRect)clipRect {
// 81,133,208 24,70,159
NSColor* color1 = [NSColor colorWithCalibratedRed:0.32 green:0.52 blue:0.82 alpha:.95];
NSColor* color2 = [NSColor colorWithCalibratedRed:0.09 green:0.28 blue:0.62 alpha:.95];
NSGradient* gradient = [[NSGradient alloc] initWithStartingColor:color1 endingColor:color2];
// [gradient drawInRect:clipRect angle:90];
NSColor *evenColor, *oddColor = [NSColor colorWithDeviceRed:0.06 green:0.06 blue:0.06 alpha:.85];
float cellHeight = [self rowHeight]+2;
NSRect visibleRect = [self visibleRect];
NSRect highlightRect;
evenColor = [NSColor colorWithCalibratedRed: 0.1 green: 0.1 blue: 0.1 alpha:.85];
highlightRect.origin = NSMakePoint(NSMinX(visibleRect), (int)(NSMinY(clipRect) / cellHeight) * cellHeight);
highlightRect.size = NSMakeSize(NSWidth(visibleRect), cellHeight);
while (NSMinY(highlightRect) < NSMaxY(clipRect)) {
NSRect clippedHighlightRect = NSIntersectionRect(highlightRect, clipRect);
int row = (int)((NSMinY(highlightRect) + cellHeight / 2.0) / cellHeight);
if ([self selectedRow] == row) {
[[NSColor colorWithCalibratedRed:.07 green:.22 blue:.54 alpha:1] setFill];
NSRectFill(clippedHighlightRect);
clippedHighlightRect.origin.y += .6;
clippedHighlightRect.size.height -= 1.2;
[gradient drawInRect:clippedHighlightRect angle:90];
} else {
NSColor *rowColor = (row % 2 == 0) ? evenColor : oddColor;
[rowColor set];
NSRectFill(clippedHighlightRect);
}
highlightRect.origin.y += cellHeight;
}
}
- (void)drawBackgroundInClipRect:(NSRect)clipRect {
[[self backgroundColor] setFill];
NSRectFill(clipRect);
}
@end