forked from sprang/Inkpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWDColorIndicator.m
More file actions
86 lines (67 loc) · 1.97 KB
/
WDColorIndicator.m
File metadata and controls
86 lines (67 loc) · 1.97 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
//
// WDColorIndicator.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) 2008-2013 Steve Sprang
//
#import "WDColorIndicator.h"
#import "WDColor.h"
#import "WDUtilities.h"
@implementation WDColorIndicator
@synthesize alphaMode = alphaMode_;
@synthesize color = color_;
+ (WDColorIndicator *) colorIndicator
{
WDColorIndicator *indicator = [[WDColorIndicator alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
return indicator;
}
- (id) initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
self.color = [WDColor whiteColor];
self.opaque = NO;
UIView *overlay = [[UIView alloc] initWithFrame:self.bounds];
[self addSubview:overlay];
overlay.layer.borderColor = [UIColor whiteColor].CGColor;
overlay.layer.borderWidth = 3;
overlay.layer.cornerRadius = CGRectGetWidth(self.bounds) / 2.0f;
overlay.layer.shadowOpacity = 0.5f;
overlay.layer.shadowRadius = 1;
overlay.layer.shadowOffset = CGSizeMake(0, 0);
return self;
}
- (void) setColor:(WDColor *)color
{
if ([color isEqual:color_]) {
return;
}
color_ = color;
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect bounds = CGRectInset([self bounds], 2, 2);
if (self.alphaMode) {
CGContextSaveGState(ctx);
CGContextAddEllipseInRect(ctx, bounds);
CGContextClip(ctx);
WDDrawTransparencyDiamondInRect(ctx, bounds);
CGContextRestoreGState(ctx);
[[self color] set];
} else {
[[[self color] opaqueUIColor] set];
}
CGContextFillEllipseInRect(ctx, bounds);
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
return NO;
}
@end