Re: Programmatically creating NSButton
Re: Programmatically creating NSButton
- Subject: Re: Programmatically creating NSButton
- From: "Louis C. Sacha" <email@hidden>
- Date: Sat, 24 Apr 2004 22:34:18 -0700
Hello...
The view that the cell is being drawn in is the issue: it appears
that the view must use a flipped coordinate system for the
NSButtonCell to draw correctly (NSButton and NSMatrix both use a
flipped coordinate system, by default the view used by NSImage for
caching uses the standard coordinate system). All you need to do is
probably just add the line:
[img setFlipped:TRUE];
before you lock focus on the image to draw. I would consider the fact
that a NSButtonCell doesn't draw correctly in a normal (unflipped)
view a bug, so if you have time it would be a good idea to file it
with Apple so that someday it might get fixed, or at least documented.
It doesn't seem to matter what view is passed to the
drawWithFrame:inRect: method at the moment, but I would still
recommend that you use [NSView focusView] to pass in the image cache
view just in case the method implementation is changed in the future.
My second suggestion would also have worked, if you can wanted to use
the NSButton instead of the cell.
- (NSImage *)btnGenerator:(NSButton *)button
{
NSRect frame = [button bounds];
NSData *data = [button dataWithPDFInsideRect:frame];
NSImage *snapShot = [[[NSImage alloc] initWith
Data:data] autorelease];
float padding = [padding floatValue];
frame.size.width = frame.size.width + 2.0f*padding;
NSImage *img = [[NSImage alloc] initWithSize:frame.size];
[img lockFocus];
[[NSColor clearColor] set];
NSRectFill(frame);
[snapShot compositeToPoint:NSMakePoint(padding,0.0f)
operation:NSCompositeSourceOver fraction:1.0f];
[img unlockFocus];
return [img autorelease];
}
Of course, the first solution would be the simpler fix, and wouldn't
require any changes to your other code.
Hope that helps,
Louis
Greg wrote:
I just tried the NSView focusView and it is a NSImageCacheView and
yeilds the same result.
_______________________________________________
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.