Skip to content

Instantly share code, notes, and snippets.

@Me1000
Created October 21, 2009 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Me1000/214781 to your computer and use it in GitHub Desktop.
Save Me1000/214781 to your computer and use it in GitHub Desktop.
@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