Added sliding in from all four corners both horizontal and vertical.
[ITKit.git] / ITSlideVerticallyWindowEffect.m
1 #import "ITSlideVerticallyWindowEffect.h"
2 #import "ITCoreGraphicsHacks.h"
3 #import "ITTransientStatusWindow.h"
4
5
6 @interface ITSlideVerticallyWindowEffect (Private)
7 - (void)performAppearFromProgress:(float)progress effectTime:(float)time;
8 - (void)appearStep;
9 - (void)appearFinish;
10 - (void)performVanishFromProgress:(float)progress effectTime:(float)time;
11 - (void)vanishStep;
12 - (void)vanishFinish;
13 - (void)setSlide:(float)distance;
14 @end
15
16
17 @implementation ITSlideVerticallyWindowEffect
18
19
20 /*************************************************************************/
21 #pragma mark -
22 #pragma mark APPEAR METHODS
23 /*************************************************************************/
24
25 - (void)performAppear
26 {
27     __idle = NO;
28     
29     [self setWindowVisibility:ITWindowAppearingState];
30     [self performAppearFromProgress:0.0 effectTime:_effectTime];
31 }
32
33 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
34 {
35     [_window setEffectProgress:progress];
36     _effectSpeed = (1.0 / (EFFECT_FPS * time));
37
38     if ( progress == 0.0 ) {
39         [_window setAlphaValue:0.0];
40     }
41
42     [_window orderFront:self];
43     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
44                                                     target:self
45                                                   selector:@selector(appearStep)
46                                                   userInfo:nil
47                                                    repeats:YES];
48 }
49
50 - (void)appearStep
51 {
52     float interSlide = 0.0;
53     [_window setEffectProgress:([_window effectProgress] + _effectSpeed)];
54     [_window setEffectProgress:( ([_window effectProgress] < 1.0) ? [_window effectProgress] : 1.0)];
55     interSlide = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
56     [self setSlide:(interSlide * [_window frame].size.height)];
57     [_window setAlphaValue:interSlide];
58
59     if ( [_window effectProgress] >= 1.0 ) {
60         [self appearFinish];
61     }
62 }
63
64 - (void)appearFinish
65 {
66     [_effectTimer invalidate];
67     _effectTimer = nil;
68     [self setWindowVisibility:ITWindowVisibleState];
69
70     __idle = YES;
71     
72     if ( __shouldReleaseWhenIdle ) {
73         [self release];
74     }
75 }
76
77 - (void)cancelAppear
78 {
79     [self setWindowVisibility:ITWindowVanishingState];
80
81     [_effectTimer invalidate];
82     _effectTimer = nil;
83
84     [self performVanishFromProgress:[_window effectProgress] effectTime:(_effectTime / 4.0)];
85 }
86
87
88 /*************************************************************************/
89 #pragma mark -
90 #pragma mark VANISH METHODS
91 /*************************************************************************/
92
93 - (void)performVanish
94 {
95     __idle = NO;
96     
97     [self setWindowVisibility:ITWindowVanishingState];
98     [self performVanishFromProgress:1.0 effectTime:_effectTime];
99 }
100
101 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
102 {
103     [_window setEffectProgress:progress];
104     _effectSpeed = (1.0 / (EFFECT_FPS * time));
105     if ( progress == 1.0 ) {
106         [_window setAlphaValue:1.0];
107     }
108
109     [_window orderFront:self];
110     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
111                                                     target:self
112                                                   selector:@selector(vanishStep)
113                                                   userInfo:nil
114                                                    repeats:YES];
115 }
116
117 - (void)vanishStep
118 {
119     float interSlide = 1.0;
120     [_window setEffectProgress:([_window effectProgress] - _effectSpeed)];
121     [_window setEffectProgress:( ([_window effectProgress] > 0.0) ? [_window effectProgress] : 0.0)];
122     interSlide = (( sin(([_window effectProgress] * pi) - (pi / 2)) + 1 ) / 2);
123     [self setSlide:(interSlide * [_window frame].size.height)];
124     [_window setAlphaValue:interSlide];
125
126     if ( [_window effectProgress] <= 0.0 ) {
127         [self vanishFinish];
128     }
129 }
130
131 - (void)vanishFinish
132 {
133     [_effectTimer invalidate];
134     _effectTimer = nil;
135     [_window orderOut:self];
136     [_window setAlphaValue:1.0];
137     [self setSlide:[_window frame].size.height];
138     [self setWindowVisibility:ITWindowHiddenState];
139
140     __idle = YES;
141     
142     if ( __shouldReleaseWhenIdle ) {
143         [self release];
144     }
145 }
146
147 - (void)cancelVanish
148 {
149     [self setWindowVisibility:ITWindowAppearingState];
150
151     [_effectTimer invalidate];
152     _effectTimer = nil;
153
154     [self performAppearFromProgress:[_window effectProgress] effectTime:(_effectTime / 4.0)];
155 }
156
157 - (void)setSlide:(float)distance
158 {
159     CGAffineTransform transform;
160     if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
161         transform = CGAffineTransformMakeTranslation( ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) ? -( 32.0 + [[_window screen] visibleFrame].origin.x ) : -(([[_window screen] visibleFrame].size.width + [[_window screen] visibleFrame].origin.x) - 32.0 - [_window frame].size.width),
162                                                     -( [[_window screen] frame].size.height - ( distance + 32.0 + [[_window screen] visibleFrame].origin.y ) ) );
163     } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
164         transform = CGAffineTransformMakeTranslation( ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) ? -( 32.0 + [[_window screen] visibleFrame].origin.x ) : -(([[_window screen] visibleFrame].size.width + [[_window screen] visibleFrame].origin.x) - 32.0 - [_window frame].size.width),
165                                                     [[_window screen] visibleFrame].origin.y - distance + 64.0 );
166     }
167     
168     CGSSetWindowTransform([NSApp contextID],
169                           (CGSWindowID)[_window windowNumber],
170                           transform);
171 }
172 @end