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 /*************************************************************************/
45 #pragma mark APPEAR METHODS
46 /*************************************************************************/
52 [self setWindowVisibility:ITWindowAppearingState];
53 [self performAppearFromProgress:0.0 effectTime:_effectTime];
56 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
58 [_window setEffectProgress:progress];
59 _effectSpeed = (1.0 / (EFFECT_FPS * time));
61 if ( progress == 0.0 ) {
62 [self setPivot:315.0];
63 [_window setAlphaValue:0.0];
66 [_window orderFront:self];
67 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
69 selector:@selector(appearStep)
76 float interPivot = 0.0;
77 [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
78 [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
79 interPivot = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
80 [self setPivot:((interPivot * 45) + 315)];
81 [_window setAlphaValue:interPivot];
83 if ( [_window effectProgress] >= 1.0 ) {
90 [_effectTimer invalidate];
92 [self setWindowVisibility:ITWindowVisibleState];
96 if ( __shouldReleaseWhenIdle ) {
103 [self setWindowVisibility:ITWindowVanishingState];
105 [_effectTimer invalidate];
108 [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
112 /*************************************************************************/
114 #pragma mark VANISH METHODS
115 /*************************************************************************/
117 - (void)performVanish
121 [self setWindowVisibility:ITWindowVanishingState];
122 [self performVanishFromProgress:1.0 effectTime:_effectTime];
125 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
127 [_window setEffectProgress:progress];
128 _effectSpeed = (1.0 / (EFFECT_FPS * time));
129 if ( progress == 1.0 ) {
131 [_window setAlphaValue:1.0];
134 [_window orderFront:self];
135 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
137 selector:@selector(vanishStep)
144 float interPivot = 1.0;
145 [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
146 [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
147 interPivot = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
148 [self setPivot:((interPivot * 45) + 315)];
149 [_window setAlphaValue:interPivot];
151 if ( [_window effectProgress] <= 0.0 ) {
158 [_effectTimer invalidate];
160 [_window orderOut:self];
161 [_window setAlphaValue:1.0];
163 [self setWindowVisibility:ITWindowHiddenState];
167 if ( __shouldReleaseWhenIdle ) {
174 [self setWindowVisibility:ITWindowAppearingState];
176 [_effectTimer invalidate];
179 [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
183 /*************************************************************************/
185 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
186 /*************************************************************************/
188 - (void)setPivot:(float)angle
192 CGAffineTransform transform;
194 if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) {
195 if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
196 degAngle = (angle * (pi / 180));
197 } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
198 degAngle = (-angle * (pi / 180));
200 } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionRight ) {
201 if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
202 degAngle = (angle * (pi / 180));
203 } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
204 degAngle = (angle * (pi / 180));
208 transform = CGAffineTransformMakeRotation(degAngle);
210 // Set pivot rotation point
211 //transform.tx = -( 32.0 + [[_window screen] visibleFrame].origin.x );
212 transform.ty = ( [_window frame].size.height + 32.0 + [[_window screen] visibleFrame].origin.y );
214 if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) {
215 appearPoint.x = -( 32.0 + [[_window screen] visibleFrame].origin.x );
216 transform.tx = -( 32.0 + [[_window screen] visibleFrame].origin.x );
217 } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionRight ) {
218 transform.tx = -( 32.0 + [[_window screen] visibleFrame].origin.x ) + [_window frame].size.width;
219 appearPoint.x = -(([[_window screen] visibleFrame].size.width + [[_window screen] visibleFrame].origin.x) - 64.0);
220 } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionCenter ) {
221 appearPoint.x = ( [_window frame].size.width - [[_window screen] visibleFrame].size.width ) / 2;
224 if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
225 appearPoint.y = ( [_window frame].size.height - [[_window screen] visibleFrame].size.height) / 2;
226 } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
227 appearPoint.y = -( [[_window screen] frame].size.height - ([_window frame].origin.y) + 32.0 + [[_window screen] visibleFrame].origin.y) ;
228 }/* else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionMiddle ) {
229 appearPoint.y = ( [_window frame].size.height - [[_window screen] visibleFrame].size.height) / 2;
231 CGSSetWindowTransform([NSApp contextID],
232 (CGSWindowID)[_window windowNumber],
233 CGAffineTransformTranslate( transform,