File:  [mozdev] / chimera / AboutBox.m
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Sun Mar 10 07:36:38 2002 UTC (17 years, 7 months ago) by macserv
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

    1: #import "AboutBox.h"
    2: 
    3: @implementation AboutBox
    4: 
    5: static AboutBox *sharedInstance = nil;
    6: 
    7: + (AboutBox *)sharedInstance
    8: {
    9:     return sharedInstance ? sharedInstance : [[self alloc] init];
   10: }
   11: 
   12: - (id)init
   13: {
   14:     if (sharedInstance) {
   15:         [self dealloc];
   16:     } else {
   17:         sharedInstance = [super init];
   18:     }
   19:         return sharedInstance;
   20: }
   21: 
   22: - (IBAction)showPanel:(id)sender
   23: {
   24:     if (!creditsField) {
   25:         NSString *creditsPath;
   26:         NSAttributedString *creditsString;
   27:         float fieldHeight;
   28:         float containerHeight;
   29: 
   30:         if (![NSBundle loadNibNamed:@"AboutBox" owner:self]) {
   31:             NSLog( @"Failed to load AboutBox.nib" );
   32:             NSBeep();
   33:             return;
   34:         }
   35: 
   36:         [window setTitle:@"About Navigator"];
   37: 
   38:         creditsPath = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"];
   39:         creditsString = [[NSAttributedString alloc] initWithPath:creditsPath documentAttributes:nil];
   40:         [creditsField replaceCharactersInRange:NSMakeRange( 0, 0 )
   41:                                        withRTF:[creditsString RTFFromRange:
   42:                                            NSMakeRange( 0, [creditsString length] )
   43:                                                         documentAttributes:nil]];
   44: 
   45:         fieldHeight = [creditsField frame].size.height;
   46:         
   47:         (void)[[creditsField layoutManager] glyphRangeForTextContainer:[creditsField textContainer]];
   48:         containerHeight = [[creditsField layoutManager] usedRectForTextContainer:
   49:                                                           [creditsField textContainer]].size.height;
   50:         maxScrollHeight = containerHeight - fieldHeight;
   51:         
   52:         [window setExcludedFromWindowsMenu:YES];
   53:         [window setMenu:nil];
   54:         [window center];
   55:     }
   56:     
   57:     if (![window isVisible]) {
   58:                 currentPosition = 0;
   59:                 restartAtTop = NO;
   60:                 startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0;
   61:                 [creditsField scrollPoint:NSMakePoint( 0, 0 )];
   62:     }
   63: 
   64:     [window makeKeyAndOrderFront:nil];
   65: }
   66: 
   67: - (void)windowDidBecomeKey:(NSNotification *)notification
   68: {
   69:     scrollTimer = [NSTimer scheduledTimerWithTimeInterval:1/4
   70:                                                    target:self
   71:                                                  selector:@selector(scrollCredits:)
   72:                                                  userInfo:nil
   73:                                                   repeats:YES];
   74: }
   75: 
   76: - (void)windowDidResignKey:(NSNotification *)notification
   77: {
   78:     [scrollTimer invalidate];
   79: }
   80: 
   81: - (void)scrollCredits:(NSTimer *)timer
   82: {
   83:     if ([NSDate timeIntervalSinceReferenceDate] >= startTime) {
   84: 
   85:         if (restartAtTop) {
   86:             startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0;
   87:             restartAtTop = NO;
   88:             [creditsField scrollPoint:NSMakePoint( 0, 0 )];
   89:             return;
   90:         }
   91: 
   92:         if (currentPosition >= maxScrollHeight) {
   93:             startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0;
   94:             currentPosition = 0;
   95:             restartAtTop = YES;
   96:         } else {
   97:             [creditsField scrollPoint:NSMakePoint( 0, currentPosition )];
   98:             currentPosition += 0.01;
   99:         }
  100:     }
  101: }
  102: 
  103: @end

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