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

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

Postby Klaus » Sat Sep 09, 2017 12:04 pm

I don't think that triggering a "move" "on mousemove" is a good idea at all. 8)
Klaus
 
Posts: 9488
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany

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

Postby jacque » Sun Sep 10, 2017 4:56 am

Klaus wrote:I don't think that triggering a "move" "on mousemove" is a good idea at all. 8)


Yeah, you're right. Next time I'll test before I post. It does work with "set the loc" though. Instead of testing the state of a modifier key, I used a script local flag to cut down on excessive polling:


Code: Select all
local sDragging

on mouseDown
  put true into sDragging
end mouseDown

on mouseUp
  put false into sDragging
end mouseUp

on mouseMove x,y
  if not sDragging then pass mouseMove
  lock screen
  repeat with i = 1 to the number of btns
    set the loc of btn i to x,item 2 of the loc of btn i
  end repeat
  unlock screen
end mouseMove


It would benefit from an mouse x-offset.

I think if I wanted anything other than straight line moves I'd just group the controls and use "grab".
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3794
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN

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

Postby richmond62 » Sun Sep 10, 2017 11:04 am

What am I missing?

script in each graphic object:

on mouseDown
grab me
end mouseDown
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
 
Posts: 1845
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Postby bogs » Sun Sep 10, 2017 2:42 pm

richmond62 wrote:What am I missing?

Well, if that script is in each graphic objects handler, I think it is missing the pass line, in case there is something else being handled by a mouseDown further down the line, isn't it?

I *think* that being in the objects script, it would only get the mouseDown for that object, but there might be other events you want fired during a mouseDown event that do not relate in general to that one object, such as timers, colors, or something else like bool logic to set a variable.

Not trying to be pedantic, I realize this is just a simplified example to illustrate one aspect of how to do something.
Image
bogs
 
Posts: 376
Joined: Sat Feb 25, 2017 10:45 pm

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

Postby jacque » Sun Sep 10, 2017 5:33 pm

richmond62 wrote:What am I missing?

script in each graphic object:

on mouseDown
grab me
end mouseDown


Right, that's the solution the OP settled on. The conversation evolved into a discussion of how to move multiple controls at once.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3794
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN

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

Postby jacque » Sun Sep 10, 2017 5:38 pm

if that script is in each graphic objects handler, I think it is missing the pass line, in case there is something else being handled by a mouseDown further down the line, isn't it?


In most cases you don't need to pass messages, and sometimes doing so can cause more problems. It depends on your code and your style. Everyone has their own method but I rarely pass messages unless there's a handler somewhere else that needs to act.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3794
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN

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

Postby richmond62 » Sun Sep 10, 2017 5:52 pm

I wonder why this does not work:

on mouseDown
grab img "1782.png"
grab img "5247.png"
grab img "1287.png"
end mouseDown

where the script is in img "1782.png"

all that happens is that img "1782.png" is grabbed
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
 
Posts: 1845
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Postby bogs » Sun Sep 10, 2017 6:06 pm

Ah, thank you for that Jacque :)

@ richmond62 » I think it doesn't work because Lc can only grab one thing at a time can't it? Just like it can only move one thing at a time?
Image
bogs
 
Posts: 376
Joined: Sat Feb 25, 2017 10:45 pm

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

Postby richmond62 » Sun Sep 10, 2017 9:01 pm

Just tried to grab a group: that one didn't work either.
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
 
Posts: 1845
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Postby jacque » Sun Sep 10, 2017 9:18 pm

I think it doesn't work because Lc can only grab one thing at a time can't it? Just like it can only move one thing at a time?


Right, it can only grab one control at a time. Not so right about moving one thing at a time -- the "lock moves" command is specifically set up for moving multiple objects in one go. The part that didn't work in my first example was because I was using the "move" command inside a mouseMove handler, which backed up the message queue pretty badly, because I forgot to add a parameter. MouseMove is sent a zillion time per second, or somewhere in that range. :)

You can indeed use the "move" command in a mouseMove handler if you remember to add "without waiting":

Code: Select all
on mouseMove x,y
  lock moves
  repeat with i = 1 to the number of btns
    move btn i to x,item 2 of the loc of btn i without waiting
  end repeat
  unlock moves
end mouseMove


This isn't as responsive as "set the loc" though because my movespeed was set to default. It could probably be tinkered with, but "set the loc" works with less scripting. You'd also want to set the script local flag here, since the above causes the move whether the mouse is down or not.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3794
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN

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

Postby jacque » Sun Sep 10, 2017 9:21 pm

richmond62 wrote:Just tried to grab a group: that one didn't work either.


It works if you click on a control in the group, same as how other mouse events behave in groups.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 3794
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN

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

Postby sphere » Wed Sep 13, 2017 3:02 pm

I was playing with this, and doublemouseup (so when doublemouseup) the object is selected.

How can i leave a button selected, and then select another button (or images), then drag them both.
So you could select any nr of objects and after that drag them?
sphere
 
Posts: 403
Joined: Sat Sep 27, 2014 10:32 am
Location: Hummelo, the Netherlands

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

Postby dunbarx » Wed Sep 13, 2017 3:51 pm

This might give you a head start:

Code: Select all
select btn 1 and btn 2


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

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

Postby sphere » Wed Sep 13, 2017 7:15 pm

Thanks Craig.

I tried some but came up with this, which almost does it(just same script in 2 btns), just not yet with mousedown but hovering over one btn with the mouse, i want it when both selected and then only when mouse down:
Code: Select all
on mouseDown
   set the backgroundcolor of me to "green"
   grab me
end mouseDown

on mouseDoubleUp
    set the backgroundcolor of me to "blue"
    --select me
end mouseDoubleUp

on mouseUp
set the backgroundcolor of me to "lightgray"
end mouseUp

--on mouseMove pNewMouseH, pNewMouseV
--repeat with i =1 to the number buttons
  --    if the backgroundcolor of btn i = "blue" then
  --       grab btn i
   --      else grab me
--  end repeat
--end mouseMove

on mouseMove x,y
lock moves
repeat with i = 1 to the number of btns
    if the backgroundcolor of btn i is "blue" then
       move btn i to x, item 2 of the loc of btn i without waiting
       end if
  end repeat
  unlock moves
end mouseMove

--on mouseDoubleDown pButtonNumber
  --set the backgroundcolor of me to "blue"
--repeat with i =1 to the number buttons
--    if the backgroundcolor of btn i = "blue" then  MoveIt
--  end repeat
--end mouseDoubleDown
sphere
 
Posts: 403
Joined: Sat Sep 27, 2014 10:32 am
Location: Hummelo, the Netherlands

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

Postby sphere » Thu Sep 14, 2017 2:30 pm

sphere
 
Posts: 403
Joined: Sat Sep 27, 2014 10:32 am
Location: Hummelo, the Netherlands

PreviousNext

Return to Getting Started with LiveCode - Complete Beginners

Who is online

Users browsing this forum: No registered users and 5 guests