• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSAffineTransform scaleBy not scaling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSAffineTransform scaleBy not scaling


  • Subject: Re: NSAffineTransform scaleBy not scaling
  • From: Shane <email@hidden>
  • Date: Fri, 4 Dec 2009 17:59:50 -0600

> That then just leaves you with the translation to deal with, for positioning the scaled path where you want it.
>

I really hate to post this again, but I believe I'm doing it right,
but there's obviously something I'm not understanding. By trying to
figure out what's wrong w/ my scaling, I've simplified it to doing
transforms only which also shows the problem (new problem after making
the changes suggested).

I'm certain I have the destination bounds, the path bounds, and even
the scaleXBy: yBy: factors correct, but I'll just stick w/ how I'm
doing the 'translateXBy yBy:' and comment out the scaleXBy method. I
plot my line, and it shows in the view perfect, as expected. If I try
to resize the view, my plot starts to move incrementing by one,
translating +1 for both x and y. Whether I resize my NSView larger or
smaller, my curve moves to the upper right corner and then eventually
off the view, as if x and y in 'translateXBy: yBy' constantly
increment by one as I resize the view.

So my thought is that somehow the transformations are not resetting to
the identity matrix, but they are as far as I can tell. Maybe, I'm
thinking, that the transforms are being added on top of each other as
the view resizes.

Anyone see anything wrong that I'm doing?

- (void) drawRect:(NSRect) rect
{
	NSRect bounds = [self bounds];

	[[NSColor blackColor] setFill];
	[NSBezierPath fillRect:bounds];

	float xFactor = (bounds.size.width * 0.9) / maxXValue;
	float yFactor = (bounds.size.height * 0.9) / maxYValue;

	NSAffineTransform *xform = [NSAffineTransform transform];

	// curve starts off translated up 2 and over 2, correct.
        // resizing view seems like x and y incr by 1 as view resizes.
	[xform translateXBy:2.0 yBy:2.0];
	//[xform scaleXBy:xFactor yBy:yFactor];

	[pointsPath transformUsingAffineTransform:xform];

	[[NSColor whiteColor] setStroke];

	[pointsPath setLineCapStyle:NSSquareLineCapStyle];
	[pointsPath stroke];

	return;
}

- (void) appendPoint:(NSPoint) point
{
	if (firstPoint) {
		[pointsPath moveToPoint:point];

		firstPoint = NO;
	}

	[pointsPath lineToPoint:point];

	return;
}

- (void) updateXMax:(double) maxX yMax:(double) maxY
{
	maxXValue = maxX;
	maxYValue = maxY;
}

This gets called for each point in my curve, which happens ~140 times.
My curve shows up as expected, then I resize the window and the curve
doesn't resize to the window, rather, it moves off the window in the
original size.

	BOOL maxFlagDirty = NO;

	NSNumber *mse = [NSNumber numberWithDouble:[[data mse] doubleValue]];
	NSNumber *iters = [NSNumber numberWithInt:[[data iterations] intValue]];

	if ([iters doubleValue] > maxXValue) {
		maxXValue = [iters doubleValue];
		maxFlagDirty = YES;
	}

	if ([mse doubleValue] > maxYValue) {
		maxYValue = [mse doubleValue];
		maxFlagDirty = YES;
	}

	if (maxFlagDirty) {
		[graphView updateXMax:maxXValue yMax:maxYValue];
	}

	NSPoint point = NSMakePoint([iters floatValue], [mse floatValue]);

	if ([self isWindowLoaded]) {
		[graphView appendPoint:point];

		[graphView setNeedsDisplay:YES];
	}
_______________________________________________

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

  • Follow-Ups:
    • Re: NSAffineTransform scaleBy not scaling
      • From: Graham Cox <email@hidden>
References: 
 >Re: NSAffineTransform scaleBy not scaling (From: Shane <email@hidden>)
 >Re: NSAffineTransform scaleBy not scaling (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: NSRuleEditor rows binding
  • Next by Date: Re: NSAffineTransform scaleBy not scaling
  • Previous by thread: Re: NSAffineTransform scaleBy not scaling
  • Next by thread: Re: NSAffineTransform scaleBy not scaling
  • Index(es):
    • Date
    • Thread