From 7cc93e9195475e0b24f8349e3c3b8bdcdc92bf9e Mon Sep 17 00:00:00 2001 From: Andoni Morales Alastruey Date: Wed, 16 May 2012 21:12:22 +0200 Subject: [PATCH] osxvideosink: fix navigation when force-aspect-ratio is activated --- sys/osxvideo/cocoawindow.h | 2 ++ sys/osxvideo/cocoawindow.m | 24 +++++++++++------------- sys/osxvideo/osxvideosink.m | 23 ++++++++++++----------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/sys/osxvideo/cocoawindow.h b/sys/osxvideo/cocoawindow.h index 049bb5f..d811cb6 100644 --- a/sys/osxvideo/cocoawindow.h +++ b/sys/osxvideo/cocoawindow.h @@ -48,6 +48,7 @@ struct _GstOSXImage; NSOpenGLContext* actualContext; NSTrackingArea *trackingArea; GstNavigation *navigation; + NSRect drawingBounds; } - (void) drawQuad; - (void) drawRect: (NSRect) rect; @@ -61,6 +62,7 @@ struct _GstOSXImage; - (void) setKeepAspectRatio: (BOOL) flag; - (void) reshape; - (void) setVideoSize: (int) w: (int) h; +- (NSRect) getDrawingBounds; - (BOOL) haveSuperview; - (void) haveSuperviewReal: (NSMutableArray *)closure; - (void) addToSuperview: (NSView *)superview; diff --git a/sys/osxvideo/cocoawindow.m b/sys/osxvideo/cocoawindow.m index b41b20d..2e93983 100644 --- a/sys/osxvideo/cocoawindow.m +++ b/sys/osxvideo/cocoawindow.m @@ -126,6 +126,7 @@ data = nil; width = frame.size.width; height = frame.size.height; + drawingBounds = NSMakeRect(0, 0, width, height); GST_LOG ("Width: %d Height: %d", width, height); @@ -140,6 +141,10 @@ return self; } +- (NSRect) getDrawingBounds { + return drawingBounds; +} + - (void) reshape { NSRect bounds; gdouble frame_par, view_par; @@ -180,6 +185,7 @@ c_y = (view_height - c_height) / 2; } + drawingBounds = NSMakeRect(c_x, c_y, c_width, c_height); glViewport (c_x, c_y, (GLint) c_width, (GLint) c_height); } @@ -475,9 +481,7 @@ - (void)sendMouseEvent:(NSEvent *)event: (const char *)event_name { NSPoint location; - NSRect bounds; gint button; - gint view_width, view_height; gdouble x, y; if (!navigation) @@ -502,19 +506,13 @@ location = [self convertPoint:[event locationInWindow] fromView:nil]; - /* scale X and Y locations to the frame size */ - bounds = [self bounds]; - view_width = bounds.size.width; - view_height = bounds.size.height; - - x = ((gdouble) location.x / view_width) * width; - y = ((gdouble) location.y / view_height) * height; - + x = location.x; + y = location.y; /* invert Y */ - y = (1 - y / height) * height; - gst_navigation_send_mouse_event (navigation, event_name, button, - x, y); + y = (1 - ((gdouble) y) / [self bounds].size.height) * [self bounds].size.height; + + gst_navigation_send_mouse_event (navigation, event_name, button, x, y); } - (void)sendKeyEvent:(NSEvent *)event: (const char *)event_name diff --git a/sys/osxvideo/osxvideosink.m b/sys/osxvideo/osxvideosink.m index eaa531d..e7de9d4 100644 --- a/sys/osxvideo/osxvideosink.m +++ b/sys/osxvideo/osxvideosink.m @@ -590,6 +590,7 @@ gst_osx_video_sink_navigation_send_event (GstNavigation * navigation, GstPad *peer; GstEvent *event; GstVideoRectangle src, dst, result; + NSRect bounds; gdouble x, y, xscale = 1.0, yscale = 1.0; peer = gst_pad_get_peer (GST_VIDEO_SINK_PAD (osxvideosink)); @@ -599,24 +600,24 @@ gst_osx_video_sink_navigation_send_event (GstNavigation * navigation, event = gst_event_new_navigation (structure); - /* FIXME: Use this when this sink is capable of keeping the display - * aspect ratio */ - if (0) { //(osxvideosink->keep_aspect) { + bounds = [osxvideosink->osxwindow->gstview getDrawingBounds]; + + if (osxvideosink->keep_par) { /* We get the frame position using the calculated geometry from _setcaps that respect pixel aspect ratios */ src.w = GST_VIDEO_SINK_WIDTH (osxvideosink); src.h = GST_VIDEO_SINK_HEIGHT (osxvideosink); - //dst.w = osxvideosink->osxwindow->gstview->width; - //dst.w = osxvideosink->osxwindow->gstview->height; + dst.w = bounds.size.width; + dst.h = bounds.size.height; gst_video_sink_center_rect (src, dst, &result, TRUE); - //result.x += osxvideosink->gstview->x; - //result.y += osxvideosink->gstview->y; + result.x += bounds.origin.x; + result.y += bounds.origin.y; } else { - result.x = 0; - result.y = 0; - result.w = osxvideosink->osxwindow->width; - result.h = osxvideosink->osxwindow->height; + result.x = bounds.origin.x; + result.y = bounds.origin.y; + result.w = bounds.size.width; + result.h = bounds.size.height; } /* We calculate scaling using the original video frames geometry to include -- 2.7.4