-
Notifications
You must be signed in to change notification settings - Fork 0
/
LevelSettingView.mm
103 lines (86 loc) · 2.74 KB
/
LevelSettingView.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
//
// LevelSettingView.mm
// Datac
//
// Created by Brad Howes on 6/4/11.
// Copyright 2011 Brad Howes. All rights reserved.
//
#import "LevelSettingView.h"
@interface LevelSettingView (Private)
- (void)makeFormatter;
- (void)fadeView;
- (void)hideView;
@end
@implementation LevelSettingView
- (void)dealloc {
[hidingTimer invalidate];
[hidingTimer release];
[formatter release];
[super dealloc];
}
- (void)makeFormatter
{
formatter = [[NSNumberFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setMaximumSignificantDigits:5];
[formatter setUsesSignificantDigits:YES];
}
- (void)fadeView
{
[hidingTimer release];
hidingTimer = nil;
[formatter release];
formatter = nil;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.40];
self.alpha = 0.0;
[UIView setAnimationDidStopSelector:@selector(hideView)];
[UIView commitAnimations];
}
- (void)hideView
{
self.hidden = YES;
}
- (void)setName:(NSString*)name value:(Float32)value
{
if (formatter == nil) [self makeFormatter];
self.text = [NSString stringWithFormat:@"%@\n%@", name,
[formatter stringFromNumber:[NSNumber numberWithFloat:value]], nil];
self.hidden = NO;
self.alpha = 1.0;
if (hidingTimer != nil) {
[hidingTimer invalidate];
[hidingTimer release];
}
hidingTimer = [[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fadeView)
userInfo:nil repeats:NO] retain];
}
- (void)fillRoundedRect:(CGRect)rect inContext:(CGContextRef)context
{
float radius = 5.0f;
CGContextBeginPath(context);
CGContextSetGrayFillColor(context, 0.2, 0.7);
CGContextMoveToPoint(context, CGRectGetMinX(rect) + radius, CGRectGetMinY(rect));
CGContextAddArc(context, CGRectGetMaxX(rect) - radius, CGRectGetMinY(rect) + radius, radius, 3 * M_PI / 2, 0, 0);
CGContextAddArc(context, CGRectGetMaxX(rect) - radius, CGRectGetMaxY(rect) - radius, radius, 0, M_PI / 2, 0);
CGContextAddArc(context, CGRectGetMinX(rect) + radius, CGRectGetMaxY(rect) - radius, radius, M_PI / 2, M_PI, 0);
CGContextAddArc(context, CGRectGetMinX(rect) + radius, CGRectGetMinY(rect) + radius, radius, M_PI, 3 * M_PI / 2, 0);
CGContextClosePath(context);
CGContextFillPath(context);
}
- (void)drawRect:(CGRect)rect
{
CGRect boxRect = self.bounds;
CGContextRef ctxt = UIGraphicsGetCurrentContext();
boxRect = CGRectInset(boxRect, 1.0f, 1.0f);
[self fillRoundedRect:boxRect inContext:ctxt];
[super drawRect:rect];
}
- (void)hide
{
if (! self.hidden) {
self.hidden = YES;
}
}
@end