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 /*************************************************************************/
22 #pragma mark APPEAR METHODS
23 /*************************************************************************/
29 [self setWindowVisibility:ITWindowAppearingState];
30 [self performAppearFromProgress:0.0 effectTime:_effectTime];
33 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
35 [_window setEffectProgress:progress];
36 _effectSpeed = (1.0 / (EFFECT_FPS * time));
38 if ( progress == 0.0 ) {
39 [self setPivot:315.0];
40 [_window setAlphaValue:0.0];
43 [_window orderFront:self];
44 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
46 selector:@selector(appearStep)
53 float interPivot = 0.0;
54 [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
55 [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
56 interPivot = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
57 [self setPivot:((interPivot * 45) + 315)];
58 [_window setAlphaValue:interPivot];
60 if ( [_window effectProgress] >= 1.0 ) {
67 [_effectTimer invalidate];
69 [self setWindowVisibility:ITWindowVisibleState];
73 if ( __shouldReleaseWhenIdle ) {
80 [self setWindowVisibility:ITWindowVanishingState];
82 [_effectTimer invalidate];
85 [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
89 /*************************************************************************/
91 #pragma mark VANISH METHODS
92 /*************************************************************************/
98 [self setWindowVisibility:ITWindowVanishingState];
99 [self performVanishFromProgress:1.0 effectTime:_effectTime];
102 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
104 [_window setEffectProgress:progress];
105 _effectSpeed = (1.0 / (EFFECT_FPS * time));
106 if ( progress == 1.0 ) {
108 [_window setAlphaValue:1.0];
111 [_window orderFront:self];
112 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
114 selector:@selector(vanishStep)
121 float interPivot = 1.0;
122 [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
123 [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
124 interPivot = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
125 [self setPivot:((interPivot * 45) + 315)];
126 [_window setAlphaValue:interPivot];
128 if ( [_window effectProgress] <= 0.0 ) {
135 [_effectTimer invalidate];
137 [_window orderOut:self];
138 [_window setAlphaValue:1.0];
140 [self setWindowVisibility:ITWindowHiddenState];
144 if ( __shouldReleaseWhenIdle ) {
151 [self setWindowVisibility:ITWindowAppearingState];
153 [_effectTimer invalidate];
156 [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
160 /*************************************************************************/
162 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
163 /*************************************************************************/
165 - (void)setPivot:(float)angle
169 CGAffineTransform transform;
171 if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) {
172 if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
173 degAngle = (angle * (pi / 180));
174 } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
175 degAngle = (-angle * (pi / 180));
177 } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionRight ) {
178 if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
179 degAngle = (angle * (pi / 180));
180 } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
181 degAngle = (-angle * (pi / 180));
185 transform = CGAffineTransformMakeRotation(degAngle);
187 // Set pivot rotation point
188 transform.tx = -( 32.0 + [[_window screen] visibleFrame].origin.x );
189 transform.ty = ( [_window frame].size.height + 32.0 + [[_window screen] visibleFrame].origin.y );
191 if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) {
192 appearPoint.x = -( 32.0 + [[_window screen] visibleFrame].origin.x );
193 } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionRight ) {
194 appearPoint.x = -(([[_window screen] visibleFrame].size.width + [[_window screen] visibleFrame].origin.x) - 32.0 - [_window frame].size.width);
195 } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionCenter ) {
196 appearPoint.x = ( [_window frame].size.width - [[_window screen] visibleFrame].size.width ) / 2;
199 if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
200 appearPoint.y = ( [_window frame].size.height - [[_window screen] visibleFrame].size.height) / 2;
201 } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
202 appearPoint.y = -( [[_window screen] frame].size.height - ([_window frame].origin.y) + 32.0 + [[_window screen] visibleFrame].origin.y) ;
203 }/* else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionMiddle ) {
204 appearPoint.y = ( [_window frame].size.height - [[_window screen] visibleFrame].size.height) / 2;
206 CGSSetWindowTransform([NSApp contextID],
207 (CGSWindowID)[_window windowNumber],
208 CGAffineTransformTranslate( transform,