forked from hallski/glossyclock
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 1bd5ef9
Showing
16 changed files
with
4,994 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,10 @@ | ||
#### `.gitignore` | ||
# xcode noise | ||
build/* | ||
*.mode1v3 | ||
*.pbxuser | ||
|
||
# osx noise | ||
.DS_Store | ||
profile | ||
|
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,17 @@ | ||
// | ||
// ClockTimer.h | ||
// GlossyClock | ||
// | ||
// Created by Mikael Hallendal on 2009-10-10. | ||
// Copyright 2009 Mikael Hallendal. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface ClockTimer : NSObject { | ||
NSString *outputString; | ||
} | ||
@property(copy) NSString *outputString; | ||
|
||
@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,45 @@ | ||
// | ||
// ClockTimer.m | ||
// GlossyClock | ||
// | ||
// Created by Mikael Hallendal on 2009-10-10. | ||
// Copyright 2009 Mikael Hallendal. All rights reserved. | ||
// | ||
|
||
#import "ClockTimer.h" | ||
|
||
|
||
@implementation ClockTimer | ||
|
||
@synthesize outputString; | ||
|
||
- (void) updateOutputString { | ||
NSDateFormatter *format = [[NSDateFormatter alloc] init]; | ||
[format setDateFormat:@"HH:mm:ss"]; | ||
|
||
[self setOutputString:[format stringFromDate:[NSDate date]]]; | ||
|
||
} | ||
|
||
- (id) init | ||
{ | ||
self = [super init]; | ||
if (self != nil) { | ||
[self updateOutputString]; | ||
|
||
[NSTimer scheduledTimerWithTimeInterval:1.0f | ||
target:self | ||
selector:@selector(timerFireMethod:) | ||
userInfo:nil repeats:YES]; | ||
// Start timer to update outputString | ||
} | ||
return self; | ||
} | ||
|
||
- (void)timerFireMethod:(NSTimer *)theTimer | ||
{ | ||
[self updateOutputString]; | ||
|
||
} | ||
|
||
@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,17 @@ | ||
// | ||
// ClockView.h | ||
// GlossyClock | ||
// | ||
// Created by Mikael Hallendal on 2009-10-10. | ||
// Copyright 2009 Mikael Hallendal. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
@class ClockTimer; | ||
|
||
@interface ClockView : NSView { | ||
ClockTimer *clockTimer; | ||
CALayer *backgroundLayer; | ||
} | ||
|
||
@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,108 @@ | ||
// | ||
// ClockView.m | ||
// GlossyClock | ||
// | ||
// Created by Mikael Hallendal on 2009-10-10. | ||
// Copyright 2009 Mikael Hallendal. All rights reserved. | ||
// | ||
|
||
#import "ClockView.h" | ||
#import <Quartz/Quartz.h> | ||
#import "ClockTimer.h" | ||
#import <QuartzCore/CoreAnimation.h> | ||
|
||
@implementation ClockView | ||
|
||
- (id)initWithFrame:(NSRect)frame | ||
{ | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
clockTimer = [[ClockTimer alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)setupBackgroundLayer | ||
{ | ||
backgroundLayer = [CAGradientLayer layer]; | ||
|
||
CGColorRef gradientColor1 = CGColorCreateGenericRGB(13.0f / 255.0, 116.0f / 255.0, 1.0, 1.0f); | ||
CGColorRef gradientColor2 = CGColorCreateGenericRGB(0.0f, 53.0f/255.0f, 126.0f/255.0f, 1.0f); | ||
|
||
NSArray *colors = [NSArray arrayWithObjects:(id)gradientColor1, (id)gradientColor2, nil]; | ||
|
||
CFRelease(gradientColor1); | ||
CFRelease(gradientColor2); | ||
|
||
[(CAGradientLayer *)backgroundLayer setColors:colors]; | ||
[backgroundLayer setCornerRadius:12.0f]; | ||
|
||
CAConstraintLayoutManager *layout = [CAConstraintLayoutManager layoutManager]; | ||
[backgroundLayer setLayoutManager:layout]; | ||
|
||
[self setLayer:backgroundLayer]; | ||
} | ||
|
||
- (void)setupClockFaceLayer { | ||
CATextLayer *clockFaceLayer = [CATextLayer layer]; | ||
[clockFaceLayer bind:@"string" toObject:clockTimer withKeyPath:@"outputString" options:nil]; | ||
[clockFaceLayer setFont:@"Menlo"]; | ||
[clockFaceLayer setFontSize:60.0f]; | ||
[clockFaceLayer setShadowOpacity:.9f]; | ||
|
||
// Constrain the text layer in the middle | ||
CAConstraint *constraint = [CAConstraint constraintWithAttribute:kCAConstraintMidX | ||
relativeTo:@"superlayer" | ||
attribute:kCAConstraintMidX]; | ||
[clockFaceLayer addConstraint:constraint]; | ||
|
||
constraint = [CAConstraint constraintWithAttribute:kCAConstraintMidY | ||
relativeTo:@"superlayer" | ||
attribute:kCAConstraintMidY]; | ||
[clockFaceLayer addConstraint:constraint]; | ||
|
||
[backgroundLayer addSublayer:clockFaceLayer]; | ||
} | ||
|
||
- (void)setupLayers | ||
{ | ||
[self setupBackgroundLayer]; | ||
|
||
[self setupClockFaceLayer]; | ||
|
||
// Draw a glossy reflection | ||
CALayer *glossLayer = [CALayer layer]; | ||
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"clock-gloss" ofType:@"png"]; | ||
NSURL *fileURL = [NSURL fileURLWithPath:filePath]; | ||
|
||
CGImageSourceRef glossySource = CGImageSourceCreateWithURL((CFURLRef)fileURL, NULL); | ||
CGImageRef glossyImage = CGImageSourceCreateImageAtIndex(glossySource, 0, NULL); | ||
CFRelease(glossySource); | ||
[glossLayer setContents:(id)glossyImage]; | ||
CFRelease(glossyImage); | ||
|
||
[glossLayer setOpacity:0.8f]; | ||
[glossLayer setCornerRadius:12.0f]; | ||
[glossLayer setMasksToBounds:YES]; | ||
[glossLayer setFrame:[self frame]]; | ||
|
||
[backgroundLayer addSublayer:glossLayer]; | ||
|
||
CALayer *borderLayer = [CALayer layer]; | ||
CGRect borderRect = CGRectInset([self frame], 8.0f, 8.0f); | ||
[borderLayer setCornerRadius:12.0f]; | ||
[borderLayer setBorderColor:CGColorGetConstantColor(kCGColorWhite)]; | ||
[borderLayer setBorderWidth:2.0f]; | ||
[borderLayer setFrame:borderRect]; | ||
|
||
[backgroundLayer addSublayer:borderLayer]; | ||
} | ||
|
||
- (void)awakeFromNib | ||
{ | ||
[self setupLayers]; | ||
|
||
[self setWantsLayer:YES]; | ||
} | ||
|
||
@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,16 @@ | ||
// | ||
// ClockWindow.h | ||
// GlossyClock | ||
// | ||
// Created by Mikael Hallendal on 2009-10-10. | ||
// Copyright 2009 Mikael Hallendal. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface ClockWindow : NSWindow { | ||
BOOL isVisible; | ||
} | ||
|
||
@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,43 @@ | ||
// | ||
// ClockWindow.m | ||
// GlossyClock | ||
// | ||
// Created by Mikael Hallendal on 2009-10-10. | ||
// Copyright 2009 Mikael Hallendal. All rights reserved. | ||
// | ||
|
||
#import "ClockWindow.h" | ||
|
||
|
||
@implementation ClockWindow | ||
|
||
- (id)initWithContentRect:(NSRect)contentRect | ||
styleMask:(NSUInteger)aStyle | ||
backing:(NSBackingStoreType)bufferingType | ||
defer:(BOOL)flag | ||
{ | ||
self = [super initWithContentRect:contentRect | ||
styleMask:NSBorderlessWindowMask | ||
backing:bufferingType | ||
defer:flag]; | ||
if (self) { | ||
[self setOpaque:NO]; | ||
[self setBackgroundColor:[NSColor clearColor]]; | ||
[self setMovableByWindowBackground:YES]; | ||
[self setLevel:NSPopUpMenuWindowLevel]; | ||
[self setStyleMask:NSBorderlessWindowMask]; | ||
|
||
isVisible = YES; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)setIsVisible:(BOOL)flag | ||
{ | ||
[[self animator] setAlphaValue:flag ? 0.0f : 1.0f]; | ||
|
||
isVisible = flag; | ||
} | ||
|
||
@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,2 @@ | ||
/* Localized versions of Info.plist keys */ | ||
|
Oops, something went wrong.