-
Notifications
You must be signed in to change notification settings - Fork 0
/
IndicatorButton.mm
137 lines (103 loc) · 3.46 KB
/
IndicatorButton.mm
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
// -*- Mode: ObjC -*-
//
// Copyright (C) 2011, Brad Howes. All rights reserved.
//
#import "IndicatorButton.h"
#import "IndicatorLight.h"
@implementation IndicatorButton
@synthesize light, label;
- (void)setOn:(BOOL)value
{
self.light.illuminated = value;
}
- (BOOL)on
{
return self.light.illuminated;
}
- (void)dealloc {
[light release];
[label release];
[super dealloc];
}
- (NSTimeInterval)blinkingInterval
{
return light.blinkingInterval;
}
- (void)setBlinkingInterval:(NSTimeInterval)interval
{
light.blinkingInterval = interval;
}
@end
#if 0
- (void)drawRect:(CGRect)rect
{
if (self.enabled == NO) return;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, true);
CGContextSetAllowsAntialiasing(context, true);
const CGFloat lineWidth = 1.5;
rect = CGRectInset(self.bounds, lineWidth / 2.0f, lineWidth / 2.0f);
CGContextSetLineWidth(context, lineWidth);
CGContextSetLineJoin(context, kCGLineJoinMiter);
CGContextSetLineCap(context, kCGLineCapRound);
const CGFloat cornerRad = 6.0f;
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
// CGColorRef color = CGColorCreate(rgb, (CGFloat[]){ 1.f, .5f, .0f, 1.f }); // orange
// CGColorRef color = CGColorCreate(rgb, (CGFloat[]){ .2f, .2f, .2f, 1.f }); // dark grey
// CGColorRef color = CGColorCreate(rgb, (CGFloat[]){ .3f, .3f, .3f, 1.f }); // dark grey
CGColorRef color = CGColorCreate(rgb, (CGFloat[]){ .0f, 1.f, 1.f, .5f }); // cyan
CGContextSetStrokeColorWithColor(context, color);
CGColorRelease(color);
CGColorSpaceRelease(rgb);
CGContextBeginPath(context);
// Top Left
CGContextMoveToPoint(context, rect.origin.x, cornerRad);
CGContextAddArcToPoint(context, rect.origin.x, rect.origin.y, rect.origin.x + cornerRad, rect.origin.y, cornerRad);
// Top right
CGContextAddArcToPoint(context, rect.origin.x + rect.size.width, rect.origin.y, rect.origin.x + rect.size.width,
rect.origin.x + cornerRad, cornerRad);
// Bottom right
CGContextAddArcToPoint(context, rect.origin.x + rect.size.width, rect.origin.y + rect.size.height,
rect.origin.x + rect.size.width - cornerRad, rect.origin.y + rect.size.height, cornerRad);
// Bottom left
CGContextAddArcToPoint(context, rect.origin.x, rect.origin.y + rect.size.height, rect.origin.x, rect.origin.y,
cornerRad);
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathStroke);
}
@implementation IndicatorButton
@synthesize light, label;
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
// UIImage* image = [UIImage imageNamed:@"BlackPushButton.png"];
// image = [image stretchableImageWithLeftCapWidth:15 topCapHeight:0];
// background = [[UIImageView alloc] initWithImage:image];
// [self insertSubview:background atIndex:0];
// background.frame = self.bounds;
}
return self;
}
- (void)setOn:(BOOL)value
{
self.light.illuminated = value;
}
- (BOOL)on
{
return self.light.illuminated;
}
- (void)dealloc {
[light release];
[label release];
[super dealloc];
}
- (NSTimeInterval)blinkingInterval
{
return light.blinkingInterval;
}
- (void)setBlinkingInterval:(NSTimeInterval)interval
{
light.blinkingInterval = interval;
}
@end
#endif