RE: Clearing an NSView
RE: Clearing an NSView
- Subject: RE: Clearing an NSView
- From: "Phil Barrett" <email@hidden>
- Date: Wed, 25 Jul 2001 17:17:10 +0100
>
The normal fill and stroke operations composite the color over whatever
>
is there before (and thus drawing completely transparently does
>
nothing). Instead you want to copy the color over the bounds, ignoring
>
whatever was there before. To do this you need to use a different
>
operation: the copy operation.
>
>
[[NSColor clearColor] set];
>
NSRectFillUsingOperation(bounds, NSCompositeCopy);
No dice. I don't get to see through to the view beneath - all I get is
black. NSCompositeClear has the same effect.
The problem is that although the window's contents are retained, the views'
contents separately are not.
My code structure is such that I don't draw when I get a drawRect message. I
draw when I know I'm ready, and only draw what I know needs to be drawn. And
because the data shown in the lower view hasn't changed, I don't redraw it,
so the lines drawn in the overlay view last time are still visible in the
window.
The upshot is: clearing the overlay view is not what I needed to to at all.
What I need is a mechanism that'll let me draw a changing overlay (a drag
box, for example) without having to re-render the image beneath. On IRIX I
use an X/GL overlay plane. On Windows I use a pair of DirectX surfaces and
blit from the main surface into the overlay surface, then draw, and then
blit from the overlay surface onto the screen. Surely there's a way to do
this in the wonderful world of Cocoa and Quartz?
I suppose I could put a borderless transparent window over the view, but
that would be difficult to maintain (keeping it in the right position and in
the z-order immediately above the view's window) and probably hard to pass
events through.
Or I could have my main view render to an NSImage and draw that to the
screen rather than re-rendering.
Any thoughts?
Phil