Re: NSView -drawRect optimization
Re: NSView -drawRect optimization
- Subject: Re: NSView -drawRect optimization
- From: Greg Titus <email@hidden>
- Date: Tue, 12 Feb 2008 14:39:14 -0800
Hi Paul,
Here are a couple of suggestions:
1) Create an OrderStepCell class, which represents the visible display
of a single OrderStep. Have it have a pointer to the OrderStep and the
rect that it draws in (i.e. it caches your OSRect value).
2) Only update that drawing rect for the cell when the OrderStep is
moved. Or update them all when your scale changes (the
pixelsPerSecond) or when enough time passes (1.0 / pixelsPerSecond = #
of seconds before the display changes by a single pixel). Use an
NSTimer for the latter.
3) When a cell moves, scale changes, or time passes, call -
updateTrackingAreas. Implement -updateTrackingAreas to
removeAllTooltips, and then create a tooltip for each order step.
Cocoa will also call -updateTrackingAreas whenever the view's geometry
changes such that tracking areas / cursor rects / tooltips need to be
updated. See the NSView documentation.
4) As a result of these changes, you should be able to remove the
computation of off-line time and the tooltip creation from your
drawing loop. You also shouldn't need to constantly redisplay - only
do it when your timer goes off or when order steps are being moved.
In short, most of your slowness here isn't really the drawing, it is
that you are doing a lot of computation during drawing that ought to
be done much less often.
Hope this helps!
- Greg
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden