• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "fixed" line width?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "fixed" line width?


  • Subject: Re: "fixed" line width?
  • From: Stefan Wolfrum <email@hidden>
  • Date: Sat, 23 Dec 2006 11:59:42 +0100 (MET)

Hi Matthew,

cool! Understood! Will try soon (after the xmas hectic...) ;-)

Thanks a LOT! So great to learn something new about Cocoa every day!

Merry Xmas to all!
Stefan.

Am 22.12.2006 um 17:02 schrieb R. Matthew Emerson:


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

_______________________________________________

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


References: 
 >"fixed" line width? (From: Stefan Wolfrum <email@hidden>)
 >Re: "fixed" line width? (From: "R. Matthew Emerson" <email@hidden>)

  • Prev by Date: Re: Build doesn't update help
  • Next by Date: Re: Delegates -- WHAT is delegated?
  • Previous by thread: Re: "fixed" line width?
  • Next by thread: crashes
  • Index(es):
    • Date
    • Thread