Questions about 'mouseEnter'

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

bogs
Posts: 3813
Joined: Sat Feb 25, 2017 10:45 pm

Questions about 'mouseEnter'

Post by bogs » Thu Aug 15, 2019 2:35 pm

I have a stack in the shape of an image with a mouseEnter routine at the stack level. I have a second image sitting on the top layer of the card, with the visible set to off.

In that image's mouseEnter, I put set the visible of me to true, but that doesn't make the image visible. I then tried using the full name of the image, like this :

Code: Select all

if the mouseLoc is within the rect of image "moveMe" then set the visible of image "moveMe" to true
but even though that works at the stack level script, it does not work with the handler in the image's script.

My thinking in moving it to the image's script was that with the image being on the top layer, if the mouse moved into the image rectangle, it should supersede the stack level script. What am I missing?
mouseEnter.png
The mouse goes in, the mouse goes out...
Image

Klaus
Posts: 11207
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Questions about 'mouseEnter'

Post by Klaus » Thu Aug 15, 2019 2:52 pm

If an object is invisible, it is also invisible for the cursor, so it does not receive any mouse messages!

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

Re: Questions about 'mouseEnter'

Post by dunbarx » Thu Aug 15, 2019 3:32 pm

Hi.

A kluge might be to track the mouseLoc, testing constantly to see if it is within the rect of the invisible control. If it is, and the mouse is "down", then you can fire a handler.

Craig

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

Re: Questions about 'mouseEnter'

Post by SparkOut » Thu Aug 15, 2019 3:57 pm

Set the image to visible but with blendLevel of 99. Then it will receive mouse messages. On mouseEnter, set the blendLevel to 0, which will have the same effect as showing and hiding to a human, but a mouse can see it all the time.

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

Re: Questions about 'mouseEnter'

Post by dunbarx » Thu Aug 15, 2019 5:27 pm

That is even a better kluge. Is there no perceptible difference between a blendLevel of 99 and invisible?

Craig

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

Re: Questions about 'mouseEnter'

Post by SparkOut » Thu Aug 15, 2019 5:31 pm

Not that my eyes have ever been able to discern

bogs
Posts: 3813
Joined: Sat Feb 25, 2017 10:45 pm

Re: Questions about 'mouseEnter'

Post by bogs » Thu Aug 15, 2019 7:22 pm

Klaus wrote:
Thu Aug 15, 2019 2:52 pm
If an object is invisible, it is also invisible for the cursor, so it does not receive any mouse messages!
Huh, I'd never have made that connection ImageImageImage
Thank you, I'd have driven myself nuts with that, for some reason I assumed that the engine determined the rect of an object regardless of whether it was visible or not, and could therefore tell if the cursor was over the object or not. After all, the object is still there as demonstrated by "put the rect of [object]" in the messagebox :?
dunbarx wrote:
Thu Aug 15, 2019 3:32 pm
A kluge might be to track the mouseLoc, testing constantly to see if it is within the rect of the invisible control. If it is, and the mouse is "down", then you can fire a handler.
SparkOut wrote:
Thu Aug 15, 2019 3:57 pm
Set the image to visible but with blendLevel of 99. Then it will receive mouse messages. On mouseEnter, set the blendLevel to 0, which will have the same effect as showing and hiding to a human, but a mouse can see it all the time.
Thank you both for putting me on a better track. I found the blendlevel can go all the way to 100 (literally not visible) and still works. That discovery let me re-write other code I have that works similarly, making it much more compact. Awesome.
Image

bogs
Posts: 3813
Joined: Sat Feb 25, 2017 10:45 pm

Re: Questions about 'mouseEnter'

Post by bogs » Mon Aug 26, 2019 10:41 am

Hi again :D
I actually posted this last night, but for some reason, it wasn't here when I woke up, so reposting :shock:

So, along the lines of the actual mouse location, I made up this little demo (YouTube) for myself to try and understand exactly what is going on better, unfortunately in some ways, the results are confusing me more.

In the picture below -
locationTests.png
What the...?!
I expected the mouseLoc and localLoc of the mouse to only report when the mouse was within the borders of the application, and sure enough, they do only change when you are within the card area.

However, I did expect the screenMouseLoc and globalLoc of the mouse to change no matter where the mouse was on the screen. To my surprise, this isn't the case, whether the stack has focus or not.

What I find confusing is why this isn't the case? I'm sure this must be reported somewhere, but I wasn't able to find it in the pending messages (although that could be a lack of understanding on my part about the pending messages, which I am also looking into).

So what am I missing here? The code is all simple and very direct (I thought) -

Code: Select all

on mouseMove
   put the mouseLoc into field 1
   put the screenMouseLoc into field 2
   put the localLoc of the mouseLoc into field 5
   put the globalLoc of the mouseLoc into field 6
   put the target into field 7
   put the pendingMessages into tmpMsg
   repeat for each line x in tmpMsg
      put item 3 of x & cr before field "msgs"
   end repeat
end mouseMove

on moveStack
   put the rect of this stack into field 3
   put the effective rect of this stack into field 4
end moveStack
Image

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

Re: Questions about 'mouseEnter'

Post by dunbarx » Mon Aug 26, 2019 2:28 pm

Bogs.

I don't see this as an issue. After all, if you place a mouseMove handler in the stack or card script, and the cursor is off the card window, the message is not sent. This works, even in a button script:

Code: Select all

on mouseUp
   repeat until the optionKey is down
      put the screenMouseLoc
   end repeat
end mouseUp
Craig

EDIT: Works also for the mouseLoc

bogs
Posts: 3813
Joined: Sat Feb 25, 2017 10:45 pm

Re: Questions about 'mouseEnter'

Post by bogs » Mon Aug 26, 2019 2:42 pm

dunbarx wrote:
Mon Aug 26, 2019 2:28 pm
I don't see this as an issue. After all, if you place a mouseMove handler in the stack or card script, and the cursor is off the card window, the message is not sent.
Ok, that brings up another question I'm having a problem comprehending. I would have thought the mouseMove message is sent whenever the mouse is moving, regardless of its position on screen, as long as the application is open.

If, for instance, the stack has focus as I was mentioning before, then shouldn't it be receiving all messages regardless of whether the mouse is within its borders? I'm really getting lost in why (or why not) certain messages get sent (or not) Image
Image

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

Re: Questions about 'mouseEnter'

Post by dunbarx » Mon Aug 26, 2019 2:59 pm

I see what you mean, that if LC is in front, why not? And the point I made about a repeat loop that keeps running while the cursor is outside the window sort of strengthens your point, eh? To a point, but I guess it just doesn't.

Apparently a running handler keeps on running, but a message has to be home in order to work.

Craig

bogs
Posts: 3813
Joined: Sat Feb 25, 2017 10:45 pm

Re: Questions about 'mouseEnter'

Post by bogs » Mon Aug 26, 2019 3:02 pm

That is just what I am not getting. After all, all the handlers/messages come straight from the engine, don't they? The engine is running as long as the program is on screen isn't it? I must be incredibly dense, but I just don't get it :?

I appreciate the alternate method though.
Image

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

Re: Questions about 'mouseEnter'

Post by dunbarx » Tue Aug 27, 2019 2:57 am

Bogs.

Not entirely the same. The "mouseMove" message is generated each time the cursor is moved. I guess this requires that the cursor be inside a card window, or the engine does not "see" it.

A running handler does not generate messages at all. I am not talking about messages generated by that handler, which is already in motion:

Code: Select all

on mouseUp
   dostuff
end mouseUp

on dostuff
   repeat until the optionKey is down
      put the screenMouseLoc
     send "dostuff" to me in 1
   end repeat
end dostuff
This works anywhere on screen.

So messages can be generated from a running handler regardless of the screenMouseLoc, but not out of whole cloth from the card to the engine if the cursor is off the card.

I guess.

Craig

bogs
Posts: 3813
Joined: Sat Feb 25, 2017 10:45 pm

Re: Questions about 'mouseEnter'

Post by bogs » Tue Aug 27, 2019 9:36 am

Well, while I still don't understand the 'why', at least I can understand what is happening thanks to your explanations. Much appreciated :D
Image

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

Re: Questions about 'mouseEnter'

Post by SparkOut » Wed Aug 28, 2019 10:15 am

Seems the server move ate my answer earlier

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”