Andrew M
Andrew M

Reputation: 4288

Drawing a Window at Coordinates or Drawing outside of NSStatus Item

I am trying to display something off the side of a NSStatusItem. I think I could do this in two ways:

Display a transparent window with the image I need at the coordinates of the mouse cursor.

OR

Use a custom NSStatusItem and move the controls/images in the view to the left so they are actually off the status item

The problem is, setting the NSRect frame negative (-200,0,100,50) doesn't seem to actually work. So, how can I render things outside of the bounds of the status item (think the CSS overflow property) or render a transparent window at specific coordinates?

Upvotes: 0

Views: 405

Answers (1)

ughoavgfhw
ughoavgfhw

Reputation: 39925

The system will prevent you from drawing outside the status item, but using a transparent window will work.

NSRect rect; //The location of the window
NSWindow *win = [[NSWindow alloc] initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
[win setOpaque:NO];

[win setBackgroundColor:[NSColor clearColor]];
//or
[win setContentView:myView];

Here, myView is a custom view which will be the background of the window. In order for the window to be transparent, you either have to set the background color to clear or use a custom content view which only draws where it is not transparent. You will probably want to use a floating window so that it stays on top. Be careful not to cover up something important because your window could intercept events intended for something underneath it.

Upvotes: 1

Related Questions