I have a transparent NSView
on a transparent NSWindow
. The view's drawRect:
method draws some content (NSImage
s, NSBezierPath
s and NSString
s) on the view but leaves parts of it transparent.
Clicking on the regions of the view that have been drawn on invokes the usual mouse event handling methods (mouseDown:
and mouseUp:
).
Clicking on the transparent areas gives focus to whatever window is behind my transparent window.
I would like to make parts of the transparent region clickable so that accidentally clicking between the elements drawn on my view does not cause the window to lose focus.
NSView
's hitTest:
method. Found that hitTest:
was only called when clicking on a non-transparent area of the view.NSView
's opaqueAncestor
method. Found that this was not called when clicking on any part of the view.[NSColor clearColor]
in the drawRect:
method, and with an almost-but-not-quite-transparent colour. This had no effect.NSTrackingArea
class. This appears to only add support for mouseEntered:
, mouseExited:
, mouseMoved:
, and cursorUpdate:
methods, not mouseUp:
and mouseDown:
.I had the same problem. It looks like [window setIgnoresMouseEvents:NO]
will do it.
(On Lion, at least. See http://www.cocoabuilder.com/archive/cocoa/306910-lion-breaks-the-ability-to-click-through-transparent-window-areas-when-the-window-is-resizable.html)
As far as I know, click events to transparent portions of windows aren't delivered to your application at all, so none of the normal event-chain overrides (i.e -hitTest:, -sendEvent:, etc) will work. The only way I can think of off the top of my head is to use Quartz Event Taps to capture all mouse clicks and then figure out if they're over a transparent area of your window manually. That, frankly, sounds like a huge PITA for not much gain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With