If I read this correctly, you're hoping that you can erase some of the drawing done in your overlay view, just revealing the original drawing in your complex background view.
That won't work (with some caveats about layer-backed mode). All views draw into one flat buffer, called the window backing store. If your selection view draws solid black in a rect, that destroys the color information that the background view had drawn there. You can get the effect you want in layer backed mode (c.f. -[NSView setWantsLayer:]). Then each view has its own buffer, so your selection drawing doesn't wipe out the background drawing, it only covers it. You don't need to do anything funky with drawing outside of drawRect:, though. Just call setNeedsDisplay: on the parts of your selection view that need to be redrawn. This will not cause the background view to redraw. It's similar to using an overlay window, just easier. -Ken On Thu, Sep 11, 2008 at 2:09 PM, Chinh Nguyen <[EMAIL PROTECTED]> wrote: > How do you clear an NSView when drawing outside of drawRect:? > > I added and positioned a custom view on top another view > (addSubView:positioned:relativeTo:) that draws a complex image so that I can > draw selections in my custom view without having to worry about redrawing my > original image or using a cached image. Inside my mouseDragged: > implementation, I lock my custom view's focus, attempt to erase the view > using fillRect with clearColor (which doesn't work), draw my selection, then > unlock the focus. When that didn't work (and I tried returning yes and no > for isOpaque), I went ahead and just did a setNeedsDisplay:YES on my custom > view and just drew the selection in drawRect:. That works but there's a > noticeable lag while the mouse is being dragged. > > In Carbon, I was able to do the above by using an overlay and > CGContextClearRect(). The only thing I can think of to try next is to use > similar logic in Cocoa and to place the custom view in a borderless window > and use NSRectFillUsingOperation(rect, NSCompositeClear). I was hoping to > avoid having to do that and deal with keeping the two view's positions and > sizes in sync. > > -Chinh Nguyen > [EMAIL PROTECTED] > > _______________________________________________ > > Cocoa-dev mailing list ([email protected]) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com > > This email sent to [EMAIL PROTECTED] > _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
