Re: Transparency in NSButtonCell
Re: Transparency in NSButtonCell
- Subject: Re: Transparency in NSButtonCell
- From: Andreas Mayer <email@hidden>
- Date: Sun, 17 Jul 2005 00:20:34 +0200
Am 16.07.2005 um 23:33 Uhr schrieb Matt Ball:
- (void)drawRect:(NSRect)rect {
[[NSColor colorWithCalibratedWhite:0.2 alpha:0.7] set];
NSBezierPath *titlebarRect = [self
bezierPathWithRoundTitlebarRectInRect:rect radius:6.0];
[titlebarRect fill];
[titlebarRect release];
[[NSColor colorWithCalibratedWhite:0.05 alpha:0.7] set];
NSBezierPath *contentRect = [self
bezierPathWithRoundContentRectInRect:rect radius:6.0];
[contentRect fill];
[contentRect release];
}
This is your problem: rect is just the rectangle that is to be
redrawn. It's not, in general, the bounding rectangle for the view.
So you are drawing your rounded rectangle in whatever space is to be
redrawn at the moment.
You could do something like this instead:
- (void)drawRect:(NSRect)rect
{
if (![self path]) {
[self setPath:[self bezierPathWithRoundContentRectInRect:
[self bounds] radius:6.0]];
[self setColor:[NSColor colorWithCalibratedWhite:0.05 alpha:
0.7]];
}
[[self color] set];
[[self path] fill];
}
And the title bar I'd add as a separate control.
Also, while this has nothing to do with your problem, convenience
methods should always return autoreleased objects.
See http://developer.apple.com/documentation/Cocoa/Conceptual/
MemoryMgmt/Concepts/ObjectOwnership.html
So in ...
- (NSBezierPath*)bezierPathWithRoundTitlebarRectInRect:(NSRect)aRect
radius:(float)radius
{
NSBezierPath* path = [[NSBezierPath alloc] init];
[...]
return path;
}
... replace the last line with
return [path autorelease];
Andreas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden