• 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: Do tracking rectangles move along with their views?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Do tracking rectangles move along with their views?


  • Subject: Re: Do tracking rectangles move along with their views?
  • From: Henry McGilton <email@hidden>
  • Date: Sat, 23 Apr 2005 14:53:04 -0700


On Apr 22, 2005, at 6:24 PM, Ken Tozier wrote:

I'm getting some squirrely tracking rectangle behavior in a custom
view in which the location of subviews can change depending on the
containing view width and height.


Is it necessary to void all old tracking rectangles and create new
ones every time a subview changes location? If you have hundreds of
subviews (which my class could easily have) having to void everything
every time the window changes by even a pixel seems awfully wasteful.

Well, the computer is doing the work . . .

Basically, although the tracking rects are set outside of the views,
it's actually the views' *window* that manages the tracking
behaviour.

So if views move around or change size for any reason, you have
to reset the tracking rects.

Also having trouble figuring out what to supply to NSView's  
"addTrackingRect:toView:owner:userData:assumeInside:"; method.

If my understanding is correct (based on some code I developed through error and trial), the tracking rect for a given view is defined in terms of that view's coordinate system. The tracking rect mechanism then does whatever magic such that the window manages the rects from then on.

What type of rect are you supposed to feed this method? The subview frame translated to window coordinates? Containing view coordinates? I've tried both and when I manually draw the view rect using NSFrameRect() the resultant rectangles either never appear, are in the lower left corner of the window or appear below and to the left of where the subview appears in the containing view. The documentation isn't very clear on whether it expects the absolute position within the window coordinates or what it's looking for.

I had a view sub-class called Memo, and Memo contained three parts, Head, Body, and Base. The head contained images that would light up on mouseEnter. In Memo's initWithFrame method, I call super's initWithFrame, then set up the Head, Body, and Base instances, call their respective initWithFrame methods, and then add then as Memo's subviews.

Memo has methods to catch any resize or movement of itself to a
different position in the window's content view.  This seems to be
a similar case to what you describe as your situation, above.

In each case, the call  [self setHeadTrackingRects];  is issued.

So, in my Memo class I have this code:

- (void)setHeadTrackingRects
{
[head removeTrackingRect: closerTrackingTag];
closerTrackingTag = [head addTrackingRect: NSMakeRect(1, 0, 11, 11) owner: head userData: nil assumeInside: NO];


[head removeTrackingRect: colorpopTrackingTag];
colorpopTrackingTag = [head addTrackingRect: NSMakeRect(14, 0, 11, 11) owner: head userData: nil assumeInside: NO];
}


So, Memo, the superview of head, tells head to add tracking rects
for its light-up controls.  The two NSMakeRect calls in the above code
define the position of the light-up controls on a Head view in that
view's coordinate system.

The owner of the tracking rect is designated as a Head instance, since
it is that class which implements  mouseEntered  and  mouseExited events
to light up its controls.

I don't need user data in this case.  And, one can assume that the
cursor is not inside the tracking rect at the time that the rect is
set up.

I read the NSView documentation, looked at some example code and read tech note which says you can't define tracking rectangles til after they are added to a view, but am still having problems with it.

I believe that is correct. At an early stage in the development of the Head class, I made a plausible but wrong assumption that a quite reasonable place to install the tracking rects for a Head instance would be in the Head's initWithFrame method. But that did not work, and I had to revert to setting the tracking rects outside.

Possibly, had I pursued the issue further, I could maybe have
a  - (void)setHeadTrackingRect  in the Head class, and invoke that
method from the superview after a Head instance had been added
as a subview.

    Hope This Helps,
		........  Henry


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


===============================+============================ 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: 
 >Do tracking rectangles move along with their views? (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: Java vs. Objective-C for Cocoa
  • Next by Date: Re: Java vs. Objective-C for Cocoa
  • Previous by thread: Do tracking rectangles move along with their views?
  • Next by thread: NSUndoTyping and NSUndoTextOperation
  • Index(es):
    • Date
    • Thread