Page 1 of 1
Forcing a dragged object to not overtake the edges of a card
Posted: Fri Jun 06, 2014 5:33 pm
by Mag
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...
Code: Select all
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
Re: Forcing a dragged object to not overtake the edges of a
Posted: Fri Jun 06, 2014 5:53 pm
by dunbarx
Ah.
A mind is a terrible thing.
You have it right, you just don't have it write. What is the variable "movegroup"? Perhaps it ought to be "movingGroup"?
Write back with your thoughts about making sure the group does not go over the edge.
Craig Newman
Re: Forcing a dragged object to not overtake the edges of a
Posted: Fri Jun 06, 2014 6:00 pm
by Mag
dunbarx wrote:Ah.
A mind is a terrible thing.
You have it right, you just don't have it write. What is the variable "movegroup"? Perhaps it ought to be "movingGroup"?
Write back with your thoughts about making sure the group does not go over the edge.
Craig Newman
Oops, sorry, yes it was "movingGroup", now I fixed it in the post (that is not the original code but a simplified version I made for posting it here).
PS
The part that tries to force the moving of the group is not present because I haven't find anything that works

Re: Forcing a dragged object to not overtake the edges of a
Posted: Fri Jun 06, 2014 7:47 pm
by dunbarx
OK.
Here is a hint. Where might you put this line in your handler?
Code: Select all
if the right of grp "xyz" > the width of this card then exit to top
And please start using quotes around all object references. ("xyz")
Craig
Re: Forcing a dragged object to not overtake the edges of a
Posted: Fri Jun 06, 2014 8:38 pm
by Mag
dunbarx wrote:OK.
Here is a hint. Where might you put this line in your handler?
Code: Select all
if the right of grp "xyz" > the width of this card then exit to top
And please start using quotes around all object references. ("xyz")
Craig
Thank you so much Craig, this is very useful as starting point.
PS
Thank you also for the advice, I will follow it.
Re: Forcing a dragged object to not overtake the edges of a
Posted: Fri Jun 06, 2014 8:47 pm
by Mag
I'm trying to develop your hint, this seems to work:
Code: Select all
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
Re: Forcing a dragged object to not overtake the edges of a
Posted: Fri Jun 06, 2014 9:06 pm
by dunbarx
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).
Code: Select all
on mouseMove
if the mouse is down then set the loc of grp "xyz" to the mouseLoc
end mouseMove
You still need to deal with those boundaries, and they should be card window based. Unless you actually want a different boundary, of course.
Craig
Re: Forcing a dragged object to not overtake the edges of a
Posted: Fri Jun 06, 2014 10:40 pm
by Simon
Craig, You do a much better job than I do
Simon
Re: Forcing a dragged object to not overtake the edges of a
Posted: Fri Jun 06, 2014 11:18 pm
by dunbarx
Simon.
I could not disagree more.
Craig
Re: Forcing a dragged object to not overtake the edges of a
Posted: Sat Jun 07, 2014 8:36 pm
by jacque
You can also calculate the correct boundaries without using an "if" statement:
Code: Select all
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.
Re: Forcing a dragged object to not overtake the edges of a
Posted: Sun Jun 22, 2014 10:09 pm
by Mag
Thank you so much Jacqueline! I did not know this approach. Like it.