VLCVideoView.m 5.31 KB
Newer Older
1
/*****************************************************************************
2
 * VLCVideoView.m: VLCKit.framework VLCVideoView implementation
3 4
 *****************************************************************************
 * Copyright (C) 2007 Pierre d'Herbemont
5
 * Copyright (C) 2007 VLC authors and VideoLAN
6 7 8 9
 * $Id$
 *
 * 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
#import "VLCVideoView.h"
26 27
#import "VLCLibrary.h"
#import "VLCEventManager.h"
28
#import "VLCVideoCommon.h"
29 30

/* Libvlc */
31 32 33 34
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

35 36 37
#include <vlc/vlc.h>
#include <vlc/libvlc.h>

38 39 40
#import <QuartzCore/QuartzCore.h>

/******************************************************************************
41
 * Soon deprecated stuff
42 43
 */

44
/* This is a forward reference to VLCOpenGLVoutView specified in minimal_macosx
45
   library.  We could get rid of this, but it prevents warnings from the
46
   compiler. (Scheduled to deletion) */
47 48 49
@interface VLCOpenGLVoutView : NSView
- (void)detachFromVout;
@end
50

51 52 53 54 55 56 57 58 59 60
/* Depreacted methods */
@interface VLCVideoView (Deprecated)
- (void)setStretchesVideo:(BOOL)value;
- (BOOL)stretchesVideo;

- (void)addVoutSubview:(NSView *)aView;  /* (Scheduled to deletion) */
- (void)removeVoutSubview:(NSView *)aView;  /* (Scheduled to deletion) */
@end

/******************************************************************************
61
 * VLCVideoView (Private)
62 63 64 65 66 67 68
 */

@interface VLCVideoView (Private)
/* Method */
- (void)addVoutLayer:(CALayer *)aLayer;
@end

69
@interface VLCVideoView ()
70 71 72 73 74 75 76
{
    id delegate;
    NSColor * backColor;
    BOOL stretchesVideo;
    id layoutManager;
    BOOL hasVideo;
}
77
/* Proeprties */
78 79 80
@property (readwrite) BOOL hasVideo;
@end

81
/******************************************************************************
82
 * Implementation VLCVideoView
83 84
 */

85
@implementation VLCVideoView
86

87
/* Initializers */
88
- (id)initWithFrame:(NSRect)rect
89
{
90
    if (self = [super initWithFrame:rect])
91
    {
92 93 94 95
        self.delegate = nil;
        self.backColor = [NSColor blackColor];
        self.fillScreen = NO;
        self.hasVideo = NO;
96

97 98
        [self setStretchesVideo:NO];
        [self setAutoresizesSubviews:YES];
99
        layoutManager = [[VLCVideoLayoutManager layoutManager] retain];
100 101 102 103 104 105
    }
    return self;
}

- (void)dealloc
{
106 107
    self.delegate = nil;
    self.backColor = nil;
108
    [layoutManager release];
109 110 111
    [super dealloc];
}

112
/* NSView Overrides */
113 114 115
- (void)drawRect:(NSRect)aRect
{
    [self lockFocus];
116
    [backColor set];
117 118 119
    NSRectFill(aRect);
    [self unlockFocus];
}
120

121 122 123 124
- (BOOL)isOpaque
{
    return YES;
}
125

126
/* Properties */
127 128
@synthesize delegate;
@synthesize backColor;
129
@synthesize hasVideo;
130 131 132 133 134 135 136 137

- (BOOL)fillScreen
{
    return [layoutManager fillScreenEntirely];
}

- (void)setFillScreen:(BOOL)fillScreen
{
138
    [(VLCVideoLayoutManager *)layoutManager setFillScreenEntirely:fillScreen];
139 140
    [[self layer] setNeedsLayout];
}
141 142 143 144 145 146 147 148
@end

/******************************************************************************
 * Implementation VLCVideoView  (Private)
 */

@implementation VLCVideoView (Private)

149
/* This is called by the libvlc module 'opengllayer' as soon as there is one
150 151 152 153 154 155
 * vout available
 */
- (void)addVoutLayer:(CALayer *)aLayer
{
    [CATransaction begin];
    [self setWantsLayer: YES];
156
    CALayer * rootLayer = [self layer];
157 158 159 160 161 162

    aLayer.name = @"vlcopengllayer";

    [layoutManager setOriginalVideoSize:aLayer.bounds.size];
    [rootLayer setLayoutManager:layoutManager];
    [rootLayer insertSublayer:aLayer atIndex:0];
Pierre d'Herbemont's avatar
Pierre d'Herbemont committed
163
    [aLayer setNeedsDisplayOnBoundsChange:YES];
164 165

    [CATransaction commit];
166
    self.hasVideo = YES;
167 168
}

169
- (void)removeVoutLayer:(CALayer *)voutLayer
170 171 172 173
{
    [CATransaction begin];
    [voutLayer removeFromSuperlayer];
    [CATransaction commit];
174
    self.hasVideo = NO;
175 176
}

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
@end

/******************************************************************************
 * Implementation VLCVideoView  (Deprecated)
 */

@implementation VLCVideoView (Deprecated)

- (void)setStretchesVideo:(BOOL)value
{
    stretchesVideo = value;
}

- (BOOL)stretchesVideo
{
    return stretchesVideo;
}

195
/* This is called by the libvlc module 'minimal_macosx' as soon as there is one
196 197 198 199 200
 * vout available
 */
- (void)addVoutSubview:(NSView *)aView /* (Scheduled to deletion) */
{
    [aView setFrame:[self bounds]];
201

202 203 204 205 206 207 208 209 210 211 212
    [self addSubview:aView];

    // TODO: Should we let the media player specify these values?
    [aView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
}

- (void)removeVoutSubview:(NSView *)view /* (Scheduled to deletion) */
{
    // Should we do something?  I don't know, however the protocol requires
    // this to be implemented
}
213
@end