Hi,
I have an object that has a mouseLeave handler. This handler is run when the mouse moves off the object. However if I keep the mouse still and move the object with the "move" command, mouseLeave is only sent when the user moves their mouse a tiny bit after the object have been moved from under the mouse pointer.
I really need the mouseLeave message to be sent immediately when the object moves away (by the move command) from under the mouse pointer.
Does anyone know how to do this?
Thanks
MouseLeave message to be sent when object moves away
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 184
- Joined: Wed Apr 10, 2013 5:09 pm
Re: MouseLeave message to be sent when object moves away
Hi,
This is similar to a few recent threads that deal with like issues.
No messages are sent during a move. It is necessary to set up a recursive handler after the "move" command line (pseudo):
Fun stuff.
Craig Newman
This is similar to a few recent threads that deal with like issues.
No messages are sent during a move. It is necessary to set up a recursive handler after the "move" command line (pseudo):
Code: Select all
...
move whatever
checkForMouseLeave
...
on checkForMouseLeave
put "Still Inside!!!"
if the mouseLoc is not within the rect of whateverControl then
put "Just Left"
exit to top
send checkForMouseLeave in 1
end checkForMouseLeave
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 10057
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: MouseLeave message to be sent when object moves away
One way to do that would be to poll for the state you're looking for (in your case, whether the mouse is within the object) using a timer, e.g.:
Code: Select all
on mouseUp
set the label of me to "In"
set the movespeed to 100
send "PollForMouseWithin" to me in 10 millisecs
move me rel 200,200 without waiting
end mouseUp
on PollForMouseWithin
if not within(me, the mouseLoc) then
set the label of me to "Out"
end if
if "PollForMouseWithin" is not in the pendingMessages \
AND the movingControls is not empty then
send "PollForMouseWithin" to me in 10 millisecs
end if
end PollForMouseWithin
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: MouseLeave message to be sent when object moves away
Yet another solution.
Immediately before the move do
send "mouseLeave" to me in 1 millisecs
This goes 'immediately' into the main loop and is done before the move!
Finally, if needed, immediately after the move do
send "mouseEnter" to me in 1 millisecs
To see what I mean and how it works here a test script. Also drag the button and let mouse go up.
Immediately before the move do
send "mouseLeave" to me in 1 millisecs
This goes 'immediately' into the main loop and is done before the move!
Finally, if needed, immediately after the move do
send "mouseEnter" to me in 1 millisecs
To see what I mean and how it works here a test script. Also drag the button and let mouse go up.
Code: Select all
on mouseUp
-- set rect of me to (200,200,280,280)
lock messages # <-- avoids flicker
send "mouseLeave" to me in 1 millisecs
--> "move me to (0,0) in 1 second" has after dragging
--> (with grab) a wrong starting point, correct this:
move me from the mouseloc to (0,0) in 1 second
move me to (100,100) in 1 second
if the mouseloc is within the rect of me
then send "mouseEnter" to me in 1 millisecs
end mouseUp
on mouseEnter
if there is no grc "Light0" then createOval
set backcolor of grc "Light0" to "red"
end mouseEnter
on mouseLeave
set backcolor of grc "Light0" to "green"
end mouseLeave
on mouseDown
grab me
end mouseDown
on createOval
create grc "Light0"
set style of grc "Light0" to oval
set opaque of grc "Light0" to true
set rect of grc "Light0" to (0,0,64,64)
end createOval
shiftLock happens