NSTextView translucency

  • I have drawn some imagery in an NSView. A child of that NSView is a
    custom NSTextView. I would like the background of the text view to be
    translucent so that the fully-opaque text is overlaid atop the
    imagery in the parent NSView.

    I have appropriately overridden the text view's isOpaque to return
    NO. I have also overridden drawViewBackgroundInRect:to do nothing (so
    that a background is not drawn).

    This has the appropriate behavior in that the text is overlaid on the
    background imagery. However, the text drawing system is now
    overlaying text on top of previously rendered text as it is no longer
    able to "erase" the old text (because drawViewBackgroundInRect no
    longer does anything).

    My current strategy is to actually "erase" the rect passed to
    drawViewBackgroundInRect:. I've tried something like this:

    - (void)drawViewBackgroundInRect:(NSRect)rect
    {
    [ [ NSColor clearColor ] set ] ;
    NSRectFill( rect ) ;
    }

    The problem with this, obviously, is that it draws nothing, and the
    problem isn't fixed.

    I then tried something like this:

    - (void)drawViewBackgroundInRect:(NSRect)rect
    {
    [ [ NSColor whiteColor ] set ] ; //  Just so I know what color's set
    NSRectFillUsingOperation( rect, NSCompositeClear ) ;
    }

    I was hoping that this would draw "clear pixels"; i.e., set all
    pixels in rect to have a 0 alpha value, thereby erasing anything that
    was previously drawn in rect. Instead, I get black.

    Can anyone tell me how I can get Cocoa to draw "clear pixels" so that
    I can erase properly?

    Less importantly, why would it draw black?

    Regards,

        ~    Mike
            alephx01 (at) mac (dot) com
previous month october 2006 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
30 31          
Go to today