• 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: fitting an NSBezierPath to a Rect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fitting an NSBezierPath to a Rect


  • Subject: Re: fitting an NSBezierPath to a Rect
  • From: b UND d <email@hidden>
  • Date: Thu, 16 Aug 2007 08:20:52 +0200


Am 15.08.2007 um 23:20 schrieb Alexander Cohen:

I'm trying to take an NSBezierPath that i did not create, and fit it in any rect and i need its bounds to start at 0,0. Here's some code i have but im not sure why this is not working. Can anyone help me out?

NSAffineTransform*	transform = [[NSAffineTransform alloc] init];
NSRect				bounds = [path bounds];
NSRect				viewRect = [view bounds];
float				ratio = 1.0;

// move the pat to (0,0)
[transform translateXBy:-bounds.origin.x yBy:-bounds.origin.y];

// get the ratio
ratio = MIN( viewRect.size.width/bounds.size.width, viewRect.size.height/bounds.size.height );


// scale by ratio
[transform scaleBy:ratio];

// set the transform
[path transformUsingAffineTransform:transform];

[transform release];

thanks
AC

I think it's only the translateBy line that should be moved to after the scaleBy:


NSAffineTransform*	transform = [[NSAffineTransform alloc] init];
NSRect				bounds = [path bounds];
NSRect				viewRect = [view bounds];
float				ratio = 1.0;

// get the ratio
ratio = MIN( viewRect.size.width/bounds.size.width, viewRect.size.height/bounds.size.height );


// scale by ratio
[transform scaleBy:ratio];

// move the pat to (0,0)
[transform translateXBy:-bounds.origin.x yBy:-bounds.origin.y];

// set the transform
[path transformUsingAffineTransform:transform];

[transform release];

Hope that helps

D.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: 
 >fitting an NSBezierPath to a Rect (From: Alexander Cohen <email@hidden>)

  • Prev by Date: Re: fitting an NSBezierPath to a Rect
  • Next by Date: NSString -drawWithRect:options:attributes
  • Previous by thread: Re: fitting an NSBezierPath to a Rect
  • Next by thread: NSColorPanel magnifying glass behavior
  • Index(es):
    • Date
    • Thread