Abhishek Banthia
9 years ago
25 changed files with 520 additions and 92 deletions
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> |
||||
<dependencies> |
||||
<deployment identifier="macosx"/> |
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/> |
||||
</dependencies> |
||||
<objects> |
||||
<customObject id="-2" userLabel="File's Owner"/> |
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> |
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/> |
||||
</objects> |
||||
</document> |
Binary file not shown.
@ -0,0 +1,13 @@
|
||||
//
|
||||
// CLPanelTextField.h
|
||||
// Clocker
|
||||
//
|
||||
// Created by Abhishek Banthia on 5/4/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h> |
||||
|
||||
@interface CLPanelTextField : NSTextField |
||||
|
||||
@end |
@ -0,0 +1,48 @@
|
||||
// |
||||
// CLPanelTextField.m |
||||
// Clocker |
||||
// |
||||
// Created by Abhishek Banthia on 5/4/16. |
||||
// |
||||
// |
||||
|
||||
#import "CLPanelTextField.h" |
||||
#import "CLFloatingWindowController.h" |
||||
|
||||
@implementation CLPanelTextField |
||||
|
||||
- (void)drawRect:(NSRect)dirtyRect { |
||||
[super drawRect:dirtyRect]; |
||||
|
||||
// Drawing code here. |
||||
} |
||||
|
||||
- (void)mouseDown:(NSEvent *)theEvent |
||||
{ |
||||
[super mouseDown:theEvent]; |
||||
|
||||
CLFloatingWindowController *windowController = [CLFloatingWindowController sharedFloatingWindow]; |
||||
|
||||
[windowController.floatingWindowTimer pause]; |
||||
} |
||||
|
||||
- (void)mouseUp:(NSEvent *)theEvent |
||||
{ |
||||
[super mouseUp:theEvent]; |
||||
|
||||
CLFloatingWindowController *windowController = [CLFloatingWindowController sharedFloatingWindow]; |
||||
|
||||
[windowController.floatingWindowTimer pause]; |
||||
} |
||||
|
||||
- (BOOL)acceptsFirstResponder |
||||
{ |
||||
return YES; |
||||
} |
||||
|
||||
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent |
||||
{ |
||||
return YES; |
||||
} |
||||
|
||||
@end |
@ -0,0 +1,28 @@
|
||||
//
|
||||
// CLPausableTimer.h
|
||||
// Clocker
|
||||
//
|
||||
// Created by Abhishek Banthia on 5/4/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h> |
||||
|
||||
@interface CLPausableTimer : NSObject |
||||
|
||||
//Timer Info
|
||||
@property (nonatomic) NSTimeInterval timeInterval; |
||||
@property (nonatomic, weak) id target; |
||||
@property (nonatomic) SEL selector; |
||||
@property (nonatomic) id userInfo; |
||||
@property (nonatomic) BOOL repeats; |
||||
|
||||
@property (strong, nonatomic) NSTimer *timer; |
||||
@property (nonatomic) BOOL isPaused; |
||||
|
||||
+(CLPausableTimer *)timerWithTimeInterval:(NSTimeInterval)timeInterval target:(id)target selector:(SEL)selector userInfo:(id)userInfo repeats:(BOOL)repeats; |
||||
|
||||
-(void)pause; |
||||
-(void)start; |
||||
|
||||
@end |
@ -0,0 +1,103 @@
|
||||
// |
||||
// CLPausableTimer.m |
||||
// Clocker |
||||
// |
||||
// Created by Abhishek Banthia on 5/4/16. |
||||
// |
||||
// |
||||
|
||||
#import "CLPausableTimer.h" |
||||
|
||||
@implementation CLPausableTimer |
||||
|
||||
{ |
||||
NSDate *cycleStartDate; |
||||
NSTimeInterval remainingInterval; |
||||
BOOL hasPausedThisCycle; |
||||
} |
||||
|
||||
+(CLPausableTimer *)timerWithTimeInterval:(NSTimeInterval)timeInterval target:(id)target selector:(SEL)selector userInfo:(id)userInfo repeats:(BOOL)repeats |
||||
{ |
||||
|
||||
CLPausableTimer *new = [[CLPausableTimer alloc] init]; |
||||
new.timeInterval = timeInterval; |
||||
new.target = target; |
||||
new.selector = selector; |
||||
new.userInfo = userInfo; |
||||
new.repeats = repeats; |
||||
|
||||
return new; |
||||
} |
||||
|
||||
-(void)start |
||||
{ |
||||
|
||||
[self.timer invalidate]; |
||||
|
||||
if(self.isPaused) |
||||
{ //If resuming from a pause, use partial remaining time interval |
||||
self.timer = [NSTimer scheduledTimerWithTimeInterval:remainingInterval target:self selector:@selector(timerFired:) userInfo:self.userInfo repeats:self.repeats]; |
||||
|
||||
} else { |
||||
self.timer = [NSTimer scheduledTimerWithTimeInterval:self.timeInterval target:self selector:@selector(timerFired:) userInfo:self.userInfo repeats:self.repeats]; |
||||
|
||||
remainingInterval = self.timeInterval; |
||||
} |
||||
|
||||
self.isPaused = NO; |
||||
cycleStartDate = [NSDate date]; |
||||
|
||||
} |
||||
|
||||
-(void)pause |
||||
{ |
||||
if(self.isPaused) return; |
||||
|
||||
self.isPaused = YES; |
||||
hasPausedThisCycle = YES; |
||||
|
||||
[self.timer invalidate]; |
||||
|
||||
//keep track of time left on this cycle |
||||
remainingInterval -= [[NSDate date] timeIntervalSinceDate:cycleStartDate]; |
||||
} |
||||
|
||||
-(void)timerFired:(NSTimer *)timer |
||||
{ |
||||
if(self.isPaused) return; |
||||
|
||||
#pragma clang diagnostic push |
||||
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" |
||||
[self.target performSelector:self.selector withObject:self]; |
||||
#pragma clang diagnostic pop |
||||
|
||||
//reset remaining time to original value |
||||
remainingInterval = self.timeInterval; |
||||
cycleStartDate = [NSDate date]; |
||||
|
||||
if(hasPausedThisCycle) |
||||
{ |
||||
//current timer is running on remainingInterval |
||||
|
||||
//reset pause flag for next cycle |
||||
hasPausedThisCycle = NO; |
||||
|
||||
if(self.repeats) |
||||
{ //need to set up a new timer with original timeInterval |
||||
[self.timer invalidate]; |
||||
[self start]; |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
-(void)dealloc |
||||
{ |
||||
[self.timer invalidate]; |
||||
self.timer = nil; |
||||
self.selector = nil; |
||||
self.target = nil; |
||||
self.userInfo = nil; |
||||
} |
||||
|
||||
@end |
Loading…
Reference in new issue