From c1a89c642e30963c3c2d8f58b6f93bcc8bd94fc8 Mon Sep 17 00:00:00 2001 From: Pierre d'Herbemont Date: Sun, 13 Jul 2008 18:34:30 +0200 Subject: [PATCH] macosx: Fix aspect ratio. This might requires some other adjustements. --- modules/gui/macosx/embeddedwindow.h | 4 +++ modules/gui/macosx/embeddedwindow.m | 22 +++++++++++++ modules/gui/macosx/vout.m | 51 ++++++++++++++++------------- 3 files changed, 55 insertions(+), 22 deletions(-) diff --git a/modules/gui/macosx/embeddedwindow.h b/modules/gui/macosx/embeddedwindow.h index e8e408d0ac..c31aa48e5f 100644 --- a/modules/gui/macosx/embeddedwindow.h +++ b/modules/gui/macosx/embeddedwindow.h @@ -51,6 +51,8 @@ NSRecursiveLock * o_animation_lock; BOOL b_window_is_invisible; + + NSSize videoRatio; } - (void)controlTintChanged; @@ -59,6 +61,8 @@ - (void)playStatusUpdated: (int)i_status; - (void)setSeekable: (BOOL)b_seekable; +- (void)setVideoRatio:(NSSize)ratio; + - (NSView *)mainView; - (BOOL)isFullscreen; diff --git a/modules/gui/macosx/embeddedwindow.m b/modules/gui/macosx/embeddedwindow.m index 774e18d016..3277971389 100644 --- a/modules/gui/macosx/embeddedwindow.m +++ b/modules/gui/macosx/embeddedwindow.m @@ -70,9 +70,12 @@ [o_btn_fullscreen setState: NO]; b_fullscreen = NO; + [self setDelegate:self]; + /* Make sure setVisible: returns NO */ [self orderOut:self]; b_window_is_invisible = YES; + videoRatio = NSMakeSize( 0., 0. ); } - (void)controlTintChanged @@ -167,6 +170,25 @@ return o_view; } +- (void)setVideoRatio:(NSSize)ratio +{ + videoRatio = ratio; +} + +- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize +{ + if( videoRatio.height == 0. || videoRatio.width == 0. ) + return proposedFrameSize; + + NSRect viewRect = [o_view convertRect:[o_view bounds] toView: nil]; + NSRect contentRect = [self contentRectForFrameRect:[self frame]]; + float marginy = viewRect.origin.y + [self frame].size.height - contentRect.size.height; + float marginx = contentRect.size.width - viewRect.size.width; + proposedFrameSize.height = (proposedFrameSize.width - marginx) * videoRatio.height / videoRatio.width + marginy; + + return proposedFrameSize; +} + /***************************************************************************** * Fullscreen support */ diff --git a/modules/gui/macosx/vout.m b/modules/gui/macosx/vout.m index dd0d9ea1ab..868eb2daa1 100644 --- a/modules/gui/macosx/vout.m +++ b/modules/gui/macosx/vout.m @@ -343,36 +343,44 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, } } -- (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate +- (NSSize)voutSizeForFactor: (float)factor { - NSSize newsize; int i_corrected_height, i_corrected_width; - NSPoint topleftbase; - NSPoint topleftscreen; + NSSize newsize; + + if( p_vout->render.i_height * p_vout->render.i_aspect > + p_vout->render.i_width * VOUT_ASPECT_FACTOR ) + { + i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect / + VOUT_ASPECT_FACTOR; + newsize.width = (int) ( i_corrected_width * factor ); + newsize.height = (int) ( p_vout->render.i_height * factor ); + } + else + { + i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR / + p_vout->render.i_aspect; + newsize.width = (int) ( p_vout->render.i_width * factor ); + newsize.height = (int) ( i_corrected_height * factor ); + } + return newsize; +} + +- (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate +{ if ( !p_vout->b_fullscreen ) { + NSSize newsize; + NSPoint topleftbase; + NSPoint topleftscreen; NSView *mainView; NSRect new_frame; topleftbase.x = 0; topleftbase.y = [o_window frame].size.height; topleftscreen = [o_window convertBaseToScreen: topleftbase]; - if( p_vout->render.i_height * p_vout->render.i_aspect > - p_vout->render.i_width * VOUT_ASPECT_FACTOR ) - { - i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect / - VOUT_ASPECT_FACTOR; - newsize.width = (int) ( i_corrected_width * factor ); - newsize.height = (int) ( p_vout->render.i_height * factor ); - } - else - { - i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR / - p_vout->render.i_aspect; - newsize.width = (int) ( p_vout->render.i_width * factor ); - newsize.height = (int) ( i_corrected_height * factor ); - } + newsize = [self voutSizeForFactor:factor]; /* In fullscreen mode we need to use a view that is different from * ourselves, with the VLCEmbeddedWindow */ @@ -390,8 +398,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, new_frame.origin.x = topleftscreen.x; new_frame.origin.y = topleftscreen.y - new_frame.size.height; - [o_window setFrame: new_frame display: animate animate: animate]; - + [o_window setFrame:new_frame display:animate animate:animate]; p_vout->i_changes |= VOUT_SIZE_CHANGE; } } @@ -958,7 +965,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])]; - [o_window setAspectRatio:NSMakeSize([o_window frame].size.width, [o_window frame].size.height)]; + [o_embeddedwindow setVideoRatio:[self voutSizeForFactor:1.0]]; /* Make sure our window is visible, if we are not in fullscreen */ if (![o_window isFullscreen]) -- 2.39.5