• 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: multible NSImages rotated in the same view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multible NSImages rotated in the same view


  • Subject: Re: multible NSImages rotated in the same view
  • From: email@hidden
  • Date: Sat, 16 Feb 2002 11:45:48 -0800

Sorry but I am feeling stupid today. Can't seem to get
a grip on the whole drawing cooridnate system. The
docs haven't helped and the list archives aren't
producing much for me.

One of those days, eh? :->

Question:
How can I rotate a NSImage multiple times in the same
NSView? This code does not work:

- (void)drawRect:(NSRect)rect {
NSRect sourceRect NSMakeRect(0,0,[img
size].width,[img size].height);

[[NSColor blueColor] set];
NSRectFill([self bounds]);

[img drawAtPoint:[self bounds].origin
fromRect:sourceRect operation:NSCompositeSourceOver
fraction:0.5];
[self rotateByAngle:45];
[img drawAtPoint:[self bounds].origin
fromRect:sourceRect operation:NSCompositeSourceOver
fraction:0.5];
[self rotateByAngle:-45];
}

I think -rotateByAngle isn't what you want. Look at the NSView doc, it has some nice pictures to illustrate the problem here. What you're doing is rotating your entire view by the given angle within its superview -- you're making your view's rectangular frame no longer aligned with the frame of its superview. Not only is this not what you want, but it also won't take effect inside -drawRect:, since your whole drawing environment is set up and focussed by the time drawRect: is called.
What you want to be using, I think, is NSAffineTransform. More specifically, I'd look at the two -rotate methods and the -concat method on NSAffineTransform. You might find the other methods useful too, as you get more deeply into the issue, but those are a good place to start.

One other question:

why does making the sourceRect bigger make the image
small on the screen? I guess I really don't understand
the coordinate system

Hmm. If you were supplying a destination rect as well, this would make perfect sense to me. If you're using code exactly like the code above, then I'm a bit mystified.

Ben Haller
Stick Software
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: NSUserDefaults stickyness
  • Next by Date: Re: what's an NSZone?
  • Previous by thread: multible NSImages rotated in the same view
  • Next by thread: Getting behind NSBeep
  • Index(es):
    • Date
    • Thread