]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/embeddedwindow.m
macosx: Fix aspect ratio.
[vlc] / modules / gui / macosx / embeddedwindow.m
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
  */