Exemple #1
0
        public void TransitionInstance_Properly_Calculates_Delay_And_Duration_Values()
        {
            var clock = new TestClock();

            int i    = -1;
            var inst = new TransitionInstance(clock, TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(70)).Subscribe(nextValue =>
            {
                switch (i++)
                {
                case 0: Assert.Equal(0, nextValue); break;

                case 1: Assert.Equal(0, nextValue); break;

                case 2: Assert.Equal(0, nextValue); break;

                case 3: Assert.Equal(0, nextValue); break;

                case 4: Assert.Equal(Math.Round(10d / 70d, 4), Math.Round(nextValue, 4)); break;

                case 5: Assert.Equal(Math.Round(20d / 70d, 4), Math.Round(nextValue, 4)); break;

                case 6: Assert.Equal(Math.Round(30d / 70d, 4), Math.Round(nextValue, 4)); break;

                case 7: Assert.Equal(Math.Round(40d / 70d, 4), Math.Round(nextValue, 4)); break;

                case 8: Assert.Equal(Math.Round(50d / 70d, 4), Math.Round(nextValue, 4)); break;

                case 9: Assert.Equal(Math.Round(60d / 70d, 4), Math.Round(nextValue, 4)); break;

                case 10: Assert.Equal(1d, nextValue); break;
                }
            });

            for (int z = 0; z <= 10; z++)
            {
                clock.Pulse(TimeSpan.FromMilliseconds(10));
            }
        }
Exemple #2
0
        public void Check_Transitions_Interpolation_Positive_Bounds_Clamp()
        {
            var clock = new TestClock();

            var border = new Border
            {
                Transitions = new Transitions
                {
                    new DoubleTransition
                    {
                        Duration = TimeSpan.FromSeconds(1),
                        Property = Border.OpacityProperty,
                    }
                }
            };

            border.Opacity = 0;

            clock.Pulse(TimeSpan.FromSeconds(0));
            clock.Pulse(TimeSpan.FromMilliseconds(1001));

            Assert.Equal(0, border.Opacity);
        }
Exemple #3
0
        public void Check_KeySpline_Handled_properly()
        {
            var keyframe1 = new KeyFrame()
            {
                Setters =
                {
                    new Setter(RotateTransform.AngleProperty, -2.5d),
                },
                KeyTime = TimeSpan.FromSeconds(0)
            };

            var keyframe2 = new KeyFrame()
            {
                Setters =
                {
                    new Setter(RotateTransform.AngleProperty, 2.5d),
                },
                KeyTime   = TimeSpan.FromSeconds(5),
                KeySpline = new KeySpline(0.1123555056179775,
                                          0.657303370786517,
                                          0.8370786516853934,
                                          0.499999999999999999)
            };

            var animation = new Animation()
            {
                Duration = TimeSpan.FromSeconds(5),
                Children =
                {
                    keyframe1,
                    keyframe2
                },
                IterationCount    = new IterationCount(5),
                PlaybackDirection = PlaybackDirection.Alternate
            };

            var rotateTransform = new RotateTransform(-2.5);
            var rect            = new Rectangle()
            {
                RenderTransform = rotateTransform
            };

            var clock        = new TestClock();
            var animationRun = animation.RunAsync(rect, clock);

            // position is what you'd expect at end and beginning
            clock.Step(TimeSpan.Zero);
            Assert.Equal(rotateTransform.Angle, -2.5);
            clock.Step(TimeSpan.FromSeconds(5));
            Assert.Equal(rotateTransform.Angle, 2.5);

            // test some points in between end and beginning
            var tolerance = 0.01;

            clock.Step(TimeSpan.Parse("00:00:10.0153932"));
            var expected = -2.4122350198982545;

            Assert.True(Math.Abs(rotateTransform.Angle - expected) <= tolerance);

            clock.Step(TimeSpan.Parse("00:00:11.2655407"));
            expected = -0.37153223002125113;
            Assert.True(Math.Abs(rotateTransform.Angle - expected) <= tolerance);

            clock.Step(TimeSpan.Parse("00:00:12.6158773"));
            expected = 0.3967885416786294;
            Assert.True(Math.Abs(rotateTransform.Angle - expected) <= tolerance);

            clock.Step(TimeSpan.Parse("00:00:14.6495256"));
            expected = 1.8016358493761722;
            Assert.True(Math.Abs(rotateTransform.Angle - expected) <= tolerance);
        }
Exemple #4
0
        public void Replacing_Transitions_During_Animation_Does_Not_Throw_KeyNotFound()
        {
            // Issue #4059
            using (Start())
            {
                Border target;
                var    clock = new TestClock();
                var    root  = new TestRoot
                {
                    Clock  = clock,
                    Styles =
                    {
                        new Style(x => x.OfType <Border>())
                        {
                            Setters =
                            {
                                new Setter(Border.TransitionsProperty,
                                           new Transitions
                                {
                                    new DoubleTransition
                                    {
                                        Property = Border.OpacityProperty,
                                        Duration = TimeSpan.FromSeconds(1),
                                    },
                                }),
                            },
                        },
                        new Style(x => x.OfType <Border>().Class("foo"))
                        {
                            Setters =
                            {
                                new Setter(Border.TransitionsProperty,
                                           new Transitions
                                {
                                    new DoubleTransition
                                    {
                                        Property = Border.OpacityProperty,
                                        Duration = TimeSpan.FromSeconds(1),
                                    },
                                }),
                                new Setter(Border.OpacityProperty, 0.0),
                            },
                        },
                    },
                    Child = target = new Border
                    {
                        Background = Brushes.Red,
                    }
                };

                root.Measure(Size.Infinity);
                root.Arrange(new Rect(root.DesiredSize));

                target.Classes.Add("foo");
                clock.Step(TimeSpan.FromSeconds(0));
                clock.Step(TimeSpan.FromSeconds(0.5));

                Assert.Equal(0.5, target.Opacity);

                target.Classes.Remove("foo");
            }
        }
Exemple #5
0
        public void Cancellation_Of_Completed_Animation_Does_Not_Fail()
        {
            var keyframe1 = new KeyFrame()
            {
                Setters =
                {
                    new Setter(Border.WidthProperty, 200d),
                },
                Cue = new Cue(1d)
            };

            var keyframe2 = new KeyFrame()
            {
                Setters =
                {
                    new Setter(Border.WidthProperty, 100d),
                },
                Cue = new Cue(0d)
            };

            var animation = new Animation()
            {
                Duration = TimeSpan.FromSeconds(10),
                Delay    = TimeSpan.FromSeconds(0),
                DelayBetweenIterations = TimeSpan.FromSeconds(0),
                IterationCount         = new IterationCount(1),
                Children =
                {
                    keyframe2,
                    keyframe1
                }
            };

            var border = new Border()
            {
                Height = 100d,
                Width  = 50d
            };
            var propertyChangedCount = 0;

            border.PropertyChanged += (sender, e) =>
            {
                if (e.Property == Control.WidthProperty)
                {
                    propertyChangedCount++;
                }
            };

            var clock = new TestClock();
            var cancellationTokenSource = new CancellationTokenSource();
            var animationRun            = animation.RunAsync(border, clock, cancellationTokenSource.Token);

            Assert.Equal(0, propertyChangedCount);

            clock.Step(TimeSpan.FromSeconds(0));
            Assert.False(animationRun.IsCompleted);
            Assert.Equal(1, propertyChangedCount);

            clock.Step(TimeSpan.FromSeconds(10));
            Assert.True(animationRun.IsCompleted);
            Assert.Equal(2, propertyChangedCount);

            cancellationTokenSource.Cancel();
            animationRun.Wait();
        }
Exemple #6
0
        public void Dispose_Subscription_Should_Stop_Animation()
        {
            var keyframe1 = new KeyFrame()
            {
                Setters =
                {
                    new Setter(Border.WidthProperty, 200d),
                },
                Cue = new Cue(1d)
            };

            var keyframe2 = new KeyFrame()
            {
                Setters =
                {
                    new Setter(Border.WidthProperty, 100d),
                },
                Cue = new Cue(0d)
            };

            var animation = new Animation()
            {
                Duration = TimeSpan.FromSeconds(10),
                Delay    = TimeSpan.FromSeconds(0),
                DelayBetweenIterations = TimeSpan.FromSeconds(0),
                IterationCount         = new IterationCount(1),
                Children =
                {
                    keyframe2,
                    keyframe1
                }
            };

            var border = new Border()
            {
                Height = 100d,
                Width  = 50d
            };
            var propertyChangedCount    = 0;
            var animationCompletedCount = 0;

            border.PropertyChanged += (sender, e) =>
            {
                if (e.Property == Control.WidthProperty)
                {
                    propertyChangedCount++;
                }
            };

            var clock      = new TestClock();
            var disposable = animation.Apply(border, clock, Observable.Return(true), () => animationCompletedCount++);

            Assert.Equal(0, propertyChangedCount);

            clock.Step(TimeSpan.FromSeconds(0));
            Assert.Equal(0, animationCompletedCount);
            Assert.Equal(1, propertyChangedCount);

            disposable.Dispose();

            // Clock ticks should be ignored after Dispose
            clock.Step(TimeSpan.FromSeconds(5));
            clock.Step(TimeSpan.FromSeconds(6));
            clock.Step(TimeSpan.FromSeconds(7));

            // On animation disposing (cancellation) on completed is not invoked (is it expected?)
            Assert.Equal(0, animationCompletedCount);
            // Initial property changed before cancellation + animation value removal.
            Assert.Equal(2, propertyChangedCount);
        }