Page 1 of 1

Detecting MouseEnters

Posted: Sun Jan 12, 2020 10:52 am
by richmond62
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 :?

Re: Detecting MouseEnters

Posted: Sun Jan 12, 2020 11:03 am
by richmond62
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.

Re: Detecting MouseEnters

Posted: Sun Jan 12, 2020 11:19 am
by bogs
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

Re: Detecting MouseEnters

Posted: Sun Jan 12, 2020 1:54 pm
by richmond62
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

Re: Detecting MouseEnters

Posted: Sun Jan 12, 2020 3:53 pm
by richmond62
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

Re: Detecting MouseEnters

Posted: Sun Jan 12, 2020 3:59 pm
by richmond62
That last bit blocked me for quite some time . . . .

So, went shopping . . .
-
KF.jpg
Cheapo supermarket in Bulgaria
KF.jpg (12.14 KiB) Viewed 529 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)

Re: Detecting MouseEnters

Posted: Sun Jan 12, 2020 5:45 pm
by jacque
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.

Re: Detecting MouseEnters

Posted: Sun Jan 12, 2020 6:58 pm
by richmond62
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." :)