Skip to content

Commit

Permalink
Prevent drawing things that are undefined in SSPieProgressView
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Oct 19, 2012
1 parent 6ff11e7 commit 27e5691
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions SSToolkit/SSPieProgressView.m
Expand Up @@ -84,30 +84,36 @@ - (void)drawRect:(CGRect)rect {
CGContextClipToRect(context, rect);

// Background
[_pieBackgroundColor set];
CGContextFillEllipseInRect(context, rect);
if (_pieBackgroundColor) {
[_pieBackgroundColor set];
CGContextFillEllipseInRect(context, rect);
}

// Fill
[_pieFillColor set];
if (_progress > 0.0f) {
CGPoint center = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
CGFloat radius = center.y;
CGFloat angle = DEGREES_TO_RADIANS((360.0f * _progress) + kAngleOffset);
CGPoint points[3] = {
CGPointMake(center.x, 0.0f),
center,
CGPointMake(center.x + radius * cosf(angle), center.y + radius * sinf(angle))
};
CGContextAddLines(context, points, sizeof(points) / sizeof(points[0]));
CGContextAddArc(context, center.x, center.y, radius, DEGREES_TO_RADIANS(kAngleOffset), angle, false);
CGContextDrawPath(context, kCGPathEOFill);
if (_pieFillColor) {
[_pieFillColor set];
if (_progress > 0.0f) {
CGPoint center = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
CGFloat radius = center.y;
CGFloat angle = DEGREES_TO_RADIANS((360.0f * _progress) + kAngleOffset);
CGPoint points[3] = {
CGPointMake(center.x, 0.0f),
center,
CGPointMake(center.x + radius * cosf(angle), center.y + radius * sinf(angle))
};
CGContextAddLines(context, points, sizeof(points) / sizeof(points[0]));
CGContextAddArc(context, center.x, center.y, radius, DEGREES_TO_RADIANS(kAngleOffset), angle, false);
CGContextDrawPath(context, kCGPathEOFill);
}
}

// Border
[_pieBorderColor set];
CGContextSetLineWidth(context, _pieBorderWidth);
CGRect pieInnerRect = CGRectMake(_pieBorderWidth / 2.0f, _pieBorderWidth / 2.0f, rect.size.width - _pieBorderWidth, rect.size.height - _pieBorderWidth);
CGContextStrokeEllipseInRect(context, pieInnerRect);
if (_pieBorderColor && _pieBorderWidth > 0.0f) {
[_pieBorderColor set];
CGContextSetLineWidth(context, _pieBorderWidth);
CGRect pieInnerRect = CGRectMake(_pieBorderWidth / 2.0f, _pieBorderWidth / 2.0f, rect.size.width - _pieBorderWidth, rect.size.height - _pieBorderWidth);
CGContextStrokeEllipseInRect(context, pieInnerRect);
}
}


Expand Down

0 comments on commit 27e5691

Please sign in to comment.