Mac Help Forums


Reply
Thread Tools Display Modes

NSTextField numbers that can RESCALE

 
New Member
Join Date: Jun 2007
Posts: 2
 
      4th June 2007
hello everyone,

i want to type in numbers in the NSTextField and want it to resize the NSView. I want it to change the scaling of X and Y:

[transform scaleXBy: bounds.size.width/10 yBy: bounds.size.height/100];

i'll type in one number for x and another for y, and x will affect 10 and y will affect 100. i can't seem to make it work...


Than you!

the whole code is:



#import "RanWithParameters.h"


@implementation RanWithParameters

- (id)initWithFrame:(NSRect)rect
{
NSLog(@"-------------initWithFrame------------------");
if (self = [super initWithFrame:rect])
{
transform = [[NSAffineTransform alloc] init];
path = [[NSBezierPath alloc] init];
//xmax = [[NSString alloc] init];
}
return self;
}

- (IBAction)generate:(id)sender
{
NSLog(@"generate");
[self drawRandomLine];
[self setNeedsDisplay:YES];
}

- (void)drawRandomLine
{
int i;
NSPoint p;

//Remove previosly drawn random points
[path removeAllPoints];

//Create a path object
[path setLineWidth:2.0];
p = [self randomPoint:0];
[path moveToPoint: p];

for (i = 0; i <= 10; i++)
{
p = [self randomPoint:i];
[path lineToPoint: p];
}
}

// randomPoint returns a random point inside the view
- (NSPoint)randomPoint:(long)index
{
NSPoint result;
result.y = (random() % 100) -50;
result.x = index + 0;

return result;
}

//Setting scales
- (void)setScale:(NSRect)bounds
{
NSAffineTransformStruct I, unitsToPix;

NSLog(@"setScale");

I.m11 = 1;
I.m12 = 0;
I.m21 = 0;
I.m22 = 1;
I.tX = 0;
I.tY = 0;

[transform setTransformStruct:I];
[transform translateXBy: bounds.origin.x yBy: bounds.origin.y + bounds.size.height/2.0];
[transform scaleXBy: bounds.size.width/10 yBy: bounds.size.height/100];

unitsToPix = [transform transformStruct];

NSLog(@"unitsToPix.m11=%f unitsToPix.m12=%f unitsToPix.m21=%f unitsToPix.m22=%f unitsToPix.tX=%f unitsToPix.tY=%f",
unitsToPix.m11, unitsToPix.m12, unitsToPix.m21, unitsToPix.m22, unitsToPix.tX, unitsToPix.tY);
}

- (IBAction)xMax:(id)sender
setScale:(NSRect)bounds
{
float xMax;

NSString *xmax = [randomOutlet stringValue];

xMax = [xmax floatValue];

[transform scaleXBy: bounds.size.width/xMax yBy: bounds.size.height/100];
}

- (void)drawRect:(NSRect)rect
{
NSRect bounds;

NSLog(@"======= drawRect ======");

bounds = [self bounds];

[self setScale:bounds];

//Fill the view with black
[[NSColor blackColor] set];
[NSBezierPath fillRect:bounds];

// Draw the path red
[[NSColor redColor] set];
[path transformUsingAffineTransform: transform]; // transform path in units to path in pixels
[path stroke]; // draw path in pixels
[transform invert]; // invert transform to go from pixels to units
[path transformUsingAffineTransform: transform]; // transform path in pixels back to path in units
[transform invert]; // invert transform back to take us from units to pixels
}

- (void)dealloc
{
[path release];
[transform release];
[super dealloc];
}



@end
 
Reply With Quote
 
 
 
 
Senior Member
Kaveman's Avatar
Join Date: Nov 2010
Location: Westland, NZ
Posts: 1,360
 
      12th June 2011
You're over complicating things.

Just calculate the size required and use NSView setBounds:
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting 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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check NSTextField boscarol Programmer Help 0 5th February 2007 11:51 PM
Getting value from NSTextField Dale Stanbrough Programmer Help 2 17th October 2006 11:49 AM
String and NSTextField MarcoS Programmer Help 3 25th August 2004 11:03 AM
Which is the best rescale algorithm for GraphicConverter? Hobo Apps 8 25th September 2003 10:25 PM
Which is the best rescale algorithm for GraphicConverter? Hobo Mac 5 22nd September 2003 07:40 PM


All times are GMT +1. The time now is 10:58 AM.
Mac-Help.com is an independent website and is not affiliated with Apple Inc.


Welcome!
Welcome to the Mac Help Forums
 


Latest Threads
New book about Steve Jobs << take part in it!
Arjan (1 Hour Ago, 09:37 AM)

Help! Stupid computer is automatically logging me out
Elizaboo (12 Hours Ago, 10:41 PM)

URGENT Help. Crazy talk Mac!
Joeker (13 Hours Ago, 09:42 PM)

PDF Document
yura (22 Hours Ago, 12:13 PM)

Difficulties with internet speed (nothing to do with connection)
sammethh (1 Day Ago, 06:36 AM)

 


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51