Added ITSplashScreen stuff. Added ITSplashScreen.h to ITKit header.
[ITKit.git] / ITSplashScreen.m
1 #import "ITSplashScreen.h"
2 #import "ITSplashWindow.h"
3 #import "ITSplashView.h"
4
5 static ITSplashScreen *_sharedController;
6
7 @implementation ITSplashScreen
8
9 + (ITSplashScreen *)sharedController
10 {
11         if (!_sharedController) {
12                 _sharedController = [[ITSplashScreen alloc] init];
13         }
14         return _sharedController;
15 }
16
17 - (id)init
18 {
19         if ( (self = [super init]) ) {
20                 _window = [[ITSplashWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 200) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
21                 _view = [[ITSplashView alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)];
22                 [_window setLevel:NSStatusWindowLevel];
23                 [_window setContentView:[_view autorelease]];
24         }
25         return self;
26 }
27
28 - (void)dealloc
29 {
30         [_window release];
31         [super dealloc];
32 }
33
34 - (double)progressValue
35 {
36         return ([[_view progressIndicator] doubleValue] / 100.0);
37 }
38
39 - (void)setProgressValue:(double)progress
40 {
41         if (progress >= 1.0) {
42                 [[_view progressIndicator] setIndeterminate:YES];
43         } else {
44                 [[_view progressIndicator] setDoubleValue:(progress * 100.0)];
45         }
46 }
47
48 - (NSImage *)image
49 {
50         return [_view image];
51 }
52
53 - (void)setImage:(NSImage *)image
54 {
55         NSRect rect = NSZeroRect, newRect = [_window frame];
56         rect.size = [image size];
57         newRect.size = rect.size;
58         [_window setFrame:newRect display:NO];
59         newRect.origin.x = 0;
60         newRect.origin.y = 0;
61         [_view setFrame:newRect];
62         [_view setImage:image];
63         [_window center];
64 }
65
66 - (NSString *)string
67 {
68         return [_view string];
69 }
70
71 - (void)setString:(NSString *)string
72 {
73         [_view setString:string];
74 }
75
76 - (void)setSettingsPath:(NSString *)path
77 {
78         [_view loadControlsFromPath:path];
79 }
80
81 - (void)showSplashWindow
82 {
83         //[_window setAlphaValue:0.0];
84         [_window makeKeyAndOrderFront:nil];
85         //_fadeTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / 30.0) target:self selector:@selector(showStep:) userInfo:nil repeats:YES];
86 }
87
88 - (void)showStep:(NSTimer *)timer
89 {
90         [_window setAlphaValue:[_window alphaValue] + 0.05];
91         if ([_window alphaValue] >= 1.0) {
92                 [timer invalidate];
93                 _fadeTimer = nil;
94         }
95 }
96
97 - (void)closeSplashWindow
98 {
99         if (_fadeTimer) {
100                 [_fadeTimer invalidate];
101         }
102         _fadeTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / 30.0) target:self selector:@selector(closeStep:) userInfo:nil repeats:YES];
103 }
104
105 - (void)closeStep:(NSTimer *)timer
106 {
107         [_window setAlphaValue:[_window alphaValue] - 0.05];
108         if ([_window alphaValue] <= 0.0) {
109                 [timer invalidate];
110                 _fadeTimer = nil;
111                 [_window orderOut:nil];
112                 [_view stopAnimation];
113         }
114 }
115
116 @end