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;
191 if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
192 yPoint = ( 64.0 + [[_window screen] visibleFrame].origin.y - [_window frame].size.height );
193 } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
194 yPoint = -( [[_window screen] frame].size.height - ( [_window frame].size.height + 32.0 + [[_window screen] visibleFrame].origin.y) );
195 } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionMiddle ) {
196 yPoint = ( [_window frame].size.height - [[_window screen] visibleFrame].size.height) / 2;
199 /*if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) {
200 transform = CGAffineTransformMakeTranslation((distance - (32.0 + [[_window screen] visibleFrame].origin.x)),
201 ( [(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 ) );
202 } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionRight ) {
203 transform = CGAffineTransformMakeTranslation(-((([[_window screen] visibleFrame].size.width + [[_window screen] visibleFrame].origin.x) + distance) - 32.0 - [_window frame].size.width),
204 ( [(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 ) );
207 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),
210 CGSSetWindowTransform([NSApp contextID],
211 (CGSWindowID)[_window windowNumber],