示例#1
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;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Attempts to perform navigation as a result of the specified game pad button 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="button">The button 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, GamePadButton button)
        {
            Contract.Require(view, "view");

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

            if (GamePad.TabButton == button)
                return PerformNavigation(view, element, FocusNavigationDirection.Next, false);

            if (GamePad.ShiftTabButton == button)
                return PerformNavigation(view, element, FocusNavigationDirection.Previous, false);

            if (!GamePad.UseAxisForDirectionalNavigation)
            {
                switch (button)
                {
                    case GamePadButton.DPadUp:
                        return PerformNavigation(view, element, FocusNavigationDirection.Up, false);

                    case GamePadButton.DPadDown:
                        return PerformNavigation(view, element, FocusNavigationDirection.Down, false);

                    case GamePadButton.DPadLeft:
                        return PerformNavigation(view, element, FocusNavigationDirection.Left, false);

                    case GamePadButton.DPadRight:
                        return PerformNavigation(view, element, FocusNavigationDirection.Right, false);
                }
            }

            return false;
        }
示例#3
0
        /// <summary>
        /// Handles <see cref="GamePad.ButtonDownEvent"/> when the drop down is closed.
        /// </summary>
        private void OnGamePadButtonDown_DropDownClosed(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                IsDropDownOpen = true;
                data.Handled   = true;
            }
            else
            {
                switch (button)
                {
                case GamePadButton.LeftStickUp:
                case GamePadButton.LeftStickLeft:
                    MoveItemSelection(-1);
                    data.Handled = true;
                    break;

                case GamePadButton.LeftStickDown:
                case GamePadButton.LeftStickRight:
                    MoveItemSelection(1);
                    data.Handled = true;
                    break;
                }
            }
        }
示例#4
0
        /// <summary>
        /// Handles <see cref="GamePad.ButtonDownEvent"/> when the drop down is closed.
        /// </summary>
        private void OnGamePadButtonDown_DropDownClosed(GamePadDevice device, GamePadButton button, Boolean repeat, ref RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                IsDropDownOpen = true;
                data.Handled   = true;
            }
            else
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                    case GamePadButton.DPadUp:
                    case GamePadButton.DPadLeft:
                        MoveItemSelection(-1);
                        break;

                    case GamePadButton.DPadDown:
                    case GamePadButton.DPadRight:
                        MoveItemSelection(1);
                        break;
                    }
                    data.Handled = true;
                }
            }
        }
 /// <inheritdoc/>
 public override Boolean MatchesGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
 {
     if (PlayerIndex == AnyPlayerIndex || PlayerIndex == device.PlayerIndex)
     {
         return(Button == button);
     }
     return(base.MatchesGamePadButtonDown(device, button, repeat, data));
 }
示例#6
0
        /// <summary>
        /// Raises the <see cref="GamePadDisconnected"/> event.
        /// </summary>
        /// <param name="device">The device that was disconnected.</param>
        /// <param name="playerIndex">The player index associated with the game pad.</param>
        private void OnGamePadDisconnected(GamePadDevice device, Int32 playerIndex)
        {
            if (primaryGamePad == device)
            {
                primaryGamePad = null;
            }

            GamePadDisconnected?.Invoke(device, playerIndex);
        }
示例#7
0
 /// <inheritdoc/>
 protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
 {
     if (GamePad.ConfirmButton == button && !repeat)
     {
         HandlePressed();
         data.Handled = true;
     }
     base.OnGamePadButtonDown(device, button, repeat, data);
 }
示例#8
0
 /// <inheritdoc/>
 protected override void OnGamePadButtonUp(GamePadDevice device, GamePadButton button, RoutedEventData data)
 {
     if (GamePad.ConfirmButton == button)
     {
         HandleReleased(false);
         data.Handled = true;
     }
     base.OnGamePadButtonUp(device, button, data);
 }
示例#9
0
        /// <summary>
        /// Handles <see cref="GamePad.ButtonDownEvent"/> when the drop down is open.
        /// </summary>
        private void OnGamePadButtonDown_DropDownOpen(GamePadDevice device, GamePadButton button, Boolean repeat, ref RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                SelectFocusedItem();
                IsDropDownOpen = false;
                data.Handled   = true;
            }
            else if (GamePad.CancelButton == button)
            {
                IsDropDownOpen = false;
                data.Handled   = true;
            }
            else if (GamePad.TabButton == button)
            {
                PerformTabNavigation(Key.Tab, ModifierKeys.None);
                data.Handled = true;
            }
            else if (GamePad.ShiftTabButton == button)
            {
                PerformTabNavigation(Key.Tab, ModifierKeys.Shift);
                data.Handled = true;
            }
            else
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                    case GamePadButton.DPadUp:
                        MoveItemSelection(-1);
                        break;

                    case GamePadButton.DPadDown:
                        MoveItemSelection(1);
                        break;

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

                    case GamePadButton.DPadRight:
                        if (PART_ScrollViewer != null)
                        {
                            PART_ScrollViewer.HandleKeyScrolling(Key.Right, ModifierKeys.None, ref data);
                        }
                        break;
                    }
                    data.Handled = true;
                }
            }
        }
示例#10
0
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, ref RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                var listBoxItem = ItemsControlUtil.FindContainer <ListBoxItem>(this, data.OriginalSource);
                if (listBoxItem != null)
                {
                    HandleItemClicked(listBoxItem);
                    data.Handled = true;
                }
            }
            else
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                    case GamePadButton.DPadLeft:
                        if (PART_ScrollViewer != null)
                        {
                            PART_ScrollViewer.HandleKeyScrolling(Key.Left, ModifierKeys.None, ref data);
                        }
                        data.Handled = true;
                        break;

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

                    case GamePadButton.DPadUp:
                        if (SelectionMode == SelectionMode.Single)
                        {
                            MoveSelectedItem(FocusNavigationDirection.Up);
                        }
                        data.Handled = true;
                        break;

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

            base.OnGamePadButtonDown(device, button, repeat, ref data);
        }
示例#11
0
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (IsDropDownOpen)
            {
                OnGamePadButtonDown_DropDownOpen(device, button, repeat, data);
            }
            else
            {
                OnGamePadButtonDown_DropDownClosed(device, button, repeat, data);
            }

            base.OnGamePadButtonDown(device, button, repeat, data);
        }
示例#12
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);
        }
示例#13
0
        /// <summary>
        /// Handles <see cref="GamePad.ButtonDownEvent"/> when the drop down is open.
        /// </summary>
        private void OnGamePadButtonDown_DropDownOpen(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                SelectFocusedItem();
                IsDropDownOpen = false;
                data.Handled   = true;
            }
            else if (GamePad.CancelButton == button)
            {
                IsDropDownOpen = false;
                data.Handled   = true;
            }
            else if (GamePad.TabButton == button)
            {
                PerformTabNavigation(Key.Tab, ModifierKeys.None);
                data.Handled = true;
            }
            else if (GamePad.ShiftTabButton == button)
            {
                PerformTabNavigation(Key.Tab, ModifierKeys.Shift);
                data.Handled = true;
            }
            else
            {
                switch (button)
                {
                case GamePadButton.LeftStickUp:
                    MoveItemFocus(-1);
                    data.Handled = true;
                    break;

                case GamePadButton.LeftStickDown:
                    MoveItemFocus(1);
                    data.Handled = true;
                    break;

                case GamePadButton.LeftStickLeft:
                    PART_ScrollViewer?.LineLeft();
                    data.Handled = true;
                    break;

                case GamePadButton.LeftStickRight:
                    PART_ScrollViewer?.LineRight();
                    data.Handled = true;
                    break;
                }
            }
        }
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            switch (button)
            {
            case GamePadButton.LeftStickUp:
                Value       += SmallChange;
                data.Handled = true;
                break;

            case GamePadButton.LeftStickDown:
                Value       -= SmallChange;
                data.Handled = true;
                break;
            }

            base.OnGamePadButtonDown(device, button, repeat, data);
        }
示例#15
0
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                var listBoxItem = ItemsControlUtil.FindContainer <ListBoxItem>(this, data.OriginalSource);
                if (listBoxItem != null)
                {
                    HandleItemClicked(listBoxItem);
                    data.Handled = true;
                }
            }
            else
            {
                switch (button)
                {
                case GamePadButton.LeftStickLeft:
                    PART_ScrollViewer?.LineLeft();
                    data.Handled = true;
                    break;

                case GamePadButton.LeftStickRight:
                    PART_ScrollViewer?.LineRight();
                    data.Handled = true;
                    break;

                case GamePadButton.LeftStickUp:
                    if (SelectionMode == SelectionMode.Single)
                    {
                        MoveSelectedItem(FocusNavigationDirection.Up);
                    }
                    data.Handled = true;
                    break;

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

            base.OnGamePadButtonDown(device, button, repeat, data);
        }
示例#16
0
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (!GamePad.UseAxisForDirectionalNavigation)
            {
                switch (button)
                {
                    case GamePadButton.DPadUp:
                        DecreaseSmall();
                        data.Handled = true;
                        break;

                    case GamePadButton.DPadDown:
                        IncreaseSmall();
                        data.Handled = true;
                        break;
                }
            }
            base.OnGamePadButtonDown(device, button, repeat, data);
        }
示例#17
0
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, ref RoutedEventData data)
        {
            if (!GamePad.UseAxisForDirectionalNavigation)
            {
                switch (button)
                {
                case GamePadButton.DPadLeft:
                    DecreaseSmall();
                    data.Handled = true;
                    break;

                case GamePadButton.DPadRight:
                    IncreaseSmall();
                    data.Handled = true;
                    break;
                }
            }
            base.OnGamePadButtonDown(device, button, repeat, ref data);
        }
示例#18
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);
        }
示例#19
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);
        }
示例#20
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);
        }
示例#21
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;
                }
            }
        }
示例#22
0
 /// <summary>
 /// When overriden in a derived class, determines whether the gesture matches the specified game pad button down input event.
 /// </summary>
 /// <param name="device">The game pad device.</param>
 /// <param name="button">The game pad button that was pressed.</param>
 /// <param name="repeat">A value indicating whether this is a repeated button press.</param>
 /// <param name="data">The routed event metadata for this event invocation.</param>
 /// <returns><see langword="true"/> if the gesture matches the event; otherwise, <see langword="false"/>.</returns>
 public virtual Boolean MatchesGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data) => false;
示例#23
0
 /// <inheritdoc/>
 public override Boolean MatchesGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data) =>
 IsValid(data.Source) ? WrappedGesture.MatchesGamePadButtonDown(device, button, repeat, data) : false;
示例#24
0
        /// <summary>
        /// Raises the <see cref="E:Ultraviolet.Presentation.Input.GamePad.ButtonUp"/> attached event for the specified element.
        /// </summary>
        internal static void RaiseButtonUp(DependencyObject element, GamePadDevice device, GamePadButton button, RoutedEventData data)
        {
            var evt = EventManager.GetInvocationDelegate <UpfGamePadButtonUpEventHandler>(ButtonUpEvent);

            evt?.Invoke(element, device, button, data);
        }
示例#25
0
        /// <summary>
        /// Raises the <see cref="E:Ultraviolet.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);
        }
示例#26
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;
                }
            }
        }
示例#27
0
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, ref RoutedEventData data)
        {
            var templatedParent = TemplatedParent as Control;
            if (templatedParent == null || !templatedParent.HandlesScrolling)
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                        case GamePadButton.DPadUp:
                            HandleKeyScrolling(Key.Up, ModifierKeys.None, ref data);
                            break;

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

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

                        case GamePadButton.DPadRight:
                            HandleKeyScrolling(Key.Right, ModifierKeys.None, ref data);
                            break;
                    }
                    data.Handled = true;
                }
            }

            base.OnGamePadButtonDown(device, button, repeat, ref data);
        }
示例#28
0
 /// <summary>
 /// Raises the <see cref="E:TwistedLogik.Ultraviolet.UI.Presentation.Input.GamePad.PreviewAxisDown"/> attached event for the specified element.
 /// </summary>
 internal static void RaisePreviewAxisDown(DependencyObject element, GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, RoutedEventData data)
 {
     var evt = EventManager.GetInvocationDelegate<UpfGamePadAxisDownEventHandler>(PreviewAxisDownEvent);
     evt?.Invoke(element, device, axis, value, repeat, data);
 }
示例#29
0
 /// <summary>
 /// Raises the AxisDown attached event for the specified element.
 /// </summary>
 internal static void RaiseAxisDown(DependencyObject element, GamePadDevice device, GamePadAxis axis, Single value, Boolean repeat, ref RoutedEventData data)
 {
     var temp = EventManager.GetInvocationDelegate<UpfGamePadAxisDownEventHandler>(AxisDownEvent);
     if (temp != null)
     {
         temp(element, device, axis, value, repeat, ref data);
     }
 }
 /// <summary>
 /// Raises the <see cref="GamePadDisconnected"/> event.
 /// </summary>
 /// <param name="device">The device that was disconnected.</param>
 /// <param name="playerIndex">The player index associated with the game pad.</param>
 private void OnGamePadDisconnected(GamePadDevice device, Int32 playerIndex) =>
 GamePadDisconnected?.Invoke(device, playerIndex);
 public GamepadHandler(int a_padID)
 {
     _bindings = InputManager.Instance.GamePadDefaults();
     PadId     = a_padID;
     device    = new GamePadDevice(_bindings, PadId);
 }
示例#32
0
        /// <summary>
        /// Handles <see cref="GamePad.ButtonDownEvent"/> when the drop down is closed.
        /// </summary>
        private void OnGamePadButtonDown_DropDownClosed(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                IsDropDownOpen = true;
                data.Handled = true;
            }
            else
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                        case GamePadButton.DPadUp:
                        case GamePadButton.DPadLeft:
                            MoveItemSelection(-1);
                            break;

                        case GamePadButton.DPadDown:
                        case GamePadButton.DPadRight:
                            MoveItemSelection(1);
                            break;
                    }
                    data.Handled = true;
                }
            }
        }
示例#33
0
        /// <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;
        }
示例#34
0
        // Init is called on startup.
        public override void Init()
        {
            _initCanvasWidth  = Width / 100f;
            _initCanvasHeight = Height / 100f;

            _canvasHeight = _initCanvasHeight;
            _canvasWidth  = _initCanvasWidth;

            // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle)
            _zoom = 400;

            _angleRoll        = 0;
            _angleRollInit    = 0;
            _twoTouchRepeated = false;
            _offset           = float2.Zero;
            _offsetInit       = float2.Zero;

            // Set the clear color for the back buffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 1, 1);

            // Load the standard model
            _scene = AssetStorage.Get <SceneContainer>(ModelFile);

            _gui = CreateGui();
            // Create the interaction handler
            _sih = new SceneInteractionHandler(_gui);

            // Register the input devices that are not already given.
            _gamePad = GetDevice <GamePadDevice>(0);

            AABBCalculator aabbc = new AABBCalculator(_scene);
            var            bbox  = aabbc.GetBox();

            if (bbox != null)
            {
                // If the model origin is more than one third away from its bounding box,
                // recenter it to the bounding box. Do this check individually per dimension.
                // This way, small deviations will keep the model's original center, while big deviations
                // will make the model rotate around its geometric center.
                float3 bbCenter = bbox.Value.Center;
                float3 bbSize   = bbox.Value.Size;
                float3 center   = float3.Zero;
                if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3)
                {
                    center.x = bbCenter.x;
                }
                if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3)
                {
                    center.y = bbCenter.y;
                }
                if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3)
                {
                    center.z = bbCenter.z;
                }
                _sceneCenter = float4x4.CreateTranslation(-center);

                // Adjust the model size
                float maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z));
                if (maxScale != 0)
                {
                    _sceneScale = float4x4.CreateScale(200.0f / maxScale);
                }
                else
                {
                    _sceneScale = float4x4.Identity;
                }
            }

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_scene);
            _guiRenderer   = new SceneRendererForward(_gui);
        }
示例#35
0
 /// <summary>
 /// Raises the <see cref="E:TwistedLogik.Ultraviolet.UI.Presentation.Input.GamePad.PreviewButtonUp"/> attached event for the specified element.
 /// </summary>
 internal static void RaisePreviewButtonUp(DependencyObject element, GamePadDevice device, GamePadButton button, RoutedEventData data)
 {
     var evt = EventManager.GetInvocationDelegate<UpfGamePadButtonUpEventHandler>(PreviewButtonUpEvent);
     evt?.Invoke(element, device, button, data);
 }
 /// <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);
 }
示例#37
0
 /// <summary>
 /// Raises the <see cref="E:TwistedLogik.Ultraviolet.UI.Presentation.Input.GamePad.ButtonDown"/> attached event for the specified element.
 /// </summary>
 internal static void RaiseButtonDown(DependencyObject element, GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
 {
     var evt = EventManager.GetInvocationDelegate<UpfGamePadButtonDownEventHandler>(ButtonDownEvent);
     evt?.Invoke(element, device, button, repeat, data);
 }
示例#38
0
        /// <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);
        }
示例#39
0
 /// <inheritdoc/>
 protected override void OnGamePadButtonUp(GamePadDevice device, GamePadButton button, RoutedEventData data)
 {
     if (GamePad.ConfirmButton == button)
     {
         HandleReleased(false);
         data.Handled = true;
     }
     base.OnGamePadButtonUp(device, button, data);
 }
 public GamepadHandler(int a_padID, GamePadBindings a_bindings)
 {
     _bindings = a_bindings;
     PadId     = a_padID;
     device    = new GamePadDevice(_bindings, PadId);
 }
示例#41
0
        /// <summary>
        /// Handles <see cref="GamePad.ButtonDownEvent"/> when the drop down is open.
        /// </summary>
        private void OnGamePadButtonDown_DropDownOpen(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                SelectFocusedItem();
                IsDropDownOpen = false;
                data.Handled = true;
            }
            else if (GamePad.CancelButton == button)
            {
                IsDropDownOpen = false;
                data.Handled = true;
            }
            else if (GamePad.TabButton == button)
            {
                PerformTabNavigation(Key.Tab, ModifierKeys.None);
                data.Handled = true;
            }
            else if (GamePad.ShiftTabButton == button)
            {
                PerformTabNavigation(Key.Tab, ModifierKeys.Shift);
                data.Handled = true;
            }
            else
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                        case GamePadButton.DPadUp:
                            MoveItemSelection(-1);
                            break;

                        case GamePadButton.DPadDown:
                            MoveItemSelection(1);
                            break;

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

                        case GamePadButton.DPadRight:
                            if (PART_ScrollViewer != null)
                            {
                                PART_ScrollViewer.HandleKeyScrolling(Key.Right, ModifierKeys.None, data);
                            }
                            break;
                    }
                    data.Handled = true;
                }
            }
        }
 /// <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);
 }
示例#43
0
 /// <inheritdoc/>
 protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
 {
     if (GamePad.ConfirmButton == button && !repeat)
     {
         HandlePressed();
         data.Handled = true;
     }
     base.OnGamePadButtonDown(device, button, repeat, data);
 }
 /// <summary>
 /// Invokes the <see cref="OnGamePadButtonUp"/> method.
 /// </summary>
 private static void OnGamePadButtonUpProxy(DependencyObject element, GamePadDevice device, GamePadButton button, RoutedEventData data)
 {
     ((UIElement)element).OnGamePadButtonUp(device, button, data);
 }
示例#45
0
 /// <summary>
 /// Raises the PreviewAxisUp attached event for the specified element.
 /// </summary>
 internal static void RaisePreviewAxisUp(DependencyObject element, GamePadDevice device, GamePadAxis axis, ref RoutedEventData data)
 {
     var temp = EventManager.GetInvocationDelegate<UpfGamePadAxisUpEventHandler>(PreviewAxisUpEvent);
     if (temp != null)
     {
         temp(element, device, axis, ref data);
     }
 }
        /// <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)
        {

        }
示例#47
0
 /// <summary>
 /// Raises the ButtonUp attached event for the specified element.
 /// </summary>
 internal static void RaiseButtonUp(DependencyObject element, GamePadDevice device, GamePadButton button, ref RoutedEventData data)
 {
     var temp = EventManager.GetInvocationDelegate<UpfGamePadButtonUpEventHandler>(ButtonUpEvent);
     if (temp != null)
     {
         temp(element, device, button, ref data);
     }
 }
        /// <summary>
        /// Invokes by the <see cref="GamePad.ButtonDownEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The game pad device.</param>
        /// <param name="button">The button that was pressed.</param>
        /// <param name="repeat">A value indicating whether this is a repeated button press.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, 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);
 }
示例#50
0
 /// <summary>
 /// Raises the <see cref="E:TwistedLogik.Ultraviolet.UI.Presentation.Input.GamePad.AxisUp"/> attached event for the specified element.
 /// </summary>
 internal static void RaiseAxisUp(DependencyObject element, GamePadDevice device, GamePadAxis axis, RoutedEventData data)
 {
     var evt = EventManager.GetInvocationDelegate<UpfGamePadAxisUpEventHandler>(AxisUpEvent);
     evt?.Invoke(element, device, axis, data);
 }
 /// <summary>
 /// Invokes the <see cref="OnGamePadButtonDown"/> method.
 /// </summary>
 private static void OnGamePadButtonDownProxy(DependencyObject element, GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
 {
     ((UIElement)element).OnGamePadButtonDown(device, button, repeat, data);
 }
示例#52
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);
        }
        /// <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)
        {

        }
示例#54
0
        /// <inheritdoc/>
        protected override void OnGamePadButtonDown(GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            if (GamePad.ConfirmButton == button)
            {
                var listBoxItem = ItemsControlUtil.FindContainer<ListBoxItem>(this, data.OriginalSource);
                if (listBoxItem != null)
                {
                    HandleItemClicked(listBoxItem);
                    data.Handled = true;
                }
            }
            else
            {
                if (!GamePad.UseAxisForDirectionalNavigation)
                {
                    switch (button)
                    {
                        case GamePadButton.DPadLeft:
                            if (PART_ScrollViewer != null)
                            {
                                PART_ScrollViewer.HandleKeyScrolling(Key.Left, ModifierKeys.None, data);
                            }
                            data.Handled = true;
                            break;

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

                        case GamePadButton.DPadUp:
                            if (SelectionMode == SelectionMode.Single)
                            {
                                MoveSelectedItem(FocusNavigationDirection.Up);
                            }
                            data.Handled = true;
                            break;

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

            base.OnGamePadButtonDown(device, button, repeat, data);
        }
        /// <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)
        {

        }
示例#56
0
        /// <summary>
        /// Raises the <see cref="E:Ultraviolet.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 by the <see cref="GamePad.ButtonUpEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The game pad device.</param>
        /// <param name="button">The button that was released.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnGamePadButtonUp(GamePadDevice device, GamePadButton button, RoutedEventData data)
        {

        }
示例#58
0
        /// <summary>
        /// Raises the <see cref="E:Ultraviolet.Presentation.Input.GamePad.PreviewAxisDown"/> attached event for the specified element.
        /// </summary>
        internal static void RaisePreviewButtonDown(DependencyObject element, GamePadDevice device, GamePadButton button, Boolean repeat, RoutedEventData data)
        {
            var evt = EventManager.GetInvocationDelegate <UpfGamePadButtonDownEventHandler>(PreviewButtonDownEvent);

            evt?.Invoke(element, device, button, repeat, data);
        }