Hi guys,

I'd just like to give you some final feedback, how I was able to solve my 
problem, drawing a view with some thousand paths in a slow-motion. You all have 
contributed to this approach, which is a mixture of your suggestions, and works 
pretty well so far.

The basic idea: 

1. make the drawing object able to draw only a part of all paths. Therefore I 
introduced an NSRange property, which reflects by default all paths
2. use a timer to step through the paths in small portions for each animations 
step and trigger drawRect: (I skipped the timer and use "performSelector")
3. As the previous drawing is still visible, it's not necessary to draw from 
the 1st path with every animation step
4. to avoid a corrupted display, I handle resizing (or changed view options) 
with a complete redraw

For those who are interested I attached some code fragments of the related 
NSView object.

Thanks again for your support!
Matthias

NSView:

- (void)startAnimation
{
        [design setDisplayRange:NSMakeRange(0, 0)];
        [self setAnimationStep:15];
        [self setAnimationDelay:0.1];
        [self nextAnimationStep:nil];
}

- (void)pauseAnimation
{
        [NSObject cancelPreviousPerformRequestsWithTarget:self];
}

- (void)resumeAnimation
{
        [self nextAnimationStep:nil];
}

- (void)stopAnimation
{
        [design setDisplayRange:NSMakeRange(0, [[design stitches] count])];
        [NSObject cancelPreviousPerformRequestsWithTarget:self];
        [self setNeedsDisplay:YES];
}

- (void)nextAnimationStep:(NSTimer *)sender
{
        NSRange displayRange = [design displayRange];
        displayRange.location += displayRange.length;
        displayRange.length = [self animationStep];

        if ((displayRange.location + displayRange.length) >= [design 
numberOfStitches])
        {
                [self stopAnimation];
        }
        else
        {
                [design setDisplayRange:displayRange];
                [self performSelector:@selector(nextAnimationStep:) 
withObject:nil afterDelay:[self animationDelay]];
                
                [self setNeedsDisplay:YES];
        }
}

- (void)setFrame:(NSRect)frameRect
{
        [super setFrame:frameRect];

        BOOL animationActive = ([design displayRange].location != 0); 
        if (animationActive)
        {
                NSRange displayRange = [design displayRange];
                [design setDisplayRange:NSMakeRange(0, displayRange.location + 
displayRange.length)]; 
        }
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to