Constraining 'grab'
Geoff Canyon
gcanyon at inspiredlogic.com
Mon Mar 4 16:26:01 EST 2002
At 2:06 PM -0800 3/4/02, Ken Norris (dialup) wrote:
>If it's unwise to use 'the mouse' repeats to do it, then...How do I
>constrain 'grab' to a rect (or any other) boundary?
>
>Know what I mean? I don't want the user to drag the object out of bounds. I
>looked through the docs and couldn't find an example.
local tDragging
on mouseDown
put true into tDragging
end mouseDown
on mouseMove mouseX,mouseY
if tDragging then
-- Do bounds checking here --
set the loc of me to (mouseX,mouseY)
end if
end mouseMove
on mouseUp
stopDragging
end mouseUp
on mouseRelease
stopDragging
end mouseRelease
on stopDragging
put false into tDragging
end stopDragging
Note that you will likely want to get the offset of the mouse from the loc of the object in the mouseDown in order to maintain that offset while dragging. Otherwise the object will snap to the mouseLoc at mouseDown.
regards,
Geoff
More information about the use-livecode
mailing list