Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dbe21e8
Showing
16 changed files
with
2,405 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// CATAppController.h | ||
// SPILDemo | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@class SPILDTopLayerView; | ||
@class SpinningProgressIndicatorLayer; | ||
|
||
|
||
@interface SPILDAppController : NSObject { | ||
IBOutlet NSWindow *_window; | ||
IBOutlet SPILDTopLayerView *_mainView; | ||
|
||
IBOutlet NSButton *_startStopButton; | ||
IBOutlet NSColorWell *_fgColorWell; | ||
IBOutlet NSColorWell *_bgColorWell; | ||
} | ||
|
||
// IB Actions | ||
- (IBAction)pickNewForeColor:(id)sender; | ||
- (IBAction)pickNewBackColor:(id)sender; | ||
- (IBAction)startStopProgressIndicator:(id)sender; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// CATAppController.m | ||
// SPILDemo | ||
// | ||
|
||
#import "SPILDAppController.h" | ||
|
||
#import "SPILDTopLayerView.h" | ||
#import "YRKSpinningProgressIndicatorLayer.h" | ||
|
||
@implementation SPILDAppController | ||
|
||
//------------------------------------------------------------------------------ | ||
#pragma mark - | ||
#pragma mark Init, Dealloc, etc | ||
//------------------------------------------------------------------------------ | ||
|
||
- (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]; | ||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
#pragma mark - | ||
#pragma mark IB Actions | ||
//------------------------------------------------------------------------------ | ||
|
||
- (IBAction)pickNewForeColor:(id)sender { | ||
[_mainView progressIndicatorLayer].foreColor = [sender color]; | ||
} | ||
|
||
- (IBAction)pickNewBackColor:(id)sender { | ||
[_mainView setPlainBackgroundColor:[sender color]]; | ||
} | ||
|
||
- (IBAction)startStopProgressIndicator:(id)sender { | ||
if ([[_mainView progressIndicatorLayer] isRunning]) { | ||
// it is running, so stop it | ||
[[_mainView progressIndicatorLayer] stopProgressAnimation]; | ||
[_startStopButton setTitle:@"Start"]; | ||
} | ||
else { | ||
// it is stopped, so start it | ||
[[_mainView progressIndicatorLayer] startProgressAnimation]; | ||
[_startStopButton setTitle:@"Stop"]; | ||
} | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// SPILDTopLayerView.h | ||
// SPILDemo | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import <QuartzCore/CoreAnimation.h> | ||
#import <Quartz/Quartz.h> | ||
|
||
@class YRKSpinningProgressIndicatorLayer; | ||
|
||
|
||
// the MenuView class is the view subclass that is inserted into | ||
// the window. It hosts the rootLayer, and responds to events | ||
@interface SPILDTopLayerView : NSView { | ||
CALayer *_rootLayer; | ||
CALayer *_plainBackgroundLayer; | ||
CALayer *_qcBackgroundLayer; | ||
YRKSpinningProgressIndicatorLayer *_progressIndicatorLayer; | ||
} | ||
|
||
// IB Actions | ||
- (IBAction)toggleBackground:(id)sender; | ||
- (void)setPlainBackgroundColor:(NSColor *)newColor; | ||
|
||
// Properties | ||
@property (readonly) CALayer *rootLayer; | ||
@property (readonly) YRKSpinningProgressIndicatorLayer *progressIndicatorLayer; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// | ||
// SPILDTopLayerView.m | ||
// SPILDemo | ||
// | ||
|
||
#import "SPILDTopLayerView.h" | ||
|
||
#import "YRKSpinningProgressIndicatorLayer.h" | ||
|
||
|
||
@interface SPILDTopLayerView () | ||
|
||
- (void)setupLayers; | ||
|
||
- (void)usePlainBackground; | ||
- (void)useQCBackground; | ||
|
||
@end | ||
|
||
|
||
@implementation SPILDTopLayerView | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
#pragma mark - | ||
#pragma mark Init, Dealloc, etc | ||
//------------------------------------------------------------------------------ | ||
|
||
- (void)dealloc { | ||
[_rootLayer removeFromSuperlayer]; | ||
[_rootLayer release]; | ||
|
||
[_progressIndicatorLayer removeFromSuperlayer]; | ||
[_plainBackgroundLayer removeFromSuperlayer]; | ||
[_qcBackgroundLayer removeFromSuperlayer]; | ||
|
||
[super dealloc]; | ||
} | ||
|
||
- (void)awakeFromNib { | ||
[self setupLayers]; | ||
} | ||
|
||
|
||
- (void)setupLayers { | ||
_rootLayer = [CALayer layer]; | ||
[self setLayer:_rootLayer]; | ||
[self setWantsLayer:YES]; | ||
|
||
// Create the plain background layer | ||
_plainBackgroundLayer = [CALayer layer]; | ||
_plainBackgroundLayer.name = @"plainBackgroundLayer"; | ||
_plainBackgroundLayer.anchorPoint = CGPointMake(0.0, 0.0); | ||
_plainBackgroundLayer.position = CGPointMake(0, 0); | ||
_plainBackgroundLayer.bounds = [[self layer] bounds]; | ||
_plainBackgroundLayer.autoresizingMask = (kCALayerWidthSizable|kCALayerHeightSizable); | ||
_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]; | ||
_progressIndicatorLayer.name = @"progressIndicatorLayer"; | ||
_progressIndicatorLayer.anchorPoint = CGPointMake(0.0, 0.0); | ||
_progressIndicatorLayer.position = CGPointMake(0, 0); | ||
_progressIndicatorLayer.bounds = [[self layer] bounds]; | ||
_progressIndicatorLayer.autoresizingMask = (kCALayerWidthSizable|kCALayerHeightSizable); | ||
_progressIndicatorLayer.zPosition = 10; // make sure it goes in front of the background layer | ||
_progressIndicatorLayer.hidden = YES; | ||
[_rootLayer addSublayer:_progressIndicatorLayer]; | ||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
#pragma mark - | ||
#pragma mark Toggling Background | ||
//------------------------------------------------------------------------------ | ||
|
||
- (IBAction)toggleBackground:(id)sender { | ||
if (nil == _qcBackgroundLayer) { | ||
[self useQCBackground]; | ||
} | ||
else { | ||
[self 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 { | ||
// Create the QC background layer | ||
_qcBackgroundLayer = [QCCompositionLayer compositionLayerWithFile: | ||
[[NSBundle mainBundle] pathForResource:@"Background" ofType:@"qtz"]]; | ||
_qcBackgroundLayer.name = @"qcBackgroundLayer"; | ||
_qcBackgroundLayer.anchorPoint = CGPointMake(0.0, 0.0); | ||
_qcBackgroundLayer.position = CGPointMake(0, 0); | ||
_qcBackgroundLayer.bounds = [[self layer] bounds]; | ||
_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]; | ||
_qcBackgroundLayer.hidden = NO; | ||
_plainBackgroundLayer.hidden = YES; | ||
[CATransaction commit]; | ||
} | ||
|
||
- (void)setPlainBackgroundColor:(NSColor *)newColor { | ||
[CATransaction begin]; | ||
[CATransaction setValue:[NSNumber numberWithBool:YES] forKey:kCATransactionDisableActions]; | ||
_plainBackgroundLayer.backgroundColor = CGColorCreateFromNSColor(newColor); | ||
[CATransaction commit]; | ||
} | ||
|
||
|
||
//------------------------------------------------------------------------------ | ||
#pragma mark - | ||
#pragma mark Properties | ||
//------------------------------------------------------------------------------ | ||
@synthesize rootLayer = _rootLayer; | ||
@synthesize progressIndicatorLayer = _progressIndicatorLayer; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// YRKSpinningProgressIndicatorLayer.h | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import <QuartzCore/QuartzCore.h> | ||
|
||
|
||
@interface YRKSpinningProgressIndicatorLayer : CALayer { | ||
BOOL _isRunning; | ||
NSTimer *_animationTimer; | ||
NSUInteger _position; | ||
|
||
CGColorRef _foreColor; | ||
CGFloat _fadeDownOpacity; | ||
|
||
NSUInteger _numFins; | ||
NSMutableArray *_finLayers; | ||
} | ||
|
||
- (void)toggleProgressAnimation; | ||
- (void)startProgressAnimation; | ||
- (void)stopProgressAnimation; | ||
|
||
// Properties and Accessors | ||
@property (readonly) BOOL isRunning; | ||
@property (readwrite, copy) NSColor *foreColor; // "copy" because we don't retain it -- we create a CGColor from it | ||
|
||
@end | ||
|
||
// Helper Functions | ||
CGColorRef CGColorCreateFromNSColor(NSColor *nscolor); | ||
NSColor *NSColorFromCGColorRef(CGColorRef cgcolor); |
Oops, something went wrong.