2007-01-30 17:19:33 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2004 Zaheer Abbas Merali <zaheerabbas at merali dot org>
|
2007-02-27 12:02:03 +00:00
|
|
|
* Copyright (C) 2007 Pioneers of the Inevitable <songbird@songbirdnest.com>
|
2007-01-30 17:19:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
2007-02-27 12:02:03 +00:00
|
|
|
*
|
|
|
|
* The development of this code was made possible due to the involvement of Pioneers
|
|
|
|
* of the Inevitable, the creators of the Songbird Music player
|
|
|
|
*
|
2007-01-30 17:19:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* inspiration gained from looking at source of osx video out of xine and vlc
|
|
|
|
* and is reflected in the code
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <Cocoa/Cocoa.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#import "cocoawindow.h"
|
|
|
|
#import "osxvideosink.h"
|
|
|
|
|
|
|
|
#include <OpenGL/OpenGL.h>
|
|
|
|
#include <OpenGL/gl.h>
|
|
|
|
#include <OpenGL/glext.h>
|
|
|
|
|
|
|
|
/* Debugging category */
|
|
|
|
#include <gst/gstinfo.h>
|
|
|
|
|
|
|
|
@ implementation GstOSXVideoSinkWindow
|
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
/* The object has to be released */
|
2012-05-14 16:01:02 +00:00
|
|
|
- (id) initWithContentNSRect: (NSRect) rect
|
2007-01-30 17:19:33 +00:00
|
|
|
styleMask: (unsigned int) styleMask
|
|
|
|
backing: (NSBackingStoreType) bufferingType
|
|
|
|
defer: (BOOL) flag
|
|
|
|
screen:(NSScreen *) aScreen
|
|
|
|
{
|
|
|
|
self = [super initWithContentRect: rect
|
|
|
|
styleMask: styleMask
|
|
|
|
backing: bufferingType
|
|
|
|
defer: flag
|
|
|
|
screen:aScreen];
|
|
|
|
|
|
|
|
GST_DEBUG ("Initializing GstOSXvideoSinkWindow");
|
|
|
|
|
|
|
|
gstview = [[GstGLView alloc] initWithFrame:rect];
|
|
|
|
|
|
|
|
if (gstview)
|
|
|
|
[self setContentView:gstview];
|
|
|
|
[self setTitle:@"GStreamer Video Output"];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setContentSize:(NSSize) size {
|
|
|
|
width = size.width;
|
|
|
|
height = size.height;
|
|
|
|
|
|
|
|
[gstview setVideoSize: (int) width:(int) height];
|
|
|
|
|
|
|
|
[super setContentSize:size];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (GstGLView *) gstView {
|
|
|
|
return gstview;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) awakeFromNib {
|
|
|
|
[self setAcceptsMouseMovedEvents:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OpenGL implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
@ implementation GstGLView
|
|
|
|
|
|
|
|
- (id) initWithFrame:(NSRect) frame {
|
|
|
|
NSOpenGLPixelFormat *fmt;
|
|
|
|
NSOpenGLPixelFormatAttribute attribs[] = {
|
|
|
|
NSOpenGLPFAAccelerated,
|
|
|
|
NSOpenGLPFANoRecovery,
|
|
|
|
NSOpenGLPFADoubleBuffer,
|
|
|
|
NSOpenGLPFAColorSize, 24,
|
|
|
|
NSOpenGLPFAAlphaSize, 8,
|
|
|
|
NSOpenGLPFADepthSize, 24,
|
|
|
|
NSOpenGLPFAWindow,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
fmt = [[NSOpenGLPixelFormat alloc]
|
|
|
|
initWithAttributes:attribs];
|
|
|
|
|
|
|
|
if (!fmt) {
|
|
|
|
GST_WARNING ("Cannot create NSOpenGLPixelFormat");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
self = [super initWithFrame: frame pixelFormat:fmt];
|
2011-10-04 08:00:02 +00:00
|
|
|
[fmt release];
|
2007-01-30 17:19:33 +00:00
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
actualContext = [self openGLContext];
|
|
|
|
[actualContext makeCurrentContext];
|
|
|
|
[actualContext update];
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
/* Black background */
|
|
|
|
glClearColor (0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
pi_texture = 0;
|
2007-03-14 16:30:19 +00:00
|
|
|
data = nil;
|
2007-01-30 17:19:33 +00:00
|
|
|
width = frame.size.width;
|
|
|
|
height = frame.size.height;
|
2012-05-16 19:12:22 +00:00
|
|
|
drawingBounds = NSMakeRect(0, 0, width, height);
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
GST_LOG ("Width: %d Height: %d", width, height);
|
|
|
|
|
2012-05-14 12:27:58 +00:00
|
|
|
trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
|
|
|
options: (NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow)
|
|
|
|
owner:self
|
|
|
|
userInfo:nil];
|
|
|
|
|
|
|
|
[self addTrackingArea:trackingArea];
|
2012-05-24 18:43:16 +00:00
|
|
|
mainThread = [NSThread mainThread];
|
2012-05-14 12:27:58 +00:00
|
|
|
|
2007-01-30 17:19:33 +00:00
|
|
|
[self initTextures];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-05-16 19:12:22 +00:00
|
|
|
- (NSRect) getDrawingBounds {
|
|
|
|
return drawingBounds;
|
|
|
|
}
|
|
|
|
|
2007-01-30 17:19:33 +00:00
|
|
|
- (void) reshape {
|
|
|
|
NSRect bounds;
|
2012-05-16 16:52:45 +00:00
|
|
|
gdouble frame_par, view_par;
|
|
|
|
gint view_height, view_width, c_height, c_width, c_x, c_y;
|
|
|
|
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
GST_LOG ("reshaping");
|
|
|
|
|
|
|
|
if (!initDone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
[actualContext makeCurrentContext];
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
bounds = [self bounds];
|
2012-05-16 16:52:45 +00:00
|
|
|
view_width = bounds.size.width;
|
|
|
|
view_height = bounds.size.height;
|
|
|
|
|
|
|
|
frame_par = (gdouble) width / height;
|
|
|
|
view_par = (gdouble) view_width / view_height;
|
|
|
|
if (!keepAspectRatio)
|
|
|
|
view_par = frame_par;
|
|
|
|
|
|
|
|
if (frame_par == view_par) {
|
|
|
|
c_height = view_height;
|
|
|
|
c_width = view_width;
|
|
|
|
c_x = 0;
|
|
|
|
c_y = 0;
|
|
|
|
} else if (frame_par < view_par) {
|
|
|
|
c_height = view_height;
|
|
|
|
c_width = c_height * frame_par;
|
|
|
|
c_x = (view_width - c_width) / 2;
|
|
|
|
c_y = 0;
|
|
|
|
} else {
|
|
|
|
c_width = view_width;
|
|
|
|
c_height = c_width / frame_par;
|
|
|
|
c_x = 0;
|
|
|
|
c_y = (view_height - c_height) / 2;
|
|
|
|
}
|
2007-01-30 17:19:33 +00:00
|
|
|
|
2012-05-16 19:12:22 +00:00
|
|
|
drawingBounds = NSMakeRect(c_x, c_y, c_width, c_height);
|
2012-05-16 16:52:45 +00:00
|
|
|
glViewport (c_x, c_y, (GLint) c_width, (GLint) c_height);
|
2007-01-30 17:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) initTextures {
|
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
[actualContext makeCurrentContext];
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
/* Free previous texture if any */
|
2007-03-14 16:30:19 +00:00
|
|
|
if (pi_texture) {
|
2008-05-06 09:33:46 +00:00
|
|
|
glDeleteTextures (1, (GLuint *)&pi_texture);
|
2007-01-30 17:19:33 +00:00
|
|
|
}
|
2007-03-14 16:30:19 +00:00
|
|
|
|
|
|
|
if (data) {
|
|
|
|
data = g_realloc (data, width * height * sizeof(short)); // short or 3byte?
|
|
|
|
} else {
|
|
|
|
data = g_malloc0(width * height * sizeof(short));
|
|
|
|
}
|
2007-01-30 17:19:33 +00:00
|
|
|
/* Create textures */
|
2008-05-06 09:33:46 +00:00
|
|
|
glGenTextures (1, (GLuint *)&pi_texture);
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
glEnable (GL_TEXTURE_RECTANGLE_EXT);
|
|
|
|
glEnable (GL_UNPACK_CLIENT_STORAGE_APPLE);
|
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
|
|
|
|
glPixelStorei (GL_UNPACK_ROW_LENGTH, width);
|
|
|
|
|
2007-01-30 17:19:33 +00:00
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, pi_texture);
|
|
|
|
|
|
|
|
/* Use VRAM texturing */
|
|
|
|
glTexParameteri (GL_TEXTURE_RECTANGLE_EXT,
|
|
|
|
GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_CACHED_APPLE);
|
|
|
|
|
|
|
|
/* Tell the driver not to make a copy of the texture but to use
|
|
|
|
our buffer */
|
|
|
|
glPixelStorei (GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
|
|
|
|
|
|
|
|
/* Linear interpolation */
|
|
|
|
glTexParameteri (GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri (GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
|
|
|
/* I have no idea what this exactly does, but it seems to be
|
|
|
|
necessary for scaling */
|
|
|
|
glTexParameteri (GL_TEXTURE_RECTANGLE_EXT,
|
|
|
|
GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri (GL_TEXTURE_RECTANGLE_EXT,
|
|
|
|
GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2007-03-14 16:30:19 +00:00
|
|
|
// glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); WHY ??
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
glTexImage2D (GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA,
|
2007-03-14 16:30:19 +00:00
|
|
|
width, height, 0,
|
|
|
|
GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, data);
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
initDone = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) reloadTexture {
|
|
|
|
if (!initDone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG ("Reloading Texture");
|
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
[actualContext makeCurrentContext];
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, pi_texture);
|
2007-03-14 16:30:19 +00:00
|
|
|
glPixelStorei (GL_UNPACK_ROW_LENGTH, width);
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
/* glTexSubImage2D is faster than glTexImage2D
|
|
|
|
http://developer.apple.com/samplecode/Sample_Code/Graphics_3D/
|
|
|
|
TextureRange/MainOpenGLView.m.htm */
|
2007-03-14 16:30:19 +00:00
|
|
|
glTexSubImage2D (GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0,
|
|
|
|
width, height,
|
|
|
|
GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, data); //FIXME
|
2007-01-30 17:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) cleanUp {
|
|
|
|
initDone = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawQuad {
|
|
|
|
f_x = 1.0;
|
|
|
|
f_y = 1.0;
|
|
|
|
|
|
|
|
glBegin (GL_QUADS);
|
|
|
|
/* Top left */
|
|
|
|
glTexCoord2f (0.0, 0.0);
|
|
|
|
glVertex2f (-f_x, f_y);
|
|
|
|
/* Bottom left */
|
|
|
|
glTexCoord2f (0.0, (float) height);
|
|
|
|
glVertex2f (-f_x, -f_y);
|
|
|
|
/* Bottom right */
|
|
|
|
glTexCoord2f ((float) width, (float) height);
|
|
|
|
glVertex2f (f_x, -f_y);
|
|
|
|
/* Top right */
|
|
|
|
glTexCoord2f ((float) width, 0.0);
|
|
|
|
glVertex2f (f_x, f_y);
|
|
|
|
glEnd ();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawRect:(NSRect) rect {
|
2008-05-06 09:33:46 +00:00
|
|
|
GLint params[] = { 1 };
|
2007-01-30 17:19:33 +00:00
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
[actualContext makeCurrentContext];
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
CGLSetParameter (CGLGetCurrentContext (), kCGLCPSwapInterval, params);
|
|
|
|
|
|
|
|
/* Black background */
|
|
|
|
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
if (!initDone) {
|
2007-03-14 16:30:19 +00:00
|
|
|
[actualContext flushBuffer];
|
2007-01-30 17:19:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw */
|
|
|
|
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, pi_texture); // FIXME
|
|
|
|
[self drawQuad];
|
|
|
|
/* Draw */
|
2007-03-14 16:30:19 +00:00
|
|
|
[actualContext flushBuffer];
|
2007-01-30 17:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) displayTexture {
|
|
|
|
if ([self lockFocusIfCanDraw]) {
|
|
|
|
|
|
|
|
[self drawRect:[self bounds]];
|
|
|
|
[self reloadTexture];
|
|
|
|
|
|
|
|
[self unlockFocus];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (char *) getTextureBuffer {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFullScreen:(BOOL) flag {
|
|
|
|
if (!fullscreen && flag) {
|
|
|
|
// go to full screen
|
|
|
|
/* Create the new pixel format */
|
|
|
|
NSOpenGLPixelFormat *fmt;
|
|
|
|
NSOpenGLPixelFormatAttribute attribs[] = {
|
|
|
|
NSOpenGLPFAAccelerated,
|
|
|
|
NSOpenGLPFANoRecovery,
|
|
|
|
NSOpenGLPFADoubleBuffer,
|
|
|
|
NSOpenGLPFAColorSize, 24,
|
|
|
|
NSOpenGLPFAAlphaSize, 8,
|
|
|
|
NSOpenGLPFADepthSize, 24,
|
|
|
|
NSOpenGLPFAFullScreen,
|
|
|
|
NSOpenGLPFAScreenMask,
|
|
|
|
CGDisplayIDToOpenGLDisplayMask (kCGDirectMainDisplay),
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
fmt = [[NSOpenGLPixelFormat alloc]
|
|
|
|
initWithAttributes:attribs];
|
|
|
|
|
|
|
|
if (!fmt) {
|
|
|
|
GST_WARNING ("Cannot create NSOpenGLPixelFormat");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the new OpenGL context */
|
|
|
|
fullScreenContext = [[NSOpenGLContext alloc]
|
|
|
|
initWithFormat: fmt shareContext:nil];
|
|
|
|
if (!fullScreenContext) {
|
|
|
|
GST_WARNING ("Failed to create new NSOpenGLContext");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
actualContext = fullScreenContext;
|
|
|
|
|
2007-01-30 17:19:33 +00:00
|
|
|
/* Capture display, switch to fullscreen */
|
|
|
|
if (CGCaptureAllDisplays () != CGDisplayNoErr) {
|
|
|
|
GST_WARNING ("CGCaptureAllDisplays() failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[fullScreenContext setFullScreen];
|
|
|
|
[fullScreenContext makeCurrentContext];
|
|
|
|
|
|
|
|
fullscreen = YES;
|
|
|
|
|
|
|
|
[self initTextures];
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
|
|
|
|
} else if (fullscreen && !flag) {
|
|
|
|
// fullscreen now and needs to go back to normal
|
|
|
|
initDone = NO;
|
2007-03-14 16:30:19 +00:00
|
|
|
|
|
|
|
actualContext = [self openGLContext];
|
|
|
|
|
2007-01-30 17:19:33 +00:00
|
|
|
[NSOpenGLContext clearCurrentContext];
|
2007-03-14 16:30:19 +00:00
|
|
|
[fullScreenContext clearDrawable];
|
|
|
|
[fullScreenContext release];
|
|
|
|
fullScreenContext = nil;
|
2007-01-30 17:19:33 +00:00
|
|
|
|
|
|
|
CGReleaseAllDisplays ();
|
|
|
|
|
|
|
|
[self reshape];
|
|
|
|
[self initTextures];
|
|
|
|
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
|
|
|
|
fullscreen = NO;
|
|
|
|
initDone = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setVideoSize: (int) w:(int) h {
|
|
|
|
GST_LOG ("width:%d, height:%d", w, h);
|
|
|
|
|
|
|
|
width = w;
|
|
|
|
height = h;
|
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
// if (data) g_free(data);
|
2007-01-30 17:19:33 +00:00
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
// data = g_malloc0 (2 * w * h);
|
|
|
|
[self initTextures];
|
2012-05-16 16:52:45 +00:00
|
|
|
[self reshape];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setKeepAspectRatio: (BOOL) flag {
|
|
|
|
keepAspectRatio = flag;
|
|
|
|
[self reshape];
|
2007-01-30 17:19:33 +00:00
|
|
|
}
|
|
|
|
|
2012-05-24 18:43:16 +00:00
|
|
|
- (void) setMainThread: (NSThread *) thread {
|
|
|
|
mainThread = thread;
|
|
|
|
}
|
|
|
|
|
2010-05-11 08:52:58 +00:00
|
|
|
- (void) haveSuperviewReal:(NSMutableArray *)closure {
|
|
|
|
BOOL haveSuperview = [self superview] != nil;
|
|
|
|
[closure addObject:[NSNumber numberWithBool:haveSuperview]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) haveSuperview {
|
|
|
|
NSMutableArray *closure = [NSMutableArray arrayWithCapacity:1];
|
2012-05-24 18:43:16 +00:00
|
|
|
[self performSelector:@selector(haveSuperviewReal:)
|
|
|
|
onThread:mainThread
|
|
|
|
withObject:(id)closure waitUntilDone:YES];
|
2010-05-11 08:52:58 +00:00
|
|
|
|
|
|
|
return [[closure objectAtIndex:0] boolValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addToSuperviewReal:(NSView *)superview {
|
|
|
|
NSRect bounds;
|
|
|
|
[superview addSubview:self];
|
|
|
|
bounds = [superview bounds];
|
|
|
|
[self setFrame:bounds];
|
|
|
|
[self setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addToSuperview: (NSView *)superview {
|
2012-05-24 18:43:16 +00:00
|
|
|
[self performSelector:@selector(addToSuperviewReal:)
|
|
|
|
onThread:mainThread
|
|
|
|
withObject:superview waitUntilDone:YES];
|
2010-05-11 08:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeFromSuperview: (id)unused
|
|
|
|
{
|
|
|
|
[self removeFromSuperview];
|
|
|
|
}
|
|
|
|
|
2007-03-14 16:30:19 +00:00
|
|
|
- (void) dealloc {
|
|
|
|
GST_LOG ("dealloc called");
|
|
|
|
if (data) g_free(data);
|
|
|
|
|
|
|
|
if (fullScreenContext) {
|
|
|
|
[NSOpenGLContext clearCurrentContext];
|
|
|
|
[fullScreenContext clearDrawable];
|
|
|
|
[fullScreenContext release];
|
|
|
|
if (actualContext == fullScreenContext) actualContext = nil;
|
|
|
|
fullScreenContext = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
2012-05-14 12:27:58 +00:00
|
|
|
|
|
|
|
- (void)updateTrackingAreas {
|
|
|
|
[self removeTrackingArea:trackingArea];
|
|
|
|
[trackingArea release];
|
|
|
|
trackingArea = [[NSTrackingArea alloc] initWithRect: [self bounds]
|
|
|
|
options: (NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow)
|
|
|
|
owner:self userInfo:nil];
|
|
|
|
[self addTrackingArea:trackingArea];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)acceptsFirstResponder {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNavigation:(GstNavigation *)nav
|
|
|
|
{
|
|
|
|
navigation = nav;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendMouseEvent:(NSEvent *)event: (const char *)event_name
|
|
|
|
{
|
|
|
|
NSPoint location;
|
|
|
|
gint button;
|
|
|
|
gdouble x, y;
|
|
|
|
|
|
|
|
if (!navigation)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch ([event type]) {
|
|
|
|
case NSMouseMoved:
|
|
|
|
button = 0;
|
|
|
|
break;
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
button = 1;
|
|
|
|
break;
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
button = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
button = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
location = [self convertPoint:[event locationInWindow] fromView:nil];
|
|
|
|
|
2012-05-16 19:12:22 +00:00
|
|
|
x = location.x;
|
|
|
|
y = location.y;
|
2012-05-14 12:27:58 +00:00
|
|
|
/* invert Y */
|
|
|
|
|
2012-05-16 19:12:22 +00:00
|
|
|
y = (1 - ((gdouble) y) / [self bounds].size.height) * [self bounds].size.height;
|
|
|
|
|
|
|
|
gst_navigation_send_mouse_event (navigation, event_name, button, x, y);
|
2012-05-14 12:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendKeyEvent:(NSEvent *)event: (const char *)event_name
|
|
|
|
{
|
|
|
|
NSString *keyCharStr = [event charactersIgnoringModifiers];
|
|
|
|
gchar * key_str;
|
|
|
|
|
|
|
|
if (!navigation)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( [keyCharStr length] == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( [keyCharStr length] == 1 ) {
|
|
|
|
key_str = g_strdup_printf("%c", [keyCharStr characterAtIndex:0]);
|
|
|
|
gst_navigation_send_key_event(navigation, event_name, (const gchar *) key_str);
|
|
|
|
g_free(key_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyDown:(NSEvent *) event;
|
|
|
|
{
|
|
|
|
[self sendKeyEvent: event: "key-press"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyUp:(NSEvent *) event;
|
|
|
|
{
|
|
|
|
[self sendKeyEvent: event: "key-release"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDown:(NSEvent *) event;
|
|
|
|
{
|
|
|
|
[self sendMouseEvent:event: "mouse-button-press"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseUp:(NSEvent *) event;
|
|
|
|
{
|
|
|
|
[self sendMouseEvent:event: "mouse-button-release"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseMoved:(NSEvent *)event;
|
|
|
|
{
|
|
|
|
[self sendMouseEvent:event: "mouse-move"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseEntered:(NSEvent *)event;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseExited:(NSEvent *)event;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-01-30 17:19:33 +00:00
|
|
|
@end
|