Page 1 of 1

Question about 'within'...

Posted: Sat Aug 10, 2019 4:15 pm
by bogs
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"

Re: Question about 'within'...

Posted: Sat Aug 10, 2019 4:31 pm
by Klaus
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

Re: Question about 'within'...

Posted: Sat Aug 10, 2019 5:12 pm
by SparkOut
Not tested, but maybe the original one liner would work using the "screenMouseLoc" perhaps?
(Which seems to be the way Klausimausi is thinking too.)

Re: Question about 'within'...

Posted: Sat Aug 10, 2019 8:48 pm
by bogs
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

Re: Question about 'within'...

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