3 using System.Collections.Generic;
4 using System.Collections.Specialized;
8 public class EdenEffect : IEdenEffect
10 private float _frameThickness;
11 private EdenData[] _edenFocusData; // Each EdenData 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 (EdenData 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 _edenFocusData = new EdenData[6];
27 EdenData edenData = new EdenData("halo", "halo.png", EdenData.Direction.Horizontal, NDalic.ParentOriginTopCenter,
28 new Vector3(50,20,0), new Vector3(0.0f, 100.0f , 0.0f), 0.0f, _bottomFrameTime);
29 _edenFocusData[0] = edenData;
31 edenData = new EdenData("bottom", "horizontalFrame.png", EdenData.Direction.Horizontal, NDalic.ParentOriginTopCenter,
32 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, _frameThickness, 0.0f), 0.0f, _bottomFrameTime);
33 _edenFocusData[1] = edenData;
35 edenData = new EdenData("left", "verticalFrame.png", EdenData.Direction.Vertical, NDalic.ParentOriginBottomLeft,
36 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(_frameThickness, 0.0f, 0.0f), _bottomFrameTime, _sideFrameTime);
37 _edenFocusData[2] = edenData;
39 edenData = new EdenData("right", "verticalFrame.png", EdenData.Direction.Vertical, NDalic.ParentOriginBottomRight,
40 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(_frameThickness, 0.0f, 0.0f), _bottomFrameTime, _sideFrameTime);
41 _edenFocusData[3] = edenData;
43 edenData = new EdenData("top-left", "horizontalFrame.png", EdenData.Direction.Horizontal, NDalic.ParentOriginBottomLeft,
44 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f ,_frameThickness, 0.0f), _sideFrameTime, _topFrameTime);
45 _edenFocusData[4] = edenData;
47 edenData = new EdenData("top-right", "horizontalFrame.png", EdenData.Direction.Horizontal, NDalic.ParentOriginBottomRight,
48 new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, _frameThickness, 0.0f), _sideFrameTime, _topFrameTime);
49 _edenFocusData[5] = edenData;
52 public void FocusAnimation(View parentItem, Vector3 itemSize, float duration, EdenEffectDirection direction)
54 var itemWidth = itemSize.x + _frameThickness / 2;
55 var itemHeight = itemSize.y + _frameThickness / 3;
62 _animation = new Animation(duration);
64 if (direction == EdenEffectDirection.BottomToTop)
66 _edenFocusData[0].ParentOrigin = NDalic.ParentOriginBottomCenter;
67 _edenFocusData[1].ParentOrigin = NDalic.ParentOriginBottomCenter;
68 _edenFocusData[2].ParentOrigin = NDalic.ParentOriginBottomLeft;
69 _edenFocusData[3].ParentOrigin = NDalic.ParentOriginBottomRight;
70 _edenFocusData[4].ParentOrigin = NDalic.ParentOriginTopLeft;
71 _edenFocusData[5].ParentOrigin = NDalic.ParentOriginTopRight;
75 _edenFocusData[0].ParentOrigin = NDalic.ParentOriginTopCenter;
76 _edenFocusData[1].ParentOrigin = NDalic.ParentOriginTopCenter;
77 _edenFocusData[2].ParentOrigin = NDalic.ParentOriginBottomLeft;
78 _edenFocusData[3].ParentOrigin = NDalic.ParentOriginBottomRight;
79 _edenFocusData[4].ParentOrigin = NDalic.ParentOriginBottomLeft;
80 _edenFocusData[5].ParentOrigin = NDalic.ParentOriginBottomRight;
83 foreach (EdenData edenData in _edenFocusData)
85 var currentParent = edenData.ImageItem.GetParent();
87 // first parent the controls
88 if (parentItem != currentParent)
90 parentItem.Add(edenData.ImageItem);
93 edenData.ImageItem.Size = new Vector3(100.0f,100.0f, 0.0f);
94 parentItem.Add(edenData.ImageItem);
96 Vector3 targetSize = edenData.TargetSize;
97 Vector3 initSize = edenData.InitSize;
99 if (edenData.EdenDirection == EdenData.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 (edenData.Name == "top-right" || edenData.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(edenData.KeyFrameStart, new Property.Value(initSize));
120 keyFrames.Add(edenData.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 (edenData.Name =="halo")
125 keyFrames.Add(edenData.KeyFrameEnd + 0.2f, new Property.Value(initSize));
128 _animation.AnimateBetween(new Property(edenData.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 (edenData.EdenDirection == EdenData.Direction.Vertical)
136 //animate position as well so it looks like animation is coming from bottom
137 KeyFrames keyFramesV = new KeyFrames();
139 if (direction == EdenEffectDirection.BottomToTop)
141 keyFramesV.Add(0.0f, new Property.Value(0.0f));
142 keyFramesV.Add(edenData.KeyFrameStart, new Property.Value(0.0f));
146 keyFramesV.Add(0.0f, new Property.Value(-itemHeight));
147 keyFramesV.Add(edenData.KeyFrameStart, new Property.Value(-itemHeight));
150 keyFramesV.Add(edenData.KeyFrameEnd, new Property.Value(-itemHeight / 2)); // animate to halfway up the control
152 _animation.AnimateBetween(new Property(edenData.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 (edenData.Name == "top-left")
159 KeyFrames keyFramesTL = new KeyFrames();
161 keyFramesTL.Add(0.0f, new Property.Value(0.0f));
162 keyFramesTL.Add(edenData.KeyFrameStart, new Property.Value(0.0f));
163 keyFramesTL.Add(edenData.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(edenData.ImageItem, Actor.Property.POSITION_X), keyFramesTL,
167 new AlphaFunction(AlphaFunction.BuiltinFunction.EASE_OUT_SINE));
170 if (edenData.Name == "top-right")
172 KeyFrames keyFramesTR = new KeyFrames();
174 keyFramesTR.Add(0.0f, new Property.Value(0.0f));
175 keyFramesTR.Add(edenData.KeyFrameStart, new Property.Value(0.0f));
176 keyFramesTR.Add(edenData.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(edenData.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 (EdenData edenData in _edenFocusData)
193 var currentParent = edenData.ImageItem.GetParent();
197 currentParent.Remove(edenData.ImageItem);