Intermediary checkin, just to mark my place and back up, in case Panther decides...
[ITKit.git] / ITSlideHorizontallyWindowEffect.m
1 #import "ITSlideHorizontallyWindowEffect.h"
2 #import "ITCoreGraphicsHacks.h"
3 #import "ITTransientStatusWindow.h"
4
5
6 @interface ITSlideHorizontallyWindowEffect (Private)
7 - (void)performAppearFromProgress:(float)progress effectTime:(float)time;
8 - (void)appearStep;
9 - (void)appearFinish;
10 - (void)performVanishFromProgress:(float)progress effectTime:(float)time;
11 - (void)vanishStep;
12 - (void)vanishFinish;
13 - (void)setSlide:(float)distance;
14 @end
15
16
17 @implementation ITSlideHorizontallyWindowEffect
18
19
20 + (NSString *)effectName
21 {
22     return @"Slide Horizontally";
23 }
24
25 + (NSDictionary *)supportedPositions
26 {
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];
40 }
41
42
43 /*************************************************************************/
44 #pragma mark -
45 #pragma mark APPEAR METHODS
46 /*************************************************************************/
47
48 - (void)performAppear
49 {
50     __idle = NO;
51
52     [self setWindowVisibility:ITWindowAppearingState];
53     [self performAppearFromProgress:0.0 effectTime:_effectTime];
54 }
55
56 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
57 {
58     [_window setEffectProgress:progress];
59     _effectSpeed = (1.0 / (EFFECT_FPS * time));
60
61     if ( progress == 0.0 ) {
62         [_window setAlphaValue:0.0];
63     }
64
65     [_window orderFront:self];
66     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
67                                                     target:self
68                                                   selector:@selector(appearStep)
69                                                   userInfo:nil
70                                                    repeats:YES];
71 }
72
73 - (void)appearStep
74 {
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];
81
82     if ( [_window effectProgress] >= 1.0 ) {
83         [self appearFinish];
84     }
85 }
86
87 - (void)appearFinish
88 {
89     [_effectTimer invalidate];
90     _effectTimer = nil;
91     [self setWindowVisibility:ITWindowVisibleState];
92
93     __idle = YES;
94
95     if ( __shouldReleaseWhenIdle ) {
96         [self release];
97     }
98 }
99
100 - (void)cancelAppear
101 {
102     [self setWindowVisibility:ITWindowVanishingState];
103
104     [_effectTimer invalidate];
105     _effectTimer = nil;
106
107     [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 4.0)];
108 }
109
110
111 /*************************************************************************/
112 #pragma mark -
113 #pragma mark VANISH METHODS
114 /*************************************************************************/
115
116 - (void)performVanish
117 {
118     __idle = NO;
119
120     [self setWindowVisibility:ITWindowVanishingState];
121     [self performVanishFromProgress:1.0 effectTime:_effectTime];
122 }
123
124 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
125 {
126     [_window setEffectProgress:progress];
127     _effectSpeed = (1.0 / (EFFECT_FPS * time));
128     if ( progress == 1.0 ) {
129         [_window setAlphaValue:1.0];
130     }
131
132     [_window orderFront:self];
133     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
134                                                     target:self
135                                                   selector:@selector(vanishStep)
136                                                   userInfo:nil
137                                                    repeats:YES];
138 }
139
140 - (void)vanishStep
141 {
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];
148
149     if ( [_window effectProgress] <= 0.0 ) {
150         [self vanishFinish];
151     }
152 }
153
154 - (void)vanishFinish
155 {
156     [_effectTimer invalidate];
157     _effectTimer = nil;
158     [_window orderOut:self];
159     [_window setAlphaValue:1.0];
160     [self setSlide:0.0];
161     [self setWindowVisibility:ITWindowHiddenState];
162
163     __idle = YES;
164     
165     if ( __shouldReleaseWhenIdle ) {
166         [self release];
167     }
168 }
169
170 - (void)cancelVanish
171 {
172     [self setWindowVisibility:ITWindowAppearingState];
173
174     [_effectTimer invalidate];
175     _effectTimer = nil;
176
177     [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 4.0)];
178 }
179
180 - (void)setSlide:(float)distance
181 {
182     CGAffineTransform transform;
183     float yPoint;
184     
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;
191     }
192     
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 ) );
199     }*/
200     
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),
202                                                  yPoint);
203     
204     CGSSetWindowTransform([NSApp contextID],
205                           (CGSWindowID)[_window windowNumber],
206                           transform);
207 }
208 @end