Sticking an image to the cursor

BNig niggemann at uni-wh.de
Sat Oct 11 19:05:26 EDT 2008



Sue Smith wrote:
> 
> I did, but it only works with mouseDown. I need it to work on the
> mouseEnter handler. I am developing (freeware) for children with
> disabilities - so many are unable to click the mouse button, let alone
> keep it held down.

Hi Sue,

the tricky part is to do it without a mouseDown and stuff. You somehow have
to determine when the image is supposed to stop following the mouse.

you could try this and see if it is what you want, the handler checks the
mouse position and compares it to the previous position, if it finds that
the position did not change for the last 50 times it gives up on following
the mouse, assuming the user has finished placing the image. Adjust timing
where noted.

code, watch for linebreaks when you copy
-------------------------
local tCursorLoc, tXOffset, tYOffset, tMouseDidNotMoveCounter, tCardRect
on mouseEnter
    put the mouseloc into tCursorLoc
    put the loc of me into tImageLoc
    put item 1 of tImageLoc - item 1 of tCursorLoc into tXOffset
    put item 2 of tImageLoc - item 2 of tCursorLoc into tYOffset
    put the rect of this card into tCardRect
    set the cursor to hand
    lock cursor
    put 0 into tMouseDidNotMoveCounter
    send isItStillMoving to me in 30 milliseconds -- adjust for smoothness
of movement
end mouseEnter

on isItStillMoving
    if tMouseDidNotMoveCounter > 50 then -- adjust here how long it takes to
release image
        unlock cursor
        exit isItStillMoving
    end if
    put the mouseloc into tMouseIsHere
    if tMouseIsHere = tCursorLoc then
        add 1 to tMouseDidNotMoveCounter -- no movement so increase counter
        send isItStillMoving to me in 30 milliseconds -- adjust for
smoothness of movement  
    else
        put item 1 of tCursorLoc + tXOffset into item 1 of tNewLocOfImage
        put item 2 of tCursorLoc + tYOffset into item 2 of tNewLocOfImage
        -- to avoid dragging the image off the card
        if tNewLocOfImage is within tCardRect then set the loc of me to
tNewLocOfImage
        put tMouseIsHere into tCursorLoc
        put 1 into tMouseDidNotMoveCounter -- reset the counter since mouse
moved
        send isItStillMoving to me in 30 milliseconds -- adjust for
smoothness of movement
    end if
end isItStillMoving
-----------------
end of code

put this into the script of an image. May be someone has a better idea how
to have the image follow the mouse without a mouseDown.

cheers
Bernd
-- 
View this message in context: http://www.nabble.com/Sticking-an-image-to-the-cursor-tp19934277p19937290.html
Sent from the Revolution - User mailing list archive at Nabble.com.




More information about the use-livecode mailing list