]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCVideoView.m
macosx/framework: Remove this nasty hack, now that core is fixed.
[vlc] / projects / macosx / framework / Sources / VLCVideoView.m
1 /*****************************************************************************
2  * VLCVideoView.m: VLCKit.framework VLCVideoView implementation
3  *****************************************************************************
4  * Copyright (C) 2007 Pierre d'Herbemont
5  * Copyright (C) 2007 the VideoLAN team
6  * $Id$
7  *
8  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #import "VLCVideoView.h"
26 #import "VLCLibrary.h"
27 #import "VLCEventManager.h"
28 #import "VLCVideoCommon.h"
29
30 /* Libvlc */
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <vlc/vlc.h>
36 #include <vlc/libvlc.h>
37
38 #import <QuartzCore/QuartzCore.h>
39
40 /******************************************************************************
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 @interface VLCOpenGLVoutView : NSView
48 - (void)detachFromVout;
49 @end
50
51 /* Depreacted methods */
52 @interface VLCVideoView (Deprecated)
53 - (void)setStretchesVideo:(BOOL)value;
54 - (BOOL)stretchesVideo;
55
56 - (void)addVoutSubview:(NSView *)aView;  /* (Scheduled to deletion) */
57 - (void)removeVoutSubview:(NSView *)aView;  /* (Scheduled to deletion) */
58 @end
59
60 /******************************************************************************
61  * VLCVideoView (Private) 
62  */
63
64 @interface VLCVideoView (Private)
65 /* Method */
66 - (void)addVoutLayer:(CALayer *)aLayer;
67 @end
68
69 @interface VLCVideoView ()
70 /* Proeprties */
71 @property (readwrite) BOOL hasVideo;
72 @end
73
74 /******************************************************************************
75  * Implementation VLCVideoView 
76  */
77
78 @implementation VLCVideoView
79
80 /* Initializers */
81 - (id)initWithFrame:(NSRect)rect
82 {
83     if (self = [super initWithFrame:rect]) 
84     {
85         self.delegate = nil;
86         self.backColor = [NSColor blackColor];
87         self.fillScreen = NO;
88         self.hasVideo = NO;
89         
90         [self setStretchesVideo:NO];
91         [self setAutoresizesSubviews:YES];
92         layoutManager = [[VLCVideoLayoutManager layoutManager] retain];
93     }
94     return self;
95 }
96
97 - (void)dealloc
98 {
99     self.delegate = nil;
100     self.backColor = nil;
101     [layoutManager release];
102     [super dealloc];
103 }
104
105 /* NSView Overrides */
106 - (void)drawRect:(NSRect)aRect
107 {
108     [self lockFocus];
109     [backColor set];
110     NSRectFill(aRect);
111     [self unlockFocus];
112 }
113
114 - (BOOL)isOpaque
115 {
116     return YES;
117 }
118
119 /* Properties */
120 @synthesize delegate;
121 @synthesize backColor;
122 @synthesize hasVideo;
123
124 - (BOOL)fillScreen
125 {
126     return [layoutManager fillScreenEntirely];
127 }
128
129 - (void)setFillScreen:(BOOL)fillScreen
130 {
131     [(VLCVideoLayoutManager *)layoutManager setFillScreenEntirely:fillScreen];
132     [[self layer] setNeedsLayout];
133 }
134 @end
135
136 /******************************************************************************
137  * Implementation VLCVideoView  (Private)
138  */
139
140 @implementation VLCVideoView (Private)
141
142 /* This is called by the libvlc module 'opengllayer' as soon as there is one 
143  * vout available
144  */
145 - (void)addVoutLayer:(CALayer *)aLayer
146 {
147     [CATransaction begin];
148     [self setWantsLayer: YES];
149         CALayer * rootLayer = [self layer];
150
151     aLayer.name = @"vlcopengllayer";
152
153     [layoutManager setOriginalVideoSize:aLayer.bounds.size];
154     [rootLayer setLayoutManager:layoutManager];
155     [rootLayer insertSublayer:aLayer atIndex:0];
156     [aLayer setNeedsDisplayOnBoundsChange:YES];
157
158     [CATransaction commit];
159     self.hasVideo = YES;
160 }
161
162 - (void)removeVoutLayer:(CALayer *)voutLayer
163 {
164     [CATransaction begin];
165     [voutLayer removeFromSuperlayer];
166     [CATransaction commit];
167     self.hasVideo = NO;
168 }
169
170 @end
171
172 /******************************************************************************
173  * Implementation VLCVideoView  (Deprecated)
174  */
175
176 @implementation VLCVideoView (Deprecated)
177
178 - (void)setStretchesVideo:(BOOL)value
179 {
180     stretchesVideo = value;
181 }
182
183 - (BOOL)stretchesVideo
184 {
185     return stretchesVideo;
186 }
187
188 /* This is called by the libvlc module 'minimal_macosx' as soon as there is one
189  * vout available
190  */
191 - (void)addVoutSubview:(NSView *)aView /* (Scheduled to deletion) */
192 {
193     [aView setFrame:[self bounds]];
194
195     [self addSubview:aView];
196
197     // TODO: Should we let the media player specify these values?
198     [aView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
199 }
200
201 - (void)removeVoutSubview:(NSView *)view /* (Scheduled to deletion) */
202 {
203     // Should we do something?  I don't know, however the protocol requires
204     // this to be implemented
205 }
206 @end