views:

420

answers:

3

Is there any way I could dim my NSWindow (basically putting a black transparent layer over top of it that you cannot click through) and then layer a custom NSView on top?

+1  A: 

You could create an additional NSView which contains your custom NSView. This new NSView would simply draw the black transparent layer in its drawRect and capture all events to avoid them being passed through to the window.

nall
I have this method working fully right now, only one thing I need to know. How do I capture all events?
macatomy
A great discussion of the basics of NSView event handling is here: http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/EventOverview/EventHandlingBasics/EventHandlingBasics.html
nall
+2  A: 

A more compartmentalized way would be to make a borderless window containing the black view and the custom NSView, and make that a child window of the window you want to “dim”. Then use NSViewAnimation to fade the window in and out.

You will, of course, need to handle keeping their sizes matched if the “dimmed” window is resizable.

Peter Hosey
+1  A: 

You could just set the background color of your NSWindow the black and change the opacity to your liking.

Andrew Johnson
Tried this and it works, but I need to put stuff on the transparent view so I decided to go with a separate NSView.
macatomy