Permalink
Browse files

Stopped using YRKSpinningProgressIndicator in favor of Apple's defaul…

…t implementation
  • Loading branch information...
1 parent c0a1c6f commit d8dbe5151763f7f9f5b0c8f4248d20cbc566c8e0 @alexzielenski committed Nov 21, 2011
View
45 ScrollToRefresh/src/3rd Party/YRKSpinningProgressIndicator/YRKSpinningProgressIndicator.h
@@ -1,45 +0,0 @@
-//
-// YRKSpinningProgressIndicator.h
-//
-// Copyright 2009 Kelan Champagne. All rights reserved.
-//
-
-
-@interface YRKSpinningProgressIndicator : NSView {
- int _position;
- int _numFins;
- NSColor **_finColors;
-
- BOOL _isAnimating;
- BOOL _isFadingOut;
- NSTimer *_animationTimer;
- NSThread *_animationThread;
-
- NSColor *_foreColor;
- NSColor *_backColor;
- BOOL _drawsBackground;
-
- BOOL _displayedWhenStopped;
- BOOL _usesThreadedAnimation;
-
- // For determinate mode
- BOOL _isIndeterminate;
- double _currentValue;
- double _maxValue;
-}
-
-@property (nonatomic, retain) NSColor *color;
-@property (nonatomic, retain) NSColor *backgroundColor;
-@property (nonatomic, assign) BOOL drawsBackground;
-
-@property (nonatomic, assign, getter=isDisplayedWhenStopped) BOOL displayedWhenStopped;
-@property (nonatomic, assign) BOOL usesThreadedAnimation;
-
-@property (nonatomic, assign, getter=isIndeterminate) BOOL indeterminate;
-@property (nonatomic, assign) double doubleValue;
-@property (nonatomic, assign) double maxValue;
-
-- (void)stopAnimation:(id)sender;
-- (void)startAnimation:(id)sender;
-
-@end
View
427 ScrollToRefresh/src/3rd Party/YRKSpinningProgressIndicator/YRKSpinningProgressIndicator.m
@@ -1,427 +0,0 @@
-//
-// YRKSpinningProgressIndicator.m
-//
-// Copyright 2009 Kelan Champagne. All rights reserved.
-//
-
-#import "YRKSpinningProgressIndicator.h"
-
-
-// Some constants to control the animation
-#define kAlphaWhenStopped 0.15
-#define kFadeMultiplier 0.85
-
-
-@interface YRKSpinningProgressIndicator ()
-
-- (void)updateFrame:(NSTimer *)timer;
-- (void)animateInBackgroundThread;
-- (void)actuallyStartAnimation;
-- (void)actuallyStopAnimation;
-- (void)generateFinColorsStartAtPosition:(int)startPosition;
-
-@end
-
-
-@implementation YRKSpinningProgressIndicator
-
-@synthesize color = _foreColor;
-@synthesize backgroundColor = _backColor;
-@synthesize drawsBackground = _drawsBackground;
-@synthesize displayedWhenStopped = _displayedWhenStopped;
-@synthesize usesThreadedAnimation = _usesThreadedAnimation;
-@synthesize indeterminate = _isIndeterminate;
-@synthesize doubleValue = _currentValue;
-@synthesize maxValue = _maxValue;
-
-
-#pragma mark Init
-
-- (id)initWithFrame:(NSRect)frame
-{
- self = [super initWithFrame:frame];
- if (self) {
- _position = 0;
- _numFins = 12;
- _finColors = calloc(_numFins, sizeof(NSColor*));
-
- _isAnimating = NO;
- _isFadingOut = NO;
-
- _foreColor = [[NSColor blackColor] retain];
- _backColor = [[NSColor clearColor] retain];
- _drawsBackground = NO;
-
- _displayedWhenStopped = YES;
- _usesThreadedAnimation = YES;
-
- _isIndeterminate = YES;
- _currentValue = 0.0;
- _maxValue = 100.0;
- }
- return self;
-}
-
-- (void) dealloc
-{
- for (int i=0; i<_numFins; i++) {
- [_finColors[i] release];
- }
- free(_finColors);
- [_foreColor release];
- [_backColor release];
- if (_isAnimating) [self stopAnimation:self];
-
- [super dealloc];
-}
-
-# pragma mark NSView overrides
-
-- (void)viewDidMoveToWindow
-{
- [super viewDidMoveToWindow];
-
- if ([self window] == nil) {
- // No window? View hierarchy may be going away. Dispose timer to clear circular retain of timer to self to timer.
- [self actuallyStopAnimation];
- }
- else if (_isAnimating) {
- [self actuallyStartAnimation];
- }
-}
-
-- (void)drawRect:(NSRect)rect
-{
- // Determine size based on current bounds
- NSSize size = [self bounds].size;
- CGFloat theMaxSize;
- if(size.width >= size.height)
- theMaxSize = size.height;
- else
- theMaxSize = size.width;
-
- // fill the background, if set
- if(_drawsBackground) {
- [_backColor set];
- [NSBezierPath fillRect:[self bounds]];
- }
-
- CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
- [NSGraphicsContext saveGraphicsState];
-
- // Move the CTM so 0,0 is at the center of our bounds
- CGContextTranslateCTM(currentContext,[self bounds].size.width/2,[self bounds].size.height/2);
-
- if (_isIndeterminate) {
- NSBezierPath *path = [[NSBezierPath alloc] init];
- CGFloat lineWidth = 0.0859375 * theMaxSize; // should be 2.75 for 32x32
- CGFloat lineStart = 0.234375 * theMaxSize; // should be 7.5 for 32x32
- CGFloat lineEnd = 0.421875 * theMaxSize; // should be 13.5 for 32x32
- [path setLineWidth:lineWidth];
- [path setLineCapStyle:NSRoundLineCapStyle];
- [path moveToPoint:NSMakePoint(0,lineStart)];
- [path lineToPoint:NSMakePoint(0,lineEnd)];
-
- for (int i=0; i<_numFins; i++) {
- if(_isAnimating) {
- [_finColors[i] set];
- }
- else {
- [[_foreColor colorWithAlphaComponent:kAlphaWhenStopped] set];
- }
-
- [path stroke];
-
- // we draw all the fins by rotating the CTM, then just redraw the same segment again
- CGContextRotateCTM(currentContext, 6.282185/_numFins);
- }
- [path release];
- }
- else {
- CGFloat lineWidth = 1 + (0.01 * theMaxSize);
- CGFloat circleRadius = (theMaxSize - lineWidth) / 2.1;
- NSPoint circleCenter = NSMakePoint(0, 0);
- [_foreColor set];
- NSBezierPath *path = [[NSBezierPath alloc] init];
- [path setLineWidth:lineWidth];
- [path appendBezierPathWithOvalInRect:NSMakeRect(-circleRadius, -circleRadius, circleRadius*2, circleRadius*2)];
- [path stroke];
- [path release];
- path = [[NSBezierPath alloc] init];
- [path appendBezierPathWithArcWithCenter:circleCenter radius:circleRadius startAngle:90 endAngle:90-(360*(_currentValue/_maxValue)) clockwise:YES];
- [path lineToPoint:circleCenter] ;
- [path fill];
- [path release];
- }
-
- [NSGraphicsContext restoreGraphicsState];
-}
-
-
-#pragma mark NSProgressIndicator API
-
-- (void)startAnimation:(id)sender
-{
- for (int x = 0; x<_numFins; x++) // start off with colors
- [self updateFrame:nil];
-
- if (!_isIndeterminate) return;
- if (_isAnimating && !_isFadingOut) return;
-
- [self actuallyStartAnimation];
-}
-
-- (void)stopAnimation:(id)sender
-{
- // animate to stopped state
- _isFadingOut = YES;
-}
-
-/// Only the spinning style is implemented
-- (void)setStyle:(NSProgressIndicatorStyle)style
-{
- if (NSProgressIndicatorSpinningStyle != style) {
- NSAssert(NO, @"Non-spinning styles not available.");
- }
-}
-
-
-# pragma mark Custom Accessors
-
-- (void)setColor:(NSColor *)value
-{
- if (_foreColor != value) {
- [_foreColor release];
- _foreColor = [value retain];
-
- // generate all the fin colors, with the alpha components
- // they already have
- for (int i=0; i<_numFins; i++) {
- CGFloat alpha = [_finColors[i] alphaComponent];
- [_finColors[i] release];
- _finColors[i] = [[_foreColor colorWithAlphaComponent:alpha] retain];
- }
-
- [self setNeedsDisplay:YES];
- }
-}
-
-- (void)setBackgroundColor:(NSColor *)value
-{
- if (_backColor != value) {
- [_backColor release];
- _backColor = [value retain];
- [self setNeedsDisplay:YES];
- }
-}
-
-- (void)setDrawsBackground:(BOOL)value
-{
- if (_drawsBackground != value) {
- _drawsBackground = value;
- }
- [self setNeedsDisplay:YES];
-}
-
-- (void)setIndeterminate:(BOOL)isIndeterminate
-{
- _isIndeterminate = isIndeterminate;
- if (!_isIndeterminate && _isAnimating) [self stopAnimation:self];
- [self setNeedsDisplay:YES];
-}
-
-- (void)setDoubleValue:(double)doubleValue
-{
- // Automatically put it into determinate mode if it's not already.
- if (_isIndeterminate) {
- [self setIndeterminate:NO];
- }
- _currentValue = doubleValue;
- [self setNeedsDisplay:YES];
-}
-
-- (void)setMaxValue:(double)maxValue
-{
- _maxValue = maxValue;
- [self setNeedsDisplay:YES];
-}
-
-- (void)setUsesThreadedAnimation:(BOOL)useThreaded
-{
- if (_usesThreadedAnimation != useThreaded) {
- _usesThreadedAnimation = useThreaded;
-
- if (_isAnimating) {
- // restart the timer to use the new mode
- [self stopAnimation:self];
- [self startAnimation:self];
- }
- }
-}
-
-- (void)setDisplayedWhenStopped:(BOOL)displayedWhenStopped
-{
- _displayedWhenStopped = displayedWhenStopped;
-
- // Show/hide ourself if necessary
- if (!_isAnimating) {
- if (_displayedWhenStopped && [self isHidden]) {
- [self setHidden:NO];
- }
- else if (!_displayedWhenStopped && ![self isHidden]) {
- [self setHidden:YES];
- }
- }
-}
-
-
-#pragma mark Private
-
-- (void)updateFrame:(NSTimer *)timer
-{
- if(_position > 0) {
- _position--;
- }
- else {
- _position = _numFins - 1;
- }
-
- // update the colors
- CGFloat minAlpha = _displayedWhenStopped ? kAlphaWhenStopped : 0.01;
- for (int i=0; i<_numFins; i++) {
- // want each fin to fade exponentially over _numFins frames of animation
- CGFloat newAlpha = [_finColors[i] alphaComponent] * kFadeMultiplier;
- if (newAlpha < minAlpha)
- newAlpha = minAlpha;
- NSColor *oldColor = _finColors[i];
- _finColors[i] = [[_foreColor colorWithAlphaComponent:newAlpha] retain];
- [oldColor release];
- }
-
- if (_isFadingOut) {
- // check if the fadeout is done
- BOOL done = YES;
- for (int i=0; i<_numFins; i++) {
- if (fabs([_finColors[i] alphaComponent] - minAlpha) > 0.01) {
- done = NO;
- break;
- }
- }
- if (done) {
- [self actuallyStopAnimation];
- }
- }
- else {
- // "light up" the next fin (with full alpha)
- NSColor *oldColor = _finColors[_position];
- _finColors[_position] = [_foreColor retain];
- [oldColor release];
- }
-
- if (_usesThreadedAnimation) {
- // draw now instead of waiting for setNeedsDisplay (that's the whole reason
- // we're animating from background thread)
- [self display];
- }
- else {
- [self setNeedsDisplay:YES];
- }
-}
-
-- (void)actuallyStartAnimation
-{
- // Just to be safe kill any existing timer.
- [self actuallyStopAnimation];
-
- _isAnimating = YES;
- _isFadingOut = NO;
-
- // always start from the top
- _position = 1;
-
- if (!_displayedWhenStopped)
- [self setHidden:NO];
-
- if ([self window]) {
- // Why animate if not visible? viewDidMoveToWindow will re-call this method when needed.
- if (_usesThreadedAnimation) {
- _animationThread = [[NSThread alloc] initWithTarget:self selector:@selector(animateInBackgroundThread) object:nil];
- [_animationThread start];
- }
- else {
- _animationTimer = [[NSTimer timerWithTimeInterval:(NSTimeInterval)0.05
- target:self
- selector:@selector(updateFrame:)
- userInfo:nil
- repeats:YES] retain];
-
- [[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSRunLoopCommonModes];
- [[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSDefaultRunLoopMode];
- [[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSEventTrackingRunLoopMode];
- }
- }
-}
-
-- (void)actuallyStopAnimation
-{
- _isAnimating = NO;
- _isFadingOut = NO;
-
- if (!_displayedWhenStopped)
- [self setHidden:YES];
-
- if (_animationThread) {
- // we were using threaded animation
- [_animationThread cancel];
- if (![_animationThread isFinished]) {
- [[NSRunLoop currentRunLoop] runMode:NSModalPanelRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
- }
- [_animationThread release];
- _animationThread = nil;
- }
- else if (_animationTimer) {
- // we were using timer-based animation
- [_animationTimer invalidate];
- [_animationTimer release];
- _animationTimer = nil;
- }
- [self setNeedsDisplay:YES];
-}
-
-- (void)generateFinColorsStartAtPosition:(int)startPosition
-{
- for (int i=0; i<_numFins; i++) {
- NSColor *oldColor = _finColors[i];
- CGFloat alpha = [oldColor alphaComponent];
- _finColors[i] = [[_foreColor colorWithAlphaComponent:alpha] retain];
- [oldColor release];
- }
-}
-
-- (void)animateInBackgroundThread
-{
- NSAutoreleasePool *animationPool = [[NSAutoreleasePool alloc] init];
-
- // Set up the animation speed to subtly change with size > 32.
- // int animationDelay = 38000 + (2000 * ([self bounds].size.height / 32));
-
- // Set the rev per minute here
- int omega = 100; // RPM
- int animationDelay = 60*1000000/omega/_numFins;
- int poolFlushCounter = 0;
-
- do {
- [self updateFrame:nil];
- usleep(animationDelay);
- poolFlushCounter++;
- if (poolFlushCounter > 256) {
- [animationPool drain];
- animationPool = [[NSAutoreleasePool alloc] init];
- poolFlushCounter = 0;
- }
- } while (![[NSThread currentThread] isCancelled]);
-
- [animationPool release];
-}
-
-@end
View
5 ScrollToRefresh/src/EQSTRScrollView.h
@@ -23,15 +23,14 @@
// THE SOFTWARE.
#import <AppKit/AppKit.h>
-#import "YRKSpinningProgressIndicator.h"
@interface EQSTRScrollView : NSScrollView {
BOOL isRefreshing;
BOOL overHeaderView;
NSView *refreshHeader;
NSView *refreshArrow;
- YRKSpinningProgressIndicator *refreshSpinner;
+ NSProgressIndicator *refreshSpinner;
id target;
SEL selector;
@@ -42,7 +41,7 @@
@property (readonly) BOOL isRefreshing;
@property (readonly) NSView *refreshHeader;
-@property (readonly) YRKSpinningProgressIndicator *refreshSpinner;
+@property (readonly) NSProgressIndicator *refreshSpinner;
@property (readonly) NSView *refreshArrow;
- (void)startLoading;
- (void)stopLoading;
View
21 ScrollToRefresh/src/EQSTRScrollView.m
@@ -80,17 +80,22 @@ - (void)createHeaderView {
refreshArrow.layer.contents=(id)[arrowImage CGImageForProposedRect:NULL
context:nil
hints:nil];
-
- // spinner
- refreshSpinner = [[YRKSpinningProgressIndicator alloc] initWithFrame:NSMakeRect(floor(NSMidX(refreshHeader.bounds)-30),
- floor(NSMidY(refreshHeader.bounds)-20),
- 60.0f,
- 40.0f)];
+
+ refreshSpinner = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(floor(NSMidX(refreshHeader.bounds)-30),
+ floor(NSMidY(refreshHeader.bounds)-20),
+ 60.0f,
+ 40.0f)];
+ refreshSpinner.style=NSProgressIndicatorSpinningStyle;
refreshSpinner.displayedWhenStopped=NO;
refreshSpinner.usesThreadedAnimation=YES;
- refreshSpinner.drawsBackground=NO;
- refreshSpinner.backgroundColor=[NSColor clearColor];
refreshSpinner.indeterminate=YES;
+ refreshSpinner.bezeled=NO;
+ [refreshSpinner sizeToFit];
+
+ [refreshSpinner setFrame:NSMakeRect(floor(NSMidX(refreshHeader.bounds)-refreshSpinner.frame.size.width/2),
+ floor(NSMidY(refreshHeader.bounds)-refreshSpinner.frame.size.height/2),
+ refreshSpinner.frame.size.width,
+ refreshSpinner.frame.size.height)];
// set autoresizing masks
refreshSpinner.autoresizingMask = NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin; // center

0 comments on commit d8dbe51

Please sign in to comment.