Drag & Drop issues

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!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
dusty_2019
Posts: 1
Joined: Sun Jun 30, 2019 6:17 pm

Drag & Drop issues

Post by dusty_2019 » Sun Jun 30, 2019 7:16 pm

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... :x

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 :)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6261
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Drag & Drop issues

Post by dunbarx » Sun Jun 30, 2019 10:33 pm

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
Last edited by dunbarx on Mon Jul 01, 2019 12:29 pm, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7022
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Drag & Drop issues

Post by FourthWorld » Mon Jul 01, 2019 2:01 am

Touch systems have no mouse.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6261
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Drag & Drop issues

Post by dunbarx » Mon Jul 01, 2019 12:28 pm

Richard.

What is the usual way to touch a control and have it track ones finger motion?

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5154
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Drag & Drop issues

Post by jacque » Mon Jul 01, 2019 6:22 pm

MouseMove is listed as compatible with mobile however.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7022
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Drag & Drop issues

Post by FourthWorld » Mon Jul 01, 2019 7:14 pm

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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5154
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Drag & Drop issues

Post by jacque » Mon Jul 01, 2019 11:54 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2400
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Drag & Drop issues

Post by jmburnod » Tue Jul 02, 2019 12:17 am

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2400
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Drag & Drop issues

Post by jmburnod » Thu Jul 04, 2019 11:07 am

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.
GrabMouseMove.zip
(128.68 KiB) Downloaded 17 times
Thanks at all to help us to make it simpliest.
Kind regards
Jean-Marc

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2400
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Drag & Drop issues

Post by jmburnod » Thu Aug 15, 2019 5:13 pm

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)
GrabMouseMove002.zip
(129.62 KiB) Downloaded 12 times
Best
Jean-Marc

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”