Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

formatting and whitespace fixes

  • Loading branch information...
commit 7998a42eade57a80259b16808b7745815920d317 1 parent 8d18203
@kelan authored
View
2  Code/SPILDAppController.h
@@ -14,7 +14,7 @@
@interface SPILDAppController : NSObject {
IBOutlet NSWindow *_window;
IBOutlet SPILDTopLayerView *_mainView;
-
+
IBOutlet NSButton *_startStopButton;
IBOutlet NSColorWell *_fgColorWell;
IBOutlet NSColorWell *_bgColorWell;
View
14 Code/SPILDAppController.m
@@ -17,12 +17,13 @@ @implementation SPILDAppController
#pragma mark Init, Dealloc, etc
//------------------------------------------------------------------------------
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
+{
// start with a nice green
NSColor *niceGreenColor = [NSColor colorWithCalibratedRed:0.40f green:0.69f blue:0.45f alpha:1.0f];
_fgColorWell.color = niceGreenColor;
[self pickNewForeColor:_fgColorWell];
-
+
_bgColorWell.color = [NSColor blueColor];
[self pickNewBackColor:_bgColorWell];
}
@@ -33,15 +34,18 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
#pragma mark IB Actions
//------------------------------------------------------------------------------
-- (IBAction)pickNewForeColor:(id)sender {
+- (IBAction)pickNewForeColor:(id)sender
+{
[_mainView progressIndicatorLayer].foreColor = [sender color];
}
-- (IBAction)pickNewBackColor:(id)sender {
+- (IBAction)pickNewBackColor:(id)sender
+{
[_mainView setPlainBackgroundColor:[sender color]];
}
-- (IBAction)startStopProgressIndicator:(id)sender {
+- (IBAction)startStopProgressIndicator:(id)sender
+{
if ([[_mainView progressIndicatorLayer] isRunning]) {
// it is running, so stop it
[[_mainView progressIndicatorLayer] stopProgressAnimation];
View
41 Code/SPILDTopLayerView.m
@@ -28,27 +28,30 @@ @implementation SPILDTopLayerView
#pragma mark Init, Dealloc, etc
//------------------------------------------------------------------------------
-- (void)dealloc {
+- (void)dealloc
+{
[_rootLayer removeFromSuperlayer];
[_rootLayer release];
-
+
[_progressIndicatorLayer removeFromSuperlayer];
- [_plainBackgroundLayer removeFromSuperlayer];
+ [_plainBackgroundLayer removeFromSuperlayer];
[_qcBackgroundLayer removeFromSuperlayer];
-
+
[super dealloc];
}
-- (void)awakeFromNib {
+- (void)awakeFromNib
+{
[self setupLayers];
}
-- (void)setupLayers {
+- (void)setupLayers
+{
_rootLayer = [CALayer layer];
[self setLayer:_rootLayer];
[self setWantsLayer:YES];
-
+
// Create the plain background layer
_plainBackgroundLayer = [CALayer layer];
_plainBackgroundLayer.name = @"plainBackgroundLayer";
@@ -59,12 +62,12 @@ - (void)setupLayers {
_plainBackgroundLayer.zPosition = 0;
_plainBackgroundLayer.backgroundColor = CGColorCreateFromNSColor([NSColor blueColor]);
[_rootLayer addSublayer:_plainBackgroundLayer];
-
+
// Start with QC background
[self useQCBackground];
-
- // Put a YRKSpinningProgressIndicatorLayer in front of everything
- _progressIndicatorLayer = [[YRKSpinningProgressIndicatorLayer alloc] init];
+
+ // Put a SpinningProgressIndicatorLayer in front of everything
+ _progressIndicatorLayer = [[SpinningProgressIndicatorLayer alloc] init];
_progressIndicatorLayer.name = @"progressIndicatorLayer";
_progressIndicatorLayer.anchorPoint = CGPointMake(0.0, 0.0);
_progressIndicatorLayer.position = CGPointMake(0, 0);
@@ -81,7 +84,8 @@ - (void)setupLayers {
#pragma mark Toggling Background
//------------------------------------------------------------------------------
-- (IBAction)toggleBackground:(id)sender {
+- (IBAction)toggleBackground:(id)sender
+{
if (nil == _qcBackgroundLayer) {
[self useQCBackground];
}
@@ -90,20 +94,22 @@ - (IBAction)toggleBackground:(id)sender {
}
}
-- (void)usePlainBackground {
+- (void)usePlainBackground
+{
// Hide the QC background and show the plain one
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions];
_qcBackgroundLayer.hidden = YES;
_plainBackgroundLayer.hidden = NO;
[CATransaction commit];
-
+
// destroy the QC background completely, so we can test the CPU usage of just the progress indicator itself
[_qcBackgroundLayer removeFromSuperlayer];
_qcBackgroundLayer = nil;
}
-- (void)useQCBackground {
+- (void)useQCBackground
+{
// Create the QC background layer
_qcBackgroundLayer = [QCCompositionLayer compositionLayerWithFile:
[[NSBundle mainBundle] pathForResource:@"Background" ofType:@"qtz"]];
@@ -114,7 +120,7 @@ - (void)useQCBackground {
_qcBackgroundLayer.autoresizingMask = (kCALayerWidthSizable|kCALayerHeightSizable);
_qcBackgroundLayer.zPosition = 0;
[_rootLayer addSublayer:_qcBackgroundLayer];
-
+
// Hide the plain background and show the QC one
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions];
@@ -123,7 +129,8 @@ - (void)useQCBackground {
[CATransaction commit];
}
-- (void)setPlainBackgroundColor:(NSColor *)newColor {
+- (void)setPlainBackgroundColor:(NSColor *)newColor
+{
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions];
_plainBackgroundLayer.backgroundColor = CGColorCreateFromNSColor(newColor);
View
4 Code/YRKSpinningProgressIndicatorLayer.h
@@ -13,10 +13,10 @@
BOOL _isRunning;
NSTimer *_animationTimer;
NSUInteger _position;
-
+
CGColorRef _foreColor;
CGFloat _fadeDownOpacity;
-
+
NSUInteger _numFins;
NSMutableArray *_finLayers;
}
View
81 Code/YRKSpinningProgressIndicatorLayer.m
@@ -33,7 +33,8 @@ @implementation YRKSpinningProgressIndicatorLayer
#pragma mark Init, Dealloc, etc
//------------------------------------------------------------------------------
-- (id)init {
+- (id)init
+{
self = [super init];
if (self) {
_position = 0;
@@ -47,10 +48,11 @@ - (id)init {
return self;
}
-- (void)dealloc {
+- (void)dealloc
+{
self.foreColor = nil;
[self removeFinLayers];
-
+
[super dealloc];
}
@@ -60,15 +62,16 @@ - (void)dealloc {
#pragma mark Overrides
//------------------------------------------------------------------------------
-- (void)setBounds:(CGRect)newBounds {
+- (void)setBounds:(CGRect)newBounds
+{
[super setBounds:newBounds];
-
+
// Resize the fins
CGRect finBounds = [self finBoundsForCurrentBounds];
CGPoint finAnchorPoint = [self finAnchorPointForCurrentBounds];
CGPoint finPosition = CGPointMake([self bounds].size.width/2, [self bounds].size.height/2);
CGFloat finCornerRadius = finBounds.size.width/2;
-
+
// do the resizing all at once, immediately
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions];
@@ -87,23 +90,24 @@ - (void)setBounds:(CGRect)newBounds {
#pragma mark Animation
//------------------------------------------------------------------------------
-- (void)advancePosition {
+- (void)advancePosition
+{
_position++;
if (_position >= _numFins) {
_position = 0;
}
-
+
CALayer *fin = (CALayer *)[_finLayers objectAtIndex:_position];
-
+
// Set the next fin to full opacity, but do it immediately, without any animation
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions];
fin.opacity = 1.0;
[CATransaction commit];
-
+
// Tell that fin to animate its opacity to transparent.
fin.opacity = _fadeDownOpacity;
-
+
[self setNeedsDisplay];
}
@@ -132,18 +136,20 @@ - (void)disposeAnimTimer
_animationTimer = nil;
}
-- (void)startProgressAnimation {
+- (void)startProgressAnimation
+{
self.hidden = NO;
_isRunning = YES;
-
+
[self setupAnimTimer];
}
-- (void)stopProgressAnimation {
+- (void)stopProgressAnimation
+{
_isRunning = NO;
[self disposeAnimTimer];
-
+
[self setNeedsDisplay];
}
@@ -156,11 +162,13 @@ - (void)stopProgressAnimation {
@synthesize isRunning = _isRunning;
// Can't use @synthesize because we need to convert NSColor <-> CGColor
-- (NSColor *)foreColor {
+- (NSColor *)foreColor
+{
// Need to convert from CGColor to NSColor
return NSColorFromCGColorRef(_foreColor);
}
-- (void)setForeColor:(NSColor *)newColor {
+- (void)setForeColor:(NSColor *)newColor
+{
// Need to convert from NSColor to CGColor
CGColorRef cgColor = CGColorCreateFromNSColor(newColor);
@@ -178,7 +186,8 @@ - (void)setForeColor:(NSColor *)newColor {
[CATransaction commit];
}
-- (void)toggleProgressAnimation {
+- (void)toggleProgressAnimation
+{
if (_isRunning) {
[self stopProgressAnimation];
}
@@ -193,34 +202,35 @@ - (void)toggleProgressAnimation {
#pragma mark Helper Methods
//------------------------------------------------------------------------------
-- (void)createFinLayers {
+- (void)createFinLayers
+{
[self removeFinLayers];
-
+
// Create new fin layers
_finLayers = [[NSMutableArray alloc] initWithCapacity:_numFins];
-
+
CGRect finBounds = [self finBoundsForCurrentBounds];
CGPoint finAnchorPoint = [self finAnchorPointForCurrentBounds];
CGPoint finPosition = CGPointMake([self bounds].size.width/2, [self bounds].size.height/2);
CGFloat finCornerRadius = finBounds.size.width/2;
-
+
int i;
for (i=0; i<_numFins; i++) {
CALayer *newFin = [CALayer layer];
-
+
newFin.bounds = finBounds;
newFin.anchorPoint = finAnchorPoint;
newFin.position = finPosition;
newFin.transform = CATransform3DMakeRotation(i*(-6.282185/_numFins), 0.0, 0.0, 1.0);
newFin.cornerRadius = finCornerRadius;
newFin.backgroundColor = _foreColor;
-
+
// Set the fin's initial opacity
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions];
newFin.opacity = _fadeDownOpacity;
[CATransaction commit];
-
+
// set the fin's fade-out time (for when it's animating)
CABasicAnimation *anim = [CABasicAnimation animation];
anim.duration = 0.7f;
@@ -228,20 +238,22 @@ - (void)createFinLayers {
anim, @"opacity",
nil];
[newFin setActions:actions];
-
+
[self addSublayer: newFin];
[_finLayers addObject:newFin];
}
}
-- (void)removeFinLayers {
+- (void)removeFinLayers
+{
for (CALayer *finLayer in _finLayers) {
[finLayer removeFromSuperlayer];
}
[_finLayers release];
}
-- (CGRect)finBoundsForCurrentBounds {
+- (CGRect)finBoundsForCurrentBounds
+{
CGSize size = [self bounds].size;
CGFloat minSide = size.width > size.height ? size.height : size.width;
CGFloat width = minSide * 0.095f;
@@ -249,7 +261,8 @@ - (CGRect)finBoundsForCurrentBounds {
return CGRectMake(0,0,width,height);
}
-- (CGPoint)finAnchorPointForCurrentBounds {
+- (CGPoint)finAnchorPointForCurrentBounds
+{
CGSize size = [self bounds].size;
CGFloat minSide = size.width > size.height ? size.height : size.width;
CGFloat height = minSide * 0.30f;
@@ -264,20 +277,22 @@ - (CGPoint)finAnchorPointForCurrentBounds {
#pragma mark Helper Functions
//------------------------------------------------------------------------------
-CGColorRef CGColorCreateFromNSColor(NSColor *nscolor) {
+CGColorRef CGColorCreateFromNSColor(NSColor *nscolor)
+{
float components[4];
NSColor *deviceColor = [nscolor colorUsingColorSpaceName: NSDeviceRGBColorSpace];
[deviceColor getRed: &components[0] green: &components[1] blue: &components[2] alpha: &components[3]];
-
+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef cgcolor = CGColorCreate(colorSpace, components);
CGColorSpaceRelease(colorSpace);
-
+
return cgcolor;
}
-NSColor *NSColorFromCGColorRef(CGColorRef cgcolor) {
+NSColor *NSColorFromCGColorRef(CGColorRef cgcolor)
+{
NSColorSpace *colorSpace = [NSColorSpace deviceRGBColorSpace];
return [NSColor colorWithColorSpace:colorSpace
components:CGColorGetComponents(cgcolor)
Please sign in to comment.
Something went wrong with that request. Please try again.