Lexandr
Lexandr

Reputation: 689

Drawing to transparent destination causes drawing artifacts

I have NSWindow:

_window = [[NSWindow alloc] init];
[_window setOpaque:NO];
[_window setBackgroundColor:[NSColor clearColor]];
[_window setStyleMask:NSBorderlessWindowMask];

And I have as its content view my custom view (without layer):

[_window setContentView:[[MyCustomView alloc] init]];

In drawRect: of my custom view I create bezier path that looks like system popup and fill with color.

- (void)drawRect:(NSRect)dirtyRect
{
    [NSGraphicsContext saveGraphicsState];
    [super drawRect:self.bounds];
    NSBezierPath *path = [self bodyShape];
    [self.backgroundColor setFill];
    [path fill];
    [NSGraphicsContext restoreGraphicsState];
}

and all looks great first time popover shows
until I move popover place indicator. After redrawing in window appears artifacts, while drawRect: of my custom view draws content rightdrawing with artifacts.
And when I draws content next time, this white triangle (see picture above) stay in same place in window and moves with window.Artifact moves with window
If I add to my view layer - all appears to be ok, but I can't add a layer.
If I fill my view with some solid color, there are no artifact.Fill with solid color
I suggest that Cocoa caches first bitmap. But I do not sure why this happens and how to fix this. Maybe someone know why how fix to it? Thanks.

Upvotes: 3

Views: 175

Answers (1)

Lexandr
Lexandr

Reputation: 689

I found it! The problem is that the window caches shadow around place indicator. I fix it with calling invalidateShadow method of NSWindow.

Upvotes: 3

Related Questions