forked from Daij-Djan/proximity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProximityStatusItem.m
58 lines (42 loc) · 1.52 KB
/
ProximityStatusItem.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
// ProximityStatusItem.m
// Proximity
// Created by Seb Jachec on 13/12/2013.
#import "ProximityStatusItem.h"
@implementation ProximityStatusItem
- (void)setup {
_inRange = NO;
_paused = NO;
[self addObserver:self forKeyPath:@"inRange" options:0 context:NULL];
[self addObserver:self forKeyPath:@"paused" options:0 context:NULL];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == self) {
self.needsDisplay = YES;
}
}
- (void)drawRect:(NSRect)dirtyRect {
[self drawStandardBackground];
if (_paused) {
//TODO: Draw image
} else {
NSRect drawRect = NSInsetRect(NSOffsetRect(_bounds, 0, 1), 3.0f, 3.0f);
NSRect circleRect = _inRange? NSInsetRect(drawRect, 1.0f, 1.0f) : drawRect;
NSBezierPath *circle = [NSBezierPath bezierPathWithOvalInRect:circleRect];
[(selected? [NSColor whiteColor] : [NSColor blackColor]) set];
if (_inRange) {
[circle setLineWidth:2.0f];
[circle stroke];
} else {
[circle fill];
}
if (!selected) {
NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.5]];
[shadow setShadowOffset:NSMakeSize(0, -1)];
[shadow setShadowBlurRadius:0.0f];
[shadow set];
[circle stroke];
}
}
}
@end