Пример #1
0
        /// <summary>
        /// Updates the button, eventually fires the events and returns the new ButtonState.
        /// </summary>
        /// <param name="element">The element the buttonLogic is calculated for.</param>
        /// <param name="position">The position of the mouse cursor.</param>
        /// <param name="button">The buttons of the mouse.</param>
        /// <param name="pressed">Flag that indicates if mouse was pressed.</param>
        /// <returns>The new buttonState.</returns>
        public ButtonState Update(IGuiElement element, Vector3 position, MouseButton button, bool pressed)
        {
            bool isOver = element.ContainsPoint(new Vector2(position.X, position.Y));

            WasOver = isOver;

            if (button == MouseButton.Left && pressed && isOver)
            {
                ButtonDown = true;
            }
            else if (button == MouseButton.Left && !pressed && ButtonDown)
            {
                ButtonDown = false;
            }

            ButtonState newState = ButtonState.Normal;

            if (ButtonDown)
            {
                if (isOver)
                {
                    newState = ButtonState.PressedHover;
                }
                else
                {
                    newState = ButtonState.Pressed;
                }
            }
            else
            {
                if (isOver)
                {
                    newState = ButtonState.Hover;
                }
                else
                {
                    newState = ButtonState.Normal;
                }
            }
            return(newState);
        }
Пример #2
0
        /// <summary>
        /// Updates the button, eventually fires the events and returns the new ButtonState.
        /// </summary>
        /// <param name="element">The element the buttonLogic is calculated for.</param>
        /// <param name="position">The position of the mouse cursor.</param>
        /// <param name="button">The buttons of the mouse.</param>
        /// <param name="pressed">Flag that indicates if mouse was pressed.</param>
        /// <returns>The new buttonState.</returns>
        public ButtonState Update(IGuiElement element, Vector3 position, MouseButton button, bool pressed)
        {
            bool isOver = element.ContainsPoint(new Vector2(position.X, position.Y));

            if (isOver && !WasOver)
            {
                if (Hover != null)
                {
                    Hover();
                }
            }
            else if (WasOver && !isOver)
            {
                if (Leave != null)
                {
                    Leave();
                }
            }
            WasOver = isOver;

            if (button == MouseButton.Left && pressed && isOver)
            {
                ButtonDown = true;
                if (Down != null)
                {
                    Down();
                }
            }
            else if (button == MouseButton.Left && !pressed && ButtonDown)
            {
                ButtonDown = false;
                if (Up != null)
                {
                    Up();
                }
            }

            ButtonState newState = ButtonState.Normal;

            if (ButtonDown)
            {
                if (isOver)
                {
                    newState = ButtonState.PressedHover;
                }
                else
                {
                    newState = ButtonState.Pressed;
                }
            }
            else
            {
                if (isOver)
                {
                    newState = ButtonState.Hover;
                }
                else
                {
                    newState = ButtonState.Normal;
                }
            }
            return(newState);
        }