Tracking rect woes
Tracking rect woes
- Subject: Tracking rect woes
- From: Keith Blount <email@hidden>
- Date: Sun, 13 Mar 2005 11:52:03 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hello,
I have a view that contains custom subviews which can
be added and removed on the fly. Each of these
subviews has a tracking rect created in its
resetCursorRects method, so that whenever the mouse is
over one of them, it highlights, using mouseEntered:
and mouseExited:.
The trouble is that the tracking rects are complicated
by the fact that these views can be added or removed
dynamically, and moved, and at the moment I'm doing so
much complicated stuff to get around this that I am
hoping that someone will be able to point me in the
direction of a simpler solution.
These are my main problems:
- If a view is moved by something other than the
mouse, so that the mouse cursor remains stationary,
and the view moves under the mouse, it does not
receive a mouseEntered: message and therefore does not
get highlighted (because when it is moved,
resetCursorRects gets called, my tracking rect is set
up again, and now the mouse is inside the view, so it
never gets the message) - likewise if the view moves
out from under the mouse.
- If a view is created while the mouse is over it, it
will not highlight because, again, it doesn't receive
a mouseEntered: message.
To get around these issues, currently I am trying to
do a check using mouseEventOutsideOfEventStream and
mouse:inRect: to see if the mouse is inside the view.
This works great in resetCursorRects, but for some
reason it doesn't work in viewDidMoveToSuperview.
This is my viewDidMoveToSuperview method - even when
the mouse is inside the view when created, the NSLog
is always "Don't highlight!" - strange:
- (void)viewDidMoveToSuperview
{
[super viewDidMoveToSuperview];
if ([self superview] != nil)
{
NSPoint mousePoint = [self convertPoint:[[self
window] mouseLocationOutsideOfEventStream]
fromView:nil];
if ([self mouse:mousePoint inRect:[self
visibleRect]])
NSLog (@"Highlight!");
else
NSLog(@"Don't highlight!");
}
}
Has anyone encountered similar issues with dynamically
created views and tracking rects? I would be very
grateful for any advice on how I can set this up in a
less complicated and more efficient manner...
Many thanks in advance,
Keith
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
_______________________________________________
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