Incremental checkin.
[ITKit.git] / ITPivotWindowEffect.m
1 #import "ITPivotWindowEffect.h"
2 #import "ITCoreGraphicsHacks.h"
3
4 @interface ITPivotWindowEffect (Private)
5 - (void)setPivot:(float)angle;
6 - (void)pivotFinish;
7 @end
8
9 @implementation ITPivotWindowEffect
10
11
12 - (void)performAppear
13 {
14     [self setPivot:315.0];
15     _effectProgress = 0.0;
16     [_window setAlphaValue:0.0];
17     [_window orderFront:self];
18     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
19                                                     target:self
20                                                   selector:@selector(appearStep)
21                                                   userInfo:nil
22                                                    repeats:YES];
23 }
24
25 - (void)performVanish
26 {
27     [self setPivot:0.0];
28     _effectProgress = 1.0;
29     [_window setAlphaValue:1.0];
30     [_window orderFront:self];
31     _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
32                                                     target:self
33                                                   selector:@selector(vanishStep)
34                                                   userInfo:nil
35                                                    repeats:YES];
36 }
37
38 - (void)cancelAppear
39 {
40     [self pivotFinish];
41     [_window orderOut:self];
42     [self setPivot:0.0];
43     [_window setAlphaValue:1.0];
44 }
45
46 - (void)cancelVanish
47 {
48     [self pivotFinish];
49     [self setPivot:0.0];
50     [_window setAlphaValue:1.0];
51     [_window orderFront:self];
52     [_window display];
53 }
54
55 - (void)appearStep
56 {
57     float interPivot = 0.0;
58     _effectProgress += (1.0 / (EFFECT_FPS * _effectTime));
59     _effectProgress = (_effectProgress < 1.0 ? _effectProgress : 1.0);
60     interPivot = (( sin((_effectProgress * pi) - (pi / 2)) + 1 ) / 2);
61     [self setPivot:((interPivot * 45) + 315)];
62     [_window setAlphaValue:interPivot];
63
64     if ( _effectProgress >= 1.0 ) {
65         [self pivotFinish];
66     }
67 }
68
69 - (void)vanishStep
70 {
71     float interPivot = 1.0;
72     _effectProgress -= (1.0 / (EFFECT_FPS * _effectTime));
73     _effectProgress = (_effectProgress > 0.0 ? _effectProgress : 0.0);
74     interPivot = (( sin((_effectProgress * pi) - (pi / 2)) + 1 ) / 2);
75     [self setPivot:((interPivot * 45) + 315)];
76     [_window setAlphaValue:interPivot];
77
78     if ( _effectProgress <= 0.0 ) {
79         [self pivotFinish];
80     }
81 }
82
83 - (void)pivotFinish
84 {
85     [_effectTimer invalidate];
86     _effectTimer = nil;
87 }
88
89
90 - (void)setPivot:(float)angle
91 {
92     float degAngle = (angle * (pi / 180));
93     CGAffineTransform transform = CGAffineTransformMakeRotation(degAngle);
94     
95  // Set pivot rotation point
96     transform.tx = -32.0;
97     transform.ty = [_window frame].size.height + 32.0;
98
99     CGSSetWindowTransform([NSApp contextID],
100                           (CGSWindowID)[_window windowNumber],
101                           CGAffineTransformTranslate(transform,
102                                                      (([_window frame].origin.x - 32.0) * -1),
103                                                      (([[_window screen] frame].size.height - ([_window frame].origin.y) + 32.0) * -1) ));
104 }
105
106
107 @end