3 using System.Collections.Generic;
7 public class FocusEffect : IFocusEffect
9 private float _frameThickness;
10 private FocusData[] _focusData; // Each FocusData is used for one key frame animation (total 6 key frame animations needed for EddenEffect)
11 private Animation _animation; // Animation used to apply all six key frame animations
15 _frameThickness = 10.0f;
16 float _bottomFrameTime = 0.6f; // complete the halo/bottom animation 60% of the way through
17 float _sideFrameTime = 0.8f; // Start the side frame animation after the bottom animation and complete at 80% of the way through
18 float _topFrameTime = 1.0f; // start the top frame animation after the side frame animation and complete at 100% way through
20 // Six key frame animations (FocusData objects) needed for EddenEffect
21 // Two key frame animations for top horizontal effect
22 // Two key frame animations for bottom horizontal effect
23 // Two key frame animations for vertical horizontal effect
24 _focusData = new FocusData[6];
26 FocusData focusData = new FocusData("halo", "halo.png", FocusData.Direction.Horizontal, NDalic.ParentOriginTopCenter,
27 new Vector3(50,20,0), new Vector3(0.0f, 100.0f , 0.0f), 0.0f, _bottomFrameTime);
28 _focusData[0] = focusData;
30 focusData = new FocusData("bottom", "horizontalFrame.png", FocusData.Direction.Horizontal, NDalic.ParentOriginTopCenter,
31 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, _frameThickness, 0.0f), 0.0f, _bottomFrameTime);
32 _focusData[1] = focusData;
34 focusData = new FocusData("left", "verticalFrame.png", FocusData.Direction.Vertical, NDalic.ParentOriginBottomLeft,
35 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(_frameThickness, 0.0f, 0.0f), _bottomFrameTime, _sideFrameTime);
36 _focusData[2] = focusData;
38 focusData = new FocusData("right", "verticalFrame.png", FocusData.Direction.Vertical, NDalic.ParentOriginBottomRight,
39 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(_frameThickness, 0.0f, 0.0f), _bottomFrameTime, _sideFrameTime);
40 _focusData[3] = focusData;
42 focusData = new FocusData("top-left", "horizontalFrame.png", FocusData.Direction.Horizontal, NDalic.ParentOriginBottomLeft,
43 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f ,_frameThickness, 0.0f), _sideFrameTime, _topFrameTime);
44 _focusData[4] = focusData;
46 focusData = new FocusData("top-right", "horizontalFrame.png", FocusData.Direction.Horizontal, NDalic.ParentOriginBottomRight,
47 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, _frameThickness, 0.0f), _sideFrameTime, _topFrameTime);
48 _focusData[5] = focusData;
51 public void FocusAnimation(View parentItem, Vector3 itemSize, float duration, FocusEffectDirection direction)
53 var itemWidth = itemSize.x + _frameThickness / 2;
54 var itemHeight = itemSize.y + _frameThickness / 3;
61 _animation = new Animation(duration);
63 if (direction == FocusEffectDirection.BottomToTop)
65 _focusData[0].ParentOrigin = NDalic.ParentOriginBottomCenter;
66 _focusData[1].ParentOrigin = NDalic.ParentOriginBottomCenter;
67 _focusData[2].ParentOrigin = NDalic.ParentOriginBottomLeft;
68 _focusData[3].ParentOrigin = NDalic.ParentOriginBottomRight;
69 _focusData[4].ParentOrigin = NDalic.ParentOriginTopLeft;
70 _focusData[5].ParentOrigin = NDalic.ParentOriginTopRight;
74 _focusData[0].ParentOrigin = NDalic.ParentOriginTopCenter;
75 _focusData[1].ParentOrigin = NDalic.ParentOriginTopCenter;
76 _focusData[2].ParentOrigin = NDalic.ParentOriginBottomLeft;
77 _focusData[3].ParentOrigin = NDalic.ParentOriginBottomRight;
78 _focusData[4].ParentOrigin = NDalic.ParentOriginBottomLeft;
79 _focusData[5].ParentOrigin = NDalic.ParentOriginBottomRight;
82 foreach (FocusData focusData in _focusData)
84 var currentParent = focusData.ImageItem.GetParent();
86 // first parent the controls
87 if (parentItem != currentParent)
89 parentItem.Add(focusData.ImageItem);
92 focusData.ImageItem.Size = new Vector3(100.0f,100.0f, 0.0f);
93 parentItem.Add(focusData.ImageItem);
95 Vector3 targetSize = focusData.TargetSize;
96 Vector3 initSize = focusData.InitSize;
98 if (focusData.FocusDirection == FocusData.Direction.Horizontal)
100 // adjust the width to match the parent
101 targetSize.x = itemWidth;
103 else // vertical frame
105 // adjust the height to match the parent
106 targetSize.y = itemHeight;
109 // half the size for the top frame as we come out from both left / right sides
110 if (focusData.Name == "top-right" || focusData.Name == "top-left")
112 targetSize.x = itemWidth - _frameThickness;
115 KeyFrames keyFrames = new KeyFrames();
117 keyFrames.Add(0.0f, new Property.Value(initSize));
118 keyFrames.Add(focusData.KeyFrameStart, new Property.Value(initSize));
119 keyFrames.Add(focusData.KeyFrameEnd, new Property.Value(targetSize));
121 // for halo add an extra keyframe to shrink it ( in 20% of time after it has finished)
122 if (focusData.Name =="halo")
124 keyFrames.Add(focusData.KeyFrameEnd + 0.2f, new Property.Value(initSize));
127 _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.SIZE), keyFrames,
128 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
130 // Simulate the vertical frame growing from the top.
131 // Vertical items are anchored to the bottom of the parent... so when they grow
132 // we need to move them to the middle of the parent ( otherwise they stick out the bottom)
133 if (focusData.FocusDirection == FocusData.Direction.Vertical)
135 //animate position as well so it looks like animation is coming from bottom
136 KeyFrames keyFramesV = new KeyFrames();
138 if (direction == FocusEffectDirection.BottomToTop)
140 keyFramesV.Add(0.0f, new Property.Value(0.0f));
141 keyFramesV.Add(focusData.KeyFrameStart, new Property.Value(0.0f));
145 keyFramesV.Add(0.0f, new Property.Value(-itemHeight));
146 keyFramesV.Add(focusData.KeyFrameStart, new Property.Value(-itemHeight));
149 keyFramesV.Add(focusData.KeyFrameEnd, new Property.Value(-itemHeight / 2)); // animate to halfway up the control
151 _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.POSITION_Y), keyFramesV,
152 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
155 // Simulate the top frame growing from the sides.
156 if (focusData.Name == "top-left")
158 KeyFrames keyFramesTL = new KeyFrames();
160 keyFramesTL.Add(0.0f, new Property.Value(0.0f));
161 keyFramesTL.Add(focusData.KeyFrameStart, new Property.Value(0.0f));
162 keyFramesTL.Add(focusData.KeyFrameEnd, new Property.Value(itemWidth / 2)); // animate to halfway up the control
164 // grow these from the left or right
165 _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.POSITION_X), keyFramesTL,
166 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
169 if (focusData.Name == "top-right")
171 KeyFrames keyFramesTR = new KeyFrames();
173 keyFramesTR.Add(0.0f, new Property.Value(0.0f));
174 keyFramesTR.Add(focusData.KeyFrameStart, new Property.Value(0.0f));
175 keyFramesTR.Add(focusData.KeyFrameEnd, new Property.Value(-itemWidth / 2)); // animate to halfway up the control
177 // grow these from the left or right
178 _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.POSITION_X), keyFramesTR,
179 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
182 _animation.Finished += OnAnimationFinished;
188 private void OnAnimationFinished(object source, Animation.FinishedEventArgs e)
190 foreach (FocusData focusData in _focusData)
192 var currentParent = focusData.ImageItem.GetParent();
196 currentParent.Remove(focusData.ImageItem);