Re: drawAtPoint - is it really slow?
Re: drawAtPoint - is it really slow?
- Subject: Re: drawAtPoint - is it really slow?
- From: Macguy84 <email@hidden>
- Date: Wed, 28 Aug 2002 15:00:28 -0700
Have you tried rendering the text onto an NSImage first? Quartz Text
Rendering onscreen is intolerably slow in the first place, but if you
draw to an NSImage first, drawing goes much much faster. You can then
use NSImage's drawAtPoint: method. Maybe you're already doing this
though with your graphicsContext/saveGraphicsState code, I could be
wrong -- I've never worked with those calls.
Good luck,
Tristan
On Wed, 28 Aug 2002 14:05:46, John Nairn <email@hidden>
wrote:
I initially had trouble drawing a label at a point when the view had
scaled bounds. From the archives of this group I got it working by
applying an NSAffineTransformation (code below) before drawing the
string using pixel dimensions.
But it appears to be very slow. In one example, I label 300 points and
scrolling and resizing are intolerable slow. When I did the same thing
in Carbon (with 300 DrawString() calls) it was much (much) faster.
The question is:
Is drawAtPoint inherently slow, or does it depend on the current
transformations and maybe only slows down when the view bounds do not
correspond to actual pixels?
Here is code to paint the label. I am sure it is drawAtPoint that is
slow because commenting it out (which gives no labels) makes it all
fast again. In other words, it is the label drawing itself, and not
other overhead associated with transformations, that is slow.
// use tranformations to center a label on a point and optionally
rotate it
// the attributes in attr are predefined and set using pixel dimensions
// pixel gives size of one real pixel in this view's coordinates
-(void)paintLabel:(NSString *)aLabel angle:(float)anAngle x:(float)anX
y:(float)anY
{
NSGraphicsContext *gc;
NSAffineTransform *t=[NSAffineTransform transform];
NSSize size;
gc=[NSGraphicsContext currentContext];
[gc saveGraphicsState];
[t translateXBy:anX yBy:anY ];
[t rotateByDegrees:anAngle];
[t scaleBy:pixel];
[t concat];
size=[aLabel sizeWithAttributes:attr];
[aLabel drawAtPoint:NSMakePoint(-size.width/2.,-size.height/2.)
withAttributes:attr];
[gc restoreGraphicsState];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.