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 (15 years, 8 months ago) by macserv
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

#import "AboutBox.h"

@implementation AboutBox

static AboutBox *sharedInstance = nil;

+ (AboutBox *)sharedInstance
{
    return sharedInstance ? sharedInstance : [[self alloc] init];
}

- (id)init
{
    if (sharedInstance) {
        [self dealloc];
    } else {
        sharedInstance = [super init];
    }
        return sharedInstance;
}

- (IBAction)showPanel:(id)sender
{
    if (!creditsField) {
        NSString *creditsPath;
        NSAttributedString *creditsString;
        float fieldHeight;
        float containerHeight;

        if (![NSBundle loadNibNamed:@"AboutBox" owner:self]) {
            NSLog( @"Failed to load AboutBox.nib" );
            NSBeep();
            return;
        }

        [window setTitle:@"About Navigator"];

        creditsPath = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"];
        creditsString = [[NSAttributedString alloc] initWithPath:creditsPath documentAttributes:nil];
        [creditsField replaceCharactersInRange:NSMakeRange( 0, 0 )
                                       withRTF:[creditsString RTFFromRange:
                                           NSMakeRange( 0, [creditsString length] )
                                                        documentAttributes:nil]];

        fieldHeight = [creditsField frame].size.height;
        
        (void)[[creditsField layoutManager] glyphRangeForTextContainer:[creditsField textContainer]];
        containerHeight = [[creditsField layoutManager] usedRectForTextContainer:
                                                          [creditsField textContainer]].size.height;
        maxScrollHeight = containerHeight - fieldHeight;
        
        [window setExcludedFromWindowsMenu:YES];
        [window setMenu:nil];
        [window center];
    }
    
    if (![window isVisible]) {
                currentPosition = 0;
                restartAtTop = NO;
                startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0;
                [creditsField scrollPoint:NSMakePoint( 0, 0 )];
    }

    [window makeKeyAndOrderFront:nil];
}

- (void)windowDidBecomeKey:(NSNotification *)notification
{
    scrollTimer = [NSTimer scheduledTimerWithTimeInterval:1/4
                                                   target:self
                                                 selector:@selector(scrollCredits:)
                                                 userInfo:nil
                                                  repeats:YES];
}

- (void)windowDidResignKey:(NSNotification *)notification
{
    [scrollTimer invalidate];
}

- (void)scrollCredits:(NSTimer *)timer
{
    if ([NSDate timeIntervalSinceReferenceDate] >= startTime) {

        if (restartAtTop) {
            startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0;
            restartAtTop = NO;
            [creditsField scrollPoint:NSMakePoint( 0, 0 )];
            return;
        }

        if (currentPosition >= maxScrollHeight) {
            startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0;
            currentPosition = 0;
            restartAtTop = YES;
        } else {
            [creditsField scrollPoint:NSMakePoint( 0, currentPosition )];
            currentPosition += 0.01;
        }
    }
}

@end

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