From cdaf08d75aed64cffcb54c908eb383b05dd92789 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Fri, 2 Jul 2004 03:39:25 +0000 Subject: [PATCH] Spin & Zoom effect. --- ITKit.xcode/project.pbxproj | 32 +++++ ITSpinAndZoomWindowEffect.h | 23 ++++ ITSpinAndZoomWindowEffect.m | 225 ++++++++++++++++++++++++++++++++++++ ITSpinWindowEffect.m | 2 - ITWindowEffect.m | 1 + 5 files changed, 281 insertions(+), 2 deletions(-) create mode 100755 ITSpinAndZoomWindowEffect.h create mode 100755 ITSpinAndZoomWindowEffect.m diff --git a/ITKit.xcode/project.pbxproj b/ITKit.xcode/project.pbxproj index 3f32676..1e394fa 100755 --- a/ITKit.xcode/project.pbxproj +++ b/ITKit.xcode/project.pbxproj @@ -537,6 +537,34 @@ settings = { }; }; + 3747E3F806950A0D001ACA46 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = ITSpinAndZoomWindowEffect.h; + refType = 4; + sourceTree = ""; + }; + 3747E3F906950A0D001ACA46 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = ITSpinAndZoomWindowEffect.m; + refType = 4; + sourceTree = ""; + }; + 3747E3FA06950A0D001ACA46 = { + fileRef = 3747E3F806950A0D001ACA46; + isa = PBXBuildFile; + settings = { + }; + }; + 3747E3FB06950A0D001ACA46 = { + fileRef = 3747E3F906950A0D001ACA46; + isa = PBXBuildFile; + settings = { + }; + }; 37B3906906923D1200E828B9 = { fileEncoding = 30; isa = PBXFileReference; @@ -1867,6 +1895,8 @@ 372C5812068FE72F00CEF54A, 37B3906906923D1200E828B9, 37B3906A06923D1200E828B9, + 3747E3F806950A0D001ACA46, + 3747E3F906950A0D001ACA46, ); isa = PBXGroup; name = Effects; @@ -2223,6 +2253,7 @@ 7C4BBADC05F98C9900734027, 372C5815068FE72F00CEF54A, 37B3906B06923D1200E828B9, + 3747E3FA06950A0D001ACA46, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -2285,6 +2316,7 @@ 7C4BBADD05F98C9900734027, 372C5814068FE72F00CEF54A, 37B3906C06923D1200E828B9, + 3747E3FB06950A0D001ACA46, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; diff --git a/ITSpinAndZoomWindowEffect.h b/ITSpinAndZoomWindowEffect.h new file mode 100755 index 0000000..5f923ec --- /dev/null +++ b/ITSpinAndZoomWindowEffect.h @@ -0,0 +1,23 @@ +/* + * ITKit + * ITSpinAndZoomWindowEffect + * Effect subclass which Spins (expands/shrinks) a window into position on the screen. + * + * Original Author : Kent Sutherland + * Responsibility : Kent Sutherland + * + * Copyright (c) 2002 - 2004 iThink Software. + * All Rights Reserved + * + */ + + +#import +#import "ITWindowEffect.h" + + +@interface ITSpinAndZoomWindowEffect : ITWindowEffect { + +} + +@end diff --git a/ITSpinAndZoomWindowEffect.m b/ITSpinAndZoomWindowEffect.m new file mode 100755 index 0000000..029b7bd --- /dev/null +++ b/ITSpinAndZoomWindowEffect.m @@ -0,0 +1,225 @@ +#import "ITSpinAndZoomWindowEffect.h" +#import "ITCoreGraphicsHacks.h" +#import "ITTransientStatusWindow.h" + + +@interface ITSpinAndZoomWindowEffect (Private) +- (void)performAppearFromProgress:(float)progress effectTime:(float)time; +- (void)appearStep; +- (void)appearFinish; +- (void)performVanishFromProgress:(float)progress effectTime:(float)time; +- (void)vanishStep; +- (void)vanishFinish; +- (void)setScale:(float)scale angle:(float)angle; +@end + + +@implementation ITSpinAndZoomWindowEffect + + ++ (NSString *)effectName +{ + return @"Spin & Zoom"; +} + ++ (NSDictionary *)supportedPositions +{ + return [NSDictionary dictionaryWithObjectsAndKeys: + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool:YES], @"Left", + [NSNumber numberWithBool:YES], @"Center", + [NSNumber numberWithBool:YES], @"Right", nil] , @"Top" , + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool:YES], @"Left", + [NSNumber numberWithBool:YES], @"Center", + [NSNumber numberWithBool:YES], @"Right", nil] , @"Middle" , + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool:YES], @"Left", + [NSNumber numberWithBool:YES], @"Center", + [NSNumber numberWithBool:YES], @"Right", nil] , @"Bottom" , nil]; +} + + ++ (unsigned int)listOrder +{ + return 600; +} + + +/*************************************************************************/ +#pragma mark - +#pragma mark APPEAR METHODS +/*************************************************************************/ + +- (void)performAppear +{ + __idle = NO; + + [self setWindowVisibility:ITWindowAppearingState]; + [self performAppearFromProgress:0.0 effectTime:_effectTime]; +} + +- (void)performAppearFromProgress:(float)progress effectTime:(float)time +{ + [_window setEffectProgress:progress]; + _effectSpeed = (1.0 / (EFFECT_FPS * time)); + + if ( progress == 0.0 ) { + [self setScale:0.0 angle:0.0]; + [_window setAlphaValue:0.0]; + } + + [_window orderFront:self]; + _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS) + target:self + selector:@selector(appearStep) + userInfo:nil + repeats:YES]; +} + +- (void)appearStep +{ + float interSpin = 0.0; + [_window setEffectProgress:([_window effectProgress] + _effectSpeed)]; + [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)]; + interSpin = (( sin((([_window effectProgress]) * pi) - (pi / 2)) + 1 ) / 2); + [self setScale:interSpin angle:-interSpin]; + [_window setAlphaValue:interSpin]; + + if ( [_window effectProgress] >= 1.0 ) { + [self appearFinish]; + } +} + +- (void)appearFinish +{ + [_effectTimer invalidate]; + _effectTimer = nil; + [self setWindowVisibility:ITWindowVisibleState]; + + __idle = YES; + + if ( __shouldReleaseWhenIdle ) { + [self release]; + } +} + +- (void)cancelAppear +{ + [self setWindowVisibility:ITWindowVanishingState]; + + [_effectTimer invalidate]; + _effectTimer = nil; + + [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)]; +} + + +/*************************************************************************/ +#pragma mark - +#pragma mark VANISH METHODS +/*************************************************************************/ + +- (void)performVanish +{ + __idle = NO; + + [self setWindowVisibility:ITWindowVanishingState]; + [self performVanishFromProgress:1.0 effectTime:_effectTime]; +} + +- (void)performVanishFromProgress:(float)progress effectTime:(float)time +{ + [_window setEffectProgress:progress]; + _effectSpeed = (1.0 / (EFFECT_FPS * time)); + if ( progress == 1.0 ) { + [self setScale:1.0 angle:0.0]; + [_window setAlphaValue:1.0]; + } + + [_window orderFront:self]; + _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS) + target:self + selector:@selector(vanishStep) + userInfo:nil + repeats:YES]; +} + +- (void)vanishStep +{ + float interSpin = 1.0; + [_window setEffectProgress:([_window effectProgress] - _effectSpeed)]; + [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)]; + interSpin = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2); + [self setScale:interSpin angle:interSpin]; + [_window setAlphaValue:interSpin]; + + if ( [_window effectProgress] <= 0.0 ) { + [self vanishFinish]; + } +} + +- (void)vanishFinish +{ + [_effectTimer invalidate]; + _effectTimer = nil; + [_window orderOut:self]; + [_window setAlphaValue:1.0]; + [self setScale:0.0 angle:0.0]; + [self setWindowVisibility:ITWindowHiddenState]; + + __idle = YES; + + if ( __shouldReleaseWhenIdle ) { + [self release]; + } +} + +- (void)cancelVanish +{ + [self setWindowVisibility:ITWindowAppearingState]; + + [_effectTimer invalidate]; + _effectTimer = nil; + + [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)]; +} + + +/*************************************************************************/ +#pragma mark - +#pragma mark PRIVATE METHOD IMPLEMENTATIONS +/*************************************************************************/ + +- (void)setScale:(float)scale angle:(float)angle +{ + int hPos = [_window horizontalPosition]; + float radAngle = (angle * 4 * pi); + CGAffineTransform transform; + NSPoint translation; + NSRect screenFrame = [[_window screen] frame]; + + translation.x = screenFrame.origin.x + ([_window frame].size.width / 2.0); + translation.y = screenFrame.origin.y + ([_window frame].size.height / 2.0); + transform = CGAffineTransformMakeTranslation(translation.x, translation.y); + transform = CGAffineTransformScale(transform, 1.0 / scale, 1.0 / scale); + transform = CGAffineTransformRotate(transform, radAngle); + transform = CGAffineTransformTranslate(transform, -translation.x, -translation.y); + + if (hPos == ITWindowPositionLeft) { + translation.x = -[_window frame].origin.x; + } else if (hPos == ITWindowPositionRight) { + translation.x = -[_window frame].origin.x; + } else { + translation.x = -[_window frame].origin.x; + } + + translation.y = -( [[_window screen] frame].size.height - [_window frame].origin.y - [_window frame].size.height ); + + transform = CGAffineTransformTranslate(transform, translation.x, translation.y); + CGSSetWindowTransform([NSApp contextID], + (CGSWindowID)[_window windowNumber], + transform); +} + +@end diff --git a/ITSpinWindowEffect.m b/ITSpinWindowEffect.m index b3137bf..ad28792 100755 --- a/ITSpinWindowEffect.m +++ b/ITSpinWindowEffect.m @@ -203,7 +203,6 @@ translation.y = screenFrame.origin.y + ([_window frame].size.height / 2.0); transform = CGAffineTransformMakeTranslation(translation.x, translation.y); transform = CGAffineTransformRotate(transform, radAngle); - //transform = CGAffineTransformScale(transform, 1.0 / progress, 1.0 / progress); transform = CGAffineTransformTranslate(transform, -translation.x, -translation.y); if (hPos == ITWindowPositionLeft) { @@ -217,7 +216,6 @@ translation.y = -( [[_window screen] frame].size.height - [_window frame].origin.y - [_window frame].size.height ); transform = CGAffineTransformTranslate(transform, translation.x, translation.y); - CGSSetWindowTransform([NSApp contextID], (CGSWindowID)[_window windowNumber], transform); diff --git a/ITWindowEffect.m b/ITWindowEffect.m index 7111d38..54a73bf 100755 --- a/ITWindowEffect.m +++ b/ITWindowEffect.m @@ -14,6 +14,7 @@ NSClassFromString(@"ITPivotWindowEffect"), NSClassFromString(@"ITZoomWindowEffect"), NSClassFromString(@"ITSpinWindowEffect"), + NSClassFromString(@"ITSpinAndZoomWindowEffect"), nil]; return classes; -- 2.20.1