Exemplo n.º 1
0
        private void EnterGamepadEngagementMode()
        {
            double currentValue = Value;

            m_shouldDiscardValue = true;

            if (currentValue == c_noValueSetSentinel)
            {
                Value = InitialSetValue;
                // Notify that the Value has changed
                ValueChanged?.Invoke(this, null);
                currentValue         = InitialSetValue;
                m_preEngagementValue = -1;
            }
            else
            {
                currentValue         = Value;
                m_preEngagementValue = currentValue;
            }

            if (SharedHelpers.IsRS1OrHigher())
            {
                ElementSoundPlayer.Play(ElementSoundKind.Invoke);
            }

            if (SharedHelpers.IsAnimationsEnabled())
            {
                double focalPoint = CalculateStarCenter((int)(currentValue - 1.0));
                m_sharedPointerPropertySet.InsertScalar("starsScaleFocalPoint", (float)(focalPoint));
            }
        }
Exemplo n.º 2
0
        private void ExitGamepadEngagementMode()
        {
            if (SharedHelpers.IsRS1OrHigher())
            {
                ElementSoundPlayer.Play(ElementSoundKind.GoBack);
            }

            m_sharedPointerPropertySet.InsertScalar("starsScaleFocalPoint", c_noPointerOverMagicNumber);
            m_disengagedWithA = false;
        }
Exemplo n.º 3
0
        private void SetRatingTo(double newRating, bool originatedFromMouse)
        {
            double ratingValue    = 0.0;
            double oldRatingValue = Value;

            ratingValue = Math.Min(newRating, (double)(MaxRating));
            ratingValue = Math.Max(ratingValue, 0.0);

            // The base case, and the you have no rating, and you pressed left case [wherein nothing should happen]
            if (oldRatingValue > c_noValueSetSentinel || ratingValue != 0.0)
            {
                if (!IsClearEnabled && ratingValue <= 0.0)
                {
                    Value = 1.0;
                }
                else if (ratingValue == oldRatingValue && IsClearEnabled && (ratingValue != MaxRating || originatedFromMouse))
                {
                    // If you increase the Rating via the keyboard/gamepad when it's maxed, the value should stay stable.
                    // But if you click a star that represents the current Rating value, it should clear the rating.

                    Value = c_noValueSetSentinel;
                }
                else if (ratingValue > 0.0)
                {
                    Value = ratingValue;
                }
                else
                {
                    Value = c_noValueSetSentinel;
                }

                if (SharedHelpers.IsRS1OrHigher() && IsFocusEngaged && SharedHelpers.IsAnimationsEnabled())
                {
                    double focalPoint = CalculateStarCenter((int)(ratingValue - 1.0));
                    m_sharedPointerPropertySet.InsertScalar("starsScaleFocalPoint", (float)(focalPoint));
                }

                // Notify that the Value has changed
                ValueChanged?.Invoke(this, null);
            }
        }
Exemplo n.º 4
0
        private void OnPointerReleasedBackgroundStackPanel(object sender, PointerRoutedEventArgs args)
        {
            if (!IsReadOnly)
            {
                var point     = args.GetCurrentPoint(m_backgroundStackPanel);
                var xPosition = point.Position.X;

                double mousePercentage = xPosition / CalculateActualRatingWidth();
                SetRatingTo(Math.Ceiling(mousePercentage * MaxRating), true);

                if (SharedHelpers.IsRS1OrHigher())
                {
                    ElementSoundPlayer.Play(ElementSoundKind.Invoke);
                }
            }

            if (m_isPointerDown)
            {
                m_isPointerDown = false;
                UpdateRatingItemsAppearance();
            }
        }
Exemplo n.º 5
0
        // IControlOverrides
        protected override void OnKeyDown(KeyRoutedEventArgs eventArgs)
        {
            if (eventArgs.Handled)
            {
                return;
            }

            if (!IsReadOnly)
            {
                bool       handled = false;
                VirtualKey key     = eventArgs.Key;

                double flowDirectionReverser = 1.0;

                if (FlowDirection == FlowDirection.RightToLeft)
                {
                    flowDirectionReverser *= -1.0;
                }

                var originalKey = eventArgs.OriginalKey;

                // Up down are right/left in keyboard only
                if (originalKey == VirtualKey.Up)
                {
                    key = VirtualKey.Right;
                    flowDirectionReverser = 1.0;
                }
                else if (originalKey == VirtualKey.Down)
                {
                    key = VirtualKey.Left;
                    flowDirectionReverser = 1.0;
                }

                if (originalKey == VirtualKey.GamepadDPadLeft || originalKey == VirtualKey.GamepadDPadRight ||
                    originalKey == VirtualKey.GamepadLeftThumbstickLeft || originalKey == VirtualKey.GamepadLeftThumbstickRight)
                {
                    if (SharedHelpers.IsRS1OrHigher())
                    {
                        ElementSoundPlayer.Play(ElementSoundKind.Focus);
                    }
                }

                switch (key)
                {
                case VirtualKey.Left:
                    ChangeRatingBy(-1.0 * flowDirectionReverser, false);
                    handled = true;
                    break;

                case VirtualKey.Right:
                    ChangeRatingBy(1.0 * flowDirectionReverser, false);
                    handled = true;
                    break;

                case VirtualKey.Home:
                    SetRatingTo(0.0, false);
                    handled = true;
                    break;

                case VirtualKey.End:
                    SetRatingTo((double)(MaxRating), false);
                    handled = true;
                    break;

                default:
                    break;
                }

                eventArgs.Handled = handled;
            }

            base.OnKeyDown(eventArgs);
        }
Exemplo n.º 6
0
        protected override void OnApplyTemplate()
        {
            RecycleEvents();

            // Retrieve pointers to stable controls
            //IControlProtected thisAsControlProtected = this;

            var captionTextBlock = (TextBlock)GetTemplateChild("Caption");

            if (captionTextBlock != null)
            {
                m_captionTextBlock            = captionTextBlock;
                captionTextBlock.SizeChanged += OnCaptionSizeChanged;
                UpdateCaptionMargins();
            }

            var backgroundStackPanel = (StackPanel)GetTemplateChild("RatingBackgroundStackPanel");

            if (backgroundStackPanel != null)
            {
                m_backgroundStackPanel = backgroundStackPanel;

                backgroundStackPanel.PointerCanceled    += OnPointerCancelledBackgroundStackPanel;
                backgroundStackPanel.PointerCaptureLost += OnPointerCaptureLostBackgroundStackPanel;
                backgroundStackPanel.PointerMoved       += OnPointerMovedOverBackgroundStackPanel;
                backgroundStackPanel.PointerEntered     += OnPointerEnteredBackgroundStackPanel;
                backgroundStackPanel.PointerExited      += OnPointerExitedBackgroundStackPanel;
                backgroundStackPanel.PointerPressed     += OnPointerPressedBackgroundStackPanel;
                backgroundStackPanel.PointerReleased    += OnPointerReleasedBackgroundStackPanel;
            }

            m_foregroundStackPanel = (StackPanel)GetTemplateChild("RatingForegroundStackPanel");

            if (SharedHelpers.IsRS1OrHigher())
            {
                // FUTURE: Ideally these would be in template overrides:

                // IsFocusEngagementEnabled means the control has to be "engaged" with
                // using the A button before it actually receives key input from gamepad.
                FocusEngaged            += OnFocusEngaged;
                FocusDisengaged         += OnFocusDisengaged;
                IsFocusEngagementEnabled = true;

                // I've picked values so that these LOOK like the redlines, but these
                // values are not actually from the redlines because the redlines don't
                // consistently pick "distance from glyph"/"distance from edge of textbox"
                // so it's not possible to actually just have a consistent sizing model
                // here based on the redlines.
                FocusVisualMargin = c_focusVisualMargin;
            }

            IsEnabledChanged        += OnIsEnabledChanged;
            m_fontFamilyChangedToken = RegisterPropertyChangedCallback(Control.FontFamilyProperty, OnFontFamilyChanged);

            Visual     visual = ElementCompositionPreview.GetElementVisual(this);
            Compositor comp   = visual.Compositor;

            m_sharedPointerPropertySet = comp.CreatePropertySet();

            m_sharedPointerPropertySet.InsertScalar("starsScaleFocalPoint", c_noPointerOverMagicNumber);
            m_sharedPointerPropertySet.InsertScalar("pointerScalar", c_mouseOverScale);

            StampOutRatingItems();
            GetUISettings().TextScaleFactorChanged += OnTextScaleFactorChanged;
        }