* Fix look of position time field to match the rest of the UI. * Fix typo. * Improve position time display. * Add days, hours support to position time display. * Fix "Current Time" toolbar item geometry/layout. * Don’t enforce leading double-digits in position time display. * MainMenu.xib touched by Xcode. * Implement and use MonospacedDigitTextFieldCell. This way the digits of numbers in playlist columns consisting of mostly digits will be aligned vertically. * Disable font scaling code without effect. * Set "Current Time" toolbar item to use MonospacedDigitTextFieldCell. * Improve SecondsFormatter. * Merge in SecondsFormatter improvements from Play. * Move formatter setup into XIB. * Add CogTests. These can later be used for integration tests. * Add SecondsFormatterTests. Tests are stubbed out. * Pouring foundation for SecondsFormatterTests. * Implement -testPositive. * Replace unsigned with int in SecondsFormatter. * Implement negative support, tests. * Rewrite SecondsFormatter in preparation for better readability.. * Rewrite SecondsFormatter for better readability. * Add negative zero support. * Improve SecondsFormatter readability. * Refactor into -stringForTimeInterval: in SecondsFormatter. * Cleanup. * Mark TimeField as space-indented. * Replace custom time formatting code in TimeField with SecondsFormatter. * Cleanup. * Improve SecondsFormatter format strings. * Add internal type for time calculations. Co-authored-by: Jan Weiß <jan@geheimwerk.de>
87 lines
1.9 KiB
Objective-C
87 lines
1.9 KiB
Objective-C
//
|
|
// TimeField.m
|
|
// Cog
|
|
//
|
|
// Created by Vincent Spader on 2/22/09.
|
|
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
|
//
|
|
|
|
#import "TimeField.h"
|
|
|
|
#import "SecondsFormatter.h"
|
|
|
|
|
|
static NSString *kTimerModeKey = @"timerShowTimeRemaining";
|
|
|
|
|
|
@implementation TimeField {
|
|
BOOL showTimeRemaining;
|
|
NSDictionary *fontAttributes;
|
|
SecondsFormatter *secondsFormatter;
|
|
}
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)aDecoder
|
|
{
|
|
if (self = [super initWithCoder:aDecoder])
|
|
{
|
|
[self commonInit];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
if (self = [super initWithFrame:frame])
|
|
{
|
|
[self commonInit];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void)commonInit
|
|
{
|
|
secondsFormatter = [[SecondsFormatter alloc] init];
|
|
}
|
|
|
|
- (void)awakeFromNib
|
|
{
|
|
showTimeRemaining = [[NSUserDefaults standardUserDefaults] boolForKey:kTimerModeKey];
|
|
}
|
|
|
|
- (void)update
|
|
{
|
|
NSString *text;
|
|
if (showTimeRemaining == NO)
|
|
{
|
|
NSTimeInterval sec = self.currentTime;
|
|
text = [secondsFormatter stringForTimeInterval:sec];
|
|
}
|
|
else
|
|
{
|
|
NSTimeInterval sec = self.currentTime - self.duration;
|
|
// NOTE: The floating point standard has support for negative zero.
|
|
// We use that to enforce the sign prefix.
|
|
if (sec == 0.0) { sec = -0.0; }
|
|
text = [secondsFormatter stringForTimeInterval:sec];
|
|
}
|
|
NSAttributedString *string = [[NSAttributedString alloc] initWithString:text
|
|
attributes:fontAttributes];
|
|
[self setAttributedStringValue: string];
|
|
}
|
|
|
|
- (void)mouseDown:(NSEvent *)theEvent
|
|
{
|
|
showTimeRemaining = !showTimeRemaining;
|
|
[[NSUserDefaults standardUserDefaults] setBool:showTimeRemaining forKey:kTimerModeKey];
|
|
[self update];
|
|
}
|
|
|
|
- (void)setCurrentTime:(NSTimeInterval)currentTime
|
|
{
|
|
_currentTime = currentTime;
|
|
[self update];
|
|
}
|
|
|
|
@end
|