Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Mar 8, 2014
0 parents commit 4759c15
Show file tree
Hide file tree
Showing 18 changed files with 1,535 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.mode1v3
*.pbxuser
*.perspectivev3
*.xcworkspace
xcuserdata
477 changes: 477 additions & 0 deletions Clock.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions Clock/Clock-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.samsoffes.clock</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2014 Sam Soffes. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string>ClockView</string>
</dict>
</plist>
9 changes: 9 additions & 0 deletions Clock/Clock-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
12 changes: 12 additions & 0 deletions Clock/ClockView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// ClockView.h
// Clock
//
// Created by Sam Soffes on 3/8/14.
// Copyright (c) 2014 Sam Soffes. All rights reserved.
//

#import <ScreenSaver/ScreenSaver.h>

@interface ClockView : ScreenSaverView
@end
100 changes: 100 additions & 0 deletions Clock/ClockView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// ClockView.m
// Clock
//
// Created by Sam Soffes on 3/8/14.
// Copyright (c) 2014 Sam Soffes. All rights reserved.
//

#import "ClockView.h"

@implementation ClockView

- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview {
if ((self = [super initWithFrame:frame isPreview:isPreview])) {
[self setAnimationTimeInterval:1.0 / 30.0];
}
return self;
}


- (void)startAnimation {
[super startAnimation];
}


- (void)stopAnimation {
[super stopAnimation];
}


- (void)drawRect:(NSRect)rect {
[super drawRect:rect];

CGSize size = rect.size;

[[NSColor blackColor] setFill];
[NSBezierPath fillRect:rect];

// NSDate *date = [NSDate date];

[[NSColor colorWithCalibratedWhite:1.0f alpha:0.2f] setStroke];

CGFloat clockSize = MIN(size.width, size.height) * 0.5;
CGRect frame = CGRectMake(roundf((size.width - clockSize) / 2.0f), roundf((size.height - clockSize) / 2.0f), clockSize, clockSize);
NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect:frame];
path.lineWidth = 4.0f;
[path stroke];

CGPoint center = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame));
NSDateComponents *comps = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];

// Seconds
[[NSColor whiteColor] setStroke];
path = [NSBezierPath bezierPath];
[path moveToPoint:center];
CGFloat angle = -(M_PI * 2.0f * (CGFloat)comps.second / 60.0f) + M_PI_2;
CGFloat l = clockSize * 0.5f;
CGPoint point = CGPointMake(center.x + cosf(angle) * l, center.y + sinf(angle) * l);
[path lineToPoint:point];
path.lineWidth = 1.0f;
[path stroke];

// Minutes
[[NSColor colorWithCalibratedWhite:1.0f alpha:0.7f] setStroke];
path = [NSBezierPath bezierPath];
[path moveToPoint:center];
angle = -(M_PI * 2.0f * (CGFloat)comps.minute / 60.0f) + M_PI_2;
l = clockSize * 0.45f;
point = CGPointMake(center.x + cosf(angle) * l, center.y + sinf(angle) * l);
[path lineToPoint:point];
path.lineWidth = 3.0f;
[path stroke];

// Hours
// [[NSColor colorWithCalibratedWhite:1.0f alpha:0.2f] setStroke];
path = [NSBezierPath bezierPath];
[path moveToPoint:center];
angle = -(M_PI * 2.0f * ((CGFloat)comps.hour + ((CGFloat)comps.minute / 60.0f)) / 12.0f) + M_PI_2;
l = clockSize * 0.4f;
point = CGPointMake(center.x + cosf(angle) * l, center.y + sinf(angle) * l);
[path lineToPoint:point];
path.lineWidth = 5.0f;
[path stroke];
}


- (void)animateOneFrame {
[self setNeedsDisplay:YES];
}


- (BOOL)hasConfigureSheet {
return NO;
}

- (NSWindow *)configureSheet {
return nil;
}

@end
2 changes: 2 additions & 0 deletions Clock/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */

16 changes: 16 additions & 0 deletions ClockTest/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// AppDelegate.h
// ClockTest
//
// Created by Sam Soffes on 3/8/14.
// Copyright (c) 2014 Sam Soffes. All rights reserved.
//

@class ClockView;

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;
@property IBOutlet ClockView *clockView;

@end
19 changes: 19 additions & 0 deletions ClockTest/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// AppDelegate.m
// ClockTest
//
// Created by Sam Soffes on 3/8/14.
// Copyright (c) 2014 Sam Soffes. All rights reserved.
//

#import "AppDelegate.h"
#import "ClockView.h"

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[self.clockView startAnimation];
[NSTimer scheduledTimerWithTimeInterval:[self.clockView animationTimeInterval] target:self.clockView selector:@selector(animateOneFrame) userInfo:nil repeats:YES];
}

@end
Loading

0 comments on commit 4759c15

Please sign in to comment.