Exemplo n.º 1
0
        private void OnTouch(TouchEvent evt)
        {
            SparrowSharp.MouseCursor = (_useHandCursor && _enabled && evt.InteractsWith(this)) ? MouseCursor.Hand : MouseCursor.Default;

            if (!_enabled)
            {
                return;
            }
            Touch touch = evt.GetTouch(this);

            if (touch == null)
            {
                State = ButtonState.Up;
            }
            else if (touch.Phase == TouchPhase.Stationary)
            {
                State = ButtonState.Over;
            }
            else if (touch.Phase == TouchPhase.Began && _state != ButtonState.Down)
            {
                _triggerBounds = GetBounds(Stage);
                _triggerBounds.Inflate(MaxDragDist, MaxDragDist);

                State = ButtonState.Down;
            }
            else if (touch.Phase == TouchPhase.Moved)
            {
                var isWithinBounds = _triggerBounds.Contains(touch.GlobalX, touch.GlobalY);

                if (_state == ButtonState.Down && !isWithinBounds)
                {
                    // reset button when finger is moved too far away ...
                    State = ButtonState.Up;
                }
                else if (_state == ButtonState.Up && isWithinBounds)
                {
                    // ... and reactivate when the finger moves back into the bounds.
                    State = ButtonState.Down;
                }
            }
            else if (touch.Phase == TouchPhase.Ended && _state == ButtonState.Down)
            {
                State = ButtonState.Up;
                Triggered?.Invoke(this, evt);
            }
        }