-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathLevelIndicator.m
More file actions
63 lines (52 loc) · 2.45 KB
/
LevelIndicator.m
File metadata and controls
63 lines (52 loc) · 2.45 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
#include <Cocoa/Cocoa.h>
@interface Window : NSWindow {
NSLevelIndicator* levelIndicator1;
NSLevelIndicator* levelIndicator2;
NSLevelIndicator* levelIndicator3;
NSLevelIndicator* levelIndicator4;
NSLevelIndicator* levelIndicator5;
NSTimer* timer;
}
- (instancetype)init;
- (void)onTimerTick:(NSTimer*)timer;
- (BOOL)windowShouldClose:(id)sender;
@end
@implementation Window
- (instancetype)init {
levelIndicator1 = [[[NSLevelIndicator alloc] initWithFrame:NSMakeRect(50, 230, 200, 20)] autorelease];
[levelIndicator1 setDoubleValue:0];
levelIndicator2 = [[[NSLevelIndicator alloc] initWithFrame:NSMakeRect(50, 200, 200, 20)] autorelease];
[levelIndicator2 setDoubleValue:2];
levelIndicator3 = [[[NSLevelIndicator alloc] initWithFrame:NSMakeRect(50, 170, 200, 20)] autorelease];
[levelIndicator3 setLevelIndicatorStyle:NSLevelIndicatorStyleContinuousCapacity];
[levelIndicator3 setDoubleValue:4];
levelIndicator4 = [[[NSLevelIndicator alloc] initWithFrame:NSMakeRect(50, 140, 200, 20)] autorelease];
[levelIndicator4 setDoubleValue:0];
levelIndicator5 = [[[NSLevelIndicator alloc] initWithFrame:NSMakeRect(50, 110, 200, 20)] autorelease];
[levelIndicator5 setLevelIndicatorStyle:NSLevelIndicatorStyleRating];
[levelIndicator5 setDoubleValue:3];
timer = [NSTimer timerWithTimeInterval:0.4f target:self selector:@selector(onTimerTick:) userInfo:levelIndicator4 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:@"LevelIndicator Example"];
[[self contentView] addSubview:levelIndicator1];
[[self contentView] addSubview:levelIndicator2];
[[self contentView] addSubview:levelIndicator3];
[[self contentView] addSubview:levelIndicator4];
[[self contentView] addSubview:levelIndicator5];
[self setIsVisible:YES];
return self;
}
- (void)onTimerTick:(NSTimer*)timer {
[levelIndicator4 setDoubleValue:[levelIndicator4 doubleValue] < [levelIndicator4 maxValue] ? [levelIndicator4 doubleValue] + 1 : [levelIndicator4 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];
}