Page 1 of 3

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

Posted: Thu Sep 07, 2017 11:48 pm
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

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

Posted: Fri Sep 08, 2017 12:14 am
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!

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

Posted: Fri Sep 08, 2017 12:42 pm
by dunbarx
You might also do something like:

Code: Select all

on mouseMove
  set the loc of grc "yourGraphic" to the mouseLoc
end mouseMove

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

Posted: Fri Sep 08, 2017 12:47 pm
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

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

Posted: Fri Sep 08, 2017 1:16 pm
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

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

Posted: Fri Sep 08, 2017 2:23 pm
by Klaus
Hey, that is cool! :)

I added "lock screen" for smoother movement.

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

Posted: Fri Sep 08, 2017 2:41 pm
by bogs
Neat stuff for sure Craig =^)

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

Posted: Fri Sep 08, 2017 5:04 pm
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.

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

Posted: Fri Sep 08, 2017 5:32 pm
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

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

Posted: Fri Sep 08, 2017 5:36 pm
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

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

Posted: Fri Sep 08, 2017 5:54 pm
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.

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

Posted: Fri Sep 08, 2017 6:09 pm
by DR White
Thanks so much for all the help!

David

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

Posted: Fri Sep 08, 2017 7:08 pm
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

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

Posted: Fri Sep 08, 2017 7:53 pm
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

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

Posted: Sat Sep 09, 2017 4:04 am
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