1 #import "ITSpinAndZoomWindowEffect.h"
2 #import "ITCoreGraphicsHacks.h"
3 #import "ITTransientStatusWindow.h"
6 @interface ITSpinAndZoomWindowEffect (Private)
7 - (void)performAppearFromProgress:(float)progress effectTime:(float)time;
10 - (void)performVanishFromProgress:(float)progress effectTime:(float)time;
13 - (void)setScale:(float)scale angle:(float)angle;
17 @implementation ITSpinAndZoomWindowEffect
20 + (NSString *)effectName
22 return @"Spin & Zoom";
25 + (NSDictionary *)supportedPositions
27 return [NSDictionary dictionaryWithObjectsAndKeys:
28 [NSDictionary dictionaryWithObjectsAndKeys:
29 [NSNumber numberWithBool:YES], @"Left",
30 [NSNumber numberWithBool:YES], @"Center",
31 [NSNumber numberWithBool:YES], @"Right", nil] , @"Top" ,
32 [NSDictionary dictionaryWithObjectsAndKeys:
33 [NSNumber numberWithBool:YES], @"Left",
34 [NSNumber numberWithBool:YES], @"Center",
35 [NSNumber numberWithBool:YES], @"Right", nil] , @"Middle" ,
36 [NSDictionary dictionaryWithObjectsAndKeys:
37 [NSNumber numberWithBool:YES], @"Left",
38 [NSNumber numberWithBool:YES], @"Center",
39 [NSNumber numberWithBool:YES], @"Right", nil] , @"Bottom" , nil];
43 + (unsigned int)listOrder
49 /*************************************************************************/
51 #pragma mark APPEAR METHODS
52 /*************************************************************************/
58 [self setWindowVisibility:ITWindowAppearingState];
59 [self performAppearFromProgress:0.0 effectTime:_effectTime];
62 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
64 [_window setEffectProgress:progress];
65 _effectSpeed = (1.0 / (EFFECT_FPS * time));
67 if ( progress == 0.0 ) {
68 [self setScale:0.0 angle:0.0];
69 [_window setAlphaValue:0.0];
72 [_window orderFront:self];
73 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
75 selector:@selector(appearStep)
82 float interSpin = 0.0;
83 [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
84 [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
85 interSpin = (( sin((([_window effectProgress]) * pi) - (pi / 2)) + 1 ) / 2);
86 [self setScale:interSpin angle:-interSpin];
87 [_window setAlphaValue:interSpin];
89 if ( [_window effectProgress] >= 1.0 ) {
96 [_effectTimer invalidate];
98 [self setWindowVisibility:ITWindowVisibleState];
102 if ( __shouldReleaseWhenIdle ) {
109 [self setWindowVisibility:ITWindowVanishingState];
111 [_effectTimer invalidate];
114 [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
118 /*************************************************************************/
120 #pragma mark VANISH METHODS
121 /*************************************************************************/
123 - (void)performVanish
127 [self setWindowVisibility:ITWindowVanishingState];
128 [self performVanishFromProgress:1.0 effectTime:_effectTime];
131 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
133 [_window setEffectProgress:progress];
134 _effectSpeed = (1.0 / (EFFECT_FPS * time));
135 if ( progress == 1.0 ) {
136 [self setScale:1.0 angle:0.0];
137 [_window setAlphaValue:1.0];
140 [_window orderFront:self];
141 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
143 selector:@selector(vanishStep)
150 float interSpin = 1.0;
151 [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
152 [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
153 interSpin = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
154 [self setScale:interSpin angle:interSpin];
155 [_window setAlphaValue:interSpin];
157 if ( [_window effectProgress] <= 0.0 ) {
164 [_effectTimer invalidate];
166 [_window orderOut:self];
167 [_window setAlphaValue:1.0];
168 [self setScale:0.0 angle:0.0];
169 [self setWindowVisibility:ITWindowHiddenState];
173 if ( __shouldReleaseWhenIdle ) {
180 [self setWindowVisibility:ITWindowAppearingState];
182 [_effectTimer invalidate];
185 [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
189 /*************************************************************************/
191 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
192 /*************************************************************************/
194 - (void)setScale:(float)scale angle:(float)angle
196 //int hPos = [_window horizontalPosition];
197 float radAngle = (angle * 4 * pi);
198 CGAffineTransform transform;
200 NSRect screenFrame = [[_window screen] frame];
202 translation.x = /*screenFrame.origin.x + */([_window frame].size.width / 2.0);
203 translation.y = /*screenFrame.origin.y + */([_window frame].size.height / 2.0);
204 transform = CGAffineTransformMakeTranslation(translation.x, translation.y);
205 transform = CGAffineTransformScale(transform, 1.0 / scale, 1.0 / scale);
206 transform = CGAffineTransformRotate(transform, radAngle);
207 transform = CGAffineTransformTranslate(transform, -translation.x, -translation.y);
209 /*if (hPos == ITWindowPositionLeft) {
210 translation.x = -[_window frame].origin.x;
211 } else if (hPos == ITWindowPositionRight) {
212 translation.x = -[_window frame].origin.x;
214 translation.x = -[_window frame].origin.x;
216 translation.x = -[_window frame].origin.x;
217 translation.y = -( screenFrame.size.height - [_window frame].origin.y - [_window frame].size.height );
219 transform = CGAffineTransformTranslate(transform, translation.x, translation.y);
220 CGSSetWindowTransform([NSApp contextID],
221 (CGSWindowID)[_window windowNumber],