drawAtPoint - is it really slow?
drawAtPoint - is it really slow?
- Subject: drawAtPoint - is it really slow?
- From: John Nairn <email@hidden>
- Date: Wed, 28 Aug 2002 14:05:46 -0600
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];
}
----------------
John Nairn (1-801-581-3413, FAX: 1-801-581-4816)
Web page:
http://www.mse.utah.edu/~nairn
_______________________________________________
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.