26 CPViewAnimationTargetKey =
@"CPViewAnimationTargetKey";
27 CPViewAnimationStartFrameKey =
@"CPViewAnimationStartFrameKey";
28 CPViewAnimationEndFrameKey =
@"CPViewAnimationEndFrameKey";
29 CPViewAnimationEffectKey =
@"CPViewAnimationEffectKey";
31 CPViewAnimationFadeInEffect =
@"CPViewAnimationFadeInEffect";
32 CPViewAnimationFadeOutEffect =
@"CPViewAnimationFadeOutEffect";
43 CPArray _viewAnimations;
73 - (id)initWithViewAnimations:(CPArray)viewAnimations
77 [
self setViewAnimations:viewAnimations];
83 - (void)startAnimation
85 var animationIndex = [_viewAnimations count];
86 while (animationIndex--)
88 var dictionary = [_viewAnimations objectAtIndex:animationIndex],
89 view = [
self _targetView:dictionary],
90 startFrame = [
self _startFrame:dictionary];
92 [view setFrame:startFrame];
94 var effect = [
self _effect:dictionary];
95 if (effect === CPViewAnimationFadeInEffect)
97 [view setAlphaValue:0.0];
98 [
self _targetView:view setHidden:NO];
100 else if (effect === CPViewAnimationFadeOutEffect)
101 [view setAlphaValue:1.0];
104 [
super startAnimation];
107 - (void)setCurrentProgress:(
float)progress
109 [
super setCurrentProgress:progress];
111 var animationIndex = [_viewAnimations count];
112 while (animationIndex--)
114 var dictionary = [_viewAnimations objectAtIndex:animationIndex],
115 view = [
self _targetView:dictionary],
116 startFrame = [
self _startFrame:dictionary],
117 endFrame = [
self _endFrame:dictionary],
118 differenceFrame = CGRectMakeZero(),
119 value = [
super currentValue];
121 differenceFrame.origin.x = endFrame.origin.x - startFrame.origin.x;
122 differenceFrame.origin.y = endFrame.origin.y - startFrame.origin.y;
123 differenceFrame.size.width = endFrame.size.width - startFrame.size.
width;
124 differenceFrame.size.height = endFrame.size.height - startFrame.size.height;
126 var intermediateFrame = CGRectMakeZero();
127 intermediateFrame.origin.x = startFrame.origin.x + differenceFrame.origin.x * value;
128 intermediateFrame.origin.y = startFrame.origin.y + differenceFrame.origin.y * value;
129 intermediateFrame.size.width = startFrame.size.width + differenceFrame.size.
width * value;
130 intermediateFrame.size.height = startFrame.size.height + differenceFrame.size.height * value;
132 [view setFrame:intermediateFrame];
135 var effect = [
self _effect:dictionary];
136 if (effect === CPViewAnimationFadeInEffect)
137 [view setAlphaValue:1.0 * value];
138 else if (effect === CPViewAnimationFadeOutEffect)
139 [view setAlphaValue:1.0 + ( 0.0 - 1.0 ) * value];
141 if (progress === 1.0)
142 [
self _targetView:view setHidden:CGRectIsEmpty(endFrame) || [view alphaValue] === 0.0];
146 - (void)stopAnimation
148 var animationIndex = [_viewAnimations count];
149 while (animationIndex--)
151 var dictionary = [_viewAnimations objectAtIndex:animationIndex],
152 view = [
self _targetView:dictionary],
153 endFrame = [
self _endFrame:dictionary];
155 [view setFrame:endFrame];
157 var effect = [
self _effect:dictionary];
158 if (effect === CPViewAnimationFadeInEffect)
159 [view setAlphaValue:1.0];
160 else if (effect === CPViewAnimationFadeOutEffect)
161 [view setAlphaValue:0.0];
163 [
self _targetView:view setHidden:CGRectIsEmpty(endFrame) || [view alphaValue] === 0.0];
166 [
super stopAnimation];
169 - (void)_targetView:(
id)theView setHidden:(BOOL)isHidden
171 if ([theView isKindOfClass:[
CPWindow class]])
174 [theView orderOut:self];
176 [theView orderFront:self];
179 [theView setHidden:isHidden];
184 var targetView = [dictionary
valueForKey:CPViewAnimationTargetKey];
193 var startFrame = [dictionary
valueForKey:CPViewAnimationStartFrameKey];
195 return [[
self _targetView:dictionary] frame];
202 var endFrame = [dictionary
valueForKey:CPViewAnimationEndFrameKey];
204 return [[
self _targetView:dictionary] frame];
211 return [dictionary
valueForKey:CPViewAnimationEffectKey];
214 - (CPArray)viewAnimations
216 return _viewAnimations;
224 - (void)setViewAnimations:(CPArray)viewAnimations
226 if (viewAnimations != _viewAnimations)
228 [
self stopAnimation];
229 _viewAnimations = [viewAnimations copy];