Event when mouse leaves card or stack?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ChiefTechnicalMonkey
Posts: 5
Joined: Tue Jul 29, 2008 6:31 pm

Event when mouse leaves card or stack?

Post by ChiefTechnicalMonkey » Wed Jul 30, 2008 2:54 pm

Hi Guys,

Im trying to implement a drop-down menu, as oppsoed to a pull down one. (A drop down activates on mouseEnter rather then mouseup)

Using a separate stack for the menu and the "pulldown" keyword I have it coming up fine, but I need an event when the cursor leaves the screen area of the menu to make it go away.

I tried mouseLeave on the card and the stack but it seems like neither generate events themselves, they just process events bubbled up. The problem with bubbling up the events from the choices buttons is that I get a mouseLeave when ever I move between two choices :(

I tried testing the mouse location when that occurs to see if its outside the card but I get an error. (My guess is because there is no valid coordinate system in the context of the menu outside of its own screen real-estate.)

Help? Can someone show me how to do this? It seems like knowing when the cursor leaves the area of a card or a stack is a generally useful thing...

CTM

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Wed Jul 30, 2008 3:24 pm

The only way I got this to work is this:

2 stacks: test1 and test2. One button on test1. Script of that button:

Code: Select all

on mouseEnter
    send "testIt" to me in 1000 millisecs
    pulldown stack "test2" 
end mouseEnter

on testIt
    if globalloc(the mouseloc) is not within the rect of stack "test2" then 
        close stack "test2"
        go stack "test1"
        -- hack to return the focus
        click at -10000,-10000
    else
        send "testIt" to me in 40 millisecs
    end if
end testIt
A bit of a dirty hack though.

Hope that helps,

Malte

ChiefTechnicalMonkey
Posts: 5
Joined: Tue Jul 29, 2008 6:31 pm

Post by ChiefTechnicalMonkey » Wed Jul 30, 2008 3:42 pm

Thanks, thats very helpful.

What does globalloc(...) do?

Im still learning this language and I was disappointed to find that there isnt really a language reference in the user's guide.

ChiefTechnicalMonkey
Posts: 5
Joined: Tue Jul 29, 2008 6:31 pm

Post by ChiefTechnicalMonkey » Wed Jul 30, 2008 3:44 pm

Oh... global loc...

Just looekd it up.

It parsed to me as "glob alloc" ... old C habits ;)

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Wed Jul 30, 2008 5:09 pm

I really like the dictionary. But I kind of grew into the language the last 6 years :-)

However, the language reference would not be of much help in this case. This example is one of the cases where you need to learn about the engine behaviour. It is a matter of taste I guess if it needs to be considdered flaky or correct behaviour.

You pulldown a stack, so the engine expects the pulldown operation to be terminated with a click somewhere. This might or might not be correct behaviour. However I find it strange to lose focus on the stack I am telling the engine to be going to until a click event happens. If the pulldown operation is not terminated with a click though, there will be no mouseEnter / leave / move events sent to the original control, which I find flaky at least.

However, glad it works for you.

All the best,

malte

ChiefTechnicalMonkey
Posts: 5
Joined: Tue Jul 29, 2008 6:31 pm

Post by ChiefTechnicalMonkey » Wed Jul 30, 2008 6:36 pm

Yeah you expect that really with any higher level "engine" environment-- that it will have its own quirks and ways of viewing the world. Those are things im just going to have to try to absorb as I worth with it.

But thanks much for the help. I'll probably be back with other questions. ;)

ChiefTechnicalMonkey
Posts: 5
Joined: Tue Jul 29, 2008 6:31 pm

Post by ChiefTechnicalMonkey » Wed Jul 30, 2008 9:05 pm

That works great thanks!

Since my menu is fully covered by buttons I didn't have to actually use the timer hack but could just use the test and body on the bubbled up mouseLeave.

Still sort of too bad though that there aren't card and stack level event generators. It seems like that would be a good addition to the next version.

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Wed Jul 30, 2008 9:46 pm

Oh, usually they are there, just not if you pulldown or popup a stack.
The strange thing is that the messages travel along the messagepath (what bit you in the first place), but the actual card and stack do not get the events if (and only if) the stack is popped up or pulled down. If you change your call to the stack to something like toplevel and hide the decorations of the pseudo pulldown you will see the card / stack getting mouseleave.

All the best,

Malte

Post Reply