The dissolve, cut and slides all work properly now, I hope :D
[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 /*************************************************************************/
19 #pragma mark -
20 #pragma mark APPEAR METHODS
21 /*************************************************************************/
22
23 - (void)performAppear
24 {
25     CGAffineTransform transform;
26     NSPoint appearPoint;
27     __idle = NO;
28     
29     //Set the location on the screen
30     if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) {
31         appearPoint.x = -( 32.0 + [[_window screen] visibleFrame].origin.x );
32     } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionRight ) {
33         appearPoint.x = -(([[_window screen] visibleFrame].size.width + [[_window screen] visibleFrame].origin.x) - 32.0 - [_window frame].size.width);
34     } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionCenter ) {
35         appearPoint.x = ( [_window frame].size.width - [[_window screen] visibleFrame].size.width ) / 2;
36     }
37     
38     if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
39         appearPoint.y = ( 64.0 + [[_window screen] visibleFrame].origin.y - [_window frame].size.height );
40     } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
41         appearPoint.y = -( [[_window screen] frame].size.height - ( [_window frame].size.height + 32.0 + [[_window screen] visibleFrame].origin.y) );
42     } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionMiddle ) {
43         appearPoint.y = ( [_window frame].size.height - [[_window screen] visibleFrame].size.height) / 2;
44     }
45     
46     transform = CGAffineTransformMakeTranslation(appearPoint.x, appearPoint.y);
47     CGSSetWindowTransform([NSApp contextID],
48                           (CGSWindowID)[_window windowNumber],
49                           transform);
50     
51     [self setWindowVisibility:ITWindowAppearingState];
52     [self performAppearFromProgress:0.0 effectTime:_effectTime];
53 }
54
55 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
56 {
57     [_window setEffectProgress:progress];
58     _effectSpeed = (1.0 / (EFFECT_FPS * time));
59
60     if ( progress == 0.0 ) {
61         [_window setAlphaValue:0.0];
62     }
63
64     [_window orderFront:self];
65     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
66                                                     target:self
67                                                   selector:@selector(appearStep)
68                                                   userInfo:nil
69                                                    repeats:YES];
70 }
71
72 - (void)appearStep
73 {
74     float interFade = 0.0;
75     [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
76     [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
77     interFade = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
78     [_window setAlphaValue:interFade];
79
80     if ( [_window effectProgress] >= 1.0 ) {
81         [self appearFinish];
82     }
83 }
84
85 - (void)appearFinish
86 {
87     [_effectTimer invalidate];
88     _effectTimer = nil;
89     [self setWindowVisibility:ITWindowVisibleState];
90
91     __idle = YES;
92     
93     if ( __shouldReleaseWhenIdle ) {
94         [self release];
95     }
96 }
97
98 - (void)cancelAppear
99 {
100     [self setWindowVisibility:ITWindowVanishingState];
101
102     [_effectTimer invalidate];
103     _effectTimer = nil;
104
105     [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
106 }
107
108
109 /*************************************************************************/
110 #pragma mark -
111 #pragma mark VANISH METHODS
112 /*************************************************************************/
113
114 - (void)performVanish
115 {
116     __idle = NO;
117     
118     [self setWindowVisibility:ITWindowVanishingState];
119     [self performVanishFromProgress:1.0 effectTime:_effectTime];
120 }
121
122 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
123 {
124     [_window setEffectProgress:progress];
125     _effectSpeed = (1.0 / (EFFECT_FPS * time));
126     if ( progress == 1.0 ) {
127         [_window setAlphaValue:1.0];
128     }
129
130     [_window orderFront:self];
131     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
132                                                     target:self
133                                                   selector:@selector(vanishStep)
134                                                   userInfo:nil
135                                                    repeats:YES];
136 }
137
138 - (void)vanishStep
139 {
140     float interFade = 1.0;
141     [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
142     [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
143     interFade = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
144     [_window setAlphaValue:interFade];
145
146     if ( [_window effectProgress] <= 0.0 ) {
147         [self vanishFinish];
148     }
149 }
150
151 - (void)vanishFinish
152 {
153     [_effectTimer invalidate];
154     _effectTimer = nil;
155     [_window orderOut:self];
156     [_window setAlphaValue:1.0];
157     [self setWindowVisibility:ITWindowHiddenState];
158
159     __idle = YES;
160     
161     if ( __shouldReleaseWhenIdle ) {
162         [self release];
163     }
164 }
165
166 - (void)cancelVanish
167 {
168     [self setWindowVisibility:ITWindowVanishingState];
169
170     [_effectTimer invalidate];
171     _effectTimer = nil;
172
173     [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 3.5)];
174 }
175
176
177 @end