1 #import "ITPivotWindowEffect.h"
2 #import "ITCoreGraphicsHacks.h"
3 #import "ITTransientStatusWindow.h"
6 @interface ITPivotWindowEffect (Private)
7 - (void)setPivot:(float)angle;
8 - (void)performAppearFromProgress:(float)progress effectTime:(float)time;
11 - (void)performVanishFromProgress:(float)progress effectTime:(float)time;
17 @implementation ITPivotWindowEffect
20 + (NSString *)effectName
25 + (NSDictionary *)supportedPositions
27 return [NSDictionary dictionaryWithObjectsAndKeys:
28 [NSDictionary dictionaryWithObjectsAndKeys:
29 [NSNumber numberWithBool:YES], @"Left",
30 [NSNumber numberWithBool:NO], @"Center",
31 [NSNumber numberWithBool:YES], @"Right", nil] , @"Top" ,
32 [NSDictionary dictionaryWithObjectsAndKeys:
33 [NSNumber numberWithBool:NO], @"Left",
34 [NSNumber numberWithBool:NO], @"Center",
35 [NSNumber numberWithBool:NO], @"Right", nil] , @"Middle" ,
36 [NSDictionary dictionaryWithObjectsAndKeys:
37 [NSNumber numberWithBool:YES], @"Left",
38 [NSNumber numberWithBool:NO], @"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 setPivot:315.0];
69 [_window setAlphaValue:0.0];
72 [_window orderFront:self];
73 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
75 selector:@selector(appearStep)
82 float interPivot = 0.0;
83 float progress = ([_window effectProgress] + _effectSpeed);
85 progress = ( (progress < 1.0) ? progress : 1.0 );
87 [_window setEffectProgress:progress];
89 interPivot = (( sin((progress * pi) - (pi / 2)) + 1 ) / 2);
90 [self setPivot:(315 + (interPivot * 45))];
91 [_window setAlphaValue:interPivot];
93 if ( progress >= 1.0 ) {
100 [_effectTimer invalidate];
102 [self setWindowVisibility:ITWindowVisibleState];
106 if ( __shouldReleaseWhenIdle ) {
113 [self setWindowVisibility:ITWindowVanishingState];
115 [_effectTimer invalidate];
118 [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
122 /*************************************************************************/
124 #pragma mark VANISH METHODS
125 /*************************************************************************/
127 - (void)performVanish
131 [self setWindowVisibility:ITWindowVanishingState];
132 [self performVanishFromProgress:1.0 effectTime:_effectTime];
135 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
137 [_window setEffectProgress:progress];
138 _effectSpeed = (1.0 / (EFFECT_FPS * time));
139 if ( progress == 1.0 ) {
141 [_window setAlphaValue:1.0];
144 [_window orderFront:self];
145 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
147 selector:@selector(vanishStep)
154 float interPivot = 1.0;
155 float progress = ([_window effectProgress] - _effectSpeed);
157 progress = ( (progress > 0.0) ? progress : 0.0);
159 [_window setEffectProgress:progress];
161 interPivot = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
162 [self setPivot:(315 + (interPivot * 45))];
163 [_window setAlphaValue:interPivot];
165 if ( progress <= 0.0 ) {
172 [_effectTimer invalidate];
174 [_window orderOut:self];
175 [_window setAlphaValue:1.0];
177 [self setWindowVisibility:ITWindowHiddenState];
181 if ( __shouldReleaseWhenIdle ) {
188 [self setWindowVisibility:ITWindowAppearingState];
190 [_effectTimer invalidate];
193 [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
197 /*************************************************************************/
199 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
200 /*************************************************************************/
202 - (void)setPivot:(float)angle
204 int hPos = [_window horizontalPosition];
205 int vPos = [_window verticalPosition];
207 if ( (hPos == ITWindowPositionCenter) || (vPos == ITWindowPositionMiddle) ) {
209 CGAffineTransform transform;
212 translation.x = ( -([_window frame].origin.x) ) ;
213 translation.y = -( [[_window screen] frame].size.height - [_window frame].origin.y - [_window frame].size.height );
215 transform = CGAffineTransformMakeTranslation( translation.x, translation.y );
217 CGSSetWindowTransform([NSApp contextID],
218 (CGSWindowID)[_window windowNumber],
223 NSRect windowFrame = [_window frame];
224 NSRect screenFrame = [[_window screen] frame];
225 float translateX = 0;
226 float translateY = 0;
227 CGAffineTransform transform;
229 if ( vPos == ITWindowPositionBottom ) {
230 if ( hPos == ITWindowPositionLeft ) {
232 } else if ( hPos == ITWindowPositionRight ) {
233 angle = ( 45 - -(315 - angle) );
235 } else if ( vPos == ITWindowPositionTop ) {
236 if ( hPos == ITWindowPositionLeft ) {
237 angle = ( 45 - -(315 - angle) );
238 } else if ( hPos == ITWindowPositionRight ) {
243 degAngle = (angle * (pi / 180));
244 transform = CGAffineTransformMakeRotation(degAngle);
246 if ( vPos == ITWindowPositionBottom ) {
247 transform.ty = ( windowFrame.size.height + windowFrame.origin.y);
248 translateY = -(screenFrame.size.height);
249 } else if ( vPos == ITWindowPositionTop ) {
250 transform.ty = -( screenFrame.size.height - windowFrame.origin.y - windowFrame.size.height );
254 if ( hPos == ITWindowPositionLeft ) {
255 transform.tx = -( windowFrame.origin.x );
257 } else if ( hPos == ITWindowPositionRight ) {
258 transform.tx = ( screenFrame.size.width - windowFrame.origin.x );
259 translateX = -(screenFrame.size.width);
262 CGSSetWindowTransform([NSApp contextID],
263 (CGSWindowID)[_window windowNumber],
264 CGAffineTransformTranslate( transform,