public override void ReleaseResources() { if (_effectFactory != null) { _effectFactory.Dispose(); _effectFactory = null; } if (_enterAnimation != null) { _enterAnimation.Dispose(); _enterAnimation = null; } if (_exitAnimation != null) { _exitAnimation.Dispose(); _exitAnimation = null; } if (_transformExpression != null) { _transformExpression.Dispose(); _transformExpression = null; } if (_propertySet != null) { _propertySet.Dispose(); _propertySet = null; } }
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; }
public CompositionImage() { this.DefaultStyleKey = typeof(CompositionImage); this.Background = new SolidColorBrush(Colors.Transparent); this._stretchMode = CompositionStretch.Uniform; this.Loading += CompImage_Loading; this.Unloaded += CompImage_Unloaded; this.SizeChanged += CompImage_SizeChanged; _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // Intialize the statics as needed if (!_staticsInitialized) { _defaultPlaceholderBrush = _compositor.CreateColorBrush(Colors.DarkGray); TimeSpan duration = TimeSpan.FromMilliseconds(1000); _fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation(); _fadeOutAnimation.InsertKeyFrame(0, 1); _fadeOutAnimation.InsertKeyFrame(1, 0); _fadeOutAnimation.Duration = duration; _scaleAnimation = _compositor.CreateVector2KeyFrameAnimation(); _scaleAnimation.InsertKeyFrame(0, new Vector2(1.25f, 1.25f)); _scaleAnimation.InsertKeyFrame(1, new Vector2(1, 1)); _scaleAnimation.Duration = duration; _staticsInitialized = true; } _placeholderDelay = TimeSpan.FromMilliseconds(50); _surfaceBrush = _compositor.CreateSurfaceBrush(null); }
Vector2KeyFrameAnimation GetVector2KeyFrameAnimation(Vector2KeyFrameAnimation obj) { if (GetExisting(obj, out Vector2KeyFrameAnimation result)) { return(result); } result = CacheAndInitializeKeyframeAnimation(obj, _c.CreateVector2KeyFrameAnimation()); foreach (var kf in obj.KeyFrames) { switch (kf.Type) { case KeyFrameAnimation <Vector2> .KeyFrameType.Expression: var expressionKeyFrame = (KeyFrameAnimation <Vector2> .ExpressionKeyFrame)kf; result.InsertExpressionKeyFrame(kf.Progress, expressionKeyFrame.Expression, GetCompositionEasingFunction(kf.Easing)); break; case KeyFrameAnimation <Vector2> .KeyFrameType.Value: var valueKeyFrame = (KeyFrameAnimation <Vector2> .ValueKeyFrame)kf; result.InsertKeyFrame(kf.Progress, valueKeyFrame.Value, GetCompositionEasingFunction(kf.Easing)); break; default: throw new InvalidOperationException(); } } StartAnimationsAndFreeze(obj, result); return(result); }
// This animation has constant duration, speedy changes depending on the distance // between sourceElement and targetElement. public async Task StartAnimation2(FrameworkElement sourceElement, FrameworkElement targetElement) { Point point = sourceElement.TransformToVisual(_rootElement).TransformPoint(new Point(0, 0)); CompositionDrawingSurface surface = await CompositionDrawingSurfaceFacade1.GetCompositionDrawingSurface(sourceElement, _compositor); SpriteVisual spriteVisual = _compositor.CreateSpriteVisual(); spriteVisual.Brush = _compositor.CreateSurfaceBrush(surface); spriteVisual.Size = new Vector2((float)surface.Size.Width, (float)surface.Size.Height); spriteVisual.Offset = new Vector3((float)point.X, (float)point.Y, 0f); _containerVisual.Children.InsertAtBottom(spriteVisual); Vector3 targetOffset = GetTargetOffset(targetElement); Vector3KeyFrameAnimation offsetAnimation = _compositor.CreateVector3KeyFrameAnimation(); Vector2 targetSize = GetTargetSize(targetElement); Vector2KeyFrameAnimation sizeAnimation = _compositor.CreateVector2KeyFrameAnimation(); var newWidth = (float)(sourceElement.ActualWidth * 1.3); var newHeight = (float)(sourceElement.ActualHeight * 1.3); var newX = (float)(point.X - (newWidth - sourceElement.ActualWidth) / 2); var newY = (float)(point.Y - (newHeight - sourceElement.ActualHeight) / 2); double sizeDurationInMs = 250; double distance = Math.Sqrt(Math.Pow(targetOffset.X - newX, 2) + Math.Pow(targetOffset.Y - newY, 2)); double offsetDurationInMs = distance / 2; double animationDurationInMs = sizeDurationInMs + offsetDurationInMs; sizeAnimation.Duration = TimeSpan.FromMilliseconds(animationDurationInMs); offsetAnimation.Duration = TimeSpan.FromMilliseconds(animationDurationInMs); SetAnimationDefautls(offsetAnimation); SetAnimationDefautls(sizeAnimation); var normalizedProgressKey0 = (float)(sizeDurationInMs / animationDurationInMs); offsetAnimation.InsertKeyFrame(normalizedProgressKey0, new Vector3(newX, newY, 0f)); sizeAnimation.InsertKeyFrame(normalizedProgressKey0, new Vector2(newWidth, newHeight)); const float normalizedProgressKey1 = 1f; offsetAnimation.InsertKeyFrame(normalizedProgressKey1, targetOffset, _compositor.CreateLinearEasingFunction()); sizeAnimation.InsertKeyFrame(normalizedProgressKey1, targetSize, _compositor.CreateLinearEasingFunction()); CompositionScopedBatch myScopedBatch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation); var batchCompletitionAwaiter = new BatchCompletitionAwaiter(myScopedBatch); spriteVisual.StartAnimation("Offset", offsetAnimation); spriteVisual.StartAnimation("Size", sizeAnimation); myScopedBatch.End(); await batchCompletitionAwaiter.Completed(); myScopedBatch.Dispose(); spriteVisual.Dispose(); surface.Dispose(); offsetAnimation.Dispose(); sizeAnimation.Dispose(); }
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(); }
Vector2KeyFrameAnimation CreateAnimation() { Vector2KeyFrameAnimation animation = _compositor.CreateVector2KeyFrameAnimation(); animation.InsertExpressionKeyFrame(0f, "this.StartingValue"); animation.InsertExpressionKeyFrame(1f, "this.FinalValue"); animation.Target = "Size"; animation.Duration = TimeSpan.FromSeconds(1); return(animation); }
// Scale Vector2KeyFrameAnimation Vector2Animation() { var result = _vector2Animation = _c.CreateVector2KeyFrameAnimation(); result.Duration = TimeSpan.FromTicks(c_durationTicks); result.InsertKeyFrame(0, new Vector2(1, 1), StepThenHoldEasingFunction()); result.InsertKeyFrame(0.588235319F, new Vector2(1, 1), HoldThenStepEasingFunction()); result.InsertKeyFrame(0.686274529F, new Vector2(0.600000024F, 0.600000024F), CubicBezierEasingFunction_0()); result.InsertKeyFrame(0.882352948F, new Vector2(1, 1), CubicBezierEasingFunction_1()); return(result); }
// Scale Vector2KeyFrameAnimation ScaleVector2Animation() { var result = _scaleVector2Animation = _c.CreateVector2KeyFrameAnimation(); result.Duration = TimeSpan.FromTicks(c_durationTicks); result.InsertKeyFrame(0, new Vector2(0.899999976F, 0.899999976F), _stepThenHoldEasingFunction); result.InsertKeyFrame(0.583333313F, new Vector2(0.899999976F, 0.899999976F), _holdThenStepEasingFunction); result.InsertKeyFrame(0.866666675F, new Vector2(1.08000004F, 1.08000004F), CubicBezierEasingFunction_3()); result.InsertKeyFrame(0.983333349F, new Vector2(1, 1), CubicBezierEasingFunction_4()); return(result); }
XElement FromVector2KeyFrameAnimation(Vector2KeyFrameAnimation obj) { return(new XElement(GetCompositionObjectName(obj), GetContents())); IEnumerable <XObject> GetContents() { foreach (var item in GetCompositionObjectContents(obj)) { yield return(item); } } }
public void StartEntranceEffect() { ContainerVisual container = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(BasePage); Compositor compositor = container.Compositor; // 设置缩放和动画 const float ScaleFactor = 20f; TimeSpan duration = TimeSpan.FromMilliseconds(1200); LinearEasingFunction linearEase = compositor.CreateLinearEasingFunction(); CubicBezierEasingFunction easeInOut = compositor.CreateCubicBezierEasingFunction(new Vector2(.38f, 0f), new Vector2(.45f, 1f)); // 创建淡出动画 ScalarKeyFrameAnimation fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation(); fadeOutAnimation.InsertKeyFrame(1, 0); fadeOutAnimation.Duration = duration; // Grid的动画 Vector2KeyFrameAnimation scaleUpGridAnimation = compositor.CreateVector2KeyFrameAnimation(); scaleUpGridAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor)); scaleUpGridAnimation.InsertKeyFrame(1, new Vector2(1, 1)); scaleUpGridAnimation.Duration = duration; // 初始屏动画 Vector2KeyFrameAnimation scaleUpSplashAnimation = compositor.CreateVector2KeyFrameAnimation(); scaleUpSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1)); scaleUpSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor)); scaleUpSplashAnimation.Duration = duration; // 设置Grid的中心缩放视觉 Visual gridVisual = ElementCompositionPreview.GetElementVisual(UIToShow); gridVisual.Size = UIToShow.ActualSize; gridVisual.CenterPoint = new Vector3(gridVisual.Size.X, gridVisual.Size.Y, 0) * .5f; // 创建一个视觉组,当改组所有视觉执行完后不再显示 CompositionScopedBatch batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); container.StartAnimation("Opacity", fadeOutAnimation); container.StartAnimation("Scale.XY", scaleUpSplashAnimation); gridVisual.StartAnimation("Scale.XY", scaleUpGridAnimation); batch.Completed += (s, a) => { ElementCompositionPreview.SetElementChildVisual(BasePage, null); SurfaceLoader.Uninitialize(); AnimationCompleted?.Invoke(this, null); }; batch.End(); }
private void HideCustomSplashScreen() { ContainerVisual container = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(this); Compositor compositor = container.Compositor; // Setup some constants for scaling and animating const float ScaleFactor = 20f; TimeSpan duration = TimeSpan.FromMilliseconds(1200); LinearEasingFunction linearEase = compositor.CreateLinearEasingFunction(); CubicBezierEasingFunction easeInOut = compositor.CreateCubicBezierEasingFunction(new Vector2(.38f, 0f), new Vector2(.45f, 1f)); // Create the fade animation which will target the opacity of the outgoing splash screen ScalarKeyFrameAnimation fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation(); fadeOutAnimation.InsertKeyFrame(1, 0); fadeOutAnimation.Duration = duration; // Create the scale up animation for the grid Vector2KeyFrameAnimation scaleUpGridAnimation = compositor.CreateVector2KeyFrameAnimation(); scaleUpGridAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor)); scaleUpGridAnimation.InsertKeyFrame(1, new Vector2(1, 1)); scaleUpGridAnimation.Duration = duration; // Create the scale up animation for the Splash screen visuals Vector2KeyFrameAnimation scaleUpSplashAnimation = compositor.CreateVector2KeyFrameAnimation(); scaleUpSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1)); scaleUpSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor)); scaleUpSplashAnimation.Duration = duration; // Configure the grid visual to scale from the center Visual gridVisual = ElementCompositionPreview.GetElementVisual(MainFrame); gridVisual.Size = new Vector2((float)MainFrame.ActualWidth, (float)MainFrame.ActualHeight); gridVisual.CenterPoint = new Vector3(gridVisual.Size.X, gridVisual.Size.Y, 0) * .5f; // // Create a scoped batch for the animations. When the batch completes, we can dispose of the // splash screen visuals which will no longer be visible. // CompositionScopedBatch batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); container.StartAnimation("Opacity", fadeOutAnimation); container.StartAnimation("Scale.XY", scaleUpSplashAnimation); gridVisual.StartAnimation("Scale.XY", scaleUpGridAnimation); batch.Completed += Batch_Completed; batch.End(); }
/// <summary> /// Start animations and re-parent to destination UI Elmenent to finish the operations /// </summary> /// <param name="destinationElement">Destination UIElement where Visual should show up after page has loaded</param> /// <param name="containerVisual">ContainerVisual that contains Visual which needs to show in UIElement</param> /// <param name="newContainerVisual">ContainerVisual after visual is parented to UIElement</param> public static void InitiateContinuity(FrameworkElement destinationElement, ContainerVisual containerVisual, out ContainerVisual newContainerVisual) { if (null == containerVisual || null == destinationElement) { newContainerVisual = null; return; } //Get the frame of Window var rootFrame = AppShell.Current; Visual rootVisual = ElementCompositionPreview.GetElementVisual(AppShell.Current); Compositor compositor = rootVisual.Compositor; //Create Temporary Container. this will be added to final UIElement ContainerVisual tempContainer = compositor.CreateContainerVisual(); // Get Sprite Visual from incoming container var spriteHeroImage = containerVisual.Children.FirstOrDefault(); //Create animation scoped batch to track animation completion and to complete re-parenting CompositionScopedBatch scopeBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); //Get coordinates of UIElement in reference to root so that it can be used for animations final value var coordinate = destinationElement.TransformToVisual(rootFrame); var position = coordinate.TransformPoint(new Point(0, 0)); //Create offset animation to make visual move on screen Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation(); offsetAnimation.InsertKeyFrame(1f, new System.Numerics.Vector3((float)position.X, (float)position.Y, 0)); offsetAnimation.Duration = TimeSpan.FromMilliseconds(600); //Create size animation to change size of the visuals Vector2KeyFrameAnimation sizeAnimation = compositor.CreateVector2KeyFrameAnimation(); sizeAnimation.InsertKeyFrame(1f, new System.Numerics.Vector2((float)destinationElement.ActualWidth, (float)destinationElement.ActualHeight)); sizeAnimation.Duration = TimeSpan.FromMilliseconds(600); //Start Animations spriteHeroImage.StartAnimation("size", sizeAnimation); containerVisual.StartAnimation("offset", offsetAnimation); //Scoped batch completed event. scopeBatch.Completed += (o, e) => { //Re-parent SpriteVisual to temp container and add temp container to UIElement as animations are finished. spriteHeroImage.Offset = new System.Numerics.Vector3(0, 0, 2000); containerVisual.Children.Remove(spriteHeroImage); tempContainer.Children.InsertAtTop(spriteHeroImage); ElementCompositionPreview.SetElementChildVisual(destinationElement, tempContainer); containerVisual = null; }; newContainerVisual = tempContainer; scopeBatch.End(); }
// Scale Vector2KeyFrameAnimation ScaleVector2Animation_1() { // Frame 0. var result = _scaleVector2Animation_1 = CreateVector2KeyFrameAnimation(0F, new Vector2(1F, 1F), _holdThenStepEasingFunction); // Frame 8. result.InsertKeyFrame(0.266666681F, new Vector2(1.12F, 1.12F), _cubicBezierEasingFunction_0); // Frame 16. result.InsertKeyFrame(0.533333361F, new Vector2(0.949999988F, 0.949999988F), _cubicBezierEasingFunction_0); // Frame 24. result.InsertKeyFrame(0.800000012F, new Vector2(1F, 1F), _cubicBezierEasingFunction_0); return(result); }
public override async Task <CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .1f, Source2 = new Transform2DEffect { Name = "LightMapTransform", Source = new CompositionEffectSourceParameter("LightMap") }, Source2Amount = 0, MultiplyAmount = 1 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" }); // Create the image _lightMap = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Assets/NormalMapsAndMasks/pointmap.jpg")); // Create the animations CubicBezierEasingFunction easeIn = _compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 0.51f), new Vector2(1.0f, 0.51f)); _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.33f, 1.25f, easeIn); _enterAnimation.InsertKeyFrame(0.66f, 0.75f, easeIn); _enterAnimation.InsertKeyFrame(1.0f, 1.0f, easeIn); _enterAnimation.Duration = TimeSpan.FromMilliseconds(5000); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Forever; _exitAnimation = _compositor.CreateVector2KeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, new Vector2(0, 0)); _exitAnimation.Duration = TimeSpan.FromMilliseconds(750); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; var propsNode = ExpressionValues.Reference.CreatePropertySetReference("props"); var propsCenterPointOffset = propsNode.GetVector2Property("CenterPointOffset"); var propsTranslate = propsNode.GetVector2Property("Translate"); var propsScale = propsNode.GetScalarProperty("Scale"); _transformExpressionNode = EF.Matrix3x2(propsScale, 0, 0, propsScale, propsCenterPointOffset.X * (1 - propsScale) + (propsTranslate.X * propsCenterPointOffset.X * 2), propsCenterPointOffset.Y * (1 - propsScale) + (propsTranslate.Y * propsCenterPointOffset.Y * 2)); return(null); }
// Scale Vector2KeyFrameAnimation ScaleVector2Animation_1() { // Frame 0. var result = _scaleVector2Animation_1 = CreateVector2KeyFrameAnimation(0F, new Vector2(1F, 1F), StepThenHoldEasingFunction()); // Frame 3. result.InsertKeyFrame(0.100000001F, new Vector2(1F, 1F), _holdThenStepEasingFunction); // Frame 11. result.InsertKeyFrame(0.366666675F, new Vector2(1.12F, 1.12F), _cubicBezierEasingFunction_0); // Frame 19. result.InsertKeyFrame(0.633333325F, new Vector2(0.949999988F, 0.949999988F), _cubicBezierEasingFunction_0); // Frame 27. result.InsertKeyFrame(0.899999976F, new Vector2(1F, 1F), _cubicBezierEasingFunction_0); return(result); }
/// <summary> /// Creates a <see cref="ScalarKeyFrameAnimation"/> instance with the given parameters to on a target element, using an expression animation /// </summary> /// <param name="compositor">The current <see cref="Compositor"/> instance used to create the animation</param> /// <param name="from">The optional starting value for the animation</param> /// <param name="to">A string that indicates the final value for the animation</param> /// <param name="duration">The animation duration</param> /// <param name="delay">The optional initial delay for the animation</param> /// <param name="ease">The optional easing function for the animation</param> public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation( this Compositor compositor, Vector2? from, string to, TimeSpan duration, TimeSpan? delay, CompositionEasingFunction ease = null) { // Set duration and delay time Vector2KeyFrameAnimation ani = compositor.CreateVector2KeyFrameAnimation(); ani.Duration = duration; if (delay.HasValue) ani.DelayTime = delay.Value; // Insert "to" and "from" keyframes ani.InsertExpressionKeyFrame(1, to, ease ?? compositor.CreateLinearEasingFunction()); if (from.HasValue) ani.InsertKeyFrame(0, from.Value); return ani; }
public void StartEntranceEffect() { try { TimeSpan AnimationDuration = TimeSpan.FromMilliseconds(1000); ContainerVisual Container = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(BasePage); ScalarKeyFrameAnimation FadeOutAnimation = Container.Compositor.CreateScalarKeyFrameAnimation(); FadeOutAnimation.InsertKeyFrame(1, 0); FadeOutAnimation.Duration = AnimationDuration; Vector2KeyFrameAnimation ScaleUIAnimation = Container.Compositor.CreateVector2KeyFrameAnimation(); ScaleUIAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor)); ScaleUIAnimation.InsertKeyFrame(1, new Vector2(1, 1)); ScaleUIAnimation.Duration = AnimationDuration; Vector2KeyFrameAnimation ScaleSplashAnimation = Container.Compositor.CreateVector2KeyFrameAnimation(); ScaleSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1)); ScaleSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor)); ScaleSplashAnimation.Duration = AnimationDuration; Visual UIVisual = ElementCompositionPreview.GetElementVisual(UIToShow); UIVisual.Size = new Vector2((float)UIToShow.ActualWidth, (float)UIToShow.ActualHeight); UIVisual.CenterPoint = new Vector3(UIVisual.Size.X, UIVisual.Size.Y, 0) * 0.5f; CompositionScopedBatch BatchAnimation = Container.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation); Container.StartAnimation("Opacity", FadeOutAnimation); Container.StartAnimation("Scale.XY", ScaleSplashAnimation); UIVisual.StartAnimation("Scale.XY", ScaleUIAnimation); BatchAnimation.Completed += (s, a) => { ElementCompositionPreview.SetElementChildVisual(BasePage, null); SurfaceLoader.Uninitialize(); AnimationCompleted?.Invoke(this, null); }; BatchAnimation.End(); } catch (Exception ex) { Debug.WriteLine($"Error in StartEntranceEffect, message:{ex.Message}"); } }
public override async Task <CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .1f, Source2 = new Transform2DEffect { Name = "LightMapTransform", Source = new CompositionEffectSourceParameter("LightMap") }, Source2Amount = 0, MultiplyAmount = 1 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" }); // Create the image _lightMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PointerEnterEffects/pointmap.jpg")); // Create the animations CubicBezierEasingFunction easeIn = _compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 0.51f), new Vector2(1.0f, 0.51f)); _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.33f, 1.25f, easeIn); _enterAnimation.InsertKeyFrame(0.66f, 0.75f, easeIn); _enterAnimation.InsertKeyFrame(1.0f, 1.0f, easeIn); _enterAnimation.Duration = TimeSpan.FromMilliseconds(5000); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Forever; _exitAnimation = _compositor.CreateVector2KeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, new Vector2(0, 0)); _exitAnimation.Duration = TimeSpan.FromMilliseconds(750); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; _transformExpression = _compositor.CreateExpressionAnimation("Matrix3x2(props.Scale, 0, 0, props.Scale, props.CenterPointOffset.X * (1-props.Scale) + (props.Translate.X * props.CenterPointOffset.X * 2), props.CenterPointOffset.Y * (1-props.Scale) + (props.Translate.Y * props.CenterPointOffset.Y * 2))"); return(null); }
public CompositionImage() { this.DefaultStyleKey = typeof(CompositionImage); this.Background = new SolidColorBrush(Colors.Transparent); this._stretchMode = CompositionStretch.Uniform; this.Loading += CompImage_Loading; this.Unloaded += CompImage_Unloaded; this.SizeChanged += CompImage_SizeChanged; _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // Intialize the statics as needed if (!_staticsInitialized) { _defaultPlaceholderBrush = _compositor.CreateColorBrush(Colors.DarkGray); TimeSpan duration = TimeSpan.FromMilliseconds(1000); _fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation(); _fadeOutAnimation.InsertKeyFrame(0, 1); _fadeOutAnimation.InsertKeyFrame(1, 0); _fadeOutAnimation.Duration = duration; _scaleAnimation = _compositor.CreateVector2KeyFrameAnimation(); _scaleAnimation.InsertKeyFrame(0, new Vector2(1.25f, 1.25f)); _scaleAnimation.InsertKeyFrame(1, new Vector2(1, 1)); _scaleAnimation.Duration = duration; _staticsInitialized = true; } // Initialize the surface loader if needed if (!SurfaceLoader.IsInitialized) { SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor); } _placeholderDelay = TimeSpan.FromMilliseconds(50); _surfaceBrush = _compositor.CreateSurfaceBrush(null); }
public static Vector2KeyFrameAnimation SetDuration(this Vector2KeyFrameAnimation animation, TimeSpan duration) { animation.Duration = duration; return(animation); }
public static void EnableFluidVisibilityAnimation(this UIElement element, AnimationAxis?axis = null, float showFromOffset = 0.0f, float hideToOffset = 0.0f, Vector3?centerPoint = null, float showFromScale = 1.0f, float hideToScale = 1.0f, float showDuration = 800.0f, float hideDuration = 800.0f, int showDelay = 0, int hideDelay = 0, bool animateOpacity = true) { var elementVisual = element.Visual(); var compositor = elementVisual.Compositor; ElementCompositionPreview.SetIsTranslationEnabled(element, true); ScalarKeyFrameAnimation hideOpacityAnimation = null; ScalarKeyFrameAnimation showOpacityAnimation = null; ScalarKeyFrameAnimation hideOffsetAnimation = null; ScalarKeyFrameAnimation showOffsetAnimation = null; Vector2KeyFrameAnimation hideScaleAnimation = null; Vector2KeyFrameAnimation showeScaleAnimation = null; if (animateOpacity) { hideOpacityAnimation = compositor.CreateScalarKeyFrameAnimation(); hideOpacityAnimation.InsertKeyFrame(1.0f, 0.0f); hideOpacityAnimation.Duration = TimeSpan.FromMilliseconds(hideDuration); hideOpacityAnimation.DelayTime = TimeSpan.FromMilliseconds(hideDelay); hideOpacityAnimation.Target = "Opacity"; } if (!hideToOffset.Equals(0.0f)) { if (axis == null) { throw new NullReferenceException("Please specify AnimationAxis!"); } hideOffsetAnimation = compositor.CreateScalarKeyFrameAnimation(); hideOffsetAnimation.InsertKeyFrame(1.0f, hideToOffset); hideOffsetAnimation.Duration = TimeSpan.FromMilliseconds(hideDuration); hideOffsetAnimation.DelayTime = TimeSpan.FromMilliseconds(hideDelay); hideOffsetAnimation.Target = $"Translation.{axis}"; } if (centerPoint.HasValue) { elementVisual.CenterPoint = centerPoint.Value; } if (!hideToScale.Equals(1.0f)) { hideScaleAnimation = compositor.CreateVector2KeyFrameAnimation(); hideScaleAnimation.InsertKeyFrame(1.0f, new Vector2(hideToScale)); hideScaleAnimation.Duration = TimeSpan.FromMilliseconds(hideDuration); hideScaleAnimation.DelayTime = TimeSpan.FromMilliseconds(hideDelay); hideScaleAnimation.Target = "Scale.XY"; } var hideAnimationGroup = compositor.CreateAnimationGroup(); if (hideOpacityAnimation != null) { hideAnimationGroup.Add(hideOpacityAnimation); } if (hideOffsetAnimation != null) { hideAnimationGroup.Add(hideOffsetAnimation); } if (hideScaleAnimation != null) { hideAnimationGroup.Add(hideScaleAnimation); } ElementCompositionPreview.SetImplicitHideAnimation(element, hideAnimationGroup); if (animateOpacity) { elementVisual.Opacity = 0.0f; showOpacityAnimation = compositor.CreateScalarKeyFrameAnimation(); showOpacityAnimation.InsertKeyFrame(1.0f, 1.0f); showOpacityAnimation.Duration = TimeSpan.FromMilliseconds(showDuration); showOpacityAnimation.DelayTime = TimeSpan.FromMilliseconds(showDelay); showOpacityAnimation.Target = "Opacity"; } if (!showFromOffset.Equals(0.0f)) { if (axis == null) { throw new NullReferenceException("Please specify AnimationAxis!"); } showOffsetAnimation = compositor.CreateScalarKeyFrameAnimation(); showOffsetAnimation.InsertKeyFrame(0.0f, showFromOffset); showOffsetAnimation.InsertKeyFrame(1.0f, 0.0f); showOffsetAnimation.Duration = TimeSpan.FromMilliseconds(showDuration); showOffsetAnimation.DelayTime = TimeSpan.FromMilliseconds(showDelay); showOffsetAnimation.Target = $"Translation.{axis}"; } if (!showFromScale.Equals(1.0f)) { showeScaleAnimation = compositor.CreateVector2KeyFrameAnimation(); showeScaleAnimation.InsertKeyFrame(0.0f, new Vector2(showFromScale)); showeScaleAnimation.InsertKeyFrame(1.0f, Vector2.One); showeScaleAnimation.Duration = TimeSpan.FromMilliseconds(showDuration); showeScaleAnimation.DelayTime = TimeSpan.FromMilliseconds(showDelay); showeScaleAnimation.Target = "Scale.XY"; } var showAnimationGroup = compositor.CreateAnimationGroup(); if (showOpacityAnimation != null) { showAnimationGroup.Add(showOpacityAnimation); } if (showOffsetAnimation != null) { showAnimationGroup.Add(showOffsetAnimation); } if (showeScaleAnimation != null) { showAnimationGroup.Add(showeScaleAnimation); } ElementCompositionPreview.SetImplicitShowAnimation(element, showAnimationGroup); }
public override async Task<CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .1f, Source2 = new Transform2DEffect { Name = "LightMapTransform", Source = new CompositionEffectSourceParameter("LightMap") }, Source2Amount = 0, MultiplyAmount = 1 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" }); // Create the image _lightMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PointerEnterEffects/pointmap.jpg")); // Create the animations CubicBezierEasingFunction easeIn = _compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 0.51f), new Vector2(1.0f, 0.51f)); _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.33f, 1.25f, easeIn); _enterAnimation.InsertKeyFrame(0.66f, 0.75f, easeIn); _enterAnimation.InsertKeyFrame(1.0f, 1.0f, easeIn); _enterAnimation.Duration = TimeSpan.FromMilliseconds(5000); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Forever; _exitAnimation = _compositor.CreateVector2KeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, new Vector2(0, 0)); _exitAnimation.Duration = TimeSpan.FromMilliseconds(750); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; _transformExpression = _compositor.CreateExpressionAnimation("Matrix3x2(props.Scale, 0, 0, props.Scale, props.CenterPointOffset.X * (1-props.Scale) + (props.Translate.X * props.CenterPointOffset.X * 2), props.CenterPointOffset.Y * (1-props.Scale) + (props.Translate.Y * props.CenterPointOffset.Y * 2))"); return null; }
public void TraitsTest() { var animationEx = new Vector2KeyFrameAnimation(); Assert.AreEqual(Vector2Traits.Instance, animationEx.Traits); }
public void Start(UIElement newParent, CompositionImage targetImage, ScrollViewer scrollViewer, UIElement animationTarget) { Visual transitionVisual = ElementCompositionPreview.GetElementChildVisual(_parent); ElementCompositionPreview.SetElementChildVisual(_parent, null); // // We need to reparent the transition visual under the new parent. This is important to ensure // it's propertly clipped, etc. // GeneralTransform coordinate = newParent.TransformToVisual(_parent); Point position = coordinate.TransformPoint(new Point(0, 0)); Vector3 currentOffset = transitionVisual.Offset; currentOffset.X -= (float)position.X; currentOffset.Y -= (float)position.Y; transitionVisual.Offset = currentOffset; _parent = newParent; _targetImage = targetImage; // Move the transition visual to it's new parent ElementCompositionPreview.SetElementChildVisual(_parent, transitionVisual); // Hide the target Image now since the handoff visual is still transitioning targetImage.Opacity = 0f; // Load image if necessary _imageLoaded = targetImage.IsContentLoaded; if (!_imageLoaded) { targetImage.ImageOpened += CompositionImage_ImageOpened; } // // Create a scoped batch around the animations. When the batch completes, we know the animations // have finished and we can cleanup the transition related objects. // Compositor compositor = transitionVisual.Compositor; _scopeBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); // // Determine the offset between the parent and the target UIElement. This will be used to calculate the // target position we are animating to. // coordinate = targetImage.TransformToVisual(_parent); position = coordinate.TransformPoint(new Point(0, 0)); TimeSpan totalDuration = TimeSpan.FromMilliseconds(1000); Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation(); if (scrollViewer != null) { CompositionPropertySet scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); // Include the scroller offset as that is a factor position.X += scrollViewer.HorizontalOffset; position.Y += scrollViewer.VerticalOffset; // // Since the target position is relative to the target UIElement which can move, we need to construct // an expression to bind the target's position to the end position of our animation. // string expression = "Vector3(scrollingProperties.Translation.X, scrollingProperties.Translation.Y, 0) + itemOffset"; offsetAnimation.InsertExpressionKeyFrame(1f, expression); offsetAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); offsetAnimation.SetVector3Parameter("itemOffset", new Vector3((float)position.X, (float)position.Y, 0)); offsetAnimation.Duration = totalDuration; } else { offsetAnimation.InsertKeyFrame(1, new Vector3((float)position.X, (float)position.Y, 0)); offsetAnimation.Duration = totalDuration; } // Create size animation to change size of the visual Vector2KeyFrameAnimation sizeAnimation = compositor.CreateVector2KeyFrameAnimation(); sizeAnimation.InsertKeyFrame(1f, new Vector2((float)targetImage.ActualWidth, (float)targetImage.ActualHeight)); sizeAnimation.Duration = totalDuration; // Create the fade in animation for the other page content if (animationTarget != null) { Visual fadeVisual = ElementCompositionPreview.GetElementVisual(animationTarget); ScalarKeyFrameAnimation fadeIn = compositor.CreateScalarKeyFrameAnimation(); fadeIn.InsertKeyFrame(0f, 0.0f); fadeIn.InsertKeyFrame(1f, 1.0f); fadeIn.Duration = totalDuration; fadeVisual.StartAnimation("Opacity", fadeIn); } //Start Animations _sprite.StartAnimation("Size", sizeAnimation); _sprite.StartAnimation("Offset", offsetAnimation); //Scoped batch completed event _scopeBatch.Completed += ScopeBatch_Completed; _scopeBatch.End(); // Clear the flag _animationCompleted = false; }
internal Vector2EasyTransitionAnimationFluentContext([NotNull] StoryBoardFluentContext parentStoryBoard, [NotNull] Vector2KeyFrameAnimation animation, [NotNull] String targetProperty) : base(parentStoryBoard, animation, targetProperty) { }
private void InitializeComposition() { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; menuGridVisual = ElementCompositionPreview.GetElementVisual(MenuGrid); var scaleFactor = 5f; _scaleUpMenuAnimation = _compositor.CreateVector2KeyFrameAnimation(); _scaleUpMenuAnimation.InsertKeyFrame(1, new Vector2(scaleFactor, scaleFactor)); _scaleUpMenuAnimation.Duration = TimeSpan.FromSeconds(MenuGridScaleUpDuration); _scaleDownMenuAnimation = _compositor.CreateVector2KeyFrameAnimation(); _scaleDownMenuAnimation.InsertKeyFrame(1, Vector2.One); _scaleDownMenuAnimation.Duration = TimeSpan.FromSeconds(MenuGridScaleDownDuration); _scaleX = (float)(400.00 / (ItemSize / 1f)); _scaleY = (float)(700.0 / (ItemSize / 1f)); _scaleUpAnimation = _compositor.CreateVector2KeyFrameAnimation(); _scaleUpAnimation.InsertKeyFrame(1, new Vector2(_scaleX, _scaleY)); _scaleUpAnimation.Duration = TimeSpan.FromSeconds(MenuGridScaleUpDuration); _scaleDownAnimation = _compositor.CreateVector2KeyFrameAnimation(); _scaleDownAnimation.InsertKeyFrame(1, Vector2.One); _scaleDownAnimation.Duration = TimeSpan.FromSeconds(MenuGridScaleDownDuration); _scaleUpContentAnimation = _compositor.CreateVector2KeyFrameAnimation(); _scaleUpContentAnimation.InsertKeyFrame(1, Vector2.One); _scaleUpContentAnimation.Duration = TimeSpan.FromSeconds(MenuGridScaleUpDuration); _scaleDownContentAnimation = _compositor.CreateVector2KeyFrameAnimation(); _scaleDownContentAnimation.InsertKeyFrame(1, new Vector2(1 / _scaleX, 1 / _scaleY)); _scaleDownContentAnimation.Duration = TimeSpan.FromSeconds(MenuGridScaleDownDuration); _offsetUpAnimation = _compositor.CreateVector3KeyFrameAnimation(); _offsetUpAnimation.InsertKeyFrame(1, Vector3.Zero); _offsetUpAnimation.Duration = TimeSpan.FromSeconds(MenuGridScaleUpDuration); _offsetDownAnimation = _compositor.CreateVector3KeyFrameAnimation(); _offsetDownAnimation.Duration = TimeSpan.FromSeconds(MenuGridScaleDownDuration); _fadeInMenuAnimation = _compositor.CreateScalarKeyFrameAnimation(); _fadeInMenuAnimation.InsertKeyFrame(1f, 1); _fadeInMenuAnimation.Duration = TimeSpan.FromSeconds(FadeInMenuDuration); _fadeOutMenuAnimation = _compositor.CreateScalarKeyFrameAnimation(); _fadeOutMenuAnimation.InsertKeyFrame(0.5f, 0f); _fadeOutMenuAnimation.Duration = TimeSpan.FromSeconds(FadeOutMenuDuration); _fadeInAnimation = _compositor.CreateScalarKeyFrameAnimation(); _fadeInAnimation.InsertKeyFrame(0.5f, 1f, _compositor.CreateLinearEasingFunction()); _fadeInAnimation.Duration = TimeSpan.FromSeconds(FadeInDuration); _fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation(); _fadeOutAnimation.InsertKeyFrame(0.65f, 0); _fadeOutAnimation.Duration = TimeSpan.FromSeconds(FadeOutDuration); _fadeInContentAnimation = _compositor.CreateScalarKeyFrameAnimation(); _fadeInContentAnimation.InsertKeyFrame(0.5f, 1f, _compositor.CreateLinearEasingFunction()); _fadeInContentAnimation.Duration = TimeSpan.FromSeconds(FadeInDuration); _fadeOutContentAnimation = _compositor.CreateScalarKeyFrameAnimation(); _fadeOutContentAnimation.InsertKeyFrame(0.5f, 0); _fadeOutContentAnimation.Duration = TimeSpan.FromSeconds(FadeOutDuration); }
public static void StartScaleAnimation(SpriteVisual visual, Vector2KeyFrameAnimation animation) { visual.StartAnimation("Scale.xy", animation); }
public static CompositionAnimation GetAnimation <TKeyFrame>( CompositionObject target, string property, TimeSpan?delay, TimeSpan duration, RepeatOption repeat, ArraySegment <TKeyFrame> keyFrames) where TKeyFrame : struct, IKeyFrameInfo { KeyFrameAnimation animation; if (typeof(T) == typeof(bool)) { BooleanKeyFrameAnimation boolAnimation = target.Compositor.CreateBooleanKeyFrameAnimation(); foreach (var keyFrame in keyFrames) { if (keyFrame.TryInsertExpressionKeyFrame(boolAnimation, duration)) { continue; } boolAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <bool>()); } animation = boolAnimation; } else if (typeof(T) == typeof(float)) { ScalarKeyFrameAnimation scalarAnimation = target.Compositor.CreateScalarKeyFrameAnimation(); foreach (var keyFrame in keyFrames) { if (keyFrame.TryInsertExpressionKeyFrame(scalarAnimation, duration)) { continue; } CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode); if (easingFunction is null) { scalarAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <float>()); } else { scalarAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <float>(), easingFunction); } } animation = scalarAnimation; } else if (typeof(T) == typeof(double)) { ScalarKeyFrameAnimation scalarAnimation = target.Compositor.CreateScalarKeyFrameAnimation(); foreach (var keyFrame in keyFrames) { if (keyFrame.TryInsertExpressionKeyFrame(scalarAnimation, duration)) { continue; } CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode); if (easingFunction is null) { scalarAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), (float)keyFrame.GetValueAs <double>()); } else { scalarAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), (float)keyFrame.GetValueAs <double>(), easingFunction); } } animation = scalarAnimation; } else if (typeof(T) == typeof(Vector2)) { Vector2KeyFrameAnimation vector2Animation = target.Compositor.CreateVector2KeyFrameAnimation(); foreach (var keyFrame in keyFrames) { if (keyFrame.TryInsertExpressionKeyFrame(vector2Animation, duration)) { continue; } CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode); if (easingFunction is null) { vector2Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector2>()); } else { vector2Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector2>(), easingFunction); } } animation = vector2Animation; } else if (typeof(T) == typeof(Vector3)) { Vector3KeyFrameAnimation vector3Animation = target.Compositor.CreateVector3KeyFrameAnimation(); foreach (var keyFrame in keyFrames) { if (keyFrame.TryInsertExpressionKeyFrame(vector3Animation, duration)) { continue; } CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode); if (easingFunction is null) { vector3Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector3>()); } else { vector3Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector3>(), easingFunction); } } animation = vector3Animation; } else if (typeof(T) == typeof(Vector4)) { Vector4KeyFrameAnimation vector4Animation = target.Compositor.CreateVector4KeyFrameAnimation(); foreach (var keyFrame in keyFrames) { if (keyFrame.TryInsertExpressionKeyFrame(vector4Animation, duration)) { continue; } CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode); if (easingFunction is null) { vector4Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector4>()); } else { vector4Animation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Vector4>(), easingFunction); } } animation = vector4Animation; } else if (typeof(T) == typeof(Color)) { ColorKeyFrameAnimation colorAnimation = target.Compositor.CreateColorKeyFrameAnimation(); foreach (var keyFrame in keyFrames) { if (keyFrame.TryInsertExpressionKeyFrame(colorAnimation, duration)) { continue; } CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode); if (easingFunction is null) { colorAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Color>()); } else { colorAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Color>(), easingFunction); } } animation = colorAnimation; } else if (typeof(T) == typeof(Quaternion)) { QuaternionKeyFrameAnimation quaternionAnimation = target.Compositor.CreateQuaternionKeyFrameAnimation(); foreach (var keyFrame in keyFrames) { if (keyFrame.TryInsertExpressionKeyFrame(quaternionAnimation, duration)) { continue; } CompositionEasingFunction?easingFunction = target.Compositor.TryCreateEasingFunction(keyFrame.EasingType, keyFrame.EasingMode); if (easingFunction is null) { quaternionAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Quaternion>()); } else { quaternionAnimation.InsertKeyFrame(keyFrame.GetNormalizedProgress(duration), keyFrame.GetValueAs <Quaternion>(), easingFunction); } } animation = quaternionAnimation; } else { throw new InvalidOperationException("Invalid animation type"); } animation.Duration = duration; if (delay.HasValue) { animation.DelayTime = delay !.Value; } animation.Target = property; (animation.IterationBehavior, animation.IterationCount) = repeat.ToBehaviorAndCount(); return(animation); }
public static Vector2KeyFrameAnimation AddKeyFrame(this Vector2KeyFrameAnimation animation, float normalizedProgressKey, Vector2 value, CompositionEasingFunction ease = null) { animation.InsertKeyFrame(normalizedProgressKey, value, ease); return animation; }
public static Vector2KeyFrameAnimation AddKeyFrame(this Vector2KeyFrameAnimation animation, float normalizedProgressKey, Vector2 value, KeySpline ease) { animation.InsertKeyFrame(normalizedProgressKey, value, animation.Compositor.CreateCubicBezierEasingFunction(ease)); return animation; }
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(); }