Fixed a crash when Core Image was available.
[ITKit.git] / ITWindowEffect.m
1 #import "ITWindowEffect.h"
2 #import "ITTransientStatusWindow.h"
3 #import <OpenGL/gl.h>
4 #import <OpenGL/glu.h>
5 #import <OpenGL/glext.h>
6
7 @implementation ITWindowEffect
8
9 + (NSArray *)effectClasses
10 {
11     NSMutableArray *classes = [[NSArray arrayWithObjects:
12         NSClassFromString(@"ITCutWindowEffect"),
13         NSClassFromString(@"ITDissolveWindowEffect"),
14         NSClassFromString(@"ITSlideHorizontallyWindowEffect"),
15         NSClassFromString(@"ITSlideVerticallyWindowEffect"),
16         NSClassFromString(@"ITPivotWindowEffect"),
17         NSClassFromString(@"ITZoomWindowEffect"),
18         NSClassFromString(@"ITSpinWindowEffect"),
19         NSClassFromString(@"ITSpinAndZoomWindowEffect"),
20         nil] mutableCopy];
21         
22         NSOpenGLView *view = [[NSOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 1, 1) pixelFormat:[NSOpenGLView defaultPixelFormat]];
23         if ([view openGLContext]) {
24                 NSString *string = [NSString stringWithCString:glGetString(GL_EXTENSIONS)];
25                 NSRange result = [string rangeOfString:@"ARB_fragment_program"];
26                 if (result.location != NSNotFound) {
27                         [classes addObject:NSClassFromString(@"ITCoreImageWindowEffect")];
28                 }
29         }
30         [view release];
31         
32     return [classes autorelease];
33 }
34
35 - (id)initWithWindow:(NSWindow *)window
36 {
37     if ( (self = [super init]) ) {
38         _window                 = [window retain];
39         _effectTime             = DEFAULT_EFFECT_TIME;
40         _effectTimer            = nil;
41         __shouldReleaseWhenIdle = NO;
42         __idle                  = YES;
43
44         if ( [window conformsToProtocol:@protocol(ITWindowPositioning)] ) {
45             _verticalPosition   = (ITVerticalWindowPosition)[(ITTransientStatusWindow *)window verticalPosition];
46             _horizontalPosition = (ITHorizontalWindowPosition)[(ITTransientStatusWindow *)window horizontalPosition];
47         } else {
48             NSLog(@"ITWindowEffect - initWithWindow: - window does not conform to ITWindowPositioning.");
49             _verticalPosition   = ITWindowPositionBottom;
50             _horizontalPosition = ITWindowPositionLeft;
51         }
52     }
53     return self;
54 }
55
56 - (NSWindow *)window
57 {
58     return _window;
59 }
60
61 - (void)setWindow:(NSWindow *)newWindow
62 {
63     [_window autorelease];
64     _window = [newWindow retain];
65 }
66
67 - (void)setWindowVisibility:(ITWindowVisibilityState)visibilityState
68 {
69     if ( [_window conformsToProtocol:@protocol(ITWindowMotility)] ) {
70        // Cast so the compiler won't gripe
71         [(ITTransientStatusWindow *)_window setVisibilityState:visibilityState];
72     } else {
73         NSLog(@"ITWindowEffect - setWindowVisibility: - window does not conform to ITWindowVisibility.");
74     }
75 }
76
77 - (float)effectTime
78 {
79     return _effectTime;
80 }
81
82 - (void)setEffectTime:(float)newTime
83 {
84     _effectTime = newTime;
85 }
86
87 + (NSString *)effectName
88 {
89     NSLog(@"ITWindowEffect does not implement +effectName.");
90     return nil;
91 }
92
93 + (NSDictionary *)supportedPositions
94 {
95     NSLog(@"ITWindowEffect does not implement +supportedPositions.");
96     
97 //  Below is an example dictionary.  Modify it appropriately when subclassing.
98     return [NSDictionary dictionaryWithObjectsAndKeys:
99         [NSDictionary dictionaryWithObjectsAndKeys:
100             [NSNumber numberWithBool:NO], @"Left",
101             [NSNumber numberWithBool:NO], @"Center",
102             [NSNumber numberWithBool:NO], @"Right", nil] , @"Top" ,
103         [NSDictionary dictionaryWithObjectsAndKeys:
104             [NSNumber numberWithBool:NO], @"Left",
105             [NSNumber numberWithBool:NO], @"Center",
106             [NSNumber numberWithBool:NO], @"Right", nil] , @"Middle" ,
107         [NSDictionary dictionaryWithObjectsAndKeys:
108             [NSNumber numberWithBool:NO], @"Left",
109             [NSNumber numberWithBool:NO], @"Center",
110             [NSNumber numberWithBool:NO], @"Right", nil] , @"Bottom" , nil];
111 }
112
113 + (unsigned int)listOrder
114 {
115     NSLog(@"ITWindowEffect does not implement +listOrder.");
116     return 0;
117 }
118
119 - (void)performAppear
120 {
121     NSLog(@"ITWindowEffect does not implement -performAppear.");
122 }
123
124 - (void)performVanish
125 {
126     NSLog(@"ITWindowEffect does not implement -performVanish.");
127 }
128
129 - (void)cancelAppear
130 {
131     NSLog(@"ITWindowEffect does not implement -cancelAppear.");
132 }
133
134 - (void)cancelVanish
135 {
136     NSLog(@"ITWindowEffect does not implement -cancelVanish.");
137 }
138
139 - (void)releaseWhenIdle;
140 {
141     if ( __idle ) {
142         [self release];
143     } else {
144         __shouldReleaseWhenIdle = YES;
145     }
146 }
147
148 - (void)dealloc
149 {
150         [_window release];
151         [super dealloc];
152 }
153
154
155 @end