Re: Simple way to drag a graphic across the screen?- Solved
Posted: Sat Sep 09, 2017 12:04 pm
I don't think that triggering a "move" "on mousemove" is a good idea at all.
Questions and answers about the LiveCode platform.
https://forums.livecode.com/
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
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?
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
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?
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?
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
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.
Code: Select all
select btn 1 and btn 2
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