PDA

View Full Version : Convert NSPanel to HUD?




Darkroom
Nov 11, 2007, 07:59 PM
i read something quite vague about what's called and NSHUDWindowMask, and i'd really like to know if it's possible to mask the NSColorPanel? it's unfortunate that i can't include the built-in NSColorPanel to my NIB, where it would be a few clicks to convert the panel to a HUD, so it would have to be done manually... any thoughts?



kainjow
Nov 12, 2007, 10:40 AM
Generally when you want to get custom window styles in Cocoa that aren't available via a checkbox in IB, you create an NSWindow subclass and override the initWithContentRect:styleMask:backing:defer:screen: method.

However, since NSColorPanel's window is not owned by you or created by you, it'd be tricky to override it. You could probably do it with some reverse engineering (http://www.culater.net/wiki/moin.cgi/CocoaReverseEngineering) though.

Darkroom
Nov 12, 2007, 11:50 AM
oh that's too bad... but at least now i know why i couldn't get styleMask working on the window... hopefully i can get it to work with the document you sent me... thanks.

robbieduncan
Nov 12, 2007, 12:06 PM
I've not tried this an am pretty tired so may not be thinking straight, but could you not do something like this:



NSColorPanel *cp;
NSPanel *myPanel;

cp = [NSColorPanel sharedColorPanel];
myPanel = [[NSPanel alloc] initWithContentRect:[cp contentRectForFrame:[cp frame]] styleMask:NSHUDWindowMask backing:NSBackingStoreRetained defer:YES];
[myPanel setContentView:[cp contentView]];


I think this should create a new panel the same size as the color panel with the correct style mask and then drop the content view from the real color panel into our new one. Of course this will probably look all wrong as the dropped in content view will not be HUD style, but it's a start.

I've not tried this mind...

kainjow
Nov 12, 2007, 02:06 PM
robbieduncan, I tried playing around with your method, but it gets screwy if you don't use the NSColorPanel class.

Using poseAsClass: (marked as deprecated in Leopard), I got it to work:

@interface Blah : NSColorPanel {}
@end
@implementation Blah
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
{
windowStyle |= 8223;
return [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
}
@end


@implementation Controller

+ (void)initialize
{
[[Blah class] poseAsClass:[NSColorPanel class]];
}

- (void)awakeFromNib
{
[NSApp orderFrontColorPanel:nil];
}

@end

As you can see, the the controls don't fit the HUD style. I didn't find in the documentation a style mask for HUD windows. It must be private? But I setup a HUD window in IB and figured it out was 8223, so that works. I also did a screenshot using NSTexturedBackgroundWindowMask, which looks much better.

robbieduncan
Nov 12, 2007, 02:26 PM
Wow, good work! As I said, I'd not actually tried the code, it just seemed to me like it should work. I suppose you need to pose as class to get the actions to link up correctly...

Darkroom
Nov 12, 2007, 02:48 PM
sweet! thanks a million everyone... and might i just say that the HUD NSColorPanel looks tasty... :D since i'm pretty new at all this still it's gonna take me a week to implement that into my code, but at least i now know it is possible... thanks again...

Catfish_Man
Nov 12, 2007, 05:55 PM
sweet! thanks a million everyone... and might i just say that the HUD NSColorPanel looks tasty... :D since i'm pretty new at all this still it's gonna take me a week to implement that into my code, but at least i now know it is possible... thanks again...

It'll take you a week to copy-paste some text?

Darkroom
Nov 13, 2007, 03:30 AM
It'll take you a week to copy-paste some text?

well, i though the process was more than simple cut/paste... and it wasn't entirely, i had to make it work with my own code, but yeah you're right, it actually took me about 2 minutes... :p

it's also very strange to see the color panel as a HUD window... such perversion! :p... if you resize the window to make it really large, and switch between the color modes, there are some geometric ghost shapes that are apparent... i suppose their placeholders?