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

Re: Questions about 'mouseEnter'

Post by bogs » Wed Aug 28, 2019 11:48 am

SparkOut wrote:
Wed Aug 28, 2019 10:15 am
Seems the server move ate my answer earlier
If you happen to remember the gist of what you wrote, I'd appreciate seeing it should you feel compelled to write it again, like I did :D
bogs wrote:
Mon Aug 26, 2019 10:41 am
I actually posted this last night, but for some reason, it wasn't here when I woke up, so reposting :shock:
Image

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

Re: Questions about 'mouseEnter'

Post by SparkOut » Wed Aug 28, 2019 1:29 pm

It was, in essence, a very short version of Craig's thoughts, mentioning that mouse messages are positional. A stack can have non positional messages reach the engine, eg keyDown, keyUp - which may have different results depending on whether the cursor is in an unlocked field or the stack / substacks have focus or not. Whereas a positional *message* is not generated unless the position is in the correct rect. But the *state* of the position is a readable property wherever the position is, so a handler that asks for the values can receive them.
Or so it seems to me.

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

Re: Questions about 'mouseEnter'

Post by bogs » Wed Aug 28, 2019 4:15 pm

Well, thanks to both of your replies, I was able to get a better handle at least as to what is going on, and was able to refine some other handlers I was working on to take it into account, but it still seems like bizarre behavior to me, or at least contrary to what I would expect to be taking place :roll:
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 » Wed Aug 28, 2019 4:59 pm

Bogs.

Just goes to show you how much we place on LC's shoulders; how much we assume nearly divine status to that program. It would never occur to any of us to question Excel in this way, that, say, hitting the return key while another app is in front would move the selected cell down one line.

Craig

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

Re: Questions about 'mouseEnter'

Post by bogs » Wed Aug 28, 2019 6:55 pm

Yes, while I don't use Excel, I would find it equally bizarre if, while (program x) had focus, some other application was intercepting the return key :P In this case though, as I outlined earlier, the behavior I find unsettling is that *this* application had focus, but did not pick up the messages.

To put those two statements on equal footing, I imagine that if you have Excel (or whatever) as the foremost program, then any messages passed would be through the focused application, such as mouse movements, entering objects, tab key presses, etc.

What I did not expect was for those messages to disappear into the ether because despite having the focus, the cursor of all things wasn't within the borders of the application.

Obviously, if the cursor is outside of the application, and you click (down/up), *then* I might reasonably assume the actual click event would go somewhere else, but that isn't what we're talking about here, we're talking about simple mouse movement, which at some level Lc *is* keeping track of, so I think it should be reporting it with the one line as written above regardless of whether the cursor is within the borders of the application or not, and probably whether the application has focus or not, but in this case, I can see that going either way.

Hopefully I am not just being too obtuse.
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 » Wed Aug 28, 2019 8:13 pm

Hopefully I am not just being too obtuse.
You are not, I see the difference as you state it.

It must then just be how the engine works. It will not send certain messages, like "mouseMove", unless the cursor is in bounds. In the stack script:

Code: Select all

on mouseUp
     send "mouseMove" to me in 1
  end mouseUp
  
  on mouseMove
     put the screenMouseLoc
  end mouseMove
Craig

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

Re: Questions about 'mouseEnter'

Post by bogs » Wed Aug 28, 2019 9:09 pm

That is indeed very close to what I wound up with. Just to take all the mystery out of it, the application is a clock/calendar/timer of sorts, and uses mouseDown/Up events to start / record the timed parts.
uberTimer.png
Has anybody got the time?
uberTimer.png (64.12 KiB) Viewed 156 times
The relevant code, thanks to your direct suggestions, turned out to be put into mouseMove with checkRect handling the actual decision of whether the mouse was over the stack or not:

Code: Select all

// stack winShape
local lclSecs, lclBool,  lclHours, lclMins, lclRec
local lclScreenPosition

on openStack
   go stack "positioner"
   go stack "winShape"
   set the blendLevel of this stack to 50
   put the abbreviated date into field "calendar" of card "frmMain"
   if line 1 of field "records" is not the long date then put the long date into line 1 of field "records"
   timeClock
   go stack "positioner"; set the blendLevel of stack "positioner" to 98
end openStack

on timeClock
   put the long time into field "clock"
   send timeClock to me in 59 ticks
end timeClock

on mouseMove
   put the effective rect of stack "positioner" into lclScreenPosition
   checkRect
end mouseMove

on checkRect
   put the effective rect of stack "positioner" into lclScreenPosition
   if the screenMouseLoc is within lclScreenPosition then
      setSolid
   else
      setTranparent
   end if
   send checkRect to me in 1 seconds
// since speed isn't a necessity, 1 or even 2 seconds works fine, and the delay is actually desireable...   
end checkRect

on setSolid
      repeat until the blendLevel of stack "winShape" is 10
         set the blendLevel of stack "winShape" to the blendLevel of  stack "winShape"  -1
         set the blendLevel of stack "positioner" to the blendLevel of  stack "winShape"  +20
         wait 1 ticks with messages
      end repeat
      exit setSolid
end setSolid

on setTranparent
   repeat until the blendLevel of  stack "winShape"  is 50
      set the blendLevel of  stack "winShape"  to the blendLevel of  stack "winShape"  +1
      set the blendLevel of stack "positioner" to the blendLevel of  stack "winShape"  +49
      wait 1 ticks with messages
   end repeat  
   exit setTranparent
end setTranparent

on closeStack
   set the stackFileVersion to 5.5
   save this stack
   pass closeStack
end closeStack

on mouseDown
   put the mouseLoc into lclTopLeft
end mouseDown

on mouseUp
   if lclTopLeft is not "" then put "" into lclTopLeft
   put the seconds into lclSecs
   if lclBool is "1" then
      put "2" into lclBool
   else
      put "00" into lclHours; put "00" into lclMins
      put "1" into lclBool
      timer   
   end if   
end mouseUp

on timer
   if lclBool is "1" then
      put format("%02d",the seconds -lclSecs) into field "timer"
      if (lclMins < "30") and (lclHours < "01") then set the textColor of field "timer" to "red"
      if (lclMins > "30") and (lclHours < "01") then set the textColor of field "timer" to "yellow"
      if lclHours > "01" then set the textColor of field "timer" to "green"
      
      if field "timer" is "60" then 
         put format("%02d",lclMins +1) into lclMins
         put the seconds into lclSecs
      end if
      
      if tmpMins is "60" then 
         put format("%02d",lclHours +1) into lclHours
         put "" into tmpMins
      end if
      send timer to me in 10 ticks
   else
      put tab & lclHours & " : " & lclMins & " : " & field "timer" & cr before line 2 of field "records"
      set the textColor of line 2 of field "records" to the textColor of field "timer"
      put "00" into field "timer"
      put "00" into lclHours
      put "00" into lclMins
      set the textColor of field "timer" to "white"
   end if
end timer
As you can see from the code, I really just need the mouse position to judge whether the timer and the positioner stack should fade or not, the timer fades a little, the positioner stack fades completely (99), so it looks like this -
uberTimerFaded.png
Blended baby!
uberTimerFaded.png (38.94 KiB) Viewed 154 times
The whole setup is designed just to not have to write the window shape moving handlers.

Code: Select all

// stack positioner...
on openStack
   set the topLeft of this stack to the topLeft of stack "winShape"
   set the blendLevel of this stack to "99"
end openStack

// thanks to Hermann again for this bit of information...
on moveStack
   set the topLeft of stack "winShape" to the topLeft of this stack
   send moveDone to me in .5 seconds
end moveStack

on moveDone
   if the mouse is up then set the topLeft of stack "winShape" to the topLeft of this stack
end moveDone
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”