I am trying to draw a shape's reflection using Cocoa. I have already applied an NSAffineTransform and redrawn the shape successfully, but now I can't figure out how to draw an alpha mask over it. I'm using an NSCompositeDestinationOut
operation, but it's giving me an unwanted result:
I'm not exactly sure how to fix this - I need to make it so the gradient acts only as an alpha mask and is not actually displayed. Am I using the wrong compositing mode?
Thanks! Here's the gradient code if needed:
- (void)fadeOutRect:(NSRect)rect {
[NSGraphicsContext saveGraphicsState];
[[NSGraphicsContext currentContext] setCompositingOperation:NSCompositeDestinationOut];
NSGradient *gradient = [[NSGradient alloc] initWithColorsAndLocations:
[[NSColor blackColor] colorWithAlphaComponent:0.5], 0.0,
[[NSColor blackColor] colorWithAlphaComponent:1.0], 0.8, nil];
[gradient drawInRect:NSMakeRect(rect.origin.x, rect.origin.y + rect.size.height - ( PILL_HEIGHT * 2 ),
rect.size.width, PILL_HEIGHT) angle:270];
[NSGraphicsContext restoreGraphicsState];
}