Esempio n. 1
0
        public void ShouldGetValue()
        {
            var testObject = new TestObject {
                Value = 123.4f
            };
            Func <float>   getter   = () => testObject.Value;
            Action <float> setter   = f => { testObject.Value = f; };
            var            property = new DelegateAnimatableProperty <float>(getter, setter);

            Assert.AreEqual(123.4f, property.GetValue());
        }
Esempio n. 2
0
        public void IsAnimatedShouldBeImplemented()
        {
            var testObject = new TestObject();
              Func<float> getter = () => testObject.Value;
              Action<float> setter = f => { testObject.Value = f; };
              var property = new DelegateAnimatableProperty<float>(getter, setter);

              Assert.IsFalse(((IAnimatableProperty)property).IsAnimated);

              ((IAnimatableProperty)property).IsAnimated = true;
              Assert.IsTrue(((IAnimatableProperty)property).IsAnimated);
        }
Esempio n. 3
0
        public void IsAnimatedShouldBeImplemented()
        {
            var            testObject = new TestObject();
            Func <float>   getter     = () => testObject.Value;
            Action <float> setter     = f => { testObject.Value = f; };
            var            property   = new DelegateAnimatableProperty <float>(getter, setter);

            Assert.IsFalse(((IAnimatableProperty)property).IsAnimated);

            ((IAnimatableProperty)property).IsAnimated = true;
            Assert.IsTrue(((IAnimatableProperty)property).IsAnimated);
        }
Esempio n. 4
0
        public AnimatableSprite(string name, SpriteBatch spriteBatch, Texture2D texture)
            : base(spriteBatch, texture)
        {
            Name = name;

            _animatablePosition = new DelegateAnimatableProperty <Vector2>(
                () => Position,
                v => Position = v);

            _animatableColor = new DelegateAnimatableProperty <Color>(
                () => Color,
                c => Color = c);
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AvatarPose"/> class for the given skeleton.
        /// </summary>
        /// <param name="skeleton">The skeleton.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="skeleton"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="skeleton"/> is not a valid Xbox LIVE Avatar skeleton.
        /// </exception>
        public AvatarPose(Skeleton skeleton)
        {
            if (skeleton.NumberOfBones != AvatarRenderer.BoneCount)
            {
                throw new ArgumentException("The specified skeleton is not a valid Avatar skeleton.", "skeleton");
            }

            _expressionWrapper = new DelegateAnimatableProperty <AvatarExpression>(
                () => _expression,     // Getter
                e => _expression = e); // Setter

            _skeletonPose = SkeletonPose.Create(skeleton);
        }
Esempio n. 6
0
        public void AnimateProperty()
        {
            var testObject = new TestObject {
                Value = 10.0f
            };
            Func <float>   getter   = () => testObject.Value;
            Action <float> setter   = f => { testObject.Value = f; };
            var            property = new DelegateAnimatableProperty <float>(null, null);

            var animation = new SingleFromToByAnimation
            {
                From       = 100,
                To         = 200,
                Duration   = TimeSpan.FromSeconds(1.0),
                IsAdditive = true,
            };

            var manager    = new AnimationManager();
            var controller = manager.StartAnimation(animation, property);

            manager.Update(TimeSpan.FromSeconds(0.5));
            manager.ApplyAnimations();

            property.GetValue = getter;
            property.SetValue = setter;

            manager.ApplyAnimations();

            Assert.AreEqual(150.0f, testObject.Value);
            Assert.IsTrue(((IAnimatableProperty)property).IsAnimated);

            manager.Update(TimeSpan.FromSeconds(0.5));
            manager.ApplyAnimations();

            Assert.AreEqual(200.0f, testObject.Value);
            Assert.IsTrue(((IAnimatableProperty)property).IsAnimated);

            controller.Stop();
            controller.UpdateAndApply();
            Assert.AreEqual(200.0f, testObject.Value);
            Assert.IsFalse(((IAnimatableProperty)property).IsAnimated);
        }
Esempio n. 7
0
        public void Constructor()
        {
            var testObject = new TestObject { Value = 123.4f };
              Func<float> getter = () => testObject.Value;
              Action<float> setter = f => { testObject.Value = f; };
              var property = new DelegateAnimatableProperty<float>(getter, setter);

              // Getter, setter
              Assert.AreEqual(getter, property.GetValue);
              Assert.AreEqual(setter, property.SetValue);

              // IAnimatable
              Assert.IsFalse(((IAnimatableProperty)property).HasBaseValue);
              Assert.That(() => { var value = ((IAnimatableProperty)property).BaseValue; }, Throws.TypeOf<NotImplementedException>());
              Assert.IsFalse(((IAnimatableProperty)property).IsAnimated);
              Assert.AreEqual(123.4f, ((IAnimatableProperty)property).AnimationValue);

              // IAnimatable<T>
              Assert.That(() => { var value = ((IAnimatableProperty<float>)property).BaseValue; }, Throws.TypeOf<NotImplementedException>());
              Assert.AreEqual(123.4f, ((IAnimatableProperty<float>)property).AnimationValue);
        }
Esempio n. 8
0
        public void NullValuesShouldBeAllowed()
        {
            var property = new DelegateAnimatableProperty <float>(null, null);

            // Getter, setter
            Assert.AreEqual(null, property.GetValue);
            Assert.AreEqual(null, property.SetValue);

            // IAnimatable
            Assert.IsFalse(((IAnimatableProperty)property).HasBaseValue);
            Assert.That(() => { var value = ((IAnimatableProperty)property).BaseValue; }, Throws.TypeOf <NotImplementedException>());
            Assert.IsFalse(((IAnimatableProperty)property).IsAnimated);
            Assert.AreEqual(null, ((IAnimatableProperty)property).AnimationValue);

            // IAnimatable<T>
            Assert.That(() => { var value = ((IAnimatableProperty <float>)property).BaseValue; }, Throws.TypeOf <NotImplementedException>());
            Assert.AreEqual(0.0f, ((IAnimatableProperty <float>)property).AnimationValue);

            // Should have no effect:
            ((IAnimatableProperty <float>)property).AnimationValue = 100.0f;
        }
Esempio n. 9
0
        public void AnimateProperty()
        {
            var testObject = new TestObject { Value = 10.0f };
              Func<float> getter = () => testObject.Value;
              Action<float> setter = f => { testObject.Value = f; };
              var property = new DelegateAnimatableProperty<float>(null, null);

              var animation = new SingleFromToByAnimation
              {
            From = 100,
            To = 200,
            Duration = TimeSpan.FromSeconds(1.0),
            IsAdditive = true,
              };

              var manager = new AnimationManager();
              var controller = manager.StartAnimation(animation, property);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();

              property.GetValue = getter;
              property.SetValue = setter;

              manager.ApplyAnimations();

              Assert.AreEqual(150.0f, testObject.Value);
              Assert.IsTrue(((IAnimatableProperty)property).IsAnimated);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();

              Assert.AreEqual(200.0f, testObject.Value);
              Assert.IsTrue(((IAnimatableProperty)property).IsAnimated);

              controller.Stop();
              controller.UpdateAndApply();
              Assert.AreEqual(200.0f, testObject.Value);
              Assert.IsFalse(((IAnimatableProperty)property).IsAnimated);
        }
Esempio n. 10
0
        public void Constructor()
        {
            var testObject = new TestObject {
                Value = 123.4f
            };
            Func <float>   getter   = () => testObject.Value;
            Action <float> setter   = f => { testObject.Value = f; };
            var            property = new DelegateAnimatableProperty <float>(getter, setter);

            // Getter, setter
            Assert.AreEqual(getter, property.GetValue);
            Assert.AreEqual(setter, property.SetValue);

            // IAnimatable
            Assert.IsFalse(((IAnimatableProperty)property).HasBaseValue);
            Assert.That(() => { var value = ((IAnimatableProperty)property).BaseValue; }, Throws.TypeOf <NotImplementedException>());
            Assert.IsFalse(((IAnimatableProperty)property).IsAnimated);
            Assert.AreEqual(123.4f, ((IAnimatableProperty)property).AnimationValue);

            // IAnimatable<T>
            Assert.That(() => { var value = ((IAnimatableProperty <float>)property).BaseValue; }, Throws.TypeOf <NotImplementedException>());
            Assert.AreEqual(123.4f, ((IAnimatableProperty <float>)property).AnimationValue);
        }
        public void SnapshotFromDelegateAnimatableProperty()
        {
            var testObject = new TestObject {
                Value = 123.4f
            };
            Func <float>   getter   = () => testObject.Value;
            Action <float> setter   = f => { testObject.Value = f; };
            var            property = new DelegateAnimatableProperty <float>(getter, setter);

            var manager     = new AnimationManager();
            var byAnimation = new SingleFromToByAnimation
            {
                Duration = TimeSpan.Zero,
                By       = 25.0f,
            };

            var controller = manager.StartAnimation(byAnimation, property, AnimationTransitions.SnapshotAndReplace());

            controller.UpdateAndApply();

            // The DelegateAnimatableProperty<T> does not provide a base value.
            // --> No snapshot is created.
            Assert.AreEqual(25.0f, testObject.Value); // 0.0f (SingleTraits.Identity) + 25.0f (By Animation)
        }
Esempio n. 12
0
        public void NullValuesShouldBeAllowed()
        {
            var property = new DelegateAnimatableProperty<float>(null, null);

              // Getter, setter
              Assert.AreEqual(null, property.GetValue);
              Assert.AreEqual(null, property.SetValue);

              // IAnimatable
              Assert.IsFalse(((IAnimatableProperty)property).HasBaseValue);
              Assert.That(() => { var value = ((IAnimatableProperty)property).BaseValue; }, Throws.TypeOf<NotImplementedException>());
              Assert.IsFalse(((IAnimatableProperty)property).IsAnimated);
              Assert.AreEqual(null, ((IAnimatableProperty)property).AnimationValue);

              // IAnimatable<T>
              Assert.That(() => { var value = ((IAnimatableProperty<float>)property).BaseValue; }, Throws.TypeOf<NotImplementedException>());
              Assert.AreEqual(0.0f, ((IAnimatableProperty<float>)property).AnimationValue);

              // Should have no effect:
              ((IAnimatableProperty<float>)property).AnimationValue = 100.0f;
        }
Esempio n. 13
0
        public void ShouldSetValue()
        {
            var testObject = new TestObject { Value = 123.4f };
              Func<float> getter = () => testObject.Value;
              Action<float> setter = f => { testObject.Value = f; };
              var property = new DelegateAnimatableProperty<float>(getter, setter);

              property.SetValue(234.5f);
              Assert.AreEqual(234.5f, ((IAnimatableProperty<float>)property).AnimationValue);
              Assert.AreEqual(234.5f, property.GetValue());
        }
Esempio n. 14
0
        public void SnapshotFromDelegateAnimatableProperty()
        {
            var testObject = new TestObject { Value = 123.4f };
              Func<float> getter = () => testObject.Value;
              Action<float> setter = f => { testObject.Value = f; };
              var property = new DelegateAnimatableProperty<float>(getter, setter);

              var manager = new AnimationManager();
              var byAnimation = new SingleFromToByAnimation
              {
            Duration = TimeSpan.Zero,
            By = 25.0f,
              };

              var controller = manager.StartAnimation(byAnimation, property, AnimationTransitions.SnapshotAndReplace());
              controller.UpdateAndApply();

              // The DelegateAnimatableProperty<T> does not provide a base value.
              // --> No snapshot is created.
              Assert.AreEqual(25.0f, testObject.Value); // 0.0f (SingleTraits.Identity) + 25.0f (By Animation)
        }