Skip to content

Commit

Permalink
Added vibrancy view to make it look cooler and make text generally mo…
Browse files Browse the repository at this point in the history
…re readable
  • Loading branch information
stonehouse committed Mar 22, 2017
1 parent 433fa01 commit d4c1a1e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
2 changes: 1 addition & 1 deletion T-Minus/CountdownView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@interface CountdownView : NSView

@property (weak) IBOutlet NSTextFieldCell *countdownLabel;
@property (nonatomic, strong) NSString *description;
@property (nonatomic, strong) NSString *backgroundPath;
@property (weak) IBOutlet NSImageView *backgroundView;

Expand Down
26 changes: 25 additions & 1 deletion T-Minus/CountdownView.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,41 @@

@interface CountdownView()

@property (weak) IBOutlet NSTextFieldCell *countdownLabel;
@property (weak) IBOutlet NSTextFieldCell *countdownTitleLabel;
@property (weak) IBOutlet NSVisualEffectView *visualEffectView;
@property (weak) IBOutlet NSLayoutConstraint *widthConstraint;

@end

@implementation CountdownView

-(void)awakeFromNib
{
[super awakeFromNib];

self.visualEffectView.layer.cornerRadius = 5.0f;
}

- (void)setDescription:(NSString *)description
{
self.countdownLabel.stringValue = description;
CGFloat currentWidth = self.widthConstraint.constant;
CGFloat defaultPadding = 20;
CGFloat desiredWidth = [self.countdownLabel cellSize].width + defaultPadding;
CGFloat diff = currentWidth - desiredWidth;
if (diff < 0 || diff > 40) {
self.widthConstraint.constant = desiredWidth + defaultPadding;
[self setNeedsUpdateConstraints:YES];
}
}

- (void)setBackgroundPath:(NSString *)backgroundPath
{
NSURL *bgURL = [NSURL fileURLWithPath:backgroundPath];
self.backgroundView.image = [[NSImage alloc] initWithContentsOfURL:bgURL];
[self adjustTextColor];
self.countdownLabel.textColor = [NSColor whiteColor];
self.countdownTitleLabel.textColor = [NSColor whiteColor];
}

- (void)adjustTextColor
Expand Down
57 changes: 34 additions & 23 deletions T-Minus/CountdownView.xib
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16B2555" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner"/>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="c22-O7-iKe" customClass="CountdownView">
<customView wantsLayer="YES" id="c22-O7-iKe" customClass="CountdownView">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="AuJ-Iz-O21">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<imageCell key="cell" scrollable="YES" lineBreakMode="clipping" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" id="ctI-ay-bQB"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Qgn-xA-33d">
<rect key="frame" x="18" y="105" width="444" height="60"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="left" title="12 Days 5:12:31" id="hPX-lE-mos">
<font key="font" metaFont="system" size="50"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="eDC-9b-xG6">
<rect key="frame" x="18" y="165" width="58" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="T-Minus:" id="jp5-zh-A1C">
<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>
<visualEffectView appearanceType="vibrantDark" blendingMode="withinWindow" material="appearanceBased" state="followsWindowActiveState" translatesAutoresizingMaskIntoConstraints="NO" id="i9L-1Z-VOl">
<rect key="frame" x="20" y="85" width="400" height="100"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Qgn-xA-33d">
<rect key="frame" x="8" y="10" width="350" height="60"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="left" title="12 Days 5:12:31" id="hPX-lE-mos">
<font key="font" metaFont="system" size="50"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="eDC-9b-xG6">
<rect key="frame" x="8" y="70" width="58" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="T-Minus:" id="jp5-zh-A1C">
<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>
</subviews>
<constraints>
<constraint firstAttribute="width" constant="400" id="EIU-VK-VpZ"/>
<constraint firstItem="Qgn-xA-33d" firstAttribute="leading" secondItem="i9L-1Z-VOl" secondAttribute="leading" constant="10" id="MNe-SI-H1A"/>
<constraint firstItem="eDC-9b-xG6" firstAttribute="leading" secondItem="Qgn-xA-33d" secondAttribute="leading" id="XwH-hJ-0Wy"/>
<constraint firstAttribute="height" constant="100" id="ZlA-87-daY"/>
<constraint firstItem="Qgn-xA-33d" firstAttribute="centerY" secondItem="i9L-1Z-VOl" secondAttribute="centerY" constant="10" id="eYF-iH-Q8G"/>
<constraint firstItem="Qgn-xA-33d" firstAttribute="top" secondItem="eDC-9b-xG6" secondAttribute="bottom" id="l8C-jV-6nz"/>
</constraints>
</visualEffectView>
</subviews>
<constraints>
<constraint firstItem="eDC-9b-xG6" firstAttribute="leading" secondItem="Qgn-xA-33d" secondAttribute="leading" id="4ol-v8-Hiq"/>
<constraint firstItem="i9L-1Z-VOl" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="2La-EP-lg6"/>
<constraint firstItem="i9L-1Z-VOl" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" constant="20" id="DVG-oW-UIC"/>
<constraint firstAttribute="trailing" secondItem="AuJ-Iz-O21" secondAttribute="trailing" id="NXh-DA-dCf"/>
<constraint firstAttribute="bottom" secondItem="AuJ-Iz-O21" secondAttribute="bottom" id="OHH-aj-Fpf"/>
<constraint firstItem="AuJ-Iz-O21" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="UyQ-WV-qUW"/>
<constraint firstItem="Qgn-xA-33d" firstAttribute="top" secondItem="eDC-9b-xG6" secondAttribute="bottom" id="Xu1-31-uvY"/>
<constraint firstItem="Qgn-xA-33d" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="bne-z6-rXY"/>
<constraint firstItem="Qgn-xA-33d" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" constant="20" id="fOj-ad-aJW"/>
<constraint firstAttribute="trailing" secondItem="Qgn-xA-33d" secondAttribute="trailing" constant="20" id="g52-e7-InQ"/>
<constraint firstItem="AuJ-Iz-O21" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="zl7-Zs-Gyz"/>
</constraints>
<connections>
<outlet property="backgroundView" destination="AuJ-Iz-O21" id="lOS-yD-zH0"/>
<outlet property="countdownLabel" destination="hPX-lE-mos" id="MIJ-nK-sTQ"/>
<outlet property="countdownTitleLabel" destination="jp5-zh-A1C" id="0LD-xZ-G9h"/>
<outlet property="visualEffectView" destination="i9L-1Z-VOl" id="FhV-sY-YEJ"/>
<outlet property="widthConstraint" destination="EIU-VK-VpZ" id="LJm-Eo-fHd"/>
</connections>
</customView>
</objects>
Expand Down
6 changes: 3 additions & 3 deletions T-Minus/CountdownViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (void)viewDidAppear

- (void)windowDidResize:(NSNotification *)notification
{
[self.countdownView adjustTextColor];

}


Expand All @@ -78,7 +78,7 @@ - (void)updateTimer {

Tminus tm = Countdown_tminus(self.ctdn);

self.countdownView.countdownLabel.stringValue = [NSString stringWithUTF8String:tm.description];
self.countdownView.description = [NSString stringWithUTF8String:tm.description];

if (tm.difference == 10) {
// With 10 seconds to go, pop to the foreground
Expand Down Expand Up @@ -149,7 +149,7 @@ - (void)cancel:(id)sender

- (void)createCountdown
{
self.countdownView.countdownLabel.stringValue = @"";
self.countdownView.description = @"";
NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
NSWindowController *vc = [storyboard instantiateControllerWithIdentifier:@"createCountdown"];

Expand Down

0 comments on commit d4c1a1e

Please sign in to comment.