enable mouse messages when button down

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mattmaier
Posts: 109
Joined: Fri Apr 19, 2013 2:49 am

enable mouse messages when button down

Post by mattmaier » Fri Oct 16, 2015 9:22 pm

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?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: enable mouse messages when button down

Post by dunbarx » Fri Oct 16, 2015 10:34 pm

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

mattmaier
Posts: 109
Joined: Fri Apr 19, 2013 2:49 am

Re: enable mouse messages when button down

Post by mattmaier » Sat Oct 17, 2015 4:17 am

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?

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: enable mouse messages when button down

Post by SparkOut » Sat Oct 17, 2015 9:48 am

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.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: enable mouse messages when button down

Post by Klaus » Sat Oct 17, 2015 2:06 pm

Hi Matt,

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


Best

Klaus

mattmaier
Posts: 109
Joined: Fri Apr 19, 2013 2:49 am

Re: enable mouse messages when button down

Post by mattmaier » Sat Oct 17, 2015 4:23 pm

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.

mattmaier
Posts: 109
Joined: Fri Apr 19, 2013 2:49 am

Re: enable mouse messages when button down

Post by mattmaier » Sat Oct 17, 2015 4:34 pm

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.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: enable mouse messages when button down

Post by Klaus » Sat Oct 17, 2015 4:41 pm

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

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: enable mouse messages when button down

Post by SparkOut » Sat Oct 17, 2015 10:42 pm

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.
Attachments
Link_Nodes_Test.zip
(1.99 KiB) Downloaded 351 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: enable mouse messages when button down

Post by richmond62 » Sun Oct 18, 2015 12:52 pm

I've just made a "quick-n-dirty" stack:
mGames.png
mGames.png (9.25 KiB) Viewed 11622 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.
Attachments
mg.zip
Here's the stack.
(788 Bytes) Downloaded 342 times

mattmaier
Posts: 109
Joined: Fri Apr 19, 2013 2:49 am

Re: enable mouse messages when button down

Post by mattmaier » Sun Oct 18, 2015 5:34 pm

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: enable mouse messages when button down

Post by richmond62 » Sun Oct 18, 2015 5:49 pm

Because of mouseStillDown . . .

melristau
Posts: 56
Joined: Tue Jul 14, 2015 5:15 pm
Contact:

Re: enable mouse messages when button down

Post by melristau » Thu Aug 25, 2016 7:14 pm

Thanks for posting Link_Nodes_Test! Great script notes and –for me– helpful intro to Custom Properties.
rebuilding visual programming app originally created in 1993 as Hypercard stack

Post Reply