I have nsview and I use draw rect to draw an image for the background. It also has 3 nsbuttons sub. The problem is that whenever the mouse falls over the button, the rest of the buttons disappear. But when I remove the draw draw method, this does not happen. Therefore, I assume this is due to the draw rect method for drawing images.
How can i avoid this? Thank.
EDIT: Ok, I figured where the problem is. Basically, I have NSMenuItem, and I put 3 buttons in it. But at NSMenu, at the top, there is a 4 pixel spacer. Therefore, basically, to remove this add-on, I used the solution provided here:
Gap above the user view NSMenuItem
From the solution there is a line in the drawRect method:
[[NSBezierPath bezierPathWithRect:fullBounds] setClip];
The moment I delete this line, and the button behaves correctly. But then the gasket on top does not go away.
Here is my drawRect:
- (void) drawRect:(NSRect)dirtyRect {
[[NSGraphicsContext currentContext] saveGraphicsState];
NSRect fullBounds = [self bounds];
fullBounds.size.height += 4;
[[NSBezierPath bezierPathWithRect:fullBounds] setClip];
NSImage *background = [NSImage imageNamed:@"bg.png"];
[background drawInRect:fullBounds fromRect:NSZeroRect operation:NSCompositeCopy fraction:100.0];
[[NSGraphicsContext currentContext] restoreGraphicsState];
}
source
share