forked from subdigital/nsscreencast
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
65de0e5
commit d57b564
Showing
11 changed files
with
1,513 additions
and
0 deletions.
There are no files selected for viewing
425 changes: 425 additions & 0 deletions
425
183-screensavers-part-2/Motivation/Motivation.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
97 changes: 97 additions & 0 deletions
97
183-screensavers-part-2/Motivation/Motivation/AgeView.swift
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,97 @@ | ||
// | ||
// AgeView.swift | ||
// Motivation | ||
// | ||
// Created by Sam Soffes on 8/6/15. | ||
// Copyright (c) 2015 Sam Soffes. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import ScreenSaver | ||
|
||
class AgeView: ScreenSaverView { | ||
|
||
// MARK: - Properties | ||
|
||
let textLabel: NSTextField = { | ||
let label = NSTextField() | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
label.editable = false | ||
label.drawsBackground = false | ||
label.bordered = false | ||
label.bezeled = false | ||
label.selectable = false | ||
label.textColor = .whiteColor() | ||
return label | ||
}() | ||
|
||
lazy var configurationWindowController: NSWindowController = { | ||
return ConfigurationWindowController() | ||
}() | ||
|
||
|
||
// MARK: - Initializers | ||
|
||
convenience init() { | ||
self.init(frame: CGRectZero, isPreview: false) | ||
} | ||
|
||
override init!(frame: NSRect, isPreview: Bool) { | ||
super.init(frame: frame, isPreview: isPreview) | ||
initialize() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
initialize() | ||
} | ||
|
||
|
||
// MARK: - NSView | ||
|
||
override func drawRect(rect: NSRect) { | ||
let backgroundColor: NSColor = .blackColor() | ||
|
||
backgroundColor.setFill() | ||
NSBezierPath.fillRect(bounds) | ||
|
||
if Preferences().birthday != nil { | ||
textLabel.font = .systemFontOfSize(bounds.width / 10) | ||
} else { | ||
textLabel.font = .systemFontOfSize(bounds.width / 30) | ||
} | ||
} | ||
|
||
|
||
// MARK: - ScreenSaverView | ||
|
||
override func animateOneFrame() { | ||
if let birthday = Preferences().birthday { | ||
let age = birthday.timeIntervalSinceNow * -1 / 60 / 60 / 24 / 365 | ||
textLabel.stringValue = String(NSString(format: "%0.9f", age)) | ||
} else { | ||
textLabel.stringValue = "Open Screen Saver Options to set your birthday." | ||
} | ||
} | ||
|
||
override func hasConfigureSheet() -> Bool { | ||
return true | ||
} | ||
|
||
override func configureSheet() -> NSWindow! { | ||
return configurationWindowController.window | ||
} | ||
|
||
|
||
// MARK: - Private | ||
|
||
private func initialize() { | ||
setAnimationTimeInterval(1 / 30) | ||
|
||
addSubview(textLabel) | ||
addConstraints([ | ||
NSLayoutConstraint(item: textLabel, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1, constant: 0), | ||
NSLayoutConstraint(item: textLabel, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0) | ||
]) | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
183-screensavers-part-2/Motivation/Motivation/Configuration.xib
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,75 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/> | ||
</dependencies> | ||
<objects> | ||
<customObject id="-2" userLabel="File's Owner" customClass="ConfigurationWindowController" customModule="Motivation" customModuleProvider="target"> | ||
<connections> | ||
<outlet property="window" destination="QvC-M9-y7g" id="yFe-qJ-2Tx"/> | ||
</connections> | ||
</customObject> | ||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> | ||
<customObject id="-3" userLabel="Application" customClass="NSObject"/> | ||
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="QvC-M9-y7g"> | ||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> | ||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> | ||
<rect key="contentRect" x="196" y="240" width="236" height="93"/> | ||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/> | ||
<view key="contentView" id="EiT-Mj-1SZ"> | ||
<rect key="frame" x="0.0" y="-5" width="236" height="93"/> | ||
<autoresizingMask key="autoresizingMask"/> | ||
<subviews> | ||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="cf0-hz-k84"> | ||
<rect key="frame" x="18" y="56" width="91" height="17"/> | ||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Your Birthday:" id="niJ-ql-s5d"> | ||
<font key="font" metaFont="system"/> | ||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> | ||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> | ||
</textFieldCell> | ||
</textField> | ||
<datePicker verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="24i-HD-fhj"> | ||
<rect key="frame" x="115" y="53" width="104" height="27"/> | ||
<datePickerCell key="cell" borderStyle="bezel" alignment="left" id="6zn-zD-imf"> | ||
<font key="font" metaFont="system"/> | ||
<calendarDate key="date" timeIntervalSinceReferenceDate="-595929600" calendarFormat="%Y-%m-%d %H:%M:%S %z"> | ||
<!--1982-02-12 16:00:00 +0000--> | ||
<timeZone key="timeZone" name="US/Pacific"/> | ||
</calendarDate> | ||
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/> | ||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> | ||
</datePickerCell> | ||
<connections> | ||
<binding destination="zet-Ww-APq" name="value" keyPath="self.birthday" id="EQq-LN-QTl"/> | ||
</connections> | ||
</datePicker> | ||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="nsQ-3M-79j"> | ||
<rect key="frame" x="162" y="13" width="60" height="32"/> | ||
<buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="JAB-GH-sNP"> | ||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> | ||
<font key="font" metaFont="system"/> | ||
<string key="keyEquivalent" base64-UTF8="YES"> | ||
DQ | ||
</string> | ||
</buttonCell> | ||
<connections> | ||
<action selector="close:" target="-2" id="6l5-z1-3YJ"/> | ||
</connections> | ||
</button> | ||
</subviews> | ||
<constraints> | ||
<constraint firstItem="nsQ-3M-79j" firstAttribute="top" secondItem="24i-HD-fhj" secondAttribute="bottom" constant="12" id="FwY-Fh-rMa"/> | ||
<constraint firstItem="cf0-hz-k84" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" constant="20" id="Lc1-MC-Y4L"/> | ||
<constraint firstAttribute="bottom" secondItem="nsQ-3M-79j" secondAttribute="bottom" constant="20" id="Lxr-Yx-Nkn"/> | ||
<constraint firstAttribute="trailing" secondItem="24i-HD-fhj" secondAttribute="trailing" constant="20" id="Rgy-r3-dU4"/> | ||
<constraint firstItem="cf0-hz-k84" firstAttribute="centerY" secondItem="24i-HD-fhj" secondAttribute="centerY" id="UWK-Al-Pj5"/> | ||
<constraint firstAttribute="trailing" secondItem="nsQ-3M-79j" secondAttribute="trailing" constant="20" id="Zr4-bI-6AB"/> | ||
<constraint firstItem="cf0-hz-k84" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" constant="20" id="cwf-UN-ISQ"/> | ||
<constraint firstItem="24i-HD-fhj" firstAttribute="leading" secondItem="cf0-hz-k84" secondAttribute="trailing" constant="8" id="fa9-Zm-ohY"/> | ||
</constraints> | ||
</view> | ||
<point key="canvasLocation" x="425" y="264.5"/> | ||
</window> | ||
<customObject id="zet-Ww-APq" customClass="Preferences" customModule="Motivation" customModuleProvider="target"/> | ||
</objects> | ||
</document> |
27 changes: 27 additions & 0 deletions
27
183-screensavers-part-2/Motivation/Motivation/ConfigurationWindowController.swift
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,27 @@ | ||
// | ||
// ConfigurationWindowController.swift | ||
// Motivation | ||
// | ||
// Created by Sam Soffes on 8/6/15. | ||
// Copyright (c) 2015 Sam Soffes. All rights reserved. | ||
// | ||
|
||
import AppKit | ||
|
||
class ConfigurationWindowController: NSWindowController { | ||
|
||
// MARK: - Properties | ||
|
||
override var windowNibName: String { | ||
return "Configuration" | ||
} | ||
|
||
|
||
// MARK: - Action | ||
|
||
@IBAction func close(sender: AnyObject?) { | ||
if let window = window { | ||
window.sheetParent?.endSheet(window) | ||
} | ||
} | ||
} |
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,28 @@ | ||
<?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>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.samsoffes.motiviation</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>0.1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright © 2015 Sam Soffes. All rights reserved.</string> | ||
<key>NSPrincipalClass</key> | ||
<string>Motivation.AgeView</string> | ||
</dict> | ||
</plist> |
38 changes: 38 additions & 0 deletions
38
183-screensavers-part-2/Motivation/Motivation/Preferences.swift
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,38 @@ | ||
// | ||
// Preferences.swift | ||
// Motivation | ||
// | ||
// Created by Sam Soffes on 8/6/15. | ||
// Copyright (c) 2015 Sam Soffes. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import ScreenSaver | ||
|
||
class Preferences: NSObject { | ||
|
||
// MARK: - Properties | ||
|
||
var birthday: NSDate? { | ||
get { | ||
let timestamp = defaults?.objectForKey("Birthday") as? NSTimeInterval | ||
return timestamp.map { NSDate(timeIntervalSince1970: $0) } | ||
} | ||
|
||
set { | ||
if let date = newValue { | ||
defaults?.setObject(date.timeIntervalSince1970, forKey: "Birthday") | ||
} else { | ||
defaults?.removeObjectForKey("Birthday") | ||
} | ||
defaults?.synchronize() | ||
} | ||
} | ||
|
||
private let defaults: ScreenSaverDefaults? = { | ||
if let bundleIdentifier = NSBundle(forClass: Preferences.self).bundleIdentifier { | ||
return ScreenSaverDefaults.defaultsForModuleWithName(bundleIdentifier) as? ScreenSaverDefaults | ||
} | ||
return nil | ||
}() | ||
} |
26 changes: 26 additions & 0 deletions
26
183-screensavers-part-2/Motivation/Preview/AppDelegate.swift
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 @@ | ||
// | ||
// AppDelegate.swift | ||
// Preview | ||
// | ||
// Created by Sam Soffes on 8/6/15. | ||
// Copyright (c) 2015 Sam Soffes. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
@NSApplicationMain | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
|
||
|
||
|
||
func applicationDidFinishLaunching(aNotification: NSNotification) { | ||
// Insert code here to initialize your application | ||
} | ||
|
||
func applicationWillTerminate(aNotification: NSNotification) { | ||
// Insert code here to tear down your application | ||
} | ||
|
||
|
||
} | ||
|
Oops, something went wrong.