FROM : John C. Randolph
DATE : Thu Dec 02 22:22:18 2004
On Dec 2, 2004, at 1:14 PM, Lemont Washington wrote:
> I'd like to know whether its more efficient to use tracking rectangles
> to determine if the mouse is over a certain region or to do it
> manually by checking the location in a loop during your NSView's
> mouseEntered method. For instance, let say you had a view with 50 or
> 60 that can be clicked or hovered over, this would require you to at
> least loop over each item in your array looking to see if the mouse
> pointer is within the bounds of each item in the array. The Sketch
> AppKit Demo does this I believe. I'm wondering if using Tracking
> Rectangles is more efficient.
>
> For example it could possibly subdivide your view using a BSP tree or
> similar data structure so that lets say it determined that the mouse
> was in a region that is on one half of the screen but not the other,
> it could discount at least half the items to check against. Is
> something like this overkill? Does the Apple implementation of
> tracking rects use a simple loop for bounds checking ors something
> more efficient speed wise?
What tracking rects give you is convenience.
I doubt that speed would be any kind of an issue unless you're checking
many hundreds of rects. Testing whether a point's in a rect is a
pretty quick operation.
-jcr
John C. Randolph <<email_removed>> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
DATE : Thu Dec 02 22:22:18 2004
On Dec 2, 2004, at 1:14 PM, Lemont Washington wrote:
> I'd like to know whether its more efficient to use tracking rectangles
> to determine if the mouse is over a certain region or to do it
> manually by checking the location in a loop during your NSView's
> mouseEntered method. For instance, let say you had a view with 50 or
> 60 that can be clicked or hovered over, this would require you to at
> least loop over each item in your array looking to see if the mouse
> pointer is within the bounds of each item in the array. The Sketch
> AppKit Demo does this I believe. I'm wondering if using Tracking
> Rectangles is more efficient.
>
> For example it could possibly subdivide your view using a BSP tree or
> similar data structure so that lets say it determined that the mouse
> was in a region that is on one half of the screen but not the other,
> it could discount at least half the items to check against. Is
> something like this overkill? Does the Apple implementation of
> tracking rects use a simple loop for bounds checking ors something
> more efficient speed wise?
What tracking rects give you is convenience.
I doubt that speed would be any kind of an issue unless you're checking
many hundreds of rects. Testing whether a point's in a rect is a
pretty quick operation.
-jcr
John C. Randolph <<email_removed>> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
| Related mails | Author | Date |
|---|---|---|
| Lemont Washington | Dec 2, 22:14 | |
| John C. Randolph | Dec 2, 22:22 | |
| Ricky Sharp | Dec 2, 22:30 |






Cocoa mail archive

