Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hallski committed Oct 11, 2009
0 parents commit 1bd5ef9
Show file tree
Hide file tree
Showing 16 changed files with 4,994 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
@@ -0,0 +1,10 @@
#### `.gitignore`
# xcode noise
build/*
*.mode1v3
*.pbxuser

# osx noise
.DS_Store
profile

17 changes: 17 additions & 0 deletions ClockTimer.h
@@ -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
45 changes: 45 additions & 0 deletions ClockTimer.m
@@ -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
17 changes: 17 additions & 0 deletions ClockView.h
@@ -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
108 changes: 108 additions & 0 deletions ClockView.m
@@ -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
16 changes: 16 additions & 0 deletions ClockWindow.h
@@ -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
43 changes: 43 additions & 0 deletions ClockWindow.m
@@ -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
2 changes: 2 additions & 0 deletions English.lproj/InfoPlist.strings
@@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */

0 comments on commit 1bd5ef9

Please sign in to comment.