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
205 CGAffineTransform transform;
206 NSRect windowFrame = [_window frame];
207 NSRect screenFrame = [[_window screen] frame];
208 int hPos = [_window horizontalPosition];
209 int vPos = [_window verticalPosition];
213 if ( vPos == ITWindowPositionBottom ) {
214 if ( hPos == ITWindowPositionLeft ) {
216 } else if ( hPos == ITWindowPositionRight ) {
217 angle = ( 45 - -(315 - angle) );
219 } else if ( vPos == ITWindowPositionTop ) {
220 if ( hPos == ITWindowPositionLeft ) {
221 angle = ( 45 - -(315 - angle) );
222 } else if ( hPos == ITWindowPositionRight ) {
227 degAngle = (angle * (pi / 180));
228 transform = CGAffineTransformMakeRotation(degAngle);
230 if ( vPos == ITWindowPositionBottom ) {
231 transform.ty = ( windowFrame.size.height + windowFrame.origin.y);
232 translateY = -(screenFrame.size.height);
233 } else if ( vPos == ITWindowPositionTop ) {
234 transform.ty = -( screenFrame.size.height - windowFrame.origin.y - windowFrame.size.height );
238 if ( hPos == ITWindowPositionLeft ) {
239 transform.tx = -( windowFrame.origin.x );
241 } else if ( hPos == ITWindowPositionRight ) {
242 transform.tx = ( screenFrame.size.width - windowFrame.origin.x );
243 translateX = -(screenFrame.size.width);
246 CGSSetWindowTransform([NSApp contextID],
247 (CGSWindowID)[_window windowNumber],
248 CGAffineTransformTranslate( transform,