File:  [mozdev] / chimera / SplashScreenWindow.m
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Sat Apr 20 00:44:56 2002 UTC (15 years, 6 months ago) by macserv
Branches: MAIN
CVS tags: HEAD
A bunch of tweaks here... no changes in functionality.  Updated trilicense header on all files that were missing it.  Fixed initialization code syntax errors all over the place.  Put back fade code, and switched fading off for now...

//
//  SplashScreenWindow.m
//  Chimera
//
//  Created by Matt L.  Judy on Sat Mar 09 2002.
//  Copyright (c) 2001 __MyCompanyName__. All rights reserved.
//

#import "SplashScreenWindow.h"

@interface SplashScreenWindow (Private)
-(void)fadeIn;
-(void)fadeInThread;
-(void)fadeOut;
-(void)fadeOutThread;
@end

@implementation SplashScreenWindow

-(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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>