private void UpdateScrollbars()
        {
            this.fullLogs.Add("UpdateScrollbars");

            if (hScrollIndicatorSpriteVisual == null || hScrollIndicatorVisual == null || hScrollBarVisual == null ||
                vScrollIndicatorSpriteVisual == null || vScrollIndicatorVisual == null || vScrollBarVisual == null)
            {
                return;
            }

            Vector2 viewport;
            CompositionGetValueStatus cgvs = scrollPresenter.ExpressionAnimationSources.Properties.TryGetVector2("Viewport", out viewport);

            txtViewport.Text = cgvs.ToString() + ", " + viewport.ToString();

            Vector2 extent;

            cgvs           = scrollPresenter.ExpressionAnimationSources.Properties.TryGetVector2("Extent", out extent);
            txtExtent.Text = cgvs.ToString() + ", " + extent.ToString();

            txtBarVisualWidth.Text  = hScrollBarVisual.Size.X.ToString();
            txtIndicatorWidth.Text  = (viewport.X * hScrollBarVisual.Size.X / Math.Max(1.0f, extent.X)).ToString();
            txtBarVisualHeight.Text = vScrollBarVisual.Size.Y.ToString();
            txtIndicatorHeight.Text = (viewport.Y * vScrollBarVisual.Size.Y / Math.Max(1.0f, extent.Y)).ToString();
        }
Example #2
0
        /// <summary>
        /// Accesses the animated Vector2 value for the provided object and its property name.
        /// </summary>
        /// <param name="sourceObject"></param>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static CompositionGetValueStatus TryGetVector2(CompositionObject sourceObject, string propertyName, out Vector2 value)
        {
            value = Vector2.Zero;

            object objectValue = null;
            CompositionGetValueStatus status = TryGetPropertyValue(sourceObject, propertyName, CompositionPropertyType.Vector2, out objectValue);

            if (objectValue != null)
            {
                value = (Vector2)objectValue;
            }
            return(status);
        }
        private static string GetTranslationForElement(UIElement element)
        {
            CompositionGetValueStatus result = GetVisual(element).Properties.TryGetVector3("Translation", out Vector3 translation);

            return(result switch
            {
                // The ("G", CultureInfo.InvariantCulture) combination produces a string with the default numeric
                // formatting style, and using ',' as component separator, so that the resulting text can safely
                // be parsed back if needed with the StringExtensions.ToVector3(string) extension, which uses
                // the invariant culture mode by default so that the syntax will always match that from XAML.
                CompositionGetValueStatus.Succeeded => translation.ToString("G", CultureInfo.InvariantCulture),
                _ => "<0, 0, 0>"
            });
Example #4
0
        /// <summary>
        /// Accesses the animated scalar value for the provided object and its property name.
        /// </summary>
        /// <param name="sourceObject"></param>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static CompositionGetValueStatus TryGetScalar(CompositionObject sourceObject, string propertyName, out float value)
        {
            value = 0.0f;

            object objectValue = null;
            CompositionGetValueStatus status = TryGetPropertyValue(sourceObject, propertyName, CompositionPropertyType.Float, out objectValue);

            if (objectValue != null)
            {
                value = (float)objectValue;
            }
            return(status);
        }
Example #5
0
        /// <summary>
        /// Accesses the animated boolean value for the provided object and its property name.
        /// </summary>
        /// <param name="sourceObject"></param>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static CompositionGetValueStatus TryGetBoolean(CompositionObject sourceObject, string propertyName, out bool value)
        {
            value = false;

            object objectValue = null;
            CompositionGetValueStatus status = TryGetPropertyValue(sourceObject, propertyName, CompositionPropertyType.Boolean, out objectValue);

            if (objectValue != null)
            {
                value = (bool)objectValue;
            }
            return(status);
        }
Example #6
0
        /// <summary>
        /// Accesses the scale value through the xaml facade provided UIElement.
        /// </summary>
        /// <param name="sourceElement"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static CompositionGetValueStatus TryGetScaleFacade(UIElement sourceElement, out Vector3 value)
        {
            value = Vector3.Zero;

            object objectValue = null;
            CompositionGetValueStatus status = TryGetFacadeValue(sourceElement, CompositionFacadeType.Scale, out objectValue);

            if (objectValue != null)
            {
                value = (Vector3)objectValue;
            }
            return(status);
        }
        private void SpyAnimatedValues() // untestsed as well
        {
            if (this.AnimatedValuesSpy != null)
            {
                //StopAnimatedValuesSpy();

                Vector3 position;
                CompositionGetValueStatus status = this.AnimatedValuesSpy.TryGetVector3("Offset", out position);
                if (CompositionGetValueStatus.Succeeded == status)
                {
                    // add a position textblock in the file
                    this.PositionX.Text = position.X.ToString();
                    this.PositionY.Text = position.Y.ToString();
                }
                else
                {
                    this.PositionX.Text = this.PositionY.Text = "status=" + status.ToString();
                }

                StartAnimatedValuesSpy();
            }
        }
        private void SpyAnimatedValues()
        {
            if (this.AnimatedValuesSpy != null)
            {
                StopAnimatedValuesSpy();

                Vector3 scale;
                CompositionGetValueStatus status = this.AnimatedValuesSpy.TryGetVector3("Scale", out scale);
                if (CompositionGetValueStatus.Succeeded == status)
                {
                    this.ScaleTextX.Text = scale.X.ToString();
                    this.ScaleTextY.Text = scale.Y.ToString();
                }
                else
                {
                    this.ScaleTextX.Text = this.ScaleTextY.Text = "status=" + status.ToString();
                }

                StartAnimatedValuesSpy();

                // System.Diagnostics.Debug.WriteLine("Spied values: " + this.ScaleTextX.Text);
            }
        }
Example #9
0
        // In non fallback mode, we have crossfading and non crossfading effects.
        // crossfading only last for hundren ms in the transition between fallback mode and acrylic mode.
        //
        void RunVerifyAcrylicBrushEffect()
        {
            bool[] results = { false, false };

            AcrylicBrush acrylicBrush1 = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = Colors.Blue,
                TintColor        = Colors.Green,
                TintOpacity      = 0.1
            };

            // Add Ellipse with Acrylic Fill and Stroke
            Ellipse1.Visibility = Visibility.Visible;
            Ellipse1.Fill       = acrylicBrush1;

            _acrylicTestApi.AcrylicBrush = acrylicBrush1;

            // Force to create a AcrylicBrush which is used for animation. So it's a CrosssFading effect brush
            _acrylicTestApi.ForceCreateAcrylicBrush(true /*useCrossFadeEffect*/);

            var fallbackColor = Colors.Black;
            var tintColor     = Colors.Black;

            // Get FallbackColor and TintColor. Only CrossFading effect brush provides animation properties for both and TryGetColor success.
            CompositionGetValueStatus fallbackColorValueStatus = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("FallbackColor.Color", out fallbackColor);
            CompositionGetValueStatus tintColorValueStatus     = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("TintColor.Color", out tintColor);

            if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.NineteenH1))
            {
                // On 19H1+, Luminosity impacts the effective tint value, so don't validate it here.
                results[0] = tintColorValueStatus != CompositionGetValueStatus.NotFound &&
                             fallbackColorValueStatus != CompositionGetValueStatus.NotFound &&
                             fallbackColor == acrylicBrush1.FallbackColor;
            }
            else
            {
                var expectIintColor = acrylicBrush1.TintColor;
                expectIintColor.A = (byte)Math.Ceiling(255 * acrylicBrush1.TintOpacity); // alpha channel
                results[0]        = fallbackColor == acrylicBrush1.FallbackColor &&
                                    expectIintColor == tintColor;
            }

            // Force to create a non crosssFading effect brush
            _acrylicTestApi.ForceCreateAcrylicBrush(false /*useCrossFadeEffect*/);

            fallbackColor = Colors.Black;
            tintColor     = Colors.Black;

            // Get FallbackColor and TintColor. Non CrossFading effect brush doesn't provide FallbackColor.Color.
            fallbackColorValueStatus = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("FallbackColor.Color", out fallbackColor);
            tintColorValueStatus     = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("TintColor.Color", out tintColor);


            if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.NineteenH1))
            {
                // On 19H1+, Luminosity impacts the effective tint value, so don't validate it here.
                results[1] = fallbackColorValueStatus == CompositionGetValueStatus.NotFound;
            }
            else
            {
                var expectIintColor = acrylicBrush1.TintColor;
                expectIintColor.A = (byte)Math.Ceiling(255 * acrylicBrush1.TintOpacity); // alpha channel

                results[1] = fallbackColorValueStatus == CompositionGetValueStatus.NotFound &&
                             expectIintColor == tintColor;
            }

            bool   result       = results[0] && results[1];
            string resultString = System.String.Format("({0},{1})", results[0], results[1]);

            TestResult.Text = "VerifyAcrylicBrushEffect: " + (result ? "Passed" : ("Failed " + resultString));
        }
Example #10
0
        private static CompositionGetValueStatus TryGetValue <T>(
            T source,
            Dictionary <T, KeyValuePair <CompositionPropertySet, Dictionary <string, ExpressionAnimation> > > dictionary,
            string propertyName,
            CompositionPropertyType type,
            out object value)
        {
            value = null;

            if (source == null || string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentException();
            }

            CompositionPropertySet propertySet = null;
            Dictionary <string, ExpressionAnimation> expressionAnimations = null;
            ExpressionAnimation expressionAnimation = null;
            string propertySetPropertyName          = null;

            GetExpressionAnimation <T>(
                source,
                propertyName,
                dictionary,
                out propertySet,
                out expressionAnimations,
                out expressionAnimation,
                out propertySetPropertyName);

            if (propertySet != null)
            {
                propertySet.StopAnimation(propertySetPropertyName);

                CompositionGetValueStatus status = CompositionGetValueStatus.TypeMismatch;

                switch (type)
                {
                case CompositionPropertyType.Boolean:
                    bool boolValue;
                    status = propertySet.TryGetBoolean(propertySetPropertyName, out boolValue);
                    value  = boolValue;
                    break;

                case CompositionPropertyType.Float:
                    float floatValue;
                    status = propertySet.TryGetScalar(propertySetPropertyName, out floatValue);
                    value  = floatValue;
                    break;

                case CompositionPropertyType.Vector2:
                    Vector2 vector2Value;
                    status = propertySet.TryGetVector2(propertySetPropertyName, out vector2Value);
                    value  = vector2Value;
                    break;

                case CompositionPropertyType.Vector3:
                    Vector3 vector3Value;
                    status = propertySet.TryGetVector3(propertySetPropertyName, out vector3Value);
                    value  = vector3Value;
                    break;
                    // Insert new case for any property type that is being added.
                }

                if (expressionAnimation != null)
                {
                    propertySet.StartAnimation(propertySetPropertyName, expressionAnimation);
                }

                return(status);
            }

            return(CompositionGetValueStatus.NotFound);
        }