コード例 #1
0
        /// <summary>
        /// Handle mouse released
        /// </summary>
        /// <param name="sender">Object sender</param>
        /// <param name="e">Event arguments</param>
        private void MouseButtonReleased(object sender, SFML.Window.MouseButtonEventArgs e)
        {
            //nice it's the right button !
            //Or mabe the right left button ^^
            //(in fact left is the right button to check !)
            //
            //OverControl can't be null, we can click on null !
            if (e.Button == Mouse.Button.Left && GuiManager.OverControl != null)
            {
                //to perform a click, last press position must be in the control bounds !!
                if (GuiManager.OverControl.Bounds.Contains(this._pressPosition))
                {
                    //hey we click play my sound pls !
                    if (GuiManager.OverControl is IAudioable)
                    {
                        IAudioable audio = (IAudioable)GuiManager.OverControl;
                        this._audioManager.PlaySound(audio.ClickSoundKey);
                    }

                    GuiManager.OverControl.OnClick(e);
                }

                //ok release is finish so switch last press position to null :)
                this._pressPosition = null;
            }
        }
コード例 #2
0
        /// <summary>
        /// Handle mouse moved
        /// </summary>
        /// <param name="sender">Object sender</param>
        /// <param name="e">Event arguments</param>
        private void MouseMoved(object sender, SFML.Window.MouseMoveEventArgs e)
        {
            Vector position = new Vector(e.X, e.Y);

            foreach (Container container in this._containers)
            {
                if (container.Bounds.Contains(position))
                {
                    foreach (Control control in container.Controls)
                    {
                        if (control.Bounds.Contains(position))
                        {
                            if (!control._isMouseOver)     //if control wasn't in mouse over state it's an OnEnter.
                            {
                                if (control is IAudioable) //hey we enter, play my sound pls !
                                {
                                    IAudioable audio = (IAudioable)control;

                                    if (!string.IsNullOrEmpty(audio.OverSoundKey))
                                    {
                                        this._audioManager.PlaySound(audio.OverSoundKey);
                                    }

                                    GuiManager.OverControl = control;
                                    control._isMouseOver   = true;
                                    control.OnEnter();
                                }
                            }
                            else//no change for me it's over !
                            {
                                control.OnOver();
                            }
                        }
                        else
                        {
                            if (control._isMouseOver)
                            {
                                if (GuiManager.OverControl == control)//hey it's me and i leave so put out my pointer pls !
                                {
                                    GuiManager.OverControl = null;
                                }

                                control._isMouseOver = false;
                                control.OnLeave();
                            }
                        }
                    }
                }
            }
        }