Commit c1a89c64 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

macosx: Fix aspect ratio.

This might requires some other adjustements.
parent 4ad2f8dc
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
NSRecursiveLock * o_animation_lock; NSRecursiveLock * o_animation_lock;
BOOL b_window_is_invisible; BOOL b_window_is_invisible;
NSSize videoRatio;
} }
- (void)controlTintChanged; - (void)controlTintChanged;
...@@ -59,6 +61,8 @@ ...@@ -59,6 +61,8 @@
- (void)playStatusUpdated: (int)i_status; - (void)playStatusUpdated: (int)i_status;
- (void)setSeekable: (BOOL)b_seekable; - (void)setSeekable: (BOOL)b_seekable;
- (void)setVideoRatio:(NSSize)ratio;
- (NSView *)mainView; - (NSView *)mainView;
- (BOOL)isFullscreen; - (BOOL)isFullscreen;
......
...@@ -70,9 +70,12 @@ ...@@ -70,9 +70,12 @@
[o_btn_fullscreen setState: NO]; [o_btn_fullscreen setState: NO];
b_fullscreen = NO; b_fullscreen = NO;
[self setDelegate:self];
/* Make sure setVisible: returns NO */ /* Make sure setVisible: returns NO */
[self orderOut:self]; [self orderOut:self];
b_window_is_invisible = YES; b_window_is_invisible = YES;
videoRatio = NSMakeSize( 0., 0. );
} }
- (void)controlTintChanged - (void)controlTintChanged
...@@ -167,6 +170,25 @@ ...@@ -167,6 +170,25 @@
return o_view; 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 * Fullscreen support
*/ */
......
...@@ -343,36 +343,44 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -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; int i_corrected_height, i_corrected_width;
NSPoint topleftbase; NSSize newsize;
NSPoint topleftscreen;
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 ) if ( !p_vout->b_fullscreen )
{ {
NSSize newsize;
NSPoint topleftbase;
NSPoint topleftscreen;
NSView *mainView; NSView *mainView;
NSRect new_frame; NSRect new_frame;
topleftbase.x = 0; topleftbase.x = 0;
topleftbase.y = [o_window frame].size.height; topleftbase.y = [o_window frame].size.height;
topleftscreen = [o_window convertBaseToScreen: topleftbase]; topleftscreen = [o_window convertBaseToScreen: topleftbase];
if( p_vout->render.i_height * p_vout->render.i_aspect > newsize = [self voutSizeForFactor:factor];
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 );
}
/* In fullscreen mode we need to use a view that is different from /* In fullscreen mode we need to use a view that is different from
* ourselves, with the VLCEmbeddedWindow */ * ourselves, with the VLCEmbeddedWindow */
...@@ -390,8 +398,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -390,8 +398,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
new_frame.origin.x = topleftscreen.x; new_frame.origin.x = topleftscreen.x;
new_frame.origin.y = topleftscreen.y - new_frame.size.height; 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; p_vout->i_changes |= VOUT_SIZE_CHANGE;
} }
} }
...@@ -958,7 +965,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -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])]; [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 */ /* Make sure our window is visible, if we are not in fullscreen */
if (![o_window isFullscreen]) if (![o_window isFullscreen])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment