• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Clicking through a NSView with CALayers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Clicking through a NSView with CALayers


  • Subject: Re: Clicking through a NSView with CALayers
  • From: Rowan Nairn <email@hidden>
  • Date: Sun, 26 Apr 2009 14:29:12 -0700

Thanks for the pointers.  I actually figured out a way to do it.  If
you [NSView setWantsLayer:NO] and render the layer yourself like
so.....

- (void)drawRect:(NSRect)dirty {
	CGContextRef ctx = [[NSGraphicsContext currentContext] graphicsPort];
	CGContextClipToRect(ctx, NSRectToCGRect(dirty));
	[[self layer] renderInContext:ctx];
}

...then the transparent pixels end up being transparent to clicks too!
 Can't say I understand what's going on here exactly and I'm guess I'm
using twice as much graphics memory as I need to now but it works.

Rowan

On Sun, Apr 26, 2009 at 12:37 PM, Bill Cheeseman <email@hidden> wrote:
> On Apr 26, 2009, at 2:09 PM, Rowan Nairn wrote:
>
>> So the little detail is this:  I
>> don't want to make my whole window transparent to mouse events.  There
>> are bits of my window on which I want to detect clicks.  Those are the
>> bits that I've drawn on.  I want the bits I haven't drawn on, the
>> visually transparent bits, to ignore clicks.
>>
>> When I use [NSView drawRect:] this works as expected - any pixel that
>> is visually transparent is also transparent to clicks.  However when I
>> use a layer (either hosted or backed) the whole area intercepts
>> clicks, whether visually transparent or not.  I'm starting to think
>> there's no way around this so I might just go back to [NSView
>> drawRect:] even though it makes the animation slower.
>
> As far as I know, there is no simple way to do that without drawing (and I
> didn't know you could do it with drawing).
>
> It occurred to me, however, that you could use Quartz event taps to do this.
> Event taps let you intercept clicks globally, in any application, and modify
> them or take other action before you pass them along. You could intercept
> every mouse event at the global session level (before it is assigned to an
> application); determine whether its screen location is in your application's
> window, and which part of that window; set clickthrough on or off in your
> window depending on whether that area is transparent; and then send the
> click along. It would automatically go to your application or the
> application under it, depending on your window's clickthrough setting. I
> believe this could be made to work with mouse dragged events as well as
> click events.
>
> You can read about event taps in Apple's "Quartz Event Services Reference"
> document, and play with them using my free utility, Event Taps Testbench, at
> <http://prefabsoftware.eventtapstestbench>.
>
> Event taps are complicated if you aren't familiar with them, so if you
> already have a drawing solution maybe that's the best bet.
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Clicking through a NSView with CALayers
      • From: David Duncan <email@hidden>
References: 
 >Clicking through a NSView with CALayers (From: Rowan Nairn <email@hidden>)
 >Re: Clicking through a NSView with CALayers (From: Rowan Nairn <email@hidden>)
 >Re: Clicking through a NSView with CALayers (From: Rowan Nairn <email@hidden>)
 >Re: Clicking through a NSView with CALayers (From: Bill Cheeseman <email@hidden>)
 >Re: Clicking through a NSView with CALayers (From: Rowan Nairn <email@hidden>)
 >Re: Clicking through a NSView with CALayers (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Query regarding cursor change
  • Next by Date: Re: Why is NSString->FSRef so hard?
  • Previous by thread: Re: Clicking through a NSView with CALayers
  • Next by thread: Re: Clicking through a NSView with CALayers
  • Index(es):
    • Date
    • Thread