-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimeOffsetView.m
61 lines (51 loc) · 1.99 KB
/
TimeOffsetView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// TimeOffsetView.m
// GPSLogger
//
// Created by German Laullon on 17/11/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "TimeOffsetView.h"
@implementation TimeOffsetView
@synthesize seconds;
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
seconds = 0;
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
NSGradient *backgroundGradient = [[NSGradient alloc] initWithStartingColor:[NSColor grayColor] endingColor:[NSColor blackColor]];
[backgroundGradient drawInRect:dirtyRect angle:90];
NSMutableDictionary *drawStringAttributes = [[NSMutableDictionary alloc] init];
[drawStringAttributes setValue:[NSColor whiteColor] forKey:NSForegroundColorAttributeName];
[drawStringAttributes setValue:[NSFont fontWithName:@"Andale Mono" size:24] forKey:NSFontAttributeName];
NSShadow *stringShadow = [[NSShadow alloc] init];
[stringShadow setShadowColor:[NSColor blackColor]];
NSSize shadowSize;
shadowSize.width = 2;
shadowSize.height = -2;
[stringShadow setShadowOffset:shadowSize];
[stringShadow setShadowBlurRadius:6];
[drawStringAttributes setValue:stringShadow forKey:NSShadowAttributeName];
NSString *sig = seconds >= 0 ? @"+" : @"-";
NSString *MRString = [NSString stringWithFormat:@"%@ %02ld:%02ld Sec.",sig,abs(seconds/60),abs(seconds%60)];
NSString *budgetString = [NSString stringWithFormat:@"%@", MRString];
NSSize stringSize = [budgetString sizeWithAttributes:drawStringAttributes];
NSPoint centerPoint;
centerPoint.x = (dirtyRect.size.width / 2) - (stringSize.width / 2);
centerPoint.y = dirtyRect.size.height / 2 - (stringSize.height / 2);
[budgetString drawAtPoint:centerPoint withAttributes:drawStringAttributes];
}
- (void)scrollWheel:(NSEvent *)theEvent
{
if([theEvent deltaY]!=0){
seconds = seconds + ([theEvent deltaY]/1.5);
if(seconds>(30*60)) seconds=(30*60);
if(seconds<-(30*60)) seconds=(-30*60);
[self setNeedsDisplay:YES];
}
}
@end