osxvideosink: fix navigation when force-aspect-ratio is activated
authorAndoni Morales Alastruey <ylatuya@gmail.com>
Wed, 16 May 2012 19:12:22 +0000 (21:12 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 24 May 2012 12:35:37 +0000 (14:35 +0200)
sys/osxvideo/cocoawindow.h
sys/osxvideo/cocoawindow.m
sys/osxvideo/osxvideosink.m

index 049bb5f..d811cb6 100644 (file)
@@ -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;
index b41b20d..2e93983 100644 (file)
   data = nil;
   width = frame.size.width;
   height = frame.size.height;
+  drawingBounds = NSMakeRect(0, 0, width, height);
 
   GST_LOG ("Width: %d Height: %d", width, height);
 
   return self;
 }
 
+- (NSRect) getDrawingBounds {
+  return drawingBounds;
+}
+
 - (void) reshape {
   NSRect bounds;
   gdouble frame_par, view_par;
     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);
 }
 
 - (void)sendMouseEvent:(NSEvent *)event: (const char *)event_name
 {
   NSPoint location;
-  NSRect bounds;
   gint button;
-  gint view_width, view_height;
   gdouble x, y;
 
   if (!navigation)
 
   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
index eaa531d..e7de9d4 100644 (file)
@@ -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