Page 1 of 1
Mouse Movement-Based Group Messages
Posted: Mon Dec 15, 2014 1:01 pm
by theotherbassist
I have nine images on a card. Each is basically a response key. I wrote some code to change the color overlay to red on mouseEnter and to white on mouseLeave for each image individually. This color overlay with a blendMode of multiply is basically how I'm achieving a red hover effect for the images. Now I have added a second mode where the nine images are split into three "clusters" (I am avoiding the use of the term "group" here) of three. I basically want this mode to be a portion of a quiz that is easier for the user because it asks them for a less-specific answer. So when the mode is changed, the three images of each cluster move together so that only space between the large clusters remains. In this mode, my script turns on the red hover for all three keys in a cluster when the mouse enters any one of the keys of that cluster (and changes the overlay to white when the mouse leaves any of the cluster's images). I also wrote code that alters the functions of each of a cluster's constituent keys to be the same when those keys squash together at the mode switch. This way, there are now effectively three larger and more inclusive response keys.
My problem is that when I hover over cluster 2 (which is a block that includes key 4, key 5, and key 6), for instance, and I move my mouse over the border between key 4 and key 5 or key 5 and key 6 (thus staying within the boundaries of the larger cluster), I often get a brief flicker. I know this is because of the mouseLeave message being sent when I exit the area over one key and the mouseEnter message sent immediately after due to the mouse entering the area over the next adjacent image. How can I bypass the mouseLeave message only when I move into an adjacent image key without using location-based commands? I might like to rearrange the keys later, so I don't want to define specific areas in pixels for this task.
I essentially want to group the images and apply mouseEnter/mouseExit functions to the groups directly, but I know this isn't possible because of the way group script is passed to the objects directly.
Re: Mouse Movement-Based Group Messages
Posted: Mon Dec 15, 2014 1:24 pm
by dave.kilroy
hi - I probably just need more coffee to be able to understand what you mean - but could you include some screenshots to explain a bit more?
Re: Mouse Movement-Based Group Messages
Posted: Mon Dec 15, 2014 1:37 pm
by theotherbassist
Re: Mouse Movement-Based Group Messages
Posted: Mon Dec 15, 2014 1:58 pm
by theotherbassist
In the clustered mode, i get a flicker at the point of the green rectangle (the image border) when i move my mouse from point A to point B
Re: Mouse Movement-Based Group Messages
Posted: Mon Dec 15, 2014 3:40 pm
by dave.kilroy
Hi - I've just experimented and the only way I can get the cursor to change is if there is something setting the cursor shape while in the image
The way I got around this was to include a mouse move handler in the containing control (card or if possible a group) that found the rect of the control and 'added some padding' to it - this way you can have a gap between your images without seeing a 'flicker' (at least I couldn't see a flicker when I tested)
Code: Select all
on mousemove
put the rect of grc "grcLeft" into tRectLeft
put the rect of grc "grcRight" into tRectRight
put (item 1 of tRectLeft - 10) into item 1 of tRectLeft
put (item 3 of tRectLeft + 10) into item 3 of tRectLeft
put (item 1 of tRectRight - 10) into item 1 of tRectRight
put (item 3 of tRectRight + 10) into item 3 of tRectRight
switch
case the mouseloc is within tRectLeft
set the cursor to hand
lock cursor
set the backgroundcolor of grc "grcLeft" to "red"
set the backgroundcolor of grc "grcRight" to "blue"
put "in"
break
case the mouseloc is within tRectRight
set the cursor to hand
lock cursor
set the backgroundcolor of grc "grcRight" to "red"
set the backgroundcolor of grc "grcLeft" to "blue"
put "in"
break
default
unlock cursor
set the backgroundcolor of grc "grcRight" to "blue"
set the backgroundcolor of grc "grcLeft" to "blue"
put "out"
end switch
end mousemove
What I've done is a 'quick-and-dirty' way without elegance which just gets the job done - I'm sure others will add refinements
Also - there are a lot of things you could do so that you don't put yourself into this position...
Kind regards
Dave
Re: Mouse Movement-Based Group Messages
Posted: Mon Dec 15, 2014 6:14 pm
by theotherbassist
If two objects are adjacent and I move the cursor from one into the other, which message is sent first: mouseLeave (first object) or mouseEnter (second object)?
Re: Mouse Movement-Based Group Messages
Posted: Mon Dec 15, 2014 6:23 pm
by Klaus
Hi Mr. Bassman,
theotherbassist wrote:If two objects are adjacent and I move the cursor from one into the other,
which message is sent first: mouseLeave (first object) or mouseEnter (second object)?
is this s trick question?
I would say, "mouseleve" comes first.
Best
Klaus, another bass player, see my basspage
http://www.major-k.de/bass/index.html
Re: Mouse Movement-Based Group Messages
Posted: Mon Dec 15, 2014 6:31 pm
by theotherbassist
Yes, it seems that would be the case intuitively. But if there is no space between the two objects, the mouseLeave message and the mouseEnter message would be sent at the exact same time. The movement upon which the mouseLeave and mouseEnter are contingent is one and the same. No?
Re: Mouse Movement-Based Group Messages
Posted: Mon Dec 15, 2014 6:37 pm
by theotherbassist
I seem to have solved this by simply delaying the "check if the mouse is outside the group rect" function by 3 ticks inside the mouseLeave.
[Script in one of the nine objects]
Code: Select all
on mouseLeave
wait 3 ticks
if the mouseLoc is not within the rect of group "whatever I called the group of objects" then
send functionForRemovingtheHilite
end if
end mouseLeave
Re: Mouse Movement-Based Group Messages
Posted: Mon Dec 15, 2014 7:13 pm
by theotherbassist
Although the processing does slow everything down significantly... because it affects usability in the individual button mode. Of course, I can add in an
to stop the delay when it isn't needed, but this extra processing creates a delay of similar proportion anyway.
Klaus:
Very cool. Music is just the expression of a deconstructed and reconstructed sonic syntax. Get good enough, and we call it a "groove." One day I'll be able to groove with livecode syntax as well. Feel free to check out my music for now though.
http://thevanvons.bandcamp.com
Re: Mouse Movement-Based Group Messages
Posted: Tue Dec 16, 2014 3:17 am
by sturgis
Not sure if it will help, but you might "lock screen" and "unlock screen" around the code that sets and unsets your hilite.
As far as which is first, yeah. Leave fires first. (you can check this with the message watcher under the development menu)
Re: Mouse Movement-Based Group Messages
Posted: Tue Dec 16, 2014 6:55 pm
by jacque
Three ticks is a long time on a computer. I think you could shave it down to a few milliseconds. If you haven't already tried it, start with 1 or 2 milliseconds and adjust from there.