Page 1 of 1
Drag & Drop issues
Posted: Sun Jun 30, 2019 7:16 pm
by dusty_2019
Hi everyone,
For my app I would give to user the opportunity to create a multiply copied controls and swapping them by "Drag and drop" method
... but I'm very confused...
The are different ways to move a control... almost
1-Using Drag messages for the object
2-Grab method
3-Using mouseMove event setting the position for the control by mouse coord
But for every method I have innumerable doubts:
1-Drag and drop method, is it a real correct way to move a control? Is it possible use it in a mobile app?
2-If I use grab command, how can I detect the collision beetwen objects if I don't kown their names or IDs?
thank yor for yor attention

Re: Drag & Drop issues
Posted: Sun Jun 30, 2019 10:33 pm
by dunbarx
Hi.
I would use mouseMove, just because i have more experience with it. There are many ways to do things in LC, though, and you could make any of them work for you. The issue is how robust each method is when you start to stretch their limits.
On a new card, make two buttons. In the script of button 2:
Code: Select all
on mouseMove
if the optionKey is down then exit mouseMove --guaranteed escape
if intersect(me,btn 1) then
set the loc of me to item 1 of the loc of me + the width of me + 4 & "," & item 2 of the loc of me + the height of me + 4
answer "collision"
exit mouseMove
end if
set the loc of me to the mouseLoc
end mouseMove
Button 2 will track the cursor whenever you place the cursor inside it. If you collide with btn 1, it scoots itself out of the way a bit, and stops tracking. You likely will want to do something more useful than that
Does this give you enough to get started?
Craig
Re: Drag & Drop issues
Posted: Mon Jul 01, 2019 2:01 am
by FourthWorld
Touch systems have no mouse.
Re: Drag & Drop issues
Posted: Mon Jul 01, 2019 12:28 pm
by dunbarx
Richard.
What is the usual way to touch a control and have it track ones finger motion?
Craig
Re: Drag & Drop issues
Posted: Mon Jul 01, 2019 6:22 pm
by jacque
MouseMove is listed as compatible with mobile however.
Re: Drag & Drop issues
Posted: Mon Jul 01, 2019 7:14 pm
by FourthWorld
jacque wrote: ↑Mon Jul 01, 2019 6:22 pm
MouseMove is listed as compatible with mobile however.
Curious. I'm assuming it's only sent in "down" state (finger on screen), since most phones don't track hovering without touching. Not had occasion to use it myself in mobile, but good to know it's there, though implemented differently.
Re: Drag & Drop issues
Posted: Mon Jul 01, 2019 11:54 pm
by jacque
I haven't needed to use it either, but I'd have to assume it's only in a "down" state, it couldn't be otherwise. For dragging an object though, that would be okay.
Re: Drag & Drop issues
Posted: Tue Jul 02, 2019 12:17 am
by jmburnod
Hi Dusty,
2-If I use grab command, how can I detect the collision beetwen objects if I don't kown their names or IDs?
You can use grab and mousemove together
Something like that :
Code: Select all
local sCurControlID
on mousedown
put the short id of the target into sCurControlID
grab me
end mousedown
on mousemove
if the optionKey is down then exit mouseMove --guaranteed escap,
get controlIntersect(sCurControlID)
if it <> empty then
beep -- not available on iOS
put the short name of control it into fld "fDev" -- spy intersects
end if
end mousemove
function controlIntersect pControlID
-- you may use a list of targets on open card instead a loop for all controls to make it faster
put empty into tNumControl
repeat with i = 1 to the num of controls
put the short id of control i into tOneControlID
if tOneControlID = pControlID then
next repeat
end if
if intersect(control id sCurControlID,control i) then
put i into tNumControl
exit repeat
end if
end repeat
return tNumControl
end controlIntersect
Best regards
Jean-Marc
Re: Drag & Drop issues
Posted: Thu Jul 04, 2019 11:07 am
by jmburnod
Hi All,
I've played with grab and mousemove to move a control with rectangle limit and intersect detection.
I added an event (just show an explosion image) as exemple.
The main problem was recursion error but i found some workarounds.
Thanks at all to help us to make it simpliest.
Kind regards
Jean-Marc
Re: Drag & Drop issues
Posted: Thu Aug 15, 2019 5:13 pm
by jmburnod
Hi All
The stack in attachment show two ways to move an object with intersect check and avoid to move outside a rect.
1. First version uses grab and mousemove: btn GrabMe
2. Second version only uses mousemove: (btn tdz) (thanks Thierry)
Best
Jean-Marc