Moving to the new means of setting the window visibility state: allowing the effects...
[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)appearFinish;
9 - (void)vanishFinish;
10 @end
11
12
13 @implementation ITPivotWindowEffect
14
15 - (void)performAppear
16 {
17       // Cast so the compiler won't gripe
18     [(ITTransientStatusWindow *)_window setVisibilityState:ITTransientStatusWindowAppearingState];
19     [self setPivot:315.0];
20     _effectProgress = 0.0;
21     [_window setAlphaValue:0.0];
22     [_window orderFront:self];
23     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
24                                                     target:self
25                                                   selector:@selector(appearStep)
26                                                   userInfo:nil
27                                                    repeats:YES];
28 }
29
30 - (void)performVanish
31 {
32       // Cast so the compiler won't gripe
33     [(ITTransientStatusWindow *)_window setVisibilityState:ITTransientStatusWindowVanishingState];
34     [self setPivot:0.0];
35     _effectProgress = 1.0;
36     [_window setAlphaValue:1.0];
37     [_window orderFront:self];
38     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
39                                                     target:self
40                                                   selector:@selector(vanishStep)
41                                                   userInfo:nil
42                                                    repeats:YES];
43 }
44
45 - (void)cancelAppear
46 {
47     [self appearFinish];
48     [_window orderOut:self];
49     [self setPivot:0.0];
50     [_window setAlphaValue:1.0];
51       // Cast so the compiler won't gripe
52     [(ITTransientStatusWindow *)_window setVisibilityState:ITTransientStatusWindowHiddenState];
53 }
54
55 - (void)cancelVanish
56 {
57     [self vanishFinish];
58     [self setPivot:0.0];
59     [_window setAlphaValue:1.0];
60     [_window orderFront:self];
61     [_window display];
62       // Cast so the compiler won't gripe
63     [(ITTransientStatusWindow *)_window setVisibilityState:ITTransientStatusWindowVisibleState];
64 }
65
66 - (void)appearStep
67 {
68     float interPivot = 0.0;
69     _effectProgress += (1.0 / (EFFECT_FPS * _effectTime));
70     _effectProgress = (_effectProgress < 1.0 ? _effectProgress : 1.0);
71     interPivot = (( sin((_effectProgress * pi) - (pi / 2)) + 1 ) / 2);
72     [self setPivot:((interPivot * 45) + 315)];
73     [_window setAlphaValue:interPivot];
74
75     if ( _effectProgress >= 1.0 ) {
76         [self appearFinish];
77     }
78 }
79
80 - (void)vanishStep
81 {
82     float interPivot = 1.0;
83     _effectProgress -= (1.0 / (EFFECT_FPS * _effectTime));
84     _effectProgress = (_effectProgress > 0.0 ? _effectProgress : 0.0);
85     interPivot = (( sin((_effectProgress * pi) - (pi / 2)) + 1 ) / 2);
86     [self setPivot:((interPivot * 45) + 315)];
87     [_window setAlphaValue:interPivot];
88
89     if ( _effectProgress <= 0.0 ) {
90         [self vanishFinish];
91     }
92 }
93
94 - (void)appearFinish
95 {
96     [_effectTimer invalidate];
97     _effectTimer = nil;
98       // Cast so the compiler won't gripe
99     [(ITTransientStatusWindow *)_window setVisibilityState:ITTransientStatusWindowVisibleState];
100 }
101
102 - (void)vanishFinish
103 {
104     [_effectTimer invalidate];
105     _effectTimer = nil;
106       // Cast so the compiler won't gripe
107     [(ITTransientStatusWindow *)_window setVisibilityState:ITTransientStatusWindowHiddenState];
108 }
109
110 - (void)setPivot:(float)angle
111 {
112     float degAngle = (angle * (pi / 180));
113     CGAffineTransform transform = CGAffineTransformMakeRotation(degAngle);
114     
115  // Set pivot rotation point
116     transform.tx = -32.0;
117     transform.ty = [_window frame].size.height + 32.0;
118
119     CGSSetWindowTransform([NSApp contextID],
120                           (CGSWindowID)[_window windowNumber],
121                           CGAffineTransformTranslate(transform,
122                                                      (([_window frame].origin.x - 32.0) * -1),
123                                                      (([[_window screen] frame].size.height - ([_window frame].origin.y) + 32.0) * -1) ));
124 }
125
126
127 @end