/// <inheritdoc/>
        public override Single GetAxisValue(GamePadAxis axis)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            switch (axis)
            {
            case GamePadAxis.None:
                return(0f);

            case GamePadAxis.LeftJoystickX:
                return(leftJoystickX);

            case GamePadAxis.LeftJoystickY:
                return(leftJoystickY);

            case GamePadAxis.RightJoystickX:
                return(rightJoystickX);

            case GamePadAxis.RightJoystickY:
                return(rightJoystickY);

            case GamePadAxis.LeftTrigger:
                return(leftTrigger);

            case GamePadAxis.RightTrigger:
                return(rightTrigger);
            }
            throw new ArgumentException("axis");
        }
Exemple #2
0
        /// <summary>
        /// Handles <see cref="GamePad.AxisDownEvent"/> when the drop down is open.
        /// </summary>
        private void OnGamePadAxisDown_DropDownOpen(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, ref RoutedEventData data)
        {
            if (GamePad.UseAxisForDirectionalNavigation)
            {
                if (GamePad.DirectionalNavigationAxisX == axis || GamePad.DirectionalNavigationAxisY == axis)
                {
                    var direction = device.GetJoystickDirectionFromAxis(axis);
                    switch (direction)
                    {
                    case GamePadJoystickDirection.Up:
                        MoveItemFocus(-1);
                        break;

                    case GamePadJoystickDirection.Down:
                        MoveItemFocus(1);
                        break;

                    case GamePadJoystickDirection.Left:
                        if (PART_ScrollViewer != null)
                        {
                            PART_ScrollViewer.HandleKeyScrolling(Key.Left, ModifierKeys.None, ref data);
                        }
                        break;

                    case GamePadJoystickDirection.Right:
                        if (PART_ScrollViewer != null)
                        {
                            PART_ScrollViewer.HandleKeyScrolling(Key.Right, ModifierKeys.None, ref data);
                        }
                        break;
                    }
                    data.Handled = true;
                }
            }
        }
        /// <inheritdoc/>
        public override Boolean IsAxisReleased(GamePadAxis axis)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            switch (axis)
            {
            case GamePadAxis.None:
                return(false);

            case GamePadAxis.LeftJoystickX:
                return(IsAxisReleased(prevLeftJoystickX, leftJoystickX));

            case GamePadAxis.LeftJoystickY:
                return(IsAxisReleased(prevLeftJoystickY, leftJoystickY));

            case GamePadAxis.RightJoystickX:
                return(IsAxisReleased(prevRightJoystickX, rightJoystickX));

            case GamePadAxis.RightJoystickY:
                return(IsAxisReleased(prevRightJoystickY, rightJoystickY));

            case GamePadAxis.LeftTrigger:
                return(IsAxisReleased(prevLeftTrigger, leftTrigger));

            case GamePadAxis.RightTrigger:
                return(IsAxisReleased(prevRightTrigger, rightTrigger));
            }

            throw new ArgumentException("axis");
        }
        /// <inheritdoc/>
        public override Boolean IsAxisUp(GamePadAxis axis)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            switch (axis)
            {
            case GamePadAxis.None:
                return(true);

            case GamePadAxis.LeftJoystickX:
                return(!IsAxisDown(leftJoystickX));

            case GamePadAxis.LeftJoystickY:
                return(!IsAxisDown(leftJoystickY));

            case GamePadAxis.RightJoystickX:
                return(!IsAxisDown(rightJoystickX));

            case GamePadAxis.RightJoystickY:
                return(!IsAxisDown(rightJoystickY));

            case GamePadAxis.LeftTrigger:
                return(!IsAxisDown(leftTrigger));

            case GamePadAxis.RightTrigger:
                return(!IsAxisDown(rightTrigger));
            }

            throw new ArgumentException("axis");
        }
Exemple #5
0
        public float GetAxis(GamePadAxis axis)
        {
            switch (axis)
            {
            case GamePadAxis.LeftThumbX:
                return(thisState.LeftThumb.X);

            case GamePadAxis.LeftThumbY:
                return(thisState.LeftThumb.Y);

            case GamePadAxis.RightThumbX:
                return(thisState.RightThumb.X);

            case GamePadAxis.RightThumbY:
                return(thisState.RightThumb.Y);

            case GamePadAxis.LeftTrigger:
                return(thisState.LeftTrigger);

            case GamePadAxis.RightTrigger:
                return(thisState.RightTrigger);

            default:
                return(0f);
            }
        }
        /// <summary>
        /// Raises <see cref="GamePadDevice.AxisPressed"/> and <see cref="GamePadDevice.AxisReleased"/> in response
        /// to changes in a particular axis.
        /// </summary>
        /// <param name="axis">The axis to evaluate.</param>
        /// <param name="previousValue">The last known value of the axis.</param>
        /// <param name="currentValue">The current value of the axis.</param>
        private void CheckForAxisPresses(GamePadAxis axis, Single previousValue, Single currentValue)
        {
            var axisIndex = (int)axis;

            var axisWasDown = IsAxisDown(previousValue);
            var axisIsDown  = IsAxisDown(currentValue);

            // Axis went from pressed->pressed but changed direction.
            if (Math.Sign(currentValue) != Math.Sign(previousValue))
            {
                timeLastPressAxis[axisIndex] = lastUpdateTime;
                repeatingAxis[axisIndex]     = false;

                OnAxisReleased(axis, 0f);
                OnAxisPressed(axis, currentValue, false);
                return;
            }

            // Axis went from pressed->released or released->pressed.
            if (axisWasDown != axisIsDown)
            {
                if (axisIsDown)
                {
                    timeLastPressAxis[axisIndex] = lastUpdateTime;
                    repeatingAxis[axisIndex]     = false;

                    OnAxisPressed(axis, currentValue, false);
                }
                else
                {
                    OnAxisReleased(axis, currentValue);
                }
                return;
            }
        }
Exemple #7
0
        /// <summary>
        /// Gets the <see cref="GamePadButton"/> value that corresponds to the specified axis and value.
        /// </summary>
        private GamePadButton ButtonFromAxis(GamePadAxis axis, Single value)
        {
            switch (axis)
            {
            case GamePadAxis.LeftJoystickX:
                return(Math.Sign(value) < 0 ? GamePadButton.LeftStickLeft : GamePadButton.LeftStickRight);

            case GamePadAxis.LeftJoystickY:
                return(Math.Sign(value) < 0 ? GamePadButton.LeftStickUp : GamePadButton.LeftStickDown);

            case GamePadAxis.RightJoystickX:
                return(Math.Sign(value) < 0 ? GamePadButton.RightStickLeft : GamePadButton.RightStickRight);

            case GamePadAxis.RightJoystickY:
                return(Math.Sign(value) < 0 ? GamePadButton.RightStickUp : GamePadButton.RightStickDown);

            case GamePadAxis.LeftTrigger:
                return(GamePadButton.LeftTrigger);

            case GamePadAxis.RightTrigger:
                return(GamePadButton.RightTrigger);
            }

            return(GamePadButton.None);
        }
Exemple #8
0
        public float GetAxis(GamePadID controllerID, GamePadAxis axis)
        {
            int id = (int)controllerID;

            if (!m_gamePads[id].playerIndexSet)
            {
                return(0f);
            }

            switch (axis)
            {
            case GamePadAxis.LeftJoystickX:
                return(m_gamePads[id].state.ThumbSticks.Left.X);

            case GamePadAxis.LeftJoystickY:
                return(m_gamePads[id].state.ThumbSticks.Left.Y);

            case GamePadAxis.RightJoystickX:
                return(m_gamePads[id].state.ThumbSticks.Right.X);

            case GamePadAxis.RightJoystickY:
                return(m_gamePads[id].state.ThumbSticks.Right.Y);

            case GamePadAxis.LeftTrigger:
                return(m_gamePads[id].state.Triggers.Left);

            case GamePadAxis.RightTrigger:
                return(m_gamePads[id].state.Triggers.Left);

            default:
                return(0f);
            }
        }
Exemple #9
0
 public GamePadAxisInfo(GamePadController controller, GamePadAxis axis, Vector2f value, bool pressed, bool prevPressed)
 {
     this.controller  = controller;
     this.axis        = axis;
     this.value       = value;
     this.pressed     = pressed;
     this.prevPressed = prevPressed;
 }
Exemple #10
0
 /// <summary>
 /// Gets the gamepad axis value.
 /// </summary>
 /// <param name="axis">Gamepad axis to check</param>
 /// <returns>Axis value.</returns>
 public float GetAxis(GamePadAxis axis)
 {
     if (_version != Input.gamepadsVersion)
     {
         throw new AccessViolationException();
     }
     return(Internal_GetAxis(_index, axis));
 }
Exemple #11
0
        public void SetAxis(GamePadAxis axis, float value)
        {
            var axisEvent = InputEventPool <GamePadAxisEvent> .GetOrCreate(this);

            axisEvent.Axis  = axis;
            axisEvent.Value = value;
            pendingEvents.Add(axisEvent);
        }
Exemple #12
0
        private GamePadAxisEvent CreateAxisEvent(GamePadAxis axis, double newValue)
        {
            GamePadAxisEvent axisEvent = InputEventPool <GamePadAxisEvent> .GetOrCreate(this);

            axisEvent.Value = (float)newValue;
            axisEvent.Axis  = axis;
            state.Update(axisEvent);
            return(axisEvent);
        }
Exemple #13
0
        public void AddBinding(GamePadAxis bindX, GamePadAxis bindY)
        {
            var x = new GamepadAxisControl(bindX, this);
            var y = new GamepadAxisControl(bindY, this);

            axisControls.Add(new AxisControlPair {
                X = x, Y = y
            });
        }
Exemple #14
0
        public override Vector2f GetGamePadAxis(GamePadAxis axis, GamePadController controller, bool rawValue)
        {
            if (controller == GamePadController.None || axis == GamePadAxis.None)
            {
                return(Vector2f.zero);
            }

            string xAxisName       = "";
            string yAxisName       = "";
            int    controllerIndex = (int)controller;

            if (controller == GamePadController.Any)
            {
                controllerIndex = 0;
            }

            switch (axis)
            {
            case GamePadAxis.Dir_Pad:
                xAxisName = "DPad_XAxis_" + controllerIndex;
                yAxisName = "DPad_YAxis_" + controllerIndex;
                break;

            case GamePadAxis.L_Stick:
                xAxisName = "L_XAxis_" + controllerIndex;
                yAxisName = "L_YAxis_" + controllerIndex;
                break;

            case GamePadAxis.R_Stick:
                xAxisName = "R_XAxis_" + controllerIndex;
                yAxisName = "R_YAxis_" + controllerIndex;
                break;
            }

            Vector2f axisValue = Vector2f.zero;

            try
            {
                if (!rawValue)
                {
                    axisValue.x = UnityEngine.Input.GetAxis(xAxisName);
                    axisValue.y = -UnityEngine.Input.GetAxis(yAxisName);
                }
                else
                {
                    axisValue.x = UnityEngine.Input.GetAxisRaw(xAxisName);
                    axisValue.y = -UnityEngine.Input.GetAxisRaw(yAxisName);
                }
            }
            catch (System.Exception e)
            {
                Core.debug.Error(e.Message);
            }

            return(axisValue);
        }
Exemple #15
0
 /// <summary>
 /// Adds a mapping from a button index to <see cref="GamePadAxis"/>
 /// </summary>
 /// <param name="index">The button index of the button on this device</param>
 /// <param name="axis">The axi to map to</param>
 /// <param name="invert">Should axis be inverted, output -1 instead of 1 on press</param>
 protected void AddButtonToAxis(int index, GamePadAxis axis, bool invert = false)
 {
     while (buttonsToTriggerMap.Count <= index)
     {
         buttonsToTriggerMap.Add(new MappedAxis {
             Axis = GamePadAxis.None
         });
     }
     buttonsToTriggerMap[index] = new MappedAxis {
         Axis = axis, Invert = invert, Remap = false
     };
 }
Exemple #16
0
 /// <summary>
 /// Adds a mapping from an axis index to <see cref="GamePadAxis"/>
 /// </summary>
 /// <param name="index">The axis index of the axis on this device</param>
 /// <param name="axis">The axis to map to</param>
 /// <param name="invert">Should axis be inverted</param>
 /// <param name="remap">Remap this axis from (-1,1) to (0,1)</param>
 protected void AddAxisToAxis(int index, GamePadAxis axis, bool invert = false, bool remap = false)
 {
     while (axisMap.Count <= index)
     {
         axisMap.Add(new MappedAxis {
             Axis = GamePadAxis.None
         });
     }
     axisMap[index] = new MappedAxis {
         Axis = axis, Invert = invert, Remap = remap
     };
 }
Exemple #17
0
        /// <inheritdoc/>
        protected override void OnGamePadAxisDown(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, ref RoutedEventData data)
        {
            if (IsDropDownOpen)
            {
                OnGamePadAxisDown_DropDownOpen(device, axis, value, repeat, ref data);
            }
            else
            {
                OnGamePadAxisDown_DropDownClosed(device, axis, value, repeat, ref data);
            }

            base.OnGamePadAxisDown(device, axis, value, repeat, ref data);
        }
        /// <summary>
        /// Raises <see cref="GamePadDevice.AxisPressed"/> and <see cref="GamePadDevice.AxisReleased"/> in response
        /// to changes in a particular axis.
        /// </summary>
        /// <param name="axis">The axis to evaluate.</param>
        /// <param name="previousValue">The last known value of the axis.</param>
        /// <param name="currentValue">The current value of the axis.</param>
        private void CheckForAxisPresses(GamePadAxis axis, Single previousValue, Single currentValue)
        {
            var axisIndex = (int)axis;

            var axisWasDown = IsAxisDown(previousValue);
            var axisIsDown  = IsAxisDown(currentValue);

            // Update button states.
            var btnPrev    = ButtonFromAxis(axis, previousValue);
            var btnCurrent = ButtonFromAxis(axis, currentValue);

            if (btnPrev != GamePadButton.None && (btnPrev != btnCurrent || !axisIsDown))
            {
                PutButtonInUpState(btnPrev);
            }

            if (btnCurrent != GamePadButton.None && axisIsDown)
            {
                PutButtonInDownState(btnCurrent);
            }

            // Axis went from pressed->pressed but changed direction.
            if (axisIsDown && axisWasDown && Math.Sign(currentValue) != Math.Sign(previousValue))
            {
                timeLastPressAxis[axisIndex] = lastUpdateTime;
                repeatingAxis[axisIndex]     = false;

                OnAxisReleased(axis, 0f);
                OnAxisPressed(axis, currentValue, false);

                return;
            }

            // Axis went from pressed->released or released->pressed.
            if (axisWasDown != axisIsDown)
            {
                if (axisIsDown)
                {
                    timeLastPressAxis[axisIndex] = lastUpdateTime;
                    repeatingAxis[axisIndex]     = false;

                    OnAxisPressed(axis, currentValue, false);
                }
                else
                {
                    OnAxisReleased(axis, currentValue);
                }
            }
        }
Exemple #19
0
        public void AddGamePadAxis(Identifier action, GamePadAxis axis, GamePadController controller = GamePadController.Any, PlayerId player = PlayerId.Player1)
        {
            var actionId        = new InputActionId(action, player);
            var gamePadAxisInfo = new GamePadAxisInfo(controller, axis, Vector2f.zero, false, false);

            if (gamePadAxisBindings.ContainsKey(actionId))
            {
                gamePadAxisBindings[actionId].Add(gamePadAxisInfo);
            }
            else
            {
                var newList = new List <GamePadAxisInfo>()
                {
                    gamePadAxisInfo
                };
                gamePadAxisBindings.Add(actionId, newList);
            }
        }
Exemple #20
0
        /// <inheritdoc/>
        protected override void OnGamePadAxisDown(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, ref RoutedEventData data)
        {
            if (GamePad.UseAxisForDirectionalNavigation)
            {
                var direction = device.GetJoystickDirectionFromAxis(axis);
                switch (direction)
                {
                case GamePadJoystickDirection.Left:
                    DecreaseSmall();
                    data.Handled = true;
                    break;

                case GamePadJoystickDirection.Right:
                    IncreaseSmall();
                    data.Handled = true;
                    break;
                }
            }
            base.OnGamePadAxisDown(device, axis, value, repeat, ref data);
        }
Exemple #21
0
        /// <inheritdoc/>
        protected override void OnGamePadAxisDown(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.UseAxisForDirectionalNavigation)
            {
                var direction = device.GetJoystickDirectionFromAxis(axis);
                switch (direction)
                {
                    case GamePadJoystickDirection.Up:
                        DecreaseSmall();
                        data.Handled = true;
                        break;

                    case GamePadJoystickDirection.Down:
                        IncreaseSmall();
                        data.Handled = true;
                        break;
                }
            }
            base.OnGamePadAxisDown(device, axis, value, repeat, data);
        }
Exemple #22
0
        /// <inheritdoc/>
        protected override void OnGamePadAxisDown(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, ref RoutedEventData data)
        {
            if (GamePad.UseAxisForDirectionalNavigation && (axis == GamePad.DirectionalNavigationAxisX || axis == GamePad.DirectionalNavigationAxisY))
            {
                var direction = device.GetJoystickDirectionFromAxis(axis);
                switch (direction)
                {
                case GamePadJoystickDirection.Left:
                    if (PART_ScrollViewer != null)
                    {
                        PART_ScrollViewer.HandleKeyScrolling(Key.Left, ModifierKeys.None, ref data);
                    }
                    break;

                case GamePadJoystickDirection.Right:
                    if (PART_ScrollViewer != null)
                    {
                        PART_ScrollViewer.HandleKeyScrolling(Key.Right, ModifierKeys.None, ref data);
                    }
                    break;

                case GamePadJoystickDirection.Up:
                    if (SelectionMode == SelectionMode.Single)
                    {
                        MoveSelectedItem(FocusNavigationDirection.Up);
                    }
                    break;

                case GamePadJoystickDirection.Down:
                    if (SelectionMode == SelectionMode.Single)
                    {
                        MoveSelectedItem(FocusNavigationDirection.Down);
                    }
                    break;
                }
                data.Handled = true;
            }

            base.OnGamePadAxisDown(device, axis, value, repeat, ref data);
        }
Exemple #23
0
        /// <summary>
        /// Handles <see cref="GamePad.AxisDownEvent"/> when the drop down is closed.
        /// </summary>
        private void OnGamePadAxisDown_DropDownClosed(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, ref RoutedEventData data)
        {
            if (GamePad.UseAxisForDirectionalNavigation)
            {
                if (GamePad.DirectionalNavigationAxisX == axis || GamePad.DirectionalNavigationAxisY == axis)
                {
                    var direction = device.GetJoystickDirectionFromAxis(axis);
                    switch (direction)
                    {
                    case GamePadJoystickDirection.Up:
                    case GamePadJoystickDirection.Left:
                        MoveItemSelection(-1);
                        break;

                    case GamePadJoystickDirection.Down:
                    case GamePadJoystickDirection.Right:
                        MoveItemSelection(1);
                        break;
                    }
                    data.Handled = true;
                }
            }
        }
Exemple #24
0
        /// <summary>
        /// Handles <see cref="GamePad.AxisDownEvent"/> when the drop down is open.
        /// </summary>
        private void OnGamePadAxisDown_DropDownOpen(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.UseAxisForDirectionalNavigation)
            {
                if (GamePad.DirectionalNavigationAxisX == axis || GamePad.DirectionalNavigationAxisY == axis)
                {
                    var direction = device.GetJoystickDirectionFromAxis(axis);
                    switch (direction)
                    {
                        case GamePadJoystickDirection.Up:
                            MoveItemFocus(-1);
                            break;

                        case GamePadJoystickDirection.Down:
                            MoveItemFocus(1);
                            break;

                        case GamePadJoystickDirection.Left:
                            if (PART_ScrollViewer != null)
                            {
                                PART_ScrollViewer.HandleKeyScrolling(Key.Left, ModifierKeys.None, data);
                            }
                            break;
                            
                        case GamePadJoystickDirection.Right:
                            if (PART_ScrollViewer != null)
                            {
                                PART_ScrollViewer.HandleKeyScrolling(Key.Right, ModifierKeys.None, data);
                            }
                            break;
                    }
                    data.Handled = true;
                }
            }
        }
 /// <summary>
 /// Gets a value indicating whether the specified game pad axis is currently considered "down"
 /// in accordance with the <see cref="AxisDownThreshold"/> property.
 /// </summary>
 /// <param name="axis">The <see cref="GamePadAxis"/> to evaluate.</param>
 /// <returns><see langword="true"/> if the axis is down; otherwise, <see langword="false"/>.</returns>
 public abstract Boolean IsAxisDown(GamePadAxis axis);
 /// <summary>
 /// Gets the value of the specified game pad axis.
 /// </summary>
 /// <param name="axis">The <see cref="GamePadAxis"/> value to retrieve.</param>
 /// <returns>The value of the specified game pad axis.</returns>
 public abstract Single GetAxisValue(GamePadAxis axis);
 /// <summary>
 /// Gets the <see cref="GamePadJoystickDirection"/> value that corresponds to the state of the specified axis.
 /// </summary>
 /// <param name="axis">A <see cref="GamePadAxis"/> value to evaluate.</param>
 /// <param name="threshold">The threshold value at which an axis is considered to be pointed in a particular direction.</param>
 /// <returns>A set of <see cref="GamePadJoystickDirection"/> values which represent the specified axis' direction.</returns>
 public abstract GamePadJoystickDirection GetJoystickDirectionFromAxis(GamePadAxis axis, Single?threshold = null);
 /// <summary>
 /// Raises the <see cref="AxisReleased"/> event.
 /// </summary>
 /// <param name="axis">The <see cref="GamePadAxis"/> that was released.</param>
 /// <param name="value">The axis' value.</param>
 protected virtual void OnAxisReleased(GamePadAxis axis, Single value) =>
 AxisReleased?.Invoke(this, axis, value);
        /// <summary>
        /// Invokes by the <see cref="GamePad.AxisUpEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The game pad device.</param>
        /// <param name="axis">The axis that was released.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnGamePadAxisUp(GamePadDevice device, GamePadAxis axis, RoutedEventData data)
        {

        }
Exemple #30
0
 /// <summary>
 /// Raises the AxisUp attached event for the specified element.
 /// </summary>
 internal static void RaiseAxisUp(DependencyObject element, GamePadDevice device, GamePadAxis axis, ref RoutedEventData data)
 {
     var temp = EventManager.GetInvocationDelegate<UpfGamePadAxisUpEventHandler>(AxisUpEvent);
     if (temp != null)
     {
         temp(element, device, axis, ref data);
     }
 }
        /// <summary>
        /// Invokes by the <see cref="GamePad.AxisChangedEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The game pad device.</param>
        /// <param name="axis">The axis that was changed.</param>
        /// <param name="value">The value to which the axis was changed.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnGamePadAxisChanged(GamePadDevice device, GamePadAxis axis, Single value, RoutedEventData data)
        {

        }
 /// <summary>
 /// Invokes the <see cref="OnGamePadAxisDown"/> method.
 /// </summary>
 private static void OnGamePadAxisDownProxy(DependencyObject element, GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, RoutedEventData data)
 {
     ((UIElement)element).OnGamePadAxisDown(device, axis, value, repeat, data);
 }
        /// <summary>
        /// Attempts to perform navigation as a result of the specified game pad axis press.
        /// </summary>
        /// <param name="view">The view for which to perform navigation.</param>
        /// <param name="device">The game pad device that raised the button press event.</param>
        /// <param name="axis">The axis that was pressed.</param>
        /// <returns><c>true</c> if navigation was performed; otherwise, <c>false</c>.</returns>
        public static Boolean PerformNavigation(PresentationFoundationView view, GamePadDevice device, GamePadAxis axis)
        {
            Contract.Require(view, "view");

            if (GamePad.UseAxisForDirectionalNavigation)
            {
                var element = (view.ElementWithFocus ?? view.LayoutRoot) as UIElement;
                if (element == null)
                    return false;

                if (GamePad.DirectionalNavigationAxisX == axis || GamePad.DirectionalNavigationAxisY == axis)
                {
                    var direction = device.GetJoystickDirectionFromAxis(axis);
                    var succeeded = false;

                    if ((direction & GamePadJoystickDirection.Up) == GamePadJoystickDirection.Up)
                        succeeded = succeeded || PerformNavigation(view, element, FocusNavigationDirection.Up, false);

                    if ((direction & GamePadJoystickDirection.Down) == GamePadJoystickDirection.Down)
                        succeeded = succeeded || PerformNavigation(view, element, FocusNavigationDirection.Down, false);

                    if ((direction & GamePadJoystickDirection.Left) == GamePadJoystickDirection.Left)
                        succeeded = succeeded || PerformNavigation(view, element, FocusNavigationDirection.Left, false);

                    if ((direction & GamePadJoystickDirection.Right) == GamePadJoystickDirection.Right)
                        succeeded = succeeded || PerformNavigation(view, element, FocusNavigationDirection.Right, false);
                }
            }
            return false;
        }
Exemple #34
0
        /// <summary>
        /// Handles <see cref="GamePad.AxisDownEvent"/> when the drop down is closed.
        /// </summary>
        private void OnGamePadAxisDown_DropDownClosed(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.UseAxisForDirectionalNavigation)
            {
                if (GamePad.DirectionalNavigationAxisX == axis || GamePad.DirectionalNavigationAxisY == axis)
                {
                    var direction = device.GetJoystickDirectionFromAxis(axis);
                    switch (direction)
                    {
                        case GamePadJoystickDirection.Up:
                        case GamePadJoystickDirection.Left:
                            MoveItemSelection(-1);
                            break;

                        case GamePadJoystickDirection.Down:
                        case GamePadJoystickDirection.Right:
                            MoveItemSelection(1);
                            break;
                    }
                    data.Handled = true;
                }
            }
        }
Exemple #35
0
 /// <summary>
 /// Raises the <see cref="E:TwistedLogik.Ultraviolet.UI.Presentation.Input.GamePad.AxisDown"/> attached event for the specified element.
 /// </summary>
 internal static void RaiseAxisDown(DependencyObject element, GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, RoutedEventData data)
 {
     var evt = EventManager.GetInvocationDelegate<UpfGamePadAxisDownEventHandler>(AxisDownEvent);
     evt?.Invoke(element, device, axis, value, repeat, data);
 }
Exemple #36
0
        /// <inheritdoc/>
        protected override void OnGamePadAxisDown(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, RoutedEventData data)
        {
            if (IsDropDownOpen)
            {
                OnGamePadAxisDown_DropDownOpen(device, axis, value, repeat, data);
            }
            else
            {
                OnGamePadAxisDown_DropDownClosed(device, axis, value, repeat, data);
            }

            base.OnGamePadAxisDown(device, axis, value, repeat, data);
        }
 /// <summary>
 /// Gets a value indicating whether the specified game pad axis is currently considered "released"
 /// in accordance with the <see cref="AxisDownThreshold"/> property.
 /// </summary>
 /// <param name="axis">The <see cref="GamePadAxis"/> to evaluate.</param>
 /// <returns><see langword="true"/> if the axis is released; otherwise, <see langword="false"/>.</returns>
 public abstract Boolean IsAxisReleased(GamePadAxis axis);
Exemple #38
0
 /// <summary>
 /// Raises the PreviewAxisDown attached event for the specified element.
 /// </summary>
 internal static void RaisePreviewAxisDown(DependencyObject element, GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, ref RoutedEventData data)
 {
     var temp = EventManager.GetInvocationDelegate<UpfGamePadAxisDownEventHandler>(PreviewAxisDownEvent);
     if (temp != null)
     {
         temp(element, device, axis, value, repeat, ref data);
     }
 }
 /// <summary>
 /// Raises the <see cref="AxisPressed"/> event.
 /// </summary>
 /// <param name="axis">The <see cref="GamePadAxis"/> that was pressed.</param>
 /// <param name="value">The axis' value.</param>
 /// <param name="repeat">A value indicating whether this is a repeated axis press.</param>
 protected virtual void OnAxisPressed(GamePadAxis axis, Single value, Boolean repeat) =>
 AxisPressed?.Invoke(this, axis, value, repeat);
 /// <summary>
 /// Invokes the <see cref="OnGamePadAxisChanged"/> method.
 /// </summary>
 private static void OnGamePadAxisChangedProxy(DependencyObject element, GamePadDevice device, GamePadAxis axis, Single value, RoutedEventData data)
 {
     ((UIElement)element).OnGamePadAxisChanged(device, axis, value, data);
 }
Exemple #41
0
 /// <summary>
 /// Raises the <see cref="E:TwistedLogik.Ultraviolet.UI.Presentation.Input.GamePad.PreviewAxisUp"/> attached event for the specified element.
 /// </summary>
 internal static void RaisePreviewAxisUp(DependencyObject element, GamePadDevice device, GamePadAxis axis, RoutedEventData data)
 {
     var evt = EventManager.GetInvocationDelegate<UpfGamePadAxisUpEventHandler>(PreviewAxisUpEvent);
     evt?.Invoke(element, device, axis, data);
 }
 /// <summary>
 /// Invokes the <see cref="OnGamePadAxisUp"/> method.
 /// </summary>
 private static void OnGamePadAxisUpProxy(DependencyObject element, GamePadDevice device, GamePadAxis axis, RoutedEventData data)
 {
     ((UIElement)element).OnGamePadAxisUp(device, axis, data);
 }
 /// <summary>
 /// Gets a value indicating whether the specified game pad axis is currently considered "pressed"
 /// in accordance with the <see cref="AxisDownThreshold"/> property.
 /// </summary>
 /// <param name="axis">The <see cref="GamePadAxis"/> to evaluate.</param>
 /// <returns><see langword="true"/> if the axis is pressed; otherwise, <see langword="false"/>.</returns>
 public abstract Boolean IsAxisPressed(GamePadAxis axis);
        /// <summary>
        /// Invokes by the <see cref="GamePad.AxisDownEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The game pad device.</param>
        /// <param name="axis">The axis that was pressed.</param>
        /// <param name="value">The axis' value when it was pressed.</param>
        /// <param name="repeat">A value indicating whether this is a repeated axis press.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnGamePadAxisDown(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, RoutedEventData data)
        {

        }
        /// <inheritdoc/>
        protected override void OnGamePadAxisDown(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, ref RoutedEventData data)
        {
            var templatedParent = TemplatedParent as Control;
            if (templatedParent == null || !templatedParent.HandlesScrolling)
            {
                if (GamePad.UseAxisForDirectionalNavigation)
                {
                    var direction = device.GetJoystickDirectionFromAxis(axis);
                    switch (direction)
                    {
                        case GamePadJoystickDirection.Up:
                            HandleKeyScrolling(Key.Up, ModifierKeys.None, ref data);
                            break;

                        case GamePadJoystickDirection.Down:
                            HandleKeyScrolling(Key.Down, ModifierKeys.None, ref data);
                            break;

                        case GamePadJoystickDirection.Left:
                            HandleKeyScrolling(Key.Left, ModifierKeys.None, ref data);
                            break;

                        case GamePadJoystickDirection.Right:
                            HandleKeyScrolling(Key.Right, ModifierKeys.None, ref data);
                            break;
                    }
                    data.Handled = true;
                }
            }
            
            base.OnGamePadAxisDown(device, axis, value, repeat, ref data);
        }
Exemple #46
0
 public GamepadAxisControl(GamePadAxis axis, PlayerAction owner) : base(axis.ToString(), owner)
 {
     this.axis = axis;
     DeadZone  = 0.2f;
 }
Exemple #47
0
        /// <inheritdoc/>
        protected override void OnGamePadAxisDown(GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.UseAxisForDirectionalNavigation && (axis == GamePad.DirectionalNavigationAxisX || axis == GamePad.DirectionalNavigationAxisY))
            {
                var direction = device.GetJoystickDirectionFromAxis(axis);
                switch (direction)
                {
                    case GamePadJoystickDirection.Left:
                        if (PART_ScrollViewer != null)
                        {
                            PART_ScrollViewer.HandleKeyScrolling(Key.Left, ModifierKeys.None, data);
                        }
                        break;

                    case GamePadJoystickDirection.Right:
                        if (PART_ScrollViewer != null)
                        {
                            PART_ScrollViewer.HandleKeyScrolling(Key.Right, ModifierKeys.None, data);
                        }
                        break;

                    case GamePadJoystickDirection.Up:
                        if (SelectionMode == SelectionMode.Single)
                        {
                            MoveSelectedItem(FocusNavigationDirection.Up);
                        }
                        break;

                    case GamePadJoystickDirection.Down:
                        if (SelectionMode == SelectionMode.Single)
                        {
                            MoveSelectedItem(FocusNavigationDirection.Down);
                        }
                        break;
                }
                data.Handled = true;
            }

            base.OnGamePadAxisDown(device, axis, value, repeat, data);
        }