Created
October 21, 2009 02:01
-
-
Save Me1000/214781 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation _CPWindowFrameAnimation : CPAnimation | |
{ | |
CPWindow _window; | |
CGRect _startFrame; | |
CGRect _targetFrame; | |
} | |
- (id)initWithWindow:(CPWindow)aWindow targetFrame:(CGRect)aTargetFrame | |
{ | |
var windowFrame = [aWindow frame], | |
deltaX = ABS(windowFrame.origin.x - aTargetFrame.origin.x), | |
deltaY = ABS(windowFrame.origin.y - aTargetFrame.origin.y), | |
deltaHeight = ABS(windowFrame.size.height - aTargetFrame.size.height), | |
deltaWidth = ABS(windowFrame.size.width - aTargetFrame.width), | |
delta = MAX(MAX(deltaX, deltaY), MAX(deltaHeight, deltaWidth)), | |
duration = MAX(0.2, MIN(0.4, delta * 0.0004)); | |
console.log("asd"); | |
self = [super initWithDuration: duration animationCurve:CPAnimationLinear]; | |
if (self) | |
{ | |
_window = aWindow; | |
_targetFrame = CGRectMakeCopy(aTargetFrame); | |
_startFrame = CGRectMakeCopy([_window frame]); | |
} | |
return self; | |
} | |
- (void)startAnimation | |
{ | |
[super startAnimation]; | |
_window._isAnimating = YES; | |
} | |
- (void)setCurrentProgress:(float)aProgress | |
{ | |
[super setCurrentProgress:aProgress]; | |
var value = [self currentValue]; | |
if (value == 1.0) | |
_window._isAnimating = NO; | |
[_window setFrameOrigin:CGPointMake(interpolate(CGRectGetMinX(_startFrame), CGRectGetMinX(_targetFrame), value), interpolate(CGRectGetMinY(_startFrame), CGRectGetMinY(_targetFrame), value))]; | |
[_window setFrameSize:CGSizeMake(interpolate(CGRectGetWidth(_startFrame), CGRectGetWidth(_targetFrame), value), interpolate(CGRectGetHeight(_startFrame), CGRectGetHeight(_targetFrame), value))]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment