Intermediary checkin, just to mark my place and back up, in case Panther decides...
[ITKit.git] / ITDissolveWindowEffect.m
1 #import "ITDissolveWindowEffect.h"
2 #import "ITTransientStatusWindow.h"
3 #import "ITCoreGraphicsHacks.h"
4
5 @interface ITDissolveWindowEffect (Private)
6 - (void)performAppearFromProgress:(float)progress effectTime:(float)time;
7 - (void)appearStep;
8 - (void)appearFinish;
9 - (void)performVanishFromProgress:(float)progress effectTime:(float)time;
10 - (void)vanishStep;
11 - (void)vanishFinish;
12 @end
13
14
15 @implementation ITDissolveWindowEffect
16
17
18 + (NSString *)effectName
19 {
20     return @"Dissolve";
21 }
22
23 + (NSDictionary *)supportedPositions
24 {
25     return [NSDictionary dictionaryWithObjectsAndKeys:
26         [NSDictionary dictionaryWithObjectsAndKeys:
27             [NSNumber numberWithBool:YES], @"Left",
28             [NSNumber numberWithBool:YES], @"Center",
29             [NSNumber numberWithBool:YES], @"Right", nil] , @"Top" ,
30         [NSDictionary dictionaryWithObjectsAndKeys:
31             [NSNumber numberWithBool:YES], @"Left",
32             [NSNumber numberWithBool:YES], @"Center",
33             [NSNumber numberWithBool:YES], @"Right", nil] , @"Middle" ,
34         [NSDictionary dictionaryWithObjectsAndKeys:
35             [NSNumber numberWithBool:YES], @"Left",
36             [NSNumber numberWithBool:YES], @"Center",
37             [NSNumber numberWithBool:YES], @"Right", nil] , @"Bottom" , nil];
38 }
39
40
41 /*************************************************************************/
42 #pragma mark -
43 #pragma mark APPEAR METHODS
44 /*************************************************************************/
45
46 - (void)performAppear
47 {
48     CGAffineTransform transform;
49     NSPoint appearPoint;
50     __idle = NO;
51     
52     //Set the location on the screen
53     if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) {
54         appearPoint.x = -( 32.0 + [[_window screen] visibleFrame].origin.x );
55     } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionRight ) {
56         appearPoint.x = -(([[_window screen] visibleFrame].size.width + [[_window screen] visibleFrame].origin.x) - 32.0 - [_window frame].size.width);
57     } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionCenter ) {
58         appearPoint.x = ( [_window frame].size.width - [[_window screen] visibleFrame].size.width ) / 2;
59     }
60     
61     if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
62         appearPoint.y = ( 64.0 + [[_window screen] visibleFrame].origin.y - [_window frame].size.height );
63     } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
64         appearPoint.y = -( [[_window screen] frame].size.height - ( [_window frame].size.height + 32.0 + [[_window screen] visibleFrame].origin.y) );
65     } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionMiddle ) {
66         appearPoint.y = ( [_window frame].size.height - [[_window screen] visibleFrame].size.height) / 2;
67     }
68     
69     transform = CGAffineTransformMakeTranslation(appearPoint.x, appearPoint.y);
70     CGSSetWindowTransform([NSApp contextID],
71                           (CGSWindowID)[_window windowNumber],
72                           transform);
73     
74     [self setWindowVisibility:ITWindowAppearingState];
75     [self performAppearFromProgress:0.0 effectTime:_effectTime];
76 }
77
78 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
79 {
80     [_window setEffectProgress:progress];
81     _effectSpeed = (1.0 / (EFFECT_FPS * time));
82
83     if ( progress == 0.0 ) {
84         [_window setAlphaValue:0.0];
85     }
86
87     [_window orderFront:self];
88     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
89                                                     target:self
90                                                   selector:@selector(appearStep)
91                                                   userInfo:nil
92                                                    repeats:YES];
93 }
94
95 - (void)appearStep
96 {
97     float interFade = 0.0;
98     [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
99     [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
100     interFade = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
101     [_window setAlphaValue:interFade];
102
103     if ( [_window effectProgress] >= 1.0 ) {
104         [self appearFinish];
105     }
106 }
107
108 - (void)appearFinish
109 {
110     [_effectTimer invalidate];
111     _effectTimer = nil;
112     [self setWindowVisibility:ITWindowVisibleState];
113
114     __idle = YES;
115     
116     if ( __shouldReleaseWhenIdle ) {
117         [self release];
118     }
119 }
120
121 - (void)cancelAppear
122 {
123     [self setWindowVisibility:ITWindowVanishingState];
124
125     [_effectTimer invalidate];
126     _effectTimer = nil;
127
128     [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
129 }
130
131
132 /*************************************************************************/
133 #pragma mark -
134 #pragma mark VANISH METHODS
135 /*************************************************************************/
136
137 - (void)performVanish
138 {
139     __idle = NO;
140     
141     [self setWindowVisibility:ITWindowVanishingState];
142     [self performVanishFromProgress:1.0 effectTime:_effectTime];
143 }
144
145 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
146 {
147     [_window setEffectProgress:progress];
148     _effectSpeed = (1.0 / (EFFECT_FPS * time));
149     if ( progress == 1.0 ) {
150         [_window setAlphaValue:1.0];
151     }
152
153     [_window orderFront:self];
154     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
155                                                     target:self
156                                                   selector:@selector(vanishStep)
157                                                   userInfo:nil
158                                                    repeats:YES];
159 }
160
161 - (void)vanishStep
162 {
163     float interFade = 1.0;
164     [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
165     [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
166     interFade = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
167     [_window setAlphaValue:interFade];
168
169     if ( [_window effectProgress] <= 0.0 ) {
170         [self vanishFinish];
171     }
172 }
173
174 - (void)vanishFinish
175 {
176     [_effectTimer invalidate];
177     _effectTimer = nil;
178     [_window orderOut:self];
179     [_window setAlphaValue:1.0];
180     [self setWindowVisibility:ITWindowHiddenState];
181
182     __idle = YES;
183     
184     if ( __shouldReleaseWhenIdle ) {
185         [self release];
186     }
187 }
188
189 - (void)cancelVanish
190 {
191     [self setWindowVisibility:ITWindowVanishingState];
192
193     [_effectTimer invalidate];
194     _effectTimer = nil;
195
196     [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
197 }
198
199
200 @end