Fastest way to push strings to the screen in an NSView?
Fastest way to push strings to the screen in an NSView?
- Subject: Fastest way to push strings to the screen in an NSView?
- From: Scott Ellsworth <email@hidden>
- Date: Wed, 17 Nov 2004 18:08:10 -0800
Hi, all.
Roughly half the time my program takes is spent drawing attributed
strings to the screen, according to Shark. This surprises me, as there
are no more than 1200 on the screen at once, though they are drawn at a
variety of locations. The attributes are not complicated, either.
I build my attribute dict only once in the program execution with:
hexFontSize=12.0f;
attributesForRegion = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont userFontOfSize:hexFontSize],
NSFontAttributeName,
nil];
Then I call the following method about 1.2k times, interleaved with
pushing a few graphics to the screen as well:
- (void) drawString:(NSString *)string inRegion:(Region) theRegion{
if (string != nil){
NSDictionary * attributesForRegion=[self
attributesForRegion:theRegion];
NSAttributedString * attributedString=[[NSAttributedString alloc]
initWithString:string attributes:attributesForRegion];
NSSize size=[attributedString size];
NSPoint basePoint = [self pointForRegion:theRegion];
NSRect r=NSMakeRect(basePoint.x-size.width/2, basePoint.y,
size.width, size.height);
[attributedString drawInRect: r];
[attributedString release];
}
}
attributesForRegion always returns the above dictionary of attributes,
and pointForRegion is a fast integer calculation.
drawAtPoint:withAttributes: seemed about the same speed, and adds the
complexity of trying to justify the result.
This is on Panther 10.3.6, running on my AlBook/1.5GHz.
NB - documentation refs, google URLs, and other pointers to info are
fine - I tried a number of searches first, but did not find anything
obvious.
Scott
_______________________________________________
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