Simple way to drag a graphic across the screen?- Solved
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Simple way to drag a graphic across the screen?- Solved
I don't think that triggering a "move" "on mousemove" is a good idea at all.
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Simple way to drag a graphic across the screen?- Solved
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:Klaus wrote:I don't think that triggering a "move" "on mousemove" is a good idea at all.
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
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
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Simple way to drag a graphic across the screen?- Solved
What am I missing?
script in each graphic object:
on mouseDown
grab me
end mouseDown
script in each graphic object:
on mouseDown
grab me
end mouseDown
Re: Simple way to drag a graphic across the screen?- Solved
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?richmond62 wrote:What am I missing?
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.
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Simple way to drag a graphic across the screen?- Solved
Right, that's the solution the OP settled on. The conversation evolved into a discussion of how to move multiple controls at once.richmond62 wrote:What am I missing?
script in each graphic object:
on mouseDown
grab me
end mouseDown
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Simple way to drag a graphic across the screen?- Solved
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.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?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Simple way to drag a graphic across the screen?- Solved
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
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
Re: Simple way to drag a graphic across the screen?- Solved
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?
@ 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?
-
- Livecode Opensource Backer
- Posts: 9387
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Simple way to drag a graphic across the screen?- Solved
Just tried to grab a group: that one didn't work either.
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Simple way to drag a graphic across the screen?- Solved
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.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?
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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Simple way to drag a graphic across the screen?- Solved
It works if you click on a control in the group, same as how other mouse events behave in groups.richmond62 wrote:Just tried to grab a group: that one didn't work either.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Simple way to drag a graphic across the screen?- Solved
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?
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?
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Simple way to drag a graphic across the screen?- Solved
This might give you a head start:
Craig
Code: Select all
select btn 1 and btn 2
Re: Simple way to drag a graphic across the screen?- Solved
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:
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