Builds now. Also some moderate effect architecture changes.
[ITKit.git] / ITPivotWindowEffect.m
1 #import "ITPivotWindowEffect.h"
2 #import "ITCoreGraphicsHacks.h"
3
4 @implementation ITPivotWindowEffect
5
6
7 - (void)performAppear
8 {
9     NSLog(@"ITPivotWindowEffect does not implement performAppear.");
10 }
11
12 - (void)performVanish
13 {
14     NSLog(@"ITPivotWindowEffect does not implement performVanish.");
15 }
16
17 - (void)pivotEffect
18 {
19     if ( YES ) {
20         [self setPivot:315.0];
21         _effectProgress = 0.0;
22         [_window setAlphaValue:0.0];
23         [_window orderFront:self];
24         _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS)
25                                                         target:self
26                                                       selector:@selector(pivotStep)
27                                                       userInfo:nil
28                                                        repeats:YES];
29     } else {
30         [_window orderOut:self];
31     }
32 }
33
34 - (void)pivotStep
35 {
36     if ( YES ) {
37         float interPivot = 0.0;
38         _effectProgress += (1.0 / (EFFECT_FPS * _effectTime));
39         _effectProgress = (_effectProgress < 1.0 ? _effectProgress : 1.0);
40         interPivot = (( sin((_effectProgress * pi) - (pi / 2)) + 1 ) / 2);
41         [self setPivot:((interPivot * 45) + 315)];
42         [_window setAlphaValue:interPivot];
43         if ( _effectProgress >= 1.0 ) {
44             [self pivotFinish];
45         }
46     } else {
47         //backwards
48     }
49 }
50
51 - (void)pivotFinish
52 {
53     if ( YES ) {
54         [_effectTimer invalidate];
55         _effectTimer = nil;
56         _effectProgress = 0.0;
57     } else {
58         //backwards
59     }
60 }
61
62
63 - (void)setPivot:(float)angle
64 {
65     float degAngle = (angle * (pi / 180));
66     CGAffineTransform transform = CGAffineTransformMakeRotation(degAngle);
67     
68  // Set pivot point
69     transform.tx = -32.0;
70     transform.ty = [_window frame].size.height + 32.0;
71
72     CGSSetWindowTransform([NSApp contextID],
73                           (CGSWindowID)[_window windowNumber],
74                           CGAffineTransformTranslate(transform,
75                                                      (([_window frame].origin.x - 32.0) * -1),
76                                                      (([[_window screen] frame].size.height - ([_window frame].origin.y) + 32.0) * -1) ));
77 }
78
79
80 @end