mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 03:35:21 +00:00
osxvideosink: fix navigation when force-aspect-ratio is activated
This commit is contained in:
parent
fd19abf9ee
commit
7cc93e9195
3 changed files with 25 additions and 24 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue