示例#1
0
        private void BackgroundImage_FirstOpened(object sender, RoutedEventArgs e)
        {
            // Image loaded, let's show the content
            this.Opacity = 1;

            // Show the content now that we should have something.
            ScalarKeyFrameAnimation fadeInAnimation = _compositor.CreateScalarKeyFrameAnimation();

            fadeInAnimation.InsertKeyFrame(0, 0);
            fadeInAnimation.InsertKeyFrame(1, 1);
            fadeInAnimation.Duration = TimeSpan.FromMilliseconds(1000);
            BackgroundImage.SpriteVisual.StartAnimation("Opacity", fadeInAnimation);
            ElementCompositionPreview.GetElementVisual(ImageList).StartAnimation("Opacity", fadeInAnimation);

            // Start a slow UV scale to create movement in the background image
            Vector2KeyFrameAnimation scaleAnimation = _compositor.CreateVector2KeyFrameAnimation();

            scaleAnimation.InsertKeyFrame(0, new Vector2(1.1f, 1.1f));
            scaleAnimation.InsertKeyFrame(.5f, new Vector2(2.0f, 2.0f));
            scaleAnimation.InsertKeyFrame(1, new Vector2(1.1f, 1.1f));
            scaleAnimation.Duration          = TimeSpan.FromMilliseconds(40000);
            scaleAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

            CompositionDrawingSurface surface = (CompositionDrawingSurface)BackgroundImage.SurfaceBrush.Surface;

            BackgroundImage.SurfaceBrush.CenterPoint = new Vector2((float)surface.Size.Width, (float)surface.Size.Height) * .5f;
            BackgroundImage.SurfaceBrush.StartAnimation("Scale", scaleAnimation);

            // Start the animation of the cross-fade brush so they're in sync
            _previousSurfaceBrush = _compositor.CreateSurfaceBrush();
            _previousSurfaceBrush.StartAnimation("Scale", scaleAnimation);

            BackgroundImage.ImageOpened -= BackgroundImage_FirstOpened;
        }
示例#2
0
        private void DialogDismissedHandler(IUICommand command)
        {
            // Start a scoped batch so we can register to completion event and hide the destination layer
            _scopeBatch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            // Start the hide animation to fade out the destination effect
            ScalarKeyFrameAnimation hideAnimation = _compositor.CreateScalarKeyFrameAnimation();

            hideAnimation.InsertKeyFrame(0f, 1f);
            hideAnimation.InsertKeyFrame(1.0f, 0f);
            hideAnimation.Duration = TimeSpan.FromMilliseconds(1000);
            _destinationSprite.StartAnimation("Opacity", hideAnimation);

            // Use whichever effect is currently selected
            ComboBoxItem item = EffectSelection.SelectedValue as ComboBoxItem;

            switch ((EffectTypes)item.Tag)
            {
            case EffectTypes.Mask:
            {
                CompositionSurfaceBrush  brush          = ((CompositionEffectBrush)_destinationSprite.Brush).GetSourceParameter("SecondSource") as CompositionSurfaceBrush;
                Vector2KeyFrameAnimation scaleAnimation = _compositor.CreateVector2KeyFrameAnimation();
                scaleAnimation.InsertKeyFrame(1f, new Vector2(2.0f, 2.0f));
                scaleAnimation.Duration = TimeSpan.FromMilliseconds(1000);
                brush.StartAnimation("Scale", scaleAnimation);
                break;
            }

            case EffectTypes.VividLight:
            {
                CompositionEffectBrush brush         = (CompositionEffectBrush)_destinationSprite.Brush;
                ColorKeyFrameAnimation coloAnimation = _compositor.CreateColorKeyFrameAnimation();
                coloAnimation.InsertKeyFrame(1f, Color.FromArgb(255, 100, 100, 100));
                coloAnimation.Duration = TimeSpan.FromMilliseconds(1500);
                brush.StartAnimation("Base.Color", coloAnimation);
                break;
            }

            case EffectTypes.Hue:
            {
                CompositionEffectBrush  brush           = (CompositionEffectBrush)_destinationSprite.Brush;
                ScalarKeyFrameAnimation rotateAnimation = _compositor.CreateScalarKeyFrameAnimation();
                rotateAnimation.InsertKeyFrame(1f, 0f);
                rotateAnimation.Duration = TimeSpan.FromMilliseconds(1500);
                brush.StartAnimation("Hue.Angle", rotateAnimation);
                break;
            }

            default:
                break;
            }

            //Scoped batch completed event
            _scopeBatch.Completed += ScopeBatch_Completed;
            _scopeBatch.End();
        }
        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);
        }
        private void StartCrossFade()
        {
            Debug.Assert(_sprite.Children.Count > 0, "Unexpected number of children");

            // Start a batch so we can cleanup the loading sprite
            CompositionScopedBatch batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            batch.Completed += EndCrossFade;

            // Animate the opacity of the loading sprite to fade it out and the texture scale just for effect
            Visual loadingVisual = _sprite.Children.LastOrDefault();

            loadingVisual.StartAnimation("Opacity", _fadeOutAnimation);

#if SDKVERSION_INSIDER
            _surfaceBrush.StartAnimation("Scale", _scaleAnimation);
            _surfaceBrush.CenterPoint = new Vector2((float)_surface.Size.Width * .5f, (float)_surface.Size.Height * .5f);
#endif
            // End the batch after those animations complete
            batch.End();
        }
        private void StartOffsetAnimation(CompositionSurfaceBrush brush, TimeSpan duration, TimeSpan delay)
        {
            var offsetAnimation = Compositor.CreateVector2KeyFrameAnimation();

            offsetAnimation.Duration          = duration;
            offsetAnimation.DelayTime         = delay;
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

            void addKey(float key, float top, float left)
            {
                offsetAnimation.InsertKeyFrame(key, new Vector2(top * 2.5f, left * 2.5f));
            };
            addKey(.1f, -0.4f, -1.1f);
            addKey(.2f, 0.4f, -0.2f);
            addKey(.3f, 0f, .5f);
            addKey(.4f, -0.3f, -0.7f);
            addKey(.5f, 0, .2f);
            addKey(.6f, 1.8f, 1.2f);
            addKey(.7f, -1f, .1f);
            addKey(.8f, -0.4f, -0.9f);
            addKey(.9f, 0, 1.2f);
            addKey(1, 0, -1.2f);
            brush.StartAnimation(nameof(CompositionSurfaceBrush.Offset), offsetAnimation);
        }
示例#6
0
        /// <summary>
        /// Updates the CompositionSurfaceBrush's Stretch and Alignment options
        /// </summary>
        /// <param name="surfaceBrush">CompositionSurfaceBrush</param>
        /// <param name="stretch">Stretch mode</param>
        /// <param name="alignX">Horizontal Alignment</param>
        /// <param name="alignY">Vertical Alignment</param>
        /// <param name="alignXAnimation">The animation to use to update the horizontal alignment of the surface brush</param>
        /// <param name="alignYAnimation">The animation to use to update the vertical alignment of the surface brush</param>
        public static void UpdateSurfaceBrushOptions(this CompositionSurfaceBrush surfaceBrush, Stretch stretch,
                                                     AlignmentX alignX, AlignmentY alignY, ScalarKeyFrameAnimation alignXAnimation = null,
                                                     ScalarKeyFrameAnimation alignYAnimation = null)
        {
            // Stretch Mode
            switch (stretch)
            {
            case Stretch.None:
                surfaceBrush.Stretch = CompositionStretch.None;
                break;

            case Stretch.Fill:
                surfaceBrush.Stretch = CompositionStretch.Fill;
                break;

            case Stretch.Uniform:
                surfaceBrush.Stretch = CompositionStretch.Uniform;
                break;

            case Stretch.UniformToFill:
                surfaceBrush.Stretch = CompositionStretch.UniformToFill;
                break;
            }

            // Horizontal Alignment
            var finalAlignX = surfaceBrush.HorizontalAlignmentRatio;

            switch (alignX)
            {
            case AlignmentX.Left:
                finalAlignX = 0;
                break;

            case AlignmentX.Center:
                finalAlignX = 0.5f;
                break;

            case AlignmentX.Right:
                finalAlignX = 1;
                break;
            }

            // If animation is available, animate to the new value
            // otherwise set it explicitly
            if (alignXAnimation == null)
            {
                surfaceBrush.HorizontalAlignmentRatio = finalAlignX;
            }
            else
            {
                alignXAnimation.InsertKeyFrame(1f, finalAlignX);
                surfaceBrush.StartAnimation(() => surfaceBrush.HorizontalAlignmentRatio, alignXAnimation);
            }

            // Vertical Alignment
            var finalAlignY = surfaceBrush.VerticalAlignmentRatio;

            switch (alignY)
            {
            case AlignmentY.Top:
                finalAlignY = 0;
                break;

            case AlignmentY.Center:
                finalAlignY = 0.5f;
                break;

            case AlignmentY.Bottom:
                finalAlignY = 1;
                break;
            }

            // If animation is available, animate to the new value
            // otherwise set it explicitly
            if (alignYAnimation == null)
            {
                surfaceBrush.VerticalAlignmentRatio = finalAlignY;
            }
            else
            {
                alignYAnimation.InsertKeyFrame(1f, finalAlignY);
                surfaceBrush.StartAnimation(() => surfaceBrush.VerticalAlignmentRatio, alignYAnimation);
            }
        }
示例#7
0
        private async void ThumbnailList_ItemClick(object sender, ItemClickEventArgs e)
        {
            Thumbnail thumbnail = (Thumbnail)e.ClickedItem;

            // If we're in the middle of an animation, cancel it now
            if (_scopeBatch != null)
            {
                CleanupScopeBatch();
            }

            // We're starting our transition, show the destination sprite
            _destinationSprite.IsVisible = true;

            // Animate from transparent to fully opaque
            ScalarKeyFrameAnimation showAnimation = _compositor.CreateScalarKeyFrameAnimation();

            showAnimation.InsertKeyFrame(0f, 0f);
            showAnimation.InsertKeyFrame(1f, 1f);
            showAnimation.Duration = TimeSpan.FromMilliseconds(1500);
            _destinationSprite.StartAnimation("Opacity", showAnimation);

            // Use whichever effect is currently selected
            ComboBoxItem item = EffectSelection.SelectedValue as ComboBoxItem;

            switch ((EffectTypes)item.Tag)
            {
            case EffectTypes.Mask:
            {
                CompositionSurfaceBrush  brush          = ((CompositionEffectBrush)_destinationSprite.Brush).GetSourceParameter("SecondSource") as CompositionSurfaceBrush;
                Vector2KeyFrameAnimation scaleAnimation = _compositor.CreateVector2KeyFrameAnimation();
                scaleAnimation.InsertKeyFrame(0f, new Vector2(1.25f, 1.25f));
                scaleAnimation.InsertKeyFrame(1f, new Vector2(0f, 0f));
                scaleAnimation.Duration = TimeSpan.FromMilliseconds(2000);
                brush.StartAnimation("Scale", scaleAnimation);
                break;
            }

            case EffectTypes.VividLight:
            {
                CompositionEffectBrush brush         = (CompositionEffectBrush)_destinationSprite.Brush;
                ColorKeyFrameAnimation coloAnimation = _compositor.CreateColorKeyFrameAnimation();
                coloAnimation.InsertKeyFrame(0f, Color.FromArgb(255, 255, 255, 255));
                coloAnimation.InsertKeyFrame(0f, Color.FromArgb(255, 30, 30, 30));
                coloAnimation.Duration = TimeSpan.FromMilliseconds(4000);
                brush.StartAnimation("Base.Color", coloAnimation);
                break;
            }

            case EffectTypes.Hue:
            {
                CompositionEffectBrush  brush           = (CompositionEffectBrush)_destinationSprite.Brush;
                ScalarKeyFrameAnimation rotateAnimation = _compositor.CreateScalarKeyFrameAnimation();
                rotateAnimation.InsertKeyFrame(0f, 0f);
                rotateAnimation.InsertKeyFrame(1f, (float)Math.PI);
                rotateAnimation.Duration = TimeSpan.FromMilliseconds(4000);
                brush.StartAnimation("Hue.Angle", rotateAnimation);
                break;
            }

            case EffectTypes.RainbowBlur:
            {
                CompositionEffectBrush brush          = (CompositionEffectBrush)_destinationSprite.Brush;
                ColorKeyFrameAnimation colorAnimation = _compositor.CreateColorKeyFrameAnimation();
                colorAnimation.InsertKeyFrame(0, Colors.Red);
                colorAnimation.InsertKeyFrame(.16f, Colors.Orange);
                colorAnimation.InsertKeyFrame(.32f, Colors.Yellow);
                colorAnimation.InsertKeyFrame(.48f, Colors.Green);
                colorAnimation.InsertKeyFrame(.64f, Colors.Blue);
                colorAnimation.InsertKeyFrame(.80f, Colors.Purple);
                colorAnimation.InsertKeyFrame(1, Colors.Red);
                colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
                colorAnimation.Duration          = TimeSpan.FromMilliseconds(5000);
                brush.StartAnimation("Base.Color", colorAnimation);
                break;
            }

            default:
                break;
            }

            // Create the dialog
            var messageDialog = new MessageDialog(thumbnail.Name);

            messageDialog.Commands.Add(new UICommand("Close", new UICommandInvokedHandler(DialogDismissedHandler)));

            // Show the message dialog
            await messageDialog.ShowAsync();
        }
        private void HandleAlignments()
        {
            if (_foregroundBrush == null)
            {
                return;
            }

            _foregroundBrush.HorizontalAlignmentRatio = 0f;
            var leftOffset = (float)ImageMargin.Left;
            var topOffset  = (float)ImageMargin.Top;

            var targetHorizontalAlignmentRatio = 0f;

            switch (ImageHorizontalAlignment)
            {
            case HorizontalAlignment.Left:
                targetHorizontalAlignmentRatio = 0f;
                break;

            case HorizontalAlignment.Center:
                targetHorizontalAlignmentRatio = 0.5f;
                break;

            case HorizontalAlignment.Right:
                targetHorizontalAlignmentRatio = 1f;

                break;

            case HorizontalAlignment.Stretch:
                targetHorizontalAlignmentRatio = 0f;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            switch (ImageVerticalAlignment)
            {
            case VerticalAlignment.Top:
                _foregroundBrush.VerticalAlignmentRatio = 0f;
                break;

            case VerticalAlignment.Center:
                _foregroundBrush.VerticalAlignmentRatio = 0.5f;
                break;

            case VerticalAlignment.Bottom:
                _foregroundBrush.VerticalAlignmentRatio = 1f;
                break;

            case VerticalAlignment.Stretch:
                _foregroundBrush.HorizontalAlignmentRatio = 0f;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // creating a margin around the image
            ForegroundVisual.Offset = new Vector3(leftOffset, topOffset, 0);

            var alignmentAnimation = _compositor.CreateScalarKeyFrameAnimation();

            alignmentAnimation.Target = nameof(CompositionSurfaceBrush.HorizontalAlignmentRatio);
            alignmentAnimation.InsertKeyFrame(0.0f, _lastHorizontalAlignmentRatio);
            alignmentAnimation.InsertKeyFrame(1.0f, targetHorizontalAlignmentRatio);
            alignmentAnimation.Duration = TimeSpan.FromMilliseconds(500);
            _foregroundBrush.StartAnimation(nameof(CompositionSurfaceBrush.HorizontalAlignmentRatio), alignmentAnimation);
            _lastHorizontalAlignmentRatio = targetHorizontalAlignmentRatio;
        }
        private void BackgroundImage_FirstOpened(object sender, RoutedEventArgs e)
        {
            // Image loaded, let's show the content
            this.Opacity = 1;

            // Show the content now that we should have something.
            ScalarKeyFrameAnimation fadeInAnimation = _compositor.CreateScalarKeyFrameAnimation();
            fadeInAnimation.InsertKeyFrame(0, 0);
            fadeInAnimation.InsertKeyFrame(1, 1);
            fadeInAnimation.Duration = TimeSpan.FromMilliseconds(1000);
            BackgroundImage.SpriteVisual.StartAnimation("Opacity", fadeInAnimation);
            ElementCompositionPreview.GetElementVisual(ImageList).StartAnimation("Opacity", fadeInAnimation);

            // Start a slow UV scale to create movement in the background image
            Vector2KeyFrameAnimation scaleAnimation = _compositor.CreateVector2KeyFrameAnimation();
            scaleAnimation.InsertKeyFrame(0, new Vector2(1.1f, 1.1f));
            scaleAnimation.InsertKeyFrame(.5f, new Vector2(2.0f, 2.0f));
            scaleAnimation.InsertKeyFrame(1, new Vector2(1.1f, 1.1f));
            scaleAnimation.Duration = TimeSpan.FromMilliseconds(40000);
            scaleAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

            CompositionDrawingSurface surface = (CompositionDrawingSurface)BackgroundImage.SurfaceBrush.Surface;
            BackgroundImage.SurfaceBrush.CenterPoint = new Vector2((float)surface.Size.Width, (float)surface.Size.Height) * .5f;
            BackgroundImage.SurfaceBrush.StartAnimation("Scale", scaleAnimation);

            // Start the animation of the cross-fade brush so they're in sync
            _previousSurfaceBrush = _compositor.CreateSurfaceBrush();
            _previousSurfaceBrush.StartAnimation("Scale", scaleAnimation);

            BackgroundImage.ImageOpened -= BackgroundImage_FirstOpened;
        }