-
Notifications
You must be signed in to change notification settings - Fork 10
/
Rik+Stepper.m
137 lines (124 loc) · 5.68 KB
/
Rik+Stepper.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
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
#import "Rik.h"
#import "Rik+Stepper.h"
@implementation Rik(RikStepper)
- (NSRect) stepperUpButtonRectWithFrame: (NSRect)frame
{
NSRect upRect = frame;
upRect.size.width = 13;
upRect.size.height = 12;
upRect.origin.x = frame.origin.x + frame.size.width/2 - 6;
upRect.origin.y = frame.origin.y + frame.size.height/2-1;
return upRect;
}
- (NSRect) stepperDownButtonRectWithFrame: (NSRect)frame
{
NSRect upRect = frame;
upRect.size.width = 13;
upRect.size.height = 12;
upRect.origin.x = frame.origin.x + frame.size.width/2 - 6;
upRect.origin.y = frame.origin.y + frame.size.height/2 - 11;
return upRect;
}
- (void) drawStepperBorder: (NSRect)frame
{
}
- (NSRect) drawStepperLightButton: (NSRect)border : (NSRect)clip
{
return NSZeroRect;
}
- (void) drawStepperUpButton: (NSRect)aRect
{
NSImage *image = [NSImage imageNamed: @"common_ArrowUp"];
[image drawInRect: NSInsetRect(aRect, 4, 4)
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
respectFlipped: YES
hints: nil];
}
- (void) drawStepperHighlightUpButton: (NSRect)aRect
{
NSGradient * fillgradient = [self _buttonGradientWithColor:[NSColor selectedControlColor]];
CGFloat roundedRectangleCornerRadius = 5;
NSRect roundedRectangleRect = aRect;
NSRect roundedRectangleInnerRect = NSInsetRect(roundedRectangleRect, roundedRectangleCornerRadius, roundedRectangleCornerRadius);
NSBezierPath* roundedRectanglePath = [NSBezierPath bezierPath];
[roundedRectanglePath moveToPoint: NSMakePoint(NSMinX(roundedRectangleRect), NSMinY(roundedRectangleRect))];
[roundedRectanglePath lineToPoint: NSMakePoint(NSMaxX(roundedRectangleRect), NSMinY(roundedRectangleRect))];
[roundedRectanglePath appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(roundedRectangleInnerRect), NSMaxY(roundedRectangleInnerRect)) radius: roundedRectangleCornerRadius startAngle: 0 endAngle: 90];
[roundedRectanglePath appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(roundedRectangleInnerRect), NSMaxY(roundedRectangleInnerRect)) radius: roundedRectangleCornerRadius startAngle: 90 endAngle: 180];
[roundedRectanglePath closePath];
[fillgradient drawInBezierPath:roundedRectanglePath angle:90];
NSImage *image = [NSImage imageNamed: @"common_ArrowUp"];
[image drawInRect: NSInsetRect(aRect, 4, 4)
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
respectFlipped: YES
hints: nil];
}
- (void) drawStepperDownButton: (NSRect)aRect
{
NSImage *image = [NSImage imageNamed: @"common_ArrowDown"];
[image drawInRect: NSInsetRect(aRect, 4, 4)
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
respectFlipped: YES
hints: nil];
}
- (void) drawStepperHighlightDownButton: (NSRect)aRect
{
NSGradient * fillgradient = [self _buttonGradientWithColor:[NSColor selectedControlColor]];
CGFloat roundedRectangleCornerRadius = 5;
NSRect roundedRectangleRect = aRect;
NSRect roundedRectangleInnerRect = NSInsetRect(roundedRectangleRect, roundedRectangleCornerRadius, roundedRectangleCornerRadius);
NSBezierPath* roundedRectanglePath = [NSBezierPath bezierPath];
[roundedRectanglePath appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(roundedRectangleInnerRect), NSMinY(roundedRectangleInnerRect)) radius: roundedRectangleCornerRadius startAngle: 180 endAngle: 270];
[roundedRectanglePath appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(roundedRectangleInnerRect), NSMinY(roundedRectangleInnerRect)) radius: roundedRectangleCornerRadius startAngle: 270 endAngle: 360];
[roundedRectanglePath lineToPoint: NSMakePoint(NSMaxX(roundedRectangleRect), NSMaxY(roundedRectangleRect))];
[roundedRectanglePath lineToPoint: NSMakePoint(NSMinX(roundedRectangleRect), NSMaxY(roundedRectangleRect))];
[roundedRectanglePath closePath];
[fillgradient drawInBezierPath:roundedRectanglePath angle:90];
NSImage *image = [NSImage imageNamed: @"common_ArrowDown"];
[image drawInRect: NSInsetRect(aRect, 4, 4)
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
respectFlipped: YES
hints: nil];
}
- (void) drawStepperCell: (NSCell*)cell
withFrame: (NSRect)cellFrame
inView: (NSView*)controlView
highlightUp: (BOOL)highlightUp
highlightDown: (BOOL)highlightDown
{
const NSRect upRect = [self stepperUpButtonRectWithFrame: cellFrame];
const NSRect downRect = [self stepperDownButtonRectWithFrame: cellFrame];
NSRect frame = NSMakeRect(cellFrame.origin.x + cellFrame.size.width/2 - 6, cellFrame.origin.y + cellFrame.size.height/2 - 11, 13, 22);
CGFloat radius = 5;
NSGradient * fillgradient = [self _buttonGradientWithColor:[NSColor controlBackgroundColor]];
NSBezierPath* roundedRectanglePath = [NSBezierPath bezierPathWithRoundedRect:frame xRadius: radius yRadius: radius];
[fillgradient drawInBezierPath:roundedRectanglePath angle:90];
if (highlightUp)
[self drawStepperHighlightUpButton: upRect];
else
[self drawStepperUpButton: upRect];
if (highlightDown)
[self drawStepperHighlightDownButton: downRect];
else
[self drawStepperDownButton: downRect];
NSColor* strokeColor = [Rik controlStrokeColor];
[strokeColor setStroke];
[roundedRectanglePath setLineWidth: 1];
[roundedRectanglePath stroke];
}
-(NSBezierPath *) stepperBezierPathWithFrame:(NSRect)frame
{
CGFloat radius = 5;
frame = NSMakeRect(frame.origin.x + frame.size.width/2 - 6, frame.origin.y + frame.size.height/2 - 11, 13, 22);
NSBezierPath* roundedRectanglePath = [NSBezierPath bezierPathWithRoundedRect:frame xRadius: radius yRadius: radius];
return RETAIN(roundedRectanglePath);
}
@end