-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathTrackBar.m
More file actions
56 lines (48 loc) · 1.76 KB
/
TrackBar.m
File metadata and controls
56 lines (48 loc) · 1.76 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
#include <Cocoa/Cocoa.h>
@interface Window : NSWindow {
NSSlider* trackBar;
NSProgressIndicator* progressBar;
NSTextField* label;
}
- (instancetype)init;
- (IBAction) valueChanged:(id)sender;
- (BOOL)windowShouldClose:(id)sender;
@end
@implementation Window
- (instancetype)init {
trackBar = [[[NSSlider alloc] initWithFrame:NSMakeRect(20, 215, 200, 25)] autorelease];
[trackBar setAction:@selector(valueChanged:)];
[trackBar setMaxValue:200];
[trackBar setDoubleValue:100];
progressBar = [[[NSProgressIndicator alloc] initWithFrame:NSMakeRect(20, 180, 200, 20)] autorelease];
[progressBar setMaxValue:200];
[progressBar setIndeterminate:NO];
[progressBar setDoubleValue:100];
label = [[[NSTextField alloc] initWithFrame:NSMakeRect(20, 130, 100, 20)] autorelease];
[label setStringValue:@"100"];
[label setBezeled:NO];
[label setDrawsBackground:NO];
[label setEditable:NO];
[label setSelectable:NO];
[super initWithContentRect:NSMakeRect(100, 100, 300, 300) styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO];
[self setTitle:@"TrackBar Example"];
[[self contentView] addSubview:trackBar];
[[self contentView] addSubview:progressBar];
[[self contentView] addSubview:label];
[self setIsVisible:YES];
return self;
}
- (IBAction) valueChanged:(id)sender {
[progressBar setDoubleValue:[trackBar doubleValue]];
[label setStringValue:[NSString stringWithFormat:@"%d", (int)[trackBar doubleValue]]];
}
- (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];
}