Window transparency

  • Hello,

    I'd like to make my window's background transparent but keep the
    drawing in it at full opaqueness. Also the titlebar and resize widget
    I'd like to keep in the normal state. The only thing I could find now
    was [myWindow setAlphaValue:float]. The problem is that this alphavalue
    will be used for my entire window, so that my view, titlebar and
    everything is transparent too.

    Terminal.app can do what I want, so I should be able to do so too. Any
    pointers, clues?

    Thanks again!

    Johan
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Hi,
    I think you don't have to do [myWindow setAlphaValue:float];
    you could just simply do [myWindow setBackgroundColor: [NSColor
    clearColor]] since myWindow is not opaque by sending setOpaque:NO to
    myWindow.
    Hope this helps,
    James
    ------------------------------------
    Ulead Systems Inc.
    James Chen
    Software Engineer
    Image Div.
    ------------------------------------
    On Feb 5, 2004, at 7:19 AM, Johan Kool wrote:

    > Hello,
    >
    > I'd like to make my window's background transparent but keep the
    > drawing in it at full opaqueness. Also the titlebar and resize widget
    > I'd like to keep in the normal state. The only thing I could find now
    > was [myWindow setAlphaValue:float]. The problem is that this
    > alphavalue will be used for my entire window, so that my view,
    > titlebar and everything is transparent too.
    >
    > Terminal.app can do what I want, so I should be able to do so too. Any
    > pointers, clues?
    >
    > Thanks again!
    >
    > Johan
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Since I joined this list to have this very question answered,  I guess
    I'll answer.

    You need to put a custom view in your window where you want the
    transparency.  Then for the window that you are going to want the
    transparent part you need

    - (void)windowControllerDidLoadNib:(NSWindowController *) aController {
        ....

        [documentWindow setAlphaValue:0.999f];
        [documentWindow setOpaque: NO];  // Not sure this is needed

        ....
    }

    or something equivalent.

    Then in the drawRect for your view you need to:

    -(void) drawRect:(NSRect)frame {

    ...
        //Clear the background
        [[NSColor clearColor] set];
        NSRectFill([self frame]);

    ...
    }

    Then draw whatever you want to be transparent at the transparency you
    want.

    Rob

    On 4 Feb 2004, at 11:19 pm, Johan Kool wrote:

    > Hello,
    >
    > I'd like to make my window's background transparent but keep the
    > drawing in it at full opaqueness. Also the titlebar and resize widget
    > I'd like to keep in the normal state. The only thing I could find now
    > was [myWindow setAlphaValue:float]. The problem is that this
    > alphavalue will be used for my entire window, so that my view,
    > titlebar and everything is transparent too.
    >
    > Terminal.app can do what I want, so I should be able to do so too. Any
    > pointers, clues?
    >
    > Thanks again!
    >
    > Johan
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • After a quick test, it looks like either of the calls

        [documentWindow setAlphaValue:0.999f];
        [documentWindow setOpaque: NO];

    will work.  Both aren't needed.

    On 5 Feb 2004, at 9:59 am, Rob Abernathy wrote:

    > Since I joined this list to have this very question answered,  I guess
    > I'll answer.
    >
    > You need to put a custom view in your window where you want the
    > transparency.  Then for the window that you are going to want the
    > transparent part you need
    >
    > - (void)windowControllerDidLoadNib:(NSWindowController *) aController {
    > ....
    >
    > [documentWindow setAlphaValue:0.999f];
    > [documentWindow setOpaque: NO];  // Not sure this is needed
    >
    > ....
    > }
    >
    > or something equivalent.
    >
    > Then in the drawRect for your view you need to:
    >
    > -(void) drawRect:(NSRect)frame {
    >
    > ...
    > //Clear the background
    > [[NSColor clearColor] set];
    > NSRectFill([self frame]);
    >
    > ...
    > }
    >
    > Then draw whatever you want to be transparent at the transparency you
    > want.
    >
    > Rob
    >
    >
    >
    > On 4 Feb 2004, at 11:19 pm, Johan Kool wrote:
    >
    >> Hello,
    >>
    >> I'd like to make my window's background transparent but keep the
    >> drawing in it at full opaqueness. Also the titlebar and resize widget
    >> I'd like to keep in the normal state. The only thing I could find now
    >> was [myWindow setAlphaValue:float]. The problem is that this
    >> alphavalue will be used for my entire window, so that my view,
    >> titlebar and everything is transparent too.
    >>
    >> Terminal.app can do what I want, so I should be able to do so too.
    >> Any pointers, clues?
    >>
    >> Thanks again!
    >>
    >> Johan
    >> _______________________________________________
    >> cocoa-dev mailing list | <cocoa-dev...>
    >> Help/Unsubscribe/Archives:
    >> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    >> Do not post admin requests to the list. They will be ignored.
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Hi Johan,

    Try looking at my junkyard. I once wrote a solitaire app (cardgame)
    which has a translucent window.
    I found out that if I painted certain areas of the window with a solid
    color, I could keep areas of the window translucent or transparant.

    http://objc-source.com/junkyard.html

    On Thursday, Feb 5, 2004, at 00:19 Europe/Copenhagen, Johan Kool wrote:

    > I'd like to make my window's background transparent but keep the
    > drawing in it at full opaqueness. Also the titlebar and resize widget
    > I'd like to keep in the normal state. The only thing I could find now
    > was [myWindow setAlphaValue:float]. The problem is that this
    > alphavalue will be used for my entire window, so that my view,
    > titlebar and everything is transparent too.
    >
    > Terminal.app can do what I want, so I should be able to do so too. Any
    > pointers, clues?

    Love,
    Jens
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Hello,

    Thanks all for your replies. Especially Rob for joining the list just
    to send me an answer! I have got it working now, and it looks quite
    okay.

    One thing though is that the shadow of the window is automatically put
    under my own view too. I don't want it there. I know that I can turn of
    the shadow of the window altogether but that gives such a weird look to
    the titlebar. Is there anyway where I can have shadow underneath my
    titlebar, but not under my own drawing in myView?

    Thanks again!

    Johan

    PS: I'd say that [documentWindow setOpaque: NO]; is the best way to use
    transparency.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • > One thing though is that the shadow of the window is automatically put
    > under my own view too. I don't want it there. I know that I can turn
    > of the shadow of the window altogether but that gives such a weird
    > look to the titlebar. Is there anyway where I can have shadow
    > underneath my titlebar, but not under my own drawing in myView?

    To answer my own question. Yes, this can be done. Call [myWindow
    invalidateShadow] right after you've drawn the clear rect, then draw
    your view. Now only the resize widget lacks shadow, but that's
    something I can live with.

    Johan
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month february 2004 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
Go to today