public override void OnControlStateChanged(Button button, View.ControlStateChangedEventArgs args)
        {
            if (button.ControlState != ControlState.Pressed)
            {
                return;
            }

            var overlayImage = button.OverlayImage;

            if (overlayImage == null)
            {
                return;
            }

            if (null == PressAnimation)
            {
                var keyFrames = new KeyFrames();
                keyFrames.Add(0.0f, 0.0f);
                AlphaFunction linear = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
                keyFrames.Add(0.25f, 1.0f, linear);
                linear.Dispose();
                AlphaFunction ease = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut);
                keyFrames.Add(1.0f, 0.0f, ease);
                ease.Dispose();

                PressAnimation           = new Animation(600);
                PressAnimation.EndAction = Animation.EndActions.StopFinal;
                PressAnimation.AnimateBetween(overlayImage, "Opacity", keyFrames);
                keyFrames.Dispose();
                Vector3       vec     = new Vector3(1, 1, 1);
                AlphaFunction easeout = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut);
                PressAnimation.AnimateTo(overlayImage, "Scale", vec, 0, 600, easeout);
                vec.Dispose();
                easeout.Dispose();
            }

            if (PressAnimation.State == Animation.States.Playing)
            {
                PressAnimation.Stop();
                overlayImage.Hide();
            }

            overlayImage.Opacity      = 0.0f;
            overlayImage.CornerRadius = button.CornerRadius;
            overlayImage.Background   = button.Background;
            overlayImage.Size         = button.Size;
            overlayImage.Scale        = new Vector3(0.80f, 0.80f, 1);
            overlayImage.Show();

            PressAnimation.Play();
        }
Пример #2
0
        private void PrepareKeyFrames()
        {
            if (_fromKeyFrame != null)
            {
                KeyFrames.Remove(_fromKeyFrame);
            }

            if (_toKeyFrame != null)
            {
                KeyFrames.Remove(_toKeyFrame);
            }

            if (!IsValueNull(From))
            {
                _fromKeyFrame       = new TKeyFrame();
                _fromKeyFrame.Key   = 0f;
                _fromKeyFrame.Value = From;
                KeyFrames.Add(_fromKeyFrame);
            }

            if (!IsValueNull(To))
            {
                _toKeyFrame       = new TKeyFrame();
                _toKeyFrame.Key   = 1f;
                _toKeyFrame.Value = To;
                KeyFrames.Add(_toKeyFrame);
            }
        }
Пример #3
0
        public void KeyFramesAddWithObjectAndAlphaFunc()
        {
            tlog.Debug(tag, $"KeyFramesAddWithObjectAndAlphaFunc START");

            var testingTarget = new KeyFrames();

            Assert.IsNotNull(testingTarget, "should be not null");
            Assert.IsInstanceOf <KeyFrames>(testingTarget, "should be an instance of KeyFrames class!");

            Position      pos    = new Position(10.0f, 20.0f, 30.0f);
            AlphaFunction linear = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);

            try
            {
                testingTarget.Add(0.3f, pos, linear);
                Assert.IsTrue("Vector3" == testingTarget.GetType().ToString());
            }
            catch (Exception e)
            {
                tlog.Error(tag, "Caught Exception" + e.ToString());
                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }

            pos.Dispose();
            linear.Dispose();
            testingTarget.Dispose();
            tlog.Debug(tag, $"KeyFramesAddWithObjectAndAlphaFunc END (OK)");
        }
        protected void PrepareKeyFrames()
        {
            if (FromKeyFrame != null)
            {
                KeyFrames.Remove(FromKeyFrame);
            }

            if (ToKeyFrame != null)
            {
                KeyFrames.Remove(ToKeyFrame);
            }

            if (!IsValueNull(From))
            {
                FromKeyFrame       = new T();
                FromKeyFrame.Key   = 0f;
                FromKeyFrame.Value = From;
                KeyFrames.Add(FromKeyFrame);
            }

            if (!IsValueNull(To))
            {
                ToKeyFrame       = new T();
                ToKeyFrame.Key   = 1f;
                ToKeyFrame.Value = To;
                KeyFrames.Add(ToKeyFrame);
            }
        }
Пример #5
0
        public void KeyFramesAddWithPropertyValueAndAlphaFunc()
        {
            tlog.Debug(tag, $"KeyFramesAddWithPropertyValueAndAlphaFunc START");

            var testingTarget = new KeyFrames();

            Assert.IsNotNull(testingTarget, "should be not null");
            Assert.IsInstanceOf <KeyFrames>(testingTarget, "should be an instance of KeyFrames class!");

            PropertyValue dummy = new PropertyValue(true);
            AlphaFunction ease  = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut);

            try
            {
                testingTarget.Add(0.3f, dummy, ease);
                Assert.IsTrue("Boolean" == testingTarget.GetType().ToString());
            }
            catch (Exception e)
            {
                tlog.Error(tag, "Caught Exception" + e.ToString());
                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }

            dummy.Dispose();
            ease.Dispose();
            testingTarget.Dispose();
            tlog.Debug(tag, $"KeyFramesAddWithPropertyValueAndAlphaFunc END (OK)");
        }
Пример #6
0
        private void ReadUncompressedKeyFrames(BinaryReader reader)
        {
            var keyFrameByOffsetMap = new Dictionary <int, RwKeyFrame>();

            for (int i = 0; i < KeyFrames.Capacity; i++)
            {
                var keyFrame = new RwKeyFrame
                {
                    Time        = reader.ReadSingle(),
                    Rotation    = new Quaternion(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()),
                    Translation = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle())
                };

                int previousKeyFrameOffset = reader.ReadInt32();

                if (keyFrame.Time != 0.0f)
                {
                    keyFrame.Previous = keyFrameByOffsetMap[previousKeyFrameOffset];
                }

                keyFrameByOffsetMap[i * UNCOMPRESSED_KEYFRAME_SIZE] = keyFrame;

                KeyFrames.Add(keyFrame);
            }
        }
Пример #7
0
 public void LoadKeyFrames(List <KeyFrame> keyFrames)
 {
     for (int i = 0; i < keyFrames?.Count; i++)
     {
         KeyFrames.Add(new LytKeyFrame(keyFrames[i]));
     }
 }
Пример #8
0
        public void AnimationAnimateBetweenWithStartTimeAndEndTime()
        {
            tlog.Debug(tag, $"AnimationAnimateBetweenWithStartTimeAndEndTime START");

            View view = new View()
            {
                Opacity = 0.0f
            };

            var keyFrames = new KeyFrames();

            Assert.IsNotNull(keyFrames, "should be not null");
            Assert.IsInstanceOf <KeyFrames>(keyFrames, "should be an instance of Animation class!");
            keyFrames.Add(0.0f, 1.0f);

            var testingTarget = new Animation(600);

            Assert.IsNotNull(testingTarget, "should be not null");
            Assert.IsInstanceOf <Animation>(testingTarget, "should be an instance of Animation class!");

            testingTarget.EndAction = Animation.EndActions.StopFinal;
            testingTarget.AnimateBetween(view, "Opacity", keyFrames, 0, 600);

            testingTarget.Dispose();
            keyFrames.Dispose();
            view.Dispose();
            tlog.Debug(tag, $"AnimationAnimateBetweenWithStartTimeAndEndTime END (OK)");
        }
 public void InsertKey(float frame, float value)
 {
     if (!KeyFrames.Any(x => x.Frame == frame))
     {
         KeyFrames.Add(new STKeyFrame(frame, value));
     }
 }
Пример #10
0
        /// <summary>
        /// Adds a frame
        /// </summary>
        /// <param name="frame">KeyFrame to add</param>
        public void AddKeyFrame(KeyFrame frame)
        {
            if (frame == null)
            {
                return;
            }

            KeyFrames.Add(frame);
            KeyFrames.Sort();
        }
Пример #11
0
        public override void OnControlStateChanged(Button button, ControlStates previousState, Touch touchInfo)
        {
            if (button.ControlState != ControlStates.Pressed)
            {
                return;
            }

            var overlayImage = button.GetCurrentOverlayImage(this);

            if (overlayImage == null)
            {
                return;
            }

            if (null == PressAnimation)
            {
                var keyFrames = new KeyFrames();
                keyFrames.Add(0.0f, 0.0f);
                keyFrames.Add(0.25f, 1.0f, new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear));
                keyFrames.Add(1.0f, 0.0f, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut));

                PressAnimation           = new Animation(600);
                PressAnimation.EndAction = Animation.EndActions.StopFinal;
                PressAnimation.AnimateBetween(overlayImage, "Opacity", keyFrames);
                PressAnimation.AnimateTo(overlayImage, "Scale", new Vector3(1, 1, 1), 0, 600, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut));
            }

            if (PressAnimation.State == Animation.States.Playing)
            {
                PressAnimation.Stop();
                overlayImage.Hide();
            }

            overlayImage.Opacity      = 0.0f;
            overlayImage.CornerRadius = button.CornerRadius;
            overlayImage.Background   = button.Background;
            overlayImage.Size         = button.Size;
            overlayImage.Scale        = new Vector3(0.80f, 0.80f, 1);
            overlayImage.Show();

            PressAnimation.Play();
        }
Пример #12
0
 protected virtual void AddChild(object child)
 {
     if (child is GeometryKeyFrame keyFrame)
     {
         KeyFrames.Add(keyFrame);
     }
     else
     {
         throw new ArgumentException("Animation_ChildMustBeKeyFrame", nameof(child));
     }
 }
        protected virtual void AddChild(object child)
        {
            var keyFrame = child as KeyFrame <T>;

            if (keyFrame == null)
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.CurrentCulture, SR.KeyFramesAnimationBase_ChildNotKeyFrame,
                                        typeof(T).Name), "child");
            }
            KeyFrames.Add(keyFrame);
        }
Пример #14
0
        protected virtual void AddChild(object child)
        {
            ColorKeyFrame keyFrame = child as ColorKeyFrame;

            if (keyFrame != null)
            {
                KeyFrames.Add(keyFrame);
            }
            else
            {
                throw new ArgumentException(SR.Get(SRID.Animation_ChildMustBeKeyFrame), "child");
            }
        }
Пример #15
0
        public bool OnPushButtonClicked1(object sender, EventArgs e)
        {
            if (_isAniFinised == true)
            {
                _isAniFinised = false;
                ////NUILog.Debug("OnPushButtonClicked1()!");

                // Create a new _animation
                if (_animation)
                {
                    //_animation.Stop(Tizen.NUI.Constants.Animation.EndAction.Stop);
                    _animation.Reset();
                }

                _animation = new Animation();
                _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.0f, 0.5f, 0.5f), 0, 1000);
                _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.5f, 0.5f, 0.5f), 1000, 2000);
                _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.0f, 0.0f, 1.0f, 1.0f), 2000, 3000);
                _animation.AnimateTo(_imageView, "PixelArea", new Vector4(0.5f, 0.5f, 0.5f, 0.5f), 3000, 4000);

                KeyFrames _keyFrames = new KeyFrames();
                _keyFrames.Add(0.0f, new Size(0.0f, 0.0f, 0.0f));
                _keyFrames.Add(0.3f, new Size(window.Size.Width * 0.7f, window.Size.Height * 0.7f, 0.0f));
                _keyFrames.Add(1.0f, new Size(window.Size));
                _animation.AnimateBetween(_imageView, "Size", _keyFrames, 4000, 6000, Animation.Interpolation.Linear);

                _animation.EndAction = Animation.EndActions.Discard;

                // Connect the signal callback for animaiton finished signal
                _animation.Finished += AnimationFinished;
                _animation.Finished += AnimationFinished2;

                // Play the _animation
                _animation.Play();
            }

            return(true);
        }
Пример #16
0
            public AnimationTrack(KEY_Parser.Group track)
            {
                InterpolationType = STInterpoaltionType.Hermite;

                foreach (var keyFrame in track.KeyFrames)
                {
                    KeyFrames.Add(new STHermiteKeyFrame()
                    {
                        Frame      = keyFrame.Frame,
                        Value      = keyFrame.Value,
                        TangentIn  = keyFrame.InSlope,
                        TangentOut = keyFrame.OutSlope,
                    });
                }
            }
Пример #17
0
        /// <summary>
        /// Function to read the track data from a data chunk.
        /// </summary>
        /// <param name="chunk">Chunk to read.</param>
        internal void FromChunk(GorgonChunkReader chunk)
        {
            InterpolationMode = chunk.Read <TrackInterpolationMode>();

            // Load all key frames from this track.
            while (chunk.HasChunk("KEYFRAME"))
            {
                IKeyFrame key = MakeKey();

                chunk.Begin("KEYFRAME");
                key.FromChunk(chunk);
                chunk.End();

                KeyFrames.Add(key);
            }
        }
Пример #18
0
        public void KeyFramesGetType()
        {
            tlog.Debug(tag, $"KeyFramesGetType START");

            var testingTarget = new KeyFrames();

            Assert.IsNotNull(testingTarget, "should be not null");
            Assert.IsInstanceOf <KeyFrames>(testingTarget, "should be an instance of KeyFrames class!");

            Color color = Color.Yellow;

            testingTarget.Add(0.3f, color);

            var result = testingTarget.GetType().ToString();

            Assert.IsTrue("Vector4" == result);

            testingTarget.Dispose();
            tlog.Debug(tag, $"KeyFramesGetType END (OK)");
        }
Пример #19
0
        public void KeyFramesAddWithObject()
        {
            tlog.Debug(tag, $"KeyFramesAddWithObject START");

            var testingTarget = new KeyFrames();

            Assert.IsNotNull(testingTarget, "should be not null");
            Assert.IsInstanceOf <KeyFrames>(testingTarget, "should be an instance of KeyFrames class!");

            Position pos = new Position(10.0f, 20.0f, 30.0f);

            testingTarget.Add(0.3f, pos);

            var result = testingTarget.GetType().ToString();

            Assert.IsTrue("Vector3" == result);

            testingTarget.Dispose();
            tlog.Debug(tag, $"KeyFramesAddWithObject END (OK)");
        }
Пример #20
0
            public PaiTagEntry(BinaryDataReader bin, bool FLEU)
            {
                uint tagStart = (uint)bin.Position;

                Index           = bin.ReadByte();
                AnimationTarget = bin.ReadByte();
                DataType        = bin.ReadUInt16();
                var KeyFrameCount = bin.ReadUInt16();

                bin.ReadUInt16();                                      //Padding
                bin.BaseStream.Position = tagStart + bin.ReadUInt32(); //offset to first keyframe
                for (int i = 0; i < KeyFrameCount; i++)
                {
                    KeyFrames.Add(new KeyFrame(bin, DataType));
                }
                if (FLEU)
                {
                    FLEUUnknownInt = bin.ReadUInt32();
                    FLEUEntryName  = bin.ReadString(BinaryStringFormat.ZeroTerminated);
                }
            }
Пример #21
0
        public void KeyFramesAddWithPropertyValue()
        {
            tlog.Debug(tag, $"KeyFramesAddWithPropertyValue START");

            var testingTarget = new KeyFrames();

            Assert.IsNotNull(testingTarget, "should be not null");
            Assert.IsInstanceOf <KeyFrames>(testingTarget, "should be an instance of KeyFrames class!");

            PropertyValue dummy = new PropertyValue(true);

            testingTarget.Add(0.3f, dummy);

            var result = testingTarget.GetType().ToString();

            Assert.IsTrue("Boolean" == result);

            dummy.Dispose();
            testingTarget.Dispose();
            tlog.Debug(tag, $"KeyFramesAddWithPropertyValue END (OK)");
        }
Пример #22
0
        private void DecompressKeyframes(List <RwCompressedKeyFrame> compressedKeyFrames, RwCompressedKeyFrameCustomData customData)
        {
            var keyFrameByOffsetMap = new Dictionary <int, RwKeyFrame>();

            for (int i = 0; i < compressedKeyFrames.Count; i++)
            {
                var compressedKeyFrame = compressedKeyFrames[i];

                var keyFrame = new RwKeyFrame
                {
                    Time     = compressedKeyFrame.Time,
                    Rotation = new Quaternion
                               (
                        DecompressFloat(compressedKeyFrame.RotationX),
                        DecompressFloat(compressedKeyFrame.RotationY),
                        DecompressFloat(compressedKeyFrame.RotationZ),
                        DecompressFloat(compressedKeyFrame.RotationW)
                               ),
                    Translation = new Vector3
                                  (
                        (DecompressFloat(compressedKeyFrame.TranslationX) * customData.Scalar.X) +
                        customData.Offset.X,
                        (DecompressFloat(compressedKeyFrame.TranslationY) * customData.Scalar.Y) +
                        customData.Offset.Y,
                        (DecompressFloat(compressedKeyFrame.TranslationZ) * customData.Scalar.Z) +
                        customData.Offset.Z
                                  )
                };

                if (keyFrame.Time != 0.0f)
                {
                    keyFrame.Previous = keyFrameByOffsetMap[compressedKeyFrame.PreviousFrameOffset];
                }

                keyFrameByOffsetMap[i * COMPRESSED_KEYFRAME_SIZE] = keyFrame;

                keyFrame.Dirty = false;
                KeyFrames.Add(keyFrame);
            }
        }
Пример #23
0
            public AnimTrack(FileReader reader, GameVersion version, bool isShortRotation)
            {
                uint numKeyFrames = 0;

                if (version >= GameVersion.MM3D)
                {
                    reader.ReadByte(); //unk
                    TrackInterpolationType = reader.ReadByte();
                    numKeyFrames           = reader.ReadUInt16();
                }
                else
                {
                    TrackInterpolationType = reader.ReadUInt32();
                    numKeyFrames           = reader.ReadUInt32();
                    uint startFrame = reader.ReadUInt32();
                    uint endFrame   = reader.ReadUInt32();
                }

                if (TrackInterpolationType == (uint)AnimationTrackType.LINEAR)
                {
                    InterpolationType = STInterpoaltionType.Linear;

                    if (version >= GameVersion.MM3D)
                    {
                        float scale = reader.ReadSingle();
                        float bias  = reader.ReadSingle();

                        for (uint i = 0; i < numKeyFrames; i++)
                        {
                            float Value = reader.ReadUInt16() * scale - bias;
                            KeyFrames.Add(new STKeyFrame()
                            {
                                Frame = i,
                                Value = Value
                            });
                        }
                    }
                    else
                    {
                        for (int i = 0; i < numKeyFrames; i++)
                        {
                            if (isShortRotation)
                            {
                                KeyFrames.Add(new STKeyFrame()
                                {
                                    Frame = reader.ReadUInt16(),
                                    Value = (float)reader.ReadUInt16() * 0.001533981f,
                                });
                            }
                            else
                            {
                                KeyFrames.Add(new STKeyFrame()
                                {
                                    Frame = reader.ReadSingle(),
                                    Value = reader.ReadSingle()
                                });
                            }
                        }
                    }
                }
                else if (TrackInterpolationType == (uint)AnimationTrackType.HERMITE)
                {
                    InterpolationType = STInterpoaltionType.Hermite;

                    for (int i = 0; i < numKeyFrames; i++)
                    {
                        if (isShortRotation)
                        {
                            KeyFrames.Add(new STHermiteKeyFrame()
                            {
                                Frame      = reader.ReadUInt16(),
                                Value      = (float)reader.ReadInt16() * 0.001533981f,
                                TangentIn  = (float)reader.ReadInt16() * 0.001533981f,
                                TangentOut = (float)reader.ReadInt16() * 0.001533981f,
                            });
                        }

                        else
                        {
                            KeyFrames.Add(new STHermiteKeyFrame()
                            {
                                Frame      = reader.ReadUInt32(),
                                Value      = reader.ReadSingle(),
                                TangentIn  = reader.ReadSingle(),
                                TangentOut = reader.ReadSingle(),
                            });
                        }
                    }
                }
                else
                {
                    throw new Exception("Unknown interpolation type! " + InterpolationType);
                }
            }
 public void AddChild(PointKeyFrame o)
 {
     KeyFrames.Add(o);
 }
Пример #25
0
 public void AddChild(ColorKeyFrame o)
 {
     KeyFrames.Add(o);
 }
 public void AddChild(DoubleKeyFrame o)
 {
     KeyFrames.Add(o);
 }
Пример #27
0
        /// <summary>
        /// Create Transition between currentTopPage and newTopPage
        /// </summary>
        /// <param name="currentTopPage">The top page of Navigator.</param>
        /// <param name="newTopPage">The new top page after transition.</param>
        /// <param name="pushTransition">True if this transition is for push new page</param>
        private TransitionSet CreateTransition(Page currentTopPage, Page newTopPage, bool pushTransition)
        {
            currentTopPage.SetVisible(true);
            newTopPage.SetVisible(true);

            List <View> taggedViewsInNewTopPage = new List <View>();

            RetrieveTaggedViews(taggedViewsInNewTopPage, newTopPage);
            List <View> taggedViewsInCurrentTopPage = new List <View>();

            RetrieveTaggedViews(taggedViewsInCurrentTopPage, currentTopPage);

            List <KeyValuePair <View, View> > sameTaggedViewPair = new List <KeyValuePair <View, View> >();

            foreach (View currentTopPageView in taggedViewsInCurrentTopPage)
            {
                bool findPair = false;
                foreach (View newTopPageView in taggedViewsInNewTopPage)
                {
                    if ((currentTopPageView.TransitionOptions != null) && (newTopPageView.TransitionOptions != null) &&
                        currentTopPageView.TransitionOptions?.TransitionTag == newTopPageView.TransitionOptions?.TransitionTag)
                    {
                        sameTaggedViewPair.Add(new KeyValuePair <View, View>(currentTopPageView, newTopPageView));
                        findPair = true;
                        break;
                    }
                }
                if (findPair)
                {
                    taggedViewsInNewTopPage.Remove(sameTaggedViewPair[sameTaggedViewPair.Count - 1].Value);
                }
            }
            foreach (KeyValuePair <View, View> pair in sameTaggedViewPair)
            {
                taggedViewsInCurrentTopPage.Remove(pair.Key);
            }

            TransitionSet newTransitionSet = new TransitionSet();

            foreach (KeyValuePair <View, View> pair in sameTaggedViewPair)
            {
                TransitionItem pairTransition = transition.CreateTransition(pair.Key, pair.Value);
                if (pair.Value.TransitionOptions?.TransitionWithChild ?? false)
                {
                    pairTransition.TransitionWithChild = true;
                }
                newTransitionSet.AddTransition(pairTransition);
            }
            newTransitionSet.Play();

            newTransitionSet.Finished += (object sender, EventArgs e) =>
            {
                transitionFinished = true;
                InvokeTransitionFinished();
                transitionSet.Dispose();
                currentTopPage.Opacity = 1.0f;
            };

            // default entering/exit transition - fast fade (half duration compaired with that of view pair transition)
            int       duration        = (transition.TimePeriod.DurationMilliseconds + transition.TimePeriod.DelayMilliseconds);
            float     durationSeconds = (float)duration / 1000.0f;
            Animation fade            = new Animation(0.8f * durationSeconds);

            fade.AnimateTo(currentTopPage, "Opacity", 0.0f);
            KeyFrames keyframes = new KeyFrames();

            keyframes.Add(0.0f, 0.0f);
            keyframes.Add(1.0f, 1.0f);
            fade.AnimateBetween(newTopPage, "Opacity", keyframes);
            fade.Play();

            return(newTransitionSet);
        }
Пример #28
0
        /// <summary>
        /// Animation Sample Application initialisation.
        /// </summary>
        private void Initialize()
        {
            Window.Instance.BackgroundColor = new Color(1.0f, 0.92f, 0.80f, 1.0f);
            View focusIndicator = new View();

            FocusManager.Instance.FocusIndicator = focusIndicator;

            // Create the guide describes how to use this sample application.
            // KEY 1: Play Position animation.
            // KEY 2: Play Size animation.
            // KEY 3: Play Scale animation.
            // KEY 4: Play Orientation animation.
            // KEY 5: Play Visible animation.
            // KEY 6: Play Color animation.
            guide = new TextLabel();
            guide.PositionUsesPivotPoint = true;
            guide.ParentOrigin           = ParentOrigin.BottomRight;
            guide.PivotPoint             = PivotPoint.BottomRight;
            guide.MultiLine = true;
            guide.PointSize = 9.0f;
            guide.Text      = "Animation Sample Guide\n" +
                              "KEY 1: Play Position animation.\n" +
                              "KEY 2: Play Size animation.\n" +
                              "KEY 3: Play Scale animation.\n" +
                              "KEY 4: Play Orientation animation.\n" +
                              "KEY 5: Play Visible animation.\n" +
                              "KEY 6: Play Color animation.";
            Window.Instance.GetDefaultLayer().Add(guide);

            // Create the view to animate.
            view          = new View();
            view.Size2D   = new Size2D(200, 200);
            view.Position = new Position(0, 0, 0);
            view.PositionUsesPivotPoint = true;
            view.PivotPoint             = PivotPoint.Center;
            view.ParentOrigin           = ParentOrigin.Center;
            view.BackgroundColor        = Color.Red;

            // Add view on Window.
            Window.Instance.GetDefaultLayer().Add(view);

            // Create the position animation.
            // The duration of the animation is 1.5s;
            positionAnimation          = new Animation();
            positionAnimation.Duration = 1500;
            // Sets the default alpha function for the animation.
            positionAnimation.DefaultAlphaFunction = new AlphaFunction(new Vector2(0.3f, 0), new Vector2(0.15f, 1));
            // To reset the view's position.
            positionAnimation.AnimateTo(view, "Position", new Position(0, 0, 0), 0, 0);

            // Create the position animation using AnimateBy.
            // Animates a property value by relative amount.
            positionAnimation.AnimateBy(view, "Position", new Position(200, 300, 0), 0, 125);
            positionAnimation.AnimateBy(view, "PositionX", -200, 125, 250);
            positionAnimation.AnimateBy(view, "PositionY", -300, 250, 375);
            positionAnimation.AnimateBy(view, "PositionZ", 0, 375, 500);

            // Create the position animation using AnimatePath.
            // Animates an view's position through a predefined path.
            Path path = new Path();

            path.AddPoint(new Position(300, 0, 0));
            path.AddPoint(new Position(300, 400, 0));
            path.AddPoint(new Position(0, 0, 0));
            path.GenerateControlPoints(0.5f);
            positionAnimation.AnimatePath(view, path, new Vector3(0, 0, 0), 500, 1000);

            // Create the position animation using AnimateBetween.
            // Animates position between keyframes.
            KeyFrames keyFrames = new KeyFrames();

            keyFrames.Add(0.0f, new Vector3(0, 0, 0));
            keyFrames.Add(0.3f, new Vector3(100, 200, 0));
            keyFrames.Add(0.6f, new Vector3(100, 0, 0));
            keyFrames.Add(1.0f, new Vector3(0, 0, 0));
            positionAnimation.AnimateBetween(view, "Position", keyFrames, 1000, 1500);

            // Create the size animation using AnimateTo.
            sizeAnimation = new Animation(1000);
            sizeAnimation.AnimateTo(view, "size", new Vector3(view.SizeWidth, view.SizeHeight, 0));
            sizeAnimation.AnimateTo(view, "sizeWidth", view.SizeWidth * 1.25f);
            sizeAnimation.AnimateTo(view, "sizeHeight", view.SizeHeight * 1.25f);
            sizeAnimation.AnimateTo(view, "sizeDepth", 0);

            // Create the scale animation using AnimateTo.
            scaleAnimation = new Animation(1000);
            scaleAnimation.AnimateTo(view, "scale", new Vector3(1.2f, 1.2f, 1.0f), 0, 200, new AlphaFunction(AlphaFunction.BuiltinFunctions.Sin));
            scaleAnimation.AnimateTo(view, "scaleX", 1.5f, 200, 400, new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear));
            scaleAnimation.AnimateTo(view, "ScaleY", 1.5f, 400, 700, new AlphaFunction(AlphaFunction.BuiltinFunctions.Bounce));
            scaleAnimation.AnimateTo(view, "ScaleZ", 1.0f, 700, 1000, new AlphaFunction(AlphaFunction.BuiltinFunctions.Count));

            // Create the orientation animation using AnimateTo.
            orientationAnimation = new Animation();
            orientationAnimation.AnimateTo(view, "Orientation", new Rotation(new Radian(new Degree(60.0f)), PositionAxis.X), 0, 400);
            orientationAnimation.AnimateTo(view, "Orientation", new Rotation(new Radian(new Degree(60.0f)), PositionAxis.Y), 400, 800);
            orientationAnimation.AnimateTo(view, "Orientation", new Rotation(new Radian(new Degree(60.0f)), PositionAxis.Z), 800, 1000);
            orientationAnimation.AnimateTo(view, "Orientation", new Rotation(new Radian(0.0f), PositionAxis.X), 1000, 1400);
            orientationAnimation.AnimateTo(view, "Orientation", new Rotation(new Radian(0.0f), PositionAxis.Y), 1400, 1800);
            orientationAnimation.AnimateTo(view, "Orientation", new Rotation(new Radian(0.0f), PositionAxis.Z), 1800, 2200);

            // Create the visible animation using AnimateTo.
            visibleAnimation = new Animation();
            visibleAnimation.AnimateTo(view, "Visible", false, 0, 500);
            visibleAnimation.AnimateTo(view, "Visible", true, 500, 1000);

            // Create the color animation using AnimateTo.
            colorAnimation = new Animation();
            colorAnimation.AnimateTo(view, "color", Color.Blue, 0, 200);
            colorAnimation.AnimateTo(view, "colorRed", Color.Red.R, 200, 400);
            colorAnimation.AnimateTo(view, "colorGreen", Color.Red.G, 400, 600);
            colorAnimation.AnimateTo(view, "colorBlue", Color.Red.B, 600, 800);
            colorAnimation.AnimateTo(view, "colorAlpha", Color.Red.A, 800, 100000);

            view.KeyEvent += OnKeyPressed;
            view.Focusable = true;
            FocusManager.Instance.SetCurrentFocusView(view);
            Window.Instance.KeyEvent += AppBack;
        }
Пример #29
0
        /// <summary>
        /// Sets the focused animation.
        /// </summary>
        /// <param name="parentItem">The focus item's parent view</param>
        /// <param name="itemSize">The size of focus view</param>
        /// <param name="duration">the duration in milli seconds of the animation.</param>
        /// <param name="direction">dirction</param>
        public void FocusAnimation(View parentItem, Vector2 itemSize, int duration, FocusEffectDirection direction)
        {
            var itemWidth  = itemSize.Width + _frameThickness / 2;
            var itemHeight = itemSize.Height + _frameThickness / 3;

            // Clear animation.
            if (_animation)
            {
                _animation.Clear();
                _animation.Reset();
            }

            _animation          = new Animation(duration);
            _animation.Duration = duration;

            if (direction == FocusEffectDirection.BottomToTop)
            {
                _focusData[0].ParentOrigin = ParentOrigin.BottomCenter;
                _focusData[1].ParentOrigin = ParentOrigin.BottomCenter;
                _focusData[2].ParentOrigin = ParentOrigin.BottomLeft;
                _focusData[3].ParentOrigin = ParentOrigin.BottomRight;
                _focusData[4].ParentOrigin = ParentOrigin.TopLeft;
                _focusData[5].ParentOrigin = ParentOrigin.TopRight;
            }
            else
            {
                _focusData[0].ParentOrigin = ParentOrigin.TopCenter;
                _focusData[1].ParentOrigin = ParentOrigin.TopCenter;
                _focusData[2].ParentOrigin = ParentOrigin.BottomLeft;
                _focusData[3].ParentOrigin = ParentOrigin.BottomRight;
                _focusData[4].ParentOrigin = ParentOrigin.BottomLeft;
                _focusData[5].ParentOrigin = ParentOrigin.BottomRight;
            }

            foreach (FocusData focusData in _focusData)
            {
                var currentParent = focusData.ImageItem.Parent;

                // first parent the controls
                if (parentItem != currentParent)
                {
                    parentItem.Add(focusData.ImageItem);
                }

                focusData.ImageItem.Size2D = new Vector2(100.0f, 100.0f);
                parentItem.Add(focusData.ImageItem);

                Vector2 targetSize = focusData.TargetSize;
                Vector2 initSize   = focusData.InitSize;

                if (focusData.FocusDirection == FocusData.Direction.Horizontal)
                {
                    // adjust the width to match the parent
                    targetSize.Width = itemWidth;
                }
                else // vertical frame
                {
                    // adjust the height to match the parent
                    targetSize.Height = itemHeight;
                }

                // half the size for the top frame as we come out from both left / right sides
                if (focusData.Name == "top-right" || focusData.Name == "top-left")
                {
                    targetSize.Width = itemWidth - _frameThickness;
                }

                KeyFrames keyFrames = new KeyFrames();

                keyFrames.Add(0.0f, initSize);
                keyFrames.Add(focusData.KeyFrameStart, initSize);
                keyFrames.Add(focusData.KeyFrameEnd, targetSize);

                // for halo add an extra keyframe to shrink it ( in 20% of time after it has finished)
                if (focusData.Name == "halo")
                {
                    keyFrames.Add(focusData.KeyFrameEnd + 0.2f, initSize);
                }

                _animation.AnimateBetween(focusData.ImageItem, "Size", keyFrames, Animation.Interpolation.Linear, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));

                // Simulate the vertical frame growing from the top.
                // Vertical items are anchored to the bottom of the parent... so when they grow
                // we need to move them to the middle of the parent ( otherwise they stick out the bottom)
                if (focusData.FocusDirection == FocusData.Direction.Vertical)
                {
                    //animate position as well so it looks like animation is coming from bottom
                    KeyFrames keyFramesV = new KeyFrames();

                    if (direction == FocusEffectDirection.BottomToTop)
                    {
                        keyFramesV.Add(0.0f, 0.0f);
                        keyFramesV.Add(focusData.KeyFrameStart, 0.0f);
                    }
                    else
                    {
                        keyFramesV.Add(0.0f, -itemHeight);
                        keyFramesV.Add(focusData.KeyFrameStart, -itemHeight);
                    }

                    // animate to halfway up the control
                    keyFramesV.Add(focusData.KeyFrameEnd, (-itemHeight / 2));


                    _animation.AnimateBetween(focusData.ImageItem, "PositionY", keyFramesV, Animation.Interpolation.Linear, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
                }

                // Simulate the top frame growing from the sides.
                if (focusData.Name == "top-left")
                {
                    KeyFrames keyFramesTL = new KeyFrames();

                    keyFramesTL.Add(0.0f, 0.0f);
                    keyFramesTL.Add(focusData.KeyFrameStart, 0.0f);
                    // animate to halfway up the control
                    keyFramesTL.Add(focusData.KeyFrameEnd, (itemWidth / 2));

                    // grow these from the left or right
                    _animation.AnimateBetween(focusData.ImageItem, "PositionX", keyFramesTL, Animation.Interpolation.Linear, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
                }

                if (focusData.Name == "top-right")
                {
                    KeyFrames keyFramesTR = new KeyFrames();

                    keyFramesTR.Add(0.0f, 0.0f);
                    keyFramesTR.Add(focusData.KeyFrameStart, 0.0f);
                    // animate to halfway up the control
                    keyFramesTR.Add(focusData.KeyFrameEnd, (-itemWidth / 2));

                    // grow these from the left or right
                    _animation.AnimateBetween(focusData.ImageItem, "PositionX", keyFramesTR, Animation.Interpolation.Linear, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
                }

                _animation.Finished += OnAnimationFinished;

                _animation.Play();
            }
        }
Пример #30
0
 public void AddChild(DiscreteObjectKeyFrame o)
 {
     KeyFrames.Add(o);
 }