Re: Rollover Effect
Re: Rollover Effect
- Subject: Re: Rollover Effect
- From: jkp <email@hidden>
- Date: Tue, 30 Aug 2005 08:52:20 +0100
Cameron is right here.
I've just implemented something exactly like what you are doing and i
can confirm you will only see usable behaviour if you make sure that
you check the mouse co-ordinates at the time the event is received by
your class instance, rather than just blindly acting on whatever
comes through.
What happens is that the event queue effectively backs-up and gets
bogged down with events that were added to the queue some time ago.
You can illustrate this by putting a series of your link class one
above the other in a view and then rapidly rolling the mouse up and
down over them - you should see the rollover's going on for some time
after your mouse leaves the area containing the views.
The code i used was something like this...
<code>
//----------------------------------------------------------
// mouseEntered:
//----------------------------------------------------------
- (void)mouseEntered:(NSEvent *)theEvent
{
// This may look over the top, but its needed to make sure we
dont redraw stuff unneccessarily.
// Without these checks the event queue can get bogged down with
events that no longer mean
// anything (the mouse has since moved away).
NSPoint mouseLocation = [[self window]
mouseLocationOutsideOfEventStream];
NSRect boundsInWindow = [self convertRect:[self bounds]
toView:nil];
if (NSPointInRect(mouseLocation,boundsInWindow) &&
highlightedAttributes)
{
mouseInView = TRUE;
...do rollover stuff
}
}
//----------------------------------------------------------
// mouseExited:
//----------------------------------------------------------
- (void)mouseExited:(NSEvent *)theEvent
{
if (mouseInView)
{
...do mouseOut stuff
}
}
</code>
Doing the above made my class usable anyway. There are still a
couple of little niggles i have with the tracking rects which i
havent ironed out but at least the rollover works as expected now.
HTH - JKP
On 29 Aug 2005, at 23:33, email@hidden wrote:
On Aug 29, 2005, at 6:00 AM, Philip Dow wrote:
This works, except that the tracking rectangles are flaky as hell.
The mouseEntered: seems to register every time, but the
mouseExited: misses a beat if I move the cursor too quickly over
the view. The effect is a button that hangs. It continues to
indicate the hover/rollover state after the mouse has passed
through it.
You might want to try overriding the mouseMoved: event as well as a
second checkpoint. I also found tracking rectangles pretty flaky,
and instead set up something using [event locationInWindow] and
then NSView's mouse:inRect: method. The only thing you have to be
careful about there is converting the coordinates of the NSRect to
the NSPoint's coordinate system, or vice versa.
Cameron
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40kirkconsulting.co.uk
This email sent to email@hidden
_______________________________________________
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