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