Re: Transparency in NSButtonCell
Re: Transparency in NSButtonCell
- Subject: Re: Transparency in NSButtonCell
- From: Matt Ball <email@hidden>
- Date: Sat, 16 Jul 2005 18:55:49 -0400
Rather than retooling my setup to include [self path] and [self
setPath:], is there any reason this wouldn't work: (because when I use
it, nothing is drawn...)
- (void)drawRect:(NSRect)rect {
if(!roundRectHasBeenFilled) {
[self drawRoundRectWithFrame:[self bounds]];
}
}
- (void)drawRoundRectWithFrame:(NSRect)rect {
[self lockFocus];
[[NSColor colorWithCalibratedWhite:0.2 alpha:0.7] set];
NSBezierPath *titlebarRect = [self
bezierPathWithRoundTitlebarRectInRect:rect radius:6.0];
[titlebarRect fill];
[[NSColor colorWithCalibratedWhite:0.05 alpha:0.7] set];
NSBezierPath *contentRect = [self
bezierPathWithRoundContentRectInRect:rect radius:6.0];
[contentRect fill];
NSShadow *theShadow = [[NSShadow alloc] init];
[theShadow setShadowColor:[NSColor colorWithCalibratedRed:0.33
green:0.33 blue:0.33 alpha:1.0]];
[theShadow setShadowBlurRadius:0];
[theShadow setShadowOffset:NSMakeSize(0,-1)];
[theShadow set];
NSMutableDictionary *attrs = [NSMutableDictionary dictionaryWithCapacity:1];
[attrs setValue:[NSColor whiteColor] forKey:@"NSColor"];
[attrs setObject:[NSFont fontWithName:@"Lucida Grande" size:10]
forKey:NSFontAttributeName];
NSAttributedString *string = [[NSAttributedString alloc]
initWithString:title attributes:attrs];
NSRect rectToDrawTitle = NSMakeRect(([self frame].size.width -
[string size].width)/2, 19 - [string size].height * 1.2, [string
size].width, [string size].height);
[title drawInRect:rectToDrawTitle withAttributes:attrs];
[string release];
[theShadow release];
[self unlockFocus];
roundRectHasBeenFilled = YES;
}
On 7/16/05, Andreas Mayer <email@hidden> wrote:
>
> 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
>
_______________________________________________
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