Smooth scrolling
Smooth scrolling
- Subject: Smooth scrolling
- From: Amar Sagoo <email@hidden>
- Date: Sun, 24 Oct 2004 19:25:06 +0100
Hi,
I am trying to implement smooth scrolling in a custom NSScrollView, like what you get in text views in Panther if you choose "Use smooth scrolling" in the Appearance preference pane. Or like in the Finder's column view.
I couldn't find a way to make this work automatically, so I implemented my own method. However, it's a little bit choppy on a Dual 867 MHz PowerMac G4. It redraws only 3 times over a 150ms period. No where near as smooth as the OS-provided animation.
So I'm wondering if there is a way to
a) Improve my algorithm
b) Make use of the system-provided animation.
OmniWeb added support for this system setting after Panther came out, but I don't know if they implemented their own animation technique or found a way to use the system's.
Here's the code I use at the moment (my view only ever scrolls horizontally):
- (void)scrollBy:(float)delta animate:(BOOL)animate
{
const double ANIMATION_DURATION = 0.15;
NSPoint oldOrigin = [self documentVisibleRect].origin;
NSPoint newOrigin = [[self contentView] constrainScrollPoint:NSMakePoint(oldOrigin.x + delta, oldOrigin.y)];
float actualDelta = newOrigin.x - oldOrigin.x;
if (animate)
{
NSDate *startTime = [NSDate date];
double secondsPassed = 0;
while (secondsPassed < ANIMATION_DURATION)
{
if (secondsPassed > 0)
{
[[self documentView] scrollPoint:
NSMakePoint(secondsPassed / ANIMATION_DURATION * actualDelta + oldOrigin.x,
newOrigin.y)];
}
[self display];
secondsPassed = -[startTime timeIntervalSinceNow];
}
}
[[self documentView] scrollPoint:newOrigin];
}
Any ideas are welcome!
Thanks
Amar
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden