Transparent rounded window but with opaque controls - cocoa

I am trying to make a HUD with a transparent rounded window with opaque controls as is commonly seen in apps such as Xcode popups, the native volume control, etc.
I'm using the technique detailed here: How to implement HUD-style window like Address Book's "Show in Large Type"
but this renders controls in the view transparent. I've tried setAlphaValue:1.0 on the controls but that has no effect. Searches for other solutions point to Matt Gemmell's RoundedFloatingPanel component. I can't open the project in Xcode 4, but looking at the code as far as I can tell the only difference seems to be in Matt's code he sets the alpha of the window to 1.0 and uses a transparent fill for the NSRect in the view. I tried this but still end up with transparent controls.

So unsurprisingly, Matt Gemmell's code works just fine and I had made a mistake. I forgot that I was also messing with the alpha of the window elsewhere in my code in order to make it fade out on close.
To to sum it up for others running into this issue, if you set the alpha on the NSWindow the controls in that window will also be transparent. Instead set the alpha on the NSBezierPath fill color in the NSView. Just like Matt Gemmell's code does. :)

Related

DirectDraw + Layered window color key?

I'm creating a window with WS_EX_LAYERED and setting a color key to it using SetLayeredWindowAttributes(). I can verify that this color key indeed creates a transparent patch in the window by drawing a simple rect using FillRect() inside the window. This doesn't work however when I'm drawing in the window using DirectDraw. I'm creating an IDirectDrawSurface7 on the window and I'm Blt()ing some pixels to it. some of the pixels are colored with the color key, but I don't see them as transparent, they just appear in the color key.
Is there something inherent in DirectDraw surface that conflicts with layered window color keying?
When i'm setting an alpha value using SetLayeredWindowAttributes(), that seem to work fine with the DirectDraw surface and it does indeed appear translucent.
I don't know if you've seen this but this paragraph from the article posted below looks kinda like what you are looking for.
The hWnd is the window handle of a window with a WS_EX_LAYERED style flag. The dwFlags parameter can have one or both of LWA_COLORKEY and LWA_ALPHA. If a LWA_COLORKEY flag is used, the crKey parameter is the transparent color key. If a LWA_ALPHA flag is used, the bAlpha parameter is the constat source alpha value. **Only top-level windows can be layered windows.**
I think its that last sentence that is the problem here. The source is a partial of a book on google books. You can read it with some code detail examples found here:
http://books.google.com/books?id=-O92IIF1Bj4C&pg=PA720&lpg=PA720&dq=WS_EX_LAYERED+%2B+DirectDraw+color+key&source=bl&ots=SyWKE3aimb&sig=DXbshrEk2tN17h7CtWdMmAkHlAo&hl=en&sa=X&ei=7_JcVKSyFMukNrumgMgB&ved=0CCkQ6AEwAg#v=onepage&q=WS_EX_LAYERED%20%2B%20DirectDraw%20color%20key&f=false
I will also include the following links that talk about a little about it, although not in nearly the same amount of detail:
http://web.cs.wpi.edu/~matt/courses/cs563/talks/cbyrd/pres3.html
http://msdn.microsoft.com/en-us/library/windows/hardware/ff567254(v=vs.85).aspx
I don't know if this will answer your question, but I hope it helps a little bit. Cheers.

Toggle NSToolbarItem between Black and Blue

I'd like to make an NSToolbarItem with a custom image which toggles between Black and Blue, like the icons at the top right of Xcode 5's main window.
Peter Hosey suggested in this answer that it was as simple as setting the image to be a template, but I haven't found that to be the case. I set it to a template image, and that causes it properly render the dark gray gradient, but it doesn't render in blue when toggled.
I uploaded a very simple example of what I've done, here. If someone could tell me how to change it to light up the NSToolbarItem in blue, as Xcode does, then I'd very much appreciate it.
You mostly have everything you need in place, with the exception of providing an NSButton object using the style NSTexturedRoundedBezelStyle, with which you’ve associated your image.
↳ modified example project here
⌘ OS X Human Interface Guidelines | Window-Frame Controls

NSOpenGLView: NSWindow resizeIndicator is missing

I am currently creating a simple Cocoa Window programmatically with and NSOpenGLView attached to it. Anyways if I create the windows style mask with with NSResizableWindowMask and [m_window setShowsResizeIndicator: YES ]; I'd expect to see the resize indicator in the bottom right. The resizing works, but the indicator does not show at all. I also checked simple NSOpenGLView examples and they also have the same problem so I am pretty certain that it's not a bug in my code but rather a problem with a view that has 100% width and height. Is there any way to position the indicator ontop of the NSOpenGLView?
Short answer: NSOpenGLView will cover the resize indicator, no matter what you do. You can fake it positioning a custom texture at the bottom right corner of your View.
See this thread for detailed discussion and some example codes:
http://www.idevgames.com/forums/thread-6160.html

Windows Vista/7 glass completely broken?

I'm trying to get the media player glass effect for an application, but I'm facing roadblocks all around. Is it me, or is it the API?
I started by calling:
MARGINS margins = { -1, -1, -1, -1 };
HRESULT result = ::DwmExtendFrameIntoClientArea(m_hWnd, &margins);
And erasing the background to black on:
OnEraseBkgnd
Everything was fine until I added an edit box. With EditBox, places where black text appears are replaced with glass. The problem is blown out of proportion with more advanced controls like ComboBoxEx and that like. Those start to look like mess.
The bright side with this approach is that the alpha blended images look alright. And are gradually blended into the glass.
The solution for edit boxes seems to be using WS_EX_LAYERED with LWA_COLORKEY and using some awful color for glass masking, and erasing the background to that color. Unfortunately this breaks other things. The alpha blending on icons looks super ugly with shadows blended to radioactive green, and the glass itself becomes click-throughable, even though I don't have a WS_EX_TRANSPARENT style on the window.
The third suggestion is sort of custom composition with GDI+, but that seems to be a bad approach, since GDI+ is a software fallback, and I can't find a way how to render EditBox or ComboBoxEx to an image that I could use for composition later.
Am I missing something?
The sources at SO also seem to face the same problems:
link1
link2
Kenny Kerr wrote an excellent article on displaying controls on glass, using edit controls as an example:
http://weblogs.asp.net/kennykerr/archive/2007/01/23/controls-and-the-desktop-window-manager.aspx
The simple answer is, you cannot do this.
All the standard controls render themselves with normal GDI calls. Normal GDI calls are alpha unaware and mostly set the alpha channel to zero.
The more complicated answer is, you can: There are some samples on the net where standard controls are mixed with aero glass. They fall into two basic categories:
WinForms (.NET) samples. WinForms don't actually use the native controls - the WinForms controls are all rewritten versions that, amongst other features, blit using alpha aware routines. This example is depressingly simple and makes me realize how much Microsoft hate native developers.
Subclassed samples: The only way to get the regular/native controls to paint on aero glass is to sublclass the controls, catch WM_PAINT messages to create a DIBBitmap, call WM_PRINT to render the controls content onto it. Use the DWM functions to repair the alpha channel data. Paint the resulting alpha'd bitap yourself using AlphaBlend.
This article on CodeProject contains a reference implementation that subclasses most of the standard controls rather well.
Try changing your text/foreground color on controls like the edit box to something "almost black" (like #010101). Then you should be able to skip the other rendering issues except alpha transparency for images/icons.
Edit: Drawing other stuff - might be some weird approaches to handle compatibility, but then again classic apps aren't glass themed by default ... don't know. Just try to avoid drawing stuff yourself, if possible.

how to customize the color of frame and title area of HUD panel

I need to let the user to customize the HUD window appearance. Is there a way to change the frame and the title area color of HUD window? There is an API for changing a background color of the window, but title and the frame stay semitransparent black. I'd like to avoid drawing these areas by myself.
Thanks,
Nava
In case nobody knows, I found a couple of links that do it. One of them is a Synapse project, which shows how to use private headers and draws the window by itself. Definitely it's not straight forward and IMO should be allowed by native interfaces. Many thanks to the guy that wrote it:
Synapse project

Resources