[vlmc-devel] RenderWidget: A clever implementation of video rendering widget

Rohit Yadav git at videolan.org
Fri Mar 25 09:06:08 CET 2011


vlmc | branch: master | Rohit Yadav <rohityadav89 at gmail.com> | Fri Mar 25 18:47:26 2011 +0530| [e9850033b89c7ef5a24a9690d47584729b416eed] | committer: Rohit Yadav

RenderWidget: A clever implementation of video rendering widget

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=e9850033b89c7ef5a24a9690d47584729b416eed
---

 src/Gui/preview/RenderWidget.h  |   63 +++++++++++++++++++++++++
 src/Gui/preview/RenderWidget.mm |   99 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 162 insertions(+), 0 deletions(-)

diff --git a/src/Gui/preview/RenderWidget.h b/src/Gui/preview/RenderWidget.h
new file mode 100644
index 0000000..c14d55b
--- /dev/null
+++ b/src/Gui/preview/RenderWidget.h
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * RenderWidget: Vout render widget
+ *****************************************************************************
+ * Copyright (C) 2008-2011 VideoLAN
+ *
+ * Authors: Rohit Yadav <rohityadav89 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ *****************************************************************************/
+
+#ifndef RENDERWIDGET_H
+#define RENDERWIDGET_H
+
+#include <QtGlobal>
+#include <QWidget>
+
+#if defined( Q_WS_MAC ) && defined( QT_MAC_USE_COCOA )
+#include <QMacCocoaViewContainer>
+
+#ifdef __OBJC__
+#define ADD_COCOA_NATIVE_REF(CocoaClass) \
+    @class CocoaClass; \
+    typedef CocoaClass *Native##CocoaClass##Ref
+#else
+#define ADD_COCOA_NATIVE_REF(CocoaClass) typedef void *Native##CocoaClass##Ref
+#endif
+
+ADD_COCOA_NATIVE_REF(NSView);
+#endif
+
+class RenderWidget : public QWidget
+{
+    Q_OBJECT
+
+public:
+#if defined( Q_WS_MAC ) && defined( QT_MAC_USE_COCOA )
+    RenderWidget( QWidget* parent = NULL );
+    NativeNSViewRef id() const;
+    void release();
+
+private:
+    NativeNSViewRef          m_video;
+    QMacCocoaViewContainer*  m_container;
+#else
+    RenderWidget( QWidget* parent = NULL )
+        : QWidget (parent) {};
+    WId id() const { return winId; };
+#endif
+};
+
+#endif // RENDERWIDGET_H
diff --git a/src/Gui/preview/RenderWidget.mm b/src/Gui/preview/RenderWidget.mm
new file mode 100644
index 0000000..23996d7
--- /dev/null
+++ b/src/Gui/preview/RenderWidget.mm
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * RenderWidget.mm: A NSView Vout render widget for Mac OS
+ *****************************************************************************
+ * Copyright (C) 2008-2011 VideoLAN
+ *
+ * Authors: Rohit Yadav <rohityadav89 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ *****************************************************************************/
+
+#include <QtGlobal>
+#if defined( Q_WS_MAC ) && defined( QT_MAC_USE_COCOA )
+
+#include "RenderWidget.h"
+#include <QPalette>
+#include <QColor>
+#include <QVBoxLayout>
+
+#import <Cocoa/Cocoa.h>
+#import <QuartzCore/QuartzCore.h>
+#import <AppKit/NSView.h>
+
+ at interface VLCNSView : NSView
+BOOL stretchesVideo;
+- ( void ) setStretchesVideo : ( BOOL ) value;
+- ( BOOL ) stretchesVideo;
+- ( void ) addVoutSubview:( NSView * ) aView;
+- ( void ) removeVoutSubview:( NSView * ) aView;
+ at end
+
+ at implementation VLCNSView
+- ( id ) initWithFrame:( NSRect ) frameRect
+{
+    if ((self = [super initWithFrame:frameRect]) == nil){ return nil; }
+    return self;
+}
+- ( void ) dealloc
+{
+    [super dealloc];
+}
+- ( void ) setStretchesVideo : ( BOOL ) value
+{
+    stretchesVideo = value;
+}
+- ( BOOL ) stretchesVideo
+{
+    return stretchesVideo;
+}
+- ( void ) addVoutSubview:( NSView * ) aView
+{
+    [aView setFrame:[self bounds]];
+    [self addSubview:aView];
+    [aView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
+}
+- (void) removeVoutSubview:(NSView *)aView {}
+ at end
+
+RenderWidget::RenderWidget( QWidget *parent ) :
+    QWidget( parent )
+{
+    m_video = [[VLCNSView alloc] init];
+    m_container = new QMacCocoaViewContainer( m_video, this );
+    m_container->setAutoFillBackground( true );
+
+    QPalette videoPalette = m_container->palette();
+    videoPalette.setColor( QPalette::Window, QColor( Qt::black ) );
+    m_container->setPalette( videoPalette );
+
+    QVBoxLayout* layout = new QVBoxLayout;
+    layout->addWidget( m_container );
+    setLayout( layout );
+}
+
+/* winId should return pointer to the NSView, m_video */
+NativeNSViewRef
+RenderWidget::id() const
+{
+    return m_video;
+}
+
+void
+RenderWidget::release()
+{
+    [m_video release];
+}
+
+#endif



More information about the Vlmc-devel mailing list