Unwanted transparency in custom view
Unwanted transparency in custom view
- Subject: Unwanted transparency in custom view
- From: Ken Tozier <email@hidden>
- Date: Mon, 17 Jun 2002 12:03:44 -0400
I'm writing a custom view class and have everything working except for
one bug, when it renders it is semi transparent. I overrode "isOpaque"
to return yes and set the color alpha to 1.0 but you can still see
through it. The class is for use in a bar graph and I wanted to
reproduce the Aqua look for the bars which I did by drawing a bunch of
lines with the same colors used in other Aqua controls. Could it be that
antialiasing is causing the boundaries between lines to be less than
opaque, or is it something simpler?
Anyone see what I'm doing wrong?
Note: as a test I tried filling the rect with one of the colors from the
table and the view was opaque, so I suspect it has something to do with
the lines.
Here's the code:
- (void) drawRect:(NSRect) inRect
{
NSRect bounds = [self bounds];
NSPoint lineStart,
lineEnd;
NSEnumerator *colorTableEnumerator;
id anObject;
// create table enumerator
colorTableEnumerator = [clickedColorTable objectEnumerator];
// set up line endpoint variables
lineStart.x = bounds.origin.x;
lineStart.y = bounds.origin.y + bounds.size.height;
lineEnd.x = bounds.origin.x + bounds.size.width;
lineEnd.y = lineStart.y;
// draw the bar
while ((anObject = [colorTableEnumerator nextObject]))
{
// set the color for the next line
[self setRGBColor:anObject];
// draw the line
[NSBezierPath strokeLineFromPoint:lineStart toPoint:lineEnd];
// increment line endpoints
lineStart.y--;
lineEnd.y--;
}
}
- (void) setRGBColor:(NSDictionary *) inDict
{
[[NSColor colorWithCalibratedRed:[[inDict objectForKey:@"Red"]
floatValue]
green:[[inDict objectForKey:@"Green"] floatValue]
blue:[[inDict objectForKey:@"Blue"] floatValue]
alpha:1] set];
}
Thanks,
Ken Tozier
_______________________________________________
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.