VLCVideoCommon.m 2.69 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 36

+ (id)layoutManager
{
37 38 39 40 41 42
	static id sLayoutManager = nil;
	static dispatch_once_t onceToken;
	dispatch_once(&onceToken, ^{
		sLayoutManager = [[self alloc] init];
	});
    return sLayoutManager;
43 44
}

45
/* CALayoutManager Implementation */
46 47 48
- (void)layoutSublayersOfLayer:(CALayer *)layer
{
    /* After having done everything normally resize the vlcopengllayer */
49
    if( [[layer sublayers] count] > 0 && [[[layer sublayers][0] name] isEqualToString:@"vlcopengllayer"])
50
    {
51
        CALayer * videolayer = [layer sublayers][0];
52 53
        CGRect bounds = layer.bounds;
        CGRect videoRect = bounds;
54 55
		CGSize original = self.originalVideoSize;
        if (original.height > 0 && original.width > 0)
56
        {
57 58 59
            CGFloat xRatio = CGRectGetWidth(bounds) / original.width;
            CGFloat yRatio = CGRectGetHeight(bounds) / original.height;
            CGFloat ratio = self.fillScreenEntirely ? MAX(xRatio, yRatio) : MIN(xRatio, yRatio);
60

61 62
            videoRect.size.width = ratio * original.width;
            videoRect.size.height = ratio * original.height;
63 64 65
            videoRect.origin.x += (CGRectGetWidth(bounds) - CGRectGetWidth(videoRect)) / 2.0;
            videoRect.origin.y += (CGRectGetHeight(bounds) - CGRectGetHeight(videoRect)) / 2.0;
        }
66 67 68
        videolayer.frame = videoRect;
    }
}
69

70
@end