-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathTTProgressView.m
70 lines (61 loc) · 1.75 KB
/
TTProgressView.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
62
63
64
65
66
67
68
69
70
//
// TTProgressView.m
// Textus
//
// Created by Jiang Jiang on 7/16/12.
//
#import "TTProgressView.h"
@implementation TTProgressView {
NSPoint _currentPoint;
}
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// TODO: figure out why 50 padding is needed here
CGFloat width = frame.size.width + 50;
NSRect rect = NSMakeRect(0, 0, width, frame.size.height);
NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
NSTrackingMouseMoved |
NSTrackingActiveInKeyWindow;
NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:rect
options:options
owner:self
userInfo:nil];
[self addTrackingArea:trackingArea];
}
return self;
}
- (void)mouseEntered:(NSEvent*)theEvent {
[[self window] setAcceptsMouseMovedEvents:YES];
}
- (void)mouseMoved:(NSEvent*)theEvent {
_currentPoint = [self convertPoint:theEvent.locationInWindow fromView:nil];
[self setNeedsDisplay:YES];
}
- (void)mouseExited:(NSEvent*)theEvent {
[[self window] setAcceptsMouseMovedEvents:NO];
}
- (void)drawRect:(NSRect)dirtyRect {
// Drawing code here.
[[NSColor darkGrayColor] setFill];
CGFloat width = self.frame.size.width / 50;
int i;
CGFloat r;
NSInteger p = [statusField integerValue];
bool unread = false;
for (i = 1; i < 50; i++) {
if (p < i * 2 && !unread) {
[[NSColor lightGrayColor] setFill];
unread = true;
}
r = 3;
if (ABS(_currentPoint.x - i * width) < 5)
r = 6;
// Create our circle path
NSRect rect = NSMakeRect(i * width - r / 2, 8.5 - r / 2, r, r);
NSBezierPath* circlePath = [NSBezierPath bezierPath];
[circlePath appendBezierPathWithOvalInRect:rect];
[circlePath fill];
}
}
@end