• 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: Transform not quite right
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Transform not quite right


  • Subject: Re: Transform not quite right
  • From: "R. Matthew Emerson" <email@hidden>
  • Date: Sat, 30 Jun 2007 11:39:22 -0400


On Jun 30, 2007, at 3:49 AM, David Arnold wrote:
I am very new to cocoa and I am trying to map my user space to an NSView object. I am almost success, but for some reason, I am not getting the translation upward that I need so the the entire sine curve will fit in the window. I feel I am missing something fundamental. Can anyone help?


- (void)drawRect:(NSRect)rect { float xmin = 0.0; float xmax = 2*pi; float ymin = -2.0; float ymax = 2.0; float numPoints = 200; float x = xmin; float dx = (xmax-xmin)/numPoints; float y;

	[[NSColor grayColor] set];
	NSRectFill(rect);

NSAffineTransform *xForm = [NSAffineTransform transform];
[xForm translateXBy:-xmin yBy:-ymin];
[xForm scaleXBy:(rect.size.width/(xmax-xmin)) yBy: (rect.size.height/(ymax-ymin))];
// [xForm translateXBy:rect.origin.x yBy:rect.origin.y];

Looks like your translations are done in the wrong order. Also, note the passed in rect includes only the invalidated portions of your view, so you'll want to refer to the view's bounds rect directly.


NSRect r = NSInsetRect([self bounds], 5, 5); /* add some margin around the plotted area */

/* snippet from working code */

    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]];

_______________________________________________

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


  • Follow-Ups:
    • Re: Transform not quite right
      • From: David Arnold <email@hidden>
References: 
 >Transform not quite right (From: David Arnold <email@hidden>)

  • Prev by Date: Re: Hide NSMenuItem
  • Next by Date: Re: [SOLVED] bindings with two interdependent NSPopupButtons
  • Previous by thread: Transform not quite right
  • Next by thread: Re: Transform not quite right
  • Index(es):
    • Date
    • Thread