A Transparent window without the things inside being transparent - objective-c

I have been looking all over the internet to find out how to make a window where the window itself isn't there its just a image or a button, for example a free floating image not attached to any windows. I did find the apple roundTransparentWindow page, but it is a bit confusing and really all I would like to know is a image or bu

Creating a completely transparent window is a multi-stage stage process:
Create the window using the style NSBorderlessWindowMask if you are doing it in code. If you are creating the window in a XIB then in Xcode uncheck all the boxes under "Controls" and "Appearance" in the Inspector.
In code set the window's opaque property to NO: [window setOpaque:NO]
In code set the window's background color to nothing: [window setBackgroundColor:[NSColor clearColor]]
Remember that the window will have no window controls (close, resize etc.) the user can interact with - you must manage all these things in your own code.

Related

Sub views in HUD Panel

I am working on OSX 10.10
I am facing a strange problem of sub view colors getting inverted for HUD Panel.
For example the button when set to default button looks right in Xib file but when executed the look and feel of button is modified by the HUD panel.
I am having a HUD Panel in my Xib file as follows
But when executed the button looses its default button status. It looks as follows
How do I maintain the look and feel of the button after execution. User is not able to judge which action will be the default action due to this look and feel
Try
_defaultButton.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
Interface Builder follows a set of rules but these rules are not context-dependent. The context I'm talking about is "being displayed in a HUD Panel".
The rule applied in this case is "draw a blueish button in Interface Builder if the button is a default button" even if it's not always what happens (cf. what you're seeing in your second screenshot).
I don't know since which OS X version it's working like that, but now controls in HUD Panels are displayed with a different style (which does not have a special color for default button).
You can confirm this Interface Builder comportment by adding a simple NSTextField in your HUD Panel, it'll draw with a white background in Interface Builder but it will have a black background when running with a gray focus ring.
Interface Builder:
OS X 10.10:
I've never found a way to disable this special styling for controls in HUD Panel but several workarounds (the default button is still working correctly even if not having a special color).
The special styling only occurs when your HUD Panel have a title bar.
self.panel.styleMask = (NSHUDWindowMask | NSTitledWindowMask | NSUtilityWindowMask | NSNonactivatingPanelMask);
If you remove the title bar, it'll display without any special styling:
self.panel.styleMask = (NSHUDWindowMask | NSUtilityWindowMask | NSNonactivatingPanelMask);
At this point, you can implement and draw your own title bar in the panel and mimic the default one. I don't really like this approach because first it's a lot of work for a simple button and the custom styling of controls make them prettier and more easy to read in a HUD Panel.
Another solution was the 'VLC' way. They use HUD Panels but their controls don't have any special styling. They're using BGHUDAppKit which was released when Apple provided HUD Panel without any special controls to go with it. They use it to force the bluish style instead of the greyish one which are now used by default in HUD Panels.
I didn't really like this approach too, I didn't want to add a library for a simple button, library not updated since 2011.
What I end up doing was drawing a custom button (with a simple subclass) for default buttons in a HUD Panel. This solution is quick and allow you to choose the color you want for default button in a HUD Panel (blueish may not be the best for a HUD Panel, your call).

Creating semi-transparent, round cornered with border Window in Cocoa?

What would be the best approach for creating a Window that is semi-transparent, has round corners and an outline around its border and the arrow, but without the the title bar and buttons.
The window will pop up from the Menu Bar when a use clicks on the menu bar icon.
I'm looking to have an effect similar to the "Applications" and "Downloads" windows:
I guess I will need to do the drawing myself. But I'm wondering what's the best way to do this and whether there is anything already built into Cocoa that can minimize the effort? Or maybe a 3rd party project that has already done that (couldn't find anything exactly like that)?
Thanks.
You can create your window with
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
with a style-mask of NSBorderlessWindowMask which will give an unadorned window. Its how the Dock does its mechanics too.
Note that you must init with this style , you can't change an already init'ed windows style.
Place a custom NSView via the contentView accessor with your desired background custom drawing at the top of the windows view stack.
You might need also to setOpaque to NO
What you are looking for has been done a lot. Too much really.
The classes you want to look into are as follows.
NSStatusItem
This is something that appears in the status bar section of the menu bar to the right side.
NSMenu
If you want this from a menu in the application menus, you'll need to do some clever things with views in menus.
NSWindow
As the other poster notes a borderless window is one way to achieve this.
NSPopover
This is another way. Combined with the above, a fancy technique is to use a clear window called a cover window then, when clicking on the menu or status menu, invoke a popover from a point below that in the clear cover window.
That should be enough to get you started with what you should look into.
Beyond that, peruse the Mac App Store and also look at cocoacontrols.com and GitHub.

Not able to drag my transparent window

For my OSX application. I have a main window with some output. On a button click a new window will pop up with a drawing on its NSView. I am making this second window transparent by setting its background color as transparent with RGB values as 0.0 and also alpha 0.0. So now my second window just have this random drawing on a transparent background. I have put both the windows in the same xib file.
My problem is that, the transparent window with a drawing that pops up is not draggable. I have overriden mouseDragged: (NSEvent *) in my secondwindow:NSWindow class. But still it is not draggable. This method should work when I try to drag my transparent window using trackpad right ? Any help would be very much appreciated . Thanks in advance
Transparent window is not draggable. The only option is to add something like imageview with image, now click and drag the imageview. Total transparent will move.

INAppStoreWindow Toolbar

I was wondering how I could add a toolbar in the titlebar using INAppStoreWindow. I succesfully added InAppStoreWindow in my application but I was thinking how to add a toolbar like the 'AppStore.app' in the center of my titlebar using INAppStoreWindow.
Nowhere on the internet nor stackoverflow has a similer topic about this toolbar inside this INAppStoreWindow method. I hope somebody could tell me if this is possible and how as I can't find any examples.
If you create an NSView with the contents of what you want to be on your window's titlebar, and have IBOutlets to both your window and that view, it can be done in 2 lines of code.
(In this case, the view is titleView and the window is theWindow)
//Make the titlebar view the same size
[self.titleView setFrameSize:self.theWindow.titleBarView.frame.size];
//Add the view to the window's "titleBarView"
[self.theWindow.titleBarView addSubview:self.titleView];

Is it possible to have focus on an NSPanel without losing focus of other background windows?

I have a custom NSPanel: http://cl.ly/K8SY
I have it set to NSPopUpMenuWindowLevel, the level at which I want it to stay as. An example is the spotlight menu, when you click on it any other focus in the windows in the background remains yet you can still type into the search field.
I open it with:
[window orderFront:nil]
but this doesn't focus on the window as well as the background.
Is it possible to achieve this? If so, how?
You need to use the -[NSWindow makeKeyAndOrderFront:] call instead.
NOTE: keyboard focus can only be directed at one view in one window. Cocoa's notion of mainWindow and keyWindow can be different windows, but its only the first responder within the keyWindow that accepts keyboard input.