Simple way to drag a graphic across the screen?- Solved

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: FourthWorld, heatherlaine, Klaus, kevinmiller

DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Simple way to drag a graphic across the screen?- Solved

Post by DR White »

What is a simple way to drag a graphic across the screen and drop it, then go get another one?

I have looked in dictionary at the various drag events and tried couple things, but no real success so far.
I little guidance would be great!

Thanks,

David
Last edited by DR White on Fri Sep 08, 2017 6:11 pm, edited 2 times in total.
DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Re: What is a simple way to drag a graphic across the screen

Post by DR White »

Sorry to bother anyone. After some more head banging, I did find some info on moving graphics in one of the tutorials. The "Grab" command works great!
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: What is a simple way to drag a graphic across the screen

Post by dunbarx »

You might also do something like:

Code: Select all

on mouseMove
  set the loc of grc "yourGraphic" to the mouseLoc
end mouseMove
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: What is a simple way to drag a graphic across the screen

Post by Klaus »

Or a tad more effective:

Code: Select all

on mouseMove x,y
  set the loc of grc "yourGraphic" to x,y
end mouseMove
:D
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: What is a simple way to drag a graphic across the screen

Post by dunbarx »

Here is another way to move stuff around. On a new card with three buttons, place this in the card script:

Code: Select all

on mouseMove x,y
   if the optionKey is down then
      set the xx of this cd to x
      set the yy of this cd to y
      wait 1
      put the xx of this cd - item 1 of the mouseLoc into newX
      put the yy of this cd - item 2 of the mouseLoc into newY
      
      repeat with u = 1 to 3
         set the loc of btn u to item 1 of the loc of btn u - newX & "," & item 2 of the loc of btn u - newY
      end repeat
   end if
end mouseMove
Craig
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: What is a simple way to drag a graphic across the screen

Post by Klaus »

Hey, that is cool! :)

I added "lock screen" for smoother movement.
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: What is a simple way to drag a graphic across the screen

Post by bogs »

Neat stuff for sure Craig =^)
Image
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: What is a simple way to drag a graphic across the screen

Post by jacque »

How does it differ from the built in move command? You can do the same thing in one line of script. I could be missing something, I didn't actually try it.

Edit - what I missed is that this is dynamic. Gotcha.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: What is a simple way to drag a graphic across the screen

Post by dunbarx »

Klaus

Lock screen is nice. There is a new message repeatedly sent, after all, and the screen unlocks between those events.

Interestingly, and this surely depends on the speed of the machine, there is a lower limit for the wait time. One tick is just about it for my 3.2 GHz iMac with OS 10.9 and LC 6.7.9. One tick is about 16 milliseconds. Not too much lower than that and the kluge (because that is what this is) will fail.

On the other end, jerkiness appears with wait values above about 3 ticks, lock screen notwithstanding.

I think 2 ticks is best.

Craig
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: What is a simple way to drag a graphic across the screen

Post by dunbarx »

@Jacque.
what I missed is that this is dynamic. Gotcha.
Hi.

What did you mean by "dynamic", or rather, what did you have in mind to move several objects?

Craig
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: What is a simple way to drag a graphic across the screen

Post by jacque »

By dynamic I meant that it responds to user drag rather than just a one time move command.

But you could still use mouseMove with the built-in move command with far less scripting.

Code: Select all

on mouseMove x, y
  move me to x, y - - or a named target 
end mouseMove
Or commonly, just set the loc of the object to x, y.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Re: What is a simple way to drag a graphic across the screen

Post by DR White »

Thanks so much for all the help!

David
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: Simple way to drag a graphic across the screen?- Solved

Post by dunbarx »

Jacque.

True about the one-liner for one control. But I was moving a handful of controls at the same time.

I was really only interested in how this might be made to work with "mouseMove". The "wait" is essential, to fool the current handler into acting on the initial x,y parameters passed with the message. Those early values have to be stored somewhere BEFORE the wait, so they can be referenced AFTER the wait, when the mouseLoc is different.

It is a kluge, as I said, which is why with a few dozen objects it starts to get jittery.

Craig
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Simple way to drag a graphic across the screen?- Solved

Post by jacque »

True about the one-liner for one control. But I was moving a handful of controls at the same time.
Like this:

Code: Select all

on mouseMove x,y
  lock moves
  repeat for each item i in tListOfControls -- you'd need to specify these
    move control i to x,y
  end repeat
  unlock moves
end mouseMove
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: Simple way to drag a graphic across the screen?- Solved

Post by dunbarx »

Jacque.

Could not get your handler as written to work. But this almost does:

Code: Select all

on mouseMove x,y
   if the optionKey is down then
        lock moves
        repeat with u = 1 to the number of controls
             move control u to x,y
        end repeat
        unlock moves
   end if
end mouseMove
But it also has problems. With two controls, one moves nicely but the other does not. With more than two, one still does not and the remaining ones are jerky.

Craig
Post Reply