Re: NSView subview backgrounds
Re: NSView subview backgrounds
- Subject: Re: NSView subview backgrounds
- From: Twisted Theory Software <email@hidden>
- Date: Mon, 1 Oct 2007 13:37:40 -0500
On 1 Oct, 2007, at 1:17 PM, glenn andreas wrote:
On Oct 1, 2007, at 12:42 PM, Twisted Theory Software wrote:
Hi,
I have an NSView subclass, which is getting a gradient background,
drawn by NSBezierPaths. I found that even though I'm drawing the
background using colours with alpha component equal to 1.0, their
colour is being effected by the colour of the object underneath it
(which is black). I can check that this is true by using the
DigitalColor Meter application.
Could anyone suggest how to fix this? I've attached my subclass'
drawRect method:
// draw the gradient by horizontal bezier paths
for (int i = 0; i < steps; i++)
{
NSColor *curColour = [NSColor
colorByInterpolatingColor:initialColour
withColor:finalColour
basedOnProgress:i
outOfPossibleSteps:steps];
curColour = [curColour colorWithAlphaComponent:1.0];
NSBezierPath *path = [NSBezierPath bezierPath];
[curColour setStroke];
[path moveToPoint:NSMakePoint(0,i)];
[path lineToPoint:NSMakePoint(rect.size.width,i)];
[path setLineWidth:1.0];
[path stroke];
}
Since the line will be centered on the division between pixels,
there will be 0.5 of a pixel drawn on each side (i.e., it will end
up being blurred with the background).
The quick fix is to do:
[path moveToPoint:NSMakePoint(0,i+0.5)];
[path lineToPoint:NSMakePoint(rect.size.width,i+0.5)];
but the better fix is to use the lower level Quartz support for
drawing gradients (which is much more efficient)
This seems to completely ignore the white colour background and
blends the lines with the black background, which is the opposite of
what I was after. I'll look into the CGShading API, as suggested
previously.
Thanks,
Josh
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden