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 (17 years, 5 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...

    1: //
    2: //  SplashScreenWindow.m
    3: //  Chimera
    4: //
    5: //  Created by Matt L.  Judy on Sat Mar 09 2002.
    6: //  Copyright (c) 2001 __MyCompanyName__. All rights reserved.
    7: //
    8: 
    9: #import "SplashScreenWindow.h"
   10: 
   11: @interface SplashScreenWindow (Private)
   12: -(void)fadeIn;
   13: -(void)fadeInThread;
   14: -(void)fadeOut;
   15: -(void)fadeOutThread;
   16: @end
   17: 
   18: @implementation SplashScreenWindow
   19: 
   20: -(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect
   21: {
   22:     NSRect		 splashRect;
   23:     NSRect		 statusFieldRect;
   24:     NSImageView *contentImageView;
   25: 
   26:     _fadeDelay = (0.5 / 60.0);
   27: 
   28:     if ( ! splashImage ) {
   29:         if ( [NSImage imageNamed:@"splash"] ) {
   30:             splashImage = [NSImage imageNamed:@"splash"];
   31:         } else {
   32:             splashImage = [NSImage imageNamed:@"NSApplicationIcon"];
   33:         }
   34:     }
   35: 
   36:     splashRect		  = NSMakeRect(0.0, 0.0, [splashImage size].width, [splashImage size].height);
   37:     statusFieldRect   = NSMakeRect(0.0, 170.0, (splashRect.size.width - 5.0), 16.0);
   38:     contentImageView  = [[NSImageView alloc] initWithFrame:splashRect];
   39:     _statusField      = [[NSTextField alloc] initWithFrame:statusFieldRect];
   40: 
   41:     if ( (self = [super initWithContentRect:splashRect
   42:                             styleMask:NSBorderlessWindowMask
   43:                               backing:NSBackingStoreBuffered
   44:                                 defer:NO]) ) {
   45: 
   46:         [contentImageView setImage:splashImage];
   47:         _fadeThreadLock = nil;
   48: 
   49:         [_statusField setDrawsBackground:NO];
   50:         [_statusField setEditable:NO];
   51:         [_statusField setSelectable:NO];
   52:         [_statusField setBezeled:NO];
   53:         [_statusField setBordered:NO];
   54:         [_statusField setFont:[NSFont fontWithName:@"Monaco" size:10.0]];
   55:         [_statusField setTextColor:[NSColor whiteColor]];
   56:         [_statusField setAlignment:NSRightTextAlignment];
   57:         [_statusField setStringValue:@"Loading..."];
   58: 
   59:         [[self contentView] addSubview:contentImageView];
   60:         [[self contentView] addSubview:_statusField];
   61:         [self setOpaque:NO];
   62:         [self setHasShadow:YES];
   63:         [self setReleasedWhenClosed:YES];
   64:         [self center];
   65: 
   66:         if ( shouldFade ) {
   67:             [self fadeIn];
   68:         } else {
   69:             [self makeKeyAndOrderFront:self];
   70:         }
   71:         __didFadeIn = shouldFade;
   72:     }
   73:     return self;
   74: }
   75: 
   76: -(NSString *)statusText
   77: {
   78:     return [_statusField stringValue];
   79: }
   80: 
   81: -(void)setStatusText:(NSString *)newText
   82: {
   83:     [_statusField setStringValue:newText];
   84:     [_statusField display];
   85: }
   86: 
   87: -(void)fadeIn
   88: {
   89:     [self setAlphaValue:0.0];
   90:     [self makeKeyAndOrderFront:self];
   91:     
   92:     if (_fadeThreadLock == nil) {
   93:         _fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
   94:     }
   95:     
   96:     [NSThread detachNewThreadSelector:@selector(fadeInThread) toTarget:self withObject:nil];
   97: }
   98: 
   99: -(void)fadeInThread
  100: {
  101:     float fadeLevel = 0.0;
  102:     NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
  103: 
  104:     [_fadeThreadLock lock];
  105: 
  106:     while ( fadeLevel < 1.0 ) {
  107:         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  108:         fadeLevel += 0.20;
  109:         [self setAlphaValue:fadeLevel];
  110:         [self flushWindow];
  111:         [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]];
  112:         [pool release];
  113:     }
  114: 
  115:     [_fadeThreadLock unlock];
  116:     [threadMainPool release];
  117: }
  118: 
  119: -(void)fadeOut
  120: {
  121:     if (_fadeThreadLock == nil) {
  122:         _fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
  123:     }
  124: 
  125:     [NSThread detachNewThreadSelector:@selector(fadeOutThread) toTarget:self withObject:nil];
  126: }
  127: 
  128: -(void)fadeOutThread
  129: {
  130:     float fadeLevel = 1.0;
  131:     NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
  132: 
  133:     [_fadeThreadLock lock];
  134: 
  135:     while ( fadeLevel > 0.0 ) {
  136:         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  137:         fadeLevel -= 0.1;
  138:         [self setAlphaValue:fadeLevel];
  139:         [self flushWindow];
  140:         [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]];
  141:         [pool release];
  142:     }
  143: 
  144:     [_fadeThreadLock unlock];
  145:     [threadMainPool release];
  146: }
  147: 
  148: -(void)close
  149: {
  150: //  if ( __didFadeIn ) {
  151:     if (      NO     ) { //Fade out is still problematic...
  152:         [self fadeOut];
  153:     }
  154:     [super close];
  155: }
  156: 
  157: -(void)dealloc
  158: {
  159:     if (_splashImage) {
  160:         [_splashImage release];
  161:     }
  162: 
  163:     [_fadeThreadLock release];
  164: 
  165:     [super dealloc];
  166: }
  167: 
  168: @end

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