Stop Group receiving multiple mouseenter

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Sjatplat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 75
Joined: Wed Jun 22, 2011 1:53 pm

Stop Group receiving multiple mouseenter

Post by Sjatplat » Fri Apr 04, 2014 6:24 pm

Hi there

My custom scrollbar and buttons are receiving multiple mouseenter and mouseleave messages when the mouse moves over different parts in the group. This results in a small flickering as I change colors on its contents to make a hover-state. How do I prevent this? I made a transparent graphic to cover all the elements in the group to stop the flickering but with this method is a little tedious when I want to edit ...

any smart solutions out there?

Sjat

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

Re: Stop Group receiving multiple mouseenter

Post by Klaus » Fri Apr 04, 2014 6:31 pm

Hi Sjat,

depends on what exactly should happen, I will need to take a look at your script(s) :D


Best

Klaus

Sjatplat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 75
Joined: Wed Jun 22, 2011 1:53 pm

Re: Stop Group receiving multiple mouseenter

Post by Sjatplat » Fri Apr 04, 2014 6:54 pm

Hi Klaus

I made a very simple group with 2 graphic rectangles to check if its my code thats wrong.
The group script is this:

Code: Select all

on mouseenter
   set the backgroundcolor of graphic 1 of me to white
end mouseenter

on mouseleave
   set the backgroundcolor of graphic 1 of me to black
end mouseleave
Whenever I move from one rectangle to the other the rectangle that changes color flickers a nanosecond....
there´s no script in the rectangles. Just this one in the group

I guess when I move from one rectangle to the other the group recieves a mouseleave and a new mouseenter message...
Sjat

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Stop Group receiving multiple mouseenter

Post by dunbarx » Fri Apr 04, 2014 7:27 pm

Right.

The group script receives messages from all the controls within it. You options are either to move the handler to the controls themselves, or to limit which controls will be allowed:

if the mouseLoc is within the rect of grc "doNotSend" then...

Now if there are no particular controls that make this work for you, perhaps you can perhaps set up a timer that locks those messages out. Can you do this? (pseudocode):

on mouseEnter
set up timerFlag
if the ticks < timerFlag then exit to top
else pass mouseEnter
end mouseEnter

The "timerFlag" can be, say, 30 or 60 ticks, or whatever, and if another message is generated within that time frame it is ignored.

Craig Newman

Sjatplat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 75
Joined: Wed Jun 22, 2011 1:53 pm

Re: Stop Group receiving multiple mouseenter

Post by Sjatplat » Fri Apr 04, 2014 7:55 pm

thanks Craig

I just remembered something else I´ve asked in the forum to prevent controls receiving messages and that solved my problem...

I just put an empty Mouseenter and mouseleave handler in the graphic control that isn´t affected. And the flicker is gone....
So you where absolutely right in asking about what should happen....This solution won´t work in other scenarios...

thank you for your time

Sjat

Sjatplat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 75
Joined: Wed Jun 22, 2011 1:53 pm

Re: Stop Group receiving multiple mouseenter

Post by Sjatplat » Fri Apr 04, 2014 9:12 pm

I was of course wrong....blah

I guess I have to choose between a timer (I´m not too fond of that..) or the way I do it: put a rectangle with a blend level at 100 on top of everything...

btw: I´m creating an invisible custom scrollbar where the scrollthumb shows up when you enter the group. Just like the scrollbars in the latest os x.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Stop Group receiving multiple mouseenter

Post by dunbarx » Sun Apr 06, 2014 3:25 am

It is perfectly OK to solve a problem with a kluge. That overlay is just such a kluge. It heads off messages at the pass.

Sometimes those things fail to adapt to changing conditions, though. A more robust solution, like a timer thingie, is the grown-up way to do it. Think how much fun it would be to write this.

Craig

Post Reply