예제 #1
0
        private void StartClipAnimation(CompositionEllipseGeometry ellipseGeometry, TimeSpan delayTime)
        {
            var compositor = Window.Current.Compositor;
            var animation  = compositor.CreateVector2KeyFrameAnimation();
            var easing     = compositor.CreateCubicBezierEasingFunction(new Vector2(0.1f, 0.9f), new Vector2(0.2f, 1f));

            animation.DelayTime = delayTime;
            animation.Duration  = TimeSpan.FromSeconds(0.7);
            animation.InsertKeyFrame(1, new Vector2(600, 600));
            ellipseGeometry.StartAnimation(nameof(CompositionEllipseGeometry.Radius), animation);
        }
예제 #2
0
        protected override void OnValueChanged(double oldValue, double newValue)
        {
            //if (newValue > 0)
            //{
            //    newValue = Math.Max(newValue, 0.0001);
            //}
            if (double.IsNaN(newValue))
            {
                newValue = 0;
            }

            if (newValue > 0 && newValue < 0.05)
            {
                newValue = 0.05;
            }

            if (_foreverAnimation != null)
            {
                if (newValue > 0 && newValue < 1)
                {
                    if (!_spinning)
                    {
                        _spinning = true;
                        _visual.RotationAngleInDegrees = 230; // 202
                        _visual.StartAnimation("RotationAngleInDegrees", _foreverAnimation);
                    }
                }
                //else if (_spinning)
                //{
                //    _spinning = false;
                //    _visual.StopAnimation("RotationAngleInDegrees");
                //}
            }

            if (_ellipse != null)
            {
                var diff = Math.Abs(oldValue - newValue);
                if (diff < 0.10 && newValue < 1)
                {
                    _ellipse.TrimStart = 0;
                    _ellipse.TrimEnd   = MathF.Max(0, MathF.Min(1, (float)newValue));
                }
                else
                {
                    var linear    = Window.Current.Compositor.CreateLinearEasingFunction();
                    var trimStart = Window.Current.Compositor.CreateScalarKeyFrameAnimation();
                    var trimEnd   = Window.Current.Compositor.CreateScalarKeyFrameAnimation();

                    if (newValue < 1)
                    {
                        //_ellipse.TrimStart = 0;
                        //_ellipse.TrimEnd = MathF.Max(0, MathF.Min(1, (float)newValue));

                        trimStart.InsertKeyFrame(1, 0, linear);
                        trimEnd.InsertKeyFrame(1, MathF.Max(0, MathF.Min(1, (float)newValue)), linear);

                        _ellipse.StartAnimation("TrimStart", trimStart);
                        _ellipse.StartAnimation("TrimEnd", trimEnd);
                    }
                    else
                    {
                        //_ellipse.TrimStart = 1;
                        //_ellipse.TrimEnd = 1;

                        trimStart.InsertKeyFrame(1, ShrinkOut ? 1 : 0, linear);
                        trimEnd.InsertKeyFrame(1, 1, linear);

                        var batch = Window.Current.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
                        batch.Completed += (s, args) =>
                        {
                            if (_foreverAnimation != null && _spinning)
                            {
                                _spinning = false;
                                _visual.StopAnimation("RotationAngleInDegrees");
                            }

                            Completed?.Invoke(this, EventArgs.Empty);
                        };

                        _ellipse.StartAnimation("TrimStart", trimStart);
                        _ellipse.StartAnimation("TrimEnd", trimEnd);

                        batch.End();
                    }
                }
            }

            //if (newValue is >= 1.0 or <= 0.0)
            //{
            //    Visibility = Visibility.Collapsed;
            //}
            //else
            //{
            //    Visibility = Visibility.Visible;
            //}
        }