-
Notifications
You must be signed in to change notification settings - Fork 10
/
Rik+Segmented.m
58 lines (52 loc) · 2.78 KB
/
Rik+Segmented.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
#import "Rik.h"
#import "Rik+Button.h"
@implementation Rik(RikSegmented)
- (void) drawSegmentedControlSegment: (NSCell *)cell
withFrame: (NSRect)cellFrame
inView: (NSView *)controlView
style: (NSSegmentStyle)style
state: (GSThemeControlState)state
roundedLeft: (BOOL)roundedLeft
roundedRight: (BOOL)roundedRight
{
NSColor * c = [[NSColor controlBackgroundColor] shadowWithLevel: 0.1];
NSGradient* normalButtongradient = [self _bezelGradientWithColor: c];
NSColor* buttonStroke = [Rik controlStrokeColor];
NSColor* buttonFill = [NSColor colorWithCalibratedRed: 0.58 green: 0.58 blue: 0.58 alpha: 1];
NSColor* buttonFillLight = [NSColor colorWithCalibratedRed: 0.663 green: 0.663 blue: 0.663 alpha: 1];
NSGradient* buttonGradient = [[NSGradient alloc] initWithColorsAndLocations:
buttonFill, 0.0,
buttonFill, 0.64,
buttonFillLight, 1.0, nil];
CGFloat button2CornerRadius = 4;
NSRect button2Rect = cellFrame;
NSRect button2InnerRect = NSInsetRect(button2Rect, button2CornerRadius, button2CornerRadius);
NSBezierPath* buttonPath;
if(roundedRight)
{
buttonPath = [NSBezierPath bezierPath];
[buttonPath moveToPoint: NSMakePoint(NSMinX(button2Rect), NSMinY(button2Rect))];
[buttonPath appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(button2InnerRect), NSMinY(button2InnerRect)) radius: button2CornerRadius startAngle: 270 endAngle: 360];
[buttonPath appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(button2InnerRect), NSMaxY(button2InnerRect)) radius: button2CornerRadius startAngle: 0 endAngle: 90];
[buttonPath lineToPoint: NSMakePoint(NSMinX(button2Rect), NSMaxY(button2Rect))];
[buttonPath closePath];
}
else if(roundedLeft)
{
buttonPath = [NSBezierPath bezierPath];
[buttonPath appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(button2InnerRect), NSMinY(button2InnerRect)) radius: button2CornerRadius startAngle: 180 endAngle: 270];
[buttonPath lineToPoint: NSMakePoint(NSMaxX(button2Rect), NSMinY(button2Rect))];
[buttonPath lineToPoint: NSMakePoint(NSMaxX(button2Rect), NSMaxY(button2Rect))];
[buttonPath appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(button2InnerRect), NSMaxY(button2InnerRect)) radius: button2CornerRadius startAngle: 90 endAngle: 180];
[buttonPath closePath];
}
else
{
buttonPath = [NSBezierPath bezierPathWithRect: button2Rect];
}
if(state == GSThemeSelectedState)
[buttonGradient drawInBezierPath: buttonPath angle: 90];
else
[normalButtongradient drawInBezierPath: buttonPath angle: 90];
}
@end