Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > scale an NSBezierPath within NSView

scale an NSBezierPath within NSView
Thread Tools
Fresh-Faced Recruit
Join Date: Oct 2009
Status: Offline
Reply With Quote
Nov 27, 2009, 11:00 PM
 
Hey all,

I'm drawing a graphing line, looks like a wave within an NSView. The line looks fine, except that it's not scaled to the size of the window. So my problem is trying to figure out how to scale it to the window size and every time that the window is resized.

I currently have something like this, but my scaleXBy, yBy on the NSAffineTransform isn't working out so well.

Anyone know how to get the NSBezierPath to take up 90% of my NSView (leaving 10% bank for borders)?

Code:
- (void) drawRect:(NSRect) rect { NSRect bounds = [self bounds]; float xAxis = bounds.size.width * 0.9; float yAxis = bounds.size.height * 0.9; [[NSColor blackColor] setFill]; [NSBezierPath fillRect:bounds]; NSAffineTransform *newTransform = [NSAffineTransform transform]; [newTransform translateXBy:40.0 yBy:30.0]; [newTransform concat]; // can't seem to get this transform to work as expected. [newTransform scaleXBy:xAxis yBy:yAxis]; [self drawAxes:rect width:xAxis height:yAxis]; [self drawGraph:rect]; return; }
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Nov 29, 2009, 02:31 PM
 
The argument to scaleXBy:yBy: is a multiplier. So if your view is 300 pixels wide, you're telling the transform to make everything 270 times as big. What you want is to find the
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -4. The time now is 06:29 PM.
All contents of these forums © 1995-2015 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2015, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2