Re: Transparent colors
Re: Transparent colors
- Subject: Re: Transparent colors
- From: "Ken Ferry" <email@hidden>
- Date: Mon, 28 Jul 2008 19:54:33 -0700
On Mon, Jul 28, 2008 at 7:46 PM, Graham Cox <email@hidden> wrote:
>
> On 29 Jul 2008, at 12:31 pm, Dale Miller wrote:
>
>> I cannot get transparent colors to work. I have tried two cases:
>> 1) I have a view which returns YES to "isTransparent". The log shows the
>> method has been called and responded YES. If I do a NSRectFill after
>> [[NSColor clearColor] set] the view displays as black.
You probably needs to set your window to non-opaque. See -[NSWindow
setOpaque:]. By default the window server assumes that the content of
your window is opaque (outside of the corners), and therefore it
doesn't need to necessarily draw anything behind it.
> -isTransparent only applies to certain controls, not to views in general.
> Did you mean -isOpaque instead?
Yes- isTransparent isn't something that you'd normally override. For
buttons and boxes, setTransparent:YES just makes them return from
drawRect: without drawing anything.
> I think there is a bug that seemed to get introduced in Leopard. The
> NSRectFill methods now seem to do something different from what they did on
> Tiger, using a different composition mode that stops transparency working
> quite right. I'm not completely sure though - I just noticed some drawing
> problems in my code when I went to Leopard and didn't investigate them - I
> just switched to using a different technique.
Don't think so.. NSRectFill does and always has filled in copy mode.
> You can avoid the problem by using NSBezierPath instead (e.g. [NSBezierPath
> fillRect:])
>
>
>>
>> 2) If i do a "drawInRect" with the attribute
>> NSBackgroundColorAttributeName set to [NSColor clearColor] (or to a color
>> with an alpha of 0. regardless of the red/green/blue components) the
>> background of the text draws as black. What is it that I don't understand?
>
> I believe this is a known bug - transparent text backgrounds aren't
> supported. You can achieve the equivalent just by rendering the text atop
> the background in the usual way (i.e. no background attribute set at all) -
> the only place this bug causes a problem is with editing text using
> NSTextView with a transparent background. So this might be related to your
> (mis)use of isTransparent?
The black would be the window server assuming that the window is
opaque. In SnowLeopard you'd actually see garbage there.
Text should be able to draw okay into transparency, though it breaks
subpixel rendering. For best results, turn off font smoothing
(CGContextSetShouldSmoothFonts) when rendering text into a transparent
context.
-Ken
Cocoa frameworks
_______________________________________________
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