Re: erasing, redrawing NSBezierPath into and NSImage problem
Re: erasing, redrawing NSBezierPath into and NSImage problem
- Subject: Re: erasing, redrawing NSBezierPath into and NSImage problem
- From: Wilhelm Phillips <email@hidden>
- Date: Wed, 7 Jul 2004 00:24:47 -0700
I was considering NSAffineTransform as a possibly more efficient method
for transforming my bezierPath.
However, in my case it is as Louis mentioned, where my bezierPath
includes rounded corners or edges that would be distorted since the
cell width can increase without the cell height increasing thus
changing the aspect ratio of my image.
Also, the initial problem I was having with redrawing into someLabel
and displaying it correctly in my labelMatrix was solved by fixing one
line of my code, thought I'm not completely sure why it works this way.
I was trying to rename my label image using setName with the same name
each time I drew the modified bezierPath into it. So, the first time
it drew correctly. After that it never updated correctly. By doing
the following, it displays and updates correctly in my labelMatrix:
- (void)drawLabels
{
// bezierPath drawing here, etc.
[someLabel setName: nil]; // added this to fix the problem
someLabel = [[NSImage alloc] initWithSize:NSMakeSize(cellWidth,
cellHeight)];
[someLabel lockFocus];
[[NSColor clearColor] set];
[bezierPath fill]; // this actually does clear bezierPath from
someLabel correctly
// in the same way that Louis' NSRectFill with clearColor
suggestion works
[[NSColor myNewColor] set];
[bezierPath fill];
[someLabel setName:@"Some Label Name"];
[someLabel unlockFocus];
}
So, by setting the name to nil first and then renaming it after I drew
into it, my labelMatrix updates correctly and everything works as I
expected. This must be a very fundamental issue that I somehow missed.
Will
On Jul 6, 2004, at 10:42 PM, Louis C. Sacha wrote:
>
Hello...
>
>
It definitely depends on the kind of path and the kind of calculations
>
that need to be done.
>
>
>
It may or may not be an issue for the original poster, but this
>
approach won't work corectly in some common situations, specifically
>
instances where some "feature" of the path is intended to be at a
>
contant size or aspect ratio and the path would need to be scaled to
>
any arbitrary size.
>
>
One example would be the "rectangle with rounded corners" look and
>
variations on that theme, where the rectangle can be any arbitrary
>
size but the corners always use the same radius or arc. If you tried
>
to do this with an affine transform, the curve at the corner would
>
also be scaled and potentially be distorted if the aspect ratio of the
>
new size is different from the original used to calculate the original
>
path.
>
>
>
On the other hand, if all the features of the path need to be scaled
>
identically and the aspect ratio doesn't matter, then the approach
>
that Scott provided is significantly easier than recalculating the
>
path for each size.
>
>
Louis
>
>
>
>
> Depending on what kind of calculations you have to do to come up with
>
> your curve points, one option you might consider. Instead of
>
> recalculating the control points each time based on the new size of
>
> the label, calculate the points once and then, before you draw your
>
> label, use an NSAffineTransform to scale the drawing context to the
>
> size that is appropriate for the label.
>
>
>
> That is to say, assume that your drawing is going to go to a label
>
> that is 100 x 100 and calculate the points for your bezier path.
>
> Then, instead of calculating a new set of points use an
>
> NSAffineTransform with a to scale the coordinate system by
>
> (actualWidth / 100, actualHeight / 100)
>
>
>
> Is that clear as mud?
>
>
>
> The point is that using this technique you should be able to
>
> eliminate the calculations of the coordinates because you only ever
>
> do them once. If they are right at one size then they should work at
>
> all sizes.
>
>
>
> Scott
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.