Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
I'm traying to force a group that I drag to not overtake the edges of a card... to date my attempts were in vain, maybe I'm missing something.. I read some examples I found and some documentation (and this is the hardest part to admit) for move, moveMouse, intercept etc. but to date I haven't found a way to accomplish this task...
local movingGroup, deltaX,deltaY
on mouseDown
if there is a group xyz then
put true into movingGroup
put the mouseLoc into mLoc
put the loc of group xyz into theGroupLoc
put item 1 of mLoc - item 1 of theGroupLoc into deltaX
put item 2 of mLoc - item 2 of theGroupLoc into deltaY
end if
end mouseDown
on mouseMove
if movingGroup is true then
put item 1 of the mouseLoc - deltaX into a
put item 2 of the mouseLoc - deltaY into b
put a,b into c
set the loc of group xyz to c
end if
end mouseMove
on mouseUp
put false into movingGroup
end mouseUp
Last edited by Mag on Fri Jun 06, 2014 6:04 pm, edited 2 times in total.
local movingGroup, deltaX,deltaY
on mouseDown
if there is a group "xyz" then
put true into movingGroup
put the mouseLoc into mLoc
put the loc of group "xyz" into theGroupLoc
put item 1 of mLoc - item 1 of theGroupLoc into deltaX
put item 2 of mLoc - item 2 of theGroupLoc into deltaY
end if
end mouseDown
on mouseMove
if movingGroup is true then
put item 1 of the mouseLoc - deltaX into a
put item 2 of the mouseLoc - deltaY into b
--------- code added ------------------------
# Right boundary
put the left of button "movingArea" + (the width of group "XYZ"/2) into theMax -- I use a button to see the boundaries
if a < theMax then put theMax into a
-- add code for left, top and bottom here
------------------------------------------------
put a,b into c
set the loc of group "xyz" to c
end if
end mouseMove
on mouseUp
put false into movingGroup
end mouseUp
Looks like your handler will work. A good exercise would be to rewrite so you do not need that bounding button. Another exercise would be to think about this alone in the card script. (Sorry, Simon. But this guy is no newbie).
set the left of grp "xyz" to max(0,the left of grp "xyz")
set the right of grp "xyz" to min(the width of this stack,the right of grp "xyz")
Do the same for top and bottom. If the boundaries aren't the stack edges, use the right and left of the bounding button instead. I agree it's best to avoid a bounding button entirely, but that does make things simpler in the the script. But if you want to avoid a button, use a scripted rectangle instead.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com