File:  [mozdev] / chimera / SplashScreenWindow.m
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Wed Mar 20 10:24:50 2002 UTC (17 years, 7 months ago) by macserv
Branches: MAIN
CVS tags: HEAD
Adding status text to the splash screen, as well as a simple method to set that text.

    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: 
   12: @implementation SplashScreenWindow
   13: 
   14: -(id)splash;
   15: {
   16:     NSRect		 splashRect;
   17:     NSRect		 statusFieldRect;
   18:     NSImageView *contentImageView;
   19:     
   20:     if ( ! [self splashImage] ) {
   21:         [self setSplashImage:[NSImage imageNamed:@"splash"]];
   22:     }
   23: 
   24:     splashRect		  = NSMakeRect(0.0, 0.0, [[self splashImage] size].width, [[self splashImage] size].height);
   25:     statusFieldRect   = NSMakeRect(0.0, 170.0, (splashRect.size.width - 5.0), 16.0);
   26:     contentImageView  = [[NSImageView alloc] initWithFrame:splashRect];
   27:     _statusField      = [[NSTextField alloc] initWithFrame:statusFieldRect];
   28:     
   29:     [self initWithContentRect:splashRect
   30:                     styleMask:NSBorderlessWindowMask
   31:                       backing:NSBackingStoreBuffered
   32:                         defer:NO];
   33:     
   34:     [contentImageView setImage:[self splashImage]];
   35: 
   36:     [_statusField setDrawsBackground:NO];
   37:     [_statusField setEditable:NO];
   38:     [_statusField setSelectable:NO];
   39:     [_statusField setBezeled:NO];
   40:     [_statusField setBordered:NO];
   41:     [_statusField setFont:[NSFont fontWithName:@"Monaco" size:10.0]];
   42:     [_statusField setTextColor:[NSColor whiteColor]];
   43:     [_statusField setAlignment:NSRightTextAlignment];
   44:     [_statusField setStringValue:@"Loading..."];
   45: 
   46:     [[self contentView] addSubview:contentImageView];
   47:     [[self contentView] addSubview:_statusField];
   48:     [self setHasShadow:YES];
   49:     [self setReleasedWhenClosed:YES];
   50:     [self center];
   51:     
   52:     if ( [self fades] ) {
   53:         [self fadeIn];
   54:     } else {
   55:         [self makeKeyAndOrderFront:self];
   56:     }
   57: 
   58:     return self;
   59: }
   60: 
   61: -(BOOL)fades
   62: {
   63:     return _fades;
   64: }
   65: 
   66: -(void)setFades:(BOOL)fadeFlag;
   67: {
   68:     _fades = fadeFlag;
   69: }
   70: 
   71: -(NSImage *)splashImage
   72: {
   73:     return _splashImage;
   74: }
   75: 
   76: -(void)setSplashImage:(NSImage *)newImage;
   77: {
   78:     [_splashImage autorelease];
   79:     _splashImage = [newImage copy];
   80: }
   81: 
   82: -(void)setStatusText:(NSString *)newText
   83: {
   84:     [_statusField setStringValue:newText];
   85:     [_statusField display];
   86: }
   87: 
   88: -(void)fadeIn
   89: {
   90:     [self setAlphaValue:0.5];
   91:     [self makeKeyAndOrderFront:self];
   92: 
   93:     if (!_fadeTimer) {
   94:         _fadeTimer = [NSTimer scheduledTimerWithTimeInterval:.10
   95:                                                       target:self
   96:                                                     selector:@selector(fadeStepUp:)
   97:                                                     userInfo:nil
   98:                                                      repeats:YES];
   99:     }
  100: }
  101: 
  102: -(void)fadeStepUp:(NSTimer *)aTimer
  103: {
  104:     NSLog(@"Fade up");
  105:     [self setAlphaValue:([self alphaValue] + 0.05)];
  106: 
  107:     if ( [self alphaValue] == 1.0 ) {
  108:         [_fadeTimer invalidate];
  109:     }
  110: }
  111: 
  112: -(void)fadeOut
  113: {
  114:     if (!_fadeTimer) {
  115:         _fadeTimer = [NSTimer scheduledTimerWithTimeInterval:.10
  116:                                                       target:self
  117:                                                     selector:@selector(fadeStepDown:)
  118:                                                     userInfo:nil
  119:                                                      repeats:YES];
  120:     }
  121: }
  122: 
  123: -(void)fadeStepDown:(NSTimer *)aTimer
  124: {
  125:     [self setAlphaValue:([self alphaValue] - 0.05)];
  126: 
  127:     if ( [self alphaValue] == 0.0 ) {
  128:         [_fadeTimer invalidate];
  129:     }
  130: }
  131: 
  132: -(void)close
  133: {
  134:     if ( [self fades] ) {
  135:         [self fadeOut];
  136:     }
  137:     [super close];
  138: }
  139: 
  140: -(void)dealloc
  141: {
  142:     if (_splashImage) {
  143:         [_splashImage release];
  144:     }
  145:     [super dealloc];
  146: }
  147: 
  148: 
  149: @end

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