forked from AlessandroSangiuliano/rik.theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSSegmentedCell+Rik.m
73 lines (68 loc) · 2.69 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
62
63
64
65
66
67
68
69
70
71
72
73
#include "Rik.h"
// @interface NSSegmentedCell(RikTheme)
@interface Rik(NSSegmentedCell)
@end
@implementation Rik(NSSegmentedCell)
// - (NSColor*) textColor
- (NSColor*) _overrideNSSegmentedCellMethod_textColor
{
RIKLOG(@"_overrideNSSegmentedCellMethod_textColor");
//IT DOES NOT WORKS
NSSegmentedCell *xself = (NSSegmentedCell*) self;
if([xself state] == GSThemeSelectedState)
return [NSColor whiteColor];
if ([xself isEnabled] == NO)
return [NSColor disabledControlTextColor];
else
return [NSColor controlTextColor];
}
// - (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
// inView: (NSView*)controlView
- (void) _overrideNSSegmentedCellMethod__drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
inView: (NSView*)controlView
{
RIKLOG(@"_overrideNSSegmentedCellMethod__drawBorderAndBackgroundWithFrame");
NSSegmentedCell *xself = (NSSegmentedCell*) self;
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 = [xself segmentCount];
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 = [xself widthForSegment: i];
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
- (void) _overrideNSSegmentedCellMethod_drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
RIKLOG(@"_overrideNSSegmentedCellMethod_drawWithFrame");
NSCell *xself = (NSCell*) self;
if (NSIsEmptyRect(cellFrame))
return;
// i want to draw the border for last
[xself drawInteriorWithFrame: cellFrame inView: controlView];
[xself _drawBorderAndBackgroundWithFrame: cellFrame inView: controlView];
[xself _drawFocusRingWithFrame: cellFrame inView: controlView];
}
@end