Detecting MouseEnters

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Detecting MouseEnters

Post by richmond62 » Sun Jan 12, 2020 10:52 am

Ouch . . . trying to be too clever as usual, or too lazy (which, arguably, are two sides of the same coin) . . .

So . . . I have a slightly silly stack containing 4 images called:

"LEFT", "CENTRE", "RIGHT" and "BeetleB.png"

and a field called "ff" as you can see in the picture:
-
MEP.png
-
"LEFT", "CENTRE", "RIGHT" all contain the following code:

Code: Select all

on mouseEnter
   put the short name of me into fld "ff"
end mouseEnter
So, if I pass my pointer over any of them the name of whichever my pointer is over
ends up in the field.

"BeetleB.png" contains the following code:

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseUp
   move me to 300,500
end mouseUp
which means I can move it around with my mouse pointer.

BUT . . . if I move my beetle over one of the targets the mouseEnter script in the target does not fire.

---------------------

Now I know I could gutter around endlessly with lots of intersect routines, . . . . BUT :?
Attachments
Mouse Enter Problem.livecode.zip
Here's the stack.
(10.81 KiB) Downloaded 142 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Detecting MouseEnters

Post by richmond62 » Sun Jan 12, 2020 11:03 am

And, why, forbye, you may ask, is Richmond asking such a simple, goofy question . . .

Well, just "sook on this" as my Granny in Dundee used to say:
-
MEP2.png
-
That's going to be a richt scunner all ways . . .

If I use an intersect routine it will either return 3 targets or only the one with the lowest number
(let us imagine, if you will, that they are called t1,t2,t3,t4,t5 and t6) . . .

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseUp
   put 1 into KOUNT
   repeat until KOUNT > 6
      put "t" & KOUNT into TKOUNT
      if intersect(me,img TKOUNT, 5) then
         set the loc of me to the loc of img TKOUNT
      end if
      add 1 to KOUNT
   end repeat
end mouseUp
If I use mouseEnter in some way, it will very much depend on where inwith the image that is being dragged my pointer is located.
Attachments
MEP2.livecode.zip
Here's the stack.
(10.69 KiB) Downloaded 146 times

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

Re: Detecting MouseEnters

Post by bogs » Sun Jan 12, 2020 11:19 am

If I had to guess, and I do, I'd say that -
richmond62 wrote:
Sun Jan 12, 2020 10:52 am
if I move my beetle over one of the targets the mouseEnter script in the target does not fire.
- because you aren't entering at the time, you are dragging (the beetle). What would work without intersects would be to put a handler in the main stack script that you can call from your mouseUp handler that says something like {not tested} -

Code: Select all

# your mouse events, in which ever script ....

on mouseUp
   move me to 300,500 
   put the mouseLoc into x
   fieldUp(x)
end mouseUp
------------------------------
on fieldUp x
   if the mouseLoc is within the rect of field x then put word 2 of field x into field "ff"
end fieldUp
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Detecting MouseEnters

Post by richmond62 » Sun Jan 12, 2020 1:54 pm

Thanks, bogs . . . with a bit of modification . . . .
-
yeah.png
-
This code was put into the scriptEditor of the button "DRAG":

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseUp
   move me to 300,300
   click at the mouseLoc
end mouseUp
and this in the target:

Code: Select all

on mouseUp
   put "yeah" into fld "ff"
   wait 3 secs
   put empty into fld "ff"
end mouseUp
Attachments
Boggy.livecode.zip
Here's the script.
(1002 Bytes) Downloaded 163 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Detecting MouseEnters

Post by richmond62 » Sun Jan 12, 2020 3:53 pm

Mind you, that "wiggling around" could be a pain in the bum if you were working on a game . . .
-
MEP3.png
-
So, probably better to use set:

Here's the code in the Beetle:

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseUp
   set the lockScreen to true
   move me to 300,300
   click at the mouseLoc
   put fld "ff" into IMENA
   set the loc of me to the loc of img IMENA
   set the lockScreen to false
end mouseUp
and the code in all the targets:

Code: Select all

on mouseUp
   put the short name of me into fld "ff"
end mouseUp
Attachments
MEP3.livecode.zip
Here's the stack.
(10.92 KiB) Downloaded 170 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Detecting MouseEnters

Post by richmond62 » Sun Jan 12, 2020 3:59 pm

That last bit blocked me for quite some time . . . .

So, went shopping . . .
-
KF.jpg
Cheapo supermarket in Bulgaria
KF.jpg (12.14 KiB) Viewed 3836 times
-

Dead easy to work out what that place is for as the Scots word for "buy" is coup.

and, interestingly enough, cheapo comes from the same root.

And all, mysteriously sorted itself out in my brain.

Frankly I always do my best programming at a safe distance from a computer. 8)
Last edited by richmond62 on Sun Jan 12, 2020 6:59 pm, edited 1 time in total.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Detecting MouseEnters

Post by jacque » Sun Jan 12, 2020 5:45 pm

You may not need to move the beetle at all if you set the enabled of it to false, click at the mouseloc, and then set the enabled back to true. Disabled objects pass mouse clicks through to the underlying object.

You might want to see if controlAtLoc(the mouseloc) works as well when the beetle is disabled, which would save some overhead. If it returns correctly then just send a mouseUp to the control.

I'm not at my Mac right now so can't test.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Detecting MouseEnters

Post by richmond62 » Sun Jan 12, 2020 6:58 pm

jacque wrote:
Sun Jan 12, 2020 5:45 pm
Disabled objects pass mouse clicks through to the underlying object.
Thank you for that, sounds "just the ticket." :)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”