views:

236

answers:

2

I have an NSWindow with 2 NSViews (an NSSplitView and a custom NSView). Accessing the data to populate these views can take some time. During this period, I'd like to gray out the content of these views.

My first approach was to have a black third NSView that covered the other 2 and achieve the graying out effect by changing its alpha value. However I've since learned having a hierarchy with sibling views is undefined.

What is the best approach here?

  • Cache the NSBitmapImageRep of the 2 views, then replace them with the 3rd view, using the cached image(s) as background
  • Set the alpha value for each view separately (still not quite sure how to get the black background for the graying effect)
  • Something I haven't considered
+2  A: 

I'd teach the views how to draw themselves in a disabled state, but there are other suggestions here:

http://stackoverflow.com/questions/466249/how-can-i-darken-everything-displayed-in-a-single-nsview

Azeem.Butt
+3  A: 

I'd use a child window. Set its content view to a plain black view (hopefully with status and progress information in subviews), and its alpha value to the desired fade-out, and add it as a child window of the window whose content you want to fade out.

Peter Hosey
Wow. I had never looked into windows being children of windows. That's perfect, thanks!
nall
A child window is a bit of overkill for this situation. Child windows are meant for things like NSDrawers or palettes that attach to a window's edges.I'd go with NSD's suggestion below, and implement a disabled state in your views so they draw differently when inactive. That's the way the Appkit handles disabled controls.
NSResponder
well I also want to overlay a progress bar, so this solution works a bit better in that case
nall
Adding a disabled state is a good idea, but they're not mutually exclusive.
Peter Hosey