Re: NSColor opacity
Re: NSColor opacity
- Subject: Re: NSColor opacity
- From: Ken Tozier <email@hidden>
- Date: Tue, 30 Jan 2007 02:13:57 -0500
Well I figured out how to do the transparency thing using CGxxx
functions.  Here's the solution for anyone else who might be interested
NSRect				rect	= [self bounds];
CGContextRef		context	= [[NSGraphicsContext currentContext]
graphicsPort];
CGContextSetRGBFillColor (context, 0,1,0, .2);
CGContextFillRect (context, CGRectMake (0, 0, rect.size.width,
rect.size.height));
This draws a 20% green screen over the entire bounds rect;
On Jan 29, 2007, at 11:53 PM, Ken Tozier wrote:
- (void) drawRect:(NSRect) rect
{
	NSColor		*tempColor		= [NSColor colorWithDeviceRed: 0
										green: 1
										blue: 0
										alpha: .1];
	NSGraphicsContext	*context	= [NSGraphicsContext currentContext];
	[context saveGraphicsState];
	// composite the image to the rect
	[currentImage drawInRect: [self bounds]
			fromRect: NSZeroRect
			operation: NSCompositeSourceOver
			fraction: 1.0];
	// overlay with hover color
	[tempColor set];
	NSRectFill([self bounds]);
	[context restoreGraphicsState];
}
What I would expect is a 10 percent green screen overlayong the
specified rect What I get however is a 90 percent black rectangle.
Also tried changing the composite method by adding following line
before the [tempColor set] command to no effect.
[context setCompositingOperation: NSCompositeSourceAtop];
On Jan 29, 2007, at 11:46 PM, I. Savant wrote:
  Code?
--
I.S.
On Jan 29, 2007, at 11:18 PM, Ken Tozier wrote:
Hi
I'm drawing an NSColor to a custom view and am having problems
with the opacity of the color. Intuitively, I would think that
setting an alpha of .1 to an RGB color would produce a 10 percent
color screen but it doesn't. What happens is that the color
approaches black as the alpha decreases when logic would conclude
it should approach transparent. I can make a lighter screen by
setting a high opacity (,8, .9) but this obscures the underlying
image more not less.
How do you do something like this?
Thanks for any help
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
40gmail.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
40comcast.net
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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