PDA

View Full Version : Cocoa: Inspector with multiple windows


AnotherJake
2004.11.12, 12:26 PM
I'm still working on my level editor. I have an inspector window which looks very similar to the inspector in IB. Right now I have it only inspecting sprites and they all have similar info so that works great. Now I want to add my terrain to the inspector but it's quite a different beast so all the info for the sprite inspector is useless. How would I go about changing the window being displayed for the inspector like InterfaceBuilder does?

I looked into the InterfaceBuilder nibs themselves and they make a separate window nib for every different type of inspector. The only thing that doesn't get included in those nibs is the selection pop-up at the top. I wasn't able to find the nib that contained that pop-up, so I suspect it may be created programmatically and the custom info inspector somehow attached below it. I suppose it could also be the other way around with the pop-up programatically added on top. Maybe they're just replacing the info window every time? I somehow doubt that. I tried a mamsam search and an apple search and a google, but no luck so far. Any ideas?

ThemsAllTook
2004.11.12, 01:04 PM
One thing I've heard you can do is create an NSTabView with invisible tabs, and programatically switch between them. I haven't actually tried this myself, but it seems like it would work...

- Alex Diener

DoG
2004.11.12, 01:13 PM
The NSTabView method works, but its sometimes a pain in IB. Another thing you can do is create NSView instances in the nib and add/remove them to/from the window as necessary. I have chosen the latter approach lately, while I previously used NSTabViews. The tab views are sometimes a pain to edit in IB.

Now I have smoothly resizing inspector windows :D

AnotherJake
2004.11.12, 01:34 PM
I thought about doing the tabView idea after stumbling across it at mamasam this afternoon. My first thought was to do it using views but I haven't experimented with it yet so I don't exactly know how that'll work, although I have a pretty good idea. I'm glad to hear it works well for DoG. I'd still like to know how IB does it but the view direction seems solid. Besides, views are well encapsulated and that should allow adding and changing new ones in the future without dealing with the myriad connections you'd have in a tab view. I'll give it a try.

Thanks!

AnotherJake
2004.11.12, 02:51 PM
Oh yeah, the views work great! I love Cocoa :love: But now I'm jealous DoG, how do you get the smoothly transitioning resizes? I have them automatically resizing between views but it's just a blink to one size or the other; it works well though. Is there a setting I can do or does it need to be done programmatically?

DoG
2004.11.13, 06:30 AM
- (void) setWindowToContentSize: (NSSize) size
{
NSRect winRect = [[self window] frame];
size.height += 16;
NSPoint offset = NSMakePoint(0.0f, winRect.size.height - size.height);
winRect.size = size;
winRect.origin = SEAddPoints(winRect.origin, offset);
[[self window] setFrame: winRect display: YES animate: YES];
}


The only problem with this is that you have to set the frame of the window, as opposed to the content rect. If you find a better way for making things fit, let me hear of it.

SEAddPoints() is just a vector add.

AnotherJake
2004.11.13, 12:15 PM
That's real slick! Thanks DoG. I looked through NSWindow and somehow missed "animate".