]> git.sesse.net Git - vlc/commitdiff
macosx: Fix aspect ratio.
authorPierre d'Herbemont <pdherbemont@videolan.org>
Sun, 13 Jul 2008 16:34:30 +0000 (18:34 +0200)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Sun, 13 Jul 2008 16:34:30 +0000 (18:34 +0200)
This might requires some other adjustements.

modules/gui/macosx/embeddedwindow.h
modules/gui/macosx/embeddedwindow.m
modules/gui/macosx/vout.m

index e8e408d0ac3ad50fc954197cac5ca5d06fa02b4e..c31aa48e5f755608de8dd4ef87a6f2ad00553050 100644 (file)
@@ -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;
index 774e18d016a71a98f7dd542ec2554e92e307609c..327797138980e92869e8df1f45d0cc4ef366eaa6 100644 (file)
     [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
         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
  */
index dd0d9ea1ab67c8d13a0b5209fb0fdcb4ae9c1acc..868eb2daa16a56a90532cb45b206a71d8af526ad 100644 (file)
@@ -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])