1 #import "ITSlideHorizontallyWindowEffect.h"
2 #import "ITCoreGraphicsHacks.h"
3 #import "ITTransientStatusWindow.h"
6 @interface ITSlideHorizontallyWindowEffect (Private)
7 - (void)performAppearFromProgress:(float)progress effectTime:(float)time;
10 - (void)performVanishFromProgress:(float)progress effectTime:(float)time;
13 - (void)setSlide:(float)distance;
17 @implementation ITSlideHorizontallyWindowEffect
20 + (NSString *)effectName
22 return @"Slide Horizontally";
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:YES], @"Left",
34 [NSNumber numberWithBool:NO], @"Center",
35 [NSNumber numberWithBool:YES], @"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 [_window setAlphaValue:0.0];
65 [_window orderFront:self];
66 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
68 selector:@selector(appearStep)
75 float interSlide = 0.0;
76 [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
77 [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
78 interSlide = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
79 [self setSlide:( [_window frame].size.width - (interSlide * [_window frame].size.width) )];
80 [_window setAlphaValue:interSlide];
82 if ( [_window effectProgress] >= 1.0 ) {
89 [_effectTimer invalidate];
91 [self setWindowVisibility:ITWindowVisibleState];
95 if ( __shouldReleaseWhenIdle ) {
102 [self setWindowVisibility:ITWindowVanishingState];
104 [_effectTimer invalidate];
107 [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 4.0)];
111 /*************************************************************************/
113 #pragma mark VANISH METHODS
114 /*************************************************************************/
116 - (void)performVanish
120 [self setWindowVisibility:ITWindowVanishingState];
121 [self performVanishFromProgress:1.0 effectTime:_effectTime];
124 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
126 [_window setEffectProgress:progress];
127 _effectSpeed = (1.0 / (EFFECT_FPS * time));
128 if ( progress == 1.0 ) {
129 [_window setAlphaValue:1.0];
132 [_window orderFront:self];
133 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
135 selector:@selector(vanishStep)
142 float interSlide = 1.0;
143 [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
144 [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
145 interSlide = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
146 [self setSlide:( [_window frame].size.width - (interSlide * [_window frame].size.width) )];
147 [_window setAlphaValue:interSlide];
149 if ( [_window effectProgress] <= 0.0 ) {
156 [_effectTimer invalidate];
158 [_window orderOut:self];
159 [_window setAlphaValue:1.0];
161 [self setWindowVisibility:ITWindowHiddenState];
165 if ( __shouldReleaseWhenIdle ) {
172 [self setWindowVisibility:ITWindowAppearingState];
174 [_effectTimer invalidate];
177 [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 4.0)];
180 - (void)setSlide:(float)distance
182 CGAffineTransform transform;
185 if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
186 yPoint = ( 64.0 + [[_window screen] visibleFrame].origin.y - [_window frame].size.height );
187 } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
188 yPoint = -( [[_window screen] frame].size.height - ( [_window frame].size.height + 32.0 + [[_window screen] visibleFrame].origin.y) );
189 } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionMiddle ) {
190 yPoint = ( [_window frame].size.height - [[_window screen] visibleFrame].size.height) / 2;
193 /*if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) {
194 transform = CGAffineTransformMakeTranslation((distance - (32.0 + [[_window screen] visibleFrame].origin.x)),
195 ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) ? -( [[_window screen] frame].size.height - ( [_window frame].size.height + 32.0 + [[_window screen] visibleFrame].origin.y) ) : ( 64.0 + [[_window screen] visibleFrame].origin.y - [_window frame].size.height ) );
196 } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionRight ) {
197 transform = CGAffineTransformMakeTranslation(-((([[_window screen] visibleFrame].size.width + [[_window screen] visibleFrame].origin.x) + distance) - 32.0 - [_window frame].size.width),
198 ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) ? -( [[_window screen] frame].size.height - ( [_window frame].size.height + 32.0 + [[_window screen] visibleFrame].origin.y) ) : ( 64.0 + [[_window screen] visibleFrame].origin.y - [_window frame].size.height ) );
201 transform = CGAffineTransformMakeTranslation( ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) ? (distance - (32.0 + [[_window screen] visibleFrame].origin.x)) : -((([[_window screen] visibleFrame].size.width + [[_window screen] visibleFrame].origin.x) + distance) - 32.0 - [_window frame].size.width),
204 CGSSetWindowTransform([NSApp contextID],
205 (CGSWindowID)[_window windowNumber],