forked from uranpro/ATMHud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATMProgressLayer.m
53 lines (46 loc) · 1.99 KB
/
ATMProgressLayer.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
/*
* ATMHudProgressLayer.m
* ATMHud
*
* Created by Marcel Müller on 2011-03-01.
* Copyright (c) 2010-2011, Marcel Müller (atomcraft)
* All rights reserved.
*
* https://github.com/atomton/ATMHud
*/
#import "ATMProgressLayer.h"
@implementation ATMProgressLayer
@synthesize theProgress, progressBorderWidth, progressBorderRadius, progressBarRadius, progressBarInset;
- (void)drawInContext:(CGContextRef)ctx {
UIGraphicsPushContext(ctx);
if (theProgress > 0) {
CGRect rrect = CGRectInset(self.bounds, progressBorderWidth, progressBorderWidth);
CGFloat radius = progressBorderRadius;
CGFloat minx = CGRectGetMinX(rrect), midx = CGRectGetMidX(rrect), maxx = CGRectGetMaxX(rrect);
CGFloat miny = CGRectGetMinY(rrect), midy = CGRectGetMidY(rrect), maxy = CGRectGetMaxY(rrect);
CGContextMoveToPoint(ctx, minx, midy);
CGContextAddArcToPoint(ctx, minx, miny, midx, miny, radius);
CGContextAddArcToPoint(ctx, maxx, miny, maxx, midy, radius);
CGContextAddArcToPoint(ctx, maxx, maxy, midx, maxy, radius);
CGContextAddArcToPoint(ctx, minx, maxy, minx, midy, radius);
CGContextClosePath(ctx);
CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1);
CGContextSetLineWidth(ctx, progressBorderWidth);
CGContextDrawPath(ctx, kCGPathStroke);
radius = progressBarRadius;
rrect = CGRectInset(rrect, progressBarInset, progressBarInset);
rrect.size.width = rrect.size.width * theProgress;
minx = CGRectGetMinX(rrect), midx = CGRectGetMidX(rrect), maxx = CGRectGetMaxX(rrect);
miny = CGRectGetMinY(rrect), midy = CGRectGetMidY(rrect), maxy = CGRectGetMaxY(rrect);
CGContextMoveToPoint(ctx, minx, midy);
CGContextAddArcToPoint(ctx, minx, miny, midx, miny, radius);
CGContextAddArcToPoint(ctx, maxx, miny, maxx, midy, radius);
CGContextAddArcToPoint(ctx, maxx, maxy, midx, maxy, radius);
CGContextAddArcToPoint(ctx, minx, maxy, minx, midy, radius);
CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx,1, 1, 1, 1);
CGContextDrawPath(ctx, kCGPathFill);
}
UIGraphicsPopContext();
}
@end