diff options
author | Damiano Galassi <[email protected]> | 2016-05-03 18:47:14 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2016-05-03 18:47:14 +0200 |
commit | e53308f9342d911a9d3e8f4d1eeba6e53fabc0ab (patch) | |
tree | f65f5390d9174276022790a308660e17d7a3601f /macosx/NSWindow+HBAdditions.m | |
parent | 4ab21a0ca630dc4bac79149a6eec598921899fe5 (diff) |
MacGui: use AVFoundation as the first option for the preview playback. Add volume and tracks controls to the player hud.
Diffstat (limited to 'macosx/NSWindow+HBAdditions.m')
-rw-r--r-- | macosx/NSWindow+HBAdditions.m | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/macosx/NSWindow+HBAdditions.m b/macosx/NSWindow+HBAdditions.m new file mode 100644 index 000000000..2951d7a1f --- /dev/null +++ b/macosx/NSWindow+HBAdditions.m @@ -0,0 +1,79 @@ +// +// NSWindow+HBAdditions.m +// HandBrake +// +// Created by Damiano Galassi on 25/04/16. +// +// + +#import "NSWindow+HBAdditions.h" + +@implementation NSWindow (HBAdditions) + +- (void)HB_resizeToBestSizeForViewSize:(NSSize)viewSize center:(NSPoint)center animate:(BOOL)animateFlag +{ + NSSize currentSize = self.contentView.frame.size; + NSRect frame = self.frame; + + // Calculate border around content region of the frame + int borderX = (int)(frame.size.width - currentSize.width); + int borderY = (int)(frame.size.height - currentSize.height); + + // Make sure the frame is smaller than the screen + NSSize maxSize = self.screen.visibleFrame.size; + + // if we are not Scale To Screen, put an 10% of visible screen on the window + maxSize.width = maxSize.width * 0.90; + maxSize.height = maxSize.height * 0.90; + + // Set the new frame size + // Add the border to the new frame size so that the content region + // of the frame is large enough to accomodate the preview image + frame.size.width = viewSize.width + borderX; + frame.size.height = viewSize.height + borderY; + + // compare frame to max size of screen + if (frame.size.width > maxSize.width) + { + frame.size.width = maxSize.width; + } + if (frame.size.height > maxSize.height) + { + frame.size.height = maxSize.height; + } + + // Since upon launch we can open up the preview window if it was open + // the last time we quit (and at the size it was) we want to make + // sure that upon resize we do not have the window off the screen + // So check the origin against the screen origin and adjust if + // necessary. + NSSize screenSize = self.screen.visibleFrame.size; + NSPoint screenOrigin = self.screen.visibleFrame.origin; + + frame.origin.x = center.x - floor(frame.size.width / 2); + frame.origin.y = center.y - floor(frame.size.height / 2); + + // our origin is off the screen to the left + if (frame.origin.x < screenOrigin.x) + { + // so shift our origin to the right + frame.origin.x = screenOrigin.x; + } + else if ((frame.origin.x + frame.size.width) > (screenOrigin.x + screenSize.width)) + { + // the right side of the preview is off the screen, so shift to the left + frame.origin.x = (screenOrigin.x + screenSize.width) - frame.size.width; + } + + [self setFrame:frame display:YES animate:animateFlag]; +} + +- (NSPoint)HB_centerPoint +{ + NSPoint center = NSMakePoint(floor(self.frame.origin.x + self.frame.size.width / 2), + floor(self.frame.origin.y + self.frame.size.height / 2)); + return center; +} + + +@end |