-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathProgressIndicator.m
More file actions
65 lines (54 loc) · 2.59 KB
/
ProgressIndicator.m
File metadata and controls
65 lines (54 loc) · 2.59 KB
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
#include <Cocoa/Cocoa.h>
@interface Window : NSWindow {
NSProgressIndicator* progressIndicator1;
NSProgressIndicator* progressIndicator2;
NSProgressIndicator* progressIndicator3;
NSProgressIndicator* progressIndicator4;
NSProgressIndicator* progressIndicator5;
NSTimer* timer;
}
- (instancetype)init;
- (void)onTimerTick:(NSTimer*)timer;
- (BOOL)windowShouldClose:(id)sender;
@end
@implementation Window
- (instancetype)init {
progressIndicator1 = [[[NSProgressIndicator alloc] initWithFrame:NSMakeRect(50, 230, 200, 20)] autorelease];
[progressIndicator1 setIndeterminate:NO];
[progressIndicator1 setDoubleValue:0];
progressIndicator2 = [[[NSProgressIndicator alloc] initWithFrame:NSMakeRect(50, 200, 200, 20)] autorelease];
[progressIndicator2 setIndeterminate:NO];
[progressIndicator2 setDoubleValue:50];
progressIndicator3 = [[[NSProgressIndicator alloc] initWithFrame:NSMakeRect(50, 170, 200, 20)] autorelease];
[progressIndicator3 setIndeterminate:NO];
[progressIndicator3 setDoubleValue:100];
progressIndicator4 = [[[NSProgressIndicator alloc] initWithFrame:NSMakeRect(50, 140, 200, 20)] autorelease];
[progressIndicator4 setIndeterminate:NO];
[progressIndicator4 setDoubleValue:0];
progressIndicator5 = [[[NSProgressIndicator alloc] initWithFrame:NSMakeRect(50, 110, 200, 20)] autorelease];
[progressIndicator5 startAnimation:progressIndicator5];
timer = [NSTimer timerWithTimeInterval:0.05f target:self selector:@selector(onTimerTick:) userInfo:progressIndicator4 repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[super initWithContentRect:NSMakeRect(100, 100, 300, 300) styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO];
[self setTitle:@"ProgressBar Example"];
[[self contentView] addSubview:progressIndicator1];
[[self contentView] addSubview:progressIndicator2];
[[self contentView] addSubview:progressIndicator3];
[[self contentView] addSubview:progressIndicator4];
[[self contentView] addSubview:progressIndicator5];
[self setIsVisible:YES];
return self;
}
- (void)onTimerTick:(NSTimer*)timer {
[progressIndicator4 setDoubleValue:[progressIndicator4 doubleValue] < [progressIndicator4 maxValue] ? [progressIndicator4 doubleValue] + 1 : [progressIndicator4 minValue]];
}
- (BOOL)windowShouldClose:(id)sender {
[NSApp terminate:sender];
return YES;
}
@end
int main(int argc, char* argv[]) {
[NSApplication sharedApplication];
[[[[Window alloc] init] autorelease] makeMainWindow];
[NSApp run];
}