VLCVideoCommon.m 2.57 KB
Newer Older
1
/*****************************************************************************
2
 * VLCVideoCommon.m: VLCKit.framework VLCVideoCommon implementation
3 4
 *****************************************************************************
 * Copyright (C) 2007 Pierre d'Herbemont
5
 * Copyright (C) 2007 VLC authors and VideoLAN
Pierre's avatar
Pierre committed
6
 * $Id$
7 8 9
 *
 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
 *
10 11 12
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
13 14 15 16
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
 *
20 21 22
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27 28 29
 *****************************************************************************/

#import "VLCVideoCommon.h"

/******************************************************************************
 * Implementation VLCVideoLayoutManager
 *
30
 * Manage the size of the video layer
31 32
 */

33
@implementation VLCVideoLayoutManager
34

35
/* Factories */
36 37 38 39 40
+ (id)layoutManager
{
    return [[[self alloc] init] autorelease];
}

41
/* CALayoutManager Impelmentation */
42 43 44 45 46 47 48 49
- (void)layoutSublayersOfLayer:(CALayer *)layer
{
    /* After having done everything normally resize the vlcopengllayer */
    if( [[layer sublayers] count] > 0 && [[[[layer sublayers] objectAtIndex:0] name] isEqualToString:@"vlcopengllayer"])
    {
        CALayer * videolayer = [[layer sublayers] objectAtIndex:0];
        CGRect bounds = layer.bounds;
        CGRect videoRect = bounds;
50

51 52
        CGFloat xRatio = CGRectGetWidth(bounds)/originalVideoSize.width;
        CGFloat yRatio = CGRectGetHeight(bounds)/originalVideoSize.height;
53
        CGFloat ratio = fillScreenEntirely ? MAX(xRatio, yRatio) : MIN(xRatio, yRatio);
54

55 56 57 58
        videoRect.size.width = ratio*originalVideoSize.width;
        videoRect.size.height = ratio*originalVideoSize.height;
        videoRect.origin.x += (CGRectGetWidth(bounds) - CGRectGetWidth(videoRect))/2.0;
        videoRect.origin.y += (CGRectGetHeight(bounds) - CGRectGetHeight(videoRect))/2.0;
59

60 61 62
        videolayer.frame = videoRect;
    }
}
63 64 65 66

/* Properties */
@synthesize fillScreenEntirely;
@synthesize originalVideoSize;
67
@end