StepEasingFunction HoldThenStepEasingFunction() { var result = _holdThenStepEasingFunction = _c.CreateStepEasingFunction(); result.IsFinalStepSingleFrame = true; return(result); }
static void OptimizeStepEasingFunctionProperties(StepEasingFunction obj) { if (obj.StepCount == 1) { obj.StepCount = null; } if (obj.IsInitialStepSingleFrame == false) { obj.IsInitialStepSingleFrame = null; } if (obj.InitialStep == 0) { obj.InitialStep = null; } if (obj.FinalStep == 1) { obj.FinalStep = null; } if (obj.IsFinalStepSingleFrame == false) { obj.IsFinalStepSingleFrame = null; } }
StepEasingFunction StepThenHoldEasingFunction() { var result = _stepThenHoldEasingFunction = _c.CreateStepEasingFunction(); result.IsInitialStepSingleFrame = true; return(result); }
internal CompositionObjectFactory(Compositor compositor) { _compositor = compositor; // Initialize singletons. _linearEasingFunction = _compositor.CreateLinearEasingFunction(); _holdStepEasingFunction = _compositor.CreateStepEasingFunction(1); _holdStepEasingFunction.IsFinalStepSingleFrame = true; _jumpStepEasingFunction = _compositor.CreateStepEasingFunction(1); _jumpStepEasingFunction.IsInitialStepSingleFrame = true; }
XElement FromStepEasingFunction(StepEasingFunction obj) { return(new XElement(GetCompositionObjectName(obj), GetContents())); IEnumerable <XObject> GetContents() { foreach (var item in GetCompositionObjectContents(obj)) { yield return(item); } } }
internal CompositionObjectFactory(TranslationContext context, Compositor compositor, uint targetUapVersion) { _context = context; _compositor = compositor; _targetUapVersion = targetUapVersion; // Initialize singletons. _linearEasingFunction = _compositor.CreateLinearEasingFunction(); _holdStepEasingFunction = _compositor.CreateStepEasingFunction(1); _holdStepEasingFunction.IsFinalStepSingleFrame = true; _jumpStepEasingFunction = _compositor.CreateStepEasingFunction(1); _jumpStepEasingFunction.IsInitialStepSingleFrame = true; }
StepEasingFunction StepThenHoldEasingFunction() { if (_stepThenHoldEasingFunction != null) { return(_stepThenHoldEasingFunction); } var result = _stepThenHoldEasingFunction = _c.CreateStepEasingFunction(); result.FinalStep = 1; result.IsInitialStepSingleFrame = true; result.StepCount = 1; return(result); }
StepEasingFunction GetStepEasingFunction(StepEasingFunction obj) { if (GetExisting(obj, out StepEasingFunction result)) { return(result); } result = CacheAndInitializeCompositionObject(obj, _c.CreateStepEasingFunction()); if (obj.FinalStep != 1) { result.FinalStep = obj.FinalStep; } if (obj.InitialStep != 0) { result.InitialStep = obj.InitialStep; } if (obj.IsFinalStepSingleFrame) { result.IsFinalStepSingleFrame = obj.IsFinalStepSingleFrame; } if (obj.IsInitialStepSingleFrame) { result.IsInitialStepSingleFrame = obj.IsInitialStepSingleFrame; } if (obj.StepCount != 1) { result.StepCount = obj.StepCount; } StartAnimationsAndFreeze(obj, result); return(result); }
private void PlayIndicatorAnimations(UIElement indicator, float from, float to, Vector2 beginSize, Vector2 endSize, bool isOutgoing) { Visual visual = ElementCompositionPreview.GetElementVisual(indicator); Compositor comp = visual.Compositor; Vector2 size = indicator.RenderSize.ToVector2(); float dimension = Orientation == Orientation.Horizontal ? size.X : size.Y; float beginScale = 1.0f; float endScale = 1.0f; if (Orientation == Orientation.Horizontal && MathF.Abs(size.X) > 0.001f) { beginScale = beginSize.X / size.X; endScale = endSize.X / size.X; } StepEasingFunction singleStep = comp.CreateStepEasingFunction(); singleStep.IsFinalStepSingleFrame = true; if (isOutgoing) { // fade the outgoing indicator so it looks nice when animating over the scroll area ScalarKeyFrameAnimation opacityAnim = comp.CreateScalarKeyFrameAnimation(); opacityAnim.InsertKeyFrame(0.0f, 1.0f); opacityAnim.InsertKeyFrame(0.333f, 1.0f, singleStep); opacityAnim.InsertKeyFrame(1.0f, 0.0f, comp.CreateCubicBezierEasingFunction(c_frame2point1, c_frame2point2)); opacityAnim.Duration = TimeSpan.FromMilliseconds(600); visual.StartAnimation("Opacity", opacityAnim); } else { visual.Opacity = 1; } ScalarKeyFrameAnimation posAnim = comp.CreateScalarKeyFrameAnimation(); posAnim.InsertKeyFrame(0.0f, from < to ? from : (from + (dimension * (beginScale - 1)))); posAnim.InsertKeyFrame(0.333f, from < to ? (to + (dimension * (endScale - 1))) : to, singleStep); posAnim.Duration = TimeSpan.FromMilliseconds(600); ScalarKeyFrameAnimation scaleAnim = comp.CreateScalarKeyFrameAnimation(); scaleAnim.InsertKeyFrame(0.0f, beginScale); scaleAnim.InsertKeyFrame(0.333f, MathF.Abs(to - from) / dimension + (from < to ? endScale : beginScale), comp.CreateCubicBezierEasingFunction(c_frame1point1, c_frame1point2)); scaleAnim.InsertKeyFrame(1.0f, endScale, comp.CreateCubicBezierEasingFunction(c_frame2point1, c_frame2point2)); scaleAnim.Duration = TimeSpan.FromMilliseconds(600); ScalarKeyFrameAnimation centerAnim = comp.CreateScalarKeyFrameAnimation(); centerAnim.InsertKeyFrame(0.0f, from < to ? 0.0f : dimension); centerAnim.InsertKeyFrame(1.0f, from < to ? dimension : 0.0f, singleStep); centerAnim.Duration = TimeSpan.FromMilliseconds(200); if (Orientation == Orientation.Horizontal) { visual.StartAnimation("Offset.X", posAnim); visual.StartAnimation("Scale.X", scaleAnim); visual.StartAnimation("CenterPoint.X", centerAnim); } else { visual.StartAnimation("Offset.Y", posAnim); visual.StartAnimation("Scale.Y", scaleAnim); visual.StartAnimation("CenterPoint.Y", centerAnim); } }
private void Scroller4_ZoomAnimationStarting(muxc.ScrollViewer sender, muxc.ZoomAnimationStartingEventArgs args) { try { ScalarKeyFrameAnimation stockKeyFrameAnimation = args.Animation as ScalarKeyFrameAnimation; if (stockKeyFrameAnimation != null) { ScalarKeyFrameAnimation customKeyFrameAnimation = stockKeyFrameAnimation; if (nameof(ZoomAnimationOptions.Default) != (string)cbZoomAnimation.SelectedItem) { float targetZoomFactor = (float)zoomFactorSlider.Value; customKeyFrameAnimation = stockKeyFrameAnimation.Compositor.CreateScalarKeyFrameAnimation(); float deltaZoomFactor = (float)(targetZoomFactor - sender.ZoomFactor); switch ((string)cbZoomAnimation.SelectedItem) { case nameof(ZoomAnimationOptions.Custom1): // "Accordion" case for (int step = 0; step < 3; step++) { customKeyFrameAnimation.InsertKeyFrame( 1.0f - (0.4f / (float)Math.Pow(2, step)), targetZoomFactor + 0.1f * deltaZoomFactor); deltaZoomFactor /= -2.0f; } customKeyFrameAnimation.InsertKeyFrame(1.0f, targetZoomFactor); break; case nameof(ZoomAnimationOptions.Custom2): // "Teleportation" case CubicBezierEasingFunction cubicBezierStart = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction( new Vector2(1.0f, 0.0f), new Vector2(1.0f, 0.0f)); StepEasingFunction stepEasingFunc = stockKeyFrameAnimation.Compositor.CreateStepEasingFunction(1); CubicBezierEasingFunction cubicBezierEnd = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction( new Vector2(0.0f, 1.0f), new Vector2(0.0f, 1.0f)); customKeyFrameAnimation.InsertKeyFrame( 0.499999f, targetZoomFactor - 0.75f * deltaZoomFactor, cubicBezierStart); customKeyFrameAnimation.InsertKeyFrame( 0.5f, targetZoomFactor - 0.25f * deltaZoomFactor, stepEasingFunc); customKeyFrameAnimation.InsertKeyFrame( 1.0f, targetZoomFactor, cubicBezierEnd); break; default: break; } customKeyFrameAnimation.Duration = stockKeyFrameAnimation.Duration; args.Animation = customKeyFrameAnimation; } if (!string.IsNullOrWhiteSpace(tbZoomDuration.Text)) { double durationOverride = Convert.ToDouble(tbZoomDuration.Text); customKeyFrameAnimation.Duration = TimeSpan.FromMilliseconds(durationOverride); } } } catch (Exception ex) { } }
private void Scroller4_ScrollAnimationStarting(muxc.ScrollViewer sender, muxc.ScrollAnimationStartingEventArgs args) { try { Vector3KeyFrameAnimation stockKeyFrameAnimation = args.Animation as Vector3KeyFrameAnimation; if (stockKeyFrameAnimation != null) { Vector3KeyFrameAnimation customKeyFrameAnimation = stockKeyFrameAnimation; if (nameof(ScrollAnimationOptions.Default) != (string)cbAnimation.SelectedItem) { double targetHorizontalOffset = args.EndPosition.X; float targetHorizontalPosition = ComputeHorizontalPositionFromOffset(sender.Content, targetHorizontalOffset, sender.ZoomFactor); double targetVerticalOffset = args.EndPosition.Y; float targetVerticalPosition = ComputeVerticalPositionFromOffset(sender.Content, targetVerticalOffset, sender.ZoomFactor); customKeyFrameAnimation = stockKeyFrameAnimation.Compositor.CreateVector3KeyFrameAnimation(); float deltaHorizontalPosition = (float)(targetHorizontalOffset - sender.HorizontalOffset); float deltaVerticalPosition = (float)(targetVerticalOffset - sender.VerticalOffset); switch ((string)cbAnimation.SelectedItem) { case nameof(ScrollAnimationOptions.Custom1): // "Accordion" case for (int keyframe = 0; keyframe < 3; keyframe++) { customKeyFrameAnimation.InsertKeyFrame( 1.0f - (0.4f / (float)Math.Pow(2, keyframe)), new Vector3(targetHorizontalPosition + 0.1f * deltaHorizontalPosition, targetVerticalPosition + 0.1f * deltaVerticalPosition, 0.0f)); deltaHorizontalPosition /= -2.0f; deltaVerticalPosition /= -2.0f; } customKeyFrameAnimation.InsertKeyFrame(1.0f, new Vector3(targetHorizontalPosition, targetVerticalPosition, 0.0f)); break; case nameof(ScrollAnimationOptions.Custom2): // "Teleportation" case CubicBezierEasingFunction cubicBezierStart = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction( new Vector2(1.0f, 0.0f), new Vector2(1.0f, 0.0f)); StepEasingFunction step = stockKeyFrameAnimation.Compositor.CreateStepEasingFunction(1); CubicBezierEasingFunction cubicBezierEnd = stockKeyFrameAnimation.Compositor.CreateCubicBezierEasingFunction( new Vector2(0.0f, 1.0f), new Vector2(0.0f, 1.0f)); customKeyFrameAnimation.InsertKeyFrame( 0.499999f, new Vector3(targetHorizontalPosition - 0.75f * deltaHorizontalPosition, targetVerticalPosition - 0.75f * deltaVerticalPosition, 0.0f), cubicBezierStart); customKeyFrameAnimation.InsertKeyFrame( 0.5f, new Vector3(targetHorizontalPosition - 0.25f * deltaHorizontalPosition, targetVerticalPosition - 0.25f * deltaVerticalPosition, 0.0f), step); customKeyFrameAnimation.InsertKeyFrame( 1.0f, new Vector3(targetHorizontalPosition, targetVerticalPosition, 0.0f), cubicBezierEnd); break; default: break; } customKeyFrameAnimation.Duration = stockKeyFrameAnimation.Duration; } if (!string.IsNullOrWhiteSpace(tbAnimDuration.Text)) { // Override animation duration double durationOverride = Convert.ToDouble(tbAnimDuration.Text); customKeyFrameAnimation.Duration = TimeSpan.FromMilliseconds(durationOverride); } args.Animation = customKeyFrameAnimation; } } catch (Exception ex) { } }
void InitConpositionResources() { easing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.215f, 0.61f), new Vector2(0.355f, 1f)); steping = compositor.CreateStepEasingFunction(2); ProgressAnimation = compositor.CreateScalarKeyFrameAnimation(); ProgressAnimation.InsertExpressionKeyFrame(0f, "This.StartingValue", easing); ProgressAnimation.InsertExpressionKeyFrame(1f, "propSet.newvalue", easing); ProgressAnimation.SetReferenceParameter("propSet", propSet); ProgressAnimation.Duration = TimeSpan.FromSeconds(0.3d); ProgressAnimation.Target = "progress"; //ImplicitAnimations = compositor.CreateImplicitAnimationCollection(); //ImplicitAnimations["progress"] = ProgressAnimation; //propSet.ImplicitAnimations = ImplicitAnimations; TopBorderVisual = ElementCompositionPreview.GetElementVisual(TopBorder); BottomBorderVisual = ElementCompositionPreview.GetElementVisual(BottomBorder); CenterBorderVisual = ElementCompositionPreview.GetElementVisual(CenterBorder); ContentBorderVisual = ElementCompositionPreview.GetElementVisual(ContentBorder); TopBorderVisual.CenterPoint = new Vector3(38f, 36f, 0f); BottomBorderVisual.CenterPoint = new Vector3(39f, 36f, 0f); CenterBorderVisual.CenterPoint = new Vector3(36f, 36f, 0f); ContentBorderVisual.CenterPoint = new Vector3(36, 36, 0); TopRotationAnimation = compositor.CreateExpressionAnimation("0.25 * Pi * propSet.progress"); TopRotationAnimation.SetReferenceParameter("propSet", propSet); BottomRotationAnimation = compositor.CreateExpressionAnimation("-0.25 * Pi * propSet.progress"); BottomRotationAnimation.SetReferenceParameter("propSet", propSet); IconRotationAnimation = compositor.CreateExpressionAnimation("propSet.isopened == 1 ? -Pi * propSet.progress : Pi * propSet.progress"); IconRotationAnimation.SetReferenceParameter("propSet", propSet); ExternalScaleXAnimation = compositor.CreateExpressionAnimation(" 1 - 0.4 * propSet.progress"); ExternalScaleXAnimation.SetReferenceParameter("propSet", propSet); InternalScaleXAnimation = compositor.CreateExpressionAnimation(" 1 - 0.04 * propSet.progress"); InternalScaleXAnimation.SetReferenceParameter("propSet", propSet); IsOpenedAnimation = compositor.CreateScalarKeyFrameAnimation(); IsOpenedAnimation.InsertExpressionKeyFrame(0f, "This.StartingValue", steping); IsOpenedAnimation.InsertKeyFrame(1f, 1f, steping); IsOpenedAnimation.Duration = TimeSpan.FromSeconds(0.001d); IsOpenedAnimation.DelayTime = TimeSpan.FromSeconds(0.3d); IsNotOpenedAnimation = compositor.CreateScalarKeyFrameAnimation(); IsNotOpenedAnimation.InsertExpressionKeyFrame(0f, "This.StartingValue", steping); IsNotOpenedAnimation.InsertKeyFrame(1f, 0f, steping); IsNotOpenedAnimation.Duration = TimeSpan.FromSeconds(0.001d); IsNotOpenedAnimation.DelayTime = TimeSpan.FromSeconds(0.3d); TopBorderVisual.StartAnimation("RotationAngle", TopRotationAnimation); BottomBorderVisual.StartAnimation("RotationAngle", BottomRotationAnimation); ContentBorderVisual.StartAnimation("RotationAngle", IconRotationAnimation); TopBorderVisual.StartAnimation("Scale.X", ExternalScaleXAnimation); BottomBorderVisual.StartAnimation("Scale.X", ExternalScaleXAnimation); CenterBorderVisual.StartAnimation("Scale.X", InternalScaleXAnimation); }