-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAYProgressIndicator.m
58 lines (47 loc) · 1.39 KB
/
AYProgressIndicator.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
//
// AYProgressIndicator.m
// AYProgressBar
//
// Created by Alexander Yakubchyk on 09.12.13.
// Copyright (c) 2013 Alexander Yakubchyk. All rights reserved.
//
#import "AYProgressIndicator.h"
@implementation AYProgressIndicator
- (id)initWithFrame:(NSRect)frameRect
progressColor:(NSColor*)progressColor
emptyColor:(NSColor*)emptyColor
minValue:(double)minValue
maxValue:(double)maxValue
currentValue:(double)currentValue
{
self = [super initWithFrame:frameRect];
if (self)
{
self.progressColor = progressColor;
self.emptyColor = emptyColor;
self.minValue = minValue;
self.maxValue = maxValue;
self.doubleValue = currentValue;
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
[self setWantsLayer:YES];
// Clear background color
[[NSColor clearColor] set];
NSRectFill(dirtyRect);
// Draw progress line
NSRect activeRect = dirtyRect;
[self.progressColor set];
activeRect.size.width = floor(activeRect.size.width * ([self doubleValue] / [self maxValue]));
NSRectFill(activeRect);
// Draw empty line
NSRect passiveRect = dirtyRect;
passiveRect.size.width -= activeRect.size.width;
passiveRect.origin.x = activeRect.size.width;
[self.emptyColor set];
NSRectFill(passiveRect);
}
@end