summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-07-09 22:18:52 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-07-30 20:02:48 +0200
commitff3b98d11c374c7ed39e1093b4598c7ee9c7f10f (patch)
treefba511839409002640c86c12dc6a198296e6afdc /video
parenta34c707f038bfc655ae161e17c6cff63c1527ba0 (diff)
downloadmpv-ff3b98d11c374c7ed39e1093b4598c7ee9c7f10f.tar.bz2
mpv-ff3b98d11c374c7ed39e1093b4598c7ee9c7f10f.tar.xz
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.
Diffstat (limited to 'video')
-rw-r--r--video/out/cocoa_common.m67
1 files changed, 16 insertions, 51 deletions
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