2 using Tizen.NUI.Constants;
3 using Tizen.NUI.BaseComponents;
5 using System.Collections.Generic;
9 public class FocusEffect : IFocusEffect
11 private float _frameThickness;
12 private FocusData[] _focusData; // Each FocusData is used for one key frame animation (total 6 key frame animations needed for EddenEffect)
13 private Animation _animation; // Animation used to apply all six key frame animations
17 _frameThickness = 10.0f;
18 float _bottomFrameTime = 0.6f; // complete the halo/bottom animation 60% of the way through
19 float _sideFrameTime = 0.8f; // Start the side frame animation after the bottom animation and complete at 80% of the way through
20 float _topFrameTime = 1.0f; // start the top frame animation after the side frame animation and complete at 100% way through
22 // Six key frame animations (FocusData objects) needed for EddenEffect
23 // Two key frame animations for top horizontal effect
24 // Two key frame animations for bottom horizontal effect
25 // Two key frame animations for vertical horizontal effect
26 _focusData = new FocusData[6];
28 FocusData focusData = new FocusData("halo", "halo.png", FocusData.Direction.Horizontal, ParentOrigin.TopCenter,
29 new Size(50.0f, 20.0f, 0.0f), new Size(0.0f, 100.0f, 0.0f), 0.0f, _bottomFrameTime);
30 _focusData[0] = focusData;
32 focusData = new FocusData("bottom", "horizontalFrame.png", FocusData.Direction.Horizontal, ParentOrigin.TopCenter,
33 new Size(0.0f, 0.0f, 0.0f), new Size(0.0f, _frameThickness, 0.0f), 0.0f, _bottomFrameTime);
34 _focusData[1] = focusData;
36 focusData = new FocusData("left", "verticalFrame.png", FocusData.Direction.Vertical, ParentOrigin.BottomLeft,
37 new Size(0.0f, 0.0f, 0.0f), new Size(_frameThickness, 0.0f, 0.0f), _bottomFrameTime, _sideFrameTime);
38 _focusData[2] = focusData;
40 focusData = new FocusData("right", "verticalFrame.png", FocusData.Direction.Vertical, ParentOrigin.BottomRight,
41 new Size(0.0f, 0.0f, 0.0f), new Size(_frameThickness, 0.0f, 0.0f), _bottomFrameTime, _sideFrameTime);
42 _focusData[3] = focusData;
44 focusData = new FocusData("top-left", "horizontalFrame.png", FocusData.Direction.Horizontal, ParentOrigin.BottomLeft,
45 new Size(0.0f, 0.0f, 0.0f), new Size(0.0f, _frameThickness, 0.0f), _sideFrameTime, _topFrameTime);
46 _focusData[4] = focusData;
48 focusData = new FocusData("top-right", "horizontalFrame.png", FocusData.Direction.Horizontal, ParentOrigin.BottomRight,
49 new Size(0.0f, 0.0f, 0.0f), new Size(0.0f, _frameThickness, 0.0f), _sideFrameTime, _topFrameTime);
50 _focusData[5] = focusData;
53 public void FocusAnimation(View parentItem, Size itemSize, int duration, FocusEffectDirection direction)
55 var itemWidth = itemSize.Width + _frameThickness / 2;
56 var itemHeight = itemSize.Height + _frameThickness / 3;
64 _animation = new Animation(duration);
65 _animation.Duration = duration;
67 if (direction == FocusEffectDirection.BottomToTop)
69 _focusData[0].ParentOrigin = ParentOrigin.BottomCenter;
70 _focusData[1].ParentOrigin = ParentOrigin.BottomCenter;
71 _focusData[2].ParentOrigin = ParentOrigin.BottomLeft;
72 _focusData[3].ParentOrigin = ParentOrigin.BottomRight;
73 _focusData[4].ParentOrigin = ParentOrigin.TopLeft;
74 _focusData[5].ParentOrigin = ParentOrigin.TopRight;
78 _focusData[0].ParentOrigin = ParentOrigin.TopCenter;
79 _focusData[1].ParentOrigin = ParentOrigin.TopCenter;
80 _focusData[2].ParentOrigin = ParentOrigin.BottomLeft;
81 _focusData[3].ParentOrigin = ParentOrigin.BottomRight;
82 _focusData[4].ParentOrigin = ParentOrigin.BottomLeft;
83 _focusData[5].ParentOrigin = ParentOrigin.BottomRight;
86 foreach (FocusData focusData in _focusData)
88 var currentParent = focusData.ImageItem.Parent;
90 // first parent the controls
91 if (parentItem != currentParent)
93 parentItem.Add(focusData.ImageItem);
96 focusData.ImageItem.Size = new Size(100.0f, 100.0f, 0.0f);
97 parentItem.Add(focusData.ImageItem);
99 Size targetSize = focusData.TargetSize;
100 Size initSize = focusData.InitSize;
102 if (focusData.FocusDirection == FocusData.Direction.Horizontal)
104 // adjust the width to match the parent
105 targetSize.Width = itemWidth;
107 else // vertical frame
109 // adjust the height to match the parent
110 targetSize.Height = itemHeight;
113 // half the size for the top frame as we come out from both left / right sides
114 if (focusData.Name == "top-right" || focusData.Name == "top-left")
116 targetSize.Width = itemWidth - _frameThickness;
119 KeyFrames keyFrames = new KeyFrames();
121 keyFrames.Add(0.0f, initSize);
122 keyFrames.Add(focusData.KeyFrameStart, initSize);
123 keyFrames.Add(focusData.KeyFrameEnd, targetSize);
125 // for halo add an extra keyframe to shrink it ( in 20% of time after it has finished)
126 if (focusData.Name == "halo")
128 keyFrames.Add(focusData.KeyFrameEnd + 0.2f, initSize);
131 _animation.AnimateBetween(focusData.ImageItem, "Size", keyFrames, Animation.Interpolation.Linear, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
133 // Simulate the vertical frame growing from the top.
134 // Vertical items are anchored to the bottom of the parent... so when they grow
135 // we need to move them to the middle of the parent ( otherwise they stick out the bottom)
136 if (focusData.FocusDirection == FocusData.Direction.Vertical)
138 //animate position as well so it looks like animation is coming from bottom
139 KeyFrames keyFramesV = new KeyFrames();
141 if (direction == FocusEffectDirection.BottomToTop)
143 keyFramesV.Add(0.0f, 0.0f);
144 keyFramesV.Add(focusData.KeyFrameStart, 0.0f);
148 keyFramesV.Add(0.0f, -itemHeight);
149 keyFramesV.Add(focusData.KeyFrameStart, -itemHeight);
152 keyFramesV.Add(focusData.KeyFrameEnd, (-itemHeight / 2)); // animate to halfway up the control
155 _animation.AnimateBetween(focusData.ImageItem, "PositionY", keyFramesV, Animation.Interpolation.Linear, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
160 // Simulate the top frame growing from the sides.
161 if (focusData.Name == "top-left")
163 KeyFrames keyFramesTL = new KeyFrames();
165 keyFramesTL.Add(0.0f, 0.0f);
166 keyFramesTL.Add(focusData.KeyFrameStart, 0.0f);
167 keyFramesTL.Add(focusData.KeyFrameEnd, (itemWidth / 2)); // animate to halfway up the control
169 // grow these from the left or right
170 _animation.AnimateBetween(focusData.ImageItem, "PositionX", keyFramesTL, Animation.Interpolation.Linear, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
175 if (focusData.Name == "top-right")
177 KeyFrames keyFramesTR = new KeyFrames();
179 keyFramesTR.Add(0.0f, 0.0f);
180 keyFramesTR.Add(focusData.KeyFrameStart, 0.0f);
181 keyFramesTR.Add(focusData.KeyFrameEnd, (-itemWidth / 2)); // animate to halfway up the control
183 // grow these from the left or right
184 _animation.AnimateBetween(focusData.ImageItem, "PositionX", keyFramesTR, Animation.Interpolation.Linear, new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine));
188 _animation.Finished += OnAnimationFinished;
194 private void OnAnimationFinished(object source, EventArgs e)
196 foreach (FocusData focusData in _focusData)
198 var currentParent = focusData.ImageItem.Parent;
202 currentParent.Remove(focusData.ImageItem);