5c90f53d68b5fb0a796708de74d7e1b7334652e8
[ITKit.git] / ITSplashView.m
1 //
2 //  ITSplashView.m
3 //  SplashScreen
4 //
5 //  Created by Kent Sutherland on 11/22/04.
6 //  Copyright 2004 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ITSplashView.h"
10
11 @implementation ITSplashView
12
13 - (id)initWithFrame:(NSRect)frame
14 {
15     if ( (self = [super initWithFrame:frame]) ) {
16     }
17     return self;
18 }
19
20 - (void)dealloc
21 {
22         [_image release];
23         [_progress release];
24         [_text release];
25         [super dealloc];
26 }
27
28 - (void)drawRect:(NSRect)rect
29 {
30         [_image compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver];
31 }
32
33 - (BOOL)isOpaque
34 {
35         return NO;
36 }
37
38 - (void)stopAnimation
39 {
40         [_progress stopAnimation:nil];
41 }
42
43 - (NSProgressIndicator *)progressIndicator
44 {
45         return _progress;
46 }
47
48 - (NSImage *)image
49 {
50         return _image;
51 }
52
53 - (NSString *)string
54 {
55         return [_text stringValue];
56 }
57
58 - (void)setImage:(NSImage *)image
59 {
60         [_image autorelease];
61         _image = [image retain];
62 }
63
64 - (void)setString:(NSString *)text
65 {
66         [_text setStringValue:text];
67 }
68
69 - (void)loadControlsFromPath:(NSString *)path
70 {
71         [_progress removeFromSuperview];
72         [_progress release];
73         [_text removeFromSuperview];
74         [_text release];
75         //Reset the controls
76         NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:path];
77         int height = [[settings objectForKey:@"ProgressIndicator.thickness"] intValue];
78         NSControlSize size;
79         switch (height) {
80                 /*case NSProgressIndicatorPreferredSmallThickness:
81                         size = NSMiniControlSize;
82                 break;*/
83                 case NSProgressIndicatorPreferredAquaThickness:
84                         size = NSSmallControlSize;
85                 break;
86                 case NSProgressIndicatorPreferredThickness:
87                 default:
88                         size = NSRegularControlSize;
89                 break;
90         }
91         if ([[settings objectForKey:@"ProgressIndicator.style"] intValue] == 0) {
92                 //We have a normal bar
93                 _progress = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect([[settings objectForKey:@"ProgressIndicator.x"] intValue], [[settings objectForKey:@"ProgressIndicator.y"] intValue], [[settings objectForKey:@"ProgressIndicator.size"] intValue], height)];
94                 [_progress setStyle:NSProgressIndicatorBarStyle];
95                 [_progress setControlSize:size];
96                 [_progress setIndeterminate:NO];
97                 [_progress setMaxValue:100.0];
98                 [_progress setMinValue:0.0];
99         } else {
100                 //We have a spinner thinger
101                 _progress = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect([[settings objectForKey:@"ProgressIndicator.x"] intValue], [[settings objectForKey:@"ProgressIndicator.y"] intValue], [[settings objectForKey:@"ProgressIndicator.size"] intValue], [[settings objectForKey:@"ProgressIndicator.size"] intValue])];
102                 [_progress setStyle:NSProgressIndicatorSpinningStyle];
103                 [_progress setControlSize:size];
104         }
105         [self addSubview:_progress];
106         [_progress startAnimation:nil];
107         
108         _text = [[NSTextField alloc] initWithFrame:NSMakeRect([[settings objectForKey:@"StatusText.x"] intValue], [[settings objectForKey:@"StatusText.y"] intValue], [[settings objectForKey:@"StatusText.width"] intValue], 22)];
109         [_text setEditable:NO];
110         [_text setSelectable:NO];
111         [_text setBezeled:NO];
112         [_text setDrawsBackground:NO];
113         [self addSubview:_text];
114         
115         [settings release];
116 }
117
118 @end