Annotation of chimera/SplashScreenWindow.m, revision 1.3

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.3     ! 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.3     ! 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: 
        !            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:         }
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.1       macserv    41:     [self initWithContentRect:splashRect
                     42:                     styleMask:NSBorderlessWindowMask
                     43:                       backing:NSBackingStoreBuffered
                     44:                         defer:NO];
1.3     ! macserv    45:         
        !            46:     [contentImageView setImage:splashImage];
        !            47:     _fadeThreadLock = nil;
1.2       macserv    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];
1.3     ! macserv    61:     [self setOpaque:NO];
1.1       macserv    62:     [self setHasShadow:YES];
                     63:     [self setReleasedWhenClosed:YES];
                     64:     [self center];
                     65:     
1.3     ! macserv    66:     if ( shouldFade ) {
1.1       macserv    67:         [self fadeIn];
                     68:     } else {
                     69:         [self makeKeyAndOrderFront:self];
                     70:     }
1.3     ! macserv    71:     __didFadeIn = shouldFade;
1.1       macserv    72: 
                     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: 
                     87: -(void)fadeIn
                     88: {
1.3     ! macserv    89:     [self setAlphaValue:0.0];
1.1       macserv    90:     [self makeKeyAndOrderFront:self];
1.3     ! macserv    91:     
        !            92:     if (_fadeThreadLock == nil) {
        !            93:         _fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
1.1       macserv    94:     }
1.3     ! macserv    95:     
        !            96:     [NSThread detachNewThreadSelector:@selector(fadeInThread) toTarget:self withObject:nil];
1.1       macserv    97: }
                     98: 
1.3     ! macserv    99: -(void)fadeInThread
1.1       macserv   100: {
1.3     ! macserv   101:     float fadeLevel = 0.0;
        !           102:     NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
        !           103: 
        !           104:     [_fadeThreadLock lock];
1.1       macserv   105: 
1.3     ! macserv   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];
1.1       macserv   113:     }
1.3     ! macserv   114: 
        !           115:     [_fadeThreadLock unlock];
        !           116:     [threadMainPool release];
1.1       macserv   117: }
                    118: 
                    119: -(void)fadeOut
                    120: {
1.3     ! macserv   121:     if (_fadeThreadLock == nil) {
        !           122:         _fadeThreadLock = [[NSLock allocWithZone:[self zone]] init];
1.1       macserv   123:     }
1.3     ! macserv   124: 
        !           125:     [NSThread detachNewThreadSelector:@selector(fadeOutThread) toTarget:self withObject:nil];
1.1       macserv   126: }
                    127: 
1.3     ! macserv   128: -(void)fadeOutThread
1.1       macserv   129: {
1.3     ! macserv   130:     float fadeLevel = 1.0;
        !           131:     NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init];
        !           132: 
        !           133:     [_fadeThreadLock lock];
1.1       macserv   134: 
1.3     ! macserv   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];
1.1       macserv   142:     }
1.3     ! macserv   143: 
        !           144:     [_fadeThreadLock unlock];
        !           145:     [threadMainPool release];
1.1       macserv   146: }
                    147: 
                    148: -(void)close
                    149: {
1.3     ! macserv   150: //  if ( __didFadeIn ) {
        !           151:     if (      NO     ) { //Fade out is still problematic...
1.1       macserv   152:         [self fadeOut];
                    153:     }
                    154:     [super close];
                    155: }
                    156: 
                    157: -(void)dealloc
                    158: {
                    159:     if (_splashImage) {
                    160:         [_splashImage release];
                    161:     }
1.3     ! macserv   162: 
        !           163:     [_fadeThreadLock release];
        !           164: 
1.1       macserv   165:     [super dealloc];
                    166: }
                    167: 
                    168: 
                    169: @end

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