• 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: Yet another NSAffineTransform problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Yet another NSAffineTransform problem


  • Subject: Re: Yet another NSAffineTransform problem
  • From: John Pannell <email@hidden>
  • Date: Wed, 11 Jan 2006 18:32:50 -0700

Hi there-

I see a couple small issues (rotation should be by 90 instead of 180, and a missing paren toward the end of the second to last line), but I think the big issue is the geometry. The rotation is going to move anything you are drawing out of view, and you need to move it back in. Here's an attempt that I got to work for me...

[[NSGraphicsContext currentContext] saveGraphicsState];
NSAffineTransform * at = [NSAffineTransform transform];
[at rotateByDegrees:90.0f];
// note: origin was at lower right; need to move string back into view
[at translateXBy:([aLabel size].width/2) yBy:([aLabel size].height/2 - imgRect.size.width)];
[at concat];
[aLabel drawAtPoint:NSMakePoint(imgRect.size.width/2.0, imgRect.size.height/2.0)];
[[NSGraphicsContext currentContext] restoreGraphicsState];


With an affine transform, you are moving the entire coordinate axes, so your string is actually/visually going to be drawn in the second quadrant with the subsequent draw commands, not in the visible area of the image (which is in the first quadrant). So you need to move everything back over to the right (which is now the y direction in your rotated coordinate system, if that isn't confusing enough :-). Thus the translate of Y by subtracting the width of the image.

So now the origin of this new coordinate system is the lower right corner of the image, with the x-axis positive in the up direction, and the y-axis positive to the left. Now draw the label in the middle of the image.

As I said, I did get this to draw correctly so I could see it. More tweaking will be needed to get it exactly centered...

Hope this made sense!

John

On Jan 11, 2006, at 2:43 PM, I. Savant wrote:

// Draw Away label
[[NSGraphicsContext currentContext] saveGraphicsState];
NSAffineTransform * at = [NSAffineTransform transform];
[at rotateByDegrees:180.0f];
[at translateXBy:[aLabel size].width/2 yBy:[aLabel size].height/2];
[at concat];
[aLabel drawAtPoint:NSMakePoint(NSMidX(imgRect), NSMidY(imgRect)];
[[NSGraphicsContext currentContext] restoreGraphicsState];

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Yet another NSAffineTransform problem
      • From: "I. Savant" <email@hidden>
References: 
 >Yet another NSAffineTransform problem (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: Run application from code
  • Next by Date: Re: Opening a document in the same window
  • Previous by thread: Re: Yet another NSAffineTransform problem
  • Next by thread: Re: Yet another NSAffineTransform problem
  • Index(es):
    • Date
    • Thread