-
Notifications
You must be signed in to change notification settings - Fork 0
/
ITSplashScreen.m
102 lines (85 loc) · 2.38 KB
/
ITSplashScreen.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#import "ITSplashScreen.h"
#import "ITSplashWindow.h"
#import "ITSplashView.h"
static ITSplashScreen *_sharedScreen;
@implementation ITSplashScreen
+ (ITSplashScreen *)sharedController {
if (!_sharedScreen) {
_sharedScreen = [[ITSplashScreen alloc] init];
}
return _sharedScreen;
}
- (id)init {
if ((self = [super init])) {
_window = [[ITSplashWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 200) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
_view = [[ITSplashView alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)];
[_window setLevel:NSStatusWindowLevel];
[_window setContentView:[_view autorelease]];
}
return self;
}
- (void)dealloc {
[_window release];
[super dealloc];
}
- (double)progressValue {
return ([[_view progressIndicator] doubleValue] / 100.0);
}
- (void)setProgressValue:(double)progress {
if (progress >= 1.0) {
[[_view progressIndicator] setIndeterminate:YES];
} else {
[[_view progressIndicator] setDoubleValue:(progress * 100.0)];
}
}
- (NSImage *)image {
return [_view image];
}
- (void)setImage:(NSImage *)image {
NSRect rect = NSZeroRect, newRect = [_window frame];
rect.size = [image size];
newRect.size = rect.size;
[_window setFrame:newRect display:NO];
newRect.origin.x = 0;
newRect.origin.y = 0;
[_view setFrame:newRect];
[_view setImage:image];
[_window center];
}
- (NSString *)string {
return [_view string];
}
- (void)setString:(NSString *)string {
[_view setString:string];
}
- (void)setSettingsPath:(NSString *)path {
[_view loadControlsFromPath:path];
}
- (void)showSplashWindow {
//[_window setAlphaValue:0.0];
[_window makeKeyAndOrderFront:nil];
//_fadeTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / 30.0) target:self selector:@selector(showStep:) userInfo:nil repeats:YES];
}
- (void)showStep:(NSTimer *)timer {
[_window setAlphaValue:([_window alphaValue] + 0.05)];
if ([_window alphaValue] >= 1.0) {
[timer invalidate];
_fadeTimer = nil;
}
}
- (void)closeSplashWindow {
if (_fadeTimer) {
[_fadeTimer invalidate];
}
_fadeTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / 30.0) target:self selector:@selector(closeStep:) userInfo:nil repeats:YES];
}
- (void)closeStep:(NSTimer *)timer {
[_window setAlphaValue:([_window alphaValue] - 0.05)];
if ([_window alphaValue] <= 0.0) {
[timer invalidate];
_fadeTimer = nil;
[_window orderOut:nil];
[_view stopAnimation];
}
}
@end