3 using System.Collections.Generic;
4 using System.Collections.Specialized;
8 public class FocusEffect : IFocusEffect
10 private float _frameThickness;
11 private FocusData[] _focusData; // Each FocusData is used for one key frame animation (total 6 key frame animations needed for EddenEffect)
12 private Animation _animation; // Animation used to apply all six key frame animations
16 _frameThickness = 10.0f;
17 float _bottomFrameTime = 0.6f; // complete the halo/bottom animation 60% of the way through
18 float _sideFrameTime = 0.8f; // Start the side frame animation after the bottom animation and complete at 80% of the way through
19 float _topFrameTime = 1.0f; // start the top frame animation after the side frame animation and complete at 100% way through
21 // Six key frame animations (FocusData objects) needed for EddenEffect
22 // Two key frame animations for top horizontal effect
23 // Two key frame animations for bottom horizontal effect
24 // Two key frame animations for vertical horizontal effect
25 _focusData = new FocusData[6];
27 FocusData focusData = new FocusData("halo", "halo.png", FocusData.Direction.Horizontal, NDalic.ParentOriginTopCenter,
28 new Vector3(50,20,0), new Vector3(0.0f, 100.0f , 0.0f), 0.0f, _bottomFrameTime);
29 _focusData[0] = focusData;
31 focusData = new FocusData("bottom", "horizontalFrame.png", FocusData.Direction.Horizontal, NDalic.ParentOriginTopCenter,
32 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, _frameThickness, 0.0f), 0.0f, _bottomFrameTime);
33 _focusData[1] = focusData;
35 focusData = new FocusData("left", "verticalFrame.png", FocusData.Direction.Vertical, NDalic.ParentOriginBottomLeft,
36 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(_frameThickness, 0.0f, 0.0f), _bottomFrameTime, _sideFrameTime);
37 _focusData[2] = focusData;
39 focusData = new FocusData("right", "verticalFrame.png", FocusData.Direction.Vertical, NDalic.ParentOriginBottomRight,
40 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(_frameThickness, 0.0f, 0.0f), _bottomFrameTime, _sideFrameTime);
41 _focusData[3] = focusData;
43 focusData = new FocusData("top-left", "horizontalFrame.png", FocusData.Direction.Horizontal, NDalic.ParentOriginBottomLeft,
44 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f ,_frameThickness, 0.0f), _sideFrameTime, _topFrameTime);
45 _focusData[4] = focusData;
47 focusData = new FocusData("top-right", "horizontalFrame.png", FocusData.Direction.Horizontal, NDalic.ParentOriginBottomRight,
48 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, _frameThickness, 0.0f), _sideFrameTime, _topFrameTime);
49 _focusData[5] = focusData;
52 public void FocusAnimation(View parentItem, Vector3 itemSize, float duration, FocusEffectDirection direction)
54 var itemWidth = itemSize.x + _frameThickness / 2;
55 var itemHeight = itemSize.y + _frameThickness / 3;
62 _animation = new Animation(duration);
64 if (direction == FocusEffectDirection.BottomToTop)
66 _focusData[0].ParentOrigin = NDalic.ParentOriginBottomCenter;
67 _focusData[1].ParentOrigin = NDalic.ParentOriginBottomCenter;
68 _focusData[2].ParentOrigin = NDalic.ParentOriginBottomLeft;
69 _focusData[3].ParentOrigin = NDalic.ParentOriginBottomRight;
70 _focusData[4].ParentOrigin = NDalic.ParentOriginTopLeft;
71 _focusData[5].ParentOrigin = NDalic.ParentOriginTopRight;
75 _focusData[0].ParentOrigin = NDalic.ParentOriginTopCenter;
76 _focusData[1].ParentOrigin = NDalic.ParentOriginTopCenter;
77 _focusData[2].ParentOrigin = NDalic.ParentOriginBottomLeft;
78 _focusData[3].ParentOrigin = NDalic.ParentOriginBottomRight;
79 _focusData[4].ParentOrigin = NDalic.ParentOriginBottomLeft;
80 _focusData[5].ParentOrigin = NDalic.ParentOriginBottomRight;
83 foreach (FocusData focusData in _focusData)
85 var currentParent = focusData.ImageItem.GetParent();
87 // first parent the controls
88 if (parentItem != currentParent)
90 parentItem.Add(focusData.ImageItem);
93 focusData.ImageItem.Size = new Vector3(100.0f,100.0f, 0.0f);
94 parentItem.Add(focusData.ImageItem);
96 Vector3 targetSize = focusData.TargetSize;
97 Vector3 initSize = focusData.InitSize;
99 if (focusData.FocusDirection == FocusData.Direction.Horizontal)
101 // adjust the width to match the parent
102 targetSize.x = itemWidth;
104 else // vertical frame
106 // adjust the height to match the parent
107 targetSize.y = itemHeight;
110 // half the size for the top frame as we come out from both left / right sides
111 if (focusData.Name == "top-right" || focusData.Name == "top-left")
113 targetSize.x = itemWidth - _frameThickness;
116 KeyFrames keyFrames = new KeyFrames();
118 keyFrames.Add(0.0f, new Property.Value(initSize));
119 keyFrames.Add(focusData.KeyFrameStart, new Property.Value(initSize));
120 keyFrames.Add(focusData.KeyFrameEnd, new Property.Value(targetSize));
122 // for halo add an extra keyframe to shrink it ( in 20% of time after it has finished)
123 if (focusData.Name =="halo")
125 keyFrames.Add(focusData.KeyFrameEnd + 0.2f, new Property.Value(initSize));
128 _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.SIZE), keyFrames,
129 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
131 // Simulate the vertical frame growing from the top.
132 // Vertical items are anchored to the bottom of the parent... so when they grow
133 // we need to move them to the middle of the parent ( otherwise they stick out the bottom)
134 if (focusData.FocusDirection == FocusData.Direction.Vertical)
136 //animate position as well so it looks like animation is coming from bottom
137 KeyFrames keyFramesV = new KeyFrames();
139 if (direction == FocusEffectDirection.BottomToTop)
141 keyFramesV.Add(0.0f, new Property.Value(0.0f));
142 keyFramesV.Add(focusData.KeyFrameStart, new Property.Value(0.0f));
146 keyFramesV.Add(0.0f, new Property.Value(-itemHeight));
147 keyFramesV.Add(focusData.KeyFrameStart, new Property.Value(-itemHeight));
150 keyFramesV.Add(focusData.KeyFrameEnd, new Property.Value(-itemHeight / 2)); // animate to halfway up the control
152 _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.POSITION_Y), keyFramesV,
153 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
156 // Simulate the top frame growing from the sides.
157 if (focusData.Name == "top-left")
159 KeyFrames keyFramesTL = new KeyFrames();
161 keyFramesTL.Add(0.0f, new Property.Value(0.0f));
162 keyFramesTL.Add(focusData.KeyFrameStart, new Property.Value(0.0f));
163 keyFramesTL.Add(focusData.KeyFrameEnd, new Property.Value(itemWidth / 2)); // animate to halfway up the control
165 // grow these from the left or right
166 _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.POSITION_X), keyFramesTL,
167 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
170 if (focusData.Name == "top-right")
172 KeyFrames keyFramesTR = new KeyFrames();
174 keyFramesTR.Add(0.0f, new Property.Value(0.0f));
175 keyFramesTR.Add(focusData.KeyFrameStart, new Property.Value(0.0f));
176 keyFramesTR.Add(focusData.KeyFrameEnd, new Property.Value(-itemWidth / 2)); // animate to halfway up the control
178 // grow these from the left or right
179 _animation.AnimateBetween(new Property(focusData.ImageItem, Actor.Property.POSITION_X), keyFramesTR,
180 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
183 _animation.Finished += OnAnimationFinished;
189 private void OnAnimationFinished(object source, Animation.FinishedEventArgs e)
191 foreach (FocusData focusData in _focusData)
193 var currentParent = focusData.ImageItem.GetParent();
197 currentParent.Remove(focusData.ImageItem);