Page 1 of 1

enable mouse messages when button down

Posted: Fri Oct 16, 2015 9:22 pm
by mattmaier
I designed some UI interaction on the whiteboard. Now that I'm trying to code them I found that Livecode is doing the exact opposite of what I'd like. Messages like mouseEnter are suppressed when the mouse button is down.

What I'd like to do is let the user click on one node, drag the mouse to another node, release the mouse, and get a link between them. But I want to show them a preview of what they're about to get so that if that's not what they want they can move the mouse back and release it on the original node, which won't change anything (like in chess where if you don't take your hand off the piece the move isn't committed). So I need to track what controls the mouse is crossing over so that I can update the preview in real time.

Is there a way to enable mouse messages even when the button is down? And also a way to have them sent to the controls the mouse is over instead of the control where the button was originally held down?

Part of the reason I favored this input pattern is that it should work perfectly fine for touch interfaces too. But I'm not familiar with using touch messages. Do they have the same suppression where the finger won't send messages to the things it passes over when it's dragged across the screen?

Re: enable mouse messages when button down

Posted: Fri Oct 16, 2015 10:34 pm
by dunbarx
Hi.

The "mouseEnter" message is sent when the mouse is released inside a control, even though it was ignored when the mouse actually entered that control and the mouse was down. Try this. With two buttons, place this in the "starting" button:

Code: Select all

on mouseDown
   put the name of me
end mouseDown
And in the "target" button:

Code: Select all

on mouseEnter
   put " :" & random(999) after msg
end mouseEnter
Craig Newman

Re: enable mouse messages when button down

Posted: Sat Oct 17, 2015 4:17 am
by mattmaier
Thanks, that's interesting. Seems like it's more confusing than useful at that point. It's not queuing the messages because it doesn't send mouseEnter, mouseLeave, mouseEnter if all of those happened while the mouse was down.

But it also doesn't help. I was hoping to use the built in mouse messages while the mouse was down. Apparently that's exactly the opposite of what Livecode expects.

So is there a way to reverse that setting? To tell Livecode to keep sending mouse messages even though the button is down?

Re: enable mouse messages when button down

Posted: Sat Oct 17, 2015 9:48 am
by SparkOut
Not AFAIK but look at mouseStillDown and mouseMove. I would probably look first at setting a "nodeLink" flag on mouseDownand rresetting it on mouseUp or mouseRelease.
Then on mouseMove check for the nodeLink state, if true then check if the mouse is within the rect of a target node and if so, highlight what you need.

Re: enable mouse messages when button down

Posted: Sat Oct 17, 2015 2:06 pm
by Klaus
Hi Matt,

maybe you could "mis-use" the DRAGxxx messages in this case! :D
These ARE sent when the mouse is "down"!


Best

Klaus

Re: enable mouse messages when button down

Posted: Sat Oct 17, 2015 4:23 pm
by mattmaier
SparkOut - Thanks, but I'd like to make use of Livecode's existing engine. I COULD rewrite the logic that continuously tracks whether or not the mouse has entered a particular area...but there are already supposed to be messages for that.

Klaus - I see what you mean about 'abusing' the drag messages. They seem to be intended to transfer data. Is there maybe a catch to it? I've been able to trigger the dragStart message but none of the other drag messages.

Re: enable mouse messages when button down

Posted: Sat Oct 17, 2015 4:34 pm
by mattmaier
It looks like I can make due using mouseMove and within.

I can catch mouseMove relatively easily check if the mouseLoc is within the rect of every node in a repeat. That's not nearly as clean as just getting a message from the control the mouse crosses into, but it looks like Livecode just straight up doesn't send those messages when the button is down. I'll ask about that at the next user group meeting.

Re: enable mouse messages when button down

Posted: Sat Oct 17, 2015 4:41 pm
by Klaus
Hi Matt,
mattmaier wrote:Klaus - I see what you mean about 'abusing' the drag messages. They seem to be intended to transfer data. Is there maybe a catch to it? I've been able to trigger the dragStart message but none of the other drag messages.
I could think about setting "the dragdata" to a string (maybe the long ID of the target?) "on dragstart"
and then check that string "on dragdrop" on the target and then do your "connection of lines".


best

Klaus

Re: enable mouse messages when button down

Posted: Sat Oct 17, 2015 10:42 pm
by SparkOut
Well here's a quick and dirty way of getting the principle achieved. It doesn't take into account actually fixing what you want done with the selected nodes, but you should be able to see how mouseMove can be used to track a mouse while the button is held down and test when it is within the rect of any target object.
It uses a behavior (stored in a hidden button) for each of the "nodes". Click on any one, drag with the mouse button held down and let go over another node to link the two with a simple graphic line.

Re: enable mouse messages when button down

Posted: Sun Oct 18, 2015 12:52 pm
by richmond62
I've just made a "quick-n-dirty" stack:
mGames.png
mGames.png (9.25 KiB) Viewed 11626 times
and the card contains this script:

on mouseMove
put empty into fld "fff"
if the mouseLoc is within the rect of grc "g1" then
put "in the yellow blob" into fld "fff"
end if
if the mouseLoc is within the rect of grc "g2" then
put "in the pink blob" into fld "fff"
end if
end mouseMove

and that works regardless of whether the mouse is Down or Up.

Re: enable mouse messages when button down

Posted: Sun Oct 18, 2015 5:34 pm
by mattmaier
I appreciate the examples. I've also implemented something using mouseMove.

The question this thread is based on is still whether or not it's possible to re-enable the mouse messages even though the mouse button is down. Livecode is based on messages. There are commands that manipulate those messages, like stopping them, or forcing a message. So maybe there's a way to enable mouse messages when the button is down. That would be a lot more consistent with how Livecode works in every other case.

I can't even find an explanation of why it would make sense to disable the normal mouse messages when the button is down. Clearly someone thought it made sense because most of the messages are disabled. But in my case it's the exact opposite of making sense, so I want to just reverse it.

Re: enable mouse messages when button down

Posted: Sun Oct 18, 2015 5:49 pm
by richmond62
Because of mouseStillDown . . .

Re: enable mouse messages when button down

Posted: Thu Aug 25, 2016 7:14 pm
by melristau
Thanks for posting Link_Nodes_Test! Great script notes and –for me– helpful intro to Custom Properties.