Exemple #1
0
        /// <summary>
        /// Handle the mouse click events.
        /// </summary>
        public virtual void Handle()
        {
            MouseButtons button = MouseButtons.None;

            if (MouseUtils.AnyButtonPressed(out button))
            {
                if (MouseDown != null)
                {
                    MouseDown(this, new MouseButtonEventArgs(button, MouseUtils.Position));
                }
                else
                {
                    OnMouseDown();
                }

                if (Click == null || !Click(this, new MouseButtonEventArgs(button, MouseUtils.Position)))
                {
                    Focus();

                    switch (button)
                    {
                    case MouseButtons.Left:
                        OnLeftClick();
                        break;

                    case MouseButtons.Middle:
                        OnMiddleClick();
                        break;

                    case MouseButtons.Right:
                        OnRightClick();
                        break;

                    case MouseButtons.XButton1:
                        OnXButton1Click();
                        break;

                    case MouseButtons.XButton2:
                        OnXButton2Click();
                        break;
                    }
                }
            }

            if (MouseUtils.AnyButtonReleased(out button))
            {
                if (MouseUp != null)
                {
                    MouseUp(this, new MouseButtonEventArgs(button, MouseUtils.Position));
                }
                else
                {
                    OnMouseUp();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Update the object. Call during any PreUpdate() function.
        /// </summary>
        public virtual void Update()
        {
            if (!PlayerInput.IgnoreMouseInterface)
            {
                if (MouseUtils.Rectangle.Intersects(Rectangle))
                {
                    Main.player[Main.myPlayer].mouseInterface = true;

                    if (MouseEnter != null && !mouseEnter)
                    {
                        mouseEnter = true;
                        MouseEnter(this, new MouseEventArgs(MouseUtils.Position));
                    }
                    else
                    {
                        OnMouseEnter();
                    }

                    if (MouseHover != null)
                    {
                        MouseHover(this, new MouseEventArgs(MouseUtils.Position));
                    }
                    else
                    {
                        OnMouseHover();
                    }

                    Handle();
                }
                else
                {
                    if (mouseEnter && MouseLeave != null)
                    {
                        mouseEnter = false;
                        MouseLeave(this, new MouseEventArgs(MouseUtils.Position));
                    }
                    else
                    {
                        OnMouseLeave();
                    }

                    if (MouseUtils.AnyButtonPressed())
                    {
                        Unfocus();
                    }
                }
            }

            foreach (UIObject obj in Children)
            {
                obj.Update();
            }
        }