Re: "fixed" line width?
Re: "fixed" line width?
- Subject: Re: "fixed" line width?
- From: "R. Matthew Emerson" <email@hidden>
- Date: Fri, 22 Dec 2006 11:02:20 -0500
On Dec 21, 2006, at 4:31 PM, Stefan Wolfrum wrote:
Unfortunately (in my case) the linewidth of a NSBezierPath
scales with the coordinate system of the view.
I'm writing some kind of graphical mathematical application
and am drawing (complex) function graphs. I nee the line
width of the path to be constant (let's say one, two, three
SCREEN PIXELS) rather than scaled with the bounds of
the view rect.
So is there a way to calculate an always-the-pixel linewidth
value for given view bounds?
or how can I achieve my goal?
Instead of scaling the view's coordinate system, maintain your own
transformation separately.
In other words, create an NSAffineTransform and set it up
appropriately, e.g.,
- (void)configureTransform
{
NSAffineTransform *transform = [NSAffineTransform transform];
NSRect r = [self plotRect];
float xs = r.size.width/([self maxX] - [self minX]);
float ys = r.size.height/([self maxY] - [self minY]);
[transform translateXBy:r.origin.x yBy:r.origin.y];
[transform scaleXBy:xs yBy:ys];
[transform translateXBy:-[self minX] yBy:-[self minY]];
[self setCurrentTransform:transform];
}
Now, in your view's -drawRect: method, create your path in the
coordinate system you just set up.
When you've finished with the path, say [path
transformUsingAffineTransform:transform], and then stroke it (using
whatever path attributes, like line width, that you want).
There's a section in Gelphman and Laden that explains this in more
detail.
http://www.amazon.com/exec/obidos/tg/detail/-/0123694736
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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