Initial commit of splash screen. NPOB.

This commit is contained in:
hyatt%netscape.com 2002-04-20 02:23:05 +00:00
Родитель eb28a6f09e
Коммит b96912ac2e
12 изменённых файлов: 904 добавлений и 8 удалений

Просмотреть файл

@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Matt Judy.
*/
#import <Cocoa/Cocoa.h>
@interface CHSplashScreenWindow : NSWindow {
NSImage *_splashImage;
BOOL _fades;
BOOL __didFadeIn;
int _fadeIndex;
NSTimeInterval _fadeDelay;
id _fadeThreadLock;
NSTextField *_statusField;
}
// This method inits the window and displays it, slightly proud of center,
// and at the size of the image it displays.
//
// The splash method should be used in your main controller's init method
// in this fashion: splashWindow = [[SplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:someRect];
//
// Passing nil to splashImage will attempt to load [NSImage imageNamed:@"splash"] instead.
// If that fails, the app icon will be displayed.
//
// The window will release itself whenever you send it the close message.
-(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect;
-(NSString *)statusText;
-(void)setStatusText:(NSString *)newText;
@end

Просмотреть файл

@ -0,0 +1,178 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Matt Judy.
*
*/
#import "CHSplashScreenWindow.h"
@interface CHSplashScreenWindow (Private)
-(void)fadeIn;
-(void)fadeInThread;
-(void)fadeOut;
-(void)fadeOutThread;
@end
@implementation CHSplashScreenWindow
-(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect
{
NSRect splashRect;
NSRect statusFieldRect;
NSImageView *contentImageView;
_fadeDelay = (0.5 / 60.0);
if ( ! splashImage ) {
if ( [NSImage imageNamed:@"splash"] ) {
splashImage = [NSImage imageNamed:@"splash"];
} else {
splashImage = [NSImage imageNamed:@"NSApplicationIcon"];
}
}
splashRect = NSMakeRect(0.0, 0.0, [splashImage size].width, [splashImage size].height);
statusFieldRect = NSMakeRect(0.0, 170.0, (splashRect.size.width - 5.0), 16.0);
contentImageView = [[NSImageView alloc] initWithFrame:splashRect];
_statusField = [[NSTextField alloc] initWithFrame:statusFieldRect];
if ( (self = [super initWithContentRect:splashRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO]) ) {
[contentImageView setImage:splashImage];
_fadeThreadLock = nil;
[_statusField setDrawsBackground:NO];
[_statusField setEditable:NO];
[_statusField setSelectable:NO];
[_statusField setBezeled:NO];
[_statusField setBordered:NO];
[_statusField setFont:[NSFont fontWithName:@"Monaco" size:10.0]];
[_statusField setTextColor:[NSColor whiteColor]];
[_statusField setAlignment:NSRightTextAlignment];
[_statusField setStringValue:@"Loading..."];
[[self contentView] addSubview:contentImageView];
[[self contentView] addSubview:_statusField];
[self setOpaque:NO];
[self setHasShadow:YES];
[self setReleasedWhenClosed:YES];
[self center];
if ( shouldFade ) {
[self fadeIn];
} else {
[self makeKeyAndOrderFront:self];
}
__didFadeIn = shouldFade;
}
return self;
}
-(NSString *)statusText
{
return [_statusField stringValue];
}
-(void)setStatusText:(NSString *)newText
{
[_statusField setStringValue:newText];
[_statusField display];
}
-(void)fadeIn
{
[self setAlphaValue:0.0];
[self makeKeyAndOrderFront:self];
if (_fadeThreadLock == nil) {
_fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
}
[NSThread detachNewThreadSelector:@selector(fadeInThread) toTarget:self withObject:nil];
}
-(void)fadeInThread
{
float fadeLevel = 0.0;
NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
[_fadeThreadLock lock];
while ( fadeLevel < 1.0 ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
fadeLevel += 0.20;
[self setAlphaValue:fadeLevel];
[self flushWindow];
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]];
[pool release];
}
[_fadeThreadLock unlock];
[threadMainPool release];
}
-(void)fadeOut
{
if (_fadeThreadLock == nil) {
_fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
}
[NSThread detachNewThreadSelector:@selector(fadeOutThread) toTarget:self withObject:nil];
}
-(void)fadeOutThread
{
float fadeLevel = 1.0;
NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
[_fadeThreadLock lock];
while ( fadeLevel > 0.0 ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
fadeLevel -= 0.1;
[self setAlphaValue:fadeLevel];
[self flushWindow];
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]];
[pool release];
}
[_fadeThreadLock unlock];
[threadMainPool release];
}
-(void)close
{
// if ( __didFadeIn ) {
if ( NO ) { //Fade out is still problematic...
[self fadeOut];
}
[super close];
}
-(void)dealloc
{
if (_splashImage) {
[_splashImage release];
}
[_fadeThreadLock release];
[super dealloc];
}
@end

Просмотреть файл

@ -2079,12 +2079,12 @@
};
F5807369023A1514010001CA = {
isa = PBXFileReference;
path = SplashScreenWindow.h;
path = CHSplashScreenWindow.h;
refType = 4;
};
F580736A023A1514010001CA = {
isa = PBXFileReference;
path = SplashScreenWindow.m;
path = CHSplashScreenWindow.m;
refType = 4;
};
F580736B023A1514010001CA = {

Просмотреть файл

@ -2079,12 +2079,12 @@
};
F5807369023A1514010001CA = {
isa = PBXFileReference;
path = SplashScreenWindow.h;
path = CHSplashScreenWindow.h;
refType = 4;
};
F580736A023A1514010001CA = {
isa = PBXFileReference;
path = SplashScreenWindow.m;
path = CHSplashScreenWindow.m;
refType = 4;
};
F580736B023A1514010001CA = {

Просмотреть файл

@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Matt Judy.
*/
#import <Cocoa/Cocoa.h>
@interface CHSplashScreenWindow : NSWindow {
NSImage *_splashImage;
BOOL _fades;
BOOL __didFadeIn;
int _fadeIndex;
NSTimeInterval _fadeDelay;
id _fadeThreadLock;
NSTextField *_statusField;
}
// This method inits the window and displays it, slightly proud of center,
// and at the size of the image it displays.
//
// The splash method should be used in your main controller's init method
// in this fashion: splashWindow = [[SplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:someRect];
//
// Passing nil to splashImage will attempt to load [NSImage imageNamed:@"splash"] instead.
// If that fails, the app icon will be displayed.
//
// The window will release itself whenever you send it the close message.
-(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect;
-(NSString *)statusText;
-(void)setStatusText:(NSString *)newText;
@end

Просмотреть файл

@ -0,0 +1,178 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Matt Judy.
*
*/
#import "CHSplashScreenWindow.h"
@interface CHSplashScreenWindow (Private)
-(void)fadeIn;
-(void)fadeInThread;
-(void)fadeOut;
-(void)fadeOutThread;
@end
@implementation CHSplashScreenWindow
-(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect
{
NSRect splashRect;
NSRect statusFieldRect;
NSImageView *contentImageView;
_fadeDelay = (0.5 / 60.0);
if ( ! splashImage ) {
if ( [NSImage imageNamed:@"splash"] ) {
splashImage = [NSImage imageNamed:@"splash"];
} else {
splashImage = [NSImage imageNamed:@"NSApplicationIcon"];
}
}
splashRect = NSMakeRect(0.0, 0.0, [splashImage size].width, [splashImage size].height);
statusFieldRect = NSMakeRect(0.0, 170.0, (splashRect.size.width - 5.0), 16.0);
contentImageView = [[NSImageView alloc] initWithFrame:splashRect];
_statusField = [[NSTextField alloc] initWithFrame:statusFieldRect];
if ( (self = [super initWithContentRect:splashRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO]) ) {
[contentImageView setImage:splashImage];
_fadeThreadLock = nil;
[_statusField setDrawsBackground:NO];
[_statusField setEditable:NO];
[_statusField setSelectable:NO];
[_statusField setBezeled:NO];
[_statusField setBordered:NO];
[_statusField setFont:[NSFont fontWithName:@"Monaco" size:10.0]];
[_statusField setTextColor:[NSColor whiteColor]];
[_statusField setAlignment:NSRightTextAlignment];
[_statusField setStringValue:@"Loading..."];
[[self contentView] addSubview:contentImageView];
[[self contentView] addSubview:_statusField];
[self setOpaque:NO];
[self setHasShadow:YES];
[self setReleasedWhenClosed:YES];
[self center];
if ( shouldFade ) {
[self fadeIn];
} else {
[self makeKeyAndOrderFront:self];
}
__didFadeIn = shouldFade;
}
return self;
}
-(NSString *)statusText
{
return [_statusField stringValue];
}
-(void)setStatusText:(NSString *)newText
{
[_statusField setStringValue:newText];
[_statusField display];
}
-(void)fadeIn
{
[self setAlphaValue:0.0];
[self makeKeyAndOrderFront:self];
if (_fadeThreadLock == nil) {
_fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
}
[NSThread detachNewThreadSelector:@selector(fadeInThread) toTarget:self withObject:nil];
}
-(void)fadeInThread
{
float fadeLevel = 0.0;
NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
[_fadeThreadLock lock];
while ( fadeLevel < 1.0 ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
fadeLevel += 0.20;
[self setAlphaValue:fadeLevel];
[self flushWindow];
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]];
[pool release];
}
[_fadeThreadLock unlock];
[threadMainPool release];
}
-(void)fadeOut
{
if (_fadeThreadLock == nil) {
_fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
}
[NSThread detachNewThreadSelector:@selector(fadeOutThread) toTarget:self withObject:nil];
}
-(void)fadeOutThread
{
float fadeLevel = 1.0;
NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
[_fadeThreadLock lock];
while ( fadeLevel > 0.0 ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
fadeLevel -= 0.1;
[self setAlphaValue:fadeLevel];
[self flushWindow];
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]];
[pool release];
}
[_fadeThreadLock unlock];
[threadMainPool release];
}
-(void)close
{
// if ( __didFadeIn ) {
if ( NO ) { //Fade out is still problematic...
[self fadeOut];
}
[super close];
}
-(void)dealloc
{
if (_splashImage) {
[_splashImage release];
}
[_fadeThreadLock release];
[super dealloc];
}
@end

Просмотреть файл

@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Matt Judy.
*/
#import <Cocoa/Cocoa.h>
@interface CHSplashScreenWindow : NSWindow {
NSImage *_splashImage;
BOOL _fades;
BOOL __didFadeIn;
int _fadeIndex;
NSTimeInterval _fadeDelay;
id _fadeThreadLock;
NSTextField *_statusField;
}
// This method inits the window and displays it, slightly proud of center,
// and at the size of the image it displays.
//
// The splash method should be used in your main controller's init method
// in this fashion: splashWindow = [[SplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:someRect];
//
// Passing nil to splashImage will attempt to load [NSImage imageNamed:@"splash"] instead.
// If that fails, the app icon will be displayed.
//
// The window will release itself whenever you send it the close message.
-(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect;
-(NSString *)statusText;
-(void)setStatusText:(NSString *)newText;
@end

Просмотреть файл

@ -0,0 +1,178 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Matt Judy.
*
*/
#import "CHSplashScreenWindow.h"
@interface CHSplashScreenWindow (Private)
-(void)fadeIn;
-(void)fadeInThread;
-(void)fadeOut;
-(void)fadeOutThread;
@end
@implementation CHSplashScreenWindow
-(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect
{
NSRect splashRect;
NSRect statusFieldRect;
NSImageView *contentImageView;
_fadeDelay = (0.5 / 60.0);
if ( ! splashImage ) {
if ( [NSImage imageNamed:@"splash"] ) {
splashImage = [NSImage imageNamed:@"splash"];
} else {
splashImage = [NSImage imageNamed:@"NSApplicationIcon"];
}
}
splashRect = NSMakeRect(0.0, 0.0, [splashImage size].width, [splashImage size].height);
statusFieldRect = NSMakeRect(0.0, 170.0, (splashRect.size.width - 5.0), 16.0);
contentImageView = [[NSImageView alloc] initWithFrame:splashRect];
_statusField = [[NSTextField alloc] initWithFrame:statusFieldRect];
if ( (self = [super initWithContentRect:splashRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO]) ) {
[contentImageView setImage:splashImage];
_fadeThreadLock = nil;
[_statusField setDrawsBackground:NO];
[_statusField setEditable:NO];
[_statusField setSelectable:NO];
[_statusField setBezeled:NO];
[_statusField setBordered:NO];
[_statusField setFont:[NSFont fontWithName:@"Monaco" size:10.0]];
[_statusField setTextColor:[NSColor whiteColor]];
[_statusField setAlignment:NSRightTextAlignment];
[_statusField setStringValue:@"Loading..."];
[[self contentView] addSubview:contentImageView];
[[self contentView] addSubview:_statusField];
[self setOpaque:NO];
[self setHasShadow:YES];
[self setReleasedWhenClosed:YES];
[self center];
if ( shouldFade ) {
[self fadeIn];
} else {
[self makeKeyAndOrderFront:self];
}
__didFadeIn = shouldFade;
}
return self;
}
-(NSString *)statusText
{
return [_statusField stringValue];
}
-(void)setStatusText:(NSString *)newText
{
[_statusField setStringValue:newText];
[_statusField display];
}
-(void)fadeIn
{
[self setAlphaValue:0.0];
[self makeKeyAndOrderFront:self];
if (_fadeThreadLock == nil) {
_fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
}
[NSThread detachNewThreadSelector:@selector(fadeInThread) toTarget:self withObject:nil];
}
-(void)fadeInThread
{
float fadeLevel = 0.0;
NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
[_fadeThreadLock lock];
while ( fadeLevel < 1.0 ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
fadeLevel += 0.20;
[self setAlphaValue:fadeLevel];
[self flushWindow];
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]];
[pool release];
}
[_fadeThreadLock unlock];
[threadMainPool release];
}
-(void)fadeOut
{
if (_fadeThreadLock == nil) {
_fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
}
[NSThread detachNewThreadSelector:@selector(fadeOutThread) toTarget:self withObject:nil];
}
-(void)fadeOutThread
{
float fadeLevel = 1.0;
NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
[_fadeThreadLock lock];
while ( fadeLevel > 0.0 ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
fadeLevel -= 0.1;
[self setAlphaValue:fadeLevel];
[self flushWindow];
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]];
[pool release];
}
[_fadeThreadLock unlock];
[threadMainPool release];
}
-(void)close
{
// if ( __didFadeIn ) {
if ( NO ) { //Fade out is still problematic...
[self fadeOut];
}
[super close];
}
-(void)dealloc
{
if (_splashImage) {
[_splashImage release];
}
[_fadeThreadLock release];
[super dealloc];
}
@end

Просмотреть файл

@ -2079,12 +2079,12 @@
};
F5807369023A1514010001CA = {
isa = PBXFileReference;
path = SplashScreenWindow.h;
path = CHSplashScreenWindow.h;
refType = 4;
};
F580736A023A1514010001CA = {
isa = PBXFileReference;
path = SplashScreenWindow.m;
path = CHSplashScreenWindow.m;
refType = 4;
};
F580736B023A1514010001CA = {

Просмотреть файл

@ -2079,12 +2079,12 @@
};
F5807369023A1514010001CA = {
isa = PBXFileReference;
path = SplashScreenWindow.h;
path = CHSplashScreenWindow.h;
refType = 4;
};
F580736A023A1514010001CA = {
isa = PBXFileReference;
path = SplashScreenWindow.m;
path = CHSplashScreenWindow.m;
refType = 4;
};
F580736B023A1514010001CA = {

Просмотреть файл

@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Matt Judy.
*/
#import <Cocoa/Cocoa.h>
@interface CHSplashScreenWindow : NSWindow {
NSImage *_splashImage;
BOOL _fades;
BOOL __didFadeIn;
int _fadeIndex;
NSTimeInterval _fadeDelay;
id _fadeThreadLock;
NSTextField *_statusField;
}
// This method inits the window and displays it, slightly proud of center,
// and at the size of the image it displays.
//
// The splash method should be used in your main controller's init method
// in this fashion: splashWindow = [[SplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:someRect];
//
// Passing nil to splashImage will attempt to load [NSImage imageNamed:@"splash"] instead.
// If that fails, the app icon will be displayed.
//
// The window will release itself whenever you send it the close message.
-(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect;
-(NSString *)statusText;
-(void)setStatusText:(NSString *)newText;
@end

Просмотреть файл

@ -0,0 +1,178 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Matt Judy.
*
*/
#import "CHSplashScreenWindow.h"
@interface CHSplashScreenWindow (Private)
-(void)fadeIn;
-(void)fadeInThread;
-(void)fadeOut;
-(void)fadeOutThread;
@end
@implementation CHSplashScreenWindow
-(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect
{
NSRect splashRect;
NSRect statusFieldRect;
NSImageView *contentImageView;
_fadeDelay = (0.5 / 60.0);
if ( ! splashImage ) {
if ( [NSImage imageNamed:@"splash"] ) {
splashImage = [NSImage imageNamed:@"splash"];
} else {
splashImage = [NSImage imageNamed:@"NSApplicationIcon"];
}
}
splashRect = NSMakeRect(0.0, 0.0, [splashImage size].width, [splashImage size].height);
statusFieldRect = NSMakeRect(0.0, 170.0, (splashRect.size.width - 5.0), 16.0);
contentImageView = [[NSImageView alloc] initWithFrame:splashRect];
_statusField = [[NSTextField alloc] initWithFrame:statusFieldRect];
if ( (self = [super initWithContentRect:splashRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO]) ) {
[contentImageView setImage:splashImage];
_fadeThreadLock = nil;
[_statusField setDrawsBackground:NO];
[_statusField setEditable:NO];
[_statusField setSelectable:NO];
[_statusField setBezeled:NO];
[_statusField setBordered:NO];
[_statusField setFont:[NSFont fontWithName:@"Monaco" size:10.0]];
[_statusField setTextColor:[NSColor whiteColor]];
[_statusField setAlignment:NSRightTextAlignment];
[_statusField setStringValue:@"Loading..."];
[[self contentView] addSubview:contentImageView];
[[self contentView] addSubview:_statusField];
[self setOpaque:NO];
[self setHasShadow:YES];
[self setReleasedWhenClosed:YES];
[self center];
if ( shouldFade ) {
[self fadeIn];
} else {
[self makeKeyAndOrderFront:self];
}
__didFadeIn = shouldFade;
}
return self;
}
-(NSString *)statusText
{
return [_statusField stringValue];
}
-(void)setStatusText:(NSString *)newText
{
[_statusField setStringValue:newText];
[_statusField display];
}
-(void)fadeIn
{
[self setAlphaValue:0.0];
[self makeKeyAndOrderFront:self];
if (_fadeThreadLock == nil) {
_fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
}
[NSThread detachNewThreadSelector:@selector(fadeInThread) toTarget:self withObject:nil];
}
-(void)fadeInThread
{
float fadeLevel = 0.0;
NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
[_fadeThreadLock lock];
while ( fadeLevel < 1.0 ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
fadeLevel += 0.20;
[self setAlphaValue:fadeLevel];
[self flushWindow];
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]];
[pool release];
}
[_fadeThreadLock unlock];
[threadMainPool release];
}
-(void)fadeOut
{
if (_fadeThreadLock == nil) {
_fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
}
[NSThread detachNewThreadSelector:@selector(fadeOutThread) toTarget:self withObject:nil];
}
-(void)fadeOutThread
{
float fadeLevel = 1.0;
NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
[_fadeThreadLock lock];
while ( fadeLevel > 0.0 ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
fadeLevel -= 0.1;
[self setAlphaValue:fadeLevel];
[self flushWindow];
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]];
[pool release];
}
[_fadeThreadLock unlock];
[threadMainPool release];
}
-(void)close
{
// if ( __didFadeIn ) {
if ( NO ) { //Fade out is still problematic...
[self fadeOut];
}
[super close];
}
-(void)dealloc
{
if (_splashImage) {
[_splashImage release];
}
[_fadeThreadLock release];
[super dealloc];
}
@end