Question about 'within'...

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
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Question about 'within'...

Post by bogs » Sat Aug 10, 2019 4:15 pm

The goal I'm working on is to see if the mouse is within the bounds of the effective rect of the stack to set a blend level of the stack.

The problem I'm having is that as soon as the mouse moves over another object, apparently it is no longer considered 'within' the rect of the stack, even though the object is obviously within the rect of the stack.

For instance, if you have a field, and the mouse moves over it, the mloc is no longer within the rect of the stack (which I admit freely, I don't understand at all).

So I tried to solve that by generating the rect boundary into a variable, then getting the two points of the mLoc and then comparing them, however, apparently 'within' is not the correct function for this (even though the dictionary says it is).

I'm sure someone knows a way to do this, and I hope they will share it here :D

Edit -
Dictionary example I was referring too is
Examples:
"22,33" is within "22,17,150,200" -- evaluates to true
Code that apparently is failing to register this example -

Code: Select all

on mouseEnter
   put the effective rect of stack "winShape" into lclRect
   put item 1 of the mouseLoc into lclX; put item 2 of the mouseLoc into lclY
   if (lclX,lclY) is within lclRect then 
      set the blendLevel of stack "winShape" to "0"
   end if
end mouseEnter
The debugger *does* stop to evaluate this, but skips immediately to 'end mouseEnter' :roll:

The original code I was attempting was

Code: Select all

if the mouseLoc is not within lclRect then set the blendLevel of stack "winShape" to "50"
Image

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

Re: Question about 'within'...

Post by Klaus » Sat Aug 10, 2019 4:31 pm

Hi bogs,

not sure if at the time of "mouseenter" the loc is already within your rect!?
You could try to SEND the check with a little delay:

Code: Select all

on mouseEnter
   send "check_the_rect" to me in 2 milisecs
end mouseEnter

command check_the_rect
   put the effective rect of stack "winShape" into lclRect
   if the mouseloc is within lclRect then 
      set the blendLevel of stack "winShape" to "0"
   end if
end check_the_rect
And remember that the rect of a stack is in GLOBAL coordinates, but LC objects are in LOCAL coordinates! Maybe that is the problem?


Best

Klaus

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

Re: Question about 'within'...

Post by SparkOut » Sat Aug 10, 2019 5:12 pm

Not tested, but maybe the original one liner would work using the "screenMouseLoc" perhaps?
(Which seems to be the way Klausimausi is thinking too.)

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

Re: Question about 'within'...

Post by bogs » Sat Aug 10, 2019 8:48 pm

You are both AWESOME, I give you 2 Image Image

Some day, if I ever get my head wrapped around this completely, i may faint dead away. SparkOut, that does indeed reduce it back to a one liner. Thank you so much for that :D
Image

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

Re: Question about 'within'...

Post by Klaus » Sat Aug 10, 2019 8:49 pm

bogs wrote:
Sat Aug 10, 2019 8:48 pm
You are both AWESOME...
Tell us something new! :D

Post Reply