public void StartAnimation(bool update = false) { if (update || expression == null || visual == null) { visual = ElementCompositionPreview.GetElementVisual(VisualElement); //if (0 <= VisualElement.Margin.Top && VisualElement.Margin.Top <= ScrollViewer.ActualHeight) //{ // min = (float)-VisualElement.Margin.Top; // max = (float)ScrollViewer.ActualHeight + min; //} //else if (VisualElement.Margin.Top < 0) //{ //} //else if (VisualElement.Margin.Top > ScrollViewer.ActualHeight) //{ //} if (scrollViewerManipProps == null) { scrollViewerManipProps = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(ScrollViewer); } Compositor compositor = scrollViewerManipProps.Compositor; // Create the expression //expression = compositor.CreateExpressionAnimation("min(max((ScrollViewerManipProps.Translation.Y + VerticalOffset), MinValue), MaxValue)"); ////Expression = compositor.CreateExpressionAnimation("ScrollViewerManipProps.Translation.Y +VerticalOffset"); //expression.SetScalarParameter("MinValue", min); //expression.SetScalarParameter("MaxValue", max); //expression.SetScalarParameter("VerticalOffset", (float)ScrollViewer.VerticalOffset); expression = compositor.CreateExpressionAnimation("ScrollViewerManipProps.Translation.Y + VerticalOffset"); ////Expression = compositor.CreateExpressionAnimation("ScrollViewerManipProps.Translation.Y +VerticalOffset"); //expression.SetScalarParameter("MinValue", min); //expression.SetScalarParameter("MaxValue", max); VerticalOffset = ScrollViewer.VerticalOffset; expression.SetScalarParameter("VerticalOffset", (float)ScrollViewer.VerticalOffset); // set "dynamic" reference parameter that will be used to evaluate the current position of the scrollbar every frame expression.SetReferenceParameter("ScrollViewerManipProps", scrollViewerManipProps); } visual.StartAnimation("Offset.Y", expression); IsActive = true; //Windows.UI.Xaml.Media.CompositionTarget.Rendering -= OnCompositionTargetRendering; //Windows.UI.Xaml.Media.CompositionTarget.Rendering += OnCompositionTargetRendering; }
// Apply two sourcemodifiers to the input source: One to provide resistance, one to stop motion public void SetupPullToRefreshBehavior( float pullToRefreshDistance) { // // Modifier 1: Cut DeltaY to a third as long as the InteractionTracker is not yet at the // pullRefreshDistance. // CompositionConditionalValue resistanceModifier = CompositionConditionalValue.Create(_compositor); ExpressionAnimation resistanceCondition = _compositor.CreateExpressionAnimation( $"-tracker.Position.Y < {pullToRefreshDistance}"); resistanceCondition.SetReferenceParameter("tracker", _tracker); ExpressionAnimation resistanceAlternateValue = _compositor.CreateExpressionAnimation( "source.DeltaPosition.Y / 3"); resistanceAlternateValue.SetReferenceParameter("source", _interactionSource); resistanceModifier.Condition = resistanceCondition; resistanceModifier.Value = resistanceAlternateValue; // // Modifier 2: Zero the delta if we are past the pullRefreshDistance. (So we can't pan // past the pullRefreshDistance) // CompositionConditionalValue stoppingModifier = CompositionConditionalValue.Create(_compositor); ExpressionAnimation stoppingCondition = _compositor.CreateExpressionAnimation( $"-tracker.Position.Y >= {pullToRefreshDistance}"); stoppingCondition.SetReferenceParameter("tracker", _tracker); ExpressionAnimation stoppingAlternateValue = _compositor.CreateExpressionAnimation("0"); stoppingModifier.Condition = stoppingCondition; stoppingModifier.Value = stoppingAlternateValue; // // Apply the modifiers to the source as a list // List <CompositionConditionalValue> modifierList = new List <CompositionConditionalValue>() { resistanceModifier, stoppingModifier }; _interactionSource.ConfigureDeltaPositionYModifiers(modifierList); }
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); }
//you must dispose it at page back. public void Dispose() { if (_offsetXAnimation != null) { _offsetXAnimation.Dispose(); _offsetXAnimation = null; } if (_scrollerViewerManipulation != null) { _scrollerViewerManipulation.Dispose(); _scrollerViewerManipulation = null; } }
private void Page_Unloaded(object sender, RoutedEventArgs e) { if (_parallaxExpression != null) { _parallaxExpression.Dispose(); _parallaxExpression = null; } if (_scrollProperties != null) { _scrollProperties.Dispose(); _scrollProperties = null; } }
private void NewFlexGrid_Unloaded(object sender, RoutedEventArgs e) { if (_offsetXAnimation != null) { _offsetXAnimation.Dispose(); _offsetXAnimation = null; } //if (_scrollerViewerManipulation != null) //{ // _scrollerViewerManipulation.Dispose(); // _scrollerViewerManipulation = null; //} }
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; } }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { CompositionPropertySet scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(myScroller); Compositor compositor = scrollerViewerManipulation.Compositor; ExpressionAnimation expression = compositor.CreateExpressionAnimation("ScrollManipululation.Translation.Y * ParallaxMultiplier"); expression.SetScalarParameter("ParallaxMultiplier", 0.3f); expression.SetReferenceParameter("ScrollManipululation", scrollerViewerManipulation); Visual textVisual = ElementCompositionPreview.GetElementVisual(background); textVisual.StartAnimation("Offset.Y", expression); }
private void StartAnimation(UIElement element) { if (element != null) { if (exp == null) { var bottomExp = "(scroll.Translation.Y < prop.viewportheight - this.target.Size.Y ? (prop.viewportheight - this.target.Size.Y - scroll.Translation.Y) : 0)"; var topExp = $"scroll.Translation.Y > 0 ? (-scroll.Translation.Y) : {bottomExp}"; exp = Window.Current.Compositor.CreateExpressionAnimation($"{topExp}"); exp.SetReferenceParameter("prop", propSet); exp.SetReferenceParameter("scroll", scrollPropSet); } ElementCompositionPreview.GetElementVisual(element).StartAnimation("Offset.Y", exp); } }
private void NewFlexGrid_Unloaded(object sender, RoutedEventArgs e) { if (_offsetXAnimation != null) { _offsetXAnimation.Dispose(); _offsetXAnimation = null; } //don't dispose at this moment,some page NavigationCacheMode is required //you must dispose it at page back. //if (_scrollerViewerManipulation != null) //{ // _scrollerViewerManipulation.Dispose(); // _scrollerViewerManipulation = null; //} }
private void CreateVisual() { visual = ElementCompositionPreview.GetElementVisual(currentTopGroupHeader); var scrollViewerManipProps = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); Compositor compositor = scrollViewerManipProps.Compositor; expression = compositor.CreateExpressionAnimation("max(0,ScrollViewerManipProps.Translation.Y)"); // set "dynamic" reference parameter that will be used to evaluate the current position of the scrollbar every frame expression.SetReferenceParameter("ScrollViewerManipProps", scrollViewerManipProps); visual.StartAnimation("Offset.Y", expression); //Windows.UI.Xaml.Media.CompositionTarget.Rendering += OnCompositionTargetRendering; }
private void GridView_Loaded(object sender, RoutedEventArgs e) { var scroll = List.Descendants <ScrollViewer>().FirstOrDefault() as ScrollViewer; if (scroll != null) { _scrollingHost = scroll; _scrollingHost.ChangeView(null, 0, null, true); scroll.ViewChanged += Scroll_ViewChanged; Scroll_ViewChanged(scroll, null); var brush = App.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"] as SolidColorBrush; var props = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroll); if (_backgroundVisual == null) { _backgroundVisual = ElementCompositionPreview.GetElementVisual(BackgroundPanel).Compositor.CreateSpriteVisual(); ElementCompositionPreview.SetElementChildVisual(BackgroundPanel, _backgroundVisual); } _backgroundVisual.Brush = _backgroundVisual.Compositor.CreateColorBrush(brush.Color); _backgroundVisual.Size = new System.Numerics.Vector2((float)BackgroundPanel.ActualWidth, (float)BackgroundPanel.ActualHeight); _backgroundVisual.Clip = _backgroundVisual.Compositor.CreateInsetClip(); _expression = _expression ?? _backgroundVisual.Compositor.CreateExpressionAnimation("Max(Maximum, Scrolling.Translation.Y)"); _expression.SetReferenceParameter("Scrolling", props); _expression.SetScalarParameter("Maximum", -(float)BackgroundPanel.Margin.Top + 1); _backgroundVisual.StopAnimation("Offset.Y"); _backgroundVisual.StartAnimation("Offset.Y", _expression); _expressionClip = _expressionClip ?? _backgroundVisual.Compositor.CreateExpressionAnimation("Min(0, Maximum - Scrolling.Translation.Y)"); _expressionClip.SetReferenceParameter("Scrolling", props); _expressionClip.SetScalarParameter("Maximum", -(float)BackgroundPanel.Margin.Top + 1); _backgroundVisual.Clip.StopAnimation("Offset.Y"); _backgroundVisual.Clip.StartAnimation("Offset.Y", _expressionClip); } var panel = List.ItemsPanelRoot as ItemsWrapGrid; if (panel != null) { panel.SizeChanged += (s, args) => { Scroll_ViewChanged(scroll, null); }; } }
internal void StartAnimation(ScrollViewer sv) { _sv = sv; if (_frozenContent == null || _sv == null || _pressedHider == null || _frozenContentVisual != null) { return; } _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(sv); _compositor = _scrollerViewerManipulation.Compositor; _offsetAnimation = _compositor.CreateExpressionAnimation("-min(0,ScrollManipulation.Translation.X)"); _offsetAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _frozenContentVisual = ElementCompositionPreview.GetElementVisual(_frozenContent); _pressedHiderVisual = ElementCompositionPreview.GetElementVisual(_pressedHider); _frozenContentVisual.StartAnimation("Offset.X", _offsetAnimation); _pressedHiderVisual.StartAnimation("Offset.X", _offsetAnimation); }
private void PrepareCompositionAnimation() { if (_scrollViewer != null) { if (_scrollerViewerManipulation == null) { _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(_scrollViewer); } if (_offsetXAnimation == null) { _offsetXAnimation = _scrollerViewerManipulation.Compositor.CreateExpressionAnimation("-min(0,ScrollManipulation.Translation.X)"); _offsetXAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _columnsHeader._offsetXAnimation = _offsetXAnimation; _frozenRows._offsetXAnimation = _offsetXAnimation; } } }
private static void StartSpy <T>( T source, Dictionary <T, KeyValuePair <CompositionPropertySet, Dictionary <string, ExpressionAnimation> > > dictionary, Compositor compositor, ref string propertyName, ref string propertySetPropertyName, out CompositionPropertySet propertySet, out ExpressionAnimation expressionAnimation) { propertySet = null; expressionAnimation = null; if (source == null) { throw new ArgumentException(); } KeyValuePair <CompositionPropertySet, Dictionary <string, ExpressionAnimation> > propertySetExpressionsPair; Dictionary <string, ExpressionAnimation> expressionAnimations = null; if (!dictionary.ContainsKey(source)) { propertySet = compositor.CreatePropertySet(); expressionAnimations = new Dictionary <string, ExpressionAnimation>(); propertySetExpressionsPair = new KeyValuePair <CompositionPropertySet, Dictionary <string, ExpressionAnimation> >(propertySet, expressionAnimations); dictionary.Add(source, propertySetExpressionsPair); } else { propertySetExpressionsPair = dictionary[source]; propertySet = propertySetExpressionsPair.Key; expressionAnimations = propertySetExpressionsPair.Value; } if (!expressionAnimations.ContainsKey(propertySetPropertyName)) { expressionAnimation = compositor.CreateExpressionAnimation(c_source + "." + propertyName); expressionAnimations.Add(propertySetPropertyName, expressionAnimation); } else { expressionAnimation = expressionAnimations[propertySetPropertyName]; } }
private static void OnNormalizedCenterPointChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is FrameworkElement element && !DesignTimeHelpers.IsRunningInLegacyDesignerMode && e.NewValue is string newValue) { Vector2 center = newValue.ToVector2(); Visual visual = element.GetVisual(); const string expression = "Vector2(this.Target.Size.X * X, this.Target.Size.Y * Y)"; ExpressionAnimation animation = visual.Compositor.CreateExpressionAnimation(expression); animation.SetScalarParameter("X", center.X); animation.SetScalarParameter("Y", center.Y); visual.StopAnimation("CenterPoint.XY"); visual.StartAnimation("CenterPoint.XY", animation); } }
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); }
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); }
public static ExpressionAnimation StartExpressionAnimation( this ScrollViewer scrollViewer, UIElement target, Axis sourceAxis, Axis targetAxis) { CompositionPropertySet scrollSet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); ExpressionAnimation animation = scrollSet.Compositor.CreateExpressionAnimation($"{nameof(scrollViewer)}.{nameof(UIElement.Translation)}.{sourceAxis}"); animation.SetReferenceParameter(nameof(scrollViewer), scrollSet); Visual visual = ElementCompositionPreview.GetElementVisual(target); visual.StartAnimation($"{nameof(Visual.Offset)}.{targetAxis}", animation); return(animation); }
public void ConfigureInteraction() { this.interactionSource = VisualInteractionSource.Create(myDrawingVisual); this.interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; this.interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; this.tracker = InteractionTracker.CreateWithOwner(this.compositor, this); this.tracker.InteractionSources.Add(this.interactionSource); this.moveSurfaceExpressionAnimation = this.compositor.CreateExpressionAnimation("-tracker.Position.X"); this.moveSurfaceExpressionAnimation.SetReferenceParameter("tracker", this.tracker); this.moveSurfaceUpDownExpressionAnimation = this.compositor.CreateExpressionAnimation("-tracker.Position.Y"); this.moveSurfaceUpDownExpressionAnimation.SetReferenceParameter("tracker", this.tracker); this.tracker.MinPosition = new System.Numerics.Vector3(0, 0, 0); //TODO: use same consts as tilemanager object this.tracker.MaxPosition = new System.Numerics.Vector3(TILESIZE * 10000, TILESIZE * 10000, 0); }
/// <summary> /// Releases all resources used by this ExpressionNode. /// </summary> public void Dispose() { _objRefList = null; _compObjToParamNameMap = null; _constParamMap = null; Subchannels = null; PropertyName = null; NodeType = ExpressionNodeType.Count; // Note: we don't recursively dispose all child nodes, as those nodes could be in use by a different Expression Children = null; if (ExpressionAnimation != null) { ExpressionAnimation.Dispose(); ExpressionAnimation = null; } }
private void buttonComposition_Click(object sender, RoutedEventArgs e) { this.visualRectangle.StartAnimation("Offset", this.vector3KeyFrameAnimation); //this.visualRectangle.StartAnimation("Offset.X", this.scalarKeyFrameAnimationRefreshEnd); //this.scalarKeyFrameAnimationRefreshEnd.InsertKeyFrame(0.1f, 30f); this.visualRectangle.StartAnimation("RotationAngleInDegrees", this.scalarKeyFrameAnimationRefreshEnd); #region Expression //Animation with expression ExpressionAnimation expressionAnimation = this.compositor.CreateExpressionAnimation(); expressionAnimation.Expression = "visualRectangle.Offset.X > 0 ? visualRectangle.Offset.X * Multiplier : 0.0f"; expressionAnimation.SetScalarParameter("Multiplier", 2.0f); expressionAnimation.SetReferenceParameter("visualRectangle", this.visualRectangle); this.visualRectangleExpression.StartAnimation("Offset.X", expressionAnimation); #endregion Expresion }
public override async Task <CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .25f, 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:///Samples/SDK 10586/PointerEnterEffects/conemap.jpg")); // Create the animations float sweep = (float)Math.PI / 10f; float fullCircle = (float)Math.PI * -2f; _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.1f, fullCircle); _enterAnimation.InsertKeyFrame(0.4f, fullCircle + sweep); _enterAnimation.InsertKeyFrame(0.8f, fullCircle - sweep); _enterAnimation.InsertKeyFrame(1.0f, fullCircle); _enterAnimation.Duration = TimeSpan.FromMilliseconds(4500); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Count; _enterAnimation.IterationCount = 1; _exitAnimation = _compositor.CreateScalarKeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, 0f); _exitAnimation.Duration = TimeSpan.FromMilliseconds(1000); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; _transformExpression = _compositor.CreateExpressionAnimation("Matrix3x2.CreateFromTranslation(-props.CenterPointOffset) * Matrix3x2(cos(props.Rotation) * props.Scale, sin(props.Rotation), -sin(props.Rotation), cos(props.Rotation) * props.Scale, 0, 0) * Matrix3x2.CreateFromTranslation(props.CenterPointOffset + props.Translate)"); return(null); }
private void Page_Loaded(object sender, RoutedEventArgs e) { Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // Get scrollviewer ScrollViewer myScrollViewer = ThumbnailList.GetFirstDescendantOfType <ScrollViewer>(); _scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(myScrollViewer); // Setup the expression _parallaxExpression = compositor.CreateExpressionAnimation(); _parallaxExpression.SetScalarParameter("StartOffset", 0.0f); _parallaxExpression.SetScalarParameter("ParallaxValue", 0.5f); _parallaxExpression.SetScalarParameter("ItemHeight", 0.0f); _parallaxExpression.SetReferenceParameter("ScrollManipulation", _scrollProperties); _parallaxExpression.Expression = "(ScrollManipulation.Translation.Y + StartOffset - (0.5 * ItemHeight)) * ParallaxValue - (ScrollManipulation.Translation.Y + StartOffset - (0.5 * ItemHeight))"; ThumbnailList.ItemsSource = Model.Items; }
private void ScrollViewer_Loaded(object sender, RoutedEventArgs e) { var border = (Border)VisualTreeHelper.GetChild(_scrollViewer, 0); _scrollViewerBorder = border; _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(_scrollViewer); _compositor = _scrollerViewerManipulation.Compositor; double ratio = 1.0; _header.Measure(new Size(this.ActualWidth, this.ActualHeight)); var headerHeight = _header.DesiredSize.Height; if (headerHeight == 0) { headerHeight = 50; } if (RefreshThreshold == 0.0) { RefreshThreshold = headerHeight; } ratio = RefreshThreshold / headerHeight; _offsetAnimation = _compositor.CreateExpressionAnimation("(min(max(0, ScrollManipulation.Translation.Y * ratio) / Divider, 1)) * MaxOffsetY"); _offsetAnimation.SetScalarParameter("Divider", (float)RefreshThreshold); _offsetAnimation.SetScalarParameter("MaxOffsetY", (float)RefreshThreshold * 5 / 4); _offsetAnimation.SetScalarParameter("ratio", (float)ratio); _offsetAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _opacityAnimation = _compositor.CreateExpressionAnimation("min((max(0, ScrollManipulation.Translation.Y * ratio) / Divider), 1)"); _opacityAnimation.SetScalarParameter("Divider", (float)headerHeight); _opacityAnimation.SetScalarParameter("ratio", (float)1); _opacityAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _headerVisual = ElementCompositionPreview.GetElementVisual(_header); _contentVisual = ElementCompositionPreview.GetElementVisual(_scrollViewerBorder); _headerVisual.StartAnimation("Offset.Y", _offsetAnimation); _headerVisual.StartAnimation("Opacity", _opacityAnimation); _contentVisual.StartAnimation("Offset.Y", _offsetAnimation); }
XElement FromExpressionAnimation(ExpressionAnimation obj, string name = null) { return(new XElement(name ?? GetCompositionObjectName(obj), GetContents())); IEnumerable <XObject> GetContents() { foreach (var item in GetCompositionObjectContents(obj)) { yield return(item); } if (obj.Target != null && obj.Target != name) { yield return(new XAttribute("Target", obj.Target)); } yield return(new XText(obj.Expression.ToString())); } }
public void StartAnimation(bool update = false) { if (update || expression == null || visual == null) { visual = ElementCompositionPreview.GetElementVisual(VisualElement); if (0 <= VisualElement.Margin.Top && VisualElement.Margin.Top <= ScrollViewer.ActualHeight) { min = (float)-VisualElement.Margin.Top; max = (float)ScrollViewer.ActualHeight + min; } else if (VisualElement.Margin.Top < 0) { } else if (VisualElement.Margin.Top > ScrollViewer.ActualHeight) { } if (scrollViewerManipProps == null) { scrollViewerManipProps = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(ScrollViewer); } Compositor compositor = scrollViewerManipProps.Compositor; // Create the expression expression = compositor.CreateExpressionAnimation("min(max((ScrollViewerManipProps.Translation.Y + VerticalOffset), MinValue), MaxValue)"); //Expression = compositor.CreateExpressionAnimation("ScrollViewerManipProps.Translation.Y +VerticalOffset"); expression.SetScalarParameter("MinValue", min); expression.SetScalarParameter("MaxValue", max); expression.SetScalarParameter("VerticalOffset", (float)ScrollViewer.VerticalOffset); // set "dynamic" reference parameter that will be used to evaluate the current position of the scrollbar every frame expression.SetReferenceParameter("ScrollViewerManipProps", scrollViewerManipProps); } visual.StartAnimation("Offset.Y", expression); IsActive = true; //Windows.UI.Xaml.Media.CompositionTarget.Rendering -= OnCompositionTargetRendering; Windows.UI.Xaml.Media.CompositionTarget.Rendering += OnCompositionTargetRendering; }
//warning internal void StopAnimation() { if (_frozenContentVisual != null) { _frozenContentVisual.StopAnimation("Offset.X"); _frozenContentVisual.Dispose(); _frozenContentVisual = null; _pressedHiderVisual.StopAnimation("Offset.X"); _pressedHiderVisual.Dispose(); _pressedHiderVisual = null; _compositor.Dispose(); _compositor = null; _offsetAnimation.Dispose(); _offsetAnimation = null; _scrollerViewerManipulation.Dispose(); _scrollerViewerManipulation = null; } }
protected override void OnConnected(UIElement targetElement) { Compositor compositor = Window.Current.Compositor; // Create SpotLight and set its properties SpotLight spotLight = compositor.CreateSpotLight(); spotLight.InnerConeAngleInDegrees = 50f; spotLight.InnerConeColor = Colors.FloralWhite; spotLight.OuterConeAngleInDegrees = 0f; spotLight.ConstantAttenuation = 1f; spotLight.LinearAttenuation = 0.253f; spotLight.QuadraticAttenuation = 0.58f; // Associate CompositionLight with XamlLight CompositionLight = spotLight; // Define resting position Animation Vector3 restingPosition = new Vector3(200, 200, 400); CubicBezierEasingFunction cbEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.3f, 0.7f), new Vector2(0.9f, 0.5f)); _offsetAnimation = compositor.CreateVector3KeyFrameAnimation(); _offsetAnimation.InsertKeyFrame(1, restingPosition, cbEasing); _offsetAnimation.Duration = TimeSpan.FromSeconds(0.5f); spotLight.Offset = restingPosition; // Define expression animation that relates light's offset to pointer position CompositionPropertySet hoverPosition = ElementCompositionPreview.GetPointerPositionPropertySet(targetElement); _lightPositionExpression = compositor.CreateExpressionAnimation("Vector3(hover.Position.X, hover.Position.Y, height)"); _lightPositionExpression.SetReferenceParameter("hover", hoverPosition); _lightPositionExpression.SetScalarParameter("height", 15.0f); // Configure pointer entered/ exited events targetElement.PointerMoved += TargetElement_PointerMoved; targetElement.PointerExited += TargetElement_PointerExited; // Add UIElement to the Light's Targets HoverLight.AddTargetElement(GetId(), targetElement); }
private void SetupModal() { // Fix display orientation DisplayInformation.AutoRotationPreferences = DisplayInformation.GetForCurrentView().CurrentOrientation; // Set up visual interaction source _root = ElementCompositionPreview.GetElementVisual(ITRoot); _compositor = _root.Compositor; _is = VisualInteractionSource.Create(_root); _is.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; // Set up interaction tracker owner _itowner = new InteractionTrackerOwner(); _itowner.StateOrValuesChanged += (r, s) => { DebugText1.Text = $"State: {s.Item1}\nPos: {s.Item2.Y}"; ChangeScroll(s); oldPosition = s.Item2; }; // Set up interaction tracker _tracker = InteractionTracker.CreateWithOwner(_compositor, _itowner); _tracker.InteractionSources.Add(_is); UpdateInteractionTrackerValues(); var exp = _compositor.CreateExpressionAnimation("-tracker.Position"); exp.SetReferenceParameter("tracker", _tracker); var bv = ElementCompositionPreview.GetElementVisual(ModalContent); bv.StartAnimation("Offset", exp); ExpressionAnimation _titleAnimation = _compositor.CreateExpressionAnimation("Clamp(tracker.Position.Y, 0, tracker.MaxPosition.Y)"); _titleAnimation.SetReferenceParameter("tracker", _tracker); var tv = ElementCompositionPreview.GetElementVisual(TitleBar); tv.StartAnimation("Offset.Y", _titleAnimation); }
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:///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 MainPage() { this.InitializeComponent(); ContactsCVS.Source = _list; this.Loaded += (s, e) => { _scrollViewer = ListView.GetScrollViewer(); _scrollViewer.DirectManipulationStarted += OnDirectManipulationStarted; _scrollViewer.DirectManipulationCompleted += OnDirectManipulationCompleted; // Retrieve the ScrollViewer manipulation and the Compositor. _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(_scrollViewer); _compositor = _scrollerViewerManipulation.Compositor; // At the moment there are three things happening when pulling down the list - // 1. The Refresh Icon fades in. // 2. The Refresh Icon rotates (400°). // 3. The Refresh Icon gets pulled down a bit (REFRESH_ICON_MAX_OFFSET_Y) // QUESTION 5 // Can we also have Geometric Path animation so we can also draw the Refresh Icon along the way? // // Create a rotation expression animation based on the overpan distance of the ScrollViewer. _rotationAnimation = _compositor.CreateExpressionAnimation("min(max(0, ScrollManipulation.Translation.Y) * Multiplier, MaxDegree)"); _rotationAnimation.SetScalarParameter("Multiplier", 10.0f); _rotationAnimation.SetScalarParameter("MaxDegree", 400.0f); _rotationAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); // Create an opacity expression animation based on the overpan distance of the ScrollViewer. _opacityAnimation = _compositor.CreateExpressionAnimation("min(max(0, ScrollManipulation.Translation.Y) / Divider, 1)"); _opacityAnimation.SetScalarParameter("Divider", 30.0f); _opacityAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); // Create an offset expression animation based on the overpan distance of the ScrollViewer. _offsetAnimation = _compositor.CreateExpressionAnimation("(min(max(0, ScrollManipulation.Translation.Y) / Divider, 1)) * MaxOffsetY"); _offsetAnimation.SetScalarParameter("Divider", 30.0f); _offsetAnimation.SetScalarParameter("MaxOffsetY", REFRESH_ICON_MAX_OFFSET_Y); _offsetAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); // Create a keyframe animation to reset properties like Offset.Y, Opacity, etc. _resetAnimation = _compositor.CreateScalarKeyFrameAnimation(); _resetAnimation.InsertKeyFrame(1.0f, 0.0f); // Create a loading keyframe animation (in this case, a rotation animation). _loadingAnimation = _compositor.CreateScalarKeyFrameAnimation(); _loadingAnimation.InsertKeyFrame(1.0f, 360); _loadingAnimation.Duration = TimeSpan.FromMilliseconds(1200); _loadingAnimation.IterationBehavior = AnimationIterationBehavior.Forever; // Get the RefreshIcon's Visual. _refreshIconVisual = ElementCompositionPreview.GetElementVisual(RefreshIcon); // Set the center point for the rotation animation. _refreshIconVisual.CenterPoint = new Vector3(Convert.ToSingle(RefreshIcon.ActualWidth / 2), Convert.ToSingle(RefreshIcon.ActualHeight / 2), 0); // Get the ListView's inner Border's Visual. var border = (Border)VisualTreeHelper.GetChild(ListView, 0); _borderVisual = ElementCompositionPreview.GetElementVisual(border); PrepareExpressionAnimationsOnScroll(); }; this.Unloaded += (s, e) => { _scrollViewer.DirectManipulationStarted -= OnDirectManipulationStarted; _scrollViewer.DirectManipulationCompleted -= OnDirectManipulationCompleted; }; }
private void WireAnimations() { _ContentVisual = ElementCompositionPreview.GetElementVisual(_ContentContainer); _LeftTextVisual = ElementCompositionPreview.GetElementVisual(_LeftTextBlock); _LeftContentVisual = ElementCompositionPreview.GetElementVisual(_LeftContent); _RightTextVisual = ElementCompositionPreview.GetElementVisual(_RightTextBlock); _RightContentVisual = ElementCompositionPreview.GetElementVisual(_RightContent); _Compositor = _ContentVisual.Compositor; _ContentAnimation = _Compositor.CreateExpressionAnimation("offset"); _ContentAnimation.SetScalarParameter("offset", (float)_OffsetX); //_ContentAnimation.SetScalarParameter("maxOffset", (float)_MaxOffsetX); // Reset Animations }
private void OnSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs e) { Vector2 size = new System.Numerics.Vector2((float)this.ActualWidth, (float)this.ActualHeight); if (m_interactionTracker != null) { m_interactionTracker.MinPosition = new Vector3(-size.X, 0, 0); m_interactionTracker.MaxPosition = new Vector3(size.X, 0, 0); if (Content != null) { var positionExpression = m_compositor.CreateExpressionAnimation("-tracker.Position"); positionExpression.SetReferenceParameter("tracker", m_interactionTracker); m_contentVisual = ElementCompositionPreview.GetElementVisual(Content); m_contentVisual.StartAnimation("Offset", positionExpression); m_contentVisual.Size = size; if (m_setUpExpressions && m_progressAnimation == null) { m_progressAnimation = m_compositor.CreateExpressionAnimation( "clamp(visual.Offset.X / visual.Size.X, -1, 1)"); m_progressAnimation.SetReferenceParameter("visual", m_contentVisual); m_rootVisual.Properties.StartAnimation("NormalizedProgress", m_progressAnimation); } } } }
/// <summary> /// Sets up the composition animations that position the Refresh Indicator and main content /// based on the overpan amount. /// </summary> private void UpdateCompositionAnimations() { if (m_root != null && m_scroller != null && m_scrollerContent != null && m_refreshIndicatorContainer != null) { if (m_scrollerContentAnimation == null) { CompositionPropertySet scrollingProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(m_scroller); Compositor compositor = scrollingProperties.Compositor; // Ensure that the maximum overpan amount corresponds to the Refresh Indicator's height. m_scrollerContentVisual = ElementCompositionPreview.GetElementVisual(m_scrollerContent); m_scrollerContentAnimation = compositor.CreateExpressionAnimation(@"overpanMultiplier * max(0, scrollingProperties.Translation.Y)"); m_scrollerContentAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); // Ensure that the Refresh Indicator is positioned on top of the main content. m_refreshIndicatorContainerVisual = ElementCompositionPreview.GetElementVisual(m_refreshIndicatorContainer); m_refreshIndicatorContainerAnimation = compositor.CreateExpressionAnimation(@"-refreshIndicatorContainerHeight"); // Create RefreshPropertySet and populate it with the PullRatio and PullProgress variables that vary from 0 to 1. this.RefreshPropertySet = compositor.CreatePropertySet(); m_pullRatioAnimation = compositor.CreateExpressionAnimation(@"clamp(max(0, scrollingProperties.Translation.Y) / maxOverpan + staticRatio, 0, 1)"); m_pullRatioAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); this.RefreshPropertySet.InsertScalar("PullRatio", 0); m_pullProgressAnimation = compositor.CreateExpressionAnimation(@"clamp(max(0, scrollingProperties.Translation.Y) / thresholdOverpan + staticProgress, 0, 1)"); m_pullProgressAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); this.RefreshPropertySet.InsertScalar("PullProgress", 0); } m_scrollerContentAnimation.SetScalarParameter("overpanMultiplier", (float)(m_refreshIndicatorContainer.ActualHeight / m_scroller.ActualHeight / MAX_SCROLLVIEWER_OVERPAN_RATIO - 1.0f / m_scroller.ZoomFactor)); m_scrollerContentVisual.StartAnimation("Offset.Y", m_scrollerContentAnimation); m_refreshIndicatorContainerAnimation.SetScalarParameter("refreshIndicatorContainerHeight", (float)m_refreshIndicatorContainer.ActualHeight); m_refreshIndicatorContainerVisual.StartAnimation("Offset.Y", m_refreshIndicatorContainerAnimation); float maxOverpan = (float)(m_scroller.ActualHeight * MAX_SCROLLVIEWER_OVERPAN_RATIO); m_pullRatioAnimation.SetScalarParameter("maxOverpan", maxOverpan); float staticRatio = (m_isAutoRefreshing || m_isSuppressingOverpan || m_scrollerContent.ManipulationMode == ManipulationModes.None) ? (float)DEFAULT_REFRESH_INDICATOR_THRESHOLD_RATIO : 0.0f; m_pullRatioAnimation.SetScalarParameter("staticRatio", staticRatio); this.RefreshPropertySet.StartAnimation("PullRatio", m_pullRatioAnimation); float thresholdOverpan = (float)(double.IsNaN(this.PullThreshold) ? (m_scroller.ActualHeight * MAX_SCROLLVIEWER_OVERPAN_RATIO * DEFAULT_REFRESH_INDICATOR_THRESHOLD_RATIO) : this.PullThreshold); m_pullProgressAnimation.SetScalarParameter("thresholdOverpan", thresholdOverpan); float staticProgress = (m_refreshActivated || m_isAutoRefreshing || m_isSuppressingOverpan || m_scrollerContent.ManipulationMode == ManipulationModes.None) ? 1.0f : 0.0f; m_pullProgressAnimation.SetScalarParameter("staticProgress", staticProgress); this.RefreshPropertySet.StartAnimation("PullProgress", m_pullProgressAnimation); } }
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 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 CreateVisual() { visual = ElementCompositionPreview.GetElementVisual(currentTopGroupHeader); var scrollViewerManipProps = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); Compositor compositor = scrollViewerManipProps.Compositor; expression = compositor.CreateExpressionAnimation("max(0,ScrollViewerManipProps.Translation.Y)"); // set "dynamic" reference parameter that will be used to evaluate the current position of the scrollbar every frame expression.SetReferenceParameter("ScrollViewerManipProps", scrollViewerManipProps); visual.StartAnimation("Offset.Y", expression); //Windows.UI.Xaml.Media.CompositionTarget.Rendering += OnCompositionTargetRendering; }
private void SetupSkyVisualOffsetExpressionAnimation() { // Kick off an expression animation that links the roll & pitch degress to the -offset of the sky canvas visual // TODO: Need to constraint the offset (total offset < dimension * SkyVisualAreaRatio) with // CreateConditionalExpressionAnimation once the next mobile build is available. _skyViusalOffsetExpressionAnimation = _compositor.CreateExpressionAnimation( "Vector3(SkyVisual.Offset.X - Reading.Offset.X * Sensitivity, SkyVisual.Offset.Y - Reading.Offset.Y * Sensitivity, 0.0f)"); _skyViusalOffsetExpressionAnimation.SetReferenceParameter("SkyVisual", _skyVisual); _skyViusalOffsetExpressionAnimation.SetReferenceParameter("Reading", _reading); _skyViusalOffsetExpressionAnimation.SetScalarParameter("Sensitivity", 0.2f); //_skyViusalOffsetExpressionAnimation.SetScalarParameter("MaxDimension", SkyVisualRadius * 2 * SkyVisualAreaRatio); _skyVisual.StartAnimation("Offset", _skyViusalOffsetExpressionAnimation); }
private void ScrollViewer_Loaded(object sender, RoutedEventArgs e) { Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // 创建驱动视差滚动的表达式动画。 parallaxAnimation0 = compositor.CreateExpressionAnimation("MyForeground.Translation.X / MyParallaxRatio"); parallaxAnimation1 = compositor.CreateExpressionAnimation("MyForeground.Translation.X / MyParallaxRatio"); parallaxAnimation2 = compositor.CreateExpressionAnimation("MyForeground.Translation.X / MyParallaxRatio"); parallaxAnimation3 = compositor.CreateExpressionAnimation("MyForeground.Translation.X / MyParallaxRatio"); parallaxAnimation4 = compositor.CreateExpressionAnimation("((MyForeground.Translation.X / MyParallaxRatio) + offset)"); // 设置对前景对象的引用。 scrollViewerProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(RootScroll); parallaxAnimation0.SetReferenceParameter("MyForeground", scrollViewerProperties); parallaxAnimation1.SetReferenceParameter("MyForeground", scrollViewerProperties); parallaxAnimation2.SetReferenceParameter("MyForeground", scrollViewerProperties); parallaxAnimation3.SetReferenceParameter("MyForeground", scrollViewerProperties); parallaxAnimation4.SetReferenceParameter("MyForeground", scrollViewerProperties); // 设置背景对象视差滚动的速度。 parallaxAnimation0.SetScalarParameter("MyParallaxRatio", 1f); parallaxAnimation1.SetScalarParameter("MyParallaxRatio", 2f); parallaxAnimation2.SetScalarParameter("MyParallaxRatio", 4f); parallaxAnimation3.SetScalarParameter("MyParallaxRatio", 8f); parallaxAnimation4.SetScalarParameter("MyParallaxRatio", 0.5f); parallaxAnimation4.SetScalarParameter("offset", 3 * (float)ActualWidth); var backgroundVisual0 = ElementCompositionPreview.GetElementVisual(BGLayer0); var backgroundVisual1 = ElementCompositionPreview.GetElementVisual(BGLayer1); var backgroundVisual2 = ElementCompositionPreview.GetElementVisual(BGLayer2); var backgroundVisual3 = ElementCompositionPreview.GetElementVisual(BGLayer3); var backgroundVisual4 = ElementCompositionPreview.GetElementVisual(RootFrame); // 对背景对象开始视差动画。 backgroundVisual0.StartAnimation("Offset.X", parallaxAnimation0); backgroundVisual1.StartAnimation("Offset.X", parallaxAnimation1); backgroundVisual2.StartAnimation("Offset.X", parallaxAnimation2); backgroundVisual3.StartAnimation("Offset.X", parallaxAnimation3); backgroundVisual4.StartAnimation("Offset.X", parallaxAnimation4); MainFrame.Navigate(typeof(CitiesPage), "nimabi"); IndAni.Begin(); }
private void CreateAnimationTemplates(Compositor compositor) { // // Near-slide and far-slide animations. // _nearSlideOffsetAnimation = compositor.CreateVector3KeyFrameAnimation(); _nearSlideOffsetAnimation.InsertExpressionKeyFrame(0.0f, "this.StartingValue"); _nearSlideOffsetAnimation.InsertExpressionKeyFrame(1.0f, "vector3(0,0,0) - myViewportCenter"); _farSlideOffsetAnimation = compositor.CreateVector3KeyFrameAnimation(); _farSlideOffsetAnimation.InsertExpressionKeyFrame(0.0f, "this.StartingValue"); _farSlideOffsetAnimation.InsertExpressionKeyFrame(0.9f, "vector3(0,0,0) - myViewportCenter"); _farSlideOffsetAnimation.InsertExpressionKeyFrame(1.0f, "vector3(0,0,0) - myViewportCenter"); _slideCenterAnimation = compositor.CreateVector3KeyFrameAnimation(); _slideCenterAnimation.InsertExpressionKeyFrame(0.0f, "this.StartingValue"); _slideCenterAnimation.InsertExpressionKeyFrame(1.0f, "myTargetCenterPoint"); _nearSlideScaleAnimation = compositor.CreateVector3KeyFrameAnimation(); _nearSlideScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _nearSlideScaleAnimation.InsertExpressionKeyFrame(1.00f, "myScale"); _farSlideScaleAnimation = compositor.CreateVector3KeyFrameAnimation(); _farSlideScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _farSlideScaleAnimation.InsertKeyFrame(0.30f, new Vector3(1.0f, 1.0f, 1.0f)); _farSlideScaleAnimation.InsertKeyFrame(1.00f, new Vector3(1.0f, 1.0f, 1.0f)); TimeSpan time4sec = TimeSpan.FromSeconds(4); TimeSpan time8sec = TimeSpan.FromSeconds(8); _nearSlideOffsetAnimation.Duration = time4sec; _farSlideOffsetAnimation.Duration = time8sec; _slideCenterAnimation.Duration = time4sec; _nearSlideScaleAnimation.Duration = time4sec; _farSlideScaleAnimation.Duration = time4sec; // // Zoom animations. // _zoomScaleAnimation = compositor.CreateVector3KeyFrameAnimation(); _zoomScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _zoomScaleAnimation.InsertKeyFrame(0.40f, new Vector3(1.0f, 1.0f, 1.0f)); _zoomScaleAnimation.InsertKeyFrame(0.60f, new Vector3(1.0f, 1.0f, 1.0f)); _zoomScaleAnimation.InsertExpressionKeyFrame(1.00f, "myScale"); _zoomCenterAnimation = compositor.CreateVector3KeyFrameAnimation(); _zoomCenterAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _zoomCenterAnimation.InsertExpressionKeyFrame(0.40f, "this.StartingValue"); _zoomCenterAnimation.InsertExpressionKeyFrame(0.60f, "myTargetCenterPoint"); _zoomCenterAnimation.InsertExpressionKeyFrame(1.00f, "myTargetCenterPoint"); _zoomOffsetAnimation = compositor.CreateVector3KeyFrameAnimation(); _zoomOffsetAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _zoomOffsetAnimation.InsertExpressionKeyFrame(1.00f, "vector3(0,0,0) - myViewportCenter"); TimeSpan time12sec = TimeSpan.FromSeconds(12); _zoomScaleAnimation.Duration = time12sec; _zoomCenterAnimation.Duration = time12sec; _zoomOffsetAnimation.Duration = time12sec; // // Stack animations. // CubicBezierEasingFunction flyInEasing; CubicBezierEasingFunction flyOutEasing; flyInEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 1.0f), new Vector2(0.8f, 1.0f)); _stackFlyInAnimation = compositor.CreateVector3KeyFrameAnimation(); _stackFlyInAnimation.InsertExpressionKeyFrame(0.00f, "stackVisual.Offset + startDelta"); _stackFlyInAnimation.InsertExpressionKeyFrame(1.00f, "stackVisual.Offset + endDelta", flyInEasing); _stackFlyInAnimation.Duration = TimeSpan.FromSeconds(2); flyOutEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 0.4f), new Vector2(1.0f, 0.6f)); _stackFlyOutAnimation = compositor.CreateVector3KeyFrameAnimation(); _stackFlyOutAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue", flyOutEasing); _stackFlyOutAnimation.InsertExpressionKeyFrame(0.50f, "this.StartingValue + delta", flyOutEasing); _stackFlyOutAnimation.InsertExpressionKeyFrame(1.00f, "originalOffset", flyOutEasing); _stackFlyOutAnimation.Duration = TimeSpan.FromSeconds(2); _stackScaleAnimation = compositor.CreateVector3KeyFrameAnimation(); _stackScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _stackScaleAnimation.InsertExpressionKeyFrame(1.00f, "myScale"); _stackScaleAnimation.Duration = TimeSpan.FromSeconds(6); // // Color flashlight expression animation. // // This expression returns a computes between 0 and 1 as a function of on how close the // center of the frame is to the center of the window. // - If the frame is at the center of the window, the expression computes 0 (no // desaturation). // - If the frame is more than 300px away from the center of the window, the // expression computes 1 (full desaturation). // - If the frame is within 300px from the center of the window, the expression // computes a value between 0 and 1 relative to how far the frame is from the 300px // boundary (partial desaturation). _colorFlashlightAnimation = compositor.CreateExpressionAnimation( "1.0 - min(" + " 1.0," + " (" + " (" + " ( frame.Offset.x + (frame.Size.x * 0.5) + grid.Offset.x - (windowWidth * 0.5) )" + " * ( frame.Offset.x + (frame.Size.x * 0.5) + grid.Offset.x - (windowWidth * 0.5) )" + " ) + (" + " ( frame.Offset.y + (frame.Size.y * 0.5) + grid.Offset.y - (windowHeight * 0.5) )" + " * ( frame.Offset.y + (frame.Size.y * 0.5) + grid.Offset.y - (windowHeight * 0.5) )" + " )" + " ) / ( radius * radius )" + ")"); _colorFlashlightAnimation.SetReferenceParameter("grid", _layoutManager.GridVisual); _colorFlashlightAnimation.SetScalarParameter("radius", 300); _colorFlashlightAnimation.SetScalarParameter("windowWidth", _windowWidth); _colorFlashlightAnimation.SetScalarParameter("windowHeight", _windowHeight); }
public void Dispose() { if (_nearSlideOffsetAnimation != null) { _nearSlideOffsetAnimation.Dispose(); _nearSlideOffsetAnimation = null; } if (_farSlideOffsetAnimation != null) { _farSlideOffsetAnimation.Dispose(); _farSlideOffsetAnimation = null; } if (_slideCenterAnimation != null) { _slideCenterAnimation.Dispose(); _slideCenterAnimation = null; } if (_zoomScaleAnimation != null) { _zoomScaleAnimation.Dispose(); _zoomScaleAnimation = null; } if (_zoomCenterAnimation != null) { _zoomCenterAnimation.Dispose(); _zoomCenterAnimation = null; } if (_zoomOffsetAnimation != null) { _zoomOffsetAnimation.Dispose(); _zoomOffsetAnimation = null; } if (_stackFlyInAnimation != null) { _stackFlyInAnimation.Dispose(); _stackFlyInAnimation = null; } if (_stackFlyOutAnimation != null) { _stackFlyOutAnimation.Dispose(); _stackFlyOutAnimation = null; } if (_stackScaleAnimation != null) { _stackScaleAnimation.Dispose(); _stackScaleAnimation = null; } if (_colorFlashlightAnimation != null) { _colorFlashlightAnimation.Dispose(); _colorFlashlightAnimation = null; } }
private void Page_Unloaded(object sender, RoutedEventArgs e) { if (parallaxAnimation0 != null) { parallaxAnimation0.Dispose(); parallaxAnimation0 = null; } if (parallaxAnimation1 != null) { parallaxAnimation1.Dispose(); parallaxAnimation1 = null; } if (parallaxAnimation2 != null) { parallaxAnimation2.Dispose(); parallaxAnimation2 = null; } if (parallaxAnimation3 != null) { parallaxAnimation3.Dispose(); parallaxAnimation3 = null; } if (parallaxAnimation4 != null) { parallaxAnimation4.Dispose(); parallaxAnimation4 = null; } if (scrollViewerProperties != null) { scrollViewerProperties.Dispose(); scrollViewerProperties = null; } IndAni.Stop(); }
public override async Task<CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .25f, 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/conemap.jpg")); // Create the animations float sweep = (float)Math.PI / 10f; float fullCircle = (float)Math.PI * -2f; _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.1f, fullCircle); _enterAnimation.InsertKeyFrame(0.4f, fullCircle + sweep); _enterAnimation.InsertKeyFrame(0.8f, fullCircle - sweep); _enterAnimation.InsertKeyFrame(1.0f, fullCircle); _enterAnimation.Duration = TimeSpan.FromMilliseconds(4500); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Count; _enterAnimation.IterationCount = 1; _exitAnimation = _compositor.CreateScalarKeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, 0f); _exitAnimation.Duration = TimeSpan.FromMilliseconds(1000); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; _transformExpression = _compositor.CreateExpressionAnimation("Matrix3x2.CreateFromTranslation(-props.CenterPointOffset) * Matrix3x2(cos(props.Rotation) * props.Scale, sin(props.Rotation), -sin(props.Rotation), cos(props.Rotation) * props.Scale, 0, 0) * Matrix3x2.CreateFromTranslation(props.CenterPointOffset + props.Translate)"); return null; }
private void ScrollViewer_Loaded(object sender, RoutedEventArgs e) { _scrollViewer.DirectManipulationStarted += ScrollViewer_DirectManipulationStarted; _scrollViewer.DirectManipulationCompleted += ScrollViewer_DirectManipulationCompleted; var border = (Border)VisualTreeHelper.GetChild(_scrollViewer, 0); _scrollViewerBorder = border; _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(_scrollViewer); _compositor = _scrollerViewerManipulation.Compositor; double ratio = 1.0; _header.Measure(new Size(this.ActualWidth, this.ActualHeight)); var headerHeight = _header.DesiredSize.Height; if (headerHeight == 0) { headerHeight = 50; } if (RefreshThreshold == 0.0) { RefreshThreshold = headerHeight; } ratio = RefreshThreshold / headerHeight; _offsetAnimation = _compositor.CreateExpressionAnimation("(min(max(0, ScrollManipulation.Translation.Y * ratio) / Divider, 1)) * MaxOffsetY"); _offsetAnimation.SetScalarParameter("Divider", (float)RefreshThreshold); _offsetAnimation.SetScalarParameter("MaxOffsetY", (float)RefreshThreshold * 5 / 4); _offsetAnimation.SetScalarParameter("ratio", (float)ratio); _offsetAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _opacityAnimation = _compositor.CreateExpressionAnimation("min((max(0, ScrollManipulation.Translation.Y * ratio) / Divider), 1)"); _opacityAnimation.SetScalarParameter("Divider", (float)headerHeight); _opacityAnimation.SetScalarParameter("ratio", (float)1); _opacityAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _headerVisual = ElementCompositionPreview.GetElementVisual(_header); _contentVisual = ElementCompositionPreview.GetElementVisual(_scrollViewerBorder); _headerVisual.StartAnimation("Offset.Y", _offsetAnimation); _headerVisual.StartAnimation("Opacity", _opacityAnimation); _contentVisual.StartAnimation("Offset.Y", _offsetAnimation); }
private void ConfigureGearAnimation(Visual currentGear, Visual previousGear) { // If rotation expression is null then create an expression of a gear rotating the opposite direction _rotationExpression = _rotationExpression ?? _compositor.CreateExpressionAnimation("-previousGear.RotationAngleInDegrees"); // put in placeholder parameters _rotationExpression.SetReferenceParameter("previousGear", previousGear); // Start the animation based on the Rotation Angle in Degrees. currentGear.StartAnimation("RotationAngleInDegrees", _rotationExpression); }
private void UpdatePerspectiveMatrix() { if (!m_setUpExpressions) { Vector3 perspectiveOrigin = new Vector3(PerspectiveOriginPercent * m_rootVisual.Size, 0); Matrix4x4 transform = Matrix4x4.CreateTranslation(-perspectiveOrigin) * new Matrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -1 / (float)PerspectiveDepth, 0, 0, 0, 1) * Matrix4x4.CreateTranslation(perspectiveOrigin); m_rootVisual.TransformMatrix = transform; } else if (m_matrixExpression == null) { m_matrixExpression = m_compositor.CreateExpressionAnimation(); m_matrixExpression.Properties.InsertVector3("LayoutSize", new Vector3(m_rootVisual.Size, 0)); // Expressions don't have an easy way to convert vector2 to vector3. But having this intermediate expression makes the below expression cleaner anyway. var perspectiveOriginExpression = m_compositor.CreateExpressionAnimation( "Vector3(publicProps.PerspectiveOriginPercent.x, publicProps.PerspectiveOriginPercent.y, 0) * props.LayoutSize"); perspectiveOriginExpression.SetReferenceParameter("publicProps", m_rootVisual.Properties); perspectiveOriginExpression.SetReferenceParameter("props", m_matrixExpression.Properties); m_matrixExpression.Properties.InsertVector3("PerspectiveOrigin", Vector3.Zero); m_matrixExpression.Properties.StartAnimation("PerspectiveOrigin", perspectiveOriginExpression); m_matrixExpression.Expression = "Matrix4x4.CreateFromTranslation(-props.PerspectiveOrigin) * " + "Matrix4x4(1,0,0,0, 0,1,0,0, 0,0,1,-1/publicProps.PerspectiveDepth, 0,0,0,1) * " + "Matrix4x4.CreateFromTranslation( props.PerspectiveOrigin)"; m_matrixExpression.SetReferenceParameter("publicProps", m_rootVisual.Properties); m_matrixExpression.SetReferenceParameter("props", m_matrixExpression.Properties); m_rootVisual.StartAnimation("TransformMatrix", m_matrixExpression); } }