Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
//// RProgressIndicator.m// R//// Created by Bibiko on 03.02.12.// Copyright 2012 __MyCompanyName__. All rights reserved.//#import "RProgressIndicator.h"@implementation RProgressIndicator// draw a gradient background behind the fints to// make the spinner visible even for dark background colors- (void)drawRect:(NSRect)dirtyRect{// Get the spinner's background color drawed by its superview's windowNSColor *backGround = [[[self superview] window] backgroundColor];// just in case bail if nothing setif(!backGround) return;// Do nothing for white backgroundif(backGround == [NSColor whiteColor]) return;NSColor *startColor, *endColor;if(_isRunning) {startColor = [NSColor whiteColor];// special case for pure black backroundif(([[backGround colorUsingColorSpaceName:NSCalibratedWhiteColorSpace] whiteComponent] == 0.0))endColor = backGround;elseendColor = [NSColor clearColor];} else {startColor = [NSColor clearColor];endColor = startColor;}NSRect bounds = [self bounds];// create the gradientNSGradient* aGradient = [[[NSGradient alloc] initWithStartingColor:startColorendingColor:endColor] autorelease];// draw a radial gradient inside circleNSBezierPath *circle = [NSBezierPath bezierPathWithOvalInRect:bounds];[aGradient drawInBezierPath:circle relativeCenterPosition:NSMakePoint(0,0)];// draw a pure filled by the background color circle in the middle// of the spinner (looks better)[backGround set];circle = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(bounds, 4.8, 4.8)];[circle fill];}- (void)startAnimation:(id)sender{_isRunning = YES;[super startAnimation:sender];}- (void)stopAnimation:(id)sender{_isRunning = NO;[super stopAnimation:sender];}@end