Annotation of chimera/SplashScreenWindow.m, revision 1.5

1.1       macserv     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: 
1.5     ! macserv    11: @interface SplashScreenWindow (Private)
        !            12: -(void)fadeIn;
        !            13: -(void)fadeInThread;
        !            14: -(void)fadeOut;
        !            15: -(void)fadeOutThread;
        !            16: @end
1.1       macserv    17: 
                     18: @implementation SplashScreenWindow
                     19: 
1.5     ! macserv    20: -(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect
1.1       macserv    21: {
                     22:     NSRect              splashRect;
1.2       macserv    23:     NSRect              statusFieldRect;
1.1       macserv    24:     NSImageView *contentImageView;
1.3       macserv    25: 
1.5     ! macserv    26:     _fadeDelay = (0.5 / 60.0);
        !            27: 
1.3       macserv    28:     if ( ! splashImage ) {
                     29:         if ( [NSImage imageNamed:@"splash"] ) {
                     30:             splashImage = [NSImage imageNamed:@"splash"];
                     31:         } else {
                     32:             splashImage = [NSImage imageNamed:@"NSApplicationIcon"];
                     33:         }
1.1       macserv    34:     }
                     35: 
1.3       macserv    36:     splashRect           = NSMakeRect(0.0, 0.0, [splashImage size].width, [splashImage size].height);
1.2       macserv    37:     statusFieldRect   = NSMakeRect(0.0, 170.0, (splashRect.size.width - 5.0), 16.0);
1.1       macserv    38:     contentImageView  = [[NSImageView alloc] initWithFrame:splashRect];
1.2       macserv    39:     _statusField      = [[NSTextField alloc] initWithFrame:statusFieldRect];
1.3       macserv    40: 
1.5     ! macserv    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];
1.1       macserv    65: 
1.5     ! macserv    66:         if ( shouldFade ) {
        !            67:             [self fadeIn];
        !            68:         } else {
        !            69:             [self makeKeyAndOrderFront:self];
        !            70:         }
        !            71:         __didFadeIn = shouldFade;
        !            72:     }
1.1       macserv    73:     return self;
                     74: }
                     75: 
1.3       macserv    76: -(NSString *)statusText
1.1       macserv    77: {
1.3       macserv    78:     return [_statusField stringValue];
1.2       macserv    79: }
                     80: 
                     81: -(void)setStatusText:(NSString *)newText
                     82: {
                     83:     [_statusField setStringValue:newText];
                     84:     [_statusField display];
1.1       macserv    85: }
                     86: 
1.5     ! macserv    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: }
1.1       macserv   156: 
                    157: -(void)dealloc
                    158: {
1.5     ! macserv   159:     if (_splashImage) {
1.1       macserv   160:         [_splashImage release];
1.5     ! macserv   161:     }
        !           162: 
        !           163:     [_fadeThreadLock release];
1.3       macserv   164: 
1.1       macserv   165:     [super dealloc];
                    166: }
                    167: 
                    168: @end

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