Checking in improvements to the effect availability heuristic.
[ITKit.git] / ITCutWindowEffect.m
1 #import "ITCutWindowEffect.h"
2 #import "ITTransientStatusWindow.h"
3 #import "ITCoreGraphicsHacks.h"
4
5 @implementation ITCutWindowEffect
6
7
8 + (NSString *)effectName
9 {
10     return @"Cut";
11 }
12
13 + (NSDictionary *)supportedPositions
14 {
15     return [NSDictionary dictionaryWithObjectsAndKeys:
16         [NSDictionary dictionaryWithObjectsAndKeys:
17             [NSNumber numberWithBool:YES], @"Left",
18             [NSNumber numberWithBool:YES], @"Center",
19             [NSNumber numberWithBool:YES], @"Right", nil] , @"Top" ,
20         [NSDictionary dictionaryWithObjectsAndKeys:
21             [NSNumber numberWithBool:YES], @"Left",
22             [NSNumber numberWithBool:YES], @"Center",
23             [NSNumber numberWithBool:YES], @"Right", nil] , @"Middle" ,
24         [NSDictionary dictionaryWithObjectsAndKeys:
25             [NSNumber numberWithBool:YES], @"Left",
26             [NSNumber numberWithBool:YES], @"Center",
27             [NSNumber numberWithBool:YES], @"Right", nil] , @"Bottom" , nil];
28 }
29
30 + (unsigned int)listOrder
31 {
32     return 100;
33 }
34
35
36 /*************************************************************************/
37 #pragma mark -
38 #pragma mark APPEAR METHODS
39 /*************************************************************************/
40
41 - (void)performAppear
42 {
43     CGAffineTransform transform;
44     NSPoint appearPoint;
45     
46     //Set the location on the screen
47     if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionLeft ) {
48         appearPoint.x = -( 32.0 + [[_window screen] visibleFrame].origin.x );
49     } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionRight ) {
50         appearPoint.x = -(([[_window screen] visibleFrame].size.width + [[_window screen] visibleFrame].origin.x) - 32.0 - [_window frame].size.width);
51     } else if ( [(ITTransientStatusWindow *)_window horizontalPosition] == ITWindowPositionCenter ) {
52         appearPoint.x = ( [_window frame].size.width - [[_window screen] visibleFrame].size.width ) / 2;
53     }
54     
55     if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionTop ) {
56         appearPoint.y = ( 64.0 + [[_window screen] visibleFrame].origin.y - [_window frame].size.height );
57     } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionBottom ) {
58         appearPoint.y = -( [[_window screen] frame].size.height - ( [_window frame].size.height + 32.0 + [[_window screen] visibleFrame].origin.y) );
59     } else if ( [(ITTransientStatusWindow *)_window verticalPosition] == ITWindowPositionMiddle ) {
60         appearPoint.y = ( [_window frame].size.height - [[_window screen] visibleFrame].size.height) / 2;
61     }
62     
63     transform = CGAffineTransformMakeTranslation(appearPoint.x, appearPoint.y);
64     CGSSetWindowTransform([NSApp contextID],
65                           (CGSWindowID)[_window windowNumber],
66                           transform);
67     
68     [_window orderFront:self];
69     [self setWindowVisibility:ITWindowVisibleState];
70 }
71
72 - (void)cancelAppear
73 {
74     [self performVanish];
75 }
76
77
78 /*************************************************************************/
79 #pragma mark -
80 #pragma mark VANISH METHODS
81 /*************************************************************************/
82
83 - (void)performVanish
84 {
85     [_window orderOut:self];
86     [self setWindowVisibility:ITWindowHiddenState];
87 }
88
89 - (void)cancelVanish
90 {
91     [self performAppear];
92 }
93
94
95 @end