예제 #1
0
        private CompositionScopedBatch PrepareBatch()
        {
            var batch = _visual.RootVisual.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            batch.Completed += (s, e) =>
            {
                if (_state is not State.Indeterminate and not State.IndeterminateToCompleted)
                {
                    return;
                }

                var batch = PrepareBatch();

                var compositor   = Window.Current.Compositor;
                var linearEasing = compositor.CreateLinearEasingFunction();

                _animation.Duration = _visual.Duration / (_state == State.IndeterminateToCompleted ? 3 : 2);
                _animation.InsertKeyFrame(0, _state == State.IndeterminateToCompleted ? 60f / 90f : 0, linearEasing);
                _animation.InsertKeyFrame(1, _state == State.IndeterminateToCompleted ? 1 : 60f / 90f, linearEasing);
                _properties.StartAnimation("Progress", _animation);

                _state = _state == State.IndeterminateToCompleted ? State.Completed : State.Indeterminate;
                batch.End();
            };

            return(batch);
        }
예제 #2
0
        private void InitializeAnimations()
        {
            _props.InsertScalar("position", 0);
            _props.InsertScalar("progress", 0);

            var trackerNode = _tracker.GetReference();

            _props.StartAnimation("position", -trackerNode.Position.X);
            _props.StartAnimation("progress", EF.Abs(trackerNode.Position.X) / trackerNode.MaxPosition.X);

            ConfigureTemplateAnimations();
        }
        private void SetOption(float optionX, float optionY)
        {
            var scalarAnimation = compositor.CreateScalarKeyFrameAnimation();

            scalarAnimation.Duration = TimeSpan.FromMilliseconds(800);
            scalarAnimation.InsertKeyFrame(1f, optionX);
            propertySet.StartAnimation("Option1", scalarAnimation);

            scalarAnimation          = compositor.CreateScalarKeyFrameAnimation();
            scalarAnimation.Duration = TimeSpan.FromMilliseconds(800);
            scalarAnimation.InsertKeyFrame(1f, optionY);
            propertySet.StartAnimation("Option2", scalarAnimation);
        }
예제 #4
0
        private void startAnimation(CompositionSurfaceBrush brush)
        {
            animatingPropset = compositor.CreatePropertySet();
            animatingPropset.InsertScalar("xcoord", 1.0f);
            animatingPropset.StartAnimation("xcoord", moveSurfaceExpressionAnimation);

            animatingPropset.InsertScalar("ycoord", 1.0f);
            animatingPropset.StartAnimation("ycoord", moveSurfaceUpDownExpressionAnimation);

            animateMatrix = compositor.CreateExpressionAnimation("Matrix3x2(1.0, 0.0, 0.0, 1.0, props.xcoord, props.ycoord)");
            animateMatrix.SetReferenceParameter("props", animatingPropset);

            brush.StartAnimation(nameof(brush.TransformMatrix), animateMatrix);
        }
예제 #5
0
        private void UpdateTo()
        {
            if (host == null)
            {
                return;
            }
            propset.StopAnimation("offsetx");
            propset.StopAnimation("offsety");
            ExpressionAnimation an = null;

            switch (To)
            {
            case FlipTransitionMode.Left:
                an = host.Compositor.CreateExpressionAnimation("-host.Size.X");
                an.SetReferenceParameter("host", host);
                propset.StartAnimation("offsetx", an);
                propset.InsertScalar("offsety", 0f);
                propset.InsertScalar("degress", 90f);
                propset.InsertVector3("axis", Vector3.UnitY);
                break;

            case FlipTransitionMode.Top:
                an = host.Compositor.CreateExpressionAnimation("-host.Size.Y");
                an.SetReferenceParameter("host", host);
                propset.InsertScalar("offsetx", 0f);
                propset.StartAnimation("offsety", an);
                propset.InsertScalar("degress", 90f);
                propset.InsertVector3("axis", Vector3.UnitX);
                break;

            case FlipTransitionMode.Right:
                an = host.Compositor.CreateExpressionAnimation("host.Size.X");
                an.SetReferenceParameter("host", host);
                propset.StartAnimation("offsetx", an);
                propset.InsertScalar("offsety", 0f);
                propset.InsertScalar("degress", -90f);
                propset.InsertVector3("axis", Vector3.UnitY);
                break;

            case FlipTransitionMode.Bottom:
                an = host.Compositor.CreateExpressionAnimation("host.Size.Y");
                an.SetReferenceParameter("host", host);
                propset.InsertScalar("offsetx", 0f);
                propset.StartAnimation("offsety", an);
                propset.InsertScalar("degress", -90f);
                propset.InsertVector3("axis", Vector3.UnitX);
                break;
            }
        }
예제 #6
0
        private void page_Loaded(object sender, RoutedEventArgs e)
        {
            Loaded -= page_Loaded;

            spVisual        = ElementCompositionPreview.GetElementVisual(spContent);
            btnScrollVisual = ElementCompositionPreview.GetElementVisual(btn_Scroll);
            compositor      = spVisual.Compositor;
            tracker         = InteractionTracker.Create(compositor);
            var tref = tracker.GetReference();

            var trackerTarget = ExpressionValues.Target.CreateInteractionTrackerTarget();
            var endpoint1     = InteractionTrackerInertiaRestingValue.Create(compositor);

            endpoint1.SetCondition(trackerTarget.NaturalRestingPosition.Y < (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2);
            endpoint1.SetRestingValue(trackerTarget.MinPosition.Y);
            var endpoint2 = InteractionTrackerInertiaRestingValue.Create(compositor);

            endpoint2.SetCondition(trackerTarget.NaturalRestingPosition.Y >= (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2);
            endpoint2.SetRestingValue(trackerTarget.MaxPosition.Y);
            tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { endpoint1, endpoint2 });

            interactionSource = VisualInteractionSource.Create(spVisual);
            interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
            tracker.InteractionSources.Add(interactionSource);
            propertySet = compositor.CreatePropertySet();
            propertySet.InsertScalar("progress", 0.0f);
            propertySet.StartAnimation("progress", tref.Position.Y / tref.MaxPosition.Y);
            var progress = propertySet.GetReference().GetScalarProperty("progress");

            btnScrollVisual.StartAnimation("RotationAngleInDegrees", ExpressionFunctions.Clamp(progress, 0f, 1f) * 180);
            btnScrollVisual.CenterPoint = new System.Numerics.Vector3((float)btn_Scroll.ActualWidth / 2, (float)btn_Scroll.ActualHeight / 2, 0);
            spVisual.StartAnimation("Offset.Y", -ExpressionFunctions.Clamp(progress, -0.4f, 1.4f) * tref.MaxPosition.Y);
            gdInfo_SizeChanged(this, null);
        }
예제 #7
0
        public MainPage()
        {
            InitializeComponent();

            _compositor = Window.Current.Compositor;
            _tracker    = InteractionTracker.CreateWithOwner(_compositor, this);
            _progress   = _compositor.CreatePropertySet();

            RenderAdaptiveCard();

            RomeShare.SessionListUpdated += OnSessionListUpdated;
            Loaded += async(s, e) => await RomeShare.DiscoverSessionsAsync();

            // When the size of the app changes, we need to update all the measures.
            SizeChanged += (s, e) =>
            {
                if (_hitTestVisual != null)
                {
                    _hitTestVisual.Size = Card.RenderSize.ToVector2();

                    var distanceFromTop = (float)Card.RelativePosition(this).Y;
                    _maxDistance         = distanceFromTop + _hitTestVisual.Size.Y;
                    _tracker.MaxPosition = new Vector3(_maxDistance);

                    var trackerNode = _tracker.GetReference();
                    _progress.StartAnimation("Progress", trackerNode.Position.Y / _tracker.MaxPosition.Y);
                }
            };
        }
예제 #8
0
        private void Header_Loaded(object sender, RoutedEventArgs e)
        {
            var scrollviewer = MainScroller;

            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollviewer);
            _compositor          = _scrollerPropertySet.Compositor;

            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);

            // Get references to our property sets for use with ExpressionNodes
            var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>();
            var props        = _props.GetReference();
            var progressNode = props.GetScalarProperty("progress");

            // Create and start an ExpressionAnimation to track scroll progress over the desired distance
            ExpressionNode progressAnimation = EF.Clamp(-scrollingProperties.Translation.Y / ((float)Header.Height), 0, 1);

            _props.StartAnimation("progress", progressAnimation);

            var headerbgVisual         = ElementCompositionPreview.GetElementVisual(HeaderBG);
            var bgblurOpacityAnimation = EF.Clamp(progressNode, 0, 1);

            headerbgVisual.StartAnimation("Opacity", bgblurOpacityAnimation);
        }
예제 #9
0
        private void _switchLight(bool turnOn)
        {
            Action animateSpotLight = () =>
            {
                var animation = _colorsProxy.Compositor.CreateScalarKeyFrameAnimation();
                animation.Duration = TimeSpan.FromMilliseconds(250);
                animation.InsertKeyFrame(1, turnOn ? 1f : 0f);
                _colorsProxy.StartAnimation("LightIntensity", animation);
            };

            if (turnOn)
            {
                //_light.IsEnabled = true;
                animateSpotLight();
            }
            else
            {
                CompositionScopedBatch scopedBatch = Window.Current.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
                animateSpotLight();
                scopedBatch.End();
                scopedBatch.Completed += (o, e) =>
                {
                    //_light.IsEnabled = false;
                };
            }
        }
예제 #10
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(SCRpost);
            _compositor          = _scrollerPropertySet.Compositor;
            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);
            _props.InsertScalar("clampSize", 150);
            _props.InsertScalar("scaleFactor", 0.7f);

            var progressAnimation = _compositor.CreateExpressionAnimation("Clamp(-scrollingProperties.Translation.Y/150,0,1)");

            progressAnimation.SetReferenceParameter("scrollingProperties", _scrollerPropertySet);
            _props.StartAnimation("progress", progressAnimation);
            Visual headerVisual = ElementCompositionPreview.GetElementVisual(Header);

            /*
             * var headerScaleAnimation = _compositor.CreateExpressionAnimation("Lerp(1,1.25f,Clamp(scrollingProperties.Translation.Y/50,0,1))");
             * headerScaleAnimation.SetReferenceParameter("scrollingProperties", _scrollerPropertySet);
             * headerVisual.StartAnimation("Scale.X", headerScaleAnimation);
             * headerVisual.StartAnimation("Scale.Y", headerScaleAnimation);
             * headerVisual.CenterPoint= new Vector3((float)(Header.ActualWidth / 2), (float)Header.ActualHeight, 0);*/
            var headerOffsetAnimation = _compositor.CreateExpressionAnimation("-150*props.progress");

            headerOffsetAnimation.SetReferenceParameter("props", _props);
            headerVisual.StartAnimation("Offset.Y", headerOffsetAnimation);
            Visual photoVisual           = ElementCompositionPreview.GetElementVisual(RECTback);
            var    photoOpacityAnimation = _compositor.CreateExpressionAnimation("1-props.progress");

            photoOpacityAnimation.SetReferenceParameter("props", _props);
            photoVisual.StartAnimation("Opacity", photoOpacityAnimation);
            Visual overlayVisual           = ElementCompositionPreview.GetElementVisual(OverlayRectangle);
            var    overlayOpacityAnimation = _compositor.CreateExpressionAnimation("props.progress");

            overlayOpacityAnimation.SetReferenceParameter("props", _props);
            overlayVisual.StartAnimation("Opacity", overlayOpacityAnimation);
            Visual blurbVisual          = ElementCompositionPreview.GetElementVisual(Blurb);
            var    textOpacityAnimation = _compositor.CreateExpressionAnimation("Clamp(1-(props.progress*2),0,1)");

            textOpacityAnimation.SetReferenceParameter("props", _props);
            var scaleAnimation = _compositor.CreateExpressionAnimation("Lerp(1,0.7f,props.progress)");

            scaleAnimation.SetReferenceParameter("props", _props);
            blurbVisual.StartAnimation("Opacity", textOpacityAnimation);
            blurbVisual.StartAnimation("Scale.X", scaleAnimation);
            blurbVisual.StartAnimation("Scale.Y", scaleAnimation);
            Visual titleVisual            = ElementCompositionPreview.GetElementVisual(TitleBlock);
            Visual buttonVisual           = ElementCompositionPreview.GetElementVisual(ButtonPanel);
            var    contentOffsetAnimation = _compositor.CreateExpressionAnimation("(props.progress)*120");
            var    titleScaleAnimation    = _compositor.CreateExpressionAnimation("Lerp(1,1.05f,props.progress)");

            contentOffsetAnimation.SetReferenceParameter("props", _props);
            titleScaleAnimation.SetReferenceParameter("props", _props);
            titleVisual.StartAnimation("Offset.Y", contentOffsetAnimation);
            titleVisual.StartAnimation("Scale.X", titleScaleAnimation);
            titleVisual.StartAnimation("Scale.Y", titleScaleAnimation);
            var buttonOffsetAnimation = _compositor.CreateExpressionAnimation("(props.progress*30)");

            buttonOffsetAnimation.SetReferenceParameter("props", _props);
            buttonVisual.StartAnimation("Offset.Y", buttonOffsetAnimation);
        }
예제 #11
0
        private void SetupInteractionTracker()
        {
            // Setup the HitTest visual of the InteractionTracker.
            _hitTestVisual      = VisualExtensions.GetVisual(Card);
            _hitTestVisual.Size = Card.RenderSize.ToVector2();
            // TODO: Why this doesn't work?
            //_hitTestVisual.RelativeSizeAdjustment = Vector2.One;

            // In this sample, we only want interactions happening on the Y-axis.
            _interactionSource = VisualInteractionSource.Create(_hitTestVisual);
            _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
            _tracker.InteractionSources.Add(_interactionSource);

            // Setup max position of the InteractionTracker.
            var distanceFromTop = (float)Card.RelativePosition(this).Y;

            _maxDistance         = distanceFromTop + _hitTestVisual.Size.Y;
            _tracker.MaxPosition = new Vector3(_maxDistance);

            // Initialize the manipulation progress.
            // Note: In this simple demo, we could have used the trackerNode.Position.Y to manipulate the offset
            // directly. But we use the manipulation progress here so we could control more things such as the
            // scale or opacity of the "copy" in the future.
            _progress.InsertScalar("Progress", 0);

            // Create an animation that tracks the progress of the manipulation and stores it in a the PropertySet _progress.
            var trackerNode = _tracker.GetReference();

            // Note here we don't want to EF.Clamp the value 'cause we want the overpan which gives a more natural feel
            // when you pan it.
            _progress.StartAnimation("Progress", trackerNode.Position.Y / _tracker.MaxPosition.Y);

            ConfigureRestingPoints();

            void ConfigureRestingPoints()
            {
                // Setup a possible inertia endpoint (snap point) for the InteractionTracker's minimum position.
                var endpoint1 = InteractionTrackerInertiaRestingValue.Create(_compositor);

                // Use this endpoint when the natural resting position of the interaction is less than the halfway point.
                var trackerTarget = ExpressionValues.Target.CreateInteractionTrackerTarget();

                endpoint1.SetCondition(trackerTarget.NaturalRestingPosition.Y < (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2);

                // Set the result for this condition to make the InteractionTracker's y position the minimum y position.
                endpoint1.SetRestingValue(trackerTarget.MinPosition.Y);

                // Setup a possible inertia endpoint (snap point) for the InteractionTracker's maximum position.
                var endpoint2 = InteractionTrackerInertiaRestingValue.Create(_compositor);

                // Use this endpoint when the natural resting position of the interaction is more than the halfway point.
                endpoint2.SetCondition(trackerTarget.NaturalRestingPosition.Y >= (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2);

                // Set the result for this condition to make the InteractionTracker's y position the maximum y position.
                endpoint2.SetRestingValue(trackerTarget.MaxPosition.Y);

                _tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { endpoint1, endpoint2 });
            }
        }
예제 #12
0
        private void StartAnimationsOnProjectionMatrix()
        {
            var matProj =
                "Matrix4x4(" +
                "1 / Max(epsilon, OrthoProj.Size), 0, 0, 0, " +
                "0, 1 / Max(epsilon, OrthoProj.Size), 0, 0, " +
                "0, 0, 1 / (OrthoProj.Far - OrthoProj.Near), 0, " +
                "0, 0, 0, 1)";

            var projExpression = _compositor.CreateExpressionAnimation();

            projExpression.Expression = matProj;
            projExpression.SetScalarParameter("epsilon", 0.0001f);
            projExpression.SetReferenceParameter("OrthoProj", _propertySet);

            _propertySet.StartAnimation("ProjectionMatrix", projExpression);
        }
예제 #13
0
        /// <summary>
        /// Starts spying on the boolean property of the provided object.
        /// </summary>
        /// <param name="sourceObject"></param>
        /// <param name="propertyName"></param>
        /// <param name="originalValue"></param>
        public static void StartSpyingBooleanProperty(CompositionObject sourceObject, string propertyName, bool originalValue = false)
        {
            CompositionPropertySet propertySet         = null;
            ExpressionAnimation    expressionAnimation = null;
            string propertySetPropertyName             = null;

            StartSpyingProperty(sourceObject, ref propertyName, out propertySet, out expressionAnimation, out propertySetPropertyName);

            propertySet.InsertBoolean(propertySetPropertyName, originalValue);
            propertySet.StartAnimation(propertySetPropertyName, expressionAnimation);
        }
예제 #14
0
        /// <summary>
        /// Starts spying on the translation facade of the provided element.
        /// </summary>
        /// <param name="sourceElement"></param>
        /// <param name="propertyName"></param>
        /// <param name="originalValue"></param>
        public static void StartSpyingScaleFacade(UIElement sourceElement, Compositor compositor, Vector3 originalValue)
        {
            CompositionPropertySet propertySet         = null;
            ExpressionAnimation    expressionAnimation = null;
            string propertySetPropertyName             = null;

            StartSpyingFacade(sourceElement, compositor, CompositionFacadeType.Scale, out propertySet, out expressionAnimation, out propertySetPropertyName);

            propertySet.InsertVector3(propertySetPropertyName, originalValue);
            propertySet.StartAnimation(propertySetPropertyName, expressionAnimation);
        }
예제 #15
0
        /// <summary>
        /// Starts spying on the scalar property of the provided object.
        /// </summary>
        /// <param name="sourceObject"></param>
        /// <param name="propertyName"></param>
        /// <param name="originalValue"></param>
        public static void StartSpyingScalarProperty(CompositionObject sourceObject, string propertyName, float originalValue = 0.0f)
        {
            CompositionPropertySet propertySet         = null;
            ExpressionAnimation    expressionAnimation = null;
            string propertySetPropertyName             = null;

            StartSpyingProperty(sourceObject, ref propertyName, out propertySet, out expressionAnimation, out propertySetPropertyName);

            propertySet.InsertScalar(propertySetPropertyName, originalValue);
            propertySet.StartAnimation(propertySetPropertyName, expressionAnimation);
        }
예제 #16
0
        public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image)
        {
            _propertySet = _compositor.CreatePropertySet();
            _propertySet.InsertScalar("Scale", 1.25f);
            _propertySet.InsertScalar("Rotation", 0f);
            _propertySet.InsertVector2("Translate", new Vector2(0f, 0f));
            _propertySet.InsertVector2("CenterPointOffset", new Vector2((float)_lightMap.Size.Width / 2f, 0f));

            _transformExpression.SetReferenceParameter("props", _propertySet);

            image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression);
            _propertySet.StartAnimation("Rotation", _enterAnimation);
        }
예제 #17
0
        public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image)
        {
            _propertySet = _compositor.CreatePropertySet();
            _propertySet.InsertScalar("Scale", 1f);
            Vector2 positionNormalized = new Vector2((pointerPosition.X / (float)image.Width) - .5f, (pointerPosition.Y / (float)image.Height) - .5f);

            _propertySet.InsertVector2("Translate", positionNormalized);
            _propertySet.InsertVector2("CenterPointOffset", new Vector2(128, 128));

            _transformExpression.SetReferenceParameter("props", _propertySet);

            image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression);
            _propertySet.StartAnimation("Scale", _enterAnimation);
        }
예제 #18
0
        private void _pressed(bool isPressed)
        {
            Action animateSpotLight = () =>
            {
                var animation = _colorsProxy.Compositor.CreateScalarKeyFrameAnimation();
                animation.Duration = TimeSpan.FromMilliseconds(250);
                animation.InsertKeyFrame(1, isPressed
                    ? OFFSET_ANIMATION_EXPRESSION_REFERENCE_PROPS_SPOTLIGHTHEIGHT_VALUE_WIDE
                    : OFFSET_ANIMATION_EXPRESSION_REFERENCE_PROPS_SPOTLIGHTHEIGHT_VALUE);
                _offsetProps.StartAnimation(OFFSET_ANIMATION_EXPRESSION_REFERENCE_PROPS_SPOTLIGHTHEIGHT_NAME, animation);
            };

            animateSpotLight();
        }
예제 #19
0
        private void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            var animationService = ConnectedAnimationService.GetForCurrentView();
            var animation        = animationService.GetAnimation(Constants.ConnectedAnimationKey);

            if (animation != null)
            {
                animation.TryStart(CoverImage, new UIElement[] { SetImage });
            }

            // Get the PropertySet that contains the scroll values from MyScrollViewer
            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(MyScrollviewer);
            _compositor          = _scrollerPropertySet.Compositor;

            // Create a PropertySet that has values to be referenced in the ExpressionAnimations below
            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);
            _props.InsertScalar("clampSize", 100);

            // Get references to our property sets for use with ExpressionNodes
            var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>();
            var props         = _props.GetReference();
            var progressNode  = props.GetScalarProperty("progress");
            var clampSizeNode = props.GetScalarProperty("clampSize");

            // Create and start an ExpressionAnimation to track scroll progress over the desired distance
            var progressAnimation = ExpressionFunctions.Clamp(-scrollingProperties.Translation.Y / clampSizeNode, 0, 1);

            _props.StartAnimation("progress", progressAnimation);

            // Get the backing visual for the header so that its properties can be animated
            var headerVisual = ElementCompositionPreview.GetElementVisual(Header);

            // Create and start an ExpressionAnimation to clamp the header's offset to keep it onscreen
            var headerTranslationAnimation = ExpressionFunctions.Conditional(progressNode < 1, 0, -scrollingProperties.Translation.Y - clampSizeNode);

            headerVisual.StartAnimation("Offset.Y", headerTranslationAnimation);

            // Create and start an ExpressionAnimation to scale the header during overpan
            var headerScaleAnimation = ExpressionFunctions.Lerp(1, 1.25f, ExpressionFunctions.Clamp(scrollingProperties.Translation.Y / 50, 0, 1));

            headerVisual.StartAnimation("Scale.X", headerScaleAnimation);
            headerVisual.StartAnimation("Scale.Y", headerScaleAnimation);

            //Set the header's CenterPoint to ensure the overpan scale looks as desired
            headerVisual.CenterPoint = new Vector3((float)(Header.ActualWidth / 2), (float)Header.ActualHeight, 0);
        }
        private void SetupAnimation()
        {
            var scrollExp = _compositor.CreateExpressionAnimation("-tracker.Position.Y");

            scrollExp.SetReferenceParameter("tracker", _tracker);
            ElementCompositionPreview.GetElementVisual(popup).StartAnimation("Offset.Y", scrollExp);

            ExpressionAnimation progressAnimation = _compositor.CreateExpressionAnimation("tracker.Position.Y / tracker.MaxPosition.Y");

            progressAnimation.SetReferenceParameter("tracker", _tracker);
            _props.InsertScalar("progress", 0);
            _props.StartAnimation("progress", progressAnimation);

            ExpressionAnimation opacityAnimation = _compositor.CreateExpressionAnimation("lerp(0, 1, props.progress)");

            opacityAnimation.SetReferenceParameter("props", _props);
            ElementCompositionPreview.GetElementVisual(popup).StartAnimation("Opacity", opacityAnimation);
        }
예제 #21
0
        private void SetupAnimation()
        {
            ExpressionAnimation progressAnimation = _compositor.CreateExpressionAnimation("tracker.Position.Y / tracker.MaxPosition.Y");

            progressAnimation.SetReferenceParameter("tracker", _tracker);
            _props.InsertScalar("progress", 0);
            _props.StartAnimation("progress", progressAnimation);

            ExpressionAnimation opacityAnimation = _compositor.CreateExpressionAnimation("lerp(0, 1, props.progress)");

            opacityAnimation.SetReferenceParameter("props", _props);
            ElementCompositionPreview.GetElementVisual(draggableRect).StartAnimation("Opacity", opacityAnimation);

            ExpressionAnimation scaleAnimation = _compositor.CreateExpressionAnimation("Vector3(1,1,1) * lerp(1, 2, props.progress)");

            scaleAnimation.SetReferenceParameter("props", _props);
            ElementCompositionPreview.GetElementVisual(draggableRect).StartAnimation("Scale", scaleAnimation);
        }
예제 #22
0
        private void Header_Loaded(object sender, RoutedEventArgs e)
        {
            var scrollviewer = MainScroller;

            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollviewer);
            _compositor          = _scrollerPropertySet.Compositor;

            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);
            _props.InsertScalar("clampSize", (float)HeaderBG.Height);
            _props.InsertScalar("scaleFactor", 0.7f);

            // Get references to our property sets for use with ExpressionNodes
            var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>();
            var props           = _props.GetReference();
            var progressNode    = props.GetScalarProperty("progress");
            var clampSizeNode   = props.GetScalarProperty("clampSize");
            var scaleFactorNode = props.GetScalarProperty("scaleFactor");

            // Create and start an ExpressionAnimation to track scroll progress over the desired distance
            var progressAnimation = EF.Clamp(-scrollingProperties.Translation.Y / clampSizeNode, 0, 1);

            _props.StartAnimation("progress", progressAnimation);

            var headerbgVisual         = ElementCompositionPreview.GetElementVisual(HeaderBG);
            var bgblurOpacityAnimation = EF.Clamp(progressNode, 0, 1);

            headerbgVisual.StartAnimation("Opacity", bgblurOpacityAnimation);

            var headerVisual   = ElementCompositionPreview.GetElementVisual(HeroTitle);
            var scaleAnimation = EF.Lerp(1, scaleFactorNode, progressNode);

            headerVisual.StartAnimation("Scale.X", scaleAnimation);
            headerVisual.StartAnimation("Scale.Y", scaleAnimation);

            var offsetAnimation  = EF.Lerp(160f, 32f, progressNode);
            var opacityAnimation = EF.Lerp(1f, 0.6f, progressNode);

            var containerVisual = ElementCompositionPreview.GetElementVisual(TextContainer);

            containerVisual.StartAnimation("Offset.Y", offsetAnimation);
            containerVisual.StartAnimation("Opacity", opacityAnimation);
        }
예제 #23
0
        private void AlbumList_Loaded(object sender, RoutedEventArgs e)
        {
            var ani = ConnectedAnimationService.GetForCurrentView().GetAnimation(Consts.ArtistPageInAnimation);

            if (ani != null)
            {
                ani.TryStart(Title, new UIElement[] { HeaderBG, Details });
            }

            var scrollviewer = AlbumList.GetScrollViewer();

            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollviewer);
            _compositor          = _scrollerPropertySet.Compositor;

            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);
            _props.InsertScalar("clampSize", (float)Title.ActualHeight + 64);
            _props.InsertScalar("scaleFactor", 0.5f);

            // Get references to our property sets for use with ExpressionNodes
            var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>();
            var props           = _props.GetReference();
            var progressNode    = props.GetScalarProperty("progress");
            var clampSizeNode   = props.GetScalarProperty("clampSize");
            var scaleFactorNode = props.GetScalarProperty("scaleFactor");

            // Create and start an ExpressionAnimation to track scroll progress over the desired distance
            ExpressionNode progressAnimation = EF.Clamp(-scrollingProperties.Translation.Y / ((float)Header.Height - clampSizeNode), 0, 1);

            _props.StartAnimation("progress", progressAnimation);

            // Get the backing visual for the header so that its properties can be animated
            Visual headerVisual = ElementCompositionPreview.GetElementVisual(Header);

            // Create and start an ExpressionAnimation to clamp the header's offset to keep it onscreen
            ExpressionNode headerTranslationAnimation = EF.Conditional(progressNode < 1, scrollingProperties.Translation.Y, -(float)Header.Height + (float)Title.ActualHeight + 64);

            headerVisual.StartAnimation("Offset.Y", headerTranslationAnimation);

            //// Create and start an ExpressionAnimation to scale the header during overpan
            //ExpressionNode headerScaleAnimation = EF.Lerp(1, 1.25f, EF.Clamp(scrollingProperties.Translation.Y / 50, 0, 1));
            //headerVisual.StartAnimation("Scale.X", headerScaleAnimation);
            //headerVisual.StartAnimation("Scale.Y", headerScaleAnimation);

            ////Set the header's CenterPoint to ensure the overpan scale looks as desired
            //headerVisual.CenterPoint = new Vector3((float)(Header.ActualWidth / 2), (float)Header.ActualHeight, 0);

            var titleVisual       = ElementCompositionPreview.GetElementVisual(Title);
            var titleshrinkVisual = ElementCompositionPreview.GetElementVisual(TitleShrink);
            var fixAnimation      = EF.Conditional(progressNode < 1, -scrollingProperties.Translation.Y, (float)Header.Height - ((float)Title.ActualHeight + 64));

            titleVisual.StartAnimation("Offset.Y", fixAnimation);
            titleshrinkVisual.StartAnimation("Offset.Y", fixAnimation);
            var detailsVisual    = ElementCompositionPreview.GetElementVisual(Details);
            var opacityAnimation = EF.Clamp(1 - (progressNode * 8), 0, 1);

            detailsVisual.StartAnimation("Opacity", opacityAnimation);

            var headerbgVisual         = ElementCompositionPreview.GetElementVisual(HeaderBG);
            var headerbgOverlayVisual  = ElementCompositionPreview.GetElementVisual(HeaderBGOverlay);
            var bgBlurVisual           = ElementCompositionPreview.GetElementVisual(BGBlur);
            var bgOpacityAnimation     = EF.Clamp(1 - progressNode, 0, 1);
            var bgblurOpacityAnimation = EF.Clamp(progressNode, 0, 1);

            titleshrinkVisual.StartAnimation("Opacity", bgblurOpacityAnimation);
            titleVisual.StartAnimation("Opacity", bgOpacityAnimation);
            headerbgVisual.StartAnimation("Opacity", bgOpacityAnimation);
            headerbgOverlayVisual.StartAnimation("Opacity", bgOpacityAnimation);
            bgBlurVisual.StartAnimation("Opacity", bgblurOpacityAnimation);
        }
        public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image)
        {
            _propertySet = _compositor.CreatePropertySet();
            _propertySet.InsertScalar("Scale", 1.25f);
            _propertySet.InsertScalar("Rotation", 0f);
            _propertySet.InsertVector2("Translate", new Vector2(0f, 0f));
            _propertySet.InsertVector2("CenterPointOffset", new Vector2((float)_lightMap.Size.Width / 2f, 0f));

            _transformExpression.SetReferenceParameter("props", _propertySet);

            image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression);
            _propertySet.StartAnimation("Rotation", _enterAnimation);
        }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var gridView = this.FindAscendant <GridView>();

            if (gridView == null)
            {
                return;
            }

            var scrollViewer    = gridView.FindDescendant <ScrollViewer>();
            var headerPresenter = (UIElement)VisualTreeHelper.GetParent((UIElement)gridView.Header);
            var headerContainer = (UIElement)VisualTreeHelper.GetParent(headerPresenter);

            Canvas.SetZIndex(headerContainer, 1);

            _scrollerPropertySet = scrollViewer.GetScrollViewerManipulationPropertySet();
            _compositor          = _scrollerPropertySet.Compositor;

            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);
            _props.InsertScalar("clampSize", 240);
            _props.InsertScalar("scaleFactor", 0.7f);

            var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>();
            var props           = _props.GetReference();
            var progressNode    = props.GetScalarProperty("progress");
            var clampSizeNode   = props.GetScalarProperty("clampSize");
            var scaleFactorNode = props.GetScalarProperty("scaleFactor");

            ExpressionNode progressAnimation = ExpressionFunctions.Clamp(-scrollingProperties.Translation.Y / clampSizeNode, 0, 1);

            _props.StartAnimation("progress", progressAnimation);

            ExpressionNode headerScaleAnimation       = ExpressionFunctions.Lerp(1, 1.25f, ExpressionFunctions.Clamp(scrollingProperties.Translation.Y / 50, 0, 1));
            ExpressionNode headerTranslationAnimation = ExpressionFunctions.Conditional(progressNode < 1, 0, -scrollingProperties.Translation.Y - clampSizeNode);

            var headerVisual = this.ElementVisual();

            headerVisual.CenterPoint = new Vector3((float)(this.ActualWidth / 2), (float)this.ActualHeight, 0);
            headerVisual.StartAnimation("Scale.X", headerScaleAnimation);
            headerVisual.StartAnimation("Scale.Y", headerScaleAnimation);
            headerVisual.StartAnimation("Offset.Y", headerTranslationAnimation);

            ExpressionNode primaryOpacityAnimation = 1 - progressNode;

            PrimaryBackground.ElementVisual().StartAnimation("opacity", primaryOpacityAnimation);

            ExpressionNode secondaryOpacityAnimation = progressNode;

            SecondaryBackground.ElementVisual().StartAnimation("opacity", secondaryOpacityAnimation);

            ExpressionNode scaleAnimation      = ExpressionFunctions.Lerp(1, scaleFactorNode, progressNode);
            ExpressionNode opacityAnimation    = ExpressionFunctions.Clamp(1 - (progressNode * 2), 0, 1);
            Visual         autoSearchBoxVisual = SearchBox.ElementVisual();

            autoSearchBoxVisual.CenterPoint = new Vector3((float)(SearchBox.ActualWidth / 2), (float)SearchBox.ActualHeight, 0);
            autoSearchBoxVisual.StartAnimation("Scale.X", scaleAnimation);
            autoSearchBoxVisual.StartAnimation("Scale.Y", scaleAnimation);
            autoSearchBoxVisual.StartAnimation("Opacity", opacityAnimation);

            Visual         subMenuPanelVisual     = SubMenuPanel.ElementVisual();
            ExpressionNode contentOffsetAnimation = progressNode * 100;

            subMenuPanelVisual.StartAnimation("Offset.Y", contentOffsetAnimation);

            ExpressionNode searchBtnOpacityAnimation = ExpressionFunctions.Conditional(progressNode < 1, 0, 1);
            Visual         searchBtnVisual           = ElementCompositionPreview.GetElementVisual(SearchBtn);

            searchBtnVisual.StartAnimation("Opacity", searchBtnOpacityAnimation);
        }
        public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image)
        {
            _propertySet = _compositor.CreatePropertySet();
            _propertySet.InsertScalar("Scale", 1f);
            Vector2 positionNormalized = new Vector2((pointerPosition.X / (float)image.Width) - .5f, (pointerPosition.Y / (float)image.Height) - .5f);
            _propertySet.InsertVector2("Translate", positionNormalized);
            _propertySet.InsertVector2("CenterPointOffset", new Vector2(128, 128));

            _transformExpression.SetReferenceParameter("props", _propertySet);

            image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression);
            _propertySet.StartAnimation("Scale", _enterAnimation);
        }
예제 #27
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);
        }
        private void MainInformationPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            ApplicationViewTitleBar formattableTitleBar = ApplicationView.GetForCurrentView().TitleBar;

            formattableTitleBar.ButtonBackgroundColor         = Colors.Transparent;
            formattableTitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
            CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;

            coreTitleBar.ExtendViewIntoTitleBar = true;

            // Update the ZIndex of the header container so that the header is above the items when scrolling
            Canvas.SetZIndex(Header, 1);

            // Get the PropertySet that contains the scroll values from the ScrollViewer
            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer);
            _compositor          = _scrollerPropertySet.Compositor;

            // Create a PropertySet that has values to be referenced in the ExpressionAnimations below
            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);
            _props.InsertScalar("clampSize", 150);
            _props.InsertScalar("scaleFactor", 0.7f);

            // Get references to our property sets for use with ExpressionNodes
            var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>();
            var props         = _props.GetReference();
            var progressNode  = props.GetScalarProperty("progress");
            var clampSizeNode = props.GetScalarProperty("clampSize");

            // Create and start an ExpressionAnimation to track scroll progress over the desired distance
            ExpressionNode progressAnimation = ExpressionFunctions.Clamp(-scrollingProperties.Translation.Y / clampSizeNode, 0, 1);

            _props.StartAnimation("progress", progressAnimation);

            // Get the backing visual for the header so that its properties can be animated
            headerVisual = ElementCompositionPreview.GetElementVisual(Header);

            // Create and start an ExpressionAnimation to clamp the header's offset to keep it onscreen
            ExpressionNode headerTranslationAnimation = ExpressionFunctions.Conditional(progressNode < 1, 0, -scrollingProperties.Translation.Y - clampSizeNode);

            headerVisual.StartAnimation("Offset.Y", headerTranslationAnimation);

            // Create and start an ExpressionAnimation to scale the header during overpan
            ExpressionNode headerScaleAnimation = ExpressionFunctions.Lerp(1, 1.25f, ExpressionFunctions.Clamp(scrollingProperties.Translation.Y / 50, 0, 1));

            headerVisual.StartAnimation("Scale.X", headerScaleAnimation);
            headerVisual.StartAnimation("Scale.Y", headerScaleAnimation);

            //Set the header's CenterPoint to ensure the overpan scale looks as desired
            headerVisual.CenterPoint = new Vector3((float)(Header.ActualWidth / 2), (float)Header.ActualHeight, 0);

            ExpressionNode OpacityAnimation = ExpressionFunctions.Clamp(1 - (progressNode * 2), 0, 1);

            Visual profileVisual = ElementCompositionPreview.GetElementVisual(ProfileImage);

            profileVisual.StartAnimation("Opacity", OpacityAnimation);

            Visual subtitleVisual = ElementCompositionPreview.GetElementVisual(SubtitleBlock);

            subtitleVisual.StartAnimation("Opacity", OpacityAnimation);

            // Get the backing visuals for the text and button containers so that their properites can be animated
            Visual buttonVisual = ElementCompositionPreview.GetElementVisual(ButtonPanel);

            ExpressionNode buttonOffsetAnimation = progressNode * -14;

            buttonVisual.StartAnimation("Offset.Y", buttonOffsetAnimation);
        }
예제 #29
0
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get the PropertySet that contains the scroll values from MyScrollViewer
            _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(MyScrollviewer);
            _compositor          = _scrollerPropertySet.Compositor;
            Model = new LocalDataSource();

            gridView.ItemsSource = Model.AggregateDataSources(new ObservableCollection <Thumbnail>[] { Model.Landscapes, Model.Nature, Model.Abstract });

            // Create a PropertySet that has values to be referenced in the ExpressionAnimations below
            _props = _compositor.CreatePropertySet();
            _props.InsertScalar("progress", 0);
            _props.InsertScalar("clampSize", 150);
            _props.InsertScalar("scaleFactor", 0.7f);

            // Get references to our property sets for use with ExpressionNodes
            var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>();
            var props           = _props.GetReference();
            var progressNode    = props.GetScalarProperty("progress");
            var clampSizeNode   = props.GetScalarProperty("clampSize");
            var scaleFactorNode = props.GetScalarProperty("scaleFactor");

            // Create a blur effect to be animated based on scroll position
            var blurEffect = new GaussianBlurEffect()
            {
                Name         = "blur",
                BlurAmount   = 0.0f,
                BorderMode   = EffectBorderMode.Hard,
                Optimization = EffectOptimization.Balanced,
                Source       = new CompositionEffectSourceParameter("source")
            };

            var blurBrush = _compositor.CreateEffectFactory(
                blurEffect,
                new[] { "blur.BlurAmount" })
                            .CreateBrush();

            blurBrush.SetSourceParameter("source", _compositor.CreateBackdropBrush());

            // Create a Visual for applying the blur effect
            _blurredBackgroundImageVisual       = _compositor.CreateSpriteVisual();
            _blurredBackgroundImageVisual.Brush = blurBrush;
            _blurredBackgroundImageVisual.Size  = new Vector2((float)OverlayRectangle.ActualWidth, (float)OverlayRectangle.ActualHeight);

            // Insert the blur visual at the right point in the Visual Tree
            ElementCompositionPreview.SetElementChildVisual(OverlayRectangle, _blurredBackgroundImageVisual);

            // Create and start an ExpressionAnimation to track scroll progress over the desired distance
            ExpressionNode progressAnimation = EF.Clamp(-scrollingProperties.Translation.Y / clampSizeNode, 0, 1);

            _props.StartAnimation("progress", progressAnimation);

            // Create and start an ExpressionAnimation to animate blur radius between 0 and 15 based on progress
            ExpressionNode blurAnimation = EF.Lerp(0, 15, progressNode);

            _blurredBackgroundImageVisual.Brush.Properties.StartAnimation("blur.BlurAmount", blurAnimation);

            // Get the backing visual for the header so that its properties can be animated
            Visual headerVisual = ElementCompositionPreview.GetElementVisual(Header);

            // Create and start an ExpressionAnimation to clamp the header's offset to keep it onscreen
            ExpressionNode headerTranslationAnimation = EF.Conditional(progressNode < 1, 0, -scrollingProperties.Translation.Y - clampSizeNode);

            headerVisual.StartAnimation("Offset.Y", headerTranslationAnimation);

            // Create and start an ExpressionAnimation to scale the header during overpan
            ExpressionNode headerScaleAnimation = EF.Lerp(1, 1.25f, EF.Clamp(scrollingProperties.Translation.Y / 50, 0, 1));

            headerVisual.StartAnimation("Scale.X", headerScaleAnimation);
            headerVisual.StartAnimation("Scale.Y", headerScaleAnimation);

            //Set the header's CenterPoint to ensure the overpan scale looks as desired
            headerVisual.CenterPoint = new Vector3((float)(Header.ActualWidth / 2), (float)Header.ActualHeight, 0);

            // Get the backing visual for the photo in the header so that its properties can be animated
            Visual photoVisual = ElementCompositionPreview.GetElementVisual(BackgroundRectangle);

            // Create and start an ExpressionAnimation to opacity fade out the image behind the header
            ExpressionNode imageOpacityAnimation = 1 - progressNode;

            photoVisual.StartAnimation("opacity", imageOpacityAnimation);

            // Get the backing visual for the profile picture visual so that its properties can be animated
            Visual profileVisual = ElementCompositionPreview.GetElementVisual(ProfileImage);

            // Create and start an ExpressionAnimation to scale the profile image with scroll position
            ExpressionNode scaleAnimation = EF.Lerp(1, scaleFactorNode, progressNode);

            profileVisual.StartAnimation("Scale.X", scaleAnimation);
            profileVisual.StartAnimation("Scale.Y", scaleAnimation);

            // Get backing visuals for the text blocks so that their properties can be animated
            Visual blurbVisual    = ElementCompositionPreview.GetElementVisual(Blurb);
            Visual subtitleVisual = ElementCompositionPreview.GetElementVisual(SubtitleBlock);
            Visual moreVisual     = ElementCompositionPreview.GetElementVisual(MoreText);

            // Create an ExpressionAnimation that moves between 1 and 0 with scroll progress, to be used for text block opacity
            ExpressionNode textOpacityAnimation = EF.Clamp(1 - (progressNode * 2), 0, 1);

            // Start opacity and scale animations on the text block visuals
            blurbVisual.StartAnimation("Opacity", textOpacityAnimation);
            blurbVisual.StartAnimation("Scale.X", scaleAnimation);
            blurbVisual.StartAnimation("Scale.Y", scaleAnimation);

            subtitleVisual.StartAnimation("Opacity", textOpacityAnimation);
            subtitleVisual.StartAnimation("Scale.X", scaleAnimation);
            subtitleVisual.StartAnimation("Scale.Y", scaleAnimation);

            moreVisual.StartAnimation("Opacity", textOpacityAnimation);
            moreVisual.StartAnimation("Scale.X", scaleAnimation);
            moreVisual.StartAnimation("Scale.Y", scaleAnimation);

            // Get the backing visuals for the text and button containers so that their properites can be animated
            Visual textVisual   = ElementCompositionPreview.GetElementVisual(TextContainer);
            Visual buttonVisual = ElementCompositionPreview.GetElementVisual(ButtonPanel);

            // When the header stops scrolling it is 150 pixels offscreen.  We want the text header to end up with 50 pixels of its content
            // offscreen which means it needs to go from offset 0 to 100 as we traverse through the scrollable region
            ExpressionNode contentOffsetAnimation = progressNode * 100;

            textVisual.StartAnimation("Offset.Y", contentOffsetAnimation);

            ExpressionNode buttonOffsetAnimation = progressNode * -100;

            buttonVisual.StartAnimation("Offset.Y", buttonOffsetAnimation);
        }
예제 #30
0
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Compositor compositor = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor;

            _imageLoader = ImageLoaderFactory.CreateImageLoader(compositor);
            ContainerVisual container = compositor.CreateContainerVisual();

            ElementCompositionPreview.SetElementChildVisual(MyGrid, container);


            //
            // Create a couple of SurfaceBrushes for the orbiters and center
            //

            CompositionSurfaceBrush redBrush = compositor.CreateSurfaceBrush();

            _redBallSurface  = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/RedBall.png"));
            redBrush.Surface = _redBallSurface.Surface;

            CompositionSurfaceBrush blueBrush = compositor.CreateSurfaceBrush();

            _blueBallSurface  = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/BlueBall.png"));
            blueBrush.Surface = _blueBallSurface.Surface;


            //
            // Create the center and orbiting sprites
            //

            SpriteVisual redSprite = compositor.CreateSpriteVisual();

            redSprite.Brush  = redBrush;
            redSprite.Size   = new Vector2(100f, 100f);
            redSprite.Offset = new Vector3(200f, 200f, 0f);
            container.Children.InsertAtTop(redSprite);

            SpriteVisual blueSprite = compositor.CreateSpriteVisual();

            blueSprite.Brush  = blueBrush;
            blueSprite.Size   = new Vector2(25f, 25f);
            blueSprite.Offset = new Vector3(0f, 0f, 0f);
            container.Children.InsertAtTop(blueSprite);

            //
            // Create the expression.  This expression positions the orbiting sprite relative to the center of
            // of the red sprite's center.  As we animate the red sprite's position, the expression will read
            // the current value of it's offset and keep the blue sprite locked in orbit.
            //

            ExpressionAnimation expressionAnimation = compositor.CreateExpressionAnimation("visual.Offset + " +
                                                                                           "propertySet.CenterPointOffset + " +
                                                                                           "Vector3(cos(ToRadians(propertySet.Rotation)) * 150," +
                                                                                           "sin(ToRadians(propertySet.Rotation)) * 75, 0)");

            //
            // Create the PropertySet.  This property bag contains all the value referenced in the expression.  We can
            // animation these property leading to the expression being re-evaluated per frame.
            //

            CompositionPropertySet propertySet = compositor.CreatePropertySet();

            propertySet.InsertScalar("Rotation", 0f);
            propertySet.InsertVector3("CenterPointOffset", new Vector3(redSprite.Size.X / 2 - blueSprite.Size.X / 2,
                                                                       redSprite.Size.Y / 2 - blueSprite.Size.Y / 2, 0));

            // Set the parameters of the expression animation
            expressionAnimation.SetReferenceParameter("propertySet", propertySet);
            expressionAnimation.SetReferenceParameter("visual", redSprite);

            // Start the expression animation!
            blueSprite.StartAnimation("Offset", expressionAnimation);


            // Now animate the rotation property in the property bag, this generates the orbitting motion.
            var linear       = compositor.CreateLinearEasingFunction();
            var rotAnimation = compositor.CreateScalarKeyFrameAnimation();

            rotAnimation.InsertKeyFrame(1.0f, 360f, linear);
            rotAnimation.Duration          = TimeSpan.FromMilliseconds(4000);
            rotAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            propertySet.StartAnimation("Rotation", rotAnimation);

            // Lastly, animation the Offset of the red sprite to see the expression track appropriately
            var offsetAnimation = compositor.CreateVector3KeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(0f, new Vector3(125f, 50f, 0f));
            offsetAnimation.InsertKeyFrame(.5f, new Vector3(125f, 200f, 0f));
            offsetAnimation.InsertKeyFrame(1f, new Vector3(125f, 50f, 0f));
            offsetAnimation.Duration          = TimeSpan.FromMilliseconds(4000);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            redSprite.StartAnimation("Offset", offsetAnimation);
        }
예제 #31
0
 public override void OnPointerExit(Vector2 pointerPosition, CompositionImage image)
 {
     _propertySet.StartAnimation("Translate", _exitAnimation);
     _propertySet.StopAnimation("Scale");
 }
예제 #32
0
 public override void OnPointerExit(Vector2 pointerPosition, CompositionImage image)
 {
     _propertySet.StartAnimation("Rotation", _exitAnimation);
 }