Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Perform Focus animation Effect on the current Focused Item on ScrollContainer.
 /// </summary>
 /// <param name="scrollContainer">Scroll Container</param>
 /// <param name="direction">Direction</param>
 private void FocusAnimation(ScrollContainer scrollContainer, FocusEffectDirection direction)
 {
     _focusEffect.FocusAnimation(scrollContainer.GetCurrentFocusedActor(), scrollContainer.ItemSize, 1000, direction);
 }