A OnHover event for Button

Sep 11, 2012 at 3:36 PM
Edited Sep 11, 2012 at 3:44 PM

Hi everybody !

Today, i make a mini code plug-in. This allow you to launch something once when the mouse is hover the button.

In Button.cs (Ruminate.GUI.Content.Button):

In Variable section:

private bool _switch;

In each public Button() :

_switch = true;

In Events section:

publicbool OnHover()
        {
            if (this.IsHover && _switch)
            {
                _switch = false;
                return true;
            }
            else if (!this.IsHover && !_switch)
            {
                _switch = true;
                return false;
            }
            else if (this.IsHover && !_switch)
            {
                return false;
            }
            else if (!this.IsHover && _switch)
            {
                return false;
            }
            else { return false; } 
        }

And a example from my project (this code part come from my gui class):

public override void Update(GameTime gameTime)
        {
            if (_connexion.OnHover() || _load.OnHover() || _profils.OnHover() || _options.OnHover() || _exit.OnHover())
            {
                _bip.Play(0.05f,0,0);
            }
            _gui.Update();
        }

So, this "plug-in" permit me to play a little sound once time the player hover the button. Enjoy ;)