This about does it. I want to do a couple more things, especially multiple screen...
[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 + (unsigned int)listOrder
41 {
42     return 200;
43 }
44
45
46 /*************************************************************************/
47 #pragma mark -
48 #pragma mark APPEAR METHODS
49 /*************************************************************************/
50
51 - (void)performAppear
52 {
53     __idle = NO;
54     
55     [self setWindowVisibility:ITWindowAppearingState];
56     [self performAppearFromProgress:0.0 effectTime:_effectTime];
57 }
58
59 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
60 {
61     [_window setEffectProgress:progress];
62     _effectSpeed = (1.0 / (EFFECT_FPS * time));
63
64     if ( progress == 0.0 ) {
65         [_window setAlphaValue:0.0];
66     }
67
68     [_window orderFront:self];
69     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
70                                                     target:self
71                                                   selector:@selector(appearStep)
72                                                   userInfo:nil
73                                                    repeats:YES];
74 }
75
76 - (void)appearStep
77 {
78     float interFade = 0.0;
79     [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
80     [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
81     interFade = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
82     [_window setAlphaValue:interFade];
83
84     if ( [_window effectProgress] >= 1.0 ) {
85         [self appearFinish];
86     }
87 }
88
89 - (void)appearFinish
90 {
91     [_effectTimer invalidate];
92     _effectTimer = nil;
93     [self setWindowVisibility:ITWindowVisibleState];
94
95     __idle = YES;
96     
97     if ( __shouldReleaseWhenIdle ) {
98         [self release];
99     }
100 }
101
102 - (void)cancelAppear
103 {
104     [self setWindowVisibility:ITWindowVanishingState];
105
106     [_effectTimer invalidate];
107     _effectTimer = nil;
108
109     [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
110 }
111
112
113 /*************************************************************************/
114 #pragma mark -
115 #pragma mark VANISH METHODS
116 /*************************************************************************/
117
118 - (void)performVanish
119 {
120     __idle = NO;
121     
122     [self setWindowVisibility:ITWindowVanishingState];
123     [self performVanishFromProgress:1.0 effectTime:_effectTime];
124 }
125
126 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
127 {
128     [_window setEffectProgress:progress];
129     _effectSpeed = (1.0 / (EFFECT_FPS * time));
130     if ( progress == 1.0 ) {
131         [_window setAlphaValue:1.0];
132     }
133
134     [_window orderFront:self];
135     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
136                                                     target:self
137                                                   selector:@selector(vanishStep)
138                                                   userInfo:nil
139                                                    repeats:YES];
140 }
141
142 - (void)vanishStep
143 {
144     float interFade = 1.0;
145     [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
146     [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
147     interFade = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
148     [_window setAlphaValue:interFade];
149
150     if ( [_window effectProgress] <= 0.0 ) {
151         [self vanishFinish];
152     }
153 }
154
155 - (void)vanishFinish
156 {
157     [_effectTimer invalidate];
158     _effectTimer = nil;
159     [_window orderOut:self];
160     [_window setAlphaValue:1.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:ITWindowVanishingState];
173
174     [_effectTimer invalidate];
175     _effectTimer = nil;
176
177     [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
178 }
179
180
181 @end