Re: Drawing an NSImage in a view with flipped coordinates
Re: Drawing an NSImage in a view with flipped coordinates
- Subject: Re: Drawing an NSImage in a view with flipped coordinates
- From: Andrew Platzer <email@hidden>
- Date: Mon, 28 Feb 2005 12:01:08 -0800
On Feb 28, 2005, at 11:49 AM, Derrick Griffel wrote:
I'm trying to draw an image in a view that has flipped coordinates.
My view has to have flipped coordinates because I am using rulers and
I would like the origin of the rulers in the upper left corner. I
was originally using [NSImage setFlipped:YES] prior to locking focus,
creating a new NSImageRep, unlocking focus, and then using
[NSImageRep drawInRect]. This resulted in my image getting drawn
correctly with one exception. Using this design, some EPS images
would not scale up correctly. To overcome the scaling problem, I
added a call to [NSImage setDataRetained:YES]. This fixed the
scaling problem, however, none of the images obey the setFlipped flag
anymore resulting in all my images being drawn upside down. If I
remove the call to setDataRetained, the images are once again drawn
in the correct orientation, but then I am still faced with the
scaling problem with certain EPS images.
Does anyone have any ideas on what I am doing wrong?
-[NSImage setFlipped:] has inconsistent behaviour depending on whether
it's cached or not. Unfortunately, it can't be changed since the
existing apps depend on it's behaviour. If you need to draw an image in
a flipped coordinate system, instead, use NSAffineTransform to undo the
flipping and avoid -[NSImage setFlipped:].
-drawImage:image atPoint:point
[NSGraphicsContext saveGraphicsState]
NSAffineTransform *transform = [NSAffineTransform transform]
[transform translateXBy:point.x yBy:point.y + [image size].height];
[transform scaleXBy:1.0 yBy:-1.0];
[transform set];
... draw image @ (0,0)...
[NSGraphicsContext restoreGraphicsState]
This translates the coordinate system to the bottom corner of the
rectangle and then flips the coordinate system so it's right side up.
Andrew
____________________________________
Andrew Platzer
Application Frameworks
Apple Computer, Inc.
_______________________________________________
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