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 + (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 [_window setAlphaValue:0.0];
71 [_window orderFront:self];
72 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
74 selector:@selector(appearStep)
81 float interSlide = 0.0;
82 [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
83 [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
84 interSlide = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
85 [self setSlide:( [_window frame].size.width - (interSlide * [_window frame].size.width) )];
86 [_window setAlphaValue:interSlide];
88 if ( [_window effectProgress] >= 1.0 ) {
95 [_effectTimer invalidate];
97 [self setWindowVisibility:ITWindowVisibleState];
101 if ( __shouldReleaseWhenIdle ) {
108 [self setWindowVisibility:ITWindowVanishingState];
110 [_effectTimer invalidate];
113 [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 4.0)];
117 /*************************************************************************/
119 #pragma mark VANISH METHODS
120 /*************************************************************************/
122 - (void)performVanish
126 [self setWindowVisibility:ITWindowVanishingState];
127 [self performVanishFromProgress:1.0 effectTime:_effectTime];
130 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
132 [_window setEffectProgress:progress];
133 _effectSpeed = (1.0 / (EFFECT_FPS * time));
134 if ( progress == 1.0 ) {
135 [_window setAlphaValue:1.0];
138 [_window orderFront:self];
139 _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
141 selector:@selector(vanishStep)
148 float interSlide = 1.0;
149 [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
150 [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
151 interSlide = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
152 [self setSlide:( [_window frame].size.width - (interSlide * [_window frame].size.width) )];
153 [_window setAlphaValue:interSlide];
155 if ( [_window effectProgress] <= 0.0 ) {
162 [_effectTimer invalidate];
164 [_window orderOut:self];
165 [_window setAlphaValue:1.0];
167 [self setWindowVisibility:ITWindowHiddenState];
171 if ( __shouldReleaseWhenIdle ) {
178 [self setWindowVisibility:ITWindowAppearingState];
180 [_effectTimer invalidate];
183 [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 4.0)];
186 - (void)setSlide:(float)distance
188 CGAffineTransform transform;
190 NSRect winFrame = [_window frame];
192 if ( [_window horizontalPosition] == ITWindowPositionLeft ) {
193 translation.x = ( -(winFrame.origin.x) + distance ) ;
194 } else if ( [_window horizontalPosition] == ITWindowPositionRight ) {
195 translation.x = ( -(winFrame.origin.x) - distance ) ;
197 translation.x = ( -(winFrame.origin.x) ) ;
200 translation.y = winFrame.origin.y + winFrame.size.height - [[NSScreen mainScreen] frame].size.height;
202 transform = CGAffineTransformMakeTranslation( translation.x, translation.y );
204 CGSSetWindowTransform([NSApp contextID],
205 (CGSWindowID)[_window windowNumber],