Re: Zooming images in NSView
Re: Zooming images in NSView
- Subject: Re: Zooming images in NSView
- From: "John C. Randolph" <email@hidden>
- Date: Sat, 11 Dec 2004 17:05:37 -0800
On Dec 11, 2004, at 4:56 PM, John C. Randolph wrote:
On Dec 11, 2004, at 12:56 PM, Chris Giordano wrote:
Thought I'd let everyone know of what looks like a bug in the
-scalePercent method in the sample code.
You're right, there's a bug. It's not in -scalePercent though, it's in
the way I was computing -scale, and mixing up a -convertSize:fromView:
with -convertSize:toView. Correction coming soon to an ADC website
near you!
And for those who might like to see it right away:
const NSSize unitSize = { 1.0, 1.0 };
@implementation NSView (scaling)
// This method makes the scaling of the receiver equal to the window's
// base coordinate system.
- (void) resetScaling { [self scaleUnitSquareToSize: [self convertSize:
unitSize fromView: nil]]; }
// This method returns the scale of the receiver's coordinate system,
relative to
// the window's base coordinate system.
- (NSSize) scale { return [self convertSize:unitSize toView:nil]; } -
(void) setScale:(NSSize) newScale // This method sets the scale in
absolute terms.
{
[self resetScaling]; // First, match our scaling to the window's
coordinate system
[self scaleUnitSquareToSize:newScale]; // Then, set the scale.
}
// Use these if you'd rather work with percentages.
- (float) scalePercent { return [self scale].width * 100; }
- (void) setScalePercent:(float) scale
{
scale = scale/100.0;
[self setScale:NSMakeSize(scale, scale)];
[self setNeedsDisplay:YES];
}
@end
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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