Repository navigation
Expand file tree
/
Copy pathWDGradientStopIndicator.m
More file actions
148 lines (110 loc) · 3.55 KB
/
Copy pathWDGradientStopIndicator.m
File metadata and controls
148 lines (110 loc) · 3.55 KB
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
138
139
140
141
142
143
144
145
146
147
148
//
// WDGradientStopIndicator.m
// Inkpad
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2010-2013 Steve Sprang
//
#import "WDColor.h"
#import "WDGradientStopIndicator.h"
#import "WDGradientStop.h"
#import "WDUtilities.h"
const float kColorRectInset = 10;
@implementation WDGradientStopOverlay
@synthesize indicator;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
self.opaque = NO;
self.backgroundColor = nil;
self.layer.shadowOpacity = 0.5f;
self.layer.shadowRadius = 1;
self.layer.shadowOffset = CGSizeMake(0, 0);
return self;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect colorRect = [indicator colorRect];
CGRect outsideRect = CGRectInset(colorRect, -2, -2);
outsideRect.size.height -= 1;
outsideRect.origin.y += 1;
CGMutablePathRef pathRef = CGPathCreateMutable();
CGPathMoveToPoint(pathRef, NULL, CGRectGetMinX(outsideRect), CGRectGetMinY(outsideRect));
CGPathAddLineToPoint(pathRef, NULL, CGRectGetMidX(self.bounds), CGRectGetMinY(self.bounds) + 0);
CGPathAddLineToPoint(pathRef, NULL, CGRectGetMaxX(outsideRect), CGRectGetMinY(outsideRect));
CGPathAddLineToPoint(pathRef, NULL, CGRectGetMaxX(outsideRect), CGRectGetMaxY(outsideRect));
CGPathAddLineToPoint(pathRef, NULL, CGRectGetMinX(outsideRect), CGRectGetMaxY(outsideRect));
CGPathCloseSubpath(pathRef);
CGPathAddRect(pathRef, NULL, CGRectInset(colorRect, 1, 1));
[[UIColor whiteColor] set];
CGContextAddPath(ctx, pathRef);
CGContextEOFillPath(ctx);
if (indicator.selected) {
CGRect selectionRect = CGRectOffset(outsideRect, 0, outsideRect.size.height);
selectionRect.size.height = 2;
[[UIColor colorWithRed:0.0f green:(118.0f / 255.0) blue:1.0f alpha:1.0f] set];
CGContextFillRect(ctx, selectionRect);
}
CGPathRelease(pathRef);
}
@end
@implementation WDGradientStopIndicator
@synthesize stop = stop_;
@synthesize selected = selected_;
@synthesize overlay = overlay_;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
self.opaque = NO;
self.backgroundColor = nil;
return self;
}
- (id) initWithStop:(WDGradientStop *)stop
{
self = [self initWithFrame:CGRectMake(0,0,39,39)];
if (!self) {
return nil;
}
self.stop = stop;
overlay_ = [[WDGradientStopOverlay alloc] initWithFrame:self.bounds];
overlay_.indicator = self;
[self addSubview:overlay_];
return self;
}
- (void) setStop:(WDGradientStop *)stop
{
stop_ = stop;
[self setNeedsDisplay];
}
- (void) setSelected:(BOOL)flag
{
selected_ = flag;
[overlay_ setNeedsDisplay];
}
- (CGRect) colorRect
{
CGRect rect = self.bounds;
rect = CGRectInset(rect, kColorRectInset, kColorRectInset);
rect.size.height = rect.size.width;
rect.origin.y = CGRectGetHeight(self.bounds) - CGRectGetHeight(rect) - (kColorRectInset - 1);
return rect;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect colorRect = [self colorRect];
WDDrawTransparencyDiamondInRect(ctx, colorRect);
[stop_.color set];
CGContextFillRect(ctx, colorRect);
}
@end