summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-04-16 22:46:50 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-04-16 22:51:01 +0200
commit33ffc28373af9e749bdbed56db24500c10d84188 (patch)
treef9f49f7a83ad18480eff059d7d00b8db22daff2a /video
parent0c1d95e81b100464d42e8c08c5293cf0729d118d (diff)
downloadmpv-33ffc28373af9e749bdbed56db24500c10d84188.tar.bz2
mpv-33ffc28373af9e749bdbed56db24500c10d84188.tar.xz
cocoa_common: refactor centered resize
This refactor makes the code easier to understand. Also corrects a bug that caused the window to move to the left when the new size was bigger than the visible frame.
Diffstat (limited to 'video')
-rw-r--r--video/out/cocoa_common.m45
1 files changed, 21 insertions, 24 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index dddef51d4d..c1c576d366 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -905,33 +905,30 @@ void create_menu()
- (void)setCenteredContentSize:(NSSize)ns
{
- NSRect nf = [self frame];
- NSRect vf = [[self screen] visibleFrame];
- NSRect cb = [[self contentView] bounds];
- int title_height = nf.size.height - cb.size.height;
- double ratio = (double)ns.width / (double)ns.height;
-
- // clip the new size to the visibleFrame's size if needed
- if (ns.width > vf.size.width || ns.height + title_height > vf.size.height) {
- ns = vf.size;
- ns.height -= title_height; // make space for the title bar
-
- if (ns.width > ns.height) {
- ns.height = ((double)ns.width * 1/ratio + 0.5);
- } else {
- ns.width = ((double)ns.height * ratio + 0.5);
- }
- }
+#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);
+
+ // clip frame to screens visibile frame
+ nf = CGRectIntersection(nf, vf);
+
+ NSPoint new_center = get_center(nf);
- int dw = nf.size.width - ns.width;
- int dh = nf.size.height - ns.height - title_height;
+ int dx0 = old_center.x - new_center.x;
+ int dy0 = old_center.y - new_center.y;
- nf.origin.x += dw / 2;
- nf.origin.y += dh / 2;
+ nf.origin.x += dx0;
+ nf.origin.y += dy0;
- NSRect new_frame =
- NSMakeRect(nf.origin.x, nf.origin.y, ns.width, ns.height + title_height);
- [self setFrame:new_frame display:YES animate:NO];
+ [self setFrame:nf display:YES animate:NO];
+#undef get_center
}
- (void)setContentSize:(NSSize)ns keepCentered:(BOOL)keepCentered