Fairly large ITTSW checkin.
[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     [self setWindowVisibility:ITTransientStatusWindowAppearingState];
26     [self performAppearFromProgress:0.0 effectTime:_effectTime];
27 }
28
29 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
30 {
31     [_window setEffectProgress:progress];
32     _effectSpeed = (1.0 / (EFFECT_FPS * time));
33
34     if ( progress == 0.0 ) {
35         [_window setAlphaValue:0.0];
36     }
37
38     [_window orderFront:self];
39     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
40                                                     target:self
41                                                   selector:@selector(appearStep)
42                                                   userInfo:nil
43                                                    repeats:YES];
44 }
45
46 - (void)appearStep
47 {
48     float interFade = 0.0;
49     [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
50     [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
51     interFade = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
52     [_window setAlphaValue:interFade];
53
54     if ( [_window effectProgress] >= 1.0 ) {
55         [self appearFinish];
56     }
57 }
58
59 - (void)appearFinish
60 {
61     [_effectTimer invalidate];
62     _effectTimer = nil;
63     [self setWindowVisibility:ITTransientStatusWindowVisibleState];
64 }
65
66 - (void)cancelAppear
67 {
68     [self setWindowVisibility:ITTransientStatusWindowVanishingState];
69
70     [_effectTimer invalidate];
71     _effectTimer = nil;
72
73     [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
74 }
75
76
77 /*************************************************************************/
78 #pragma mark -
79 #pragma mark VANISH METHODS
80 /*************************************************************************/
81
82 - (void)performVanish
83 {
84     [self setWindowVisibility:ITTransientStatusWindowVanishingState];
85     [self performVanishFromProgress:1.0 effectTime:_effectTime];
86 }
87
88 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
89 {
90     [_window setEffectProgress:progress];
91     _effectSpeed = (1.0 / (EFFECT_FPS * time));
92     if ( progress == 1.0 ) {
93         [_window setAlphaValue:1.0];
94     }
95
96     [_window orderFront:self];
97     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
98                                                     target:self
99                                                   selector:@selector(vanishStep)
100                                                   userInfo:nil
101                                                    repeats:YES];
102 }
103
104 - (void)vanishStep
105 {
106     float interFade = 1.0;
107     [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
108     [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
109     interFade = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
110     [_window setAlphaValue:interFade];
111
112     if ( [_window effectProgress] <= 0.0 ) {
113         [self vanishFinish];
114     }
115 }
116
117 - (void)vanishFinish
118 {
119     [_effectTimer invalidate];
120     _effectTimer = nil;
121     [_window orderOut:self];
122     [_window setAlphaValue:1.0];
123     [self setWindowVisibility:ITTransientStatusWindowHiddenState];
124 }
125
126 - (void)cancelVanish
127 {
128     [self setWindowVisibility:ITTransientStatusWindowVanishingState];
129
130     [_effectTimer invalidate];
131     _effectTimer = nil;
132
133     [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
134 }
135
136
137 @end