Adding a better cancel job to the Pivot effect. Also redoing the showcase interface...
[ITKit.git] / ITPivotWindowEffect.m
1 #import "ITPivotWindowEffect.h"
2 #import "ITCoreGraphicsHacks.h"
3 #import "ITTransientStatusWindow.h"
4
5
6 @interface ITPivotWindowEffect (Private)
7 - (void)setPivot:(float)angle;
8 - (void)performAppearFromProgress:(float)progress effectTime:(float)time;
9 - (void)performVanishFromProgress:(float)progress effectTime:(float)time;
10 - (void)appearFinish;
11 - (void)vanishFinish;
12 @end
13
14
15 @implementation ITPivotWindowEffect
16
17 - (void)performAppear
18 {
19     [self setWindowVisibility:ITTransientStatusWindowAppearingState];
20     [self performAppearFromProgress:0.0 effectTime:_effectTime];
21 }
22
23 - (void)performAppearFromProgress:(float)progress effectTime:(float)time
24 {
25     _effectProgress = progress;
26     _effectSpeed = (1.0 / (EFFECT_FPS * time));
27     
28     if ( progress == 0.0 ) {
29         [self setPivot:315.0];
30         [_window setAlphaValue:0.0];
31     }
32
33     [_window orderFront:self];
34     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
35                                                     target:self
36                                                   selector:@selector(appearStep)
37                                                   userInfo:nil
38                                                    repeats:YES];
39 }
40
41 - (void)performVanish
42 {
43     [self setWindowVisibility:ITTransientStatusWindowVanishingState];
44     [self performVanishFromProgress:1.0 effectTime:_effectTime];
45 }
46
47 - (void)performVanishFromProgress:(float)progress effectTime:(float)time
48 {
49     _effectProgress = progress;
50     _effectSpeed = (1.0 / (EFFECT_FPS * time));
51     if ( progress == 1.0 ) {
52         [self setPivot:0.0];
53         [_window setAlphaValue:1.0];
54     }
55
56     [_window orderFront:self];
57     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
58                                                     target:self
59                                                   selector:@selector(vanishStep)
60                                                   userInfo:nil
61                                                    repeats:YES];
62 }
63
64 - (void)cancelAppear
65 {
66     [self setWindowVisibility:ITTransientStatusWindowVanishingState];
67     
68     [_effectTimer invalidate];
69     _effectTimer = nil;
70     
71     [self performVanishFromProgress:_effectProgress effectTime:(_effectTime / 3.5)];
72 }
73
74 - (void)cancelVanish
75 {
76     [self setWindowVisibility:ITTransientStatusWindowAppearingState];
77
78     [_effectTimer invalidate];
79     _effectTimer = nil;
80
81     [self performAppearFromProgress:_effectProgress effectTime:(_effectTime / 3.5)];
82 }
83
84 - (void)appearStep
85 {
86     float interPivot = 0.0;
87     _effectProgress += _effectSpeed;
88     _effectProgress = (_effectProgress < 1.0 ? _effectProgress : 1.0);
89     interPivot = (( sin((_effectProgress * pi) - (pi / 2)) + 1 ) / 2);
90     [self setPivot:((interPivot * 45) + 315)];
91     [_window setAlphaValue:interPivot];
92
93     if ( _effectProgress >= 1.0 ) {
94         [self appearFinish];
95     }
96 }
97
98 - (void)vanishStep
99 {
100     float interPivot = 1.0;
101     _effectProgress -= _effectSpeed;
102     _effectProgress = (_effectProgress > 0.0 ? _effectProgress : 0.0);
103     interPivot = (( sin((_effectProgress * pi) - (pi / 2)) + 1 ) / 2);
104     [self setPivot:((interPivot * 45) + 315)];
105     [_window setAlphaValue:interPivot];
106
107     if ( _effectProgress <= 0.0 ) {
108         [self vanishFinish];
109     }
110 }
111
112 - (void)appearFinish
113 {
114     [_effectTimer invalidate];
115     _effectTimer = nil;
116     [self setWindowVisibility:ITTransientStatusWindowVisibleState];
117 }
118
119 - (void)vanishFinish
120 {
121     [_effectTimer invalidate];
122     _effectTimer = nil;
123     [self setWindowVisibility:ITTransientStatusWindowHiddenState];
124 }
125
126 - (void)setPivot:(float)angle
127 {
128     float degAngle = (angle * (pi / 180));
129
130     CGAffineTransform transform = CGAffineTransformMakeRotation(degAngle);
131     
132  // Set pivot rotation point
133     transform.tx = -32.0;
134     transform.ty = [_window frame].size.height + 32.0;
135
136     CGSSetWindowTransform([NSApp contextID],
137                           (CGSWindowID)[_window windowNumber],
138                           CGAffineTransformTranslate(transform,
139                                                      (([_window frame].origin.x - 32.0) * -1),
140                                                      (([[_window screen] frame].size.height - ([_window frame].origin.y) + 32.0) * -1) ));
141 }
142
143
144 @end