25 @
typedef CPProgressIndicatorStyle
58 CPControlSize _controlSize;
61 CPProgressIndicatorStyle _style;
65 BOOL _isDisplayedWhenStoppedSet;
66 BOOL _isDisplayedWhenStopped;
71 return @"progress-indicator";
79 @"default-height": 20,
85 @"circular-border-size": 1,
90 + (Class)_binderClassForBinding:(
CPString)aBinding
92 if (aBinding === CPValueBinding || aBinding ===
@"isIndeterminate")
93 return [_CPProgressIndicatorBinder class];
95 return [
super _binderClassForBinding:aBinding];
98 - (id)initWithFrame:(CGRect)aFrame
110 _isDisplayedWhenStoppedSet = NO;
123 - (void)setUsesThreadedAnimation:(BOOL)aFlag
131 - (void)startAnimation:(
id)aSender
135 [
self _hideOrDisplay];
142 - (void)stopAnimation:(
id)aSender
146 [
self _hideOrDisplay];
152 - (BOOL)usesThreadedAnimation
162 - (void)incrementBy:(
double)aValue
170 - (void)setDoubleValue:(
double)aValue
172 _doubleValue = MIN(MAX(aValue, _minValue), _maxValue);
180 - (double)doubleValue
189 - (void)setMinValue:(
double)aValue
206 - (void)setMaxValue:(
double)aValue
224 - (void)setControlSize:(CPControlSize)aControlSize
226 if (_controlSize == aControlSize)
229 _controlSize = aControlSize;
237 - (CPControlSize)controlSize
245 - (void)setControlTint:(CPControlTint)aControlTint
252 - (CPControlTint)controlTint
260 - (void)setBezeled:(BOOL)isBezeled
276 - (void)setIndeterminate:(BOOL)indeterminate
278 if (_indeterminate == indeterminate)
281 _indeterminate = indeterminate;
289 - (BOOL)isIndeterminate
291 return _indeterminate;
298 - (void)setStyle:(CPProgressIndicatorStyle)aStyle
300 if (_style == aStyle)
316 [
self setFrameSize:[[CPProgressIndicatorSpinningStyleColors[_controlSize] patternImage] size]];
318 [
self setFrameSize:CGSizeMake(CGRectGetWidth([
self frame]), [
self valueForThemeAttribute:@"default-height"])];
326 - (void)setDisplayedWhenStopped:(BOOL)isDisplayedWhenStopped
328 if (_isDisplayedWhenStoppedSet && _isDisplayedWhenStopped == isDisplayedWhenStopped)
331 _isDisplayedWhenStoppedSet = YES;
333 _isDisplayedWhenStopped = isDisplayedWhenStopped;
335 [
self _hideOrDisplay];
341 - (BOOL)isDisplayedWhenStopped
343 if (_isDisplayedWhenStoppedSet)
344 return _isDisplayedWhenStopped;
353 - (void)_hideOrDisplay
355 [
self setHidden:!_isAnimating && ![
self isDisplayedWhenStopped]];
358 - (void)setFrameSize:(CGSize)aSize
374 return [[
CPView alloc] initWithFrame:CGRectMakeZero()];
377 - (CGRect)rectForEphemeralSubviewNamed:(
CPString)aViewName
382 barWidth =
width * ((_doubleValue - _minValue) / (_maxValue - _minValue));
384 if (barWidth > 0.0 && barWidth < 4.0)
390 return CGRectMake(0, 0, barWidth, [
self valueForThemeAttribute:
@"default-height"]);
397 - (void)updateBackgroundColor
409 - (void)layoutSubviews
434 [barView setBackgroundColor:[
self currentValueForThemeAttribute:@"indeterminate-bar-color"]];
436 [barView setBackgroundColor:[
self currentValueForThemeAttribute:@"bar-color"]];
443 - (void)drawRect:(CGRect)aRect
448 rect = CGRectMakeCopy(aRect),
449 borderSize = [
self currentValueForThemeAttribute:@"circular-border-size"];
451 rect.origin.x += borderSize;
452 rect.origin.y += borderSize;
453 rect.size.width = rect.size.width - borderSize * 2;
454 rect.size.height = rect.size.height - borderSize * 2;
456 if ([
self doubleValue] > [
self minValue] && [
self doubleValue] < [
self maxValue])
458 var midX = CGRectGetMidX(rect),
459 midY = CGRectGetMidY(rect),
460 endAngle = Math.PI * 2 * (([
self doubleValue] - [
self minValue]) / ([
self maxValue] - [
self minValue])) - Math.PI / 2,
461 radius = MIN(rect.size.width / 2, rect.size.height / 2);
467 CGContextAddArc(context, midX, midY, radius, 3 * Math.PI / 2, endAngle, YES);
473 else if ([
self doubleValue] == [
self maxValue])
498 if (
self = [super initWithCoder:aCoder])
500 _minValue = [aCoder decodeObjectForKey:@"_minValue"];
501 _maxValue = [aCoder decodeObjectForKey:@"_maxValue"];
502 _doubleValue = [aCoder decodeObjectForKey:@"_doubleValue"];
503 _controlSize = [aCoder decodeObjectForKey:@"_controlSize"];
504 _indeterminate = [aCoder decodeObjectForKey:@"_indeterminate"];
505 _style = [aCoder decodeIntForKey:@"_style"];
506 _isAnimating = [aCoder decodeObjectForKey:@"_isAnimating"];
507 _isDisplayedWhenStoppedSet = [aCoder decodeObjectForKey:@"_isDisplayedWhenStoppedSet"];
508 _isDisplayedWhenStopped = [aCoder decodeObjectForKey:@"_isDisplayedWhenStopped"];
525 [aCoder encodeObject:_minValue forKey:@"_minValue"];
526 [aCoder encodeObject:_maxValue forKey:@"_maxValue"];
527 [aCoder encodeObject:_doubleValue forKey:@"_doubleValue"];
528 [aCoder encodeObject:_controlSize forKey:@"_controlSize"];
529 [aCoder encodeObject:_indeterminate forKey:@"_indeterminate"];
530 [aCoder encodeInt:_style forKey:@"_style"];
531 [aCoder encodeObject:_isAnimating forKey:@"_isAnimating"];
532 [aCoder encodeObject:_isDisplayedWhenStoppedSet forKey:@"_isDisplayedWhenStoppedSet"];
533 [aCoder encodeObject:_isDisplayedWhenStopped forKey:@"_isDisplayedWhenStopped"];
537 @implementation _CPProgressIndicatorBinder :
CPBinder 544 var value = aBinding === CPValueBinding ? 0.0 : YES;
546 [
self _setPlaceholder:value forMarker:CPMultipleValuesMarker isDefault:YES];
547 [
self _setPlaceholder:value forMarker:CPNoSelectionMarker isDefault:YES];
548 [
self _setPlaceholder:value forMarker:CPNotApplicableMarker isDefault:YES];
549 [
self _setPlaceholder:value forMarker:CPNullMarker isDefault:YES];
552 - (id)valueForBinding:(
CPString)aBinding
554 if (aBinding === CPValueBinding)
555 return [_source doubleValue];
556 else if (aBinding ===
@"isIndeterminate")
557 [_source isIndeterminate];
559 return [
super valueForBinding:aBinding];
562 - (BOOL)_setValue:(
id)aValue forBinding:(
CPString)aBinding
564 if (aBinding === CPValueBinding)
565 [_source setDoubleValue:aValue];
566 else if (aBinding ===
@"isIndeterminate")
567 [_source setIndeterminate:aValue];
574 - (void)setValue:(
id)aValue forBinding:(
CPString)aBinding
576 if (![
self _setValue:aValue forBinding:aBinding])
577 [
super setValue:aValue forBinding:aBinding];
580 - (void)setPlaceholderValue:(
id)aValue withMarker:(
CPString)aMarker forBinding:(
CPString)aBinding
582 if (![
self _setValue:aValue forBinding:aBinding])
583 [
super setPlaceholderValue:aValue withMarker:aMarker forBinding:aBinding];
id initWithFrame:(CGRect aFrame)
CPTheme defaultHudTheme()
CPGraphicsContext currentContext()
An object representation of nil.
function CGContextSetStrokeColor(aContext, aColor)
void setFrameSize:(CGSize aSize)
CPColor backgroundColor()
function CGContextAddLineToPoint(aContext, x, y)
function CGContextAddArc(aContext, x, y, radius, startAngle, endAngle, clockwise)
function CGContextStrokePath(aContext)
function CGContextAddEllipseInRect(aContext, aRect)
A mutable key-value pair collection.
function CGContextSetLineWidth(aContext, aLineWidth)
function CGContextClosePath(aContext)
An immutable string (collection of characters).
function CGContextSetFillColor(aContext, aColor)
void setNeedsDisplay:(BOOL aFlag)
void encodeWithCoder:(CPCoder aCoder)
function CGContextBeginPath(aContext)
void updateBackgroundColor()
CPColor backgroundColor()
var CPProgressIndicatorSpinningStyleColors
Defines methods for use when archiving & restoring (enc/decoding).
CPProgressIndicatorSpinningStyle
CPControlSize CPRegularControlSize
void setBackgroundColor:(CPColor aColor)
void setFrameSize:(CGSize aSize)
CPProgressIndicatorHUDBarStyle
CPProgressIndicatorStyle CPProgressIndicatorBarStyle
function CGContextFillPath(aContext)
function CGContextMoveToPoint(aContext, x, y)
void setDoubleValue:(double aValue)
CPView layoutEphemeralSubviewNamed:positioned:relativeToEphemeralSubviewNamed:(CPString aViewName, [positioned] CPWindowOrderingMode anOrderingMode, [relativeToEphemeralSubviewNamed] CPString relativeToViewName)