From ff3b98d11c374c7ed39e1093b4598c7ee9c7f10f Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 9 Jul 2013 22:18:52 +0200 Subject: cocoa_common: simplify resize code This introduces some changes in resize behaviour. Most importantly the window frame is not constrained to it's screen's `visibleFrame`. Anyone who still wants that kind of behaviour when opening a video, can use `--autofit-larger`. Even though the size of the window is not constrained, it's position is, so that the titlebar will always be visible. When using `--no-border` even the position will not be constrained in any way. --- video/out/cocoa_common.m | 67 ++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 51 deletions(-) (limited to 'video') diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index b280b54a31..48bcbfa1ac 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -46,8 +46,7 @@ - (void)fullscreen; - (void)mulSize:(float)multiplier; - (int)titleHeight; -- (NSRect)clipFrame:(NSRect)frame withContentAspect:(NSSize) aspect; -- (void)setContentSize:(NSSize)newSize keepCentered:(BOOL)keepCentered; +- (void)setCenteredContentSize:(NSSize)newSize; @property(nonatomic, assign) struct vo *videoOutput; @end @@ -284,7 +283,7 @@ static void update_state_sizes(struct vo_cocoa_state *s, static void resize_window_from_stored_size(struct vo *vo) { struct vo_cocoa_state *s = vo->cocoa; - [s->window setContentSize:s->current_video_size keepCentered:YES]; + [s->window setCenteredContentSize:s->current_video_size]; [s->window setContentAspectRatio:s->current_video_size]; } @@ -742,7 +741,7 @@ int vo_cocoa_cgl_color_size(struct vo *vo) .width = self.videoOutput->cocoa->aspdat.prew * multiplier, .height = self.videoOutput->cocoa->aspdat.preh * multiplier }; - [self setContentSize:size keepCentered:YES]; + [self setCenteredContentSize:size]; } } @@ -753,60 +752,26 @@ int vo_cocoa_cgl_color_size(struct vo *vo) 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); - } else { - s.height = ((double)s.width * 1.0/ratio); - } - - 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]; - NSPoint old_center = get_center(of); - - NSRect nf = NSMakeRect(vf.origin.x, vf.origin.y, - ns.width, ns.height + [self titleHeight]); - - nf = [self clipFrame:nf withContentAspect:ns]; - - NSPoint new_center = get_center(nf); - - int dx0 = old_center.x - new_center.x; - int dy0 = old_center.y - new_center.y; + NSRect f = [self frame]; + CGFloat dx = (f.size.width - ns.width) / 2; + CGFloat dy = (f.size.height - ns.height - [self titleHeight]) / 2; + NSRect nf = NSRectFromCGRect(CGRectInset(NSRectToCGRect(f), dx, dy)); - nf.origin.x += dx0; - nf.origin.y += dy0; + struct vo *vo = self.videoOutput; + if (!(vo && !vo->opts->border)) { + NSRect s = [[self screen] visibleFrame]; + if (nf.origin.y + nf.size.height > s.origin.y + s.size.height) + nf.origin.y = s.size.height - nf.size.height; + } - [self setFrame:nf display:YES animate:NO]; -#undef get_center + [self setFrame:nf display:NO animate:NO]; } -- (void)setContentSize:(NSSize)ns keepCentered:(BOOL)keepCentered +- (NSRect)constrainFrameRect:(NSRect)rect toScreen:(NSScreen *)screen { - if (keepCentered) { - [self setCenteredContentSize:ns]; - } else { - [self setContentSize:ns]; - } + return rect; } @end -- cgit v1.2.3