source: branches/PlayerFramework/CommonMediaPlayer/Media Players/DVD Framework/CMPDVDWindowCreationAction.m @ 1125

Revision 1125, 22.2 KB checked in by gbooker, 5 years ago (diff)

All views are now relative sizes. This should work better with different screen resolutions

Line 
1/*
2 * CMPDVDWindowCreationAction.m
3 * CommonMediaPlayer
4 *
5 * Created by Graham Booker on Feb. 2 2010
6 * Copyright 2010 Common Media Player
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
10 * Lesser General Public License as published by the Free Software Foundation; either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License along with this program; if
18 * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#import <DVDPlayback/DVDPlayback.h>
23
24#import "CMPDVDWindowCreationAction.h"
25#import "CMPScreenReleaseAction.h"
26#import "CoreGraphicsServices.h"
27#import "CMPOverlayModeAction.h"
28#import "CMPATVVersion.h"
29#import "CMPDVDPlayer.h"
30
31#define ANIMATE_TIME_INTERVAL 0.02
32
33@implementation CMPDVDOverlayWindow
34
35- (id)initWithContentRect:(NSRect)contentRect overWindow:(int)windowID
36{
37        self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
38        if(!self)
39                return self;
40       
41        screenRect = contentRect;
42        overWindowID = windowID;
43        [self setReleasedWhenClosed:NO];
44       
45        [self setBackgroundColor:[NSColor blackColor]];
46        [[self contentView] setNeedsDisplay:YES];
47       
48        return self;
49}
50
51- (void) dealloc
52{
53        [opacityChangeTimer invalidate];
54        [opacityChangeStartTime release];
55        [super dealloc];
56}
57
58- (void)display
59{
60        CGSSetWindowLevel(_CGSDefaultConnection(), [self windowNumber], CGShieldingWindowLevel()+1);
61        CGSOrderWindow(_CGSDefaultConnection(), [self windowNumber], kCGSOrderAbove, overWindowID);
62        [super display];
63}
64
65- (void)closeWithFadeTime:(NSNumber *)aFadeTimeNumber
66{
67        float aFadeTime = [aFadeTimeNumber floatValue];
68        //Alpha is horrible on the ATV since it displays grey, but this one step fade forces everything to draw in the background before it is displayed.
69        if(![CMPATVVersion usingLeopard])
70                aFadeTime = ANIMATE_TIME_INTERVAL / 2;
71        if(aFadeTime == 0)
72        {
73                [self close];
74                return;
75        }
76        initialOpacity = [self alphaValue];
77        finalOpacity = 0;
78        fadeTime = aFadeTime;
79        [opacityChangeStartTime release];
80        opacityChangeStartTime = [[NSDate date] retain];
81        [opacityChangeTimer invalidate];
82        opacityChangeTimer = [NSTimer scheduledTimerWithTimeInterval:ANIMATE_TIME_INTERVAL target:self selector:@selector(opacityTimerFire) userInfo:nil repeats:YES];
83}
84
85- (void)displayWithFadeTime:(float)aFadeTime
86{
87        //Same as above
88        if(![CMPATVVersion usingLeopard])
89                aFadeTime = ANIMATE_TIME_INTERVAL / 2;
90        if(aFadeTime)
91                [self setAlphaValue:0];
92        [self display];
93        if(aFadeTime)
94        {
95                initialOpacity = 0;
96                finalOpacity = 1;
97                fadeTime = aFadeTime;
98                opacityChangeStartTime = [[NSDate date] retain];
99                opacityChangeTimer = [NSTimer scheduledTimerWithTimeInterval:ANIMATE_TIME_INTERVAL target:self selector:@selector(opacityTimerFire) userInfo:nil repeats:YES];         
100        }
101}
102
103- (void)opacityTimerFire
104{
105        double interval = -[opacityChangeStartTime timeIntervalSinceNow];
106        float currentOpacity;
107        if(interval > fadeTime)
108        {
109                [[self retain] autorelease];    //Prevent us from being released with the invalidate
110                currentOpacity = finalOpacity;
111                [opacityChangeTimer invalidate];
112                opacityChangeTimer = nil;
113                if(finalOpacity == 0)
114                {
115                        [self close];
116                        return;
117                }
118        }
119        else
120                currentOpacity = initialOpacity + (finalOpacity - initialOpacity) * interval / fadeTime;
121        [self setAlphaValue:currentOpacity];
122}
123
124@end
125
126@implementation CMPDVDTextView
127
128- (id)initWithContentRect:(NSRect)contentRect position:(CMPDVDOverlayPosition)aPosition overWindow:(int)windowID
129{
130        self = [super initWithContentRect:contentRect overWindow:windowID];
131        if(!self)
132                return nil;
133       
134        position = aPosition;
135        textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 300)];
136        [[self contentView] addSubview:textField];
137        [textField setStringValue:@""];
138        [textField setTextColor:[NSColor blueColor]];
139        [textField setBackgroundColor:[NSColor blackColor]];
140        NSFont *font = [textField font];
141        NSFont *newFont = [NSFont fontWithName:[font fontName] size:contentRect.size.height / 15];
142        [textField setFont:newFont];
143        [textField setBezeled:NO];
144        [textField setBordered:NO];
145       
146        return self;
147}
148
149- (void)dealloc
150{
151        [textField release];
152        [super dealloc];
153}
154
155- (void)setText:(NSString *)text
156{
157        [textField setStringValue:text];
158        [textField sizeToFit];
159        NSRect frameRect;
160        frameRect.size = [textField frame].size;
161        NSLog(@"Size is %fx%f", frameRect.size.width, frameRect.size.height);
162        float distanceFromEdge = screenRect.size.height / 15;
163        if(position == CMPDVDOverlayUpperLeft || position == CMPDVDOverlayUpperRight)
164                frameRect.origin.y = screenRect.size.height - frameRect.size.height - distanceFromEdge;
165        else
166                frameRect.origin.y = distanceFromEdge;
167        if(position == CMPDVDOverlayUpperRight || position == CMPDVDOverlayLowerRight)
168                frameRect.origin.x = screenRect.size.width - frameRect.size.width - distanceFromEdge;
169        else
170                frameRect.origin.x = distanceFromEdge;
171        [self setFrame:frameRect display:YES]; 
172}
173
174@end
175
176
177@interface CMPDVDPlayerPlayHeadView : NSView
178{
179        float                   playHeadLocation;
180}
181- (void)setPlayHeadLocation:(float)playHeadLocation;
182
183@end
184
185@implementation CMPDVDPlayerPlayHeadView
186
187- (void)drawRect:(NSRect)rect
188{
189        NSRect myFrame = [self frame];
190        float height = myFrame.size.height;
191        float width = myFrame.size.width;
192        [[NSColor blackColor] set];
193        NSRectFill(rect);
194        NSBezierPath *path = [NSBezierPath bezierPath];
195        [path moveToPoint:NSMakePoint(height/2, height)];
196        [path appendBezierPathWithArcWithCenter:NSMakePoint(height/2, height/2) radius:height/2 startAngle:90 endAngle:270];
197        [path lineToPoint:NSMakePoint(width-height/2, 0)];
198        [path appendBezierPathWithArcWithCenter:NSMakePoint(width-height/2, height/2) radius:height/2 startAngle:270 endAngle:90];
199        [path closePath];
200        [[NSColor colorWithDeviceRed:0.25 green:0.25 blue:1 alpha:1] set];
201        [path fill];
202       
203        path = [NSBezierPath bezierPath];
204        float position = playHeadLocation * (width - height) + height/2;
205        [path moveToPoint:NSMakePoint(position, 0)];
206        [path lineToPoint:NSMakePoint(position-height/2, height/2)];
207        [path lineToPoint:NSMakePoint(position, height)];
208        [path lineToPoint:NSMakePoint(position+height/2, height/2)];
209        [path closePath];
210        [[NSColor blackColor] set];
211        [path fill];
212}
213
214- (void)setPlayHeadLocation:(float)aPlayHeadLocation
215{
216        playHeadLocation = aPlayHeadLocation;
217        [self setNeedsDisplay:YES];
218}
219
220@end
221
222
223@implementation CMPDVDPlayerPlayHead
224
225- (id)initWithContentRect:(NSRect)contentRect overWindow:(int)windowID
226{
227        self = [super initWithContentRect:contentRect overWindow:windowID];
228        if(!self)
229                return self;
230       
231        float myWidth = contentRect.size.width * 27 / 32;
232        float textHeight = contentRect.size.height * 5 / 72;
233        float textWidth = textHeight * 3;
234        float textSize = contentRect.size.height / 20;
235        elapsedField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, (textSize-textHeight)/7, textWidth, textHeight)];
236        [[self contentView] addSubview:elapsedField];
237        [elapsedField setStringValue:@""];
238        [elapsedField setTextColor:[NSColor blueColor]];
239        [elapsedField setBackgroundColor:[NSColor blackColor]];
240        NSFont *font = [elapsedField font];
241        NSFont *newFont = [NSFont fontWithName:[font fontName] size:textSize];
242        [elapsedField setFont:newFont];
243        [elapsedField setBezeled:NO];
244        [elapsedField setBordered:NO];
245        [elapsedField setSelectable:NO];
246        [elapsedField setAlignment:NSRightTextAlignment];
247       
248        durationField = [[NSTextField alloc] initWithFrame:NSMakeRect(myWidth-textWidth, (textSize-textHeight)/7, textWidth, textHeight)];
249        [[self contentView] addSubview:durationField];
250        [durationField setStringValue:@""];
251        [durationField setTextColor:[NSColor blueColor]];
252        [durationField setBackgroundColor:[NSColor blackColor]];
253        [durationField setFont:newFont];
254        [durationField setBezeled:NO];
255        [durationField setBordered:NO];
256        [durationField setSelectable:NO];
257       
258        playView = [[CMPDVDPlayerPlayHeadView alloc] initWithFrame:NSMakeRect(textWidth, textHeight / 5, myWidth-textWidth*2, textHeight * 3 /5)];
259        [[self contentView] addSubview:playView];
260        [self setFrame:NSMakeRect(contentRect.size.width * 5 / 64, textHeight*2, myWidth, textHeight) display:NO];
261       
262        return self;
263}
264
265- (void) dealloc
266{
267        [durationField release];
268        [player release];
269        [playView release];
270        [updateTimer invalidate];
271        [super dealloc];
272}
273
274NSString *timeStringForTime(int time)
275{
276        int seconds = time % 60;
277        time /= 60;
278        int minutes = time % 60;
279        time /= 60;
280        int hours = time;
281       
282        if(hours == 0)
283                return [NSString stringWithFormat:@"%d:%02d", minutes, seconds];
284       
285        return [NSString stringWithFormat:@"%d:%02d:%02d", hours, minutes, seconds];
286}
287
288- (void)close
289{
290        [updateTimer invalidate];
291        updateTimer = nil;
292        [super close];
293}
294
295- (void)updateDisplay
296{
297        int elapsedTime = [player titleElapsedTime];
298        int durationTime = [player titleDurationTime];
299       
300        [elapsedField setStringValue:timeStringForTime(elapsedTime)];
301        [durationField setStringValue:timeStringForTime(durationTime)];
302        [playView setPlayHeadLocation:((float)elapsedTime)/((float)durationTime)];
303}
304
305- (void)setPlayer:(CMPDVDPlayer *)aPlayer
306{
307        [player release];
308        player = [aPlayer retain];
309       
310        [self updateDisplay];
311       
312        [updateTimer invalidate];
313        updateTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateDisplay) userInfo:nil repeats:YES];
314}
315
316@end
317
318@interface CMPDVDSelectionView : NSView
319{
320        NSTimer                 *moveTimer;
321        float                   initialY, finalY;
322        NSDate                  *startTime;
323}
324@end
325
326@implementation CMPDVDSelectionView
327
328#define CMPDVDSelectionViewMoveTime 0.2
329
330- (id)initWithFrame:(NSRect)frame
331{
332        self = [super initWithFrame:frame];
333        if(!self)
334                return self;
335       
336        initialY = finalY = frame.origin.y;
337       
338        return self;
339}
340
341- (void)dealloc
342{
343        [moveTimer invalidate];
344        [startTime release];
345        [super dealloc];
346}
347
348void Interpolate (void* info, float const* inData, float* outData)
349{
350        float value = sin(M_PI_2 * inData[0])/2;
351        outData[0] = value;
352        outData[1] = value;
353        outData[2] = value;
354        outData[3] = 1.0;
355}
356
357- (void)drawRect:(NSRect)rect
358{
359        NSRect frame = [self frame];
360        NSRect drawPath = frame;
361        drawPath.origin.x = frame.size.height/8;
362        drawPath.origin.y = frame.size.height/8;
363        drawPath.size.width -= frame.size.height/4;
364        drawPath.size.height -= frame.size.height/4;
365        NSBezierPath *path = [NSBezierPath bezierPathWithRect:drawPath];
366       
367        NSShadow *theShadow = [[NSShadow alloc] init];
368        [theShadow setShadowOffset:NSMakeSize(0, 0)];
369        [theShadow setShadowBlurRadius:frame.size.height/8];
370        [theShadow setShadowColor:[NSColor blueColor]];
371        [NSGraphicsContext saveGraphicsState];
372        [theShadow set];
373        [[NSColor blueColor] set];
374        [path fill];
375       
376        [NSGraphicsContext restoreGraphicsState];
377        [theShadow release];
378
379        [[NSColor blackColor] set];
380        NSRectFill(drawPath);
381       
382        //Gradient
383        struct CGFunctionCallbacks callbacks = { 0, Interpolate, NULL };
384       
385        CGFunctionRef function = CGFunctionCreate(NULL, 1, NULL, 4, NULL, &callbacks);
386        CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
387       
388        CGPoint start = CGPointMake(drawPath.origin.x, drawPath.origin.y + drawPath.size.height);
389        CGPoint end = CGPointMake(drawPath.origin.x, drawPath.origin.y + drawPath.size.height/2);
390        CGShadingRef shading = CGShadingCreateAxial(cspace, start, end, function, false, false);
391       
392        CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
393        CGContextSaveGState(context);
394        CGContextClipToRect(context, CGRectMake(drawPath.origin.x, drawPath.origin.y, drawPath.size.width, drawPath.size.height));
395        CGContextDrawShading(context, shading);
396        CGContextRestoreGState(context);
397       
398        CGShadingRelease(shading);
399        CGColorSpaceRelease(cspace);
400        CGFunctionRelease(function);
401        [[NSColor blackColor] set];
402        [path stroke];
403}
404
405- (void)moveTimerFire
406{
407        double interval = -[startTime timeIntervalSinceNow];
408        float currentY;
409        if(interval > CMPDVDSelectionViewMoveTime)
410        {
411                currentY = finalY;
412                [moveTimer invalidate];
413                moveTimer = nil;
414        }
415        else
416                currentY = initialY + (finalY - initialY) * interval / CMPDVDSelectionViewMoveTime;
417        NSRect frame = [self frame];
418        NSRect newFrame = frame;
419        newFrame.origin.y = currentY;
420        [self setFrame:newFrame];
421        [[self superview] setNeedsDisplayInRect:frame];
422        [self setNeedsDisplay:YES];
423}
424
425- (void)animateMoveToYDelta:(float)newY
426{
427        [moveTimer invalidate];
428        finalY += newY;
429        initialY = [self frame].origin.y;
430        [startTime release];
431        startTime = [[NSDate date] retain];
432        moveTimer = [NSTimer scheduledTimerWithTimeInterval:ANIMATE_TIME_INTERVAL target:self selector:@selector(moveTimerFire) userInfo:nil repeats:YES];
433}
434
435@end
436
437
438
439@implementation CMPDVDBlurredMenu
440
441- (id)initWithItems:(NSArray*)anItems contentRect:(NSRect)contentRect overWindow:(int)windowID
442{
443        self = [super initWithContentRect:contentRect overWindow:windowID];
444        if(!self)
445                return self;
446       
447        imageView = [[NSImageView alloc] initWithFrame:contentRect];
448        [[self contentView] addSubview:imageView];
449       
450        NSMutableArray *items = [[NSMutableArray alloc] init];
451       
452        int itemCount = [anItems count];
453        itemHeight = contentRect.size.height / 12;
454        int itemWidth = itemHeight * 10;
455        int bottom = (contentRect.size.height - itemHeight * itemCount) / 2;
456        int left = (contentRect.size.width - itemWidth) / 2;
457       
458        float inset = contentRect.size.height * 5 / 144;
459        float borderSize = contentRect.size.height / 72;
460        selectionView = [[CMPDVDSelectionView alloc] initWithFrame:NSMakeRect(left, bottom + itemHeight * (itemCount-1) - borderSize, itemWidth, itemHeight+borderSize*2)];
461        [[self contentView] addSubview:selectionView];
462       
463        NSFont *newFont = nil;
464        for(int i=0; i<itemCount; i++)
465        {
466                NSTextField *menuItem = [[NSTextField alloc] initWithFrame:NSMakeRect(left+inset, bottom+itemHeight*(itemCount-1-i), itemWidth-inset, itemHeight)];
467                [menuItem setStringValue:[anItems objectAtIndex:i]];
468                [[self contentView] addSubview:menuItem];
469                [menuItem setTextColor:[NSColor whiteColor]];
470                [menuItem setDrawsBackground:NO];
471                [menuItem setBezeled:NO];
472                [menuItem setBordered:NO];
473                [menuItem setSelectable:NO];
474                if(newFont == nil)
475                {
476                        NSFont *font = [menuItem font];
477                        newFont = [NSFont fontWithName:[font fontName] size:contentRect.size.height / 20];
478                }
479                [menuItem setFont:newFont];
480               
481                [menuItem sizeToFit];
482                NSRect frame = [menuItem frame];
483                frame.origin.y += (itemHeight - frame.size.height) / 2;
484                [menuItem setFrame:frame];
485               
486                [items addObject:menuItem];
487                [menuItem release];
488        }
489       
490        menuItems = [items copy];
491        [items release];
492       
493        [self setFrame:contentRect display:YES];
494       
495        return self;
496}
497
498- (void) dealloc
499{
500        [menuItems release];
501        [selectionView release];
502        [imageView release];
503        [super dealloc];
504}
505
506
507- (void)display
508{
509        if(!overWindowID)
510                return;
511        CGSConnectionID cid = _CGSDefaultConnection();
512        CGRect bounds;
513        CGSGetWindowBounds(cid, overWindowID, &bounds);
514        //NSLog(@"Bounds is %fx%f - %fx%f", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
515        //      CGLGetCurrentContext()
516        NSLog(@"bounds is %fx%f-%fx%f", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
517        CGRect imageBounds = bounds;
518        if(bounds.size.height > 480 || bounds.size.width > 720)
519        {
520                float py = bounds.size.height / 480;
521                float px = bounds.size.width / 720;
522                float divisor = MIN(py, px);
523                imageBounds.size.width /= divisor;
524                imageBounds.size.height /= divisor;
525        }
526        int bitmapSize = imageBounds.size.width *imageBounds.size.height * 4;
527        char *bitmap = malloc(bitmapSize);
528        CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
529        CGContextRef context = CGBitmapContextCreate(bitmap, imageBounds.size.width, imageBounds.size.height, 8, imageBounds.size.width * 4, colorspace, kCGImageAlphaNoneSkipFirst);
530    // Copy the contents of the window to the graphic context
531        CGContextCopyWindowCaptureContentsToRect(context, imageBounds, cid, overWindowID, 0);   
532       
533        NSData *bitmapData = [NSData dataWithBytesNoCopy:bitmap length:bitmapSize];
534        CIImage *myCIImage = [[CIImage alloc] initWithBitmapData:bitmapData bytesPerRow:imageBounds.size.width * 4 size:imageBounds.size format:kCIFormatARGB8 colorSpace:colorspace];
535        CIFilter *gaussianBlur = [CIFilter filterWithName:@"CIGaussianBlur"];
536        [gaussianBlur setDefaults];
537        [gaussianBlur setValue:myCIImage forKey:@"inputImage"];
538        [myCIImage release];
539       
540        CIImage *result = [gaussianBlur valueForKey:@"outputImage"];
541        CIFilter *crop = [CIFilter filterWithName:@"CICrop"];
542        [crop setDefaults];
543        [crop setValue:result forKey:@"inputImage"];
544        [crop setValue:[CIVector vectorWithX:0 Y:0 Z:imageBounds.size.width W:imageBounds.size.height] forKey:@"inputRectangle"];
545        result = [crop valueForKey:@"outputImage"];
546        NSImage *resultAsNSImage;
547        if([result isKindOfClass:[CIImage class]])
548        {
549                resultAsNSImage = [[NSImage alloc] initWithSize:NSMakeSize([result extent].size.width, [result extent].size.height)];
550                [resultAsNSImage addRepresentation:[NSCIImageRep imageRepWithCIImage:result]];
551                [resultAsNSImage autorelease];
552        }
553        else
554                resultAsNSImage = (NSImage *)result;
555       
556        [resultAsNSImage setScalesWhenResized:YES];
557        [resultAsNSImage setSize:NSMakeSize(bounds.size.width, bounds.size.height)];
558        [imageView setImage:resultAsNSImage];
559        [imageView setImageScaling:NSScaleProportionally];
560       
561        CGContextRelease(context);
562        CGColorSpaceRelease(colorspace);
563       
564        [super display];
565}
566
567- (BOOL)previousItem
568{
569        if(selectedItem == 0)
570                return NO;
571        [selectionView animateMoveToYDelta:itemHeight];
572        selectedItem--;
573        return YES;
574}
575
576- (BOOL)nextItem
577{
578        if(selectedItem == [menuItems count]-1)
579                return NO;
580        [selectionView animateMoveToYDelta:-itemHeight];
581        selectedItem++;
582        return YES;
583}
584
585- (int)selectedItem
586{
587        return selectedItem;
588}
589
590@end
591
592
593
594@interface BRDisplayManager (compat)
595+ (BRDisplayManager *)sharedInstance;
596@end
597
598@implementation CMPDVDWindowCreationAction
599
600- (id)initWithController:(id <CMPPlayerController>)controller andSettings:(NSDictionary *)settings
601{
602        self = [super init];
603        if(!self)
604                return self;
605       
606//      screenRelease = [[CMPOverlayModeAction alloc] initWithController:controller andSettings:settings];
607        screenRelease = [[CMPScreenReleaseAction alloc] initWithController:controller andSettings:settings];
608        overlays = [[NSMutableArray alloc] init];
609       
610        return self;
611}
612
613- (void) dealloc
614{
615        [screenRelease release];
616        [dvdWindow release];
617        [overlays release];
618        [super dealloc];
619}
620
621static int CreateEmptyWindow(CGRect myFrame)
622{
623        //NSLog(@"createEmptyWindow");
624    CGSRegion frameRgn;
625    CGSRegion emptyRgn;
626    int window;
627    char something[100];
628       
629       
630    CGSNewRegionWithRect(&myFrame, &frameRgn);
631    CGSNewEmptyRegion(&emptyRgn);
632       
633    int conn = CGSMainConnectionID();
634       
635        //NSLog(@"connection id: %i", conn);
636       
637    CGSNewWindowWithOpaqueShape(conn, 2, 0, 0, frameRgn, emptyRgn, 0, &something,
638                                                                32, &window);
639       
640   
641        CGSSetWindowOpacity(conn, window, 1);
642       
643       
644    CGSReleaseRegion(emptyRgn);
645    CGSReleaseRegion(frameRgn);
646       
647    return window;
648}
649
650- (BOOL)openWithError:(NSError **)error
651{
652        BOOL success = [screenRelease openWithError:error];
653       
654        if(!success)
655        {       
656                NSLog(@"Release failed");
657                return NO;
658        }
659       
660        //NSLog(@"createDvdWindow");
661    CGDirectDisplayID display = [(BRDisplayManager *)[BRDisplayManager sharedInstance] display];
662    CGRect frame = CGDisplayBounds(display);
663    frame.size.width = CGDisplayPixelsWide(display);
664    frame.size.height = CGDisplayPixelsHigh(display);
665       
666    if(frame.size.width < 0.0f)
667        frame.size.width = ABS(frame.size.width);
668    if(frame.size.height < 0.0f)
669        frame.size.height = ABS(frame.size.height);
670       
671        NSRect frameRect = NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
672        NSApplicationLoad();
673        dvdWindow = [[NSWindow alloc] initWithContentRect:frameRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
674        [dvdWindow setReleasedWhenClosed:NO];
675        [dvdWindow setBackgroundColor:[NSColor blackColor]];
676        int dvdWindowID = [dvdWindow windowNumber];
677        //dvdWindowID = CreateEmptyWindow(frame);
678        CGSSetWindowLevel(_CGSDefaultConnection(), dvdWindowID, CGShieldingWindowLevel()+1);
679               
680        CGSOrderWindow(_CGSDefaultConnection(), dvdWindowID, kCGSOrderAbove, 0);
681       
682    CGContextRef ctx = (CGContextRef)CGWindowContextCreate(_CGSDefaultConnection(), dvdWindowID, NULL);
683       
684    CGContextClear(ctx);
685    CGContextFlush(ctx);
686    CGContextRelease(ctx);
687               
688        OSStatus setWindowErr = DVDSetVideoWindowID(dvdWindowID);
689        if(setWindowErr != noErr)
690                NSLog(@"Set DVD Window error is %d", setWindowErr);
691        OSStatus displayErr = DVDSetVideoDisplay([[BRDisplayManager sharedInstance] display]);
692        if(displayErr != noErr)
693                NSLog(@"Set DVD Video error is %d", displayErr);
694       
695        return setWindowErr == noErr && displayErr == noErr;
696}
697
698- (void)setWindowAlpha:(float)alpha
699{
700        [dvdWindow setAlphaValue:alpha];
701}
702
703- (CMPDVDOverlayWindow *)addBlackShieldWindow
704{
705        CMPDVDOverlayWindow *ret = [[CMPDVDOverlayWindow alloc] initWithContentRect:[dvdWindow frame] overWindow:[dvdWindow windowNumber]];
706       
707        [overlays addObject:ret];
708        [ret release];
709       
710        return ret;
711}
712
713- (CMPDVDTextView *)addTextOverlayInPosition:(CMPDVDOverlayPosition)position
714{
715        CMPDVDTextView *ret = [[CMPDVDTextView alloc] initWithContentRect:[dvdWindow frame] position:position overWindow:[dvdWindow windowNumber]];
716       
717        [overlays addObject:ret];
718        [ret release];
719       
720        return ret;
721}
722
723- (CMPDVDPlayerPlayHead *)addPlayheadOverlay
724{
725        CMPDVDPlayerPlayHead *ret = [[CMPDVDPlayerPlayHead alloc] initWithContentRect:[dvdWindow frame] overWindow:[dvdWindow windowNumber]];
726       
727        [overlays addObject:ret];
728        [ret release];
729       
730        return ret;
731}
732
733- (CMPDVDBlurredMenu *)addBlurredMenuOverlayWithItems:(NSArray *)items
734{
735        CMPDVDBlurredMenu *ret = [[CMPDVDBlurredMenu alloc] initWithItems:items contentRect:[dvdWindow frame] overWindow:[dvdWindow windowNumber]];
736       
737        [overlays addObject:ret];
738        [ret release];
739       
740        return ret;
741}
742
743- (void)closeOverlay:(CMPDVDOverlayWindow *)overlay
744{
745        [overlay close];
746        [overlays removeObject:overlay];
747}
748
749- (void)closeAllOverlays
750{
751        [overlays makeObjectsPerformSelector:@selector(close)];
752        [overlays removeAllObjects];
753}
754
755- (void)closeAllOverlaysWithFadeTime:(float)fadeTime
756{
757        if(fadeTime > 0.0f)
758                [overlays makeObjectsPerformSelector:@selector(closeWithFadeTime:) withObject:[NSNumber numberWithFloat:fadeTime]];
759        else
760                [overlays makeObjectsPerformSelector:@selector(close)];
761        [overlays removeAllObjects];
762}
763
764- (BOOL)closeWithError:(NSError **)error
765{
766//      int conn = _CGSDefaultConnection();
767//      NSLog(@"conn: %i dvdWindow: %i", conn, dvdWindowID);
768//      OSStatus theErr = CGSReleaseWindow(conn, dvdWindowID);
769//      NSLog(@"CGSReleaseWindow: %d", theErr);
770        [self closeAllOverlays];
771        [dvdWindow close];
772       
773        return [screenRelease closeWithError:error];
774}
775@end
Note: See TracBrowser for help on using the repository browser.