HUGE ITTSW Checkin. For those only interested in the short version, it is as
[ITKit.git] / ITDissolveWindowEffect.m
1 #import "ITDissolveWindowEffect.h"
2 #import "ITTransientStatusWindow.h"
3
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 /*************************************************************************/
19 #pragma mark -
20 #pragma mark APPEAR METHODS
21 /*************************************************************************/
22
23 - (void)performAppear
24 {
25     __idle = NO;
26     
27     [self setWindowVisibility:ITWindowAppearingState];
28     [self performAppearFromProgress:0.0 effectTime:_effectTime];
29 }
30
31 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
32 {
33     [_window setEffectProgress:progress];
34     _effectSpeed = (1.0 / (EFFECT_FPS * time));
35
36     if ( progress == 0.0 ) {
37         [_window setAlphaValue:0.0];
38     }
39
40     [_window orderFront:self];
41     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
42                                                     target:self
43                                                   selector:@selector(appearStep)
44                                                   userInfo:nil
45                                                    repeats:YES];
46 }
47
48 - (void)appearStep
49 {
50     float interFade = 0.0;
51     [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
52     [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
53     interFade = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
54     [_window setAlphaValue:interFade];
55
56     if ( [_window effectProgress] >= 1.0 ) {
57         [self appearFinish];
58     }
59 }
60
61 - (void)appearFinish
62 {
63     [_effectTimer invalidate];
64     _effectTimer = nil;
65     [self setWindowVisibility:ITWindowVisibleState];
66
67     __idle = YES;
68     
69     if ( __shouldReleaseWhenIdle ) {
70         [self release];
71     }
72 }
73
74 - (void)cancelAppear
75 {
76     [self setWindowVisibility:ITWindowVanishingState];
77
78     [_effectTimer invalidate];
79     _effectTimer = nil;
80
81     [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
82 }
83
84
85 /*************************************************************************/
86 #pragma mark -
87 #pragma mark VANISH METHODS
88 /*************************************************************************/
89
90 - (void)performVanish
91 {
92     __idle = NO;
93     
94     [self setWindowVisibility:ITWindowVanishingState];
95     [self performVanishFromProgress:1.0 effectTime:_effectTime];
96 }
97
98 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
99 {
100     [_window setEffectProgress:progress];
101     _effectSpeed = (1.0 / (EFFECT_FPS * time));
102     if ( progress == 1.0 ) {
103         [_window setAlphaValue:1.0];
104     }
105
106     [_window orderFront:self];
107     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
108                                                     target:self
109                                                   selector:@selector(vanishStep)
110                                                   userInfo:nil
111                                                    repeats:YES];
112 }
113
114 - (void)vanishStep
115 {
116     float interFade = 1.0;
117     [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
118     [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
119     interFade = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
120     [_window setAlphaValue:interFade];
121
122     if ( [_window effectProgress] <= 0.0 ) {
123         [self vanishFinish];
124     }
125 }
126
127 - (void)vanishFinish
128 {
129     [_effectTimer invalidate];
130     _effectTimer = nil;
131     [_window orderOut:self];
132     [_window setAlphaValue:1.0];
133     [self setWindowVisibility:ITWindowHiddenState];
134
135     __idle = YES;
136     
137     if ( __shouldReleaseWhenIdle ) {
138         [self release];
139     }
140 }
141
142 - (void)cancelVanish
143 {
144     [self setWindowVisibility:ITWindowVanishingState];
145
146     [_effectTimer invalidate];
147     _effectTimer = nil;
148
149     [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
150 }
151
152
153 @end