Skip navigation.
 
mlRe: NSView -drawRect optimization
FROM : Greg Titus
DATE : Tue Feb 12 23:39:14 2008

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

Related mailsAuthorDate
mlNSView -drawRect optimization Paul Bruneau Feb 12, 23:02
mlRe: NSView -drawRect optimization John Stiles Feb 12, 23:17
mlRe: NSView -drawRect optimization Peter Ammon Feb 12, 23:31
mlRe: NSView -drawRect optimization Greg Titus Feb 12, 23:39
mlRe: NSView -drawRect optimization Graham Feb 12, 23:49
mlRe: NSView -drawRect optimization Erik Buck Feb 13, 00:51
mlRe: NSView -drawRect optimization Paul Bruneau Feb 13, 14:22
mlRe: NSView -drawRect optimization Paul Bruneau Feb 13, 14:22
mlRe: NSView -drawRect optimization John Stiles Feb 13, 18:41
mlRe: NSView -drawRect optimization Paul Bruneau Feb 14, 14:47
mlRe: NSView -drawRect optimization Paul Bruneau Feb 14, 15:13
mlRe: NSView -drawRect optimization Paul Bruneau Feb 14, 15:26
mlRe: NSView -drawRect optimization Kyle Sluder Feb 14, 16:43