summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-04-17 21:22:22 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-04-17 21:22:22 +0200
commit9a6e6b2fc24cce5bed2831d892fbaf91f7926b53 (patch)
treecedb385fe686b7e193ee85e877876378b34fefa7 /video
parent22d53fb97cfd534b131b3f8a87afb56c55f1de52 (diff)
downloadmpv-9a6e6b2fc24cce5bed2831d892fbaf91f7926b53.tar.bz2
mpv-9a6e6b2fc24cce5bed2831d892fbaf91f7926b53.tar.xz
cocoa_common: keep aspect ratio when clipping window
With commit 33ffc283 resizing to double size would cause the window to lose aspect ratio. This commit fixes this bug.
Diffstat (limited to 'video')
-rw-r--r--video/out/cocoa_common.m42
1 files changed, 35 insertions, 7 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index 836373e051..ee451ed1dc 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -92,6 +92,8 @@ static bool RightAltPressed(NSEvent *event)
- (void)fullscreen;
- (void)mouseEvent:(NSEvent *)theEvent;
- (void)mulSize:(float)multiplier;
+- (int)titleHeight;
+- (NSRect)clipFrame:(NSRect)frame withContentAspect:(NSSize) aspect;
- (void)setContentSize:(NSSize)newSize keepCentered:(BOOL)keepCentered;
@end
@@ -903,21 +905,47 @@ void create_menu()
}
}
+- (int)titleHeight
+{
+ NSRect of = [self frame];
+ NSRect cb = [[self contentView] bounds];
+ return of.size.height - cb.size.height;
+}
+
+- (NSRect)clipFrame:(NSRect)frame withContentAspect:(NSSize) aspect
+{
+ NSRect vf = [[self screen] visibleFrame];
+ double ratio = (double)aspect.width / (double)aspect.height;
+
+ // clip frame to screens visibile frame
+ frame = CGRectIntersection(frame, vf);
+
+ NSSize s = frame.size;
+ s.height -= [self titleHeight];
+
+ if (s.width > s.height) {
+ s.width = ((double)s.height * ratio + 0.5);
+ } else {
+ s.height = ((double)s.width * 1/ratio + 0.5);
+ }
+
+ s.height += [self titleHeight];
+ frame.size = s;
+
+ return frame;
+}
+
- (void)setCenteredContentSize:(NSSize)ns
{
#define get_center(x) NSMakePoint(CGRectGetMidX((x)), CGRectGetMidY((x)))
NSRect of = [self frame];
NSRect vf = [[self screen] visibleFrame];
- NSRect cb = [[self contentView] bounds];
- int title_h = of.size.height - cb.size.height;
-
NSPoint old_center = get_center(of);
- NSRect nf =
- NSMakeRect(vf.origin.x, vf.origin.y, ns.width, ns.height + title_h);
+ NSRect nf = NSMakeRect(vf.origin.x, vf.origin.y,
+ ns.width, ns.height + [self titleHeight]);
- // clip frame to screens visibile frame
- nf = CGRectIntersection(nf, vf);
+ nf = [self clipFrame:nf withContentAspect:ns];
NSPoint new_center = get_center(nf);