Re: Receiving tracking rectangle events
Re: Receiving tracking rectangle events
- Subject: Re: Receiving tracking rectangle events
- From: Greg Titus <email@hidden>
- Date: Fri, 28 May 2004 17:47:05 -0700
On May 28, 2004, at 4:06 PM, Thomas Davie wrote:
Hi,
I've been writing a game that has a similar set up to chess, pieces
are placed and moved on an 8x8 board. One of the features I've been
attempting to write is the ability for the user to hover the mouse
over a piece and show it's valid moves. To do this I'm setting up 64
tracking rectangles using NSView's addTrackingRect....... method in
the initWithFrame method with owner set to self on my board view, and
then adding two functions - (void)mouseEntered:(NSEvent *)event and -
(void)mouseExited:(NSEvent *)event. However, neither event ever gets
called no matter how much I move the mouse in and out of the relevant
squares. Have I missed something critical?
Hi Tom,
Your problem is that you are setting up the tracking rects too early.
Tracking rectangles actually get added to the window that a view is on,
they aren't kept track of by the view itself. When you set up the rects
in -initWithFrame:, your view hasn't been added to its window yet so
the tracking rects aren't actually being set up.
Set them up in -viewDidMoveToWindow instead, and it ought to work.
Hope this helps,
- Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.