forked from nongio-zz/rik.theme
-
Notifications
You must be signed in to change notification settings - Fork 7
/
NSSegmentedCell+Rik.m
61 lines (57 loc) · 2.01 KB
/
NSSegmentedCell+Rik.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
#include "Rik.h"
@interface NSSegmentedCell(RikTheme)
@end
@implementation NSSegmentedCell(RikTheme)
- (NSColor*) textColor
{
//IT DOES NOT WORKS
if(_cell.state == GSThemeSelectedState)
return [NSColor whiteColor];
if (_cell.is_disabled)
return [NSColor disabledControlTextColor];
else
return [NSColor controlTextColor];
}
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
inView: (NSView*)controlView
{
CGFloat radius = 4;
cellFrame = NSInsetRect(cellFrame, 0.5, 0.5);
NSColor* strokeColorButton = [Rik controlStrokeColor];
NSBezierPath* roundedRectanglePath = [NSBezierPath bezierPathWithRoundedRect: cellFrame
xRadius: radius
yRadius: radius];
[strokeColorButton setStroke];
[roundedRectanglePath setLineWidth: 1];
[roundedRectanglePath stroke];
NSInteger i;
NSUInteger count = [_items count];
NSRect frame = cellFrame;
NSRect controlFrame = [controlView frame];
NSBezierPath* linesPath = [NSBezierPath bezierPath];
[linesPath setLineWidth: 1];
CGFloat offsetX = 0;
for (i = 0; i < count-1;i++)
{
frame.size.width = [[_items objectAtIndex: i] width];
if(frame.size.width == 0.0)
{
frame.size.width = (controlFrame.size.width - frame.origin.x) / (count);
}
offsetX += frame.size.width;
offsetX = floor(offsetX) + 0.5;
[linesPath moveToPoint: NSMakePoint(offsetX, NSMinY(frame) + 3)];
[linesPath lineToPoint: NSMakePoint(offsetX, NSMaxY(frame) - 3)];
}
[linesPath stroke];
}
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
if (NSIsEmptyRect(cellFrame))
return;
// i want to draw the border for last
[self drawInteriorWithFrame: cellFrame inView: controlView];
[self _drawBorderAndBackgroundWithFrame: cellFrame inView: controlView];
[self _drawFocusRingWithFrame: cellFrame inView: controlView];
}
@end