Skip to content

Commit

Permalink
added more font options
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamik423 committed Feb 10, 2022
1 parent 7857bdf commit 794cbca
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 93 deletions.
4 changes: 2 additions & 2 deletions Padbury Clock Revived.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
MARKETING_VERSION = 1.0.2;
MARKETING_VERSION = 1.1.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.hans.Padbury-Clock-Revived";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -308,7 +308,7 @@
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
MARKETING_VERSION = 1.0.2;
MARKETING_VERSION = 1.1.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.hans.Padbury-Clock-Revived";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Binary file not shown.
30 changes: 11 additions & 19 deletions Padbury Clock Revived/ClockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,23 @@ final class ClockView: ScreenSaverView {
dateFormatter.amSymbol = "AM"
dateFormatter.pmSymbol = "PM"

fontSize = 0.2 * bounds.width
let fontSizeScaleFactor : CGFloat
switch preferences.font {
case .sanFrancisco, .helveticaNeue:
fontSizeScaleFactor = 0.20
case .sanFranciscoMono:
fontSizeScaleFactor = 0.15
case .newYork:
fontSizeScaleFactor = 0.17
}
fontSize = fontSizeScaleFactor * bounds.width

// TODO: dynamically determine value. I don't know how though
// 0.5: align center of target rect with center of screen
// 0.15: offset so font is visually centered
vOffset = fontSize * 0.5 - 0.15 * fontSize

let font: NSFont
if preferences.useSystemFont {
font = NSFont.monospacedDigitSystemFont(ofSize: fontSize, weight: preferences.fontWeight)
} else {
let fontName: String
switch preferences.fontWeight {
case .ultraLight: fontName = "Helvetica Neue UltraLight"
case .thin: fontName = "Helvetica Neue Thin"
case .light: fontName = "Helvetica Neue Light"
case .regular: fontName = "Helvetica Neue"
case .medium: fontName = "Helvetica Neue Medium"
case .bold: fontName = "Helvetica Neue Bold"
default: fontName = "Helvetica Neue"
}
// not supported:
// semibold, heavy, black
font = NSFont(name: fontName, size: fontSize)!
}
let font = preferences.nsFont(ofSize: fontSize)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
attributes = [
Expand Down
144 changes: 83 additions & 61 deletions Padbury Clock Revived/ConfigureSheet.xib

Large diffs are not rendered by default.

30 changes: 22 additions & 8 deletions Padbury Clock Revived/ConfigureSheetController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ class ConfigureSheetController: NSObject {

@IBOutlet var window: NSWindow?

@IBOutlet var versionStringLabel: NSTextField!

@IBOutlet var darkThemeCheckbox: NSButton!
@IBOutlet var nightTimeModeCheckbox: NSButton!
@IBOutlet var twentyfourHoursCheckbox: NSButton!
@IBOutlet var showSecondsCheckbox: NSButton!
@IBOutlet var showTimeSeparatorsCheckbox: NSButton!
@IBOutlet var useSystemFontCheckbox: NSButton!
@IBOutlet var fontSelector: NSPopUpButton!
@IBOutlet var fontWeightSelector: NSPopUpButton!

override init() {
Expand All @@ -32,23 +34,31 @@ class ConfigureSheetController: NSObject {
}

func setup() {
let bundle = Bundle(for: ConfigureSheetController.self)
versionStringLabel.stringValue = "v\(bundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") ?? "???") b\(bundle.object(forInfoDictionaryKey: "CFBundleVersion") ?? "?")"

if let preferences = Preferences.shared {
darkThemeCheckbox.state = preferences.darkTheme ? .on : .off
nightTimeModeCheckbox.state = preferences.nightTimeMode ? .on : .off
twentyfourHoursCheckbox.state = preferences.useAmPm ? .off : .on
showSecondsCheckbox.state = preferences.showSeconds ? .on : .off
showTimeSeparatorsCheckbox.state = preferences.showTimeSeparators ? .on : .off
useSystemFontCheckbox.state = preferences.useSystemFont ? .on : .off
fontSelector.selectItem(withTitle: preferences.font.name)

fontSelector.removeAllItems()
let availableFonts: [String] = SupportedFonts.allCases.map { $0.name }
for font in availableFonts {
fontSelector.addItem(withTitle: font)
}
fontSelector.selectItem(withTitle: preferences.font.name)

fontWeightSelector.removeAllItems()
let availableFontWeights: [NSFont.Weight] = preferences.useSystemFont ?
[.ultraLight, .thin, .light, .regular, .medium, .semibold, .bold, .heavy, .black] :
[.ultraLight, .thin, .light, .regular, .medium, .bold]
for fontWeight in availableFontWeights {
for fontWeight in preferences.font.availableWeights {
fontWeightSelector.addItem(withTitle: fontWeight.name)
}
fontWeightSelector.selectItem(at: availableFontWeights.firstIndex(of: preferences.fontWeight) ?? 0)
fontWeightSelector.selectItem(at: preferences.font.availableWeights.firstIndex(of: preferences.fontWeight) ?? 0)
preferences.fontWeight = NSFont.Weight.from(name: fontWeightSelector.selectedItem?.title ?? "")

ClockView.shared?.setup(force: true)
}
}
Expand All @@ -60,7 +70,7 @@ class ConfigureSheetController: NSObject {
preferences.useAmPm = twentyfourHoursCheckbox.state == .off
preferences.showSeconds = showSecondsCheckbox.state == .on
preferences.showTimeSeparators = showTimeSeparatorsCheckbox.state == .on
preferences.useSystemFont = useSystemFontCheckbox.state == .on
preferences.font = SupportedFonts.named(fontSelector.selectedItem?.title ?? "")
preferences.fontWeight = NSFont.Weight.from(name: fontWeightSelector.selectedItem?.title ?? "")

self.setup()
Expand All @@ -70,4 +80,8 @@ class ConfigureSheetController: NSObject {
@IBAction func closeConfigureSheet(_ sender: AnyObject) {
window?.sheetParent?.endSheet(window!)
}

@IBAction func openGithubLink(_ sender: Any) {
NSWorkspace.shared.open(URL(string: "https://github.com/Kamik423/Padbury-Clock-Revived")!)
}
}
72 changes: 72 additions & 0 deletions Padbury Clock Revived/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,39 @@ class Preferences: NSObject {
defaults.synchronize()
}
}

var font: SupportedFonts {
get { return SupportedFonts.named(defaults.value(forKey: "Font") as? String ?? "") }
set {
defaults.setValue(newValue.name, forKey: "Font")
defaults.synchronize()
}
}

func nsFont(ofSize fontSize: CGFloat) -> NSFont {
let fallback = NSFont.monospacedDigitSystemFont(ofSize: fontSize, weight: fontWeight)
switch font {
case .sanFrancisco:
return .monospacedDigitSystemFont(ofSize: fontSize, weight: fontWeight)
case .sanFranciscoMono:
return .monospacedSystemFont(ofSize: fontSize, weight: fontWeight)
case .newYork:
let descriptor = NSFont.monospacedDigitSystemFont(ofSize: fontSize, weight: fontWeight).fontDescriptor
return NSFont(descriptor: descriptor.withDesign(.serif) ?? descriptor, size: 0.0) ?? fallback
case .helveticaNeue:
let fontName: String
switch fontWeight {
case .ultraLight: fontName = "Helvetica Neue UltraLight"
case .thin: fontName = "Helvetica Neue Thin"
case .light: fontName = "Helvetica Neue Light"
case .regular: fontName = "Helvetica Neue"
case .medium: fontName = "Helvetica Neue Medium"
case .bold: fontName = "Helvetica Neue Bold"
default: fontName = "Helvetica Neue"
}
return NSFont(name: fontName, size: fontSize) ?? fallback
}
}

var darkTheme: Bool {
get { return (defaults.value(forKey: "DarkTheme") as? Bool) ?? true }
Expand Down Expand Up @@ -77,6 +110,45 @@ class Preferences: NSObject {
}
}

// MARK: - Supported Fonts ENum

enum SupportedFonts: String, CaseIterable {
case sanFrancisco
case sanFranciscoMono
case newYork
case helveticaNeue

var name: String {
switch self {
case .sanFrancisco:
return "San Francisco (System Font)"
case .sanFranciscoMono:
return "San Francisco Mono"
case .newYork:
return "New York"
case .helveticaNeue:
return "Helvetica Neue (Padbury Original)"
}
}

static func named(_ name: String) -> SupportedFonts {
SupportedFonts.allCases.first(where: { $0.name == name }) ?? .sanFrancisco
}

var availableWeights: [NSFont.Weight] {
switch self {
case .sanFrancisco:
return [.ultraLight, .thin, .light, .regular, .medium, .semibold, .bold, .heavy, .black]
case .sanFranciscoMono:
return [.light, .regular, .medium, .semibold, .bold, .heavy, .black]
case .newYork:
return [.regular, .medium, .semibold, .bold, .heavy, .black]
case .helveticaNeue:
return [.ultraLight, .thin, .light, .regular, .medium, .bold]
}
}
}

// MARK: - NSFont.Weight Names

extension NSFont.Weight {
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Padbury Clock Revived

![screenshot](screenshots/screenshot-0.png)
<img src="screenshots/screenshot-0.png" width=100%>

The [Padbury Clock](https://padbury.app) is a minimalist screensaver created by [Robert Padbury](https://twitter.com/Padbury).
It has not been updated in ages and actually broke for me during the Big Sur beta cycle (although that issue resolved itself).
Expand All @@ -11,7 +11,8 @@ The original screensaver used Helvetia Neue Ultra Light.
With the new version you will also be able to select San Francisco, Apple's new system font as the font used.
The night time mode from the original is also supported.

<img src="screenshots/screenshot-1.png" width=50%><img src="screenshots/screenshot-2.png" width=50%>
<img src="screenshots/screenshot-1.png" width=30%> <img src="screenshots/screenshot-2.png" width=30%> <img src="screenshots/screenshot-3.png" width=30%>
<img src="screenshots/screenshot-4.png" width=30%> <img src="screenshots/screenshot-5.png" width=30%> <img src="screenshots/screenshot-6.png" width=30%>

![settings](screenshots/settings.png)
## Installation
Expand All @@ -20,7 +21,13 @@ Download [the latest version](https://github.com/Kamik423/Padbury-Clock-Revived/

## Changelog

### 1.0.2 (2022-02-10)
### 1.1.0 (2022-02-10)

* Added more font options
* Added GitHub button
* Added version number to settings screen

### 1.0.2 (2022-02-09)

* Added night time mode
* Fixed settings not saving correctly
Expand Down
Binary file added screenshots/screenshot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/screenshot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/screenshot-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/screenshot-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 794cbca

Please sign in to comment.