• 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: Speaking of tracking rects...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Speaking of tracking rects...


  • Subject: Re: Speaking of tracking rects...
  • From: Henry McGilton <email@hidden>
  • Date: Sun, 10 Sep 2006 07:50:01 -0700




On Sep 10, 2006, at 5:33 AM, Michael Ash wrote:

On 9/9/06, Dave Budde <email@hidden> wrote:
I am working on an app that has several (16 actually) tracking
rectangles for control points in a set of bezier curves. When
implementing the tracking mechanism for mouseEntered and mouseExited
I notice that tracking numbers start at 3 (at least for any
addTrackingRects in my code). What are the other 2 tracking rects for?


And is there a way to reset the trackingNumber?  It just seems to
keep going up and up as I run the code.  I assume it will wrap and
not fault as I overflow the integer size.  Someone speak up if this
isn't true.

So I'm using some modulo arithmetic:

mTrackingNumber = ([theEvent trackingNumber] -3) % 16;

to figure out which trackingRect the mouse entered.   This seems a
bit odd.  But does work.

Reiterating what Michael writes below: you should not write code based on assumptions made by observing a limited snapshot of an appkit object's behaviour. It's likely to change in the future. The Tracking Rectangle management and the NSTrackingRectTags are abstractions and should stay that way.


No, no, no, no, and also no. Did I mention no?

The tracking rect tag that's returned from addTrackingRect:... is not
documented to follow any behavior other than being unique. The system
would be perfectly fine in returning 42, then 1000000, then -1, etc.
By assuming they start at 3 and work up, you're relying on an
implementation detail that could change at any moment.

Better to maintain some kind of array or dictionary mechanism to keep 'track' of your racking rects, or use the user data mentioned below.


The correct way to figure out which tracking rect the mouse entered is to use the userData: argument of this method. Pass it something handy and identifying-like, then you can get it back out of the NSEvent when things come in and do something with it. If you absolutely must use the tracking rect tag itself, use it as the key to an NSDictionary which maps arbitrary tags to the useful data you need.

Further note that Tracking Rectangles, while added to a NSView, are actually managed by the view's window. When a view moves or is resized, you can use the tracking rect tags to remove the tracking rect and then re-instate the tracking rect.

I suspect that long before the tracking rect tags wrap around
at around two billion tags, your application will have run into
other system resource limitations . . .

    Cheers,
        ........  Henry


===============================+============================ Henry McGilton, Boulevardier | Trilithon Software Objective-C/Java Composer | Seroia Research -------------------------------+---------------------------- mailto:email@hidden | http://www.trilithon.com | ===============================+============================


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Speaking of tracking rects... (From: Dave Budde <email@hidden>)
 >Re: Speaking of tracking rects... (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: Bind to single table selection but not multiple?
  • Next by Date: Recent menu items and SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar)
  • Previous by thread: Re: Speaking of tracking rects...
  • Next by thread: Re: Speaking of tracking rects...
  • Index(es):
    • Date
    • Thread