Re: Flipped NSView + scaled NSAffineTransform = confusion
Re: Flipped NSView + scaled NSAffineTransform = confusion
- Subject: Re: Flipped NSView + scaled NSAffineTransform = confusion
- From: Matt Neuburg <email@hidden>
- Date: Sat, 02 Oct 2010 06:54:01 -0700
- Thread-topic: Flipped NSView + scaled NSAffineTransform = confusion
On Fri, 1 Oct 2010 02:28:33 -0400, Ken Tozier <email@hidden> said:
>- (void) drawRect:(NSRect) inDirtyRect
>{
> [[[self superview] subTransform] concat];
> [[NSColor greenColor] set];
> NSRectFillUsingOperation(inDirtyRect, NSCompositeSourceOver);
>}
>
>What do I need to do to scale a subview using an NSAffineTransform
Sorry, I didn't see this earlier query from you, where you do in fact show
code.
Right, then. So, what exactly are you expecting this to do? "Scale a
subview" sounds like you expect it to alter the size of the view itself. A
transform doesn't do that. It just changes the meaning of subsequent draw
operations within the graphics context. So, here, you're just changing the
meaning of the rect "inDirtyRect". If you change its meaning so that it no
longer falls within the visible context boundaries, the view will become
invisible.
Also, scaling takes place around the origin. That's in the left corner (on
Mac OS X, the lower left corner). If you wanted to scale your drawing around
the center of the view, you'd also transform the origin.
Here's an example of applying a scale transform that actually does something
visible that you can sink your teeth into:
- (void)drawRect:(NSRect)dirtyRect {
NSRect r = [self bounds];
NSRectFill(r);
NSAffineTransform* t = [NSAffineTransform transform];
[t scaleBy:0.9];
[t concat];
[[NSColor greenColor] set];
NSRectFill(r);
}
That creates a black rectangle with a slightly smaller green rectangle in
the lower left corner. Go Ye And Do Likewise.
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.apeth.net/matt/default.html#applescriptthings
_______________________________________________
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